summaryrefslogtreecommitdiffstats
path: root/syslog-controller.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-controller.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-controller.lua')
-rw-r--r--syslog-controller.lua190
1 files changed, 113 insertions, 77 deletions
diff --git a/syslog-controller.lua b/syslog-controller.lua
index a32f103..4fe7755 100644
--- a/syslog-controller.lua
+++ b/syslog-controller.lua
@@ -23,97 +23,101 @@ local function getstatus(self)
return status
end
-function status(self)
- return { status=getstatus(self) }
-end
-
-function config(self)
- local cmdmanagement
- local cmd_save_result = {}
- local cmderrors = {}
- if ( self.clientdata.cmd_management) then
- local cmd_management = cfe({
- name="cmd_management",
- value=string.lower(self.clientdata.cmd_management),
- })
- cmdmanagement = self.model:startstop_service( cmd_management )
- end
- if ( self.clientdata.cmd_save) then
- local variables="logfile loglevel smallerlogs maxsize numrotate localandnetworklog remotelogging" -- Advanced-config options
- --local variables="remotelogging" -- Guided-config options
- for var in string.gmatch(variables, "%S+") do
- -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset the variable in the config-file
- if (self.clientdata[var] == "") then self.clientdata[var] = nil end
- cmd_save_result[var] = self.model:setconfigs("SYSLOGD_OPTS",var,self.clientdata[var])
- end
- end
-
- local status = getstatus(self)
---[[
- if (#status.status.value > 0) then
- status.status.value = "Enabled"
- else
- status.status.value = "Disabled"
- end
---]]
-
- local config, errors = self.model.getconfig()
+local function displaycmdsave(self)
-- Add a cmd button to the view
- config.cmd_save = cfe({ name="cmd_save",
+ local cmdsave = cfe({ name="cmdsave",
label="Save/Apply above settings",
value="Save",
type="submit",
})
+ return cmdsave
+end
+
+local function displaycmdmanagement(disablestart,disablestop,disablerestart)
-- Add a management buttons
- management = {}
- management.start = cfe({ name="cmd_management",
+ local management = {}
+ management.start = cfe({ name="cmdmanagement",
label="Program control-panel",
value="Start",
type="submit",
})
- management.stop = cfe({ name="cmd_management",
+ management.stop = cfe({ name="cmdmanagement",
label="Program control-panel",
value="Stop",
type="submit",
})
- management.restart = cfe({ name="cmd_management",
+ management.restart = cfe({ name="cmdmanagement",
label="Program control-panel",
value="Restart",
type="submit",
})
+
+ -- Disable management buttons based on if the process is running or not
+ if (disablestart) then management.start.disabled = "yes" end
+ if (disablestop) then management.stop.disabled = "yes" end
+ if (disablerestart) then management.restart.disabled = "yes" end
+
+ return management
+end
+
+function status(self)
+ return { status=getstatus(self) }
+end
+
+function config(self)
+ local cmdmanagement
+ local cmdsavereply = {}
+ local cmdsaveresult = {}
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement),
+ })
+ cmdmanagement = self.model:startstop_service( cmdmanagement )
+ end
+ if ( self.clientdata.cmdsave) then
+ local variables="logfile loglevel smallerlogs maxsize numrotate localandnetworklog remotelogging" -- Advanced-config options
+-- local variables="remotelogging" -- Guided-config options
+ for var in string.gmatch(variables, "%S+") do
+ -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset the variable in the config-file
+ if (self.clientdata[var] == "") then self.clientdata[var] = nil end
+ cmdsaveresult[var], cmdsavereply[var] = self.model:setconfigs( var,self.clientdata[var] )
+ end
+ end
+
+ local status = getstatus(self)
+ local config = self.model.getconfig()
+
+ -- Write out erros from previous cmdsave actions
+ for k,v in pairs(cmdsaveresult) do
+ if not (v) then
+ config[k]["errtxt"] = tostring(cmdsavereply[k]["errtxt"])
+ end
+ end
+
+ -- Display save button
+ config.cmdsave = displaycmdsave()
+
+ -- Management buttons
+ local disablestart,disablestop,disablerestart
-- Disable management buttons based on if the process is running or not
if (string.lower(status.status.value) == "enabled" ) then
- management.start.disabled = "yes"
- management.stop.disabled = nil
+ disablestart = "yes"
else
- management.start.disabled = nil
- management.stop.disabled = "yes"
+ disablestop = "yes"
end
-
-- Disable management buttons if there exist errors in the config
for k,v in pairs(config) do
if (config[k]["errtxt"] ~= "") then
- management.start.disabled = "yes"
- management.stop.disabled = "yes"
- management.restart.disabled = "yes"
+ disablestart = "yes"
+ disablestop = "yes"
+ disablerestart = "yes"
break
end
end
-
- local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ -- Display management buttons
+ local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
- local cmderrors_str = ""
- for k,v in pairs(cmderrors) do
- if (type(v) ~= "table") then
- cmderrors_str = v.. "\n" .. cmderrors_str
- else
- for kk,vv in pairs(v) do
- cmderrors_str = tostring(vv) .. "\n" .. tostring(cmderrors_str)
- end
- end
- end
- if (cmderrors_str == "") then cmderrors_str = nil end
-
return {
option={ script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
@@ -121,35 +125,67 @@ function config(self)
action = "config", },
status = status,
cmdmanagement = cmdmanagement,
- clientdata = self.clientdata,
management = management,
config = config,
- cmd_save_result = cmd_save_result,
- errors = errors,
- cmderrors = cmderrors_str,
- url = url, }
+ debugclientdata = self.clientdata,
+ }
end
function expert(self)
- local modifications = self.clientdata.modifications or ""
- if ( self.clientdata.cmdsave) then
- modifications = self.model:update_filecontent(modifications)
+ local cmdmanagement
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement),
+ })
+ cmdmanagement = self.model:startstop_service( cmdmanagement )
end
- if ( self.clientdata.cmddaemon) then
- startstop = self.model:startstop_service( self.clientdata.cmddaemon )
+ -- Save changes
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave) then
+ modifications = self.model:update_filecontent(modifications)
end
--- local status = self.model.getstatus()
local status = getstatus(self)
+ local config = self.model:get_filedetails()
+
- local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ -- Display save button
+ config.cmdsave = displaycmdsave()
- return { file = self.model:get_filedetails(),
+ -- Management buttons
+ local disablestart,disablestop,disablerestart
+ -- Disable management buttons based on if the process is running or not
+ if (string.lower(status.status.value) == "enabled" ) then
+ disablestart = "yes"
+ else
+ disablestop = "yes"
+ end
+ -- Disable management buttons if there exist errors in the config
+ for k,v in pairs(config) do
+ if (config[k]["errtxt"] ~= "") then
+ disablestart = "yes"
+ disablestop = "yes"
+ disablerestart = "yes"
+ break
+ end
+ end
+ -- Display management buttons
+ local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
+
+ return {
+ option={ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action = "expert", },
+ cmdmanagement = cmdmanagement,
+ management = management,
+ config = config,
status = status,
startstop = startstop,
- clientdata = self.clientdata,
- url = url, }
+ debugclientdata = self.clientdata,
+ }
end