Commit 010cf490 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 ed4e254d
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 details(self)
function mymodule.details(self)
return self.model.getstatusdetails()
end
function filterrules(self)
function mymodule.filterrules(self)
return self.model.getrules("filter")
end
function natrules(self)
function mymodule.natrules(self)
return self.model.getrules("nat")
end
function manglerules(self)
function mymodule.manglerules(self)
return self.model.getrules("mangle")
end
function editchain(self)
function mymodule.editchain(self)
return self.handle_form(self, function() return self.model.read_chain(self.clientdata.table, self.clientdata.chain or "") end, self.model.update_chain, self.clientdata, "Save", "Edit Chain", "Chain saved")
end
function createchain(self)
function mymodule.createchain(self)
return self.handle_form(self, function() return self.model.read_chain(self.clientdata.table) end, self.model.create_chain, self.clientdata, "Create", "Create New Chain", "Chain created")
end
function deletechain(self)
function mymodule.deletechain(self)
return self.handle_form(self, self.model.get_delete_chain, self.model.delete_chain, self.clientdata, "Delete", "Delete Chain", "Chain deleted")
end
function editrule(self)
function mymodule.editrule(self)
return self.handle_form(self, function() return self.model.read_rule(self.clientdata.table, self.clientdata.chain or "", self.clientdata.position or "") end, self.model.update_rule, self.clientdata, "Save", "Edit Rule", "Rule saved")
end
function createrule(self)
function mymodule.createrule(self)
return self.handle_form(self, function() return self.model.read_rule(self.clientdata.table, self.clientdata.chain, self.clientdata.position) end, self.model.create_rule, self.clientdata, "Create", "Create New Rule", "Rule created")
end
function deleterule(self)
function mymodule.deleterule(self)
return self.handle_form(self, self.model.get_delete_rule, self.model.delete_rule, self.clientdata, "Delete", "Delete Rule", "Rule deleted")
end
function expert(self)
function mymodule.expert(self)
return self.handle_form(self, self.model.readrulesfile, self.model.updaterulesfile, self.clientdata, "Save", "Edit Rules File", "Rules File Saved")
end
function startstop(self)
function mymodule.startstop(self)
return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata)
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
......@@ -194,11 +194,11 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
function getstatus()
function mymodule.getstatus()
return modelfunctions.getstatus(servicename, packagename, "IPtables Status")
end
function getstatusdetails()
function mymodule.getstatusdetails()
getdetails()
local retval = {}
for i,tab in ipairs(tables) do
......@@ -214,14 +214,14 @@ function getstatusdetails()
return cfe({ type="structure", value=retval, label="IPtables Status Details" })
end
function getrules(tab)
function mymodule.getrules(tab)
getdetails()
tab = tab or "filter"
return cfe({ type="structure", value=details[tab] or {}, label=string.gsub(tab, "^.", string.upper).." Rules" })
end
function read_chain(tab, chain)
function mymodule.read_chain(tab, chain)
local retval = {}
retval.table = cfe({ type="select", value=tab or "filter", label="Table", option=tables, seq=1 })
retval.chain = cfe({ value=chain or "", label="Chain", seq=2 })
......@@ -245,7 +245,7 @@ function read_chain(tab, chain)
return cfe({ type="group", value=retval, label="Chain" })
end
function update_chain(self, chain)
function mymodule.update_chain(self, chain)
local success = true
getdetails()
if not details[chain.value.table.value] then
......@@ -268,7 +268,7 @@ function update_chain(self, chain)
return chain
end
function create_chain(self, chain)
function mymodule.create_chain(self, chain)
local success = true
getdetails()
if not details[chain.value.table.value] then
......@@ -293,14 +293,14 @@ function create_chain(self, chain)
return chain
end
function get_delete_chain(self, clientdata)
function mymodule.get_delete_chain(self, clientdata)
local retval = {}
retval.table = cfe({ type="select", value=clientdata.table or "filter", label="Table", option=tables })
retval.chain = cfe({ value=clientdata.chain or "", label="Chain" })
return cfe({ type="group", value=retval, label="Delete Chain" })
end
function delete_chain(self, chain)
function mymodule.delete_chain(self, chain)
local chn = find_chain(chain.value.table.value, chain.value.chain.value)
if not chn then
chain.errtxt = "Could not find chain"
......@@ -316,7 +316,7 @@ function delete_chain(self, chain)
return chain
end
function read_rule(tab, chain, pos)
function mymodule.read_rule(tab, chain, pos)
local retval = {}
-- Identification
retval.table = cfe({ type="select", value=tab or "filter", label="Table", option=tables })
......@@ -470,7 +470,7 @@ function read_rule(tab, chain, pos)
return cfe({ type="group", value=retval, label="Rule" })
end
function create_rule(self, rule)
function mymodule.create_rule(self, rule)
local success, rule = validate_rule(rule)
if success then
......@@ -494,7 +494,7 @@ function create_rule(self, rule)
return rule
end
function update_rule(self, rule)
function mymodule.update_rule(self, rule)
local success, rule = validate_rule(rule)
if not tonumber(rule.value.position.value) then
rule.value.position.errtxt = "Must be a number"
......@@ -514,7 +514,7 @@ function update_rule(self, rule)
return rule
end
function get_delete_rule(self, clientdata)
function mymodule.get_delete_rule(self, clientdata)
local retval = {}
-- Identification
retval.table = cfe({ type="select", value=clientdata.table or "filter", label="Table", option=tables })
......@@ -523,7 +523,7 @@ function get_delete_rule(self, clientdata)
return cfe({ type="group", value=retval, label="Delete Rule" })
end
function delete_rule(self, rule)
function mymodule.delete_rule(self, rule)
if "" == rule.value.table.value or "" == rule.value.chain.value or "" == rule.value.position.value then
rule.errtxt = "Incomplete specification - must define table, chain, and position"
else
......@@ -533,20 +533,22 @@ function delete_rule(self, rule)
return rule
end
function readrulesfile()
function mymodule.readrulesfile()
local rulesfile = format.get_ini_entry(fs.read_file(configfile) or "", "", "IPTABLES_SAVE")
return modelfunctions.getfiledetails(rulesfile)
end
function updaterulesfile(self, filedetails)
function mymodule.updaterulesfile(self, filedetails)
local rulesfile = format.get_ini_entry(fs.read_file(configfile) or "", "", "IPTABLES_SAVE")
return modelfunctions.setfiledetails(self, filedetails, {rulesfile})
end
function get_startstop(self, clientdata)
function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(servicename)
end
function startstop_service(self, startstop, action)
function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
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