diff options
author | onefang | 2019-11-13 20:38:42 +1000 |
---|---|---|
committer | onefang | 2019-11-13 20:38:42 +1000 |
commit | 7a8fdb894665b3ce8aec4ef7193a1d13327a76d0 (patch) | |
tree | 8aae4d4f4d5a49822964f2ceac1f82aca0a30f30 /apt-panopticon-report-DNS.lua | |
parent | HTMLize the logs. (diff) | |
download | apt-panopticon-7a8fdb894665b3ce8aec4ef7193a1d13327a76d0.zip apt-panopticon-7a8fdb894665b3ce8aec4ef7193a1d13327a76d0.tar.gz apt-panopticon-7a8fdb894665b3ce8aec4ef7193a1d13327a76d0.tar.bz2 apt-panopticon-7a8fdb894665b3ce8aec4ef7193a1d13327a76d0.tar.xz |
Clean up the reports, and merge the DNS report into the web report.
Include links to the logs.
Tweak the colours a little.
Put the results into a table, for better readability.
Diffstat (limited to '')
-rwxr-xr-x | apt-panopticon-report-DNS.lua | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/apt-panopticon-report-DNS.lua b/apt-panopticon-report-DNS.lua deleted file mode 100755 index c571c3d..0000000 --- a/apt-panopticon-report-DNS.lua +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | local args = {...} | ||
4 | |||
5 | local logFile | ||
6 | |||
7 | |||
8 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. | ||
9 | From http://lua-users.org/wiki/SortedIteration | ||
10 | ]] | ||
11 | function __genOrderedIndex( t ) | ||
12 | local orderedIndex = {} | ||
13 | for key in pairs(t) do | ||
14 | table.insert( orderedIndex, key ) | ||
15 | end | ||
16 | table.sort( orderedIndex ) | ||
17 | return orderedIndex | ||
18 | end | ||
19 | function orderedNext(t, state) | ||
20 | -- Equivalent of the next function, but returns the keys in the alphabetic | ||
21 | -- order. We use a temporary ordered key table that is stored in the | ||
22 | -- table being iterated. | ||
23 | |||
24 | local key = nil | ||
25 | --print("orderedNext: state = "..tostring(state) ) | ||
26 | if state == nil then | ||
27 | -- the first time, generate the index | ||
28 | t.__orderedIndex = __genOrderedIndex( t ) | ||
29 | key = t.__orderedIndex[1] | ||
30 | else | ||
31 | -- fetch the next value | ||
32 | for i = 1,table.getn(t.__orderedIndex) do | ||
33 | if t.__orderedIndex[i] == state then | ||
34 | key = t.__orderedIndex[i+1] | ||
35 | end | ||
36 | end | ||
37 | end | ||
38 | |||
39 | if key then | ||
40 | return key, t[key] | ||
41 | end | ||
42 | |||
43 | -- no more value to return, cleanup | ||
44 | t.__orderedIndex = nil | ||
45 | return | ||
46 | end | ||
47 | function orderedPairs(t) | ||
48 | -- Equivalent of the pairs() function on tables. Allows to iterate | ||
49 | -- in order | ||
50 | return orderedNext, t, nil | ||
51 | end | ||
52 | |||
53 | |||
54 | -- Use this to dump a table to a string. | ||
55 | dumpTable = function (table, space, name) | ||
56 | local r = "" | ||
57 | -- if "" == space then r = r .. space .. name .. " =\n" else r = r .. space .. "[" .. name .. "] =\n" end | ||
58 | if "" == space then r = r .. space .. name .. " \n" else r = r .. space .. name .. "\n" end | ||
59 | -- r = r .. space .. "{\n" | ||
60 | r = r .. dumpTableSub(table, space .. " ") | ||
61 | -- if "" == space then r = r .. space .. "}\n" else r = r .. space .. "},\n" end | ||
62 | if "" == space then r = r .. space .. "\n" end | ||
63 | return r | ||
64 | end | ||
65 | dumpTableSub = function (table, space) | ||
66 | local r = "" | ||
67 | -- for k, v in pairs(table) do | ||
68 | for k, v in orderedPairs(table) do | ||
69 | -- if type(k) == "string" then k = '"' .. k .. '"' end | ||
70 | if type(v) == "table" then | ||
71 | r = r .. dumpTable(v, space, k) | ||
72 | -- elseif type(v) == "string" then | ||
73 | -- r = r .. space .. "[" .. k .. "] = '" .. v .. "';\n" | ||
74 | -- elseif type(v) == "function" then | ||
75 | -- r = r .. space .. "[" .. k .. "] = function ();\n" | ||
76 | -- elseif type(v) == "userdata" then | ||
77 | -- r = r .. space .. "userdata " .. "[" .. k .. "];\n" | ||
78 | -- elseif type(v) == "boolean" then | ||
79 | -- if (v) then | ||
80 | -- r = r .. space .. "[" .. k .. "] = true;\n" | ||
81 | -- else | ||
82 | -- r = r .. space .. "[" .. k .. "] = false;\n" | ||
83 | -- end | ||
84 | else | ||
85 | -- r = r .. space .. "[" .. k .. "] = " .. v .. ";\n" | ||
86 | r = r .. space .. k .. "\n" | ||
87 | end | ||
88 | end | ||
89 | return r | ||
90 | end | ||
91 | |||
92 | local results = {} | ||
93 | |||
94 | local log = function(v, t, s, prot, test, host) | ||
95 | local x = "" | ||
96 | if nil == prot then prot = "" end | ||
97 | if nil ~= test then x = x .. test else test = "" end | ||
98 | if nil ~= host then | ||
99 | if #x > 0 then x = x .. " " end | ||
100 | x = x .. host | ||
101 | end | ||
102 | if #x > 0 then | ||
103 | t = t .. "(" .. x .. ")" | ||
104 | if "" == test then | ||
105 | if v == 0 then results[prot].errors = results[prot].errors + 1 end | ||
106 | if v == 1 then results[prot].warnings = results[prot].warnings + 1 end | ||
107 | else | ||
108 | if v == 0 then results[prot][test].errors = results[prot][test].errors + 1 end | ||
109 | if v == 1 then results[prot][test].warnings = results[prot][test].warnings + 1 end | ||
110 | end | ||
111 | end | ||
112 | if v <= verbosity then | ||
113 | if 3 <= verbosity then t = os.date() .. " " .. t end | ||
114 | print(t .. ": " .. s) | ||
115 | end | ||
116 | if nil ~= logFile then | ||
117 | logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") | ||
118 | logFile:flush() | ||
119 | end | ||
120 | end | ||
121 | local D = function(s) log(3, "DEBUG ", s) end | ||
122 | local I = function(s) log(2, "INFO ", s) end | ||
123 | local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end | ||
124 | local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end | ||
125 | local C = function(s) log(-1, "CRITICAL", s) end | ||
126 | |||
127 | local mirrors = loadfile("results/mirrors.lua")() | ||
128 | local m = {} | ||
129 | |||
130 | for k, v in pairs(mirrors) do | ||
131 | mirrors[k].Protocols = nil | ||
132 | mirrors[k].FQDN = nil | ||
133 | mirrors[k].Active = nil | ||
134 | mirrors[k].Rate = nil | ||
135 | mirrors[k].BaseURL = nil | ||
136 | mirrors[k].Country = nil | ||
137 | mirrors[k].Bandwidth = nil | ||
138 | m["\n" .. k .. " DNS entries -"] = mirrors[k].IPs | ||
139 | end | ||
140 | |||
141 | |||
142 | local file, e = io.open("results/Report-DNS.txt", "w+") | ||
143 | if nil == file then C("opening mirrors file - " .. e) else | ||
144 | file:write("This DNS report lists each mirror, and the DNS entries for that \nmirror. " .. | ||
145 | "If a mirror has a CNAME, that CNAME is listed along with that \nCNAMEs DNS entries. " .. | ||
146 | "deb.devuan.org is the DNS round robin, which points \nto the mirrors that are part of the DNS-RR. " .. | ||
147 | "pkgmaster.devuan.org is the \nmaster mirror, all the others sync to it. ") | ||
148 | file:write(dumpTable(m, "", "")) | ||
149 | file:close() | ||
150 | end | ||