Commit bc7effba authored by Ted Trask's avatar Ted Trask

Modified fetchmail to clean up status and expert, and add startstop. Still...

Modified fetchmail to clean up status and expert, and add startstop.  Still have to implement config.

git-svn-id: svn://svn.alpinelinux.org/acf/fetchmail/trunk@1375 ab2d0c66-481e-0410-8bed-d214d4d58bed
parent 4788958b
module(..., package.seeall)
-- ################################################################################
-- LOCAL FUNCTIONS
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
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
-- ################################################################################
-- PUBLIC FUNCTIONS
require("controllerfunctions")
default_action = "status"
function status(self)
return { status=self.model:getstatus(self) }
return self.model.getstatus()
end
function expert(self)
-- 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
-- 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(self)
local config = self.model:get_filedetails()
-- Display save button
config.cmdsave = displaycmdsave()
---[[ -- 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
function startstop(self)
return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)
end
--[[
function config(self)
return controllerfunctions.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
--]]
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "expert", },
management = management,
config = config,
status = status,
}
function expert(self)
return controllerfunctions.handle_form(self, self.model.get_filedetails, self.model.update_filecontent, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
<% local form = ...
require("viewfunctions")
%>
<%
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")
--]]
%>
<H1>SYSTEM INFO</H1>
<DL>
<%
local myform = form.status
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<H1>CONFIGURATION</H1>
<% local myform = form.config %>
<form action="<%= form.option.script .. "/" .. form.option.prefix ..
form.option.controller .. "/" .. form.option.action %>" method="POST">
<H2>EXPERT CONFIGURATION</H2>
<H3>FILE DETAILS</H3>
<DL>
<%
local tags = { "filename", "filesize", "mtime", "sumerrors" }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<H3>FILE CONTENT</H3>
<%
io.write(html.form[form.config.filecontent.type](form.config.filecontent))
%>
<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
<DL>
<%
local tags = { "cmdsave", }
displayinfo(myform,tags)
%>
</DL>
<%
-- Management buttons
local myform = form.management
local tags = { "start", "stop", "restart" }
if (myform) then
io.write("<H1>MANAGEMENT</H1>\n<DL>")
displaymanagement(myform,tags)
io.write("</DL>")
end
%>
</form>
../expert-html.lsp
\ No newline at end of file
module(..., package.seeall)
-- Load libraries
require("modelfunctions")
require("fs")
require("procps")
require("format")
require("daemoncontrol")
require("validator")
require("processinfo")
-- Set variables
local packagename = "fetchmail"
......@@ -181,112 +177,28 @@ pool <host> protocol etrn smtpdomain <mydomain>
end
local function process_status_text(procname)
local t = procps.pidof(procname)
if (t) and (#t > 0) then
return "Enabled"
else
return "Disabled"
end
end
-- ################################################################################
-- PUBLIC FUNCTIONS
function startstop_service ( self, action )
local cmd = action.value
local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd)
action.descr=cmdmessage
action.errtxt=cmderror
return cmdresult,action
function startstop_service(action)
return modelfunctions.startstop_service(processname, action)
end
function getstatus()
local opts = getconfig()
local status = {}
local value, errtxt = processinfo.package_version(packagename)
status.version = cfe({ name = "version",
label="Program version",
value=value,
errtxt=errtxt,
})
status.status = cfe({ name="status",
label="Program status",
value=process_status_text(processname),
})
local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
status.autostart = cfe({ name="autostart",
label="Autostart sequence",
value=autostart_sequense,
errtxt=autostart_errtxt,
})
status.configfile = cfe({ name="configfile",
label="Config file",
value=configfile,
})
return status
return modelfunctions.getstatus(processname, packagename, "Fetchmail Status")
end
function get_filedetails()
local path = configfile
local file = {}
local filedetails = {}
local config = {}
local filenameerrtxt
if (fs.is_file(path)) then
filedetails = fs.stat(path)
config = getconfig(path)
else
config = {}
config.filename = {}
config["filename"]["errtxt"]="Config file '".. path .. "' is missing!"
end
file["filename"] = cfe({
name="filename",
label="File name",
value=path,
errtxt=filenameerrtxt
})
file["filesize"] = cfe({
name="filesize",
label="File size",
value=filedetails.size or 0,
})
file["mtime"] = cfe({
name="mtime",
label="File date",
value=filedetails.mtime or "---",
})
file["filecontent"] = cfe({
type="longtext",
name="filecontent",
label="File content",
value=fs.read_file(path),
})
-- Sum all errors into one cfe
local sumerrors = ""
for k,v in pairs(config) do
if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then
sumerrors = sumerrors .. config[k]["errtxt"] .. "\n"
end
end
if (sumerrors ~= "") then
file["sumerrors"] = cfe ({
name="sumerrors",
label = "Configuration errors",
errtxt = string.match(sumerrors, "(.-)\n$"),
})
end
-- FIXME - validation
return modelfunctions.getfiledetails(configfile)
end
return file
function update_filecontent(filedetails)
filedetails.value.filename.value = configfile
-- FIXME - validation
return modelfunctions.setfiledetails(filedetails)
end
function getconfig()
local config = {}
local mailboxes,configcontent_postmaster,configcontent_etrn = read_config()
......@@ -333,10 +245,3 @@ function getconfig()
return config
end
-- modifications should be a CFE
function update_filecontent (self, modifications)
local path = configfile
local file_result,err = fs.write_file(path, format.dostounix(modifications))
return file_result, err
end
../startstop-html.lsp
\ No newline at end of file
<% local form = ...
require("viewfunctions")
%>
<%
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")
--]]
%>
<H1>SYSTEM INFO</H1>
<DL>
<%
local myform = form.status
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<DL>
<%
local myform = form.status
local tags = { "configfile", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
../status-html.lsp
\ No newline at end of file
READ=fetchmail:status
UPDATE=fetchmail:expert
UPDATE=fetchmail:expert,fetchmail:startstop
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