diff options
Diffstat (limited to 'openntpd-model.lua')
-rw-r--r-- | openntpd-model.lua | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/openntpd-model.lua b/openntpd-model.lua index 5c52444..2db000a 100644 --- a/openntpd-model.lua +++ b/openntpd-model.lua @@ -1,6 +1,7 @@ module (..., package.seeall) require("format") +require("date") require("fs") local ntpdconfig = "/etc/ntpd.conf" @@ -59,40 +60,47 @@ local function get_version () return programversion end +local is_running = function( process ) + local statusreport = "" + local pidofsx, error = io.popen("pidof " .. process ,r) + local pidofs = format.string_to_table(" ", string.gsub(pidofsx:read("*a"), "\n", "")) + pidofsx:close() + if (table.maxn(pidofs) > 1) then + statusreport = "Running" + elseif (table.maxn(pidofs) == 1) then + statusreport = "Unknown (Only 1 process running, this might be wrong)" + else + statusreport = "Stopped" + end + return statusreport +end -- ################################################################################ -- PUBLIC FUNCTIONS ---[[ -function restart_service () - local f,err = io.popen("/etc/init.d/shorewall restart") - local restart = f:read("*a") + +function startstop_service ( self, state ) + local status = {} + local f,err = io.popen("/etc/init.d/ntpd " .. state) + local config = f:read("*a") f:close() - local status = get_status() - status.restart = restart + if (config == "") then + config = "OK!" + end + status.status = "Command:" .. state .." Result:" ..config return status end ---]] ---[[ -function get_status () - local f,error = io.popen("/sbin/shorewall status") - local fake = f:read("*l") - local fake = f:read("*l") - local programstatus = f:read("*l") - local programstate = f:read("*l") - f:close() - local f,error = io.popen("/sbin/shorewall version") - local programversion = f:read("*l") - f:close() - return {programversion=programversion,programstatus=programstatus,programstate=programstate} -end ---]] + function get () local path = ntpdconfig + if not (fs.is_file(path)) then + local file_result,err = fs.write_file(path, "") + end config = config_content ( path ) config["version"] = string.match(get_version(), "^(%S*)" ) - config["status"] = "xXx" + config["status"] = is_running ("ntpd") config["date"] = os.date() + config["timezone"] = date.what_tz() return config end |