From 1bc58d4a16cc7f3e8af1f08a187f264d3df98e28 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Tue, 1 May 2012 11:18:46 +0000 Subject: policy file description attribute --- awall-cli | 4 +++- awall/policy.lua | 24 +++++++++++++++--------- sample-policy.json | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/awall-cli b/awall-cli index c2603b5..121aa9e 100755 --- a/awall-cli +++ b/awall-cli @@ -100,7 +100,9 @@ require 'awall' policyset = awall.PolicySet.new(params.i, params.I) if mode == 'list' then - for name, status in policyset:list() do print(name, status) end + for name, status, desc in policyset:list() do + print(name, status, desc) + end os.exit() end diff --git a/awall/policy.lua b/awall/policy.lua index 572ff60..af00ace 100644 --- a/awall/policy.lua +++ b/awall/policy.lua @@ -73,6 +73,17 @@ function PolicySet:init(confdirs, importdirs) end +function PolicySet:loadJSON(name, fname) + local file = fname and io.open(fname) or open(name, self.importdirs) + if not file then error('Import failed: '..name) end + + local data = '' + for line in file:lines() do data = data..line end + file:close() + return json.decode(data) +end + + function PolicySet:load() local input = {} @@ -86,20 +97,15 @@ function PolicySet:load() error('Circular import: '..name) end - local file = fname and io.open(fname) or open(name, self.importdirs) - if not file then error('Import failed: '..name) end - - local data = '' - for line in file:lines() do data = data..line end - file:close() - data = json.decode(data) + local data = self:loadJSON(name, fname) table.insert(required, name) for i, iname in util.listpairs(data.import) do import(iname) end table.insert(imported, name) for cls, objs in pairs(data) do - if cls ~= 'import' then + if not util.contains({'description', 'import'}, + cls) then if not input[cls] then input[cls] = objs elseif objs[1] then util.extend(input[cls], objs) else @@ -160,6 +166,6 @@ function PolicySet:list() elseif util.contains(imported, name) then status = 'required' else status = 'disabled' end - return name, status + return name, status, self:loadJSON(name, pols[i][2]).description end end diff --git a/sample-policy.json b/sample-policy.json index 73850c3..8dc9d95 100644 --- a/sample-policy.json +++ b/sample-policy.json @@ -1,4 +1,6 @@ { + "description": "Sample awall policy; copy to /etc/awall to use", + "variable": { "internet_if": "eth0" }, "zone": { -- cgit v1.2.3