aboutsummaryrefslogtreecommitdiffstats
path: root/testing/aaudit/aaudit-common.lua
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-05-10 01:10:59 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-05-10 01:12:00 +0300
commit6fbca72d680bb7ce7bccb41c86becf1762b042c1 (patch)
treec4beb6bfd620ad2eca86079fa04452ad0e1b9618 /testing/aaudit/aaudit-common.lua
parent9562bf59198a9b1ae90daec9bad97d545a781080 (diff)
downloadaports-6fbca72d680bb7ce7bccb41c86becf1762b042c1.tar.bz2
aports-6fbca72d680bb7ce7bccb41c86becf1762b042c1.tar.xz
testing/aaudit: rewrite client in lua, use json in configs
also use json to talk between client and server. and make the client program handle all command line flags.
Diffstat (limited to 'testing/aaudit/aaudit-common.lua')
-rw-r--r--testing/aaudit/aaudit-common.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/testing/aaudit/aaudit-common.lua b/testing/aaudit/aaudit-common.lua
new file mode 100644
index 0000000000..d7b1bc4837
--- /dev/null
+++ b/testing/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