summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-21 00:44:51 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-21 00:44:51 +0000
commit4088e14476b222e0a59ea3e4e789f99b32cec40f (patch)
tree044ec57511a7dae581dafd2da152ad5be6fa9bac
parentc07bcb228f39b86e4b886f044c41cd05aa249b9f (diff)
downloadacf-tcpproxy-4088e14476b222e0a59ea3e4e789f99b32cec40f.tar.bz2
acf-tcpproxy-4088e14476b222e0a59ea3e4e789f99b32cec40f.tar.xz
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.
-rw-r--r--tcpproxy-controller.lua28
-rw-r--r--tcpproxy-model.lua41
2 files changed, 36 insertions, 33 deletions
diff --git a/tcpproxy-controller.lua b/tcpproxy-controller.lua
index 3809a10..198da9d 100644
--- a/tcpproxy-controller.lua
+++ b/tcpproxy-controller.lua
@@ -1,47 +1,49 @@
-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 expert(self)
+function mymodule.expert(self)
return self.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved")
end
-function smtpstatus(self)
+function mymodule.smtpstatus(self)
return self.model.getsmtpstatus()
end
-function listsmtpentries(self)
+function mymodule.listsmtpentries(self)
return self.model.listsmtpentries(self)
end
-function editsmtpentry(self)
+function mymodule.editsmtpentry(self)
return self.handle_form(self, function() return self.model.readsmtpentry(self.clientdata.ipaddr) end, self.model.updatesmtpentry, self.clientdata, "Save", "Edit SMTP Proxy Entry", "SMTP Proxy Entry Saved" )
end
-function delsmtpentry(self)
+function mymodule.delsmtpentry(self)
return self.handle_form(self, self.model.getdelsmtpentry, self.model.delsmtpentry, self.clientdata, "Delete", "Delete SMTP Proxy Entry", "SMTP Proxy Entry Deleted" )
end
-function listsmtpfiles(self)
+function mymodule.listsmtpfiles(self)
return self.model.listsmtpfiles(self)
end
-function createsmtpfile(self)
+function mymodule.createsmtpfile(self)
return self.handle_form(self, self.model.getnewsmtpfile, self.model.createsmtpfile, self.clientdata, "Create", "Create New SMTP Proxy File", "SMTP Proxy File Created")
end
-function editsmtpfile(self)
+function mymodule.editsmtpfile(self)
return self.handle_form(self, function() return self.model.readsmtpfile(self.clientdata.filename) end, self.model.updatesmtpfile, self.clientdata, "Save", "Edit SMTP Proxy File", "SMTP Proxy File Saved" )
end
-function delsmtpfile(self)
+function mymodule.delsmtpfile(self)
return self.handle_form(self, self.model.getdelsmtpfile, self.model.delsmtpfile, self.clientdata, "Delete", "Delete SMTP Proxy File", "SMTP Proxy File Deleted" )
end
+
+return mymodule
diff --git a/tcpproxy-model.lua b/tcpproxy-model.lua
index 9f6f8a5..ecd7017 100644
--- a/tcpproxy-model.lua
+++ b/tcpproxy-model.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
@@ -189,33 +189,33 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function get_startstop(self, clientdata)
+function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(processname)
end
-function startstop_service(self, startstop, action)
+function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
end
-function getstatus()
+function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "TCP Proxy Status")
end
-function getconfigfile()
+function mymodule.getconfigfile()
return modelfunctions.getfiledetails(configfile)
end
-function setconfigfile(self, filedetails)
+function mymodule.setconfigfile(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, {configfile})
end
-function getsmtpstatus()
+function mymodule.getsmtpstatus()
local value, errtxt = processinfo.package_version(smtppackagename)
local version = cfe({ value=value, label="Program version", errtxt=errtxt, name=smtppackagename })
return cfe({ type="group", value={version=version}, label="SMTP Proxy Status" })
end
-function listsmtpentries(self)
+function mymodule.listsmtpentries(self)
local entries = cfe({ type="structure", value={}, label="SMTP Command Entries" })
if self then
local interfacescontroller = self:new("alpine-baselayout/interfaces")
@@ -253,10 +253,10 @@ function listsmtpentries(self)
return entries
end
-function readsmtpentry(ipaddr)
+function mymodule.readsmtpentry(ipaddr)
local exec = getsmtpcmd(ipaddr)
- local listfiles = listsmtpfiles()
+ local listfiles = mymodule.listsmtpfiles()
table.insert(listfiles.value, 1, "")
local ipaddrcfe = cfe({ value=ipaddr, label="Interface / IP Address", readonly=true, seq=0 })
@@ -284,7 +284,7 @@ function readsmtpentry(ipaddr)
return cfe({ type="group", value={ipaddr=ipaddrcfe, server=server, addressonly=addressonly, domain=domain, optionalserver=optionalserver, optionalrewritelist=optionalrewritelist, senderlistfile=senderlistfile, rcptlistfile=rcptlistfile}, label="SMTP Proxy Entry" })
end
-function updatesmtpentry(self, entry)
+function mymodule.updatesmtpentry(self, entry)
local success, entry = validatesmtpentry(entry)
if success then
@@ -333,19 +333,19 @@ function updatesmtpentry(self, entry)
return entry
end
-function getdelsmtpentry(self, clientdata)
+function mymodule.getdelsmtpentry(self, clientdata)
local retval = {}
retval.ipaddr = cfe({ value=clientdata.ipaddr or "", label="IP Address" })
return cfe({ type="group", value=retval, label="Delete SMTP Proxy Entry" })
end
-function delsmtpentry(self, delentry)
+function mymodule.delsmtpentry(self, delentry)
-- TODO - validate ipaddr
setsmtpcmd(delentry.value.ipaddr.value, nil)
return delentry
end
-function listsmtpfiles()
+function mymodule.listsmtpfiles()
local retval = cfe({ type="list", value={}, label="SMTP Proxy Files" })
if not fs.is_dir(smtpdirectory) then fs.create_directory(smtpdirectory) end
for file in posix.files(smtpdirectory) do
@@ -356,12 +356,12 @@ function listsmtpfiles()
return retval
end
-function getnewsmtpfile()
+function mymodule.getnewsmtpfile()
local filename = cfe({ label="File Name", descr="Must be in "..smtpdirectory })
return cfe({ type="group", value={filename=filename}, label="SMTP Proxy File" })
end
-function createsmtpfile(self, filedetails)
+function mymodule.createsmtpfile(self, filedetails)
local success = true
if not validator.is_valid_filename(filedetails.value.filename.value, smtpdirectory) then
@@ -384,21 +384,21 @@ function createsmtpfile(self, filedetails)
return filedetails
end
-function readsmtpfile(filename)
+function mymodule.readsmtpfile(filename)
return modelfunctions.getfiledetails(filename, function(filename) return validator.is_valid_filename(filename, smtpdirectory) end)
end
-function updatesmtpfile(self, filedetails)
+function mymodule.updatesmtpfile(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, function(filename) return validator.is_valid_filename(filename, smtpdirectory) end)
end
-function getdelsmtpfile(self, clientdata)
+function mymodule.getdelsmtpfile(self, clientdata)
local retval = {}
retval.filename = cfe({ value=clientdata.filename or "", label="File Name" })
return cfe({ type="group", value=retval, label="Delete SMTP Proxy File" })
end
-function delsmtpfile(self, delfile)
+function mymodule.delsmtpfile(self, delfile)
local filename = delfile.value.filename.value
if validator.is_valid_filename(filename, smtpdirectory) and fs.is_file(filename) then
os.remove(filename)
@@ -410,3 +410,4 @@ function delsmtpfile(self, delfile)
return delfile
end
+return mymodule