News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
lighttpd interface
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
lighttpd interface

This is a (Linux/Unix/BSD) gui interface to the lighttpd web server.
I've been tweaking it a little here and there since it was still a Lua-FLTK script.
At this point I think it will work for all versions of MurgaLua from the start to 0.5.5 since it doesn't use anything other than Lua and FLTK.

You might want to check/edit the paths under "find conf file" (or just change the lightyvar variable) to reflect where the lighttpd config file is located. This script was designed to work with a lighttpd package for Damn Small Linux that installed to /opt/lighttpd. It should be tweaked some more for general (non-DSL) use, but I was working on it a little today and just thought I'd post it.

It should be run as root, or edit the commands to run as root.

Code:
#!/bin/murgaLua

--[[

  gui controller for lighttpd (c)2006-2007 mikshaw
  should work with all versions of murgaLua, including 0.5.5,
  which was the current version at the time of this release

]]

Fl:get_system_colors()
Fl:scheme(NULL)

-- test if given file is readable
function find_conf(file)
local filetest=io.open(file)
if filetest then
  filetest:close()
  return true
end
end

-- find conf file
lightyvar=os.getenv("LIGHTTPD_CONF")
if lightyvar and find_conf(lightyvar) then lighttpd_conf=lightyvar
elseif find_conf("/opt/lighttpd.conf") then lighttpd_conf="/opt/lighttpd.conf"
else lighttpd_conf="/opt/lighttpd/test/lighttpd.conf" end

tempfile="/tmp/lighttpd.lua.tmp" -- for command output

function checkstatus() -- see if server is running
state:hide() -- prevents label overlap
if os.execute("pidof lighttpd &>/dev/null") == 0 then
state:label("server is running") else state:label("server is not running")
end
state:show()
end

-- this might need some improvement one day
function lcontrol(self)
if self:label() == "test config" then
os.execute("/opt/lighttpd/lighty test &>"..tempfile)
else
os.execute("/opt/lighttpd/lighty "..self:label().." &>"..tempfile.." && sleep 1")
checkstatus()
end
-- show the command output
for line in io.lines(tempfile) do outpoot:add(line) end
outpoot:bottomline(outpoot:size())
os.remove(tempfile)
end

-- start interface
bw=80;bh=25;ww=bw*4;wh=bh*7
w=fltk:Fl_Window(ww,wh,"LIGHTTPD Control")
cfg=fltk:Fl_Box(0,bh,ww,bh)
cfg:label("config file: "..lighttpd_conf)
state=fltk:Fl_Box(0,bh*2,ww,bh)
bup=fltk:Fl_Button(0,0,bw,bh,"start");bup:callback(lcontrol)
bdn=fltk:Fl_Button(bw,0,bw,bh,"stop");bdn:callback(lcontrol)
bre=fltk:Fl_Button(bw*2,0,bw,bh,"restart");bre:callback(lcontrol)
bt=fltk:Fl_Button(bw*3,0,bw,bh,"test config");bt:callback(lcontrol)

outpoot=fltk:Fl_Browser(0,bh*3,ww,bh*4)
w:resizable(outpoot)

checkstatus()
w:show()
Fl:run()


Oh...I forgot it makes use of a bash script too:

Code:
#! /bin/sh

LIGHTTPD=/opt/lighttpd/sbin/lighttpd

# Find a configuration file; checks for existing LIGHTTPD_CONF variable first
[ -r "${LIGHTTPD_CONF}" ] ||  LIGHTTPD_CONF=/opt/lighttpd.conf
[ -r "${LIGHTTPD_CONF}" ] ||  LIGHTTPD_CONF=/opt/lighttpd/test/lighttpd.conf
#PIDFILE=/var/run/lighttpd.pid

testlightycfg() {
        echo "lighttpd: Using configuration file ${LIGHTTPD_CONF}..."
        ${LIGHTTPD} ${1} -t -f ${LIGHTTPD_CONF} || exit 1
}

case $1 in
    start)
        testlightycfg
        echo "Starting lighttpd"
        ${LIGHTTPD} -f ${LIGHTTPD_CONF}
        ;;
    stop)
        echo "Shutting down lighttpd"
        killall ${LIGHTTPD}
        rm -f /var/run/lighttpd.pid
        ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    test*)
        testlightycfg -p
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|test}"
        exit 1
        ;;
esac


If I had remembered that, i'd have rewritten it to work completely from murgaLua...my bad.
I'll be back later to fix that.

It also appears that the code tags don't preserve text as well as I'd thought. The bash script is riddled with "\{{mybb-code}}" where there should be variables.

This post was last modified: 09-08-2007 04:51 PM by mikshaw.

09-08-2007 09:53 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
lighttpd interface - mikshaw - 09-08-2007 09:53 AM
RE: lighttpd interface - mikshaw - 09-09-2007, 04:53 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: