diff options
author | Leonardo Arena <rnalrd@alpinelinux.org> | 2014-06-12 07:56:57 +0000 |
---|---|---|
committer | Leonardo Arena <rnalrd@alpinelinux.org> | 2014-06-12 07:57:18 +0000 |
commit | 15f898ca8068419fc02364231bb2981cc54971cb (patch) | |
tree | e3ec5995d70831834d467d40615870b44bca7044 /main/aaudit/aaudit-common.lua | |
parent | 94983a506d2e95be0a5864ae7bcc7d7d61dc6cce (diff) | |
download | aports-15f898ca8068419fc02364231bb2981cc54971cb.tar.bz2 aports-15f898ca8068419fc02364231bb2981cc54971cb.tar.xz |
testing/aaudit: move to main
Diffstat (limited to 'main/aaudit/aaudit-common.lua')
-rw-r--r-- | main/aaudit/aaudit-common.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/main/aaudit/aaudit-common.lua b/main/aaudit/aaudit-common.lua new file mode 100644 index 0000000000..d7b1bc4837 --- /dev/null +++ b/main/aaudit/aaudit-common.lua @@ -0,0 +1,31 @@ +local M = {} + +local posix = require 'posix' +local json = require 'cjson' + +M.config = "/etc/aaudit/aaudit.json" + +function M.readfile(fn) + local F = io.open(fn, "r") + if F == nil then return nil end + local ret = F:read("*all") + F:close() + return ret +end + +function M.readconfig(fn) + fn = fn or M.config + local success, res = pcall(json.decode, M.readfile(fn)) + if not success then io.stderr:write(("Error reading %s: %s\n"):format(fn, res)) end + return res +end + +function M.writefile(content, fn) + assert(io.open(fn, "w")):write(content):close() +end + +function M.writeconfig(config, fn) + M.writefile(json.encode(config), fn or M.config) +end + +return M |