summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openntpd-controller.lua9
-rw-r--r--openntpd-model.lua52
-rw-r--r--openntpd-read-html.lsp17
3 files changed, 51 insertions, 27 deletions
diff --git a/openntpd-controller.lua b/openntpd-controller.lua
index d298b1d..06b53b2 100644
--- a/openntpd-controller.lua
+++ b/openntpd-controller.lua
@@ -18,7 +18,14 @@ end
read = function (self)
- return ( {filecontent = self.model:get(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ 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 } )
+ else
+ return ( {filecontent = self.model:get(), shutdown = "" , startup = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ end
end
advanced = function (self)
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
diff --git a/openntpd-read-html.lsp b/openntpd-read-html.lsp
index 5c88cbc..08c5336 100644
--- a/openntpd-read-html.lsp
+++ b/openntpd-read-html.lsp
@@ -7,15 +7,15 @@
<dt>Program version</dt>
<dd><? io.write(view.filecontent.version) ?></dd>
-<dt>Process running or not</dt>
+<dt>Process status</dt>
<dd><? io.write(view.filecontent.status) ?></dd>
<dt>Current time</dt>
<dd><? io.write(view.filecontent.date) ?></dd>
-<? --[[ ?>
+<? ---[[ ?>
<dt>TimeZone</dt>
-<dd>xxx</dd>
+<dd><? io.write(view.filecontent.timezone) ?></dd>
<? --]] ?>
<h2>NTPD SETTINGS</h2>
@@ -64,8 +64,17 @@ for i = 1, table.maxn(view.filecontent.listen) do ?>
<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))
--]]