summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-18 20:02:30 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-18 20:02:30 +0000
commitb564ccb75dc3abda19acbb2b94e9db45b043fc9e (patch)
treea265dbb54b6fe935fb7d5fd6d610deb649ec2fe1
parent5dead1840ddd8e2053d4f13adf41fbbc74b9bbda (diff)
downloadacf-awall-b564ccb75dc3abda19acbb2b94e9db45b043fc9e.tar.bz2
acf-awall-b564ccb75dc3abda19acbb2b94e9db45b043fc9e.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--awall-controller.lua24
-rw-r--r--awall-model.lua34
2 files changed, 31 insertions, 27 deletions
diff --git a/awall-controller.lua b/awall-controller.lua
index 9fa56a1..e666304 100644
--- a/awall-controller.lua
+++ b/awall-controller.lua
@@ -1,39 +1,41 @@
-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 listpolicies(self)
+function mymodule.listpolicies(self)
return self.model.list_policies()
end
-function viewpolicy(self)
+function mymodule.viewpolicy(self)
return self.model.read_policyfile(self, clientdata)
end
-function createpolicy(self)
+function mymodule.createpolicy(self)
return self.handle_form(self, self.model.get_newpolicy, self.model.create_policy, self.clientdata, "Create", "Create New Policy File", "Policy File Created")
end
-function deletepolicy(self)
+function mymodule.deletepolicy(self)
return self.handle_form(self, self.model.get_delete_policy, self.model.delete_policy, self.clientdata, "Delete", "Delete Policy File", "Policy File Deleted")
end
-function editpolicy(self)
+function mymodule.editpolicy(self)
return self.handle_form(self, self.model.get_policyfile, self.model.update_policyfile, self.clientdata, "Save", "Edit Policy", "Policy File Saved")
end
-function enablepolicy(self)
+function mymodule.enablepolicy(self)
return self.handle_form(self, self.model.get_enablepolicy, self.model.enable_policy, self.clientdata, "Enable", "Enable Policy", "Policy Enabled")
end
-function disablepolicy(self)
+function mymodule.disablepolicy(self)
return self.handle_form(self, self.model.get_enablepolicy, self.model.disable_policy, self.clientdata, "Disable", "Disable Policy", "Policy Disabled")
end
+
+return mymodule
diff --git a/awall-model.lua b/awall-model.lua
index c8c6dc3..e242d40 100644
--- a/awall-model.lua
+++ b/awall-model.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
-- Load libraries
posix = require("posix")
@@ -68,16 +68,16 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function getstatus()
+function mymodule.getstatus()
return modelfunctions.getstatus(nil, packagename, "AWall Status")
end
-function get_startstop(self, clientdata)
+function mymodule.get_startstop(self, clientdata)
local actions = {"Verify", "Translate", "Activate"}
return cfe({ type="group", label="Management", value={}, option=actions })
end
-function startstop_service(self, startstop, action)
+function mymodule.startstop_service(self, startstop, action)
if not action then
startstop.errtxt = "Invalid Action"
else
@@ -99,7 +99,7 @@ function startstop_service(self, startstop, action)
return startstop
end
-function list_policies()
+function mymodule.list_policies()
-- core-router disabled BSN core router
local policies = {}
local reversepolicies = {}
@@ -147,14 +147,14 @@ function list_policies()
return cfe({ type="list", value=policies, label="Policies", errtxt=errtxt })
end
-function get_newpolicy()
+function mymodule.get_newpolicy()
local newpolicy = {}
newpolicy.name = cfe({ label="Name", seq=1 })
newpolicy.optional = cfe({ type="boolean", label="Optional", seq=2 })
return cfe({ type="group", value=newpolicy, label="New Policy" })
end
-function create_policy(self, newpolicy)
+function mymodule.create_policy(self, newpolicy)
local success = true
local name = newpolicy.value.name.value
@@ -162,7 +162,7 @@ function create_policy(self, newpolicy)
newpolicy.value.name.errtxt = "Invalid name"
success = false
else
- local policies = list_policies()
+ local policies = mymodule.list_policies()
for i,pol in ipairs(policies.value) do
if pol.name == newpolicy.value.name.value then
newpolicy.value.name.errtxt = "Name already exists"
@@ -195,13 +195,13 @@ function create_policy(self, newpolicy)
return newpolicy
end
-function get_delete_policy(self, clientdata)
+function mymodule.get_delete_policy(self, clientdata)
retval = {}
retval.filename = cfe({ value=clientdata.filename or "", label="File Name" })
return cfe({ type="group", value=retval, label="Delete Policy File" })
end
-function delete_policy(self, delpolicy)
+function mymodule.delete_policy(self, delpolicy)
if validateeditablefile(delpolicy.value.filename.value) then
os.remove(delpolicy.value.filename.value)
else
@@ -212,7 +212,7 @@ function delete_policy(self, delpolicy)
return delpolicy
end
-function read_policyfile(self, clientdata)
+function mymodule.read_policyfile(self, clientdata)
-- Can read from all 4 locations
return modelfunctions.getfiledetails(clientdata.filename, function(filename)
local dir = posix.dirname(filename or "").."/"
@@ -224,27 +224,29 @@ function read_policyfile(self, clientdata)
end)
end
-function get_policyfile(self, clientdata)
+function mymodule.get_policyfile(self, clientdata)
-- Can only get (for editing) from /etc/ locations
return modelfunctions.getfiledetails(clientdata.filename, validateeditablefile)
end
-function update_policyfile(self, filedetails)
+function mymodule.update_policyfile(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, validateeditablefile, validatefiledetails)
end
-function get_enablepolicy(self, clientdata)
+function mymodule.get_enablepolicy(self, clientdata)
local policy = {}
policy.name = cfe({ value=clientdata.name or "", label="Name", seq=1 })
return cfe({ type="group", value=policy, label="Policy" })
end
-function enable_policy(self, enable)
+function mymodule.enable_policy(self, enable)
enable.descr, enable.errtxt = modelfunctions.run_executable({"awall", "enable", enable.value.name.value}, true)
return enable
end
-function disable_policy(self, disable)
+function mymodule.disable_policy(self, disable)
disable.descr, disable.errtxt = modelfunctions.run_executable({"awall", "disable", disable.value.name.value}, true)
return disable
end
+
+return mymodule