2022-03-08 20:22:07 -07:00
|
|
|
#!/usr/bin/lua
|
|
|
|
--[[
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
2022-03-08 20:22:07 -07:00
|
|
|
Copyright (C) 2021 Tim Wilkinson
|
|
|
|
Original Perl Copyright (C) 2015 Conrad Lara
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Additional use restrictions exist on the AREDN® trademark and logo.
|
2022-03-08 20:22:07 -07:00
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Attributions to the AREDN® Project must be retained in the source code.
|
2022-03-08 20:22:07 -07:00
|
|
|
If importing this code into a new or existing project attribution
|
2024-05-29 01:45:25 -06:00
|
|
|
to the AREDN® project must be added to the source code.
|
2022-03-08 20:22:07 -07:00
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
|
|
|
require("nixio")
|
|
|
|
require("aredn.utils")
|
|
|
|
require("uci")
|
|
|
|
require("iwinfo")
|
|
|
|
|
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
local wifiif = uci.cursor():get("network", "wifi", "device")
|
2022-03-08 20:22:07 -07:00
|
|
|
local phy = iwinfo.nl80211.phyname(wifiif)
|
|
|
|
local mfg = capture("/usr/local/bin/get_hardware_mfg"):chomp()
|
|
|
|
|
|
|
|
|
|
|
|
local files = {
|
|
|
|
"/etc/config/",
|
|
|
|
"/etc/config.mesh/",
|
|
|
|
"/etc/local/",
|
|
|
|
"/etc/mesh-release",
|
2022-12-22 13:22:49 -07:00
|
|
|
"/etc/os-release",
|
2022-03-08 20:22:07 -07:00
|
|
|
"/tmp/etc/",
|
|
|
|
"/var/run/hosts_olsr",
|
2022-03-15 23:36:03 -06:00
|
|
|
"/var/run/services_olsr",
|
2022-03-08 20:22:07 -07:00
|
|
|
"/tmp/rssi.dat",
|
|
|
|
"/tmp/rssi.log",
|
2022-12-22 13:22:49 -07:00
|
|
|
"/tmp/rssi_ath10k.log",
|
2023-03-30 12:36:31 -06:00
|
|
|
"/tmp/station_monitor.log",
|
2022-03-08 20:22:07 -07:00
|
|
|
"/tmp/olsrd.log",
|
2023-09-19 21:04:38 -06:00
|
|
|
"/tmp/dnsmasq.d/",
|
2022-03-08 20:22:07 -07:00
|
|
|
"/tmp/AutoDistReset.log",
|
2022-05-22 20:06:02 -06:00
|
|
|
"/tmp/lqm.info",
|
2023-06-20 02:27:23 -06:00
|
|
|
"/tmp/wireless_monitor.info",
|
2022-12-24 22:17:53 -07:00
|
|
|
"/tmp/sysinfo/board_name",
|
|
|
|
"/tmp/sysinfo/boardid",
|
|
|
|
"/tmp/sysinfo/hardware_mfg",
|
|
|
|
"/tmp/sysinfo/hardware_type",
|
|
|
|
"/tmp/sysinfo/model",
|
2022-03-08 20:22:07 -07:00
|
|
|
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
|
|
|
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
|
|
|
|
"/etc/board.json"
|
2015-05-08 20:52:49 -06:00
|
|
|
}
|
2022-03-08 20:22:07 -07:00
|
|
|
local sensitive = {
|
|
|
|
"/etc/config/vtun",
|
|
|
|
"/etc/config.mesh/vtun",
|
2024-03-06 11:24:03 -07:00
|
|
|
"/etc/config/network",
|
|
|
|
"/etc/config.mesh/wireguard"
|
2015-05-08 20:52:49 -06:00
|
|
|
}
|
2022-03-08 20:22:07 -07:00
|
|
|
local cmds = {
|
|
|
|
"cat /proc/cpuinfo",
|
|
|
|
"cat /proc/meminfo",
|
|
|
|
"df -k",
|
|
|
|
"dmesg",
|
|
|
|
"ifconfig",
|
2022-12-22 13:22:49 -07:00
|
|
|
"ethtool eth0",
|
|
|
|
"ethtool eth1",
|
|
|
|
"ip link",
|
|
|
|
"ip addr",
|
|
|
|
"ip neigh",
|
2022-03-08 20:22:07 -07:00
|
|
|
"ip route list",
|
|
|
|
"ip route list table 29",
|
|
|
|
"ip route list table 30",
|
|
|
|
"ip route list table 31",
|
|
|
|
"ip route list table main",
|
|
|
|
"ip route list table default",
|
|
|
|
"ip rule list",
|
2022-04-19 12:45:13 -06:00
|
|
|
"netstat -aln",
|
2022-03-08 20:22:07 -07:00
|
|
|
"iwinfo",
|
|
|
|
"iwinfo " .. wifiif .. " assoclist",
|
2022-03-13 08:48:10 -06:00
|
|
|
phy and "iw phy " .. phy .. " info" or "",
|
2022-03-08 20:22:07 -07:00
|
|
|
"iw dev " .. wifiif .. " info",
|
|
|
|
"iw dev " .. wifiif .. " scan",
|
|
|
|
"iw dev " .. wifiif .. " station dump",
|
2022-12-22 13:22:49 -07:00
|
|
|
"nft list ruleset",
|
2022-03-08 20:22:07 -07:00
|
|
|
"md5sum /www/cgi-bin/*",
|
|
|
|
"echo /all | nc 127.0.0.1 2006",
|
|
|
|
"opkg list-installed",
|
|
|
|
"ps -w",
|
|
|
|
"/usr/local/bin/get_hardwaretype",
|
|
|
|
"/usr/local/bin/get_boardid",
|
|
|
|
"/usr/local/bin/get_model",
|
|
|
|
"/usr/local/bin/get_hardware_mfg",
|
2022-12-22 13:22:49 -07:00
|
|
|
"logread",
|
2015-05-08 20:52:49 -06:00
|
|
|
}
|
2022-03-08 20:22:07 -07:00
|
|
|
local cmds_ubnt = {
|
|
|
|
"cat /dev/mtd0|grep 'U-Boot'|head -n1"
|
2018-05-13 22:02:57 -06:00
|
|
|
}
|
|
|
|
|
2022-03-08 20:22:07 -07:00
|
|
|
-- need space for this
|
|
|
|
local vfs = nixio.fs.statvfs("/tmp")
|
|
|
|
local fspace = vfs.bfree * vfs.bsize / 1024
|
|
|
|
if fspace < 2048 then
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
remove_all("/tmp/sd")
|
|
|
|
|
|
|
|
for _, path in ipairs(files)
|
|
|
|
do
|
|
|
|
if nixio.fs.stat(path) then
|
|
|
|
local m = path:match("^/(.*/).*/$")
|
|
|
|
if m then
|
|
|
|
os.execute("mkdir -p /tmp/sd/" .. m);
|
|
|
|
os.execute("cp -r -p " .. path .. " /tmp/sd/" .. m)
|
|
|
|
else
|
|
|
|
m = path:match("^/(.*/).*")
|
|
|
|
os.execute("mkdir -p /tmp/sd/" .. m);
|
|
|
|
os.execute("cp -r -p " .. path .. " /tmp/sd/" .. m)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-05 18:23:13 -07:00
|
|
|
-- hide sensitive information
|
2022-03-08 20:22:07 -07:00
|
|
|
for _, path in ipairs(sensitive)
|
|
|
|
do
|
2024-03-05 18:23:13 -07:00
|
|
|
local file = "/tmp/sd" .. path
|
|
|
|
if nixio.fs.stat(file) then
|
|
|
|
local lines = read_all(file)
|
|
|
|
local nlines = {}
|
|
|
|
for line in lines:gmatch("([^\n]*\n?)")
|
|
|
|
do
|
|
|
|
line = line:gsub("option passwd.+", "option passwd '***HIDDEN***'\n")
|
|
|
|
line = line:gsub("option public_key.+", "option public_key '***HIDDEN***'\n")
|
|
|
|
line = line:gsub("option private_key.+", "option private_key '***HIDDEN***'\n")
|
2024-03-06 11:24:03 -07:00
|
|
|
line = line:gsub("option key.+", "option key '***HIDDEN***'\n")
|
2024-03-05 18:23:13 -07:00
|
|
|
nlines[#nlines + 1] = line
|
|
|
|
end
|
|
|
|
write_all(file, table.concat(nlines, ""))
|
2022-03-08 20:22:07 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- remove passwords from config file
|
|
|
|
os.execute("sed -i -e 's/ key.*$/ key ******/' /tmp/sd/etc/config/wireless")
|
|
|
|
os.execute("sed -i -e 's/_key =.*$/_key =/' /tmp/sd/etc/config.mesh/_setup")
|
|
|
|
|
|
|
|
local f = io.open("/tmp/sd/data.txt", "w")
|
|
|
|
if f then
|
|
|
|
if mfg == "Ubiquiti" then
|
|
|
|
for _, cmd in ipairs(cmds_ubnt)
|
|
|
|
do
|
|
|
|
local p = io.popen(cmd)
|
|
|
|
if p then
|
2022-12-22 13:22:49 -07:00
|
|
|
f:write("\n========== " .. cmd .. " (UBNT only) ==========\n")
|
2022-03-08 20:22:07 -07:00
|
|
|
f:write(p:read("*a"))
|
|
|
|
p:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-12-22 13:22:49 -07:00
|
|
|
for _, cmd in ipairs(cmds)
|
|
|
|
do
|
|
|
|
local p = io.popen(cmd)
|
|
|
|
if p then
|
|
|
|
f:write("\n========== " .. cmd .. " ==========\n")
|
|
|
|
f:write(p:read("*a"))
|
|
|
|
p:close()
|
|
|
|
end
|
|
|
|
end
|
2022-03-08 20:22:07 -07:00
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
|
2024-03-05 18:23:13 -07:00
|
|
|
os.execute("tar -zcf /tmp/supportdata.tar.gz -C /tmp/sd ./")
|
2022-03-08 20:22:07 -07:00
|
|
|
-- cleaup the temp files
|
|
|
|
remove_all("/tmp/sd")
|
|
|
|
|
|
|
|
local nodename = capture("uname -n"):chomp()
|
|
|
|
local tstamp = capture("date +%Y%m%d%H%M"):chomp()
|
|
|
|
|
|
|
|
if os.getenv("GATEWAY_INTERFACE") ~= "" then
|
2024-03-05 18:23:13 -07:00
|
|
|
local fn = "supportdata-" .. nodename .. "-" .. tstamp .. ".tar.gz"
|
2022-03-08 20:22:07 -07:00
|
|
|
print("Content-type: application/x-gzip\r")
|
|
|
|
print("Content-Disposition: attachment; filename=" .. fn .. "\r")
|
|
|
|
print("\r")
|
2024-03-05 18:23:13 -07:00
|
|
|
io.write(read_all("/tmp/supportdata.tar.gz"))
|
2022-03-08 20:22:07 -07:00
|
|
|
else
|
2024-03-05 18:23:13 -07:00
|
|
|
local fn = "/tmp/supportdata-" .. nodename .. "-" .. tstamp .. ".tar.gz"
|
2022-03-08 20:22:07 -07:00
|
|
|
nixio.fs.remove(fn)
|
2024-03-05 18:23:13 -07:00
|
|
|
nixio.fs.rename("/tmp/supportdata.tar.gz", fn)
|
2022-03-08 20:22:07 -07:00
|
|
|
print("File created: " .. fn)
|
|
|
|
print("Please copy this file and remove from the node")
|
|
|
|
print("to free up resources.")
|
|
|
|
end
|