aboutsummaryrefslogtreecommitdiffstats
path: root/awall-cli
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-31 14:49:51 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-31 19:07:51 +0300
commit8e0c7cb2607622cf601c90e691ef7ef4380779f4 (patch)
tree0e314a7f3cb075b6d223d99cb171e585ccb7280b /awall-cli
parent8d1004410f11f0c67fd296b75abe3f8738437334 (diff)
downloadawall-8e0c7cb2607622cf601c90e691ef7ef4380779f4.tar.bz2
awall-8e0c7cb2607622cf601c90e691ef7ef4380779f4.tar.xz
eliminate deprecated module style
Diffstat (limited to 'awall-cli')
-rwxr-xr-xawall-cli67
1 files changed, 39 insertions, 28 deletions
diff --git a/awall-cli b/awall-cli
index 9f7dd28..a71f5fb 100755
--- a/awall-cli
+++ b/awall-cli
@@ -6,10 +6,9 @@ Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
-require 'alt_getopt'
-require 'lfs'
-require 'signal'
-require 'stringy'
+get_opts = require('alt_getopt').get_opts
+signal = require('signal')
+stringy = require('stringy')
function help()
io.stderr:write([[
@@ -78,7 +77,7 @@ if not stringy.startswith(arg[1], '-') then
table.remove(arg, 1)
end
-opts, opind = alt_getopt.get_opts(
+opts, opind = get_opts(
arg,
'afo:V',
{all='a', force='f', ['output-dir']='o', verify='V'}
@@ -98,12 +97,22 @@ if not mode then
end
-require 'awall.util'
-util = awall.util
+util = require('awall.util')
+contains = util.contains
-if not util.contains({'translate', 'activate', 'fallback', 'flush',
- 'enable', 'disable', 'list', 'dump'},
- mode) then help() end
+if not contains(
+ {
+ 'translate',
+ 'activate',
+ 'fallback',
+ 'flush',
+ 'enable',
+ 'disable',
+ 'list',
+ 'dump'
+ },
+ mode
+) then help() end
pol_paths = {}
for i, cls in ipairs{'mandatory', 'optional', 'private'} do
@@ -119,12 +128,14 @@ if stringy.endswith(arg[0], '/awall-cli') then
table.insert(pol_paths.mandatory, basedir..'/json')
end
-local uerror = require('awall.uerror')
+uerror = require('awall.uerror')
+call = uerror.call
-if not uerror.call(
+if not call(
function()
- require 'awall'
+ local awall = require('awall')
+ local printtabular = util.printtabular
policyset = awall.PolicySet(pol_paths)
@@ -137,7 +148,7 @@ if not uerror.call(
if all or policy.type == 'optional' then
if policy.enabled then status = 'enabled'
- elseif util.contains(imported, name) then status = 'required'
+ elseif contains(imported, name) then status = 'required'
else status = 'disabled' end
polinfo = {name, status, policy:load().description}
@@ -151,11 +162,11 @@ if not uerror.call(
end
end
- util.printtabular(data)
+ printtabular(data)
os.exit()
end
- if util.contains({'disable', 'enable'}, mode) then
+ if contains({'disable', 'enable'}, mode) then
if opind > #arg then help() end
repeat
name = arg[opind]
@@ -178,10 +189,10 @@ if not uerror.call(
end
- require 'awall.iptables'
+ local iptables = require('awall.iptables')
if mode == 'dump' then
- require 'json'
+ local json = require('json')
expinput = input:expand()
function capitalize(cls)
@@ -189,7 +200,7 @@ if not uerror.call(
end
for cls, objs in pairs(input.data) do
- if level > 2 or (level == 2 and cls ~= 'service') or util.contains(
+ if level > 2 or (level == 2 and cls ~= 'service') or contains(
{'variable', 'zone'},
cls
) then
@@ -224,7 +235,7 @@ if not uerror.call(
end
table.sort(items, function(a, b) return a[1] < b[1] end)
- if level == 0 then util.printtabular(items)
+ if level == 0 then printtabular(items)
else
util.printtabulars(
util.map(items, function(x) return x[2] end)
@@ -242,7 +253,9 @@ if not uerror.call(
elseif mode == 'activate' then
- awall.iptables.backup()
+ local lpc = require('lpc')
+
+ iptables.backup()
if not force then
signal.signal(
@@ -261,7 +274,6 @@ if not uerror.call(
)
end
- require 'lpc'
pid, stdio, stdout = lpc.run(arg[0], 'fallback')
stdio:close()
stdout:close()
@@ -274,11 +286,11 @@ if not uerror.call(
end
function revert()
- awall.iptables.revert()
+ iptables.revert()
os.exit(1)
end
- if uerror.call(config.activate, config) then
+ if call(config.activate, config) then
if not force then
io.stderr:write('New firewall configuration activated\n')
@@ -309,13 +321,12 @@ if not uerror.call(
signal.signal('SIG'..sig, function() end)
end
- require 'lsleep'
- lsleep.sleep(10)
+ require('lsleep').sleep(10)
io.stderr:write('\nTimeout, reverting to the old configuration\n')
- awall.iptables.revert()
+ iptables.revert()
- elseif mode == 'flush' then awall.iptables.flush()
+ elseif mode == 'flush' then iptables.flush()
else assert(false) end