summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--syslog-controller.lua31
-rw-r--r--syslog-expert-html.lsp1
-rw-r--r--syslog-model.lua29
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)
<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>
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