summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2012-12-25 01:45:58 +0000
committerTed Trask <ttrask01@yahoo.com>2012-12-25 01:45:58 +0000
commitc86539f56cbacfb13162f7274802c573fe52db04 (patch)
treedfd0e01254fa32995ac12e1bca878119727fb058
parent395f0127a4bf665f54944cf188d54234e8e1551d (diff)
downloadacf-awall-c86539f56cbacfb13162f7274802c573fe52db04.tar.bz2
acf-awall-c86539f56cbacfb13162f7274802c573fe52db04.tar.xz
Replace io.popen with modelfunctions.run_executable calls
-rw-r--r--awall-model.lua39
1 files changed, 12 insertions, 27 deletions
diff --git a/awall-model.lua b/awall-model.lua
index 4b2bff8..479fd3d 100644
--- a/awall-model.lua
+++ b/awall-model.lua
@@ -84,20 +84,20 @@ function startstop_service(self, startstop, action)
if not action then
startstop.errtxt = "Invalid Action"
else
- local cmd
+ local cmd = {"awall"}
if action == "Verify" then
- cmd = path.."awall translate -V 2>&1"
+ cmd[#cmd+1] = "translate"
+ cmd[#cmd+1] = "-V"
elseif action == "Translate" then
- cmd = path.."awall translate 2>&1"
+ cmd[#cmd+1] = "translate"
else
- cmd = path.."awall activate -f 2>&1"
+ cmd[#cmd+1] = "activate"
+ cmd[#cmd+1] = "-f"
end
- local f = io.popen(cmd)
- startstop.descr = f:read("*a")
- if startstop.descr == "" then
+ startstop.descr, startstop.errtxt = modelfunctions.run_executable(cmd, true)
+ if not startstop.errtxt and startstop.descr == "" then
startstop.descr = "Success"
end
- f:close()
end
return startstop
end
@@ -107,9 +107,8 @@ function list_policies()
local policies = {}
local reversepolicies = {}
local errtxt
- local cmd = path.."awall list 2>&1"
- local f = io.popen(cmd)
- for l in f:lines() do
+ local f = modelfunctions.run_executable({"awall", "list"}, true)
+ for l in string.match(f, "[^\n]+") do
local a,b,c = string.match(l, "(%S+)%s+(%S+)%s*(.*)")
if a and a == "/usr/bin/lua:" then
errtxt = b.." "..c
@@ -120,7 +119,6 @@ function list_policies()
reversepolicies[a] = #policies
end
end
- f:close()
-- Since awall seems to crash (and not give results) when there is any error
-- Let's show the actual files too
local addfiles = function(files, editable, mandatory)
@@ -245,23 +243,10 @@ function get_enablepolicy(self, clientdata)
end
function enable_policy(self, enable)
- local cmd = path.."awall enable "..format.escapespecialcharacters(enable.value.name.value).." 2>&1"
- local f = io.popen(cmd)
- local result = f:read("*a")
- f:close()
- if result ~= "" then
- enable.errtxt = result
- end
+ enable.descr, enable.errtxt = modelfunctions.run_executable({"awall", "enable", enable.value.name.value}, true)
return enable
end
function disable_policy(self, disable)
- local cmd = path.."awall disable "..format.escapespecialcharacters(disable.value.name.value).." 2>&1"
- local f = io.popen(cmd)
- local result = f:read("*a")
- f:close()
- if result ~= "" then
- disable.errtxt = result
- end
- return disable
+ disable.descr, disable.errtxt = modelfunctions.run_executable({"awall", "disable", disable.value.name.value}, true)
end