From 018259f210c2e8addd76dd24969803a3529a553d Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 13 Dec 2019 03:16:12 +1000 Subject: Refactor the protocols table. --- apt-panopticommon.lua | 12 ++++++++++-- apt-panopticon-report-email-web.lua | 3 ++- apt-panopticon.lua | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index 182d90c..22354f3 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -3,6 +3,8 @@ local APT = {} -- https://oss.oetiker.ch/rrdtool/prog/rrdlua.en.html APT.rrd = require 'rrd' +APT.protocols = {"ftp", "http", "https", "rsync"} + verbosity = -1 APT.origin = false APT.keep = false @@ -247,6 +249,13 @@ dumpTableSub = function (table, space) return r end +APT.search = function(t, s) + for i, v in pairs(t) do + if v == s then return true end + end + return false +end + APT.results = {} APT.logFile = nil APT.html = false @@ -392,7 +401,7 @@ APT.plurals = function(e, w) end APT.padResults = function(results) - for k, v in pairs{"ftp", "http", "https", "rsync"} do + for k, v in pairs(APT.protocols) do tests = results[v] if nil == tests then tests = {errors = 0; warnings = 0} end if nil == tests.Integrity then tests.Integrity = {errors = 0; warnings = 0} end @@ -477,7 +486,6 @@ APT.now = 0 local status status, APT.now = APT.execute('TZ="GMT" ls -l --time-style="+%s" results/stamp | cut -d " " -f 6-6') APT.now = tonumber(APT.now) -APT.protocols = {'ftp', 'http', 'https', 'rsync'} APT.tests = {'raw', 'Integrity', 'Protocol', 'Updated', 'URLSanity', 'Speed'} local start = 'now-2week' local step = '10min' diff --git a/apt-panopticon-report-email-web.lua b/apt-panopticon-report-email-web.lua index 382b14d..94f0417 100755 --- a/apt-panopticon-report-email-web.lua +++ b/apt-panopticon-report-email-web.lua @@ -49,7 +49,8 @@ local status = function(host, results, typ) local w = 0 local s = nil ~= APT.mirrors[host].Protocols[typ] local to = results.timeout - if ('http' ~= typ) and ('https' ~= typ) and ('ftp' ~= typ) and ('rsync' ~= typ) then s = true end +-- if ('http' ~= typ) and ('https' ~= typ) and ('ftp' ~= typ) and ('rsync' ~= typ) then s = true end + if not APT.search(APT.protocols, typ) then s = true end if nil ~= results[typ] then e = results[typ].errors w = results[typ].warnings diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 62acbf25..8b02626 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -606,7 +606,8 @@ local getMirrors = function () elseif "Protocols" == t then local prot = {} for w in d:gmatch("(%w+)") do - prot[w] = true; +-- prot[w] = true; + if APT.search(APT.protocols, w:lower()) then prot[w] = true end end m[t] = prot elseif "Active" == t and nil == d:sub(1, 3):find("yes", 1, true) then -- cgit v1.1