diff options
-rw-r--r-- | syslog-config-html.lsp | 74 | ||||
-rw-r--r-- | syslog-controller.lua | 16 | ||||
-rw-r--r-- | syslog-model.lua | 19 |
3 files changed, 67 insertions, 42 deletions
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index 174cb5d..8c7c111 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -18,29 +18,32 @@ <H2>Advanced config</H2> <H3>General settings</H3> <DL> - <DT<? if (view.errors) and (view.errors.LBU_MEDIA) then io.write("class='error'") end ?>>Log to given file</DT> - <DD><input type="text" class="text" name="logfile" value="<?= view.config["SYSLOGD_OPTS"]["-O"] ?>"/> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-O"]) then io.write("<p class='error'>", view.errors["SYSLOGD_OPTS"]["-O"] ,"</p>") end ?> + <? var = "-O" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Log to given file</DT> + <DD><input type="text" class="text" name="<?= var ?>" value="<?= view.config["SYSLOGD_OPTS"][var] ?>"/> + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("<p class='error'>", view.errors["SYSLOGD_OPTS"]["-O"] ,"</p>") end ?> </DD> - <DT>Set local log level</DT> + <? var = "-l" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Set local log level</DT> <DD> <? for i=1, table.maxn(view.config["SYSLOGD_OPTS"]["-l_list"]) do ?> - <input class="radio" type="radio" name="loglevel" value="1" - <? if (tostring(view.config["SYSLOGD_OPTS"]["-l_list"][i]) == tostring(view.config["SYSLOGD_OPTS"]["-l"])) + <input class="radio" type="radio" name="<?= var ?>" value="<?= i ?>" + <? if (tostring(view.config["SYSLOGD_OPTS"]["-l_list"][i]) == tostring(view.config["SYSLOGD_OPTS"][var])) then io.write('checked=yes') end ?>> <?= view.config["SYSLOGD_OPTS"]["-l_list"][i] ?> <? end ?> <p>(1=Quiet, ... , <?= table.maxn(view.config["SYSLOGD_OPTS"]["-l_list"]) ?>=Debug)</p> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-l"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-l"] ,"</p>") + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> - <DT>Smaller logging output</DT> - <DD><input type="checkbox" name="smallog" <? if (view.config["SYSLOGD_OPTS"]["-S"]) then io.write('checked=yes') end ?> /> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-S"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-S"] ,"</p>") + <? var = "-S" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Smaller logging output</DT> + <DD><input type="checkbox" name="<?= var ?>" <? if (view.config["SYSLOGD_OPTS"][var]) then io.write('checked=yes') end ?> /> + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> </DL> @@ -48,43 +51,42 @@ <H3>Save logs for a longer period</H3> <DL> - <DT>Max size (KB) before rotate</DT> - <DD><input type="text" class="text" name="maxsize" value="<?= view.config["SYSLOGD_OPTS"]["-s"] ?>"/> + <? var = "-s" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Max size (KB) before rotate</DT> + <DD><input type="text" class="text" name="<?= var ?>" value="<?= view.config["SYSLOGD_OPTS"][var] ?>"/> <p>(default=200KB, 0=off)</p> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-s"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-s"] ,"</p>") + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> - <DT>Number of rotated logs to keep</DT> - <DD><input type="text" class="text" name="logrotate" value="<?= view.config["SYSLOGD_OPTS"]["-b"] ?>"/> + <? var = "-b" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Number of rotated logs to keep</DT> + <DD><input type="text" class="text" name="<?= var ?>" value="<?= view.config["SYSLOGD_OPTS"][var] ?>"/> <p>(default=1, max=99, 0=purge)</p> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-b"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-b"] ,"</p>") + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> </DL> <H3>Remote logging</H3> <DL> - <DT>Activate remote logging</DT> - <DD><input type="checkbox" name="remotelogging" <? if (view.config["SYSLOGD_OPTS"]["-R"] ~= "") then io.write('checked=yes') end ?> /> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-R"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-R"] ,"</p>") - end ?> - </DD> - <DT>Log locally and via network</DT> - <DD><input type="checkbox" name="smallog" <? if (view.config["SYSLOGD_OPTS"]["-L"]) then io.write('checked=yes') end ?> /> + <? var = "-L" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Log locally and via network</DT> + <DD><input type="checkbox" name="<?= var ?>" <? if (view.config["SYSLOGD_OPTS"][var]) then io.write('checked=yes') end ?> /> <P>(default is network only if you have defined remote-logging)</p> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-L"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-L"] ,"</p>") + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> - <DT>Log to IP or hostname on PORT</DT> - <DD><input type="text" class="text" name="host" value="<?= view.config["SYSLOGD_OPTS"]["-R"] ?>"/> - <P>HOST[:PORT] (default PORT=514/UDP)</P> - <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"]["-R"]) then - io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"]["-R"] ,"</p>") + + <? var = "-R" ?> + <DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Log to IP or hostname on PORT</DT> + <DD><input type="text" class="text" name="<?= var ?>" value="<?= view.config["SYSLOGD_OPTS"][var] ?>"/> + <P>(Empty=No remote logging) HOST[:PORT] (default PORT=514/UDP)</P> + <? if (view.errors["SYSLOGD_OPTS"]) and (view.errors["SYSLOGD_OPTS"][var]) then + io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>") end ?> </DD> @@ -94,7 +96,7 @@ <H2>Save and apply above settings</H2> <DL> <DT>Apply settings</DT> - <DD><input class="submit" type="submit" name="cmdsave" value="Apply" disabled/></DD> + <DD><input class="submit" type="submit" name="cmdsave" value="Apply" /></DD> </DL> </form> <H1>MANAGEMENT</H1> diff --git a/syslog-controller.lua b/syslog-controller.lua index 89e41c0..553b765 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -18,13 +18,19 @@ function status(self) end function config(self) - + local cmdresult = {} + local cmderrors = {} if ( self.clientdata.cmddaemon) then startstop = self.model:startstop_service( self.clientdata.cmddaemon ) end --- if ( self.clientdata.cmdsave) then --- modifications = self.model:update_filecontent(modifications) --- end + if ( self.clientdata.cmdsave) then + local variables="-O -l -S -s -b -L -R" + for var in string.gmatch(variables, "%S+") do + -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset + if (self.clientdata[var] == "") then self.clientdata[var] = nil end + cmdresult[var],cmderrors[var] = self.model:setconfigs("SYSLOGD_OPTS",var,self.clientdata[var]) + end + end local status = self.model.getstatus() local config, errors = self.model.getconfig() @@ -34,8 +40,10 @@ function config(self) status = status, startstop = startstop, clientdata = self.clientdata, + cmdresult = cmdresult, config = config, errors = errors, + cmderrors = cmderrors, url = url, } end diff --git a/syslog-model.lua b/syslog-model.lua index a2a6eb2..f8563fc 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -71,6 +71,9 @@ function getconfig() errors["configfile"] = "Config file '".. configfile .. "' is missing!" end -- Next section is to set/show default values when a option is not configured in the configfile + if not (config["SYSLOGD_OPTS"]) then + config["SYSLOGD_OPTS"] = {} + end config["SYSLOGD_OPTS"]["-O"] = config["SYSLOGD_OPTS"]["-O"] or "/var/log/messages" config["SYSLOGD_OPTS"]["-l_list"] = getloglevels() config["SYSLOGD_OPTS"]["-R"] = config["SYSLOGD_OPTS"]["-R"] or "" @@ -83,6 +86,9 @@ function getconfig() else config["SYSLOGD_OPTS"]["-l"] = config["SYSLOGD_OPTS"]["-l"] or 8 end + if (config["SYSLOGD_OPTS"]["-L"] ~= nil) and (config["SYSLOGD_OPTS"]["-R"] == "") then + errors["SYSLOGD_OPTS"]["-L"] = "Logging to local and network is possible unless you define a host for remote logging." + end return config, errors end @@ -106,9 +112,18 @@ service_control = function ( self, srvcmd ) return retval end -function setconfigs(self,value) - --TODO: Validate so that user cant add values with '-' +function setconfigs(self,variable,parameter,value) + --TODO: Validate so that user cant add values with '-' (could cause major breakage next time you do getopts) + --If file is missing... then create a new one +-- if not (fs.is_file(configfile)) then fs.write_file(configfile, "SYSLOGD_OPTS=\"\"\nKLOGD_OPTS=\"\"") end + if not (variable) or not (parameter) then return nil, "Usage setconfigs(variable,parameter,value)" end + if not (string.find(parameter, "-%a$")) then return nil, "Parameter must be formated '-a' (where a is one upper/lowercase letter [a-z])" end + -- Set specific variables (and their values + if (value) and ((parameter == "-S") or (parameter == "-L")) then value = "" end + local retval, errors = getopts.setoptsinfile(configfile,variable,parameter,value) + return retval, errors end + function update_filecontent (self, modifications) local path = configfile local file_result,err = fs.write_file(path, format.dostounix(modifications)) |