summaryrefslogtreecommitdiffstats
path: root/dhcp-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dhcp-model.lua')
-rw-r--r--dhcp-model.lua64
1 files changed, 64 insertions, 0 deletions
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 = {}