diff options
Diffstat (limited to 'awall-cli')
-rwxr-xr-x | awall-cli | 48 |
1 files changed, 35 insertions, 13 deletions
@@ -51,7 +51,9 @@ List optional policies: another policy which is in use. Dump variable and zone definitions: - awall dump + awall dump [level] + + Verbosity level is an integer in range 0-3 and defaults to 0. ]]) os.exit() @@ -121,22 +123,42 @@ end config = policyset:load() if mode == 'dump' then + level = 0 + (arg[opind] or 0) + require 'json' expconfig = config:expand() - for i, section in ipairs({'variable', 'zone'}) do - if config.data[section] then - print(string.upper(string.sub(section, 1, 1))..string.sub(section, 2, -1)..'s:') - lines = {} - for k, v in pairs(config.data[section]) do - def = json.encode(v) - exp = json.encode(expconfig[section][k]) - if exp ~= def then def = def..' = '..exp end - table.insert(lines, k..' = '..def..' ('..config.source[section][k]..')') + function capitalize(cls) + return string.upper(string.sub(cls, 1, 1))..string.sub(cls, 2, -1) + end + + for cls, objs in pairs(config.data) do + if level > 2 or (level == 2 and cls ~= 'service') or util.contains({'variable', + 'zone'}, + cls) then + if level == 0 then print(capitalize(cls)..'s:') end + + items = {} + for k, v in pairs(objs) do + exp = expconfig[cls][k] + expj = json.encode(exp) + src = config.source[cls][k] + if level == 0 then table.insert(items, {k, expj, src}) + else + table.insert(items, + {k, {{capitalize(cls)..' '..k, json.encode(v)}, + {'('..src..')', + util.compare(exp, v) and '' or '-> '..expj}}}) + end + end + table.sort(items, function(a, b) return a[1] < b[1] end) + + if level == 0 then util.printtabular(items) + else + util.printtabulars(util.map(items, + function(x) return x[2] end)) + print() end - table.sort(lines) - for i, line in ipairs(lines) do print(line) end - print() end end |