diff options
Diffstat (limited to 'syslog-model.lua')
-rw-r--r-- | syslog-model.lua | 19 |
1 files changed, 17 insertions, 2 deletions
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)) |