diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-05-15 21:00:31 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-05-15 21:00:31 +0000 |
commit | 95498147f492908372796c6e084a245007f25bc3 (patch) | |
tree | ac22809ac3045862e6abd4c488f9022bd5b8f63f | |
parent | d8afa977ce3587ee2819c44d545753aa0cc38760 (diff) | |
download | acf-alpine-baselayout-95498147f492908372796c6e084a245007f25bc3.tar.bz2 acf-alpine-baselayout-95498147f492908372796c6e084a245007f25bc3.tar.xz |
Added validation to syslog expert page.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1123 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | syslog-model.lua | 114 |
1 files changed, 70 insertions, 44 deletions
diff --git a/syslog-model.lua b/syslog-model.lua index c105dd4..3a8ffa5 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -55,6 +55,52 @@ local writeconfig = function (config) return cmdmessage, cmderror end +local makeconfig = function(configcontent) + local config = {} + configcontent = configcontent or {} + -- Next section selects which configurations we should show to the user + config["logfile"] = cfe({ + label = "Log to given file", + descr = "File must be in /var/log directory", + value = configcontent["-O"] or "/var/log/messages", + }) + config["loglevel"] = cfe({ + label = "Set local log level", + value = configcontent["-l"] or "8", + type = "select", + option = getloglevels(), + descr = "1=Quiet, ... , " .. table.maxn(getloglevels()) .. "=Debug", + }) + config["smallerlogs"] = cfe({ + label = "Smaller logging output", + value = (configcontent["-S"] == ""), + type = "boolean", + }) + config["maxsize"] = cfe ({ + label = "Max size (KB) before rotate", + descr = "Default=200KB, 0=off", + value = configcontent["-s"] or "", + }) + config["numrotate"] = cfe ({ + label = "Number of rotated logs to keep", + descr = "Default=1, max=99, 0=purge", + value = configcontent["-b"] or "", + }) + config["localandnetworklog"] = cfe ({ + label = "Log locally and via network", + value = (configcontent["-L"] == ""), + type = "boolean", + descr = "Default is network only if host[:PORT] is defined", + }) + config["remotelogging"] = cfe ({ + label = "Log to IP or hostname on PORT", + descr = "host[:PORT] - Default PORT=514/UDP", + value = configcontent["-R"] or "", + }) + + return cfe({ type="group", value=config, label="Configuration" }) +end + local validateconfig = function(config) local success = true -- Validate entries and create error strings @@ -163,51 +209,14 @@ end function getconfig() local config = {} if (fs.is_file(configfile)) then - configcontent = getopts.getoptsfromfile(configfile, "", "SYSLOGD_OPTS", true) or {} + local configcontent = getopts.getoptsfromfile(configfile, "", "SYSLOGD_OPTS", true) or {} + config = makeconfig(configcontent) else + config = makeconfig() config["errtxt"] = "Config file '".. configfile .. "' is missing!" end - -- Next section selects which configurations we should show to the user - config["logfile"] = cfe({ - label = "Log to given file", - descr = "File must be in /var/log directory", - value = configcontent["-O"] or "/var/log/messages", - }) - config["loglevel"] = cfe({ - label = "Set local log level", - value = configcontent["-l"] or "8", - type = "select", - option = getloglevels(), - descr = "1=Quiet, ... , " .. table.maxn(getloglevels()) .. "=Debug", - }) - config["smallerlogs"] = cfe({ - label = "Smaller logging output", - value = (configcontent["-S"] == ""), - type = "boolean", - }) - config["maxsize"] = cfe ({ - label = "Max size (KB) before rotate", - descr = "Default=200KB, 0=off", - value = configcontent["-s"] or "", - }) - config["numrotate"] = cfe ({ - label = "Number of rotated logs to keep", - descr = "Default=1, max=99, 0=purge", - value = configcontent["-b"] or "", - }) - config["localandnetworklog"] = cfe ({ - label = "Log locally and via network", - value = (configcontent["-L"] == ""), - type = "boolean", - descr = "Default is network only if host[:PORT] is defined", - }) - config["remotelogging"] = cfe ({ - label = "Log to IP or hostname on PORT", - descr = "host[:PORT] - Default PORT=514/UDP", - value = configcontent["-R"] or "", - }) - return cfe({ type="group", value=config, label="Configuration" }) + return config end function updateconfig (clientdata) @@ -233,8 +242,25 @@ function updateconfig (clientdata) end function update_filecontent (self, modifications) - -- FIXME add validation before writing - fs.write_file(configfile, format.dostounix(modifications)) - return get_filedetails() + -- Validation before writing + local configcontent = getopts.getoptsfromfile(format.dostounix(modifications), "", "SYSLOGD_OPTS", true) or {} + local config = makeconfig(configcontent) + local success + 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!" } + 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 + end end |