From 264a35ad5a5c5a22e3cb14190826d200c2b66ab2 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 5 Dec 2007 11:06:13 +0000 Subject: Working on start|stop of the service (start|stop doesn't work at this point... And I don't know why) git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@409 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openntpd-controller.lua | 9 ++++++++- openntpd-model.lua | 52 ++++++++++++++++++++++++++++--------------------- openntpd-read-html.lsp | 17 ++++++++++++---- 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 @@
Program version
-
Process running or not
+
Process status
Current time
- +
TimeZone
-
xxx
+

NTPD SETTINGS

@@ -64,8 +64,17 @@ for i = 1, table.maxn(view.filecontent.listen) do ?>
+

MANAGEMENT

+ +
Start NTPD
+
+ +
Stop NTPD
+
+ +