summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-09-22 21:02:48 +0000
committerTed Trask <ttrask01@yahoo.com>2008-09-22 21:02:48 +0000
commitda850749abcdb675610d4c9805bdf3efaa764de8 (patch)
treedd97f2a3b8121dc552a60259244b32818800ac82
parente1b24fbcaf560a158f5dc99e4ea5debf9bdaf38f (diff)
downloadacf-chrony-da850749abcdb675610d4c9805bdf3efaa764de8.tar.bz2
acf-chrony-da850749abcdb675610d4c9805bdf3efaa764de8.tar.xz
Update of chrony to use new libraries and standard lsp files.
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1482 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--chrony-controller.lua114
l---------[-rw-r--r--]chrony-expert-html.lsp59
-rw-r--r--chrony-logfile-html.lsp32
-rw-r--r--chrony-model.lua154
l---------chrony-startstop-html.lsp1
l---------[-rw-r--r--]chrony-status-html.lsp29
-rw-r--r--chrony-time-html.lsp17
-rw-r--r--chrony.menu2
-rw-r--r--chrony.roles4
9 files changed, 49 insertions, 363 deletions
diff --git a/chrony-controller.lua b/chrony-controller.lua
index 0cc4d92..5cc1b1b 100644
--- a/chrony-controller.lua
+++ b/chrony-controller.lua
@@ -1,117 +1,21 @@
module(..., package.seeall)
--- Load libraries
-require("format")
-
--- Set variables
-local newrecordtxt = "[New]"
-
--- ################################################################################
--- LOCAL FUNCTIONS
-
-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",
- })
-
- -- 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
+require("controllerfunctions")
default_action = "status"
function status(self)
- return { status=self.model.getstatus() }
+ return 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 = self.conf.script .. 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, } )
+function startstop(self)
+ return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)
end
-function logfile(self)
-
- local status=self.model.getstatus()
- local logfile = self.model:get_logfile()
+function expert(self)
+ return controllerfunctions.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit Config File", "Configuration Set")
+end
- return ({
- status = status,
- logfile = logfile,
- url = url,
- })
+function time(self)
+ return self.model.gettime()
end
diff --git a/chrony-expert-html.lsp b/chrony-expert-html.lsp
index 78ec15d..207f324 100644..120000
--- a/chrony-expert-html.lsp
+++ b/chrony-expert-html.lsp
@@ -1,58 +1 @@
-<% 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>
-
+../expert-html.lsp \ No newline at end of file
diff --git a/chrony-logfile-html.lsp b/chrony-logfile-html.lsp
index f3d889e..24991da 100644
--- a/chrony-logfile-html.lsp
+++ b/chrony-logfile-html.lsp
@@ -1,31 +1,7 @@
-<% local form = ... %>
-<%
+<% local data, viewlibrary = ...
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>
+<% if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {name="/var/log/messages", grep="chronyd"})
+end %>
diff --git a/chrony-model.lua b/chrony-model.lua
index 0996463..33cec37 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -1,167 +1,39 @@
module(..., package.seeall)
-- Load libraries
-require("fs")
-require("procps")
-require("format")
-require("posix")
-require("daemoncontrol")
-require("validator")
-require("processinfo")
+require("modelfunctions")
-- Set variables
local configfile = "/etc/chrony/chrony.conf"
local processname = "chronyd"
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
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, 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,
- })
-
- status.date = cfe({
- name = "date",
- label="Current time",
- value=os.date(),
- })
-
- return status
+ return modelfunctions.getstatus(processname, packagename, "Chrony Status")
end
-function get_logfile ()
- local file = {}
- local cmdtxt = "grep ".. processname .. " /var/log/messages"
- 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
+function gettime()
+ return cfe({ value=os.date(), label="Current time" })
end
-function getconfig()
- local config = {}
- return config
+function get_filedetails()
+ -- FIXME validate
+ return modelfunctions.getfiledetails(configfile)
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
+function update_filedetails(filedetails)
+ -- FIXME validate
+ filedetails.value.filename.value = configfile
+ return modelfunctions.setfiledetails(filedetails)
end
diff --git a/chrony-startstop-html.lsp b/chrony-startstop-html.lsp
new file mode 120000
index 0000000..0ea2627
--- /dev/null
+++ b/chrony-startstop-html.lsp
@@ -0,0 +1 @@
+../startstop-html.lsp \ No newline at end of file
diff --git a/chrony-status-html.lsp b/chrony-status-html.lsp
index ebd2052..b2f8480 100644..120000
--- a/chrony-status-html.lsp
+++ b/chrony-status-html.lsp
@@ -1,28 +1 @@
-<% 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>
-<%
-local myform = form.status
-local tags = { "date", }
-displayinfo(myform,tags,"viewonly")
-%>
-</DL>
+../status-html.lsp \ No newline at end of file
diff --git a/chrony-time-html.lsp b/chrony-time-html.lsp
new file mode 100644
index 0000000..24a3245
--- /dev/null
+++ b/chrony-time-html.lsp
@@ -0,0 +1,17 @@
+<% local data, viewlibrary = ...
+require("viewfunctions")
+%>
+<%
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(data))
+io.write("</span>")
+--]]
+%>
+
+<% viewlibrary.dispatch_component("status") %>
+
+<H2><%= data.label %></H2>
+<DL>
+<% displayitem(data) %>
+</DL>
diff --git a/chrony.menu b/chrony.menu
index f49ad36..56a9f5f 100644
--- a/chrony.menu
+++ b/chrony.menu
@@ -1,5 +1,5 @@
#CAT GROUP/DESC TAB ACTION
-Networking 20NTP(chrony) Status status
+Networking 20NTP(chrony) Status time
Networking 46NTP(chrony) Expert expert
Networking 46NTP(chrony) Logfile logfile
diff --git a/chrony.roles b/chrony.roles
index 1741e87..e6c0a42 100644
--- a/chrony.roles
+++ b/chrony.roles
@@ -1,2 +1,2 @@
-READ=chrony:status,chrony:logfile
-UPDATE=chrony:expert
+READ=chrony:status,chrony:logfile,chrony:time
+UPDATE=chrony:expert,chrony:startstop