diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | fetchmail-config-html.lsp | 2 | ||||
-rw-r--r-- | fetchmail-controller.lua | 66 | ||||
-rw-r--r-- | fetchmail-expert-html.lsp | 42 | ||||
-rw-r--r-- | fetchmail-model.lua | 43 | ||||
-rw-r--r-- | fetchmail-status-html.lsp | 2 | ||||
-rw-r--r-- | fetchmail.menu | 2 |
7 files changed, 107 insertions, 53 deletions
@@ -1,13 +1,12 @@ APP_NAME=fetchmail PACKAGE=acf-$(APP_NAME) -VERSION=0.1 +VERSION=0.1.0 APP_DIST=\ fetchmail-controller.lua \ fetchmail-model.lua \ fetchmail-expert-html.lsp \ fetchmail-status-html.lsp \ - fetchmail-config-html.lsp \ fetchmail.menu \ EXTRA_DIST=README Makefile config.mk diff --git a/fetchmail-config-html.lsp b/fetchmail-config-html.lsp index d6f86af..fdc5422 100644 --- a/fetchmail-config-html.lsp +++ b/fetchmail-config-html.lsp @@ -50,7 +50,7 @@ end <H1>SYSTEM INFO</H1> <? local myform = form.status -local tags = { "status", "version", } +local tags = { "status", "version", "autostart", } informationform(myform,tags) ?> diff --git a/fetchmail-controller.lua b/fetchmail-controller.lua index cf30d9b..654a519 100644 --- a/fetchmail-controller.lua +++ b/fetchmail-controller.lua @@ -60,10 +60,40 @@ local function displaycmdmanagement(disablestart,disablestop,disablerestart) return management end +local function displaycmdmanagement(disablestart,disablestop,disablerestart) + -- 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", + }) + + -- 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 + +-- ################################################################################ +-- PUBLIC FUNCTIONS + function status(self) return { status=getstatus(self) } end - +--[==[ function config(self) local cmdmanagement, cmdmanagementresult local cmdsavereply = {} @@ -145,15 +175,20 @@ function config(self) debugclientdata = self.clientdata, } end - +--]==] function expert(self) - local cmdmanagement, cmdmanagementresult + -- Start/Stop/Restart process + local cmdmanagement if ( self.clientdata.cmdmanagement) then - cmdmanagement = cfe({ + cmdmanagement = cfe({ + name="cmdmanagement", + label="Previous action result", + action=cfe({ name="cmdmanagement", - value=string.lower(self.clientdata.cmdmanagement), - }) - cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) + value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) + }), + }) + local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) end -- Save changes @@ -169,7 +204,7 @@ function expert(self) -- Display save button config.cmdsave = displaycmdsave() ---[[ + -- Management buttons local disablestart,disablestop,disablerestart -- Disable management buttons based on if the process is running or not @@ -178,25 +213,16 @@ function expert(self) 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) ---]] +-- 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, + cmdmanagement = cmdmanagement, config = config, status = status, startstop = startstop, diff --git a/fetchmail-expert-html.lsp b/fetchmail-expert-html.lsp index 0a36abb..597e162 100644 --- a/fetchmail-expert-html.lsp +++ b/fetchmail-expert-html.lsp @@ -49,7 +49,7 @@ end <H1>SYSTEM INFO</H1> <? local myform = form.status -local tags = { "status", "version", } +local tags = { "status", "version", "autostart", } informationform(myform,tags) ?> @@ -77,32 +77,30 @@ configform(myform,tags) ?> </form> - -<? +<? -- MANAGEMENT BUTTONS local cmdform = form.management +local cmdresult = form.cmdmanagement local tags = { "start", "stop", "restart" } if (cmdform) and (cmdform[tags[1]]) then -?> - <form name="management" action="" method="POST"> - <H1>MANAGEMENT</H1> - <dl> - <dt><?= cmdform[tags[1]]["label"] ?></dt> - <dd> - <? for k,v in pairs(tags) do ?> - <? if (cmdform[v]) then ?> - <? io.write(html.form[cmdform[v].type](cmdform[v])) ?> - <? end ?> - <? end ?> - </dd> - <? if (form.cmdmanagement) and (#form.cmdmanagement.descr > 0) then ?> - <dt>Previous action result</dt> - <dd><pre><?= form.cmdmanagement.descr ?></pre></dd> - <? end ?> - </dl> - </form> + io.write('<form name="management" action="" method="POST">') + io.write('<H1>MANAGEMENT</H1>') + io.write('<dl>') + io.write('<dt>' .. cmdform[tags[1]]["label"] .. '</dt>') + io.write('<dd>') + for k,v in pairs(tags) do + if (cmdform[v]) then + io.write(html.form[cmdform[v].type](cmdform[v])) + end + end + io.write('</dd>') -<? end ?> + if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then + io.write('<dt>' .. cmdresult.label .. '</dt>') + io.write('<dd><pre>' .. cmdresult.action.descr .. '</pre></dd>') + end + io.write('</dl></form>') +end ?> <? --[[ DEBUG INFORMATION diff --git a/fetchmail-model.lua b/fetchmail-model.lua index 6e446fd..6556209 100644 --- a/fetchmail-model.lua +++ b/fetchmail-model.lua @@ -12,11 +12,17 @@ local configfile = "/root/.fetchmailrc" local config = {} local function get_version() - local cmd = "/usr/bin/fetchmail --version 2>/dev/null" + local cmd_output_result, cmd_output_error + local cmd = "/sbin/apk_version -vs " .. processname .." 2>/dev/null" local f = io.popen( cmd ) - local cmd_output_result = f:read("*l") + local cmdresult = f:read("*l") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = string.match(cmdresult,"^%S*") or "Unknown" + else + cmd_output_error = "Program not installed" + end f:close() - return cmd_output_result or "Not installed" + return cmd_output_result,cmd_output_error end local function getloglevels() @@ -181,10 +187,24 @@ pool <host> protocol etrn smtpdomain <mydomain> return mailboxes,configcontent_postmaster,configcontent_etrn end + +local function autostarts() + local cmd_output_result, cmd_output_error + local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null" + local f = io.popen( cmd ) + local cmdresult = f:read("*a") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')" + else + cmd_output_error = "Not programmed to autostart" + end + f:close() + return cmd_output_result,cmd_output_error +end + -- ################################################################################ -- PUBLIC FUNCTIONS --- action should be a CFE function startstop_service ( self, action ) local cmd = action.value local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd) @@ -192,25 +212,36 @@ function startstop_service ( self, action ) action.errtxt=cmderror -- Reporting back (true|false, the original acition) return cmdresult,action - end function getstatus() local opts = getconfig() local status = {} + + local value, errtxt = get_version() status.version = cfe({ name = "version", label="Program version", - value=get_version(), + value=value, + errtxt=errtxt, }) + status.status = cfe({ name="status", label="Program status", value=procps.pidof(processname), }) + status.configfile = cfe({ name="configfile", label="Config file", value=configfile, }) + local autostart_sequense, autostart_errtxt = autostarts() + status.autostart = cfe({ name="autostart", + label="Autostart sequence", + value=autostart_sequense, + errtxt=autostart_errtxt, + }) + --[[ if (opts["remotelogging"]) and not ((opts["remotelogging"]["value"] ~= "") and not (opts["localandnetworklog"]["value"])) then status.logfile = cfe({ name="logfile", diff --git a/fetchmail-status-html.lsp b/fetchmail-status-html.lsp index 780abb3..9b3372a 100644 --- a/fetchmail-status-html.lsp +++ b/fetchmail-status-html.lsp @@ -23,7 +23,7 @@ end <H1>SYSTEM INFO</H1> <? local myform = form.status -local tags = { "status", "version", } +local tags = { "status", "version", "autostart", } informationform(myform,tags) ?> diff --git a/fetchmail.menu b/fetchmail.menu index e7d8933..1ebbda9 100644 --- a/fetchmail.menu +++ b/fetchmail.menu @@ -1,4 +1,4 @@ #CAT GROUP/DESC TAB ACTION Networking 30Fetchmail Status status -Networking 30Fetchmail Config config +#Networking 30Fetchmail Config config Networking 30Fetchmail Expert expert |