diff options
author | Ted Trask <ttrask01@yahoo.com> | 2012-11-20 16:17:29 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2012-11-20 16:17:29 +0000 |
commit | bcad4853dd409c55f405465720d3abe6dbdce9e7 (patch) | |
tree | 86c73fee5ccb512dad091380c3c90f18ade2625d | |
parent | 27f34fe0b3fdbf568526cdac2f7fb2caa66d8403 (diff) | |
download | acf-awall-0.0-stable.tar.bz2 acf-awall-0.0-stable.tar.xz |
Backported to work with acf-core-0.14 and bumped version to 0.0.2v0.0.20.0-stable
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | awall-controller.lua | 19 | ||||
l--------- | awall-createpolicy-html.lsp | 1 | ||||
l--------- | awall-deletepolicy-html.lsp | 1 | ||||
l--------- | awall-disablepolicy-html.lsp | 1 | ||||
l--------- | awall-enablepolicy-html.lsp | 1 | ||||
-rw-r--r-- | awall-listpolicies-html.lsp | 12 | ||||
-rw-r--r-- | awall-model.lua | 65 | ||||
l--------- | awall-startstop-html.lsp | 1 |
9 files changed, 56 insertions, 47 deletions
@@ -1,6 +1,6 @@ APP_NAME=awall PACKAGE=acf-$(APP_NAME) -VERSION=0.0.1 +VERSION=0.0.2 APP_DIST=\ awall* \ diff --git a/awall-controller.lua b/awall-controller.lua index 9fa56a1..9e356f8 100644 --- a/awall-controller.lua +++ b/awall-controller.lua @@ -1,13 +1,16 @@ module(..., package.seeall) -default_action = "status" +-- Load libraries +require("controllerfunctions") +default_action = "status" + function status(self) return self.model.getstatus() end function startstop(self) - return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.clientdata) end function listpolicies(self) @@ -15,25 +18,25 @@ function listpolicies(self) end function viewpolicy(self) - return self.model.read_policyfile(self, clientdata) + return self.model.read_policyfile(self.clientdata.filename) end function 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") + return controllerfunctions.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) - return self.handle_form(self, self.model.get_delete_policy, self.model.delete_policy, self.clientdata, "Delete", "Delete Policy File", "Policy File Deleted") + return controllerfunctions.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) - return self.handle_form(self, self.model.get_policyfile, self.model.update_policyfile, self.clientdata, "Save", "Edit Policy", "Policy File Saved") + return controllerfunctions.handle_form(self, function() return self.model.get_policyfile(self.clientdata.filename) end, self.model.update_policyfile, self.clientdata, "Save", "Edit Policy", "Policy File Saved") end function enablepolicy(self) - return self.handle_form(self, self.model.get_enablepolicy, self.model.enable_policy, self.clientdata, "Enable", "Enable Policy", "Policy Enabled") + return controllerfunctions.handle_form(self, self.model.get_enablepolicy, self.model.enable_policy, self.clientdata, "Enable", "Enable Policy", "Policy Enabled") end function disablepolicy(self) - return self.handle_form(self, self.model.get_enablepolicy, self.model.disable_policy, self.clientdata, "Disable", "Disable Policy", "Policy Disabled") + return controllerfunctions.handle_form(self, self.model.get_enablepolicy, self.model.disable_policy, self.clientdata, "Disable", "Disable Policy", "Policy Disabled") end diff --git a/awall-createpolicy-html.lsp b/awall-createpolicy-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/awall-createpolicy-html.lsp @@ -0,0 +1 @@ +../form-html.lsp
\ No newline at end of file diff --git a/awall-deletepolicy-html.lsp b/awall-deletepolicy-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/awall-deletepolicy-html.lsp @@ -0,0 +1 @@ +../form-html.lsp
\ No newline at end of file diff --git a/awall-disablepolicy-html.lsp b/awall-disablepolicy-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/awall-disablepolicy-html.lsp @@ -0,0 +1 @@ +../form-html.lsp
\ No newline at end of file diff --git a/awall-enablepolicy-html.lsp b/awall-enablepolicy-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/awall-enablepolicy-html.lsp @@ -0,0 +1 @@ +../form-html.lsp
\ No newline at end of file diff --git a/awall-listpolicies-html.lsp b/awall-listpolicies-html.lsp index 1d807e9..25a94d0 100644 --- a/awall-listpolicies-html.lsp +++ b/awall-listpolicies-html.lsp @@ -1,5 +1,5 @@ <% local form, viewlibrary, page_info, session = ... -require("htmlviewfunctions") +require("viewfunctions") html = require("acf.html") %> @@ -11,8 +11,8 @@ html = require("acf.html") }); </script> -<% htmlviewfunctions.displaycommandresults({"deletepolicy", "editpolicy", "viewpolicy", "enablepolicy", "disablepolicy", "startstop"}, session) %> -<% htmlviewfunctions.displaycommandresults({"createpolicy"}, session, true) %> +<% displaycommandresults({"deletepolicy", "editpolicy", "viewpolicy", "enablepolicy", "disablepolicy", "startstop"}, session) %> +<% displaycommandresults({"createpolicy"}, session, true) %> <h1>Policies</h1> <DL> @@ -28,11 +28,11 @@ html = require("acf.html") <TR> <TD style="padding-right:20px;white-space:nowrap;"> <% - if viewlibrary.check_permission("deletepolicy") and pol.editable and pol.status ~= "enabled" and pol.status ~= "required" then io.write(html.link{value = "deletepolicy?submit=true&filename=" .. pol.filename, label="Delete ", class="deletepolicy" }) end + if viewlibrary.check_permission("deletepolicy") and pol.editable and pol.status ~= "enabled" and pol.status ~= "required" then io.write(html.link{value = "deletepolicy?Delete=true&filename=" .. pol.filename, label="Delete ", class="deletepolicy" }) end if viewlibrary.check_permission("editpolicy") and pol.editable then io.write(html.link{value = "editpolicy?filename=" .. pol.filename.."&redir="..page_info.orig_action, label="Edit " }) end if viewlibrary.check_permission("viewpolicy") and not pol.editable and pol.filename then io.write(html.link{value = "viewpolicy?filename=" .. pol.filename.."&redir="..page_info.orig_action, label="View " }) end - if viewlibrary.check_permission("enablepolicy") and (pol.status == "disabled" or pol.status == "required") then io.write(html.link{value = "enablepolicy?submit=true&name=" .. pol.name, label="Enable " }) end - if viewlibrary.check_permission("disablepolicy") and pol.status == "enabled" then io.write(html.link{value = "disablepolicy?submit=true&name=" .. pol.name, label="Disable " }) end + if viewlibrary.check_permission("enablepolicy") and (pol.status == "disabled" or pol.status == "required") then io.write(html.link{value = "enablepolicy?Enable=true&name=" .. pol.name, label="Enable " }) end + if viewlibrary.check_permission("disablepolicy") and pol.status == "enabled" then io.write(html.link{value = "disablepolicy?Disable=true&name=" .. pol.name, label="Disable " }) end %> </TD> <TD style="white-space:nowrap;" width="90%"><%= html.html_escape(string.gsub(pol.status or "", "^%l", string.upper)) %></TD> 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") diff --git a/awall-startstop-html.lsp b/awall-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/awall-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp
\ No newline at end of file |