diff options
Diffstat (limited to 'tcpproxy-model.lua')
-rw-r--r-- | tcpproxy-model.lua | 41 |
1 files changed, 21 insertions, 20 deletions
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 |