summaryrefslogtreecommitdiffstats
path: root/fetchmail-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'fetchmail-model.lua')
-rw-r--r--fetchmail-model.lua119
1 files changed, 12 insertions, 107 deletions
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
-