Commit 20407dfd authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

helper function for printing to stderr

parent 2f835190
...@@ -116,6 +116,7 @@ end ...@@ -116,6 +116,7 @@ end
util = require('awall.util') util = require('awall.util')
contains = util.contains contains = util.contains
printmsg = util.printmsg
if not contains( if not contains(
{ {
...@@ -283,7 +284,7 @@ if not call( ...@@ -283,7 +284,7 @@ if not call(
elseif mode == 'diff' then elseif mode == 'diff' then
if not posix.stat(dumpfile) 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) os.exit(1)
end end
...@@ -351,15 +352,15 @@ if not call( ...@@ -351,15 +352,15 @@ if not call(
if call(config.activate, config) then if call(config.activate, config) then
if not force 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: ') io.stderr:write('Press RETURN to commit changes permanently: ')
interrupted = not io.read() interrupted = not io.read()
kill() kill()
if interrupted then if interrupted then
io.stderr:write( printmsg(
'\nActivation canceled, reverting to the old configuration\n' '\nActivation canceled, reverting to the old configuration'
) )
revert() revert()
end end
...@@ -382,7 +383,7 @@ if not call( ...@@ -382,7 +383,7 @@ if not call(
posix.sleep(10) posix.sleep(10)
io.stderr:write('\nTimeout, reverting to the old configuration\n') printmsg('\nTimeout, reverting to the old configuration')
iptables.revert() iptables.revert()
elseif mode == 'flush' then iptables.flush() elseif mode == 'flush' then iptables.flush()
......
--[[ --[[
Ipset file dumper for Alpine Wall Ipset file dumper for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
local sortedkeys = require('awall.util').sortedkeys local util = require('awall.util')
local IPSet = require('awall.class')() local IPSet = require('awall.class')()
...@@ -24,13 +24,13 @@ function IPSet:create() ...@@ -24,13 +24,13 @@ function IPSet:create()
'ipset', '-!', 'create', name, table.unpack(ipset.options) 'ipset', '-!', 'create', name, table.unpack(ipset.options)
) )
if lpc.wait(pid) ~= 0 then if lpc.wait(pid) ~= 0 then
io.stderr:write('ipset creation failed: '..name) util.printmsg('ipset creation failed: '..name)
end end
end end
end end
function IPSet:print() function IPSet:print()
for _, name in sortedkeys(self.config) do for _, name in util.sortedkeys(self.config) do
self:dumpfile(name, io.output()) self:dumpfile(name, io.output())
io.write('\n') io.write('\n')
end end
......
--[[ --[[
Iptables file dumper for Alpine Wall Iptables file dumper for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
...@@ -9,6 +9,7 @@ local class = require('awall.class') ...@@ -9,6 +9,7 @@ local class = require('awall.class')
local raise = require('awall.uerror').raise local raise = require('awall.uerror').raise
local util = require('awall.util') local util = require('awall.util')
local printmsg = util.printmsg
local sortedkeys = util.sortedkeys local sortedkeys = util.sortedkeys
...@@ -71,9 +72,7 @@ function BaseIPTables:restore(test) ...@@ -71,9 +72,7 @@ function BaseIPTables:restore(test)
disabled = false disabled = false
elseif test then elseif test then printmsg('Warning: '..family..' rules not tested') end
io.stderr:write('Warning: '..family..' rules not tested\n')
end
end end
if disabled then raise('Firewall not enabled in kernel') end if disabled then raise('Firewall not enabled in kernel') end
...@@ -159,11 +158,7 @@ function M.flush() ...@@ -159,11 +158,7 @@ function M.flush()
for i, chain in ipairs(M.builtin[tbl]) do for i, chain in ipairs(M.builtin[tbl]) do
empty.config[family][tbl][chain] = {} empty.config[family][tbl][chain] = {}
end end
else else printmsg('Warning: not flushing unknown table: '..tbl) end
io.stderr:write(
'Warning: not flushing unknown table: '..tbl..'\n'
)
end
end end
end end
end end
......
--[[ --[[
Base data model for Alpine Wall Base data model for Alpine Wall
Copyright (C) 2012-2015 Kaarle Ritvanen Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
...@@ -84,7 +84,7 @@ end ...@@ -84,7 +84,7 @@ end
function M.ConfigObject:error(msg) raise(self.location..': '..msg) end function M.ConfigObject:error(msg) raise(self.location..': '..msg) end
function M.ConfigObject:warning(msg) function M.ConfigObject:warning(msg)
io.stderr:write(self.location..': '..msg..'\n') util.printmsg(self.location..': '..msg)
end end
function M.ConfigObject:trules() return {} end function M.ConfigObject:trules() return {} end
......
--[[ --[[
User error handling for Alpine Wall User error handling for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
local printmsg = require('awall.util').printmsg
local M = {} local M = {}
local prefix = 'awall user error: ' local prefix = 'awall user error: '
...@@ -18,8 +21,8 @@ function M.call(f, ...) ...@@ -18,8 +21,8 @@ function M.call(f, ...)
function(msg) function(msg)
local si, ei = msg:find(prefix, 1, true) local si, ei = msg:find(prefix, 1, true)
if si then msg = 'awall: '..msg:sub(ei + 1, -1) end if si then msg = 'awall: '..msg:sub(ei + 1, -1) end
io.stderr:write(msg..'\n') printmsg(msg)
if not si then io.stderr:write(debug.traceback()..'\n') end if not si then printmsg(debug.traceback()) end
end end
) )
end end
......
--[[ --[[
Utility module for Alpine Wall Utility module for Alpine Wall
Copyright (C) 2012-2015 Kaarle Ritvanen Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
...@@ -142,4 +142,7 @@ end ...@@ -142,4 +142,7 @@ end
function M.printtabular(tbl) M.printtabulars({tbl}) end function M.printtabular(tbl) M.printtabulars({tbl}) end
function M.printmsg(msg) io.stderr:write(msg..'\n') end
return M return M
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment