From e59373c8af941fdca9e2c26a7ab366439002bb7a Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 26 Nov 2019 01:39:37 +1000 Subject: Update the email report to match the web report. I should merge these two, or factor out common stuff into a library that might be useful for other reports. --- apt-panopticon-report-email.lua | 84 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/apt-panopticon-report-email.lua b/apt-panopticon-report-email.lua index d36aab0..5cf2d05 100755 --- a/apt-panopticon-report-email.lua +++ b/apt-panopticon-report-email.lua @@ -52,6 +52,25 @@ function orderedPairs(t) end +local plurals = function(e, w) + local result = "" + if 1 == e then + result = e .. " error" + elseif e ~= 0 then + result = e .. " errors" + end + if 0 < w then + if 0 < e then result = result .. ", " end + if 1 == w then + result = result .. w .. " warning" + else + result = result .. w .. " warnings" + end + end + if "" ~= result then result = " (" .. result .. ")" end + return result +end + local results = {} local log = function(v, t, s, prot, test, host) @@ -165,6 +184,31 @@ end local mirrors = loadfile("results/mirrors.lua")() +local logCount = function(domain, ip) + local nm = "LOG_" .. domain + local log = "" + local extra = "" + if nil ~= ip then nm = nm .. "_" .. ip end + nm = nm .. ".html" + local rfile, e = io.open("results/" .. nm, "r") + if nil ~= rfile then + local errors = 0 + local warnings = 0 + for l in rfile:lines() do + if nil ~= l:match(">ERROR ") then errors = errors + 1 end + if nil ~= l:match(">WARNING ") then warnings = warnings + 1 end + end + rfile:close() +-- if nil == ip then +-- log = "" .. domain .. "" +-- else +-- log = "" .. ip .. "" +-- end + log = log .. plurals(errors, warnings) + end + return log +end + local file, e = io.open("results/Report-email.txt", "w+") if nil == file then C("opening mirrors file - " .. e) else file:write( "Dear Mirror Admins,\n\n" .. @@ -192,13 +236,47 @@ if nil == file then C("opening mirrors file - " .. e) else end local http = status(k, results, "http") local https = status(k, results, "https") - local dns = "[skip]" + local dns = "" local protocol = status(k, results, "Protocol") local sanity = "[skip]" local integrity = status(k, results, "Integrity") local updated = "[skip]" - file:write( " http: " .. http .. " https: " .. https .. " DNS-RR: " .. dns .. " Protocol: " .. protocol .. "\n" .. - " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. " Updated: " .. updated .. "\n") + + -- DNS-RR test. + if ("deb.devuan.org" ~= k) and (nil ~= mirrors["deb.devuan.org"]) then + for l, w in pairs(mirrors[k].IPs) do + if type(w) == "table" then + for i, u in pairs(w) do + if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then + local log = logCount("deb.devuan.org", i) + if "" ~= log then + if "" == dns then dns = " " else dns = dns .. " " end + dns = dns .. logCount("deb.devuan.org", i) + else + if "" == dns then dns = " " else dns = dns .. " " end + dns = dns .. i + end + end + end + else + if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then + local log = logCount("deb.devuan.org", l) + if "" ~= log then + if "" == dns then dns = " " else dns = dns .. " " end + dns = dns .. log + else + if "" == dns then dns = " " else dns = dns .. " " end + dns = dns .. l + end + end + end + end + if "" == dns then dns = "[no]" end + dns = " DNS-RR: " .. dns + end + + file:write( " http: " .. http .. " https: " .. https .. dns .. "\n" .. + " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. " Updated: " .. updated .. "\n") end file:write( "\n==== faulty mirrors: ====\n" .. faulty) file:write( "\n---- END MIRROR-STATUS ----\n\n" .. -- cgit v1.1