summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openntpd-advanced-html.lsp28
-rw-r--r--openntpd-controller.lua37
-rw-r--r--openntpd-model.lua49
-rw-r--r--openntpd-read-html.lsp72
4 files changed, 91 insertions, 95 deletions
diff --git a/openntpd-advanced-html.lsp b/openntpd-advanced-html.lsp
index 5cb8104..33f59e5 100644
--- a/openntpd-advanced-html.lsp
+++ b/openntpd-advanced-html.lsp
@@ -1,18 +1,15 @@
<? local view = ... ?>
-<?
---[[ DEBUG INFORMATION
-require("debugs")
-io.write(debugs.variables(view))
---]]
-?>
<h1>System time</h1>
-<h2>MENU</h2>
+<h2>SYSTEM INFO</h2>
+
+<dt>Process status</dt>
+<dd><? io.write(view.statusinfo.status) ?><? if (view.startstop.status) then io.write(" (" .. view.startstop.status .. ")") end ?></dd>
-<dt><?= html.link{value = view.url .. "/", label="Home" } ?></dt>
-<dd>Go back to start page</dd>
+<dt>Start or stop process</dt>
+<dd><form name="start" action="" method="POST"><input type=submit name="cmd" value="start" style="width:100px"></form><form name="stop" action="" method="POST"><input type=submit name="cmd" value="stop" style="width:100px"></form></dd>
<h2>Details</h2>
@@ -25,15 +22,22 @@ io.write(debugs.variables(view))
<dt>Last modified</dt>
<dd><?= view.filecontent.filedetails.mtimelong ?></dd>
-<? if (view.filecontent.errtxt) then ?>
+<? if (view.statusinfo.errtxt) then ?>
<dt>Error message</dt>
-<dd class="error"><?= view.filecontent.errtxt ?></dd>
+<dd class="error"><?= view.statusinfo.errtxt ?></dd>
<? end ?>
<h2>Content</h2>
<form name="myform" action="" method="POST">
-<input name="name" type=hidden value="<?= view.filecontent.filedetails.name ?>" style="width:100%">
+<input name="name" type=hidden value="<?= view.filecontent.filedetails.longname ?>" style="width:100%">
<textarea name="modifications" style="width:100%;height:360px;"><?= view.filecontent.value ?></textarea>
<input type="submit" name="cmd" value="update"></form>
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
+
diff --git a/openntpd-controller.lua b/openntpd-controller.lua
index 06b53b2..8b1fe04 100644
--- a/openntpd-controller.lua
+++ b/openntpd-controller.lua
@@ -3,6 +3,7 @@ module (..., package.seeall)
-- Cause an http redirect to our "read" action
-- 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)
+require("posix")
local list_redir = function (self)
self.conf.action = "read"
self.conf.type = "redir"
@@ -17,25 +18,41 @@ mvc.on_load = function(self, parent)
end
-read = function (self)
+settings = function (self)
local cmd = self.clientdata.cmd
- if ( cmd == "start" ) then
- return ( {filecontent = self.model:get(), startup = self.model:startstop_service( cmd ), shutdown = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- elseif ( cmd == "stop" ) then
- return ( {filecontent = self.model:get(), shutdown = self.model:startstop_service( cmd ), startup = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ if ( cmd ~= nil ) then
+ local startstop = self.model:startstop_service( cmd )
+ posix.sleep(1) -- Wait for the process to start|stop
+ local statusinfo = self.model:get()
+ return ( {startstop = startstop, statusinfo = statusinfo, url = url } )
else
- return ( {filecontent = self.model:get(), shutdown = "" , startup = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ return ( {statusinfo = self.model:get(), startstop = "", url = url } )
end
end
+read = function (self)
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ return ( {statusinfo = self.model:get(), url = url } )
+end
+
advanced = function (self)
local filecontent = self.clientdata.modifications or ""
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+
if ( filecontent ~= "") then
- local me = ( {filecontent = self.model:update_filecontent(filecontent), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- list_redir(self)
+ local me = ( {filecontent = self.model:update_filecontent(filecontent), url = url } )
+ return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
else
- local me = ( {filecontent = self.model:get_filecontent(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- return me
+ if ( cmd ~= nil ) then
+ local startstop = self.model:startstop_service( cmd )
+ posix.sleep(1) -- Wait for the process to start|stop
+ return ( {startstop = startstop, statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
+ else
+ return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
+ end
end
end
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
diff --git a/openntpd-read-html.lsp b/openntpd-read-html.lsp
index 08c5336..4a3a9d9 100644
--- a/openntpd-read-html.lsp
+++ b/openntpd-read-html.lsp
@@ -5,76 +5,28 @@
<h2>SYSTEM INFO</h2>
<dt>Program version</dt>
-<dd><? io.write(view.filecontent.version) ?></dd>
+<dd><? io.write(view.statusinfo.version) ?></dd>
<dt>Process status</dt>
-<dd><? io.write(view.filecontent.status) ?></dd>
+<dd><? io.write(view.statusinfo.status) ?></dd>
+
+<dt>Configured as server (listens)</dt>
+<dd><? io.write(view.statusinfo.listenstate) ?></dd>
<dt>Current time</dt>
-<dd><? io.write(view.filecontent.date) ?></dd>
+<dd><? io.write(view.statusinfo.date) ?></dd>
+
+<dt>Latest time adjustment</dt>
+<dd><? io.write(view.statusinfo.timechanged) ?></dd>
-<? ---[[ ?>
+<? --[[ ?>
<dt>TimeZone</dt>
-<dd><? io.write(view.filecontent.timezone) ?></dd>
+<dd><? io.write(view.statusinfo.timezone) ?></dd>
<? --]] ?>
-<h2>NTPD SETTINGS</h2>
-
-<dt>Set time immediately at startup</dt>
-<dd><input type="checkbox" name=""></dd>
-
-<h3>'SET TIME' OPTIONS</h3>
-<dt>Timeserver hosts...</dt>
-<dd>
-<select name="" size="3" style="width:200px;">
-<? if (view.filecontent.servers) then
-for i = 1, table.maxn(view.filecontent.servers) do ?>
- <option name="<? io.write(view.filecontent.servers[i].value) ?>"><? io.write(view.filecontent.servers[i].value) ?></option>
-<? end end ?>
-<? if (view.filecontent.server) then
-for i = 1, table.maxn(view.filecontent.server) do ?>
- <option name="<? io.write(view.filecontent.server[i].value) ?>"><? io.write(view.filecontent.server[i].value) ?></option>
-<? end end ?>
-</select><BR>
-In most cases you could use <i><b>pool.ntp.org</b></i> or <i><b>[countryname].pool.ntp.org</i></b> (if listed in <i><b>http://www.pool.ntp.org/</b></i>).
-</dd>
-
-<dt>Delete selected host</dt>
-<dd><input type="submit" value="Delete"> (see above)</dd>
-
-<dt>Add new host</dt>
-<dd><input type="text" name="" value=""> <input type="submit" value="Add"></dd>
-
-<h3>'PRESENT TIME' OPTIONS (ACT AS TIME SERVER)</h3>
-<dt>Listen on address...</dt>
-<dd>
-<select name="" size="3" style="width:200px;">
-<? if (view.filecontent.listen) then
-for i = 1, table.maxn(view.filecontent.listen) do ?>
- <option name="<? io.write(view.filecontent.listen[i].value) ?>"><? io.write(view.filecontent.listen[i].value) ?></option>
-<? end end ?>
-</select><BR>Empty list = Not listening or acting as server; "*" = All local addresses
-</dd>
-
-<dt>Delete selected address</dt>
-<dd><input type="submit" value="Delete"> (see above)</dd>
-
-
-<dt>Add new listen address</dt>
-<dd><input type="text" name="" value=""> <input type="submit" value="Add"></dd>
-
-
-<h2>MANAGEMENT</h2>
-
-<dt>Start NTPD</dt>
-<dd><form name="check" action="" method="POST"><input type=submit name="cmd" value="start" style="width:100px"></form><? if (view.startup.status) then io.write(view.startup.status) end ?></dd>
-
-<dt>Stop NTPD</dt>
-<dd><form name="restart" action="" method="POST"><input type=submit name="cmd" value="stop" style="width:100px"></form><? if (view.shutdown.status) then io.write(view.shutdown.status) end ?></dd>
-
<?
----[[ DEBUG INFORMATION
+--[[ DEBUG INFORMATION
require("debugs")
io.write(debugs.variables(view))
--]]