Commit da7f4cb2 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

dump level 4 prints generated files

parent caa5010a
......@@ -60,7 +60,7 @@ List optional policies:
Dump variable and zone definitions:
awall dump [level]
Verbosity level is an integer in range 0-3 and defaults to 0.
Verbosity level is an integer in range 0-4 and defaults to 0.
]])
os.exit()
......@@ -170,7 +170,7 @@ if mode == 'dump' then
end
end
os.exit()
if level < 4 then os.exit() end
end
......@@ -179,7 +179,11 @@ awall.loadmodules(basedir)
config = awall.Config.new(config)
if mode == 'translate' then
if mode == 'dump' then
config:print()
elseif mode == 'translate' then
if verify then config:test() end
config:dump(iptdir, ipsfile)
......
......@@ -111,6 +111,12 @@ function Config:init(policyconfig)
self.ipset = ipset.IPSet.new(self.input.ipset)
end
function Config:print()
self.ipset:print()
print()
self.iptables:print()
end
function Config:dump(iptdir, ipsfile)
self.ipset:dump(ipsfile or '/etc/ipset.d/awall')
self.iptables:dump(iptdir or '/etc/iptables')
......
......@@ -14,7 +14,7 @@ IPSet = awall.object.class(awall.object.Object)
function IPSet:init(config) self.config = config end
function IPSet:commands()
local res = {}
local res = {'# ipset file generated by awall\n'}
if self.config then
for name, ipset in pairs(self.config) do
if not ipset.type then ipset:error('Type not defined') end
......@@ -37,8 +37,13 @@ function IPSet:create()
end
end
function IPSet:print(file)
if not file then file = io.stdout end
for i, line in ipairs(self:commands()) do file:write(line) end
end
function IPSet:dump(ipsfile)
local file = io.output(ipsfile)
for i, line in ipairs(self:commands()) do file:write(line) end
self:print(file)
file:close()
end
......@@ -34,6 +34,13 @@ local backupdir = '/var/run/awall'
local BaseIPTables = class(awall.object.Object)
function BaseIPTables:print()
for family, tbls in pairs(families) do
self:dumpfile(family, io.stdout)
print()
end
end
function BaseIPTables:dump(dir)
for family, tbls in pairs(families) do
local file = io.output(dir..'/'..families[family].file)
......
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