summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-07-04 13:35:07 +0000
committerTed Trask <ttrask01@yahoo.com>2008-07-04 13:35:07 +0000
commit9fcda9ad78f8c42ed291c10e8bfea3e3000c30a3 (patch)
tree82e16c3a24e531d759062933e3dcaa714ccfcbd9
parent32d91ea7a92c5edee22900e8da1cafda058ca400 (diff)
downloadacf-alpine-baselayout-9fcda9ad78f8c42ed291c10e8bfea3e3000c30a3.tar.bz2
acf-alpine-baselayout-9fcda9ad78f8c42ed291c10e8bfea3e3000c30a3.tar.xz
Modified syslog to use controllerfunctions, modelfunctions, and common lsp files. Changed status->loginfo and basicstatus->status. Stopped expert from adding blank lines to the end.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1274 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--alpine-baselayout.roles2
-rw-r--r--syslog-basicstatus-html.lsp13
-rw-r--r--syslog-config-html.lsp28
-rw-r--r--syslog-controller.lua64
l---------[-rw-r--r--]syslog-expert-html.lsp54
-rw-r--r--syslog-loginfo-html.lsp23
-rw-r--r--syslog-model.lua61
l---------[-rw-r--r--]syslog-startstop-html.lsp27
l---------[-rw-r--r--]syslog-status-html.lsp24
-rw-r--r--syslog.menu2
10 files changed, 59 insertions, 239 deletions
diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles
index 9e0e086..a015e00 100644
--- a/alpine-baselayout.roles
+++ b/alpine-baselayout.roles
@@ -1,5 +1,5 @@
CREATE=interfaces:create,interfaces:editintfile
-READ=health:storage,health:proc,health:network,health:modules,interfaces:status,interfaces:read,logfiles:status,logfiles:view,logfiles:download,syslog:status,syslog:basicstatus
+READ=health:storage,health:proc,health:network,health:modules,interfaces:status,interfaces:read,logfiles:status,logfiles:view,logfiles:download,syslog:status,syslog:loginfo
UPDATE=interfaces:update,interfaces:ifup,interfaces:ifdown,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert
DELETE=interfaces:delete,logfiles:delete
ALL=health:system,hostname:read
diff --git a/syslog-basicstatus-html.lsp b/syslog-basicstatus-html.lsp
deleted file mode 100644
index cf1e789..0000000
--- a/syslog-basicstatus-html.lsp
+++ /dev/null
@@ -1,13 +0,0 @@
-<? local data = ... ?>
-<? require("viewfunctions") ?>
-<? --[[
-io.write(html.cfe_unpack(data))
---]] ?>
-
-<H1>SYSTEM INFO</H1>
-<DL>
-<?
-displayitem(data.value.status)
-displayitem(data.value.version)
-?>
-</DL>
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp
index 03a7b4a..5d4061f 100644
--- a/syslog-config-html.lsp
+++ b/syslog-config-html.lsp
@@ -2,24 +2,22 @@
<? require("viewfunctions") ?>
<?
--[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write("<H1>Debugging</H1><span style='color:red'><H2>Debug Info:</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")
--]]
?>
-<? ---[[ ?>
<? if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("basicstatus")
+ viewlibrary.dispatch_component("status")
end ?>
-<? --]] ?>
-<H1>CONFIGURATION</H1>
+<H1>Configuration</H1>
<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?>
<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?>
<form action="" method="POST">
-<H2>ADVANCED CONFIGURATION</H2>
-<H3>GENERAL</H3>
+<H2>Advanced Configuration</H2>
+<H3>General</H3>
<DL>
<?
displayformitem(form.value.logfile, "logfile")
@@ -27,35 +25,25 @@ end ?>
displayformitem(form.value.smallerlogs, "smallerlogs")
?>
</DL>
-<H3>LOGROTATE</H3>
+<H3>Log Rotate</H3>
<DL>
<?
displayformitem(form.value.maxsize, "maxsize")
displayformitem(form.value.numrotate, "numrotate")
?>
</DL>
-<H3>REMOTE LOGGING</H3>
+<H3>Remote Logging</H3>
<DL>
<?
displayformitem(form.value.localandnetworklog, "localandnetworklog")
displayformitem(form.value.remotelogging, "remotelogging")
?>
</DL>
-<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
+<H2>Save and Apply Above Settings</H2>
<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL>
</form>
-<? ---[[ ?>
<? if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("startstop")
end
?>
-<? --]] ?>
-
-<?
---[[ 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>")
---]]
-?>
diff --git a/syslog-controller.lua b/syslog-controller.lua
index 12a7929..5bd65c4 100644
--- a/syslog-controller.lua
+++ b/syslog-controller.lua
@@ -1,75 +1,25 @@
module(..., package.seeall)
+require("controllerfunctions")
-default_action = "status"
+default_action = "loginfo"
-function status(self)
+function loginfo(self)
return self.model.getlogging()
end
function config(self)
- local config = self.model.getconfig()
- if self.clientdata.Save then
- for name,value in pairs(config.value) do
- if value.type == "boolean" then
- value.value = (self.clientdata[name] ~= nil)
- elseif clientdata[name] then
- value.value = clientdata[name]
- end
- end
- config = self.model.updateconfig(config)
- if not config.errtxt then
- config.descr = "Saved config"
- end
- end
-
- config.type = "form"
- config.label = "Edit config"
- config.option = "Save"
-
- return config
+ return controllerfunctions.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit config", "Configuration Set")
end
function expert(self)
- -- Save changes
- local config = self.model.get_filedetails()
- if self.clientdata.Save then
- local modifications = self.clientdata.filecontent or ""
- local result = self.model.update_filecontent(modifications)
- if not result.value then
- config.value.filecontent.value = modifications
- config.value.filecontent.errtxt = result.errtxt
- config.errtxt = "Failed to save config!"
- else
- config = self.model.get_filedetails()
- config.descr = "Saved File"
- end
- end
-
- config.type = "form"
- config.label = "Edit config"
- config.option = "Save"
-
- return config
+ return controllerfunctions.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit config", "Configuration Set")
end
function startstop(self)
- local result
- if self.clientdata.action then
- result = self.model:startstop_service(self.clientdata.action)
- self.sessiondata.syslogstartstopresult = result
- self.redirect_to_referrer(self)
- end
-
- local status = self.model.getstatus()
- if self.sessiondata.syslogstartstopresult then
- result = self.sessiondata.syslogstartstopresult
- self.sessiondata.syslogstartstopresult = nil
- end
-
- return cfe({ type="group", value={status=status, result=result} })
+ return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)
end
-function basicstatus(self)
+function status(self)
status = self.model.getstatus()
version = self.model.getversion()
return cfe({ type="group", value={status=status, version=version} })
diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp
index c8832a8..207f324 100644..120000
--- a/syslog-expert-html.lsp
+++ b/syslog-expert-html.lsp
@@ -1,53 +1 @@
-<? local form, viewlibrary = ... ?>
-<? 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>")
---]]
-?>
-
-<? ---[[ ?>
-<? if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("basicstatus")
-end ?>
-<? --]] ?>
-
-<H1>CONFIGURATION</H1>
-<H2>EXPERT CONFIGURATION</H2>
-<H3>FILE DETAILS</H3>
-<DL>
-<?
-displayitem(form.value.filename)
-displayitem(form.value.filesize)
-displayitem(form.value.mtime)
-?>
-</DL>
-
-<H3>FILE CONTENT</H3>
-<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?>
-<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?>
-<form action="" method="POST">
-<textarea name="filecontent">
-<?= form.value.filecontent.value ?>
-</textarea>
-<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?>
-
-<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
-<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL>
-</form>
-
-<? ---[[ ?>
-<? if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("startstop")
-end ?>
-<? --]] ?>
-
-<?
---[[ 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>")
---]]
-?>
+../expert-html.lsp \ No newline at end of file
diff --git a/syslog-loginfo-html.lsp b/syslog-loginfo-html.lsp
new file mode 100644
index 0000000..a0b8c38
--- /dev/null
+++ b/syslog-loginfo-html.lsp
@@ -0,0 +1,23 @@
+<? local form, viewlibrary = ... ?>
+<? 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>")
+--]]
+?>
+
+<? ---[[ ?>
+<? if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("status")
+end ?>
+<? --]] ?>
+
+<H2>Program Specific Options/Information</H2>
+<DL>
+<?
+displayitem(form.value.logfile)
+displayitem(form.value.remote)
+?>
+</DL>
diff --git a/syslog-model.lua b/syslog-model.lua
index 3d50031..273cc27 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -1,14 +1,14 @@
module(..., package.seeall)
+require("modelfunctions")
require("fs")
-require("procps")
require("getopts")
require("format")
-require("daemoncontrol")
require("validator")
local configfile = "/etc/conf.d/syslog"
-local processname = "syslog"
+local processinitname = "syslog"
+local processname = "syslogd"
local function get_version()
local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_version -v -s busybox | cut -d ' ' -f 1"
@@ -136,10 +136,8 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function startstop_service ( self, action )
- -- action is validated in daemoncontrol
- local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action)
- return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label="Start/Stop result" })
+function startstop_service(action)
+ return modelfunctions.startstop_service(processinitname, action)
end
function getversion()
@@ -150,16 +148,7 @@ function getversion()
end
function getstatus()
- local status = cfe({
- label="Program status",
- value=procps.pidof("syslogd"),
- })
- if (#status.value > 0) then
- status.value = "Enabled"
- else
- status.value = "Disabled"
- end
- return status
+ return modelfunctions.getenabled(processname)
end
function getlogging()
@@ -182,29 +171,7 @@ function getlogging()
end
function get_filedetails()
- local path = configfile
- local filedetails = fs.stat(path)
- local config = getconfig(path)
- local file = {}
- file["filename"] = cfe({
- label="File name",
- value=path,
- })
- file["filesize"] = cfe({
- label="File size",
- value=filedetails.size or "0",
- })
- file["mtime"] = cfe({
- label="File date",
- value=filedetails.mtime or "---",
- })
- file["filecontent"] = cfe({
- type="longtext",
- label="File content",
- value=fs.read_file(path),
- })
-
- return cfe({ type="group", value=file, label="Config file details" })
+ return modelfunctions.getfiledetails(configfile)
end
function getconfig()
@@ -233,14 +200,17 @@ function updateconfig (config)
return config
end
-function update_filecontent (modifications)
+function update_filedetails (filedetails)
-- Validation before writing
- local configcontent = getopts.getoptsfromfile(format.dostounix(modifications), "", "SYSLOGD_OPTS", true) or {}
+ filedetails.value.filecontent.value = format.dostounix(filedetails.value.filecontent.value)
+ filedetails.value.filecontent.value = filedetails.value.filecontent.value:gsub("\n+$", "")
+ local configcontent = getopts.getoptsfromfile(filedetails.value.filecontent.value, "", "SYSLOGD_OPTS", true) or {}
local config = makeconfig(configcontent)
local success, errtxt
success, config = validateconfig(config)
if success == true then
- fs.write_file(configfile, format.dostounix(modifications))
+ fs.write_file(configfile, filedetails.value.filecontent.value)
+ filedetails = get_filedetails()
else
local errormessages = {}
for x,y in pairs(config.value) do
@@ -248,8 +218,9 @@ function update_filecontent (modifications)
errormessages[#errormessages + 1] = y.label .. " - " .. y.errtxt
end
end
- errtxt = table.concat(errormessages, "\n")
+ filedetails.value.filecontent.errtxt = table.concat(errormessages, "\n")
+ filedetials.errtxt = "Failed to set configuration"
end
- return cfe({ type="boolean", value=success, errtxt=errtxt, label="Update filecontent result" })
+ return filedetails
end
diff --git a/syslog-startstop-html.lsp b/syslog-startstop-html.lsp
index f3f7013..0ea2627 100644..120000
--- a/syslog-startstop-html.lsp
+++ b/syslog-startstop-html.lsp
@@ -1,26 +1 @@
-<? local data = ... ?>
-<? --[[
-io.write(html.cfe_unpack(data))
---]] ?>
-
-<H1>MANAGEMENT</H1>
-<DL>
-<form action="startstop" method="POST">
-<DT>Program control-panel</DT>
-<DD>
-<input class="submit" type="submit" name="action" value="Start" <? if data.value.status.value== "Enabled" then io.write("disabled") end ?>>
-<input class="submit" type="submit" name="action" value="Stop" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>>
-<input class="submit" type="submit" name="action" value="Restart" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>>
-</DD>
-</form>
-
-<? if data.value.result then ?>
-<DT>Previous action result</DT>
-<DD>
-<? if data.value.result.descr then ?>
-<P CLASS='descr'><?= string.gsub(data.value.result.descr, "\n", "<BR>") ?></P>
-<? end if data.value.result.errtxt then ?>
-<P CLASS='error'><?= string.gsub(data.value.result.errtxt, "\n", "<BR>") ?></P>
-<? end end ?>
-</DD>
-</DL>
+../startstop-html.lsp \ No newline at end of file
diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp
index f68147d..b2f8480 100644..120000
--- a/syslog-status-html.lsp
+++ b/syslog-status-html.lsp
@@ -1,23 +1 @@
-<? local form, viewlibrary = ... ?>
-<? 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>")
---]]
-?>
-
-<? ---[[ ?>
-<? if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("basicstatus")
-end ?>
-<? --]] ?>
-
-<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
-<DL>
-<?
-displayitem(form.value.logfile)
-displayitem(form.value.remote)
-?>
-</DL>
+../status-html.lsp \ No newline at end of file
diff --git a/syslog.menu b/syslog.menu
index 32b138d..7be6ef4 100644
--- a/syslog.menu
+++ b/syslog.menu
@@ -1,4 +1,4 @@
#CAT GROUP/DESC TAB ACTION
-System 22System_Logging Status status
+System 22System_Logging Status loginfo
System 22System_Logging Config config
System 22System_Logging Expert expert