summaryrefslogtreecommitdiffstats
path: root/openssh-controller.lua
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2008-06-14 20:55:20 +0000
committerNatanael Copa <natanael.copa@gmail.com>2008-06-14 20:55:20 +0000
commit9c1669a4343097cbb2453a51ac09b9417ad95f70 (patch)
treedcf2576cf3463c1d6c0d88b76f73835d3bdf5e44 /openssh-controller.lua
downloadacf-openssh-9c1669a4343097cbb2453a51ac09b9417ad95f70.tar.bz2
acf-openssh-9c1669a4343097cbb2453a51ac09b9417ad95f70.tar.xz
added initial acf for opensshv0.1
git-svn-id: svn://svn.alpinelinux.org/acf/openssh/trunk@1218 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openssh-controller.lua')
-rw-r--r--openssh-controller.lua166
1 files changed, 166 insertions, 0 deletions
diff --git a/openssh-controller.lua b/openssh-controller.lua
new file mode 100644
index 0000000..767c5fd
--- /dev/null
+++ b/openssh-controller.lua
@@ -0,0 +1,166 @@
+module (..., package.seeall)
+
+-- Load libraries
+require("posix")
+require("validator")
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function displaycmdmanagement(pidofstatus)
+ -- Add a management buttons
+ local management = {}
+ management.start = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Start",
+ type="submit",
+ })
+ management.stop = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Stop",
+ type="submit",
+ })
+ management.restart = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Restart",
+ type="submit",
+ })
+ -- next CFE can be used to present the result of the previous action
+ management.actionresult = cfe({ name="actionresult",
+ label="Previous action result",
+ })
+
+ -- Disable management buttons based on if the process is running or not
+ if (pidofstatus) then
+ management.start.disabled = "yes"
+ else
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
+ return management
+end
+
+local function displaycmdsave(self)
+ -- Add a cmd button to the view
+ local cmdsave = cfe({ name="cmdsave",
+ label="Save/Apply above settings",
+ value="Save",
+ type="submit",
+ })
+ return cmdsave
+end
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+default_action = "config"
+
+function config(self)
+ local errors = {}
+ local modify_opts = nil
+ local cmdsavereply = {}
+ local cmdsaveresult = {}
+
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ return ( {status = status,
+ config = self.model.read_config(),
+ management = management,
+ url = url,
+ errors = errors,
+ cmdsavereply = cmdsavereply,
+ cmdsaveresult = cmdsaveresult,
+ modify_opts = modify_opts,
+ clientdata = self.clientdata,
+ } )
+end
+
+function logfile(self)
+
+ local status = self.model:getstatus(self)
+ local logfile = self.model:get_logfile()
+
+ return ({
+ status = status,
+ logfile = logfile,
+ url = url,
+ })
+end
+
+function status (self)
+ local cmd = self.clientdata.cmd
+ local url = self.conf.script .. self.conf.prefix .. self.conf.controller
+ return ( {status = "whoops", url = url } )
+end
+
+function expert (self)
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave ) then
+ modifications = self.model:update_filecontent(modifications)
+ end
+ local url = self.conf.script .. self.conf.prefix .. self.conf.controller
+
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ local status = self.model:getstatus(self)
+ local file = self.model:get_filedetails()
+
+ -- Add buttons
+ file.cmdsave = cfe ({
+ name="cmdsave",
+ label="Apply settings",
+ value="Apply",
+ type="submit",
+ })
+ if (self.clientdata.cmdsave) then
+ file.cmdsave.descr="* Changes has been saved!"
+ end
+
+
+ -- Management buttons (Hide/show buttons
+ local pidofstatus
+ if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
+ management = displaycmdmanagement(pidofstatus)
+ if (actionresult) then
+ management.actionresult.descr=cmdmanagement.descr
+ management.actionresult.errtxt=cmdmanagement.errtxt
+ end
+ if (status) and (status.version) and (#status.version.value == 0) then
+ management.start.disabled = "yes"
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
+ return ( {
+ status = status,
+ file = file,
+ modifications = modifications,
+ management = management,
+ url = url, } )
+end
+