Commit d630f6b8 authored by Ted Trask's avatar Ted Trask

Remove all calls to 'module' in preparation for move to Lua 5.2

Use mymodule parameter for module definition.
This was also helpful in revealing places where the code relied on the global environment.
parent 1d8f30e8
module(..., package.seeall)
local mymodule = {}
default_action = "status"
mymodule.default_action = "status"
function status(self)
function mymodule.status(self)
return self.model.getstatus()
end
function startstop(self)
function mymodule.startstop(self)
return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata)
end
function editconfig(self)
function mymodule.editconfig(self)
return self.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
function expert(self)
function mymodule.expert(self)
return self.handle_form(self, self.model.get_filedetails, self.model.update_filecontent, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
function listentries(self)
function mymodule.listentries(self)
return self.model.readentries()
end
function editentry(self)
function mymodule.editentry(self)
return self.handle_form(self, function() return self.model.readentry(self.clientdata.remotehost, self.clientdata.method, self.clientdata.remotemailbox, self.clientdata.localdomain) end, self.model.updateentry, self.clientdata, "Save", "Edit Entry", "Entry Saved")
end
function createentry(self)
function mymodule.createentry(self)
return self.handle_form(self, function() return self.model.readentry() end, self.model.createentry, self.clientdata, "Create", "Create Entry", "Entry Created")
end
function deleteentry(self)
function mymodule.deleteentry(self)
return self.handle_form(self, self.model.get_deleteentry, self.model.deleteentry, self.clientdata, "Delete", "Delete Entry", "Entry Deleted")
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
......@@ -388,12 +388,12 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
function get_startstop(self, clientdata)
function mymodule.get_startstop(self, clientdata)
local actions = {"Run", "Test"}
return cfe({ type="group", label="Management", value={}, option=actions })
end
function startstop_service(self, startstop, action)
function mymodule.startstop_service(self, startstop, action)
if action and (action:lower() == "run" or action:lower() == "test") then
local cmd
if action:lower() == "run" then
......@@ -408,16 +408,16 @@ function startstop_service(self, startstop, action)
return startstop
end
function getstatus()
function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "Fetchmail Status")
end
function get_filedetails()
function mymodule.get_filedetails()
-- FIXME - validation
return modelfunctions.getfiledetails(configfile)
end
function update_filecontent(self, filedetails)
function mymodule.update_filecontent(self, filedetails)
-- FIXME - validation
local retval = modelfunctions.setfiledetails(self, filedetails, {configfile})
posix.chmod(configfile, "rw-------")
......@@ -426,7 +426,7 @@ function update_filecontent(self, filedetails)
return retval
end
function getconfig()
function mymodule.getconfig()
local interval = cfe({ value="60", label="Polling Interval", descr="Interval in seconds" })
local postmaster = cfe({ label="Postmaster", descr="If defined, undeliverable mail is sent to this account, otherwise it is discarded" })
local bounceerrors = cfe({ type="boolean", value=true, label="Bounce Errors", descr="Bounce errors back to the sender or send them to the postmaster" })
......@@ -448,7 +448,7 @@ function getconfig()
return cfe({ type="group", value={interval=interval, postmaster=postmaster, bounceerrors=bounceerrors}, label="Fetchmail Global Config" })
end
function updateconfig(self, conf)
function mymodule.updateconfig(self, conf)
local success, conf = validateconfig(conf)
if success then
......@@ -491,7 +491,7 @@ function updateconfig(self, conf)
return conf
end
function readentries()
function mymodule.readentries()
local entries = cfe({ type="structure", value={}, label="List of Fetchmail entries" })
config = config or parseconfigfile(fs.read_file(configfile) or "")
for i,entry in ipairs(config or {}) do
......@@ -519,7 +519,7 @@ function readentries()
return entries
end
function readentry(entryname, meth, remotemailbx, localdom)
function mymodule.readentry(entryname, meth, remotemailbx, localdom)
local enabled = cfe({ type="boolean", value=true, label="Enable", seq=2 })
local method = cfe({ type="select", value="pop3", label="Method", option=methods, seq=3 })
local remotehost = cfe({ value=entryname, label="Remote Host", seq=1 })
......@@ -581,7 +581,7 @@ function readentry(entryname, meth, remotemailbx, localdom)
return cfe({ type="group", value={enabled=enabled, method=method, remotehost=remotehost, remotemailbox=remotemailbox, remotepassword=remotepassword, localhost=localhost, localmailbox=localmailbox, localdomain=localdomain, ssl=ssl, envelope=envelope}, label="Fetchmail Entry" })
end
function updateentry(self, entrystruct)
function mymodule.updateentry(self, entrystruct)
local success, entrystruct = validateentry(entrystruct)
local entry = findentryline(entrystruct.value.remotehost.value, entrystruct.value.method.value, entrystruct.value.remotemailbox.value, entrystruct.value.localdomain.value)
if not entry then
......@@ -598,7 +598,7 @@ function updateentry(self, entrystruct)
return entrystruct
end
function createentry(self, entrystruct)
function mymodule.createentry(self, entrystruct)
local success, entrystruct = validateentry(entrystruct)
local entry = findentryline(entrystruct.value.remotehost.value, entrystruct.value.method.value, entrystruct.value.remotemailbox.value, entrystruct.value.localdomain.value)
if entry then
......@@ -615,7 +615,7 @@ function createentry(self, entrystruct)
return entrystruct
end
function get_deleteentry(self, clientdata)
function mymodule.get_deleteentry(self, clientdata)
local retval = {}
retval.remotehost = cfe({ value=clientdata.remotehost or "", label="Remote Host" })
retval.method = cfe({ type="select", value=clientdata.method or "pop3", label="Method", option=methods })
......@@ -625,7 +625,7 @@ function get_deleteentry(self, clientdata)
return cfe({ type="group", value=retval, label="Delete Entry" })
end
function deleteentry(self, ent)
function mymodule.deleteentry(self, ent)
local entry = findentryline(ent.value.remotehost.value, ent.value.method.value, ent.value.remotemailbox.value, ent.value.localdomain.value)
if entry then
writeentryline(nil, entry)
......@@ -635,3 +635,5 @@ function deleteentry(self, ent)
return ent
end
return mymodule
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