Commit a5e87d00 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 3376bd99
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 config(self)
function mymodule.config(self)
return self.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
function expert(self)
function mymodule.expert(self)
return self.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config File", "Configuration File Set")
end
function editips(self)
function mymodule.editips(self)
return self.handle_form(self, self.model.getIPs, self.model.setIPs, self.clientdata, "Save", "Edit IP List", "IP List Set")
end
function listdomains(self)
function mymodule.listdomains(self)
return self.model.getDomains()
end
function createdomain(self)
function mymodule.createdomain(self)
return self.handle_form(self, self.model.getNewDomain, self.model.setNewDomain, self.clientdata, "Create", "Create New Domain", "New Domain Created")
end
function editdomain(self)
function mymodule.editdomain(self)
return self.handle_form(self, self.model.getDomain, self.model.setDomain, self.clientdata, "Save", "Edit Domain Entry", "Domain Saved")
end
function deletedomain(self)
function mymodule.deletedomain(self)
return self.handle_form(self, self.model.getDeleteDomain, self.model.deleteDomain, self.clientdata, "Delete", "Delete Domain Entry", "Domain Deleted")
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
posix = require("posix")
......@@ -37,7 +37,7 @@ end
local function validatedomain(domain)
local success = false
local domains = getDomains()
local domains = mymodule.getDomains()
domain.value.domain.errtxt = "Invalid domain"
for i,name in ipairs(domains.value) do
if name == domain.value.domain.value then
......@@ -59,19 +59,19 @@ 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, "DNS Cache Status")
end
function getconfig()
function mymodule.getconfig()
local conf = format.parse_ini_file(fs.read_file(configfile) or "", "") or {}
local output = {}
output.IPSEND = cfe({ value = conf.IPSEND or "", label="IP address for requests",
......@@ -83,7 +83,7 @@ function getconfig()
return cfe({ type="group", value=output, label="DNS Cache Config" })
end
function setconfig(self, config)
function mymodule.setconfig(self, config)
local success, config = validateconfig(config)
if success then
......@@ -104,17 +104,17 @@ function setconfig(self, config)
return config
end
function getconfigfile()
function mymodule.getconfigfile()
-- FIXME Validate
return modelfunctions.getfiledetails(configfile)
end
function setconfigfile(self, filedetails)
function mymodule.setconfigfile(self, filedetails)
-- FIXME Validate
return modelfunctions.setfiledetails(self, filedetails, {configfile})
end
function getIPs()
function mymodule.getIPs()
local ipdir = baseurl.."ip"
local iplist = cfe({ type="list", value={}, label="IP prefixes to respond to" })
if fs.is_dir(ipdir) then
......@@ -129,7 +129,7 @@ function getIPs()
return cfe({ type="group", value={iplist=iplist} })
end
function setIPs(self, iplist)
function mymodule.setIPs(self, iplist)
local reverseIPs = {}
for i,name in ipairs(iplist.value.iplist.value) do
-- check if a valid (or partial) ip
......@@ -141,7 +141,7 @@ function setIPs(self, iplist)
reverseIPs[name] = i
end
if not iplist.errtxt then
local currentIPlist = getIPs()
local currentIPlist = mymodule.getIPs()
for i,name in ipairs(currentIPlist.value.iplist.value) do
if reverseIPs[name] then
reverseIPs[name] = nil
......@@ -158,7 +158,7 @@ function setIPs(self, iplist)
return iplist
end
function getDomains()
function mymodule.getDomains()
local domaindir = baseurl.."servers"
local domainlist = cfe({ type="list", value={}, label="DNS Server Domains" })
if fs.is_dir(domaindir) then
......@@ -173,12 +173,12 @@ function getDomains()
return domainlist
end
function getNewDomain()
function mymodule.getNewDomain()
local domain = cfe({ label="Domain" })
return cfe({ type="group", value={domain=domain} })
end
function setNewDomain(self, domain)
function mymodule.setNewDomain(self, domain)
if "" ~= string.gsub(domain.value.domain.value..".", "%w+%.", "") then
domain.value.domain.errtxt = "Invalid domain"
domain.errtxt = "Failed to create domain"
......@@ -192,11 +192,11 @@ function setNewDomain(self, domain)
return domain
end
function getDomain(self, clientdata)
function mymodule.getDomain(self, clientdata)
local getdomainname = clientdata.domain
local domain = cfe({ value=getdomainname, label="Domain", errtxt="Invalid domain", readonly=true, seq=1 })
local iplist = cfe({ type="list", value={}, label="List of DNS servers", seq=2 })
local domains = getDomains()
local domains = mymodule.getDomains()
for i,name in ipairs(domains.value) do
if name == getdomainname then
domain.errtxt = nil
......@@ -212,7 +212,7 @@ function getDomain(self, clientdata)
return cfe({ type="group", value={domain=domain, iplist=iplist} })
end
function setDomain(self, domain)
function mymodule.setDomain(self, domain)
local success, domain = validatedomain(domain)
if success then
fs.write_file(baseurl.."servers/"..domain.value.domain.value,
......@@ -223,15 +223,15 @@ function setDomain(self, domain)
return domain
end
function getDeleteDomain(self, clientdata)
function mymodule.getDeleteDomain(self, clientdata)
local domain = cfe({ value=clientdata.domain or "", label="Domain" })
return cfe({ type="group", value={domain=domain}, label="Delete Domain" })
end
function deleteDomain(self, domain)
function mymodule.deleteDomain(self, domain)
domain.errtxt = "Domain not deleted"
domain.value.domain.errtxt = "Invalid domain"
local domains = getDomains()
local domains = mymodule.getDomains()
if domain.value.domain.value == "@" then
domain.value.domain.errtxt = "Cannot delete root domain"
else
......@@ -246,3 +246,5 @@ function deleteDomain(self, domain)
end
return domain
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