diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-15 14:52:31 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-15 14:52:31 +0000 |
commit | f4ff698b7b510fc24ccd4d44ccfe0fcbcce417a5 (patch) | |
tree | 307e9ab2a9cb82f5cdad3b47ce7232cd93cf48ad /chrony-controller.lua | |
download | acf-chrony-f4ff698b7b510fc24ccd4d44ccfe0fcbcce417a5.tar.bz2 acf-chrony-f4ff698b7b510fc24ccd4d44ccfe0fcbcce417a5.tar.xz |
Creating acf-chrony. status/expert/logfile functionallity should work.
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@992 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'chrony-controller.lua')
-rw-r--r-- | chrony-controller.lua | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/chrony-controller.lua b/chrony-controller.lua new file mode 100644 index 0000000..4176ec1 --- /dev/null +++ b/chrony-controller.lua @@ -0,0 +1,129 @@ +module(..., package.seeall) + +-- Load libraries +require("format") + +-- Set variables +local newrecordtxt = "[New]" + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function list_redir(self) + self.conf.action = "status" + self.conf.type = "redir" + error (self.conf) +end + +local function displaycmdmanagement(pidofstatus) + -- Add a management buttons + local management = {} + management.start = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Start", + type="submit", + }) + management.stop = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Stop", + type="submit", + }) + management.restart = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Restart", + type="submit", + }) + -- next CFE can be used to present the result of the previous action + management.actionresult = cfe({ name="actionresult", + label="Previous action result", + descr="", --Content of this variable is displayed as <PRE> ... </PRE> in BLACK text + errtxt="", --Content of this variable is displayed as <PRE> ... </PRE> in RED text + }) + + -- Disable management buttons based on if the process is running or not + if (pidofstatus) then + management.start.disabled = "yes" + else + management.stop.disabled = "yes" + management.restart.disabled = "yes" + end + + return management +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS +mvc = {} +function mvc.on_load(self, parent) + if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then + self.worker[self.conf.action] = list_redir(self) + end +end + +function status(self) + return { status=self.model.getstatus() } +end + +function expert(self) + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave ) then + modifications = self.model:update_filecontent(modifications) + end + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller + + -- Start/Stop/Restart process + local cmdmanagement, actionresult + if ( self.clientdata.cmdmanagement) then + cmdmanagement = cfe({ + name="cmdmanagement", + label="Previous action result", + action=cfe({ + name="cmdmanagement", + value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) + }), + }) + actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) + end + + local status=self.model.getstatus() + local file = self.model:get_filedetails() + + -- Add buttons + file.cmdsave = cfe ({ + name="cmdsave", + label="Apply settings", + value="Apply", + type="submit", + }) + if (self.clientdata.cmdsave) then + file.cmdsave.descr="* Changes has been saved!" + end + + -- Management buttons (Hide/show buttons + local pidofstatus + if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end + management = displaycmdmanagement(pidofstatus) + if (actionresult) then + management.actionresult.descr=cmdmanagement.descr + management.actionresult.errtxt=cmdmanagement.errtxt + end + + return ( { + status = status, + file = file, + modifications = modifications, + management = management, + url = url, } ) +end + +function logfile(self) + + local status=self.model.getstatus() + local logfile = self.model:get_logfile() + + return ({ + status = status, + logfile = logfile, + url = url, + }) +end |