aboutsummaryrefslogtreecommitdiffstats
path: root/awall-cli
diff options
context:
space:
mode:
Diffstat (limited to 'awall-cli')
-rwxr-xr-xawall-cli42
1 files changed, 34 insertions, 8 deletions
diff --git a/awall-cli b/awall-cli
index c70519e..25b64eb 100755
--- a/awall-cli
+++ b/awall-cli
@@ -11,26 +11,33 @@ require 'lfs'
require 'signal'
require 'stringy'
-short_opts = 'aFo:V'
+short_opts = 'ad:e:Flo:V'
long_opts = {activate='a',
+ disable='d',
+ enable='e',
+ list='l',
['output-dir']='o',
verify='V'}
+params = {d = {}, e = {}}
+
if stringy.endswith(arg[0], '/awall-cli') then
basedir = string.sub(arg[0], 1, -11)
- input = {basedir..'/json'}
- import = {}
+ params.i = {basedir..'/json'}
+ params.I = {}
short_opts = short_opts..'i:I:'
long_opts['input-dir'] = 'i'
long_opts['import-path'] = 'I'
end
+require 'awall.util'
+
for switch, value in pairs(alt_getopt.get_opts(arg, short_opts, long_opts)) do
- if switch == 'a' then activate = true
+ if awall.util.contains({'a', 'l'}, switch) then mode = switch
+ elseif awall.util.contains({'d', 'e', 'i', 'I'}, switch) then
+ table.insert(awall.util.params[switch], value)
elseif switch == 'F' then fallback = true
- elseif switch == 'i' then table.insert(input, value)
- elseif switch == 'I' then table.insert(import, value)
elseif switch == 'o' then
iptdir = value
ipsfile = value..'/ipset'
@@ -39,14 +46,33 @@ for switch, value in pairs(alt_getopt.get_opts(arg, short_opts, long_opts)) do
end
+require 'awall.policy'
+
+for i, action in ipairs({'disable', 'enable'}) do
+ for i, policy in ipairs(params[string.sub(action, 1, 1)]) do
+ policyset = policyset or awall.policy.PolicySet.new(params.i, params.I)
+ policyset[action](policyset, policy, confdir, import)
+ end
+end
+if policyset then os.exit() end
+
+if mode == 'l' then
+ for name, status in awall.policy.PolicySet.new(params.i,
+ params.I):list() do
+ print(name, status)
+ end
+ os.exit()
+end
+
+
require 'awall'
require 'awall.iptables'
awall.loadmodules(basedir)
-config = awall.Config.new(input, import)
+config = awall.Config.new(params.i, params.I)
-if activate then
+if mode == 'a' then
awall.iptables.backup()