Commit 20ae74c3 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

command for dumping variable and zone definitions

parent 6b7e5230
......@@ -50,6 +50,9 @@ List optional policies:
enabled by the user but is in use because it is required by
another policy which is in use.
Dump variable and zone definitions:
awall dump
]])
os.exit()
end
......@@ -91,7 +94,7 @@ end
require 'awall.util'
if not awall.util.contains({'translate', 'activate', 'fallback',
'enable', 'disable', 'list'},
'enable', 'disable', 'list', 'dump'},
mode) then help() end
......@@ -115,8 +118,30 @@ if awall.util.contains({'disable', 'enable'}, mode) then
os.exit()
end
config = policyset:load()
if mode == 'dump' then
require 'json'
function dump(title, data)
print(title..':')
local lines = {}
for k, v in pairs(data) do
table.insert(lines, k..' = '..json.encode(v))
end
table.sort(lines)
for i, line in ipairs(lines) do print(line) end
print()
end
dump('Variables', config:variables())
config = config:expand()
dump('Zones', config.zone)
os.exit()
end
require 'awall.iptables'
awall.loadmodules(basedir)
......
......@@ -49,6 +49,14 @@ function PolicyConfig:eval(value)
return value ~= '' and value or nil
end
function PolicyConfig:variables()
local res = {}
for name, value in pairs(self.data.variable or {}) do
res[name] = self:eval('$'..name)
end
return res
end
function PolicyConfig:expand()
local function expand(obj)
......
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