diff options
author | Timo Teräs <timo.teras@iki.fi> | 2014-05-06 13:23:55 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-05-06 16:56:23 +0300 |
commit | 4898593dd7fdb5dec3f0ccdbec5e7347b2146c48 (patch) | |
tree | fd4025d3918c2c761adc387648778ad588e64275 /testing/aaudit/aaudit-emaildiff | |
parent | 3e62492bb468dbae22138a6238262696bce754c9 (diff) | |
download | aports-4898593dd7fdb5dec3f0ccdbec5e7347b2146c48.tar.bz2 aports-4898593dd7fdb5dec3f0ccdbec5e7347b2146c48.tar.xz |
testing/aaudit: new aport
Alpine Auditor - utility to track remote apkovls in a git tree and
email about changes
Diffstat (limited to 'testing/aaudit/aaudit-emaildiff')
-rwxr-xr-x | testing/aaudit/aaudit-emaildiff | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/aaudit/aaudit-emaildiff b/testing/aaudit/aaudit-emaildiff new file mode 100755 index 0000000000..56d7541032 --- /dev/null +++ b/testing/aaudit/aaudit-emaildiff @@ -0,0 +1,61 @@ +#!/usr/bin/lua5.2 + +local posix = require 'posix' +local config_file = "/etc/aaudit/aaudit.conf" + +local function load_config(filename) + local F = io.open(filename, "r") + local cfg = "return {" .. F:read("*all").. "}" + F:close() + return loadstring(cfg, "config:"..filename)() +end + +local function match_file(fn, match_list) + if not match_list then return false end + local i, m + for i, pattern in ipairs(match_list) do + if posix.fnmatch(pattern, fn) then return true end + end + return false +end + +local CONF = load_config(config_file) +if CONF.notify_email == nil or CONF.smtp_server == nil then return end + +local visible, has_data = false, false +local diff = {} +for l in io.lines() do + local fn = l:match("^diff [^ \t]* a/([^ \t]*)") + if fn then + visible = not match_file(fn, CONF.no_notify_files) + if visible then + has_data = true + visible = not match_file(fn, CONF.private_files) + if not visible then + table.insert(diff, "Private file "..fn.." changed") + end + end + end + if visible then table.insert(diff, l) end +end + +if has_data then + local EMAIL = io.popen(string.format("sendmail -t -S %s", CONF.smtp_server), "w") + EMAIL:write(string.format([[ +From: %s <%s> +To: %s +Subject: Configuration change on %s +Date: %s + +This is automatically generated e-mail about the following configuration change: + +%s +]], + CONF.author_name or "Alpine Auditor", CONF.author_email or "auditor@alpine.local", + table.concat(CONF.notify_email, ", "), + arg[1], + os.date("%a, %d %b %Y %H:%M:%S"), + table.concat(diff, '\n') + )) + EMAIL:close() +end |