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 | |
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
-rw-r--r-- | Makefile | 49 | ||||
-rw-r--r-- | README | 0 | ||||
-rw-r--r-- | chrony-controller.lua | 129 | ||||
-rw-r--r-- | chrony-expert-html.lsp | 58 | ||||
-rw-r--r-- | chrony-logfile-html.lsp | 31 | ||||
-rw-r--r-- | chrony-model.lua | 163 | ||||
-rw-r--r-- | chrony-status-html.lsp | 24 | ||||
-rw-r--r-- | chrony.menu | 5 | ||||
-rw-r--r-- | config.mk | 10 |
9 files changed, 469 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..563a926 --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +APP_NAME=chrony +PACKAGE=acf-$(APP_NAME) +VERSION=0.1.0 + +APP_DIST=\ + chrony-controller.lua \ + chrony-model.lua \ + chrony-status-html.lsp \ + chrony-logfile-html.lsp \ + chrony-expert-html.lsp \ + chrony.menu \ + + +EXTRA_DIST=README Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install 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 diff --git a/chrony-expert-html.lsp b/chrony-expert-html.lsp new file mode 100644 index 0000000..4f77e5e --- /dev/null +++ b/chrony-expert-html.lsp @@ -0,0 +1,58 @@ +<? local form = ... +require("viewfunctions") +?> +<? +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +?> + +<H1>SYSTEM INFO</H1> +<DL> +<? +local myform = form.status +local tags = { "status", "version", "autostart", } +displayinfo(myform,tags,"viewonly") +?> +</DL> + +<form name="myform" action="" method="POST"> +<h1>CONFIGURATION</h1> +<H2>Expert config</H2> +<h3>File details</h3> +<DL> +<? +local myform = form.file +local tags = { "filename", "filesize", "mtime", "sumerrors", } +displayinfo(myform,tags,"viewonly") +?> +</DL> + +<H3>FILE CONTENT</H3> +<? +local myform = form.file +io.write(html.form[myform.filecontent.type](myform.filecontent)) +?> + +<H2>SAVE AND APPLY ABOVE SETTINGS</H2> +<DL> +<? +local tags = { "cmdsave", } +displayinfo(myform,tags) +?> +</DL> + +<? +-- Management buttons +local myform = form.management +local tags = { "start", "stop", "restart" } +if (myform) then + io.write("<H1>MANAGEMENT</H1>\n<DL>") + displaymanagement(myform,tags) + io.write("</DL>") +end +?> +</form> + diff --git a/chrony-logfile-html.lsp b/chrony-logfile-html.lsp new file mode 100644 index 0000000..aa0b6e5 --- /dev/null +++ b/chrony-logfile-html.lsp @@ -0,0 +1,31 @@ +<? local form = ... ?> +<? +require("viewfunctions") +?> + +<H1>SYSTEM INFO</H1> +<DL> +<? +local myform = form.status +local tags = { "status", "version", "autostart", } +displayinfo(myform,tags,"viewonly") +?> +</DL> + +<form name="myform" action="" method="POST"> +<h1>LOGFILE</h1> +<h2>Details</h2> +<DL> +<? +local myform = form.logfile +local tags = { "filename", "filesize", "mtime", "sumerrors", } +displayinfo(myform,tags,"viewonly") +?> +</DL> + +<H3>FILE CONTENT</H3> +<? +io.write(html.form[myform.filecontent.type](myform.filecontent)) +?> + +</form> diff --git a/chrony-model.lua b/chrony-model.lua new file mode 100644 index 0000000..7ed494f --- /dev/null +++ b/chrony-model.lua @@ -0,0 +1,163 @@ +module(..., package.seeall) + +-- Load libraries +require("fs") +require("procps") +require("getopts") +require("format") +require("posix") +require("daemoncontrol") +require("validator") +require("socket") +require("processinfo") + +-- Set variables +local configfile = "/etc/chrony/chrony.conf" +local processname = "chrony" +local packagename = "chrony" +local baseurl = "/etc/chrony" +local descr = { +} + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function process_status_text(procname) + local t = procps.pidof(procname) + if (t) and (#t > 0) then + return "Enabled" + else + return "Disabled" + end +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function startstop_service ( self, action ) + local cmd = action.value + local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd) + action.descr=cmdmessage + action.errtxt=cmderror + return cmdresult,action +end + +function getstatus() + local status = {} + + local value, errtxt = processinfo.package_version(packagename) + status.version = cfe({ name = "version", + label="Program version", + value=value, + errtxt=errtxt, + }) + + status.status = cfe({ name="status", + label="Program status", + value=process_status_text(processname), + }) + + local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) + status.autostart = cfe({ name="autostart", + label="Autostart sequence", + value=autostart_sequense, + errtxt=autostart_errtxt, + }) + + return status +end + +function get_logfile () + local file = {} + local cmdtxt = "cat /var/log/messages | grep " .. processname + local cmd, error = io.popen(cmdtxt ,r) + local cmdoutput = cmd:read("*a") + cmd:close() + + file["filename"] = cfe({ + name="filename", + label="File name", + value=cmdtxt, + }) + + file["filecontent"] = cfe({ + type="longtext", + name="filecontent", + label="File content", + value=cmdoutput, + }) + + return file +end + +function getconfig() + local config = {} + return config +end + +function get_filedetails(self,num) + local path + if (num == "2") then + path = configfile2 + else + path = configfile + end + local file = {} + local filedetails = {} + local config = {} + local filenameerrtxt + if (path) and (fs.is_file(path)) then + filedetails = fs.stat(path) + config = getconfig(path) + else + config = {} + config.filename = {} + config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" + end + + file["filename" .. (num or "")] = cfe({ + name="filename" .. (num or ""), + label="File name", + value=path, + errtxt=filenameerrtxt + }) + file["filesize" .. (num or "")] = cfe({ + name="filesize" .. (num or ""), + label="File size", + value=filedetails.size or 0, + }) + file["mtime" .. (num or "")] = cfe({ + name="mtime" .. (num or ""), + label="File date", + value=filedetails.mtime or "---", + }) + file["filecontent" .. (num or "")] = cfe({ + type="longtext", + name="filecontent" .. (num or ""), + label="File content", + value=fs.read_file(path), + }) + + -- Sum all errors into one cfe + local sumerrors = "" + for k,v in pairs(config) do + if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then + sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" + end + end + if (sumerrors ~= "") then + file["sumerrors" .. (num or "")] = cfe ({ + name="sumerrors" .. (num or ""), + label = "Configuration errors", + errtxt = string.match(sumerrors, "(.-)\n$"), + }) + end + + return file +end +function update_filecontent (self, modifications) + local path = configfile + local file_result,err = fs.write_file(path, format.dostounix(modifications)) + return file_result +end + diff --git a/chrony-status-html.lsp b/chrony-status-html.lsp new file mode 100644 index 0000000..2063b8a --- /dev/null +++ b/chrony-status-html.lsp @@ -0,0 +1,24 @@ +<? local form = ... +require("viewfunctions") +?> +<? +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +?> + +<H1>SYSTEM INFO</H1> +<DL> +<? +local myform = form.status +local tags = { "status", "version", "autostart", } +displayinfo(myform,tags,"viewonly") +?> +</DL> + +<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> +<DL> + +</DL> diff --git a/chrony.menu b/chrony.menu new file mode 100644 index 0000000..f49ad36 --- /dev/null +++ b/chrony.menu @@ -0,0 +1,5 @@ +#CAT GROUP/DESC TAB ACTION +Networking 20NTP(chrony) Status status +Networking 46NTP(chrony) Expert expert +Networking 46NTP(chrony) Logfile logfile + diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..45f4d21 --- /dev/null +++ b/config.mk @@ -0,0 +1,10 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions |