From 393eb13e81d2f0f88acb4b83e132124c3d376401 Mon Sep 17 00:00:00 2001
From: onefang
Date: Sun, 29 Dec 2019 10:16:06 +1000
Subject: Refactor nested pairs() calls.
---
apt-panopticon.lua | 65 +++++++++++++++---------------------------------------
1 file changed, 18 insertions(+), 47 deletions(-)
(limited to 'apt-panopticon.lua')
diff --git a/apt-panopticon.lua b/apt-panopticon.lua
index 25c2b49..675754d 100755
--- a/apt-panopticon.lua
+++ b/apt-panopticon.lua
@@ -1011,17 +1011,8 @@ if 0 < #arg then
if nil == path then path = '' end
if APT.origin then
local ips = APT.results["IPs"]
- for k, v in pairs(ips) do
- if "table" == type(v) then
- for k1, v1 in pairs(v) do
- if v1 == "A" then
- if APT.testing("IPv4") then APT.exe("./apt-panopticon.lua " .. sendArgs .. " " .. pu.host .. path .. " " .. k1 .. " " .. file):Nice():log():fork() end
- elseif v1 == "AAAA" then
- if APT.testing("IPv6") then APT.exe("./apt-panopticon.lua " .. sendArgs .. " " .. pu.host .. path .. " " .. k1 .. " " .. file):Nice():log():fork() end
- end
- D('logging to ' .. APT.logName(pu.host, k1, file)[2])
- end
- else
+ APT.allpairs(ips,
+ function(k, v)
if v == "A" then
if APT.testing("IPv4") then APT.exe("./apt-panopticon.lua " .. sendArgs .. " " .. pu.host .. path .. " " .. k .. " " .. file):Nice():log():fork() end
elseif v == "AAAA" then
@@ -1029,7 +1020,7 @@ if 0 < #arg then
end
D('logging to ' .. APT.logName(pu.host, k, file)[2])
end
- end
+ )
end
if not APT.redir then
@@ -1156,48 +1147,28 @@ os.execute('sleep 1') -- Wait for things to start up before checking for them.
if not dn then table.insert(baseFiles, ll) end
end
- APT.logOpen(hst)
- APT.logFile:write('
Note log lines will be out of order, this is a bunch of other log files combined.
\n')
- for i, f in pairs(baseFiles) do
- f = f:sub(9, -1)
- APT.logFile:write('
\n
\n\n')
- for l in io.lines('results/' .. f) do
- if l:match('^' .. os.date('%Y%-%m%-%d ') .. '.*$') then APT.logFile:write(l .. '\n') end
+ local combine = function(ip, a)
+ if not APT.logOpen(hst, ip) then print('PROBLEM OPENING LOG FILE ' .. hst .. ' ' .. ip) end
+ APT.logFile:write('Note log lines will be out of order, this is a bunch of other log files combined.
\n')
+ for i, f in pairs(a) do
+ f = f:sub(9, -1)
+ APT.logFile:write('
\n
\n\n')
+ for ln in io.lines('results/' .. f) do
+ if ln:match('^' .. os.date('!%Y%-%m%-%d ') .. '.*$') then APT.logFile:write(ln .. '\n') end -- %F isn't good enough, coz we have to escape the '-'.
+ end
end
+ APT.logPost()
+ APT.args = APT_args
+ APT.logFile = APT_logFile
end
- APT.logPost()
- APT.args = APT_args
- APT.logFile = APT_logFile
-
+ combine(nil, baseFiles)
for ip, a in pairs(IPfiles) do
if nil == a[1] then
for i, f in pairs(a) do
- if not APT.logOpen(hst, i) then print('PROBLEM OPENING LOG FILE ' .. hst .. ' ' .. i) end
- APT.logFile:write('Note log lines will be out of order, this is a bunch of other log files combined.
\n')
- for j, g in pairs(f) do
- g = g:sub(9, -1)
- APT.logFile:write('
\n
\n\n')
- for l in io.lines('results/' .. g) do
- if l:match('^' .. os.date('%Y%-%m%-%d ') .. '.*$') then APT.logFile:write(l .. '\n') end
- end
- end
- APT.logPost()
- APT.args = APT_args
- APT.logFile = APT_logFile
+ combine(i, f)
end
else
- if not APT.logOpen(hst, ip) then print('PROBLEM OPENING LOG FILE ' .. hst .. ' ' .. ip) end
- APT.logFile:write('Note log lines will be out of order, this is a bunch of other log files combined.
\n')
- for i, f in pairs(a) do
- f = f:sub(9, -1)
- APT.logFile:write('
\n
\n\n')
- for l in io.lines('results/' .. f) do
- if l:match('^' .. os.date('%Y%-%m%-%d ') .. '.*$') then APT.logFile:write(l .. '\n') end
- end
- end
- APT.logPost()
- APT.args = APT_args
- APT.logFile = APT_logFile
+ combine(ip, a)
end
end
--
cgit v1.1