Commit 913b0dbe authored by Mika Havela's avatar Mika Havela

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
parent 878bdd0f
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
......
......@@ -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)
?>
......
......@@ -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,
......
......@@ -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
......
......@@ -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
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",
......
......@@ -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)
?>
......
#CAT GROUP/DESC TAB ACTION
Networking 30Fetchmail Status status
Networking 30Fetchmail Config config
#Networking 30Fetchmail Config config
Networking 30Fetchmail Expert expert
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment