2015-05-08 20:52:49 -06:00
|
|
|
#!/usr/bin/perl
|
2016-12-23 12:48:36 -07:00
|
|
|
=for comment
|
2015-05-08 20:52:49 -06:00
|
|
|
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
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:
|
|
|
|
|
|
|
|
Additional use restrictions exist on the AREDN(TM) 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.
|
|
|
|
|
2016-12-23 22:23:58 -07:00
|
|
|
You must not misrepresent the origin of the material contained within.
|
2015-05-08 20:52:49 -06:00
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
BEGIN {push @INC, '/www/cgi-bin'};
|
|
|
|
use perlfunc;
|
2018-09-01 17:39:19 -06:00
|
|
|
chomp (${wifiif}=`uci -q get 'network.wifi.ifname'`);
|
2018-09-13 00:41:40 -06:00
|
|
|
$phy=get_wlan2phy("${wifiif}");
|
2015-05-08 20:52:49 -06:00
|
|
|
|
|
|
|
|
|
|
|
@files = ( "/etc/config/",
|
|
|
|
"/etc/config.ap/",
|
|
|
|
"/etc/config.client/",
|
|
|
|
"/etc/config.mesh/",
|
|
|
|
"/etc/config.mesh_ap/",
|
|
|
|
"/etc/config.router/",
|
|
|
|
"/etc/local/",
|
|
|
|
"/etc/mesh-release",
|
|
|
|
"/tmp/etc/",
|
|
|
|
"/var/run/hosts_olsr",
|
2015-11-03 21:32:36 -07:00
|
|
|
"/tmp/rssi.dat",
|
|
|
|
"/tmp/rssi.log",
|
2018-09-13 00:41:40 -06:00
|
|
|
"/tmp/zombie.log",
|
2019-01-25 23:13:13 -07:00
|
|
|
"/tmp/olsrd.log",
|
2019-04-01 21:48:41 -06:00
|
|
|
"/tmp/AutoDistReset.log",
|
|
|
|
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
|
|
|
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to"
|
2015-05-08 20:52:49 -06:00
|
|
|
);
|
|
|
|
|
2015-05-24 14:47:16 -06:00
|
|
|
@sensitive = ( "/etc/config/vtun",
|
|
|
|
"/etc/config.mesh/vtun",
|
|
|
|
"/etc/httpd.conf",
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
@cmds = ( "cat /proc/cpuinfo",
|
2017-04-29 19:58:15 -06:00
|
|
|
"cat /proc/meminfo",
|
2015-05-08 20:52:49 -06:00
|
|
|
"df -k",
|
2015-05-24 14:29:49 -06:00
|
|
|
"dmesg",
|
2015-05-08 20:52:49 -06:00
|
|
|
"ifconfig",
|
|
|
|
"iptables -t filter -S",
|
|
|
|
"iptables -t nat -S",
|
|
|
|
"iptables -t mangle -S",
|
|
|
|
"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",
|
|
|
|
"iwinfo",
|
2018-09-01 17:39:19 -06:00
|
|
|
"iwinfo ${wifiif} assoclist",
|
|
|
|
"iw phy ${phy} info",
|
|
|
|
"iw dev ${wifiif} info",
|
|
|
|
"iw dev ${wifiif} scan",
|
|
|
|
"iw dev ${wifiif} station dump",
|
2015-05-08 20:52:49 -06:00
|
|
|
"logread",
|
|
|
|
"md5sum /www/cgi-bin/*",
|
2015-05-24 14:29:49 -06:00
|
|
|
"echo /all | nc 127.0.0.1 2006",
|
2015-05-08 20:52:49 -06:00
|
|
|
"opkg list-installed",
|
|
|
|
"ps -w",
|
|
|
|
"/usr/local/bin/get_hardwaretype",
|
|
|
|
"/usr/local/bin/get_boardid",
|
|
|
|
"/usr/local/bin/get_model",
|
2018-05-13 22:02:57 -06:00
|
|
|
"/usr/local/bin/get_hardware_mfg",
|
|
|
|
);
|
|
|
|
|
|
|
|
@cmds_ubnt = (
|
|
|
|
"cat /dev/mtd0|grep 'U-Boot'|head -n1",
|
2015-05-08 20:52:49 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
$FREE_SPACE_TMP=get_free_space("/tmp");
|
|
|
|
|
2018-05-13 22:02:57 -06:00
|
|
|
$mfg = `/usr/local/bin/get_hardware_mfg`;
|
|
|
|
chomp($mfg);
|
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
if ($FREE_SPACE_TMP eq "N/A" || $FREE_SPACE_TMP <= 2*1024) {
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
system ("rm", "-r", "-f", "/tmp/sd");
|
|
|
|
|
|
|
|
foreach $path (@files) {
|
|
|
|
|
2018-12-12 14:16:07 -07:00
|
|
|
next if (! -e $path and ! -d $path);
|
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
if ( $path =~ /^\/(.*\/).*\/$/ ) {
|
|
|
|
my $rpath = $1;
|
|
|
|
system("mkdir", "-p", "/tmp/sd/$rpath");
|
|
|
|
system("cp","-r","-p","$path","/tmp/sd/$rpath");
|
|
|
|
} else {
|
|
|
|
$path =~ /^(.*\/).*/;
|
|
|
|
my $sourcepath = $1;
|
|
|
|
system("mkdir", "-p", "/tmp/sd/$sourcepath");
|
|
|
|
system("cp","-r","-p","$path","/tmp/sd/$path");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-24 14:47:16 -06:00
|
|
|
#Remove sensitive files
|
|
|
|
foreach $path (@sensitive) {
|
|
|
|
if ( $path =~ /^\/(.*)/ ) {
|
|
|
|
my $sourcepath = $1;
|
|
|
|
system("rm", "-r", "-f", "/tmp/sd/$sourcepath");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 14:16:07 -07:00
|
|
|
#Remove passwords from config files
|
|
|
|
system ("cat /tmp/sd/etc/config/wireless | sed -e 's/ key.*\$/ key \*\*\*\*\*\*/' > /tmp/sd/etc/config/wireless.sav");
|
|
|
|
unlink "rm /tmp/sd/etc/config/wireless";
|
|
|
|
rename "/tmp/sd/etc/config/wireless.sav", "/tmp/sd/etc/config/wireless";
|
|
|
|
system ("cat /tmp/sd/etc/config.mesh/_setup | sed -e 's/_key =.*\$/_key =/' > /tmp/sd/etc/config.mesh/_setup.sav");
|
|
|
|
unlink "/tmp/sd/etc/config.mesh/_setup";
|
|
|
|
rename "/tmp/sd/etc/config.mesh/_setup.sav", "/tmp/sd/etc/config.mesh/_setup";
|
2015-05-24 14:47:16 -06:00
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
|
|
|
|
system("touch","/tmp/sd/data.txt");
|
|
|
|
open (my $CMDS_OUT, '>', '/tmp/sd/data.txt') or die "Could not open dump file";
|
|
|
|
foreach $cmd (@cmds) {
|
|
|
|
print $CMDS_OUT "========== $cmd ==========\n";
|
|
|
|
open(my $CMD_PIPE, "-|", $cmd ) or next;
|
|
|
|
while (<$CMD_PIPE>) {
|
|
|
|
print { $CMDS_OUT } $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 22:02:57 -06:00
|
|
|
if ( $mfg eq "Ubiquiti" ) {
|
|
|
|
foreach $cmd (@cmds_ubnt) {
|
|
|
|
print $CMDS_OUT "========== $cmd (UBNT only) ==========\n";
|
|
|
|
open(my $CMD_PIPE, "-|", $cmd ) or next;
|
|
|
|
while (<$CMD_PIPE>) {
|
|
|
|
print { $CMDS_OUT } $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
close ($CMDS_OUT);
|
|
|
|
|
|
|
|
system("tar", "-zcf", "/tmp/supportdata.tgz", "-C", "/tmp/sd", "./");
|
|
|
|
|
2016-12-27 21:06:05 -07:00
|
|
|
# Cleanup the temp files
|
|
|
|
system ("rm", "-r", "-f", "/tmp/sd");
|
|
|
|
|
2015-05-24 15:17:31 -06:00
|
|
|
$nodename=`uname -n`;
|
|
|
|
chomp($nodename);
|
|
|
|
$tstamp=`date +%Y%m%d%H%M`;
|
|
|
|
chomp($tstamp);
|
|
|
|
|
2015-05-08 20:52:49 -06:00
|
|
|
open(my $SDFH, '<', "/tmp/supportdata.tgz") or exit(1);
|
|
|
|
binmode $SDFH;
|
|
|
|
|
2016-12-25 14:40:57 -07:00
|
|
|
if (exists $ENV{GATEWAY_INTERFACE}) {
|
|
|
|
print "Content-type: application/x-gzip\r\n";
|
|
|
|
print "Content-Disposition: attachment; filename=supportdata-$nodename-$tstamp.tgz\r\n";
|
|
|
|
print "\r\n";
|
|
|
|
|
|
|
|
print while <$SDFH>;
|
|
|
|
undef ($SDFH);
|
|
|
|
|
|
|
|
unlink("/tmp/supportdata.tgz");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
undef ($SDFH);
|
|
|
|
unlink ("/tmp/supportdata-$nodename-$tstamp.tgz"); # Shouldn't exist but lets be sure
|
|
|
|
system ("mv", "/tmp/supportdata.tgz", "/tmp/supportdata-$nodename-$tstamp.tgz");
|
|
|
|
if ($? != 0) {
|
|
|
|
print "Failed to rename the support data file.\n It may be present at /tmp/supportdata.tgz\n";
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
print "File created: /tmp/supportdata-$nodename-$tstamp.tgz\n";
|
|
|
|
print "Please copy this file and remove from the node\n";
|
|
|
|
print "to free up resources.\n"
|
|
|
|
}
|
|
|
|
}
|