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-model.lua | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'syslog-model.lua') 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