summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dhcp-controller.lua73
-rw-r--r--dhcp-home-html.lsp80
-rw-r--r--dhcp-model.lua64
-rw-r--r--dhcp-settings-html.lsp2
-rw-r--r--dhcp-status-html.lsp36
-rw-r--r--dhcp-viewconfig-html.lsp (renamed from dhcp-view-html.lsp)0
-rw-r--r--dhcp-viewleases-html.lsp12
-rw-r--r--dhcp.menu5
8 files changed, 228 insertions, 44 deletions
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
?>
-<h1>Home</h1>
-<h2>System info</h2>
+<?
+function displayinfo(myform,tags,viewonly)
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+end
+?>
+<H1>SYSTEM INFO</H1>
<DL>
-<dt>Program version</dt>
-<dd><? io.write(form.info.version.value) ?></dd>
-
-<dt>Process status</dt>
-<dd><? io.write( form.info.status.value ) ?></dd>
-
-<dt>Daemon control</dt>
-<dd><form action="" method="POST">
-<input type=submit name="srvcmd" value="start" class="submit">
-<input type=submit name="srvcmd" value="stop" class="submit">
-<input type=submit name="srvcmd" value="restart" class="submit"></form>
-<p class='error'><? io.write( form.info.srvctrl.value ) ?></p>
-</dd>
+<?
+local myform = form.info
+local tags = { "status", "version", "autostart", }
+displayinfo(myform,tags,"viewonly")
+?>
</DL>
<H2>Change/Generate settings</H2>
@@ -68,15 +82,27 @@
<? if form.genmsg ~= nil then io.write( "<p class='error'>" .. form.genmsg .. "</p>" ) end ?></dd>
</DL>
-<h2>View files</h2>
-<DL>
-<form action="<? io.write(data.script .. data.prefix .. data.controller .. "/view") ?>" method="POST">
-<dt>View dhcpd.conf</dt>
-<dd><input type=submit name="conf" value="dhcpd.conf" class="submit"></dd>
-
-<dt>View dhcpd.leases</dt>
-<dd><input type=submit name="leases" value="dhcpd.leases" class="submit"></dd>
-</form>
-</DL>
-
-
+<? -- MANAGEMENT BUTTONS
+local cmdform = form.management
+local cmdresult = form.cmdmanagement
+local tags = { "start", "stop", "restart" }
+if (cmdform) and (cmdform[tags[1]]) then
+
+ io.write('<form name="management" action="" method="POST">')
+ io.write('<H1>MANAGEMENT</H1>')
+ io.write('<dl>')
+ io.write('<dt>' .. cmdform[tags[1]]["label"] .. '</dt>')
+ io.write('<dd>')
+ for k,v in pairs(tags) do
+ if (cmdform[v]) then
+ io.write(html.form[cmdform[v].type](cmdform[v]))
+ end
+ end
+ io.write('</dd>')
+
+ if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then
+ io.write('<dt>' .. cmdresult.label .. '</dt>')
+ io.write('<dd><pre>' .. cmdresult.action.descr .. '</pre></dd>')
+ end
+ io.write('</dl></form>')
+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 @@
</form>
<dt>Cancel and go back</dt>
-<dd><form action="<? io.write(option.script .. option.prefix .. option.controller .. "/home") ?> method="POST">
+<dd><form action="<? io.write(option.script .. option.prefix .. option.controller .. "/home") ?>" method="POST">
<input type=submit name="cmd" value="back" class="submit"></form></dd>
</DL>
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 @@
+<? local form = ... ?>
+
+<?
+function displayinfo(myform,tags,viewonly)
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+end
+?>
+
+<H1>SYSTEM INFO</H1>
+<DL>
+<?
+local myform = form.info
+local tags = { "status", "version", "autostart", }
+displayinfo(myform,tags,"viewonly")
+?>
+</DL>
+
+
diff --git a/dhcp-view-html.lsp b/dhcp-viewconfig-html.lsp
index 9cf116e..9cf116e 100644
--- a/dhcp-view-html.lsp
+++ b/dhcp-viewconfig-html.lsp
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 @@
+<?
+ local form = ...
+ local option = form.option
+ local value = form.value
+?>
+<h1>View <? io.write(value.filename.value) ?></h1>
+
+<textarea name=""><? io.write(value.contents.value) ?></textarea>
+<form action="<? io.write(option.script .. option.prefix .. option.controller .. "/home") ?>" method="POST">
+ <input type=submit name="cmd" value="Back" class="submit">
+</form>
+
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