From 68c7979c8ed1628fee78b9c47214997e0c47f0e2 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 5 Jun 2008 17:41:22 +0000 Subject: Modified syslog to move clientdata processing from model to controller. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1201 ab2d0c66-481e-0410-8bed-d214d4d58bed --- syslog-controller.lua | 31 +++++++++++++++++++++---------- syslog-expert-html.lsp | 1 + syslog-model.lua | 29 +++++++++-------------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/syslog-controller.lua b/syslog-controller.lua index 48e7b56..12a7929 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -7,11 +7,19 @@ function status(self) end function config(self) - local config + local config = self.model.getconfig() if self.clientdata.Save then - config = self.model.updateconfig(self.clientdata) - else - config = self.model.getconfig() + 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" @@ -23,15 +31,18 @@ end function expert(self) -- Save changes - local config - local modifications = self.clientdata.filecontent or "" + local config = self.model.get_filedetails() if self.clientdata.Save then - config = self.model:update_filecontent(modifications) - if not config.errtxt 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 - else - config = self.model:get_filedetails() end config.type = "form" diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp index be57b96..c8832a8 100644 --- a/syslog-expert-html.lsp +++ b/syslog-expert-html.lsp @@ -32,6 +32,7 @@ displayitem(form.value.mtime) +

") ?>

SAVE AND APPLY ABOVE SETTINGS

Save/Apply above settings
diff --git a/syslog-model.lua b/syslog-model.lua index 3a8ffa5..3d50031 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -137,8 +137,9 @@ 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=action.." result" }) + return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label="Start/Stop result" }) end function getversion() @@ -219,17 +220,8 @@ function getconfig() return config end -function updateconfig (clientdata) - local config = getconfig() +function updateconfig (config) local success = true - for name in pairs(config.value) do - if config.value[name].type == "boolean" then - config.value[name].value = (clientdata[name] == "true") - elseif clientdata[name] then - config.value[name].value = clientdata[name] - end - end - success, config = validateconfig(config) if success == true then @@ -241,26 +233,23 @@ function updateconfig (clientdata) return config end -function update_filecontent (self, modifications) +function update_filecontent (modifications) -- Validation before writing local configcontent = getopts.getoptsfromfile(format.dostounix(modifications), "", "SYSLOGD_OPTS", true) or {} local config = makeconfig(configcontent) - local success + local success, errtxt success, config = validateconfig(config) if success == true then fs.write_file(configfile, format.dostounix(modifications)) - return get_filedetails() else - local details = get_filedetails() - details.value.filecontent.value = modifications - local errormessages = { "Failed to save config!" } + local errormessages = {} for x,y in pairs(config.value) do if y.errtxt then errormessages[#errormessages + 1] = y.label .. " - " .. y.errtxt end end - details.errtxt = table.concat(errormessages, "\n") - return details + errtxt = table.concat(errormessages, "\n") end -end + return cfe({ type="boolean", value=success, errtxt=errtxt, label="Update filecontent result" }) +end -- cgit v1.2.3