From 9fcda9ad78f8c42ed291c10e8bfea3e3000c30a3 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 4 Jul 2008 13:35:07 +0000 Subject: 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 --- alpine-baselayout.roles | 2 +- syslog-basicstatus-html.lsp | 13 --------- syslog-config-html.lsp | 28 ++++++-------------- syslog-controller.lua | 64 +++++---------------------------------------- syslog-expert-html.lsp | 54 +------------------------------------- syslog-loginfo-html.lsp | 23 ++++++++++++++++ syslog-model.lua | 61 ++++++++++++------------------------------ syslog-startstop-html.lsp | 27 +------------------ syslog-status-html.lsp | 24 +---------------- syslog.menu | 2 +- 10 files changed, 59 insertions(+), 239 deletions(-) delete mode 100644 syslog-basicstatus-html.lsp mode change 100644 => 120000 syslog-expert-html.lsp create mode 100644 syslog-loginfo-html.lsp mode change 100644 => 120000 syslog-startstop-html.lsp mode change 100644 => 120000 syslog-status-html.lsp 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 @@ - - - - -

SYSTEM INFO

-
- -
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 @@ DEBUGGING

DEBUG INFO: CFE

") +io.write("

Debugging

Debug Info:

") io.write(html.cfe_unpack(form)) io.write("
") --]] ?> - - -

CONFIGURATION

+

Configuration

") ?>

") ?>

-

ADVANCED CONFIGURATION

-

GENERAL

+

Advanced Configuration

+

General

displayformitem(form.value.smallerlogs, "smallerlogs") ?>
-

LOGROTATE

+

Log Rotate

-

REMOTE LOGGING

+

Remote Logging

-

SAVE AND APPLY ABOVE SETTINGS

+

Save and Apply Above Settings

Save/Apply above settings
- - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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 deleted file mode 100644 index c8832a8..0000000 --- a/syslog-expert-html.lsp +++ /dev/null @@ -1,53 +0,0 @@ - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - - - - - -

CONFIGURATION

-

EXPERT CONFIGURATION

-

FILE DETAILS

-
- -
- -

FILE CONTENT

-

") ?>

-

") ?>

-
- -

") ?>

- -

SAVE AND APPLY ABOVE SETTINGS

-
Save/Apply above settings
-
- - - - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/syslog-expert-html.lsp @@ -0,0 +1 @@ +../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 @@ + + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + + + + + +

Program Specific Options/Information

+
+ +
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 deleted file mode 100644 index f3f7013..0000000 --- a/syslog-startstop-html.lsp +++ /dev/null @@ -1,26 +0,0 @@ - - - -

MANAGEMENT

-
-
-
Program control-panel
-
-> -> -> -
-
- - -
Previous action result
-
- -

") ?>

- -

") ?>

- -
-
diff --git a/syslog-startstop-html.lsp b/syslog-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/syslog-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp deleted file mode 100644 index f68147d..0000000 --- a/syslog-status-html.lsp +++ /dev/null @@ -1,23 +0,0 @@ - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - - - - - -

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
- -
diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/syslog-status-html.lsp @@ -0,0 +1 @@ +../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 -- cgit v1.2.3