diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2012-07-13 12:28:24 +0000 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2012-07-13 12:28:24 +0000 |
commit | da7f4cb2b03eed2999c7b76dc05a6e6eff8ab511 (patch) | |
tree | 7b16f91d423bbee59877db5c004e197903b1d5c4 | |
parent | caa5010add951a604943d99fcce852cc30389143 (diff) | |
download | awall-da7f4cb2b03eed2999c7b76dc05a6e6eff8ab511.tar.bz2 awall-da7f4cb2b03eed2999c7b76dc05a6e6eff8ab511.tar.xz |
dump level 4 prints generated files
-rwxr-xr-x | awall-cli | 10 | ||||
-rw-r--r-- | awall/init.lua | 6 | ||||
-rw-r--r-- | awall/ipset.lua | 9 | ||||
-rw-r--r-- | awall/iptables.lua | 7 |
4 files changed, 27 insertions, 5 deletions
@@ -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) diff --git a/awall/init.lua b/awall/init.lua index 9787c53..8ec2797 100644 --- a/awall/init.lua +++ b/awall/init.lua @@ -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') diff --git a/awall/ipset.lua b/awall/ipset.lua index 68e7293..73dea04 100644 --- a/awall/ipset.lua +++ b/awall/ipset.lua @@ -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 diff --git a/awall/iptables.lua b/awall/iptables.lua index 4118ffe..78dc48d 100644 --- a/awall/iptables.lua +++ b/awall/iptables.lua @@ -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) |