diff options
-rw-r--r-- | syslog-config-html.lsp | 110 | ||||
-rw-r--r-- | syslog-controller.lua | 44 | ||||
-rw-r--r-- | syslog-expert-html.lsp | 4 | ||||
-rw-r--r-- | syslog-model.lua | 165 | ||||
-rw-r--r-- | syslog-status-html.lsp | 28 |
5 files changed, 152 insertions, 199 deletions
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index f7aab7b..1167751 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -2,6 +2,7 @@ <h1>SYSTEM INFO</h1> + <DL> <dt>Program status</dt> <DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD> @@ -15,63 +16,78 @@ <H1>CONFIGURATION</H1> <H2>Advanced config</H2> <H3>General settings</H3> - -<DL> -<DT><?= view.config.logfile.label ?></DT> -<DD><input type="text" class="text" name="smallerlogg" value="<?= view.config.logfile.value ?>"/> -<P>(default=/var/log/messages)</P> -<p class="error"><?= view.config.logfile.errtxt ?></p> -</DD> -</DL> - -<DL> -<DT><?= view.config.loglevel.label ?></DT> -<DD><input class="radio" type="radio" name="loglevel" value="1" <? if (tostring(view.config.loglevel.value) == "1") then io.write('checked') end ?>>1 -<input class="radio" type="radio" name="loglevel" value="2" <? if (tostring(view.config.loglevel.value) == "2") then io.write('checked') end ?>>2 -<input class="radio" type="radio" name="loglevel" value="3" <? if (tostring(view.config.loglevel.value) == "3") then io.write('checked') end ?>>3 -<input class="radio" type="radio" name="loglevel" value="4" <? if (tostring(view.config.loglevel.value) == "4") then io.write('checked') end ?>>4 -<input class="radio" type="radio" name="loglevel" value="5" <? if (tostring(view.config.loglevel.value) == "5") then io.write('checked') end ?>>5 -<input class="radio" type="radio" name="loglevel" value="" <? if (tostring(view.config.loglevel.value) == "") then io.write('checked') end ?>>Default -<p><?= view.config.loglevel.helptxt ?></P> -<p class="error"><?= view.config.loglevel.errtxt ?></p></DD> -</DL> - <DL> -<DT><?= view.config.smallog.label ?></DT> -<DD><input type="checkbox" name="smallog" <? if (view.config.smallog.value ~= "") then io.write('checked') end ?>/><p class="error"><?= view.config.smallog.errtxt ?></p></DD> + <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="smallerlogg" 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 ?> + </DD> + + <DT>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"])) + 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>") + 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>") + end ?> + </DD> </DL> <H3>Save logs for a longer period</H3> -<DL> -<DT><?= view.config.maxsize.label ?></DT> -<DD><input type="text" class="text" name="maxsize" value="<?= view.config.maxsize.value ?>"/> -<p>(default=200KB, 0=off)</p> -<p class="error"><?= view.config.maxsize.errtxt ?></p> -</DD> -</DL> <DL> -<DT><?= view.config.logrotate.label ?></DT> -<DD><input type="text" class="text" name="logrotate" value="<?= view.config.logrotate.value ?>"/> -<p>(default=1, max=99, 0=purge)</p> -<p class="error"><?= view.config.logrotate.errtxt ?></p> -</DD> + <DT>Max size (KB) before rotate</DT> + <DD><input type="text" class="text" name="maxsize" value="<?= view.config["SYSLOGD_OPTS"]["-s"] ?>"/> + <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>") + end ?> + </DD> + + <DT>Number of rotated logs to keep</DT> + <DD><input type="text" class="text" name="logrotate" value="<?= view.config["SYSLOGD_OPTS"]["-b"] ?>"/> + <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>") + end ?> + </DD> </DL> <H3>Remote logging</H3> - <DL> -<DT><?= view.config.remote.label ?></DT> -<DD><input type="text" class="text" name="host" value="<?= view.config.remote.value ?>"/> -<P>(default PORT=514/UDP)</P> -<p class="error"><?= view.config.remote.errtxt ?></p> -</DD> -</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 ?> /> + <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>") + 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>") + end ?> + </DD> + -<H2>Save and apply above settings</H2> -<DL> -<DT>Apply settings</DT> -<DD><input class="submit" type="submit" value="Apply" disabled/></DD> </DL> <H1>MANAGEMENT</H1> @@ -92,9 +108,11 @@ </dl> <? end ?> + <? --[[ DEBUG INFORMATION require("debugs") io.write(debugs.variables(view)) --]] ?> + diff --git a/syslog-controller.lua b/syslog-controller.lua index 0bdc2f5..288ae7b 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -10,22 +10,40 @@ function status(self) end function config(self) - local srvcmdresult = nil - local srvcmd = self.clientdata.srvcmd - if (srvcmd ~= nil) then - srvcmdresult = self.model:service_control(srvcmd) - if (srvcmd == "stop") or (srvcmd == "restart") then - posix.sleep(3) -- Wait for the process to start|stop - else - posix.sleep(1) -- Wait for the process to start|stop - end - end - - return { status = self.model.getstatus(), srvcmdresult=srvcmdresult, config= self.model.getconfig() } +-- local srvcmdresult = nil +-- local srvcmd = self.clientdata.srvcmd +-- if (srvcmd ~= nil) then +-- srvcmdresult = self.model:service_control(srvcmd) +-- if (srvcmd == "stop") or (srvcmd == "restart") then +-- posix.sleep(3) -- Wait for the process to start|stop +-- else +-- posix.sleep(1) -- Wait for the process to start|stop +-- end +-- end + local status = self.model.getstatus() + local config, errors = self.model.getconfig() + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller + + return { + status = status, +-- srvcmdresult = srvcmdresult, + config = config, + errors = errors, + url = url, } end function expert(self) - return { file = self.model:get_filedetails(), status = self.model.getstatus(),} + local modifications = self.clientdata.modifications or "" + if ( modifications ~= "") then + modifications = self.model:update_filecontent(modifications) + end + + local status = self.model.getstatus() + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller + + return { file = self.model:get_filedetails(), + status = status, + url = url, } end diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp index a212df0..97dd3d5 100644 --- a/syslog-expert-html.lsp +++ b/syslog-expert-html.lsp @@ -30,7 +30,7 @@ <DL> <dt>Last modified</dt> -<dd><?= view.file.details.mtimelong ?></dd> +<dd><?= view.file.details.mtime ?></dd> </DL> <h3>File content</h3> @@ -42,7 +42,7 @@ <H2>Save and apply above settings</H2> <DL> <DT>Apply settings</DT> -<DD><input class="submit" type="submit" value="Apply" disabled/></DD> +<DD><input class="submit" type="submit" value="Apply"/></DD> </DL> <H1>MANAGEMENT</H1> diff --git a/syslog-model.lua b/syslog-model.lua index 88700e2..1d402d3 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -1,8 +1,11 @@ module(..., package.seeall) require("fs") -require("posix") require("procps") +require("getopts") +require("format") + +local configfile = "/etc/conf.d/syslog" local function get_version() local cmd = "/sbin/apk_version -v -s busybox | cut -d ' ' -f 1" @@ -12,104 +15,53 @@ local function get_version() return cmd_output_result end -local is_running = function( process ) - local statusreport = nil - if procps.pidof(process) then - statusreport = "Yes" - end - return statusreport -end - -local function readopts(optname) - local opts = {} - local line - local f = io.open("/etc/conf.d/syslog", "r") - if (f == nil) then - return nil - end - for line in f:lines() do - local optstr = string.match(line, "^" .. optname .. "=\"?(.*)%\"+") - if optstr then - local option = "" - local optvalue = "" - opts["org"]=optstr - for j = 1, string.len(optstr) do - if (string.sub(optstr, j, j) == "-") then - option=string.sub(optstr, j, j+1) - for k = j+1, string.len(optstr) do - if (string.sub(optstr, k, k) == "-") then - opts[option] = string.match(string.sub(optstr, j+2, k-1),"^%s*(.*)%s?") - break - end - if (k == string.len(optstr)) then - opts[option] = string.match(string.sub(optstr, j+2, k),"^%s*(.*)%s?") - break - end - - end - end - end - end - end - return opts -end - -local function file_info ( path ) - local filedetails = posix.stat(path) - filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name") - filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name") - filedetails["atimelong"]=os.date("%c", filedetails["atime"]) - filedetails["mtimelong"]=os.date("%c", filedetails["mtime"]) - filedetails["path"]=path - filedetails["name"]=basename(path) - - if ( filedetails["size"] > 1073741824 ) then - filedetails["size"]=((filedetails["size"]/1073741824) - (filedetails["size"]/1073741824%0.1)) .. "G" - elseif ( filedetails["size"] > 1048576 ) then - filedetails["size"]=((filedetails["size"]/1048576) - (filedetails["size"]/1048576%0.1)) .. "M" - elseif ( filedetails["size"] > 1024 ) then - filedetails["size"]=((filedetails["size"]/1024) - (filedetails["size"]/1024%0.1)) .. "k" - else - filedetails["size"]=filedetails["size"] +local function getloglevels() + local loglevels = {} + for i=1,8 do + table.insert(loglevels,i) end - return filedetails - + return loglevels end -- ################################################################################ --- EXPERIMENTAL LOCAL FUNCTIONS - - --- ################################################################################ -- PUBLIC FUNCTIONS function getstatus() - local opts = readopts("SYSLOGD_OPTS") + local opts = getconfig() local status = {} status.version = get_version() - status.enabled = is_running("syslogd") - status.logfile = opts["-O"] or "/var/log/messages" - status.remote = opts["-R"] + status.enabled = procps.pidof("syslogd") + if not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then + status.logfile = opts["SYSLOGD_OPTS"]["-O"] + end + if (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then + status.remote = opts["SYSLOGD_OPTS"]["-R"] + end return status end function get_filedetails() local filedetails = {} - local path = "/etc/conf.d/syslog" - filedetails.details = file_info(path) + local path = configfile + filedetails.details = fs.stat(path) filedetails.content = fs.read_file(path) return filedetails end function getconfig() - local opts = readopts("SYSLOGD_OPTS") - local config = {} - config.debug = opts - config.logfile = cfe({value=opts["-O"], type="text", option="", errtxt="" ,label="Log to given file", }) - config.loglevel = cfe({value=opts["-l"], type="radio", option="", errtxt="", helptxt="(1=Quiet, 5=Noisy, Default=Not specifyed any loglevel in the config)", label="Set local log level", }) - config.smallog = cfe({value=opts["-S"], type="select", option="", errtxt="", label="Smaller logging output", }) - config.maxsize = cfe({value=opts["-s"], type="text", option="", errtxt="", label="Max size (KB) before rotate", }) - config.logrotate = cfe({value=opts["-b"], type="text", option="", errtxt="", label="Number of rotated logs to keep", }) - config.remote = cfe({value=opts["-R"], type="text", option="", errtxt="", label="Log to IP or hostname on PORT", }) - return config + local errors = {} + errors["SYSLOGD_OPTS"] = {} + errors["KLOGD_OPTS"] = {} + local config = getopts.getoptsfromfile(configfile) + 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 "" + if (config["SYSLOGD_OPTS"]["-l"]) and + ((tonumber(config["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(config["SYSLOGD_OPTS"]["-l"]) > 8)) then + errors["SYSLOGD_OPTS"]["-l"] = "Log value is out of range. Please select one of the above." + else + config["SYSLOGD_OPTS"]["-l"] = config["SYSLOGD_OPTS"]["-l"] or 8 + end + + return config, errors end service_control = function ( self, srvcmd ) @@ -132,46 +84,15 @@ service_control = function ( self, srvcmd ) return retval end --- ################################################################################ --- OTHER FUNCTIONS - --- we actually need root permissions to get the process list ---[[ -priv = {} -function priv.is_enabled() - return (pidof.pidof("syslogd")) +function setconfigs(self,value) + --TODO: Validate so that user cant add values with '-' end - -function priv.enable(opts) - if opts and opts.remote then - local f = io.open("/etc/conf.d/syslog", "w") - if f == nil then - return nil - end - f:write("# this file was written by and will be overwritten by acf\n") - f:write("SYSLOGD_OPTS=\"-R "..opts.remote.."\"") - f:close() - end - os.system("/etc/init.d/syslogd restart; rc_add -k -s 20 syslog") +function update_filecontent (self, modifications) + local path = configfile + local file_result,err = fs.write_file(path, format.dostounix(modifications)) + return file_result, err end ---]] ---[[ --- this func does not need privileges -local function readopts() - local opts = {} - local line - local f = io.open("/etc/conf.d/syslog", "r") - if f == nil then - return nil - end - for line in f:lines() do - local optstr = string.match(line, "^SYSLOGD_OPTS=\"?(.*)\"?") - if optstr then - opts.remote = string.match(optstr, "-R%s*(.*)%s*.*$") - opts.optstr = optstr - end - end - return opts -end ---]] +-- ################################################################################ +-- OTHER FUNCTIONS + diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp index 6e830ea..845abec 100644 --- a/syslog-status-html.lsp +++ b/syslog-status-html.lsp @@ -3,29 +3,25 @@ <h1>SYSTEM INFO</h1> <DL> -<dt>Program status</dt> -<DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD> -</DL> + <dt>Program status</dt> + <DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD> -<DL> -<dt>Program version</dt> -<dd><?= view.status.version ?></dd> + <dt>Program version</dt> + <dd><?= view.status.version ?></dd> </DL> <H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> -<? if (view.status.logfile) then ?> <DL> -<dt>Locally logging to</dt> -<dd><?= view.status.logfile ?></dd> -</DL> -<? end ?> + <? if (view.status.logfile) then ?> + <dt>Locally logging to</dt> + <dd><?= view.status.logfile ?></dd> + <? end ?> -<? if (view.status.remote) then ?> -<DL> -<dt>Remote logging to</dt> -<dd><?= view.status.remote ?></dd> + <? if (view.status.remote) then ?> + <dt>Remote logging to</dt> + <dd><?= view.status.remote ?></dd> + <? end ?> </DL> -<? end ?> <? |