From 913b0dbe7a980d2c72a052e397f082050f072836 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 2 Apr 2008 08:49:15 +0000 Subject: Show autostart sequence. Disable not working config-tab. Hiding management-buttons because there exists no /etc/init.d/fetchmail script. git-svn-id: svn://svn.alpinelinux.org/acf/fetchmail/trunk@889 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 3 +-- fetchmail-config-html.lsp | 2 +- fetchmail-controller.lua | 66 +++++++++++++++++++++++++++++++++-------------- fetchmail-expert-html.lsp | 42 ++++++++++++++---------------- fetchmail-model.lua | 43 +++++++++++++++++++++++++----- fetchmail-status-html.lsp | 2 +- fetchmail.menu | 2 +- 7 files changed, 107 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 5aa1149..3843421 100644 --- a/Makefile +++ b/Makefile @@ -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

SYSTEM INFO

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

SYSTEM INFO

@@ -77,32 +77,30 @@ configform(myform,tags) ?> - - -
-

MANAGEMENT

-
-
-
- - - - - -
- 0) then ?> -
Previous action result
-
- -
-
+ io.write('
') + io.write('

MANAGEMENT

') + io.write('
') + io.write('
' .. cmdform[tags[1]]["label"] .. '
') + io.write('
') + for k,v in pairs(tags) do + if (cmdform[v]) then + io.write(html.form[cmdform[v].type](cmdform[v])) + end + end + io.write('
') - + if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then + io.write('
' .. cmdresult.label .. '
') + io.write('
' .. cmdresult.action.descr .. '
') + end + io.write('
') +end ?> /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 protocol etrn smtpdomain 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

SYSTEM INFO

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 -- cgit v1.2.3