summaryrefslogtreecommitdiffstats
path: root/awall-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'awall-model.lua')
-rw-r--r--awall-model.lua65
1 files changed, 33 insertions, 32 deletions
diff --git a/awall-model.lua b/awall-model.lua
index 4cf52aa..f836b4d 100644
--- a/awall-model.lua
+++ b/awall-model.lua
@@ -86,31 +86,32 @@ function getstatus()
return cfe({ type="group", value=status, label="AWall Status" })
end
-function 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)
- if not action then
- startstop.errtxt = "Invalid Action"
- else
+function startstop_service(action)
+ local result = {}
+ result.actions = cfe({ type="list", value={"Verify", "Translate", "Activate"}, label="Start/Stop actions" })
+ if action then
+ result.result = cfe({ label="Start/Stop result" })
+
local cmd
- if action == "Verify" then
+ if (string.lower(action) == "verify") then
cmd = path.."awall translate -V 2>&1"
- elseif action == "Translate" then
+ elseif (string.lower(action) == "translate") then
cmd = path.."awall translate 2>&1"
- else
+ elseif (string.lower(action) == "activate") then
cmd = path.."awall activate -f 2>&1"
+ else
+ result.result.errtxt = "Unknown command!"
end
- local f = io.popen(cmd)
- startstop.descr = f:read("*a")
- if startstop.descr == "" then
- startstop.descr = "Success"
+ if cmd then
+ local f = io.popen(cmd)
+ result.result.value = f:read("*a")
+ if result.result.value == "" then
+ result.result.value = "Success"
+ end
+ f:close()
end
- f:close()
end
- return startstop
+ return cfe({ type="group", value=result, label="Start/Stop result" })
end
function list_policies()
@@ -170,7 +171,7 @@ function get_newpolicy()
return cfe({ type="group", value=newpolicy, label="New Policy" })
end
-function create_policy(self, newpolicy)
+function create_policy(newpolicy)
local success = true
local name = newpolicy.value.name.value
@@ -211,13 +212,13 @@ function create_policy(self, newpolicy)
return newpolicy
end
-function get_delete_policy(self, clientdata)
+function get_delete_policy()
retval = {}
- retval.filename = cfe({ value=clientdata.filename or "", label="File Name" })
+ retval.filename = cfe({ label="File Name" })
return cfe({ type="group", value=retval, label="Delete Policy File" })
end
-function delete_policy(self, delpolicy)
+function delete_policy(delpolicy)
if validateeditablefile(delpolicy.value.filename.value) then
os.remove(delpolicy.value.filename.value)
else
@@ -228,9 +229,9 @@ function delete_policy(self, delpolicy)
return delpolicy
end
-function read_policyfile(self, clientdata)
+function read_policyfile(filename)
-- Can read from all 4 locations
- return modelfunctions.getfiledetails(clientdata.filename, function(filename)
+ return modelfunctions.getfiledetails(filename, function(filename)
local dir = posix.dirname(filename or "").."/"
if string.find(filename, "%.json$") and (dir==etcpath or dir==etcoptionalpath or dir==usrpath or dir==usroptionalpath) then
return true
@@ -240,22 +241,22 @@ function read_policyfile(self, clientdata)
end)
end
-function get_policyfile(self, clientdata)
+function get_policyfile(filename)
-- Can only get (for editing) from /etc/ locations
- return modelfunctions.getfiledetails(clientdata.filename, validateeditablefile)
+ return modelfunctions.getfiledetails(filename, validateeditablefile)
end
-function update_policyfile(self, filedetails)
- return modelfunctions.setfiledetails(self, filedetails, validateeditablefile, validatefiledetails)
+function update_policyfile(filedetails)
+ return modelfunctions.setfiledetails(filedetails, validateeditablefile, validatefiledetails)
end
-function get_enablepolicy(self, clientdata)
+function get_enablepolicy()
local policy = {}
- policy.name = cfe({ value=clientdata.name or "", label="Name", seq=1 })
+ policy.name = cfe({ label="Name", seq=1 })
return cfe({ type="group", value=policy, label="Policy" })
end
-function enable_policy(self, enable)
+function enable_policy(enable)
local cmd = path.."awall enable "..format.escapespecialcharacters(enable.value.name.value).." 2>&1"
local f = io.popen(cmd)
local result = f:read("*a")
@@ -266,7 +267,7 @@ function enable_policy(self, enable)
return enable
end
-function disable_policy(self, disable)
+function disable_policy(disable)
local cmd = path.."awall disable "..format.escapespecialcharacters(disable.value.name.value).." 2>&1"
local f = io.popen(cmd)
local result = f:read("*a")