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

helper function for printing to stderr

parent 2f835190
......@@ -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()
......
--[[
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
......
--[[
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
......
--[[
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
......
--[[
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
......
--[[
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
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