summaryrefslogtreecommitdiffstats
path: root/openntpd-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openntpd-model.lua')
-rw-r--r--openntpd-model.lua49
1 files changed, 36 insertions, 13 deletions
diff --git a/openntpd-model.lua b/openntpd-model.lua
index 2db000a..14aad55 100644
--- a/openntpd-model.lua
+++ b/openntpd-model.lua
@@ -3,6 +3,7 @@ module (..., package.seeall)
require("format")
require("date")
require("fs")
+require("posix")
local ntpdconfig = "/etc/ntpd.conf"
local progname = "openntpd"
@@ -61,58 +62,80 @@ local function get_version ()
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
+ local statusreport = nil
+ local cmdoutput = {}
+ local cmd, error = io.popen("pidof " .. process ,r)
+ local cmdoutput = string.gsub(cmd:read("*a"), "%s", "")
+ cmd:close()
+ if (cmdoutput ~= "") 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
+local last_time_change = function()
+ local cmdoutput = {}
+ local cmd, error = io.popen("cat /var/log/messages | grep ntpd | grep adjusting | tail -1" ,r)
+ local cmdoutput1,cmdoutput2 = string.match(cmd:read("*a"), "^%s*(%S+%s+%S+%s+%S+%s+).*: (.*)$")
+ cmd:close()
+-- if not (cmdoutput1) then cmdouput
+ cmdoutput1 = cmdoutput1 or "(Have no data on updates)"
+ cmdoutput2 = cmdoutput2 or ""
+ return cmdoutput1 .. cmdoutput2
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
function startstop_service ( self, state )
local status = {}
- local f,err = io.popen("/etc/init.d/ntpd " .. state)
+ -- This is a strange hack to get the init.d script working
+ local f,err = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/ntpd " .. state)
local config = f:read("*a")
f:close()
if (config == "") then
config = "OK!"
end
- status.status = "Command:" .. state .." Result:" ..config
+ status.status = config
return status
end
function get ()
local path = ntpdconfig
+ local config = {}
if not (fs.is_file(path)) then
local file_result,err = fs.write_file(path, "")
end
- config = config_content ( path )
+ local startstop = is_running ("ntpd")
+ local config = config_content ( path )
+ if (config["listen"]) then
+ server = "Yes"
+ else
+ server = "No"
+ end
config["version"] = string.match(get_version(), "^(%S*)" )
- config["status"] = is_running ("ntpd")
config["date"] = os.date()
+ config["status"] = startstop
+ config["listenstate"] = server
+ config["timechanged"] = last_time_change()
config["timezone"] = date.what_tz()
return config
end
function get_filecontent (self)
local path = ntpdconfig
- file_content = nil
+ local file_content = get()
if (fs.is_file(path)) then
local filedetails = file_info(path)
+ local configstatus = get()
local file = io.open( path )
local file_result = file:read("*a") or "unknown"
+ file_content["filedetails"]=filedetails
+ file_content["value"]=file_result
file:close()
- file_content = {name=name, value=file_result, filedetails=filedetails}
else
file_content = {value="", errtxt="File is missing, but will be created when you save your new settings",filedetails={longname=path, size="0", mtimelong=""}}
end