summaryrefslogtreecommitdiffstats
path: root/syslog-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-01 13:41:30 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-01 13:41:30 +0000
commit1889fca8b509381c749d7e418e92cf809ec8d5ce (patch)
treefba8af3c48ce4792539ab7c9767b2f0624f8486d /syslog-model.lua
parent28ef684f79089fdb764163a02029bab21387c004 (diff)
downloadacf-alpine-baselayout-1889fca8b509381c749d7e418e92cf809ec8d5ce.tar.bz2
acf-alpine-baselayout-1889fca8b509381c749d7e418e92cf809ec8d5ce.tar.xz
Many changes (mostly to use cfe's when sending/receiving things from model/controller/view).
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@676 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'syslog-model.lua')
-rw-r--r--syslog-model.lua170
1 files changed, 111 insertions, 59 deletions
diff --git a/syslog-model.lua b/syslog-model.lua
index f4b2681..e9e03d5 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -28,9 +28,10 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+-- action should be a CFE
function startstop_service ( self, action )
local cmd = action.value
- local cmdresult,cmdaction,cmdmessage,cmderror = daemoncontrol.daemoncontrol("syslog", cmd)
+ local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol("syslog", cmd)
action.descr=cmdmessage
action.errtxt=cmderror
return action
@@ -64,15 +65,35 @@ function getstatus()
end
function get_filedetails()
- local filedetails = {}
local path = configfile
- filedetails.details = {path=path, size="0",mtime=""}
- filedetails.content = ""
- if (fs.is_file(path)) then
- filedetails.details = fs.stat(path)
- filedetails.content = fs.read_file(path)
- end
- return filedetails
+ local filedetails = fs.stat(path)
+ local config = getconfig(path)
+ local file = {}
+ file["filename"] = cfe({
+ name="filename",
+ label="File name",
+ value=path,
+ })
+ file["filesize"] = cfe({
+ name="filesize",
+ label="File size",
+ value=filedetails.size,
+ })
+ file["mtime"] = cfe({
+ name="mtime",
+ label="File name",
+ value=filedetails.mtime,
+ })
+ file["filecontent"] = cfe({
+ type="longtext",
+ name="filecontent",
+ label="File content",
+ value=fs.read_file(path),
+ })
+
+ file["sumerrors"] = config.sumerrors
+
+ return file
end
function getconfig()
local config = {}
@@ -134,36 +155,40 @@ function getconfig()
-- Next section is to print errormessages when configs are wrong
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."
+ config["loglevel"]["errtxt"] = "Log value is out of range!\nCurrent value in config is '" ..
+ configcontent["SYSLOGD_OPTS"]["-l"] ..
+ "' - This is invalid!\nPlease select one of the above and save your changes."
+ table.insert(config["loglevel"]["option"], tonumber(configcontent["SYSLOGD_OPTS"]["-l"]))
end
- 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."
+ if (configcontent["SYSLOGD_OPTS"]["-L"] ~= nil) and ((configcontent["SYSLOGD_OPTS"]["-R"] == nil) or (configcontent["SYSLOGD_OPTS"]["-R"] == "")) then
+ config["localandnetworklog"]["errtxt"] = "Logging to local and network (-L) is not possible unless you define a host (-R) for remote logging or remove this option."
end
- return config
-end
-service_control = function ( self, srvcmd )
- local srvcmd = string.lower(srvcmd)
- local retval = ""
- local line = ""
- if (srvcmd == "start") or (srvcmd == "stop") or (srvcmd == "restart") then
- local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/syslog " .. srvcmd .. " 2>&1" )
- if file ~= nil then
- line = file:read( "*l" )
- while line ~= nil do
- retval = retval .. "\n" .. line
- line = file:read( "*l" )
- end
- file:close()
+ -- Sum all errors into one cfe
+ local sumerrors = ""
+ for k,v in pairs(config) do
+ if (config[k]["errtxt"] ~= "") then
+ sumerrors = sumerrors .. config[k]["errtxt"] .. "\n"
end
- else
- retval = "Unknown command!"
end
- return retval
+ if (sumerrors ~= "") then
+ config["sumerrors"] = cfe ({
+ name="sumerrors",
+ label = "Configuration errors",
+ errtxt = sumerrors,
+ })
+ end
+
+ return config
end
-function setconfigs(self,variable,parameter,value)
+-- IMPORTANT! This function is a exception! It's not fed with CFE's
+-- Parameter should be one of the ones defined in the variable 'variabletranslator'.
+-- value should be whatever the new value should be.
+function setconfigs(self,parameter,value)
+ -- Set variables
+ local variable = "SYSLOGD_OPTS"
local variabletranslator = ({
logfile = "-O",
loglevel = "-l",
@@ -173,48 +198,75 @@ function setconfigs(self,variable,parameter,value)
localandnetworklog = "-L",
remotelogging = "-R",
})
- parameter = variabletranslator[parameter]
+ cmdparameter = variabletranslator[parameter]
+
+ -- Report a error if someone tryes to use a invalid parameter
+ if not (cmdparameter) then
+ local availablevariables = ""
+ for k,v in pairs(variabletranslator) do
+ availablevariables = k .. ", " .. availablevariables
+ end
+ parameter = parameter or ""
+ return false, cfe({
+ name="syslog.model.setconfigs()",
+ errtxt="'" .. parameter .. "' is not a valid parameter!\nValid options are: " .. availablevariables,
+ })
+ end
--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
- local value, errors = validator.is_valid_filename(value, "/var/log" )
- if (errors) then
- return cfe({
- name="setconfig",
- errtxt= errors,
+
+ -- This config-file only accepts one type of parameters (report error if someone uses wrong parameter)
+ if not (string.find(cmdparameter, "-%a$")) then
+ return false, cfe({
+ name="syslog.model.setconfigs()",
+ errtxt="Parameter must be formated '-a' (where a is one upper/lowercase letter [a-z])",
+ })
+ end
+
+ -- Validate userinput (if valid path/filename)
+ if (value) and (cmdparameter == "-O") then
+ local cmdresult, cmdmessage = validator.is_valid_filename(value, "/var/log" )
+ if not (cmdresult) then
+ return false, cfe({
+ name="syslog.model.setconfigs()",
+ errtxt=cmdmessage,
})
end
end
---[[
- if (value) and (parameter == "-R") then
- local port = string.match(value, ":(.-)$")
- local host = string.match(value, "^(.-):?")
+ -- Validate userinput (Has the user entered a valid hostname and/or port)
+ if (value) and (cmdparameter == "-R") then
+ local hostport = format.string_to_table(value, ":")
+ local host = hostport[1]
+ local port = hostport[2]
if (port) and not (validator.is_port(port)) then
- errors["-R"] = "Port:'" .. tostring(port) .. "' is not a valid portnumber!"
+ return false, cfe({
+ name="syslog.model.setconfigs.getopts.setoptsinfile()",
+ errtxt="You entered '" .. tostring(port) .. "' as port - This is not valid!",
+ })
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)
--- if (errorscmd) and (#errorscmd > 0) then
- local errorscmd = cfe({ name="variable", errtxt=errorscmd, })
--- end
- return true, e
+
+ -- Set/Unset checkbox variables
+ if (value) and ((cmdparameter == "-S") or (cmdparameter == "-L")) then value = "" end
+
+ local cmdresult, cmdmessage, cmderror = getopts.setoptsinfile(configfile,variable,cmdparameter,value)
+ if (cmderror) then
+ return false, cfe({
+ name="syslog.model.setconfigs.getopts.setoptsinfile()",
+ errtxt=cmderror,
+ })
+ end
+ return true, cfe({
+ name="syslog.model.setconfigs()",
+ value=cmdmessage,
+ })
end
+-- modifications should be a CFE
function update_filecontent (self, modifications)
local path = configfile
local file_result,err = fs.write_file(path, format.dostounix(modifications))
return file_result, err
end
--- ################################################################################
--- OTHER FUNCTIONS
-