From a1e005f1c2cf658dfbb6a23fc99b44b6316d2830 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 29 Jan 2008 16:19:42 +0000 Subject: Now you can save configs in config-tab. It works but is still unstable. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@660 ab2d0c66-481e-0410-8bed-d214d4d58bed --- syslog-config-html.lsp | 74 ++++++++++++++++++++++++++------------------------ syslog-controller.lua | 16 ++++++++--- 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 @@

Advanced config

General settings

- >Log to given file -
"/> - ", view.errors["SYSLOGD_OPTS"]["-O"] ,"

") end ?> + +
>Log to given file
+
"/> + ", view.errors["SYSLOGD_OPTS"]["-O"] ,"

") end ?>
-
Set local log level
+ +
>Set local log level
- >

(1=Quiet, ... , =Debug)

- ",view.errors["SYSLOGD_OPTS"]["-l"] ,"

") + ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>
-
Smaller logging output
-
/> - ",view.errors["SYSLOGD_OPTS"]["-S"] ,"

") + +
>Smaller logging output
+
/> + ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>
@@ -48,43 +51,42 @@

Save logs for a longer period

-
Max size (KB) before rotate
-
"/> + +
>Max size (KB) before rotate
+
"/>

(default=200KB, 0=off)

- ",view.errors["SYSLOGD_OPTS"]["-s"] ,"

") + ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>
-
Number of rotated logs to keep
-
"/> + +
>Number of rotated logs to keep
+
"/>

(default=1, max=99, 0=purge)

- ",view.errors["SYSLOGD_OPTS"]["-b"] ,"

") + ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>

Remote logging

-
Activate remote logging
-
/> - ",view.errors["SYSLOGD_OPTS"]["-R"] ,"

") - end ?> -
-
Log locally and via network
-
/> + +
>Log locally and via network
+
/>

(default is network only if you have defined remote-logging)

- ",view.errors["SYSLOGD_OPTS"]["-L"] ,"

") + ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>
-
Log to IP or hostname on PORT
-
"/> -

HOST[:PORT] (default PORT=514/UDP)

- ",view.errors["SYSLOGD_OPTS"]["-R"] ,"

") + + +
>Log to IP or hostname on PORT
+
"/> +

(Empty=No remote logging) HOST[:PORT] (default PORT=514/UDP)

+ ",view.errors["SYSLOGD_OPTS"][var] ,"

") end ?>
@@ -94,7 +96,7 @@

Save and apply above settings

Apply settings
-
+

MANAGEMENT

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)) -- cgit v1.2.3