diff options
Diffstat (limited to 'apt-panopticon-report-email.lua')
-rwxr-xr-x | apt-panopticon-report-email.lua | 292 |
1 files changed, 0 insertions, 292 deletions
diff --git a/apt-panopticon-report-email.lua b/apt-panopticon-report-email.lua deleted file mode 100755 index 53db16f..0000000 --- a/apt-panopticon-report-email.lua +++ /dev/null | |||
@@ -1,292 +0,0 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | local args = {...} | ||
4 | |||
5 | verbosity = -1 | ||
6 | local logFile | ||
7 | |||
8 | |||
9 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. | ||
10 | From http://lua-users.org/wiki/SortedIteration | ||
11 | ]] | ||
12 | function __genOrderedIndex( t ) | ||
13 | local orderedIndex = {} | ||
14 | for key in pairs(t) do | ||
15 | table.insert( orderedIndex, key ) | ||
16 | end | ||
17 | table.sort( orderedIndex ) | ||
18 | return orderedIndex | ||
19 | end | ||
20 | function orderedNext(t, state) | ||
21 | -- Equivalent of the next function, but returns the keys in the alphabetic | ||
22 | -- order. We use a temporary ordered key table that is stored in the | ||
23 | -- table being iterated. | ||
24 | |||
25 | local key = nil | ||
26 | --print("orderedNext: state = "..tostring(state) ) | ||
27 | if state == nil then | ||
28 | -- the first time, generate the index | ||
29 | t.__orderedIndex = __genOrderedIndex( t ) | ||
30 | key = t.__orderedIndex[1] | ||
31 | else | ||
32 | -- fetch the next value | ||
33 | for i = 1,table.getn(t.__orderedIndex) do | ||
34 | if t.__orderedIndex[i] == state then | ||
35 | key = t.__orderedIndex[i+1] | ||
36 | end | ||
37 | end | ||
38 | end | ||
39 | |||
40 | if key then | ||
41 | return key, t[key] | ||
42 | end | ||
43 | |||
44 | -- no more value to return, cleanup | ||
45 | t.__orderedIndex = nil | ||
46 | return | ||
47 | end | ||
48 | function orderedPairs(t) | ||
49 | -- Equivalent of the pairs() function on tables. Allows to iterate | ||
50 | -- in order | ||
51 | return orderedNext, t, nil | ||
52 | end | ||
53 | |||
54 | |||
55 | local plurals = function(e, w) | ||
56 | local result = "" | ||
57 | if 1 == e then | ||
58 | result = e .. " error" | ||
59 | elseif e ~= 0 then | ||
60 | result = e .. " errors" | ||
61 | end | ||
62 | if 0 < w then | ||
63 | if 0 < e then result = result .. ", " end | ||
64 | if 1 == w then | ||
65 | result = result .. w .. " warning" | ||
66 | else | ||
67 | result = result .. w .. " warnings" | ||
68 | end | ||
69 | end | ||
70 | if "" ~= result then result = " (" .. result .. ")" end | ||
71 | return result | ||
72 | end | ||
73 | |||
74 | local results = {} | ||
75 | |||
76 | local log = function(v, t, s, prot, test, host) | ||
77 | local x = "" | ||
78 | if nil == prot then prot = "" end | ||
79 | if nil ~= test then x = x .. test else test = "" end | ||
80 | if nil ~= host then | ||
81 | if #x > 0 then x = x .. " " end | ||
82 | x = x .. host | ||
83 | end | ||
84 | if #x > 0 then | ||
85 | t = t .. "(" .. x .. ")" | ||
86 | end | ||
87 | if v <= verbosity then | ||
88 | if 3 <= verbosity then t = os.date() .. " " .. t end | ||
89 | print(t .. ": " .. s) | ||
90 | end | ||
91 | if nil ~= logFile then | ||
92 | logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") | ||
93 | logFile:flush() | ||
94 | end | ||
95 | end | ||
96 | local D = function(s) log(3, "DEBUG ", s) end | ||
97 | local I = function(s) log(2, "INFO ", s) end | ||
98 | local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end | ||
99 | local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end | ||
100 | local C = function(s) log(-1, "CRITICAL", s) end | ||
101 | |||
102 | local faulty = "" | ||
103 | local status = function(host, results, typ) | ||
104 | local result = "" | ||
105 | local e = 0 | ||
106 | local w = 0 | ||
107 | if nil ~= results[typ] then | ||
108 | e = results[typ].errors | ||
109 | w = results[typ].warnings | ||
110 | for k, v in pairs(results[typ]) do | ||
111 | if "table" == type(v) then | ||
112 | e = e + v.errors | ||
113 | w = w + v.warnings | ||
114 | end | ||
115 | end | ||
116 | else | ||
117 | for k, v in pairs(results) do | ||
118 | if "table" == type(v) then | ||
119 | for i, u in pairs(v) do | ||
120 | if "table" == type(u) then | ||
121 | if typ == i then | ||
122 | e = e + u.errors | ||
123 | w = w + u.warnings | ||
124 | end | ||
125 | end | ||
126 | end | ||
127 | end | ||
128 | end | ||
129 | end | ||
130 | |||
131 | if 0 < e then result = e .. " errors" end | ||
132 | if 1 == e then result = e .. " error" end | ||
133 | if 0 < w then | ||
134 | if 0 < e then result = result .. ", " end | ||
135 | if 1 == w then | ||
136 | result = result .. w .. " warning" | ||
137 | else | ||
138 | result = result .. w .. " warnings" | ||
139 | end | ||
140 | end | ||
141 | if "[OK]" ~= result then | ||
142 | if 0 < e then | ||
143 | result = "[FAILED] (" .. result .. ")" | ||
144 | faulty = faulty .. host .. " (" .. typ .. ")\n" | ||
145 | elseif 0 < w then | ||
146 | result = "[OK] (" .. result .. ")" | ||
147 | else | ||
148 | result = "[OK]" | ||
149 | end | ||
150 | end | ||
151 | return result | ||
152 | end | ||
153 | |||
154 | local collate = function(host, ip, results) | ||
155 | local f = "results/" .. host .. "_" .. ip .. ".lua" | ||
156 | local rfile, e = io.open(f, "r") | ||
157 | if nil == rfile then I("opening " .. f .. " file - " .. e) else | ||
158 | rfile:close() | ||
159 | local rs = loadfile(f)() | ||
160 | for k, v in pairs(rs) do | ||
161 | if "table" == type(v) then | ||
162 | for i, u in pairs(v) do | ||
163 | if "table" == type(u) then | ||
164 | for h, t in pairs(u) do | ||
165 | local a = results[k][h] | ||
166 | if nil == a then a = 0 end | ||
167 | results[k][h] = a + t | ||
168 | end | ||
169 | else | ||
170 | local a = results[k][i] | ||
171 | if nil == a then a = 0 end | ||
172 | results[k][i] = a + u | ||
173 | end | ||
174 | end | ||
175 | else | ||
176 | local a = results[k] | ||
177 | if nil == a then a = 0 end | ||
178 | results[k] = a + v | ||
179 | end | ||
180 | end | ||
181 | end | ||
182 | return results | ||
183 | end | ||
184 | |||
185 | local mirrors = loadfile("results/mirrors.lua")() | ||
186 | |||
187 | local logCount = function(domain, ip) | ||
188 | local nm = "LOG_" .. domain | ||
189 | local log = "" | ||
190 | local extra = "" | ||
191 | if nil ~= ip then nm = nm .. "_" .. ip end | ||
192 | nm = nm .. ".html" | ||
193 | local rfile, e = io.open("results/" .. nm, "r") | ||
194 | if nil ~= rfile then | ||
195 | local errors = 0 | ||
196 | local warnings = 0 | ||
197 | for l in rfile:lines() do | ||
198 | if nil ~= l:match("><b>ERROR ") then errors = errors + 1 end | ||
199 | if nil ~= l:match("><b>WARNING ") then warnings = warnings + 1 end | ||
200 | end | ||
201 | rfile:close() | ||
202 | -- if nil == ip then | ||
203 | -- log = "<a href='" .. nm .. "'>" .. domain .. "</a>" | ||
204 | -- else | ||
205 | -- log = "<a href='" .. nm .. "'>" .. ip .. "</a>" | ||
206 | -- end | ||
207 | log = log .. plurals(errors, warnings) | ||
208 | end | ||
209 | return log | ||
210 | end | ||
211 | |||
212 | local file, e = io.open("results/Report-email.txt", "w+") | ||
213 | if nil == file then C("opening mirrors file - " .. e) else | ||
214 | file:write( "Dear Mirror Admins,\n\n" .. | ||
215 | "The full list of Devuan package mirrors is available at the URL:\n\n" .. | ||
216 | " https://pkgmaster.devuan.org/mirror_list.txt\n\n" .. | ||
217 | 'Please contact "mirrors@devuan.org" if any of the information \nin the file above needs to be amended. \n\n' .. | ||
218 | "The full results of the mirror checking is available at the URL:\n\n" .. | ||
219 | " https://sledjhamr.org/apt-panopticon/results/Report-web.html\n\n" .. | ||
220 | "Due to the nature of the tests, some errors or warnings will be \ncounted several times. " .. | ||
221 | "Refer to the logs on the web page for details.\n\n" .. | ||
222 | "Please see below the current status of the Devuan Package Mirror \nnetwork:\n\n" .. | ||
223 | "---- BEGIN MIRROR-STATUS " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ----\n") | ||
224 | for k, v in orderedPairs(mirrors) do | ||
225 | local results = loadfile("results/" .. k .. ".lua")() | ||
226 | file:write(k .. "....\n") | ||
227 | local IPs = v.IPs | ||
228 | for i, u in pairs(IPs) do | ||
229 | if "table" == type(u) then | ||
230 | for h, t in pairs(u) do | ||
231 | results = collate(k, h, results) | ||
232 | end | ||
233 | else | ||
234 | results = collate(k, i, results) | ||
235 | end | ||
236 | end | ||
237 | local ftp = "[skip]" | ||
238 | local http = status(k, results, "http") | ||
239 | local https = status(k, results, "https") | ||
240 | local rsync = "[skip]" | ||
241 | local dns = "" | ||
242 | local protocol = status(k, results, "Protocol") | ||
243 | local sanity = "[skip]" | ||
244 | local integrity = status(k, results, "Integrity") | ||
245 | local updated = status(k, results, "Updated") | ||
246 | |||
247 | -- DNS-RR test. | ||
248 | if ("deb.devuan.org" ~= k) and (nil ~= mirrors["deb.devuan.org"]) then | ||
249 | for l, w in pairs(mirrors[k].IPs) do | ||
250 | if type(w) == "table" then | ||
251 | for i, u in pairs(w) do | ||
252 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then | ||
253 | local log = logCount("deb.devuan.org", i) | ||
254 | if "" ~= log then | ||
255 | if "" == dns then dns = " " else dns = dns .. " " end | ||
256 | dns = dns .. logCount("deb.devuan.org", i) | ||
257 | else | ||
258 | if "" == dns then dns = " " else dns = dns .. " " end | ||
259 | dns = dns .. i | ||
260 | end | ||
261 | end | ||
262 | end | ||
263 | else | ||
264 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then | ||
265 | local log = logCount("deb.devuan.org", l) | ||
266 | if "" ~= log then | ||
267 | if "" == dns then dns = " " else dns = dns .. " " end | ||
268 | dns = dns .. log | ||
269 | else | ||
270 | if "" == dns then dns = " " else dns = dns .. " " end | ||
271 | dns = dns .. l | ||
272 | end | ||
273 | end | ||
274 | end | ||
275 | end | ||
276 | if "" == dns then dns = "[no]" end | ||
277 | dns = " DNS-RR: " .. dns | ||
278 | end | ||
279 | |||
280 | file:write( " ftp: " .. ftp .. " http: " .. http .. " https: " .. https .." rsync: " .. rsync .. "\n" .. | ||
281 | " " .. dns .. "\n" .. | ||
282 | " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. "\n" .. | ||
283 | " Updated: " .. updated .. "\n") | ||
284 | end | ||
285 | file:write( "\n==== faulty mirrors: ====\n" .. faulty) | ||
286 | file:write( "\n---- END MIRROR-STATUS ----\n\n" .. | ||
287 | "Thanks for your precious help in ensuring that Devuan GNU+Linux \nremains a universal, stable, dependable, free operating system.\n\n" .. | ||
288 | "You can get the source code from https://sledjhamr.org/cgit/apt-panopticon/about/ ." .. | ||
289 | "Love\n\n" .. | ||
290 | "The Dev1Devs\n\n") | ||
291 | file:close() | ||
292 | end | ||