aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2016-07-17 17:51:21 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2016-07-17 23:50:51 +0300
commit20407dfd6bb00e9c3459a5d84720a20899c0a381 (patch)
tree6787640c14049ebfd64f3052d59d50df4157d8d5
parent2f83519036b4ad3f11a29bd2ab73205e18c75525 (diff)
downloadawall-20407dfd6bb00e9c3459a5d84720a20899c0a381.tar.bz2
awall-20407dfd6bb00e9c3459a5d84720a20899c0a381.tar.xz
helper function for printing to stderr
-rwxr-xr-xawall-cli11
-rw-r--r--awall/ipset.lua8
-rw-r--r--awall/iptables.lua13
-rw-r--r--awall/model.lua4
-rw-r--r--awall/uerror.lua9
-rw-r--r--awall/util.lua5
6 files changed, 26 insertions, 24 deletions
diff --git a/awall-cli b/awall-cli
index 220bc8b..e1b0cd5 100755
--- a/awall-cli
+++ b/awall-cli
@@ -116,6 +116,7 @@ end
util = require('awall.util')
contains = util.contains
+printmsg = util.printmsg
if not contains(
{
@@ -283,7 +284,7 @@ if not call(
elseif mode == 'diff' then
if not posix.stat(dumpfile) then
- io.stderr:write('Please translate or activate first\n')
+ printmsg('Please translate or activate first')
os.exit(1)
end
@@ -351,15 +352,15 @@ if not call(
if call(config.activate, config) then
if not force then
- io.stderr:write('New firewall configuration activated\n')
+ printmsg('New firewall configuration activated')
io.stderr:write('Press RETURN to commit changes permanently: ')
interrupted = not io.read()
kill()
if interrupted then
- io.stderr:write(
- '\nActivation canceled, reverting to the old configuration\n'
+ printmsg(
+ '\nActivation canceled, reverting to the old configuration'
)
revert()
end
@@ -382,7 +383,7 @@ if not call(
posix.sleep(10)
- io.stderr:write('\nTimeout, reverting to the old configuration\n')
+ printmsg('\nTimeout, reverting to the old configuration')
iptables.revert()
elseif mode == 'flush' then iptables.flush()
diff --git a/awall/ipset.lua b/awall/ipset.lua
index 081ba97..5f7b9b3 100644
--- a/awall/ipset.lua
+++ b/awall/ipset.lua
@@ -1,11 +1,11 @@
--[[
Ipset file dumper for Alpine Wall
-Copyright (C) 2012-2014 Kaarle Ritvanen
+Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--
-local sortedkeys = require('awall.util').sortedkeys
+local util = require('awall.util')
local IPSet = require('awall.class')()
@@ -24,13 +24,13 @@ function IPSet:create()
'ipset', '-!', 'create', name, table.unpack(ipset.options)
)
if lpc.wait(pid) ~= 0 then
- io.stderr:write('ipset creation failed: '..name)
+ util.printmsg('ipset creation failed: '..name)
end
end
end
function IPSet:print()
- for _, name in sortedkeys(self.config) do
+ for _, name in util.sortedkeys(self.config) do
self:dumpfile(name, io.output())
io.write('\n')
end
diff --git a/awall/iptables.lua b/awall/iptables.lua
index b1303b8..662a7d9 100644
--- a/awall/iptables.lua
+++ b/awall/iptables.lua
@@ -1,6 +1,6 @@
--[[
Iptables file dumper for Alpine Wall
-Copyright (C) 2012-2014 Kaarle Ritvanen
+Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -9,6 +9,7 @@ local class = require('awall.class')
local raise = require('awall.uerror').raise
local util = require('awall.util')
+local printmsg = util.printmsg
local sortedkeys = util.sortedkeys
@@ -71,9 +72,7 @@ function BaseIPTables:restore(test)
disabled = false
- elseif test then
- io.stderr:write('Warning: '..family..' rules not tested\n')
- end
+ elseif test then printmsg('Warning: '..family..' rules not tested') end
end
if disabled then raise('Firewall not enabled in kernel') end
@@ -159,11 +158,7 @@ function M.flush()
for i, chain in ipairs(M.builtin[tbl]) do
empty.config[family][tbl][chain] = {}
end
- else
- io.stderr:write(
- 'Warning: not flushing unknown table: '..tbl..'\n'
- )
- end
+ else printmsg('Warning: not flushing unknown table: '..tbl) end
end
end
end
diff --git a/awall/model.lua b/awall/model.lua
index 648de6c..982a35e 100644
--- a/awall/model.lua
+++ b/awall/model.lua
@@ -1,6 +1,6 @@
--[[
Base data model for Alpine Wall
-Copyright (C) 2012-2015 Kaarle Ritvanen
+Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -84,7 +84,7 @@ end
function M.ConfigObject:error(msg) raise(self.location..': '..msg) end
function M.ConfigObject:warning(msg)
- io.stderr:write(self.location..': '..msg..'\n')
+ util.printmsg(self.location..': '..msg)
end
function M.ConfigObject:trules() return {} end
diff --git a/awall/uerror.lua b/awall/uerror.lua
index 7282b6e..750f2cb 100644
--- a/awall/uerror.lua
+++ b/awall/uerror.lua
@@ -1,10 +1,13 @@
--[[
User error handling for Alpine Wall
-Copyright (C) 2012-2014 Kaarle Ritvanen
+Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--
+local printmsg = require('awall.util').printmsg
+
+
local M = {}
local prefix = 'awall user error: '
@@ -18,8 +21,8 @@ function M.call(f, ...)
function(msg)
local si, ei = msg:find(prefix, 1, true)
if si then msg = 'awall: '..msg:sub(ei + 1, -1) end
- io.stderr:write(msg..'\n')
- if not si then io.stderr:write(debug.traceback()..'\n') end
+ printmsg(msg)
+ if not si then printmsg(debug.traceback()) end
end
)
end
diff --git a/awall/util.lua b/awall/util.lua
index 0057cd2..909e3fb 100644
--- a/awall/util.lua
+++ b/awall/util.lua
@@ -1,6 +1,6 @@
--[[
Utility module for Alpine Wall
-Copyright (C) 2012-2015 Kaarle Ritvanen
+Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -142,4 +142,7 @@ end
function M.printtabular(tbl) M.printtabulars({tbl}) end
+
+function M.printmsg(msg) io.stderr:write(msg..'\n') end
+
return M