summaryrefslogtreecommitdiffstats
path: root/dhcp-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-03 15:11:35 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-03 15:11:35 +0000
commit18897d09522e08bdf6f7b87110686445abf3f979 (patch)
treec0c7b58d5a3a0f36d31fb243d9f6587160059e4f /dhcp-model.lua
parent1af8d04a69cb46bbebfb77a39e14e1c4978a7749 (diff)
downloadacf-dhcp-18897d09522e08bdf6f7b87110686445abf3f979.tar.bz2
acf-dhcp-18897d09522e08bdf6f7b87110686445abf3f979.tar.xz
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
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 = {}