From 18897d09522e08bdf6f7b87110686445abf3f979 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 3 Apr 2008 15:11:35 +0000 Subject: Adding a 'status' tab that shows some basic information. git-svn-id: svn://svn.alpinelinux.org/acf/dhcp/trunk@909 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dhcp-controller.lua | 73 ++++++++++++++++++++++++++++++++++--------- dhcp-home-html.lsp | 80 ++++++++++++++++++++++++++++++++---------------- dhcp-model.lua | 64 ++++++++++++++++++++++++++++++++++++++ dhcp-settings-html.lsp | 2 +- dhcp-status-html.lsp | 36 ++++++++++++++++++++++ dhcp-view-html.lsp | 12 -------- dhcp-viewconfig-html.lsp | 12 ++++++++ dhcp-viewleases-html.lsp | 12 ++++++++ dhcp.menu | 5 ++- 9 files changed, 240 insertions(+), 56 deletions(-) create mode 100644 dhcp-status-html.lsp delete mode 100644 dhcp-view-html.lsp create mode 100644 dhcp-viewconfig-html.lsp create mode 100644 dhcp-viewleases-html.lsp diff --git a/dhcp-controller.lua b/dhcp-controller.lua index cf9d307..9e0d428 100644 --- a/dhcp-controller.lua +++ b/dhcp-controller.lua @@ -6,7 +6,7 @@ module (..., package.seeall) -- We use the self.conf table because it already has prefix,controller,etc -- The redir code is defined in the application error handler (acf-controller) local list_redir = function (self) - self.conf.action = "home" + self.conf.action = "status" self.conf.type = "redir" error (self.conf) end @@ -214,6 +214,18 @@ createnet = function ( self ) end end +status = function ( self ) + return cfe({ option = { script = ENV["SCRIPT_NAME"], + prefix = self.conf.prefix, + controller = self.conf.controller, + action = self.conf.action, + extra = "", + }, + value = "", + genmsg = genmsg, + info = self.model.getstatus() }) +end + home = function ( self ) -- dependancy check for neccessary libs/packages et al. @@ -242,25 +254,56 @@ home = function ( self ) action = self.conf.action, extra = "" } - local info = { status = { value = "stopped" }, version = { value = self.model.get_dhcpd_version() }, srvctrl = { value = srvctrl} }; - if self.model.is_running( "dhcpd" ) then - info.status.value = "running" - end + + local info = self.model.getstatus() info.subnets = self.model.get_subnets() - return ( cfe({ option = option, value = "", genmsg = genmsg, info = info }) ) + -- Add a management buttons + local management = {} + management.start = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Start", + type="submit", + }) + management.stop = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Stop", + type="submit", + }) + management.restart = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Restart", + type="submit", + }) + -- Disable management buttons based on if the process is running or not + if (string.lower(info.status.value) == "enabled") then management.start.disabled = "yes" end + if (string.lower(info.status.value) == "disabled") then management.stop.disabled = "yes" end + if (string.lower(info.status.value) == "disabled") then management.restart.disabled = "yes" end + + return ( cfe({ option = option, value = "", genmsg = genmsg, info = info, management = management, }) ) end -view = function ( self ) +viewleases = function ( self ) - local filename = "" - if self.clientdata.conf then - filename = "/etc/dhcp/dhcpd.conf" - elseif self.clientdata.leases then - filename = "/var/lib/dhcpd/dhcpd.leases"; - else - list_redir(self) - end + local filename = "/var/lib/dhcp/dhcpd.leases"; + + local option = { script = ENV["SCRIPT_NAME"], + prefix = self.conf.prefix, + controller = self.conf.controller, + action = self.conf.action, + extra = "" + } + + local value = { filename = { value=filename }, + contents = { value=self.model.read_file(filename) } + } + + return ( cfe({ option = option, value = value }) ) +end + +viewconfig = function ( self ) + + local filename = "/etc/dhcp/dhcpd.conf" local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, diff --git a/dhcp-home-html.lsp b/dhcp-home-html.lsp index 9bfc6cf..075e1c3 100644 --- a/dhcp-home-html.lsp +++ b/dhcp-home-html.lsp @@ -3,23 +3,37 @@ local data = form.option ?> -

Home

-

System info

+ 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end +end +?> +

SYSTEM INFO

-
Program version
-
- -
Process status
-
- -
Daemon control
-
- - -
-

-
+

Change/Generate settings

@@ -68,15 +82,27 @@ " .. form.genmsg .. "

" ) end ?> -

View files

-
-
" method="POST"> -
View dhcpd.conf
-
- -
View dhcpd.leases
-
-
-
- - +') + io.write('

MANAGEMENT

') + io.write('
') + io.write('
' .. cmdform[tags[1]]["label"] .. '
') + io.write('
') + for k,v in pairs(tags) do + if (cmdform[v]) then + io.write(html.form[cmdform[v].type](cmdform[v])) + end + end + io.write('
') + + if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then + io.write('
' .. cmdresult.label .. '
') + io.write('
' .. cmdresult.action.descr .. '
') + end + io.write('
') +end ?> diff --git a/dhcp-model.lua b/dhcp-model.lua index 4ea2afd..84fe35c 100644 --- a/dhcp-model.lua +++ b/dhcp-model.lua @@ -6,9 +6,73 @@ module (..., package.seeall) require("procps") require("validator") require("daemoncontrol") +require("procps") local subnet = {} local cfgdir = "/etc/dhcp/" +local processname = "dhcpd" +local packagename = "dhcp" + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function get_version() + local cmd = "/sbin/apk_version -v -s " .. packagename .. " | cut -d ' ' -f 1" + local cmd_output = io.popen( cmd ) + local cmd_output_result = cmd_output:read("*a") or "" + cmd_output:close() + return cmd_output_result +end + +local function autostarts() + local cmd_output_result + local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null" + local f = io.popen( cmd ) + local cmdresult = f:read("*a") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')" + else + cmd_output_error = "Not programmed to autostart" + end + f:close() + return cmd_output_result, cmd_output_error +end + +function process_status_text(procname) + local t = procps.pidof(procname) + if (t) and (#t > 0) then + return "Enabled" + else + return "Disabled" + end +end +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function getstatus () + local status = {} + + status.version = cfe({ + name = "version", + label="Program version", + value=get_version(), + }) + + status.status = cfe({ + name="status", + label="Program status", + value=process_status_text(processname), + }) + + local autostart_sequense, autostart_errtxt = autostarts() + status.autostart = cfe({ name="autostart", + label="Autostart sequence", + value=autostart_sequense, + errtxt=autostart_errtxt, + }) + + return status +end --- the tokenizer functions - must be dislocated into a library later tokenizer = {} diff --git a/dhcp-settings-html.lsp b/dhcp-settings-html.lsp index 1654d29..ea3a4ba 100644 --- a/dhcp-settings-html.lsp +++ b/dhcp-settings-html.lsp @@ -31,7 +31,7 @@
Cancel and go back
-
method="POST"> +
" method="POST">
diff --git a/dhcp-status-html.lsp b/dhcp-status-html.lsp new file mode 100644 index 0000000..183b2bb --- /dev/null +++ b/dhcp-status-html.lsp @@ -0,0 +1,36 @@ + + + 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end +end +?> + +

SYSTEM INFO

+
+ +
+ + diff --git a/dhcp-view-html.lsp b/dhcp-view-html.lsp deleted file mode 100644 index 9cf116e..0000000 --- a/dhcp-view-html.lsp +++ /dev/null @@ -1,12 +0,0 @@ - -

View

- - -
" method="POST"> - -
- diff --git a/dhcp-viewconfig-html.lsp b/dhcp-viewconfig-html.lsp new file mode 100644 index 0000000..9cf116e --- /dev/null +++ b/dhcp-viewconfig-html.lsp @@ -0,0 +1,12 @@ + +

View

+ + +
" method="POST"> + +
+ diff --git a/dhcp-viewleases-html.lsp b/dhcp-viewleases-html.lsp new file mode 100644 index 0000000..9cf116e --- /dev/null +++ b/dhcp-viewleases-html.lsp @@ -0,0 +1,12 @@ + +

View

+ + +
" method="POST"> + +
+ diff --git a/dhcp.menu b/dhcp.menu index 8cb8b26..567e7bd 100644 --- a/dhcp.menu +++ b/dhcp.menu @@ -1,4 +1,7 @@ # Prefix and controller are already known at this point # Cat Group Tab Action -Networking 10DHCP Home home +Networking 10DHCP Status status +Networking 10DHCP Config home +Networking 10DHCP View_leases viewleases +Networking 10DHCP View_config viewconfig Networking 10DHCP Help help -- cgit v1.2.3