diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-08-11 18:42:29 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-08-11 18:42:29 +0000 |
commit | bc7effbae906b23589c625dd401c1fd09bb434e1 (patch) | |
tree | 97cffd084e313992695c1acb4584ea374ea043cc | |
parent | 4788958ba73b4274a5ef9824d0291fe3c82d0d5b (diff) | |
download | acf-fetchmail-bc7effbae906b23589c625dd401c1fd09bb434e1.tar.bz2 acf-fetchmail-bc7effbae906b23589c625dd401c1fd09bb434e1.tar.xz |
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
-rw-r--r-- | fetchmail-controller.lua | 110 | ||||
l---------[-rw-r--r--] | fetchmail-expert-html.lsp | 59 | ||||
-rw-r--r-- | fetchmail-model.lua | 119 | ||||
l--------- | fetchmail-startstop-html.lsp | 1 | ||||
l---------[-rw-r--r--] | fetchmail-status-html.lsp | 29 | ||||
-rw-r--r-- | fetchmail.roles | 2 |
6 files changed, 27 insertions, 293 deletions
diff --git a/fetchmail-controller.lua b/fetchmail-controller.lua index 03668f6..8adb959 100644 --- a/fetchmail-controller.lua +++ b/fetchmail-controller.lua @@ -1,109 +1,21 @@ 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 - diff --git a/fetchmail-expert-html.lsp b/fetchmail-expert-html.lsp index 533c32f..207f324 100644..120000 --- a/fetchmail-expert-html.lsp +++ b/fetchmail-expert-html.lsp @@ -1,58 +1 @@ -<% 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 diff --git a/fetchmail-model.lua b/fetchmail-model.lua index 26a68f9..d619f0e 100644 --- a/fetchmail-model.lua +++ b/fetchmail-model.lua @@ -1,12 +1,8 @@ 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 - diff --git a/fetchmail-startstop-html.lsp b/fetchmail-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/fetchmail-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp
\ No newline at end of file diff --git a/fetchmail-status-html.lsp b/fetchmail-status-html.lsp index 630b440..b2f8480 100644..120000 --- a/fetchmail-status-html.lsp +++ b/fetchmail-status-html.lsp @@ -1,28 +1 @@ -<% 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 diff --git a/fetchmail.roles b/fetchmail.roles index f84c194..a88ba43 100644 --- a/fetchmail.roles +++ b/fetchmail.roles @@ -1,2 +1,2 @@ READ=fetchmail:status -UPDATE=fetchmail:expert +UPDATE=fetchmail:expert,fetchmail:startstop |