summaryrefslogtreecommitdiffstats
path: root/syslog-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-31 16:23:48 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-31 16:23:48 +0000
commit272e1f2444e68ed59533719f433b9435aa7f48a7 (patch)
tree17df8f736029f9c044e8beeb98c52b5c2b388e91 /syslog-model.lua
parent6d30c3259050b88f42e92038e8eb8d325fc28540 (diff)
downloadacf-alpine-baselayout-272e1f2444e68ed59533719f433b9435aa7f48a7.tar.bz2
acf-alpine-baselayout-272e1f2444e68ed59533719f433b9435aa7f48a7.tar.xz
Changing things so we use cfe for sending/receiving things from model and controller.
The view-file is using loops instead to reduce code. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@668 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'syslog-model.lua')
-rw-r--r--syslog-model.lua137
1 files changed, 92 insertions, 45 deletions
diff --git a/syslog-model.lua b/syslog-model.lua
index 2013b76..0045b5b 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -25,13 +25,6 @@ local function getloglevels()
end
return loglevels
end
-local function isrunning(process)
- if (procps.pidof("syslogd")) then
- return "Enabled"
- else
- return "Disabled"
- end
-end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -42,23 +35,26 @@ end
function getstatus()
local opts = getconfig()
local status = {}
- status.version = cfe({ name="Program version",
+ status.version = cfe({ name = "version",
+ label="Program version",
value=get_version(),
})
- status.status = cfe({ name="Program status",
- value=isrunning("syslogd"),
+ status.status = cfe({ name="status",
+ label="Program status",
+ value=procps.pidof("syslogd"),
})
- if (opts["SYSLOGD_OPTS"]) and not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then
- status.logfile = cfe({ name="Locally logging to",
- value=opts["SYSLOGD_OPTS"]["-O"],
+ if (opts["remotelogging"]) and not ((opts["remotelogging"]["value"] ~= "") and not (opts["localandnetworklog"]["value"])) then
+ status.logfile = cfe({ name="logfile",
+ label="Locally logging to",
+ value=opts["logfile"]["value"],
})
end
if (opts["SYSLOGD_OPTS"]) and (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then
- status.remote = cfe({ name="Remote logging to",
+ status.remote = cfe({ name="remotelogging",
+ label="Remote logging to",
value=opts["SYSLOGD_OPTS"]["-R"],
})
end
---]]
return status
end
@@ -75,38 +71,71 @@ function get_filedetails()
end
function getconfig()
local config = {}
- config['SYSLOGD_OPTS']={}
- local errors = {}
- errors["SYSLOGD_OPTS"] = {}
- errors["KLOGD_OPTS"] = {}
if (fs.is_file(configfile)) then
- config = getopts.getoptsfromfile(configfile) or config
+ configcontent = getopts.getoptsfromfile(configfile) or config
if (type(config["SYSLOGD_OPTS"]) == "string") then
config["SYSLOGD_OPTS"] = {}
end
else
- 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"] = {}
+ config["configfile"] = "Config file '".. configfile .. "' is missing!"
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 ""
- config["SYSLOGD_OPTS"]["-s"] = config["SYSLOGD_OPTS"]["-s"] or ""
- config["SYSLOGD_OPTS"]["-b"] = config["SYSLOGD_OPTS"]["-b"] or ""
+ -- Next section selects which configurations we should show to the user
+ config["logfile"] = cfe({
+ name="logfile",
+ label = "Log to given file",
+ value = configcontent["SYSLOGD_OPTS"]["-O"] or "/var/log/messages",
+ })
+ config["loglevel"] = cfe({
+ name="loglevel",
+ label = "Set local log level",
+ value = tonumber(configcontent["SYSLOGD_OPTS"]["-l"]) or 8,
+ type = "select",
+ option = getloglevels(),
+ descr = "1=Quiet, ... , " .. table.maxn(getloglevels()) .. "=Debug",
+ })
+ config["smallerlogs"] = cfe({
+ name="smallerlogs",
+ label = "Smaller logging output",
+ checked = configcontent["SYSLOGD_OPTS"]["-S"],
+ value = "smallerlogs",
+ type = "checkbox",
+ })
+ config["maxsize"] = cfe ({
+ name="maxsize",
+ label = "Max size (KB) before rotate",
+ descr = "Default=200KB, 0=off",
+ value = configcontent["SYSLOGD_OPTS"]["-s"],
+ })
+ config["numrotate"] = cfe ({ name="numrotate",
+ label = "Number of rotated logs to keep",
+ descr = "Default=1, max=99, 0=purge",
+ value = configcontent["SYSLOGD_OPTS"]["-b"],
+ })
+ config["localandnetworklog"] = cfe ({
+ name="localandnetworklog",
+ label = "Log locally and via network",
+ checked = configcontent["SYSLOGD_OPTS"]["-L"],
+ value = "localandnetworklog",
+ type = "checkbox",
+ descr = "Default is network only if -R",
+ })
+ config["remotelogging"] = cfe ({
+ name="remotelogging",
+ label = "Log to IP or hostname on PORT",
+ descr = "host[:PORT] - Default PORT=514/UDP",
+ value = configcontent["SYSLOGD_OPTS"]["-R"],
+ })
+
-- Next section is to print errormessages when configs are wrong
- 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
+ if (configcontent["SYSLOGD_OPTS"]["-l"]) and
+ ((tonumber(configcontent["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(configcontent["SYSLOGD_OPTS"]["-l"]) > 8)) then
+ config["loglevel"]["errtxt"] = "Log value is out of range. Please select one of the above."
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."
+
+ if (configcontent["SYSLOGD_OPTS"]["-L"] ~= nil) and (configcontent["SYSLOGD_OPTS"]["-R"] == "") then
+ config["localandnetworklog"]["errtxt"] = "Logging to local and network is possible unless you define a host for remote logging."
end
- return config, errors
+ return config
end
service_control = function ( self, srvcmd )
@@ -130,17 +159,33 @@ service_control = function ( self, srvcmd )
end
function setconfigs(self,variable,parameter,value)
- if (errors == nil) then
- errors = {}
- end
+ local variabletranslator = ({
+ logfile = "-O",
+ loglevel = "-l",
+ smallerlogs = "-S",
+ maxsize = "-s",
+ numrotate = "-b",
+ localandnetworklog = "-L",
+ remotelogging = "-R",
+ })
+ parameter = variabletranslator[parameter]
+
--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
if (value) and (parameter == "-O") then
- value, errors["-O"] = validator.is_valid_filename(value, "/var/log" )
+ local value, errors = validator.is_valid_filename(value, "/var/log" )
+ if (errors) then
+ return cfe({
+ name="setconfig",
+ errtxt= errors,
+ })
+ end
end
+
+--[[
if (value) and (parameter == "-R") then
local port = string.match(value, ":(.-)$")
local host = string.match(value, "^(.-):?")
@@ -149,12 +194,14 @@ function setconfigs(self,variable,parameter,value)
end
errors["-R"] = "Port:'" .. tostring(port) .. "' Host:" .. tostring(host)
end
-
+--]]
-- Set specific variables (and their values)
if (value) and ((parameter == "-S") or (parameter == "-L")) then value = "" end
local retval, errorscmd = getopts.setoptsinfile(configfile,variable,parameter,value)
- errors["commit"] = errorscmd
- return retval, errors
+-- if (errorscmd) and (#errorscmd > 0) then
+ local errorscmd = cfe({ name="variable", errtxt=errorscmd, })
+-- end
+ return errorscmd
end
function update_filecontent (self, modifications)