aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rwxr-xr-xapt-panopticon-report-email.lua186
1 files changed, 186 insertions, 0 deletions
diff --git a/apt-panopticon-report-email.lua b/apt-panopticon-report-email.lua
new file mode 100755
index 0000000..2f7c8d1
--- /dev/null
+++ b/apt-panopticon-report-email.lua
@@ -0,0 +1,186 @@
1#!/usr/bin/env luajit
2
3local args = {...}
4
5verbosity = -1
6local 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 ]]
12function __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
19end
20function 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
47end
48function orderedPairs(t)
49 -- Equivalent of the pairs() function on tables. Allows to iterate
50 -- in order
51 return orderedNext, t, nil
52end
53
54
55local results = {}
56
57local log = function(v, t, s, prot, test, host)
58 local x = ""
59 if nil == prot then prot = "" end
60 if nil ~= test then x = x .. test else test = "" end
61 if nil ~= host then
62 if #x > 0 then x = x .. " " end
63 x = x .. host
64 end
65 if #x > 0 then
66 t = t .. "(" .. x .. ")"
67 end
68 if v <= verbosity then
69 if 3 <= verbosity then t = os.date() .. " " .. t end
70 print(t .. ": " .. s)
71 end
72 if nil ~= logFile then
73 logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n")
74 logFile:flush()
75 end
76end
77local D = function(s) log(3, "DEBUG ", s) end
78local I = function(s) log(2, "INFO ", s) end
79local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end
80local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end
81local C = function(s) log(-1, "CRITICAL", s) end
82
83local faulty = ""
84local status = function(host, results, typ)
85 local result = ""
86 local e = results[typ].errors
87 local w = results[typ].warnings
88 for i, u in pairs(results[typ]) do
89 if "table" == type(u) then
90 e = e + u.errors
91 w = w + u.warnings
92 end
93 end
94
95 if 0 < e then result = e .. " errors" end
96 if 1 == e then result = e .. " error" end
97 if 0 < w then
98 if 0 < e then result = result .. ", " end
99 if 1 == w then
100 result = result .. w .. " warning"
101 else
102 result = result .. w .. " warnings"
103 end
104 end
105 if "[OK]" ~= result then
106 if 0 < e then
107 result = "[FAILED] (" .. result .. ")"
108 faulty = faulty .. host .. " (" .. typ .. ")\n"
109 elseif 0 < w then
110 result = "[OK] (" .. result .. ")"
111 else
112 result = "[OK]"
113 end
114 end
115 return result
116end
117
118local collate = function(host, ip, results)
119 local f = "results/" .. host .. "_" .. ip .. ".lua"
120 local rfile, e = io.open(f, "r")
121 if nil == rfile then C("opening " .. f .. " file - " .. e) else
122 rfile:close()
123 local rs = loadfile(f)()
124 for k, v in pairs(rs) do
125 if "table" == type(v) then
126 for i, u in pairs(v) do
127 if "table" == type(u) then
128 for h, t in pairs(u) do
129 local a = results[k][h]
130 if nil == a then a = 0 end
131 results[k][h] = a + t
132 end
133 else
134 local a = results[k][i]
135 if nil == a then a = 0 end
136 results[k][i] = a + u
137 end
138 end
139 else
140 local a = results[k]
141 if nil == a then a = 0 end
142 results[k] = a + v
143 end
144 end
145 end
146 return results
147end
148
149
150local mirrors = loadfile("results/mirrors.lua")()
151
152local file, e = io.open("results/Report-email.txt", "w+")
153if nil == file then C("opening mirrors file - " .. e) else
154 file:write( "Dear Mirror Admins,\n\n" ..
155 "The full list of Devuan package mirrors is available at the URL:\n\n" ..
156 " https://pkgmaster.devuan.org/mirror_list.txt\n\n" ..
157 'Please contact "mirrors@devuan.org" if any of the information \nin the file above needs to be amended. \n\n' ..
158 "Please see below the current status of the Devuan Package Mirror \nnetwork:\n\n" ..
159 "---- BEGIN MIRROR-STATUS ----\n")
160 for k, v in orderedPairs(mirrors) do
161 local results = loadfile("results/" .. k .. ".lua")()
162 file:write(k .. "....\n")
163 local IPs = v.IPs
164 for i, u in pairs(IPs) do
165 if "table" == type(u) then
166 for h, t in pairs(u) do
167 results = collate(k, h, results)
168 end
169 else
170 results = collate(k, i, results)
171 end
172 end
173 local http = status(k, results, "http")
174 local https = status(k, results, "https")
175 local dns = "[skip]"
176 local updated = "[skip]"
177 local integrity = "[skip]"
178 file:write(" http: " .. http .. " https: " .. https .. " DNS-RR: " .. dns .. " Updated: " .. updated .. " Integrity: " .. integrity .. "\n")
179 end
180 file:write( "==== faulty mirrors: ====\n\n" .. faulty)
181 file:write( "---- END MIRROR-STATUS ----\n\n" ..
182 "Thanks for your precious help in ensuring that Devuan GNU+Linux \nremains a universal, stable, dependable, free operating system.\n\n" ..
183 "Love\n\n" ..
184 "The Dev1Devs\n\n")
185 file:close()
186end