mirror of https://github.com/aredn/aredn.git
171 lines
5.4 KiB
Plaintext
Executable File
171 lines
5.4 KiB
Plaintext
Executable File
{%
|
|
/*
|
|
* Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
|
* Copyright (C) 2024 Tim Wilkinson
|
|
* 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:
|
|
*
|
|
* Additional use restrictions exist on the AREDN® trademark and logo.
|
|
* See AREDNLicense.txt for more info.
|
|
*
|
|
* Attributions to the AREDN® Project must be retained in the source code.
|
|
* If importing this code into a new or existing project attribution
|
|
* to the AREDN® project must be added to the source code.
|
|
*
|
|
* 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
|
|
*/
|
|
%}
|
|
{%
|
|
if (request.env.REQUEST_METHOD === "PUT") {
|
|
response.headers["HX-Redirect"] = request.env.REQUEST_URI;
|
|
return;
|
|
}
|
|
|
|
const wifiiface = uci.get("network", "wifi", "device");
|
|
|
|
const files = [
|
|
"/etc/board.json",
|
|
"/etc/config/",
|
|
"/etc/config.mesh/",
|
|
"/etc/local/",
|
|
"/etc/mesh-release",
|
|
"/etc/os-release",
|
|
"/var/run/hosts_olsr",
|
|
"/var/run/services_olsr",
|
|
"/tmp/etc/",
|
|
"/tmp/dnsmasq.d/",
|
|
"/tmp/lqm.info",
|
|
"/tmp/wireless_monitor.info",
|
|
"/tmp/service-validation-state",
|
|
"/tmp/sysinfo/",
|
|
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
|
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to"
|
|
];
|
|
const sensitive = [
|
|
"/etc/config/vtun",
|
|
"/etc/config.mesh/vtun",
|
|
"/etc/config/network",
|
|
"/etc/config.mesh/wireguard",
|
|
"/etc/config/wireless",
|
|
"/etc/config.mesh/_setup",
|
|
];
|
|
const cmds = [
|
|
"cat /proc/cpuinfo",
|
|
"cat /proc/meminfo",
|
|
"df -k",
|
|
"dmesg",
|
|
"ifconfig",
|
|
"ethtool eth0",
|
|
"ethtool eth1",
|
|
"ip link",
|
|
"ip addr",
|
|
"ip neigh",
|
|
"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",
|
|
"netstat -aln",
|
|
"iwinfo",
|
|
`${wifiiface ? "iwinfo " + wifiiface + " assoclist" : null}`,
|
|
`${wifiiface ? "iw phy " + (replace(wifiiface, "wlan", "phy")) + " info" : null}`,
|
|
`${wifiiface ? "iw dev " + wifiiface + " info" : null}`,
|
|
`${wifiiface ? "iw dev " + wifiiface + " scan" : null}`,
|
|
`${wifiiface ? "iw dev " + wifiiface + " station dump" : null}`,
|
|
"wg show all",
|
|
"wg show all latest-handshakes",
|
|
"nft list ruleset",
|
|
"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",
|
|
"logread",
|
|
];
|
|
if (trim(fs.popen("/usr/local/bin/get_hardware_mfg").read("all")) === "Ubiquiti") {
|
|
push(cmds, "cat /dev/mtd0|grep 'U-Boot'|head -n1");
|
|
}
|
|
|
|
system("/bin/rm -rf /tmp/sd");
|
|
system("/bin/mkdir -p /tmp/sd");
|
|
|
|
for (let i = 0; i < length(files); i++) {
|
|
const file = files[i];
|
|
const s = fs.stat(file);
|
|
if (s) {
|
|
if (s.type === "directory") {
|
|
system(`/bin/mkdir -p /tmp/sd${file}`);
|
|
system(`/bin/cp -rp ${file}/* /tmp/sd/${file}`);
|
|
}
|
|
else {
|
|
system(`/bin/mkdir -p /tmp/sd${fs.dirname(file)}`);
|
|
system(`/bin/cp -p ${file} /tmp/sd/${file}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < length(sensitive); i++) {
|
|
const file = sensitive[i];
|
|
const f = fs.open(file);
|
|
if (f) {
|
|
const lines = [];
|
|
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
|
l = replace(l, /option passwd.+/, "option passwd '***HIDDEN***'\n");
|
|
l = replace(l, /option public_key.+/, "option public_key '***HIDDEN***'\n");
|
|
l = replace(l, /option private_key.+/, "option private_key '***HIDDEN***'\n");
|
|
l = replace(l, /option key.+/, "option key '***HIDDEN***'\n");
|
|
push(lines, l);
|
|
}
|
|
f.close();
|
|
fs.writefile(`/tmp/sd${file}`, join("", lines));
|
|
}
|
|
}
|
|
|
|
const f = fs.open("/tmp/sd/data.txt", "w");
|
|
if (f) {
|
|
for (let i = 0; i < length(cmds); i++) {
|
|
const cmd = cmds[i];
|
|
if (cmd) {
|
|
const p = fs.popen(`(${cmd}) 2> /dev/null`);
|
|
if (p) {
|
|
f.write(`\n===\n========== ${cmd} ==========\n===\n`);
|
|
f.write(p.read("all"));
|
|
p.close();
|
|
}
|
|
}
|
|
}
|
|
f.close();
|
|
}
|
|
|
|
system("/bin/tar -zcf /tmp/supportdata.tar.gz -C /tmp/sd ./");
|
|
system("/bin/rm -rf /tmp/sd");
|
|
|
|
const tm = localtime();
|
|
response.override = true;
|
|
uhttpd.send(`Status: 200 OK\r\nContent-Type: application/x-gzip\r\nContent-Disposition: attachment; filename=supportdata-${configuration.getName()}-${tm.year}-${tm.mon}-${tm.mday}-${tm.hour}-${tm.min}.tar.gz\r\nCache-Control: no-store\r\n\r\n`);
|
|
uhttpd.send(fs.readfile("/tmp/supportdata.tar.gz"));
|
|
|
|
%}
|