mirror of https://github.com/aredn/aredn.git
Lua stragglers (#274)
* Final bits of perl replaced by lua * Use iwinfo during first boot (api I was using fails this early) * Retry getting phy device (it can fail as the node is booting up)
This commit is contained in:
parent
922a74d574
commit
a0e7749b1e
|
@ -1,141 +1,108 @@
|
||||||
#!/usr/bin/perl -w
|
#! /usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
Copyright (C) 2015 Conrad Lara
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
See Contributors file for additional contributors
|
Original Perl Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
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 free software: you can redistribute it and/or modify
|
This program is distributed in the hope that it will be useful,
|
||||||
it under the terms of the GNU General Public License as published by
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
the Free Software Foundation version 3 of the License.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
You should have received a copy of the GNU General Public License
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
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
|
Additional Terms:
|
||||||
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.
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
See AREDNLicense.txt for more info.
|
If importing this code into a new or existing project attribution
|
||||||
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
You must not misrepresent the origin of the material contained within.
|
||||||
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
|
||||||
|
|
||||||
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
|
-- do the initial setup of the essential nvram variables
|
||||||
|
-- node - node name
|
||||||
|
-- mac2 - last 3 bytes of wifi mac address in the form ddd.ddd.ddd
|
||||||
|
-- wifi_mac - full mac address of wireless card in the form hh:hh:hh:hh:hh:hh
|
||||||
|
--
|
||||||
|
-- intended to run every boot but it should only actually do anything
|
||||||
|
-- on the first boot
|
||||||
|
|
||||||
# do the initial setup of the essential nvram variables
|
require("aredn.utils")
|
||||||
# node - node name
|
require("iwinfo")
|
||||||
# mac2 - last 3 bytes of wifi mac address in the form ddd.ddd.ddd
|
require("aredn.hardware")
|
||||||
# wifi_mac - full mac address of wireless card in the form hh:hh:hh:hh:hh:hh
|
local aredn_info = require('aredn.info')
|
||||||
#
|
|
||||||
# intended to run every boot but it should only actually do anything
|
|
||||||
# on the first boot
|
|
||||||
|
|
||||||
sub fail
|
local wifi_mac = aredn_info.get_nvram("wifimac")
|
||||||
{
|
local mac2 = aredn_info.get_nvram("mac2")
|
||||||
open(ERR, ">>/tmp/nvram_errors");
|
local node = aredn_info.get_nvram("node")
|
||||||
print ERR "@_\n";
|
local dtdmac = aredn_info.get_nvram("dtdmac")
|
||||||
close(ERR);
|
|
||||||
die "@_\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_wlan2phy
|
local hardware_mac
|
||||||
{
|
if wifi_mac == "" or mac2 == "" then
|
||||||
my ($wlan) = $1;
|
local phy
|
||||||
my ($phy) = "";
|
for i = 1,5
|
||||||
return "phy0" unless $wlan;
|
do
|
||||||
foreach(`iwinfo $wlan info`)
|
local f = io.popen("iwinfo " .. get_ifname("wifi") .. " info")
|
||||||
{
|
if f then
|
||||||
next unless /^.*PHY name:\s*([a-z0-4]+)/;
|
for line in f:lines()
|
||||||
$phy = $1;
|
do
|
||||||
}
|
phy = line:match("PHY name:%s*([a-z0-4]+)")
|
||||||
return $phy;
|
if phy then
|
||||||
}
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
if phy then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
sleep(5);
|
||||||
|
end
|
||||||
|
for line in io.lines("/sys/class/ieee80211/" .. phy .. "/macaddress")
|
||||||
|
do
|
||||||
|
local m = line:match("(%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)")
|
||||||
|
if m then
|
||||||
|
hardware_mac = m
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not hardware_mac then
|
||||||
|
io.stderr:write("ERROR: hardware mac not found\n")
|
||||||
|
os.exit(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
$commit = 0;
|
if wifi_mac == "" then
|
||||||
$wifiif = `uci -q get network.wifi.ifname`;
|
aredn_info.set_nvram("wifimac", hardware_mac)
|
||||||
$phy = get_wlan2phy("$wifiif");
|
end
|
||||||
|
|
||||||
# Added new wifimac parm, the radio* wont startup without it, use the path location in wifi config
|
if mac2 == "" then
|
||||||
# Actually it just needs some path to get to the radio.
|
local a, b, c = hardware_mac:match("%w%w:%w%w:%w%w:(%w%w):(%w%w):(%w%w)")
|
||||||
|
mac2 = string.format("%d.%d.%d", tonumber(a, 16), tonumber(b, 16), tonumber(c, 16))
|
||||||
|
aredn_info.set_nvram("mac2", mac2)
|
||||||
|
end
|
||||||
|
|
||||||
chomp ($wifi_mac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.wifimac`);
|
if node == "" then
|
||||||
|
aredn_info.set_nvram("node", "NOCALL-" .. mac2:gsub("%.", "-"))
|
||||||
|
end
|
||||||
|
|
||||||
if($wifi_mac eq "")
|
if dtdmac == "" then
|
||||||
{
|
local a, b, c = aredn.hardware.get_interface_mac(aredn.hardware.get_iface_name("lan")):match("%w%w:%w%w:%w%w:(%w%w):(%w%w):(%w%w)")
|
||||||
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
aredn_info.set_nvram("dtdmac", string.format("%d.%d.%d", tonumber(a, 16), tonumber(b, 16), tonumber(c, 16)))
|
||||||
while(<FILE>)
|
end
|
||||||
{
|
|
||||||
next unless /(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/;
|
|
||||||
$wifi_mac = $1;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
close(FILE);
|
|
||||||
fail("ERROR: wireless mac not found") if $wifi_mac eq "";
|
|
||||||
system "uci -c /etc/local/uci/ set hsmmmesh.settings.wifimac=$wifi_mac";
|
|
||||||
$commit = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
chomp ($mac2 = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.mac2`);
|
|
||||||
|
|
||||||
if($mac2 eq "")
|
|
||||||
{
|
|
||||||
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
|
||||||
while(<FILE>)
|
|
||||||
{
|
|
||||||
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
|
||||||
$mac2 = join ".", hex $1, hex $2, hex $3;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
close(FILE);
|
|
||||||
fail("ERROR: wireless mac not found") if $mac2 eq "";
|
|
||||||
system "uci -c /etc/local/uci/ set hsmmmesh.settings.mac2=$mac2";
|
|
||||||
$commit = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
chomp ($node = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.node`);
|
|
||||||
|
|
||||||
if($node eq "")
|
|
||||||
{
|
|
||||||
$mac2 =~ s/\./-/g;
|
|
||||||
$node = "NOCALL-$mac2";
|
|
||||||
system "uci -c /etc/local/uci/ set hsmmmesh.settings.node=NOCALL-$mac2";
|
|
||||||
$commit = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
chomp ($dtdmac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.dtdmac`);
|
|
||||||
|
|
||||||
if($dtdmac eq "")
|
|
||||||
{
|
|
||||||
# We should always have an eth0 interface on all nodes.
|
|
||||||
# Not porting get_interface into this file at this time
|
|
||||||
# as on a firstboot where nvram-setup runs the interfaces
|
|
||||||
# should not be changed yet.
|
|
||||||
open(FILE, "/sbin/ifconfig eth0 |") or fail("ERROR: eth0 mac not available");
|
|
||||||
while(<FILE>)
|
|
||||||
{
|
|
||||||
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
|
||||||
$dtdmac = join ".", hex $1, hex $2, hex $3;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
close(FILE);
|
|
||||||
system "uci -c /etc/local/uci/ set hsmmmesh.settings.dtdmac=$dtdmac";
|
|
||||||
$commit = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
system "uci -c /etc/local/uci/ commit" if $commit;
|
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
|
Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
# do the initial setup of the essential nvram variables
|
||||||
|
# node - node name
|
||||||
|
# mac2 - last 3 bytes of wifi mac address in the form ddd.ddd.ddd
|
||||||
|
# wifi_mac - full mac address of wireless card in the form hh:hh:hh:hh:hh:hh
|
||||||
|
#
|
||||||
|
# intended to run every boot but it should only actually do anything
|
||||||
|
# on the first boot
|
||||||
|
|
||||||
|
sub fail
|
||||||
|
{
|
||||||
|
open(ERR, ">>/tmp/nvram_errors");
|
||||||
|
print ERR "@_\n";
|
||||||
|
close(ERR);
|
||||||
|
die "@_\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_wlan2phy
|
||||||
|
{
|
||||||
|
my ($wlan) = $1;
|
||||||
|
my ($phy) = "";
|
||||||
|
return "phy0" unless $wlan;
|
||||||
|
foreach(`iwinfo $wlan info`)
|
||||||
|
{
|
||||||
|
next unless /^.*PHY name:\s*([a-z0-4]+)/;
|
||||||
|
$phy = $1;
|
||||||
|
}
|
||||||
|
return $phy;
|
||||||
|
}
|
||||||
|
|
||||||
|
$commit = 0;
|
||||||
|
$wifiif = `uci -q get network.wifi.ifname`;
|
||||||
|
$phy = get_wlan2phy("$wifiif");
|
||||||
|
|
||||||
|
# Added new wifimac parm, the radio* wont startup without it, use the path location in wifi config
|
||||||
|
# Actually it just needs some path to get to the radio.
|
||||||
|
|
||||||
|
chomp ($wifi_mac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.wifimac`);
|
||||||
|
|
||||||
|
if($wifi_mac eq "")
|
||||||
|
{
|
||||||
|
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
||||||
|
while(<FILE>)
|
||||||
|
{
|
||||||
|
next unless /(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/;
|
||||||
|
$wifi_mac = $1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
close(FILE);
|
||||||
|
fail("ERROR: wireless mac not found") if $wifi_mac eq "";
|
||||||
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.wifimac=$wifi_mac";
|
||||||
|
$commit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
chomp ($mac2 = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.mac2`);
|
||||||
|
|
||||||
|
if($mac2 eq "")
|
||||||
|
{
|
||||||
|
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available");
|
||||||
|
while(<FILE>)
|
||||||
|
{
|
||||||
|
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
||||||
|
$mac2 = join ".", hex $1, hex $2, hex $3;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
close(FILE);
|
||||||
|
fail("ERROR: wireless mac not found") if $mac2 eq "";
|
||||||
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.mac2=$mac2";
|
||||||
|
$commit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
chomp ($node = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.node`);
|
||||||
|
|
||||||
|
if($node eq "")
|
||||||
|
{
|
||||||
|
$mac2 =~ s/\./-/g;
|
||||||
|
$node = "NOCALL-$mac2";
|
||||||
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.node=NOCALL-$mac2";
|
||||||
|
$commit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
chomp ($dtdmac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.dtdmac`);
|
||||||
|
|
||||||
|
if($dtdmac eq "")
|
||||||
|
{
|
||||||
|
# We should always have an eth0 interface on all nodes.
|
||||||
|
# Not porting get_interface into this file at this time
|
||||||
|
# as on a firstboot where nvram-setup runs the interfaces
|
||||||
|
# should not be changed yet.
|
||||||
|
open(FILE, "/sbin/ifconfig eth0 |") or fail("ERROR: eth0 mac not available");
|
||||||
|
while(<FILE>)
|
||||||
|
{
|
||||||
|
next unless /\w\w:\w\w:\w\w:(\w\w):(\w\w):(\w\w)/;
|
||||||
|
$dtdmac = join ".", hex $1, hex $2, hex $3;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
close(FILE);
|
||||||
|
system "uci -c /etc/local/uci/ set hsmmmesh.settings.dtdmac=$dtdmac";
|
||||||
|
$commit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
system "uci -c /etc/local/uci/ commit" if $commit;
|
|
@ -1,50 +1,48 @@
|
||||||
#!/usr/bin/perl -w
|
#! /usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
Copyright (C) 2015 Conrad Lara
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
See Contributors file for additional contributors
|
Original Perl Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
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 free software: you can redistribute it and/or modify
|
This program is distributed in the hope that it will be useful,
|
||||||
it under the terms of the GNU General Public License as published by
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
the Free Software Foundation version 3 of the License.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
You should have received a copy of the GNU General Public License
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
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
|
Additional Terms:
|
||||||
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.
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
See AREDNLicense.txt for more info.
|
If importing this code into a new or existing project attribution
|
||||||
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
You must not misrepresent the origin of the material contained within.
|
||||||
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
|
||||||
|
|
||||||
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
|
if #arg ~= 1 then
|
||||||
|
io.stderr:write("usage: setpasswd <password>\nthis sets both the system and website paswords\n")
|
||||||
|
os.exit(-1)
|
||||||
|
end
|
||||||
|
|
||||||
unless(defined ($pw = shift))
|
local pw = arg[1]:gsub("'", "\\'")
|
||||||
{
|
local f = io.popen("{ echo '" .. pw .. "'; sleep 1; echo '" .. pw .. "'; } | passwd")
|
||||||
print STDERR "\nusage: setpasswd <password>\n";
|
f:read("*a")
|
||||||
print STDERR "this sets both the system and website paswords\n\n";
|
f:close()
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pw2 = $pw;
|
io.stderr:write("passwords changed.\n")
|
||||||
$pw2 =~ s/'/'\\''/g;
|
|
||||||
system "{ echo '$pw2'; sleep 1; echo '$pw2'; } | passwd > /dev/null\n";
|
|
||||||
|
|
||||||
print STDERR "passwords changed.\n";
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
|
Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
unless(defined ($pw = shift))
|
||||||
|
{
|
||||||
|
print STDERR "\nusage: setpasswd <password>\n";
|
||||||
|
print STDERR "this sets both the system and website paswords\n\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pw2 = $pw;
|
||||||
|
$pw2 =~ s/'/'\\''/g;
|
||||||
|
system "{ echo '$pw2'; sleep 1; echo '$pw2'; } | passwd > /dev/null\n";
|
||||||
|
|
||||||
|
print STDERR "passwords changed.\n";
|
|
@ -1,335 +1,315 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
||||||
Copyright (C) 2015 Conrad Lara
|
|
||||||
See Contributors file for additional contributors
|
|
||||||
|
|
||||||
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
|
Original Perl Copyright (c) 2015 Joe Ayers AE6XE
|
||||||
|
Original Perl Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
2015-04-01 AE6XE update to display neighbor nodes, replace vendor with mode
|
2015-04-01 AE6XE update to display neighbor nodes, replace vendor with mode
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation version 3 of the License.
|
the Free Software Foundation version 3 of the License.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Additional Terms:
|
Additional Terms:
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
||||||
See AREDNLicense.txt for more info.
|
See AREDNLicense.txt for more info.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
If importing this code into a new or existing project attribution
|
If importing this code into a new or existing project attribution
|
||||||
to the AREDN project must be added to the source code.
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
You must not misrepresent the origin of the material contained within.
|
You must not misrepresent the origin of the material contained within.
|
||||||
|
|
||||||
Modified versions must be modified to attribute to the original source
|
Modified versions must be modified to attribute to the original source
|
||||||
and be marked in reasonable ways as differentiate it from the original
|
and be marked in reasonable ways as differentiate it from the original
|
||||||
version.
|
version
|
||||||
|
|
||||||
=cut
|
--]]
|
||||||
|
|
||||||
sub usage
|
require("nixio")
|
||||||
{
|
require("aredn.utils")
|
||||||
print "usage: wscan [-1abnor] [-i iface]\n";
|
require("aredn.hardware")
|
||||||
print " -1 run once and quit\n";
|
aredn.info = require("aredn.info")
|
||||||
print " -a average mode\n";
|
|
||||||
print " -b batch mode\n";
|
|
||||||
print " -n <num> number of times to scan\n";
|
|
||||||
print " -o show only open access points\n";
|
|
||||||
print " -r raw mode\n";
|
|
||||||
print " -w produce html output\n";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub freq_to_chan
|
function usage()
|
||||||
{
|
print("usage: wscan [-1abnor] [-i iface]")
|
||||||
my ($freq) = @_;
|
print(" -1 run once and quit")
|
||||||
|
print(" -a average mode")
|
||||||
|
print(" -b batch mode")
|
||||||
|
print(" -n <num> number of times to scan")
|
||||||
|
print(" -o show only open access points")
|
||||||
|
print(" -r raw mode")
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
|
||||||
if ($freq < 256 )
|
function die(msg)
|
||||||
{
|
print(msg)
|
||||||
return $freq;
|
os.exit(1)
|
||||||
}
|
end
|
||||||
elsif ($freq == 2484)
|
|
||||||
{
|
|
||||||
return "14";
|
|
||||||
}
|
|
||||||
elsif ($freq == 2407)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
elsif ($freq < 2484)
|
|
||||||
{
|
|
||||||
return ($freq-2407)/5;
|
|
||||||
}
|
|
||||||
elsif ($freq < 5000)
|
|
||||||
{
|
|
||||||
return $freq ; # stay in freq, no ch #s
|
|
||||||
}
|
|
||||||
elsif ($freq < 5380) # these are 5Ghz channels 75 and below
|
|
||||||
{
|
|
||||||
return ($freq-5000)/5 ;
|
|
||||||
}
|
|
||||||
elsif ($freq < 5500) # ch 76 to 99 can only be 3Ghz freq, no part 15 here
|
|
||||||
{
|
|
||||||
return ($freq-2000); # return 3ghz freq (5ghz boards with -2Ghz transverter)
|
|
||||||
}
|
|
||||||
elsif ($freq < 6000)
|
|
||||||
{
|
|
||||||
return ($freq-5000)/5;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $freq;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub pushAP
|
function freq_to_chan(freq)
|
||||||
{
|
local chan = freq
|
||||||
my($signal, $freq, $key, $ssid, $host, $mac, $mode) = @_;
|
if chan < 256 then
|
||||||
|
elseif chan == 2484 then
|
||||||
|
return 14
|
||||||
|
elseif chan == 2407 then
|
||||||
|
return 0
|
||||||
|
elseif chan < 2484 then
|
||||||
|
return (chan - 2407) / 5
|
||||||
|
elseif chan < 5000 then
|
||||||
|
elseif chan < 5380 then
|
||||||
|
return (chan - 5000) / 5
|
||||||
|
elseif chan < 5500 then
|
||||||
|
return chan - 2000
|
||||||
|
elseif chan < 6000 then
|
||||||
|
return (chan - 5000) / 5
|
||||||
|
end
|
||||||
|
return "?"
|
||||||
|
end
|
||||||
|
|
||||||
return if $mac eq "";
|
-- load arp cache
|
||||||
return if $openap and ($key ne "");
|
local arpcache = {}
|
||||||
|
arptable(function(a)
|
||||||
|
arpcache[a["HW address"]] = a["IP address"]
|
||||||
|
end)
|
||||||
|
|
||||||
$chan=freq_to_chan($freq);
|
local hostcache = {}
|
||||||
|
function mac_to_host(mac)
|
||||||
if($ssid eq "") { $ssid = "(hidden)" }
|
if not mac then
|
||||||
if($chan eq "") { $chan = "?" }
|
return "N/A"
|
||||||
|
end
|
||||||
if($key eq "") { $key = " " }
|
local host = hostcache[mac]
|
||||||
else { $key = "*" }
|
if host then
|
||||||
|
return host
|
||||||
if($avg)
|
end
|
||||||
{
|
local ip = arpcache[mac]
|
||||||
$avgs{"$mac total"} += $signal;
|
if ip then
|
||||||
$avgs{"$mac num"} += 1;
|
hostname = ip
|
||||||
$aphash{$mac} = sprintf "% 3d %s %-32s\t%s\t%s\t%s\n",
|
local f = io.popen("nslookup " .. ip)
|
||||||
$chan, $key, $ssid, $host, $mac, $mode;
|
if f then
|
||||||
}
|
for line in f:lines()
|
||||||
elsif($web)
|
do
|
||||||
{
|
local m = line:match("name = (.*)%.local%.mesh")
|
||||||
push @list, sprintf "% 3d|%d|%s|%s|%s|%s|%s",
|
if m then
|
||||||
$signal, $chan, $key, sprintf("&#x%*vX", '&#x',$ssid), $host, $mac, $mode;
|
f:close()
|
||||||
}
|
hostcache[mac] = m
|
||||||
else
|
return m
|
||||||
{
|
end
|
||||||
push @list, sprintf "% 3d %2d %s %-32s\t%s\t%s\t%s\n",
|
end
|
||||||
$signal, $chan, $key, $ssid, $host, $mac, $mode;
|
f:close()
|
||||||
}
|
end
|
||||||
}
|
|
||||||
|
|
||||||
###################################################
|
|
||||||
|
|
||||||
$avg = 0; # average mode
|
|
||||||
$batch = 0; # batch mode
|
|
||||||
$loops = 0; # number of times to run 0=inf
|
|
||||||
$raw = 0; # raw mode
|
|
||||||
$openap = 0; # show open ap's
|
|
||||||
$iface = `uci -q get 'network.wifi.ifname'`; # wireless interface
|
|
||||||
chomp $iface;
|
|
||||||
|
|
||||||
$iters = 0; # number of iterations
|
|
||||||
%avgs = (); # average statistics
|
|
||||||
%aphash = (); # list of ap's for avg mode
|
|
||||||
|
|
||||||
$mychan = `iwinfo $iface info | grep -i channel`;
|
|
||||||
$mychan =~ /Channel:\s+(-*\d+)/;
|
|
||||||
$mychan = ( ! defined $1 || ! int($1) || ! ($1 >= -4 && $1 <= 185) ) ? 0 : $1;
|
|
||||||
|
|
||||||
# ch 76 - 99 are 3ghz since no part 15 usage (5ghz board with -2ghz transverter)
|
|
||||||
if ($mychan >= 76 and $mychan <= 99)
|
|
||||||
{
|
|
||||||
$mychan = ($mychan*5+3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(defined ($arg = shift))
|
|
||||||
{
|
|
||||||
if ($arg eq "-h") { usage() }
|
|
||||||
elsif($arg eq "-1") { $loops = 1 }
|
|
||||||
elsif($arg eq "-a") { $avg = 1 }
|
|
||||||
elsif($arg eq "-b") { $batch = 1 }
|
|
||||||
elsif($arg eq "-o") { $openap = 1 }
|
|
||||||
elsif($arg eq "-r") { $raw = 1 }
|
|
||||||
elsif($arg eq "-i") { $iface = shift }
|
|
||||||
elsif($arg eq "-n") { $loops = shift }
|
|
||||||
elsif($arg eq "-w") { $web = 1 }
|
|
||||||
else { die "bad arg $arg\n" }
|
|
||||||
}
|
|
||||||
|
|
||||||
die "bad interface" if not defined $iface;
|
|
||||||
|
|
||||||
if($raw)
|
|
||||||
{
|
|
||||||
system("iw dev $iface scan passive");
|
|
||||||
system("iw dev $iface station dump");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
$line = `egrep "['\\"].*-(5|10|20)-v[3456]" /etc/config/wireless | head -1`;
|
|
||||||
$line =~ /['"](.*-(5|10|20)-v[3456])/;
|
|
||||||
$myssid = $1;
|
|
||||||
|
|
||||||
open(FILE, "iw dev $iface scan passive 2>&1 |") or die "iw scan failed";
|
|
||||||
$mac = "";
|
|
||||||
$host = "N/A";
|
|
||||||
$lastseen = 0;
|
|
||||||
@list = ();
|
|
||||||
|
|
||||||
while($line = <FILE>)
|
|
||||||
{
|
|
||||||
if($line =~ /BSS\s+(([[:xdigit:]]{2}:){5}[[:xdigit:]]{2})/)
|
|
||||||
{
|
|
||||||
if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $host, $mac, $mode) }
|
|
||||||
$mac = uc $1;
|
|
||||||
|
|
||||||
$mode = "AP";
|
|
||||||
$ssid = "";
|
|
||||||
$signal = 0;
|
|
||||||
$chan = "";
|
|
||||||
$key = "";
|
|
||||||
$lastseen = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if($line =~ /BSS(\s+)([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}.*joined/)
|
|
||||||
{
|
|
||||||
$mode = "My Ad-Hoc Network";
|
|
||||||
$chan = $mychan;
|
|
||||||
}
|
|
||||||
if($line =~ /\bSSID: (.*)/) { $ssid = $1 }
|
|
||||||
if($line =~ /\bSSID: unknown/) { $ssid = "unknown" }
|
|
||||||
if($line =~ /\bcapability: (IBSS)/ and $mode eq "AP")
|
|
||||||
{ $mode = "Foreign Ad-Hoc Network" }
|
|
||||||
if($line =~ /\bfreq: (\d+)/) { $chan = $1 }
|
|
||||||
if($line =~ /\bsignal: ([\d-]+)/) { $signal = $1 }
|
|
||||||
if($line =~ /\bGroup cipher:(.+)/) { $key = $1 }
|
|
||||||
if($line =~ /\blast seen: (\d+)/) { $lastseen = $1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
close(FILE);
|
|
||||||
|
|
||||||
if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $host, $mac, $mode) }
|
|
||||||
sleep 1 if not scalar @list and $loops != 1;
|
|
||||||
|
|
||||||
$mac = "";
|
|
||||||
$mode = "Connected Ad-Hoc Station";
|
|
||||||
$signal = 0;
|
|
||||||
$key = "";
|
|
||||||
$lastseen = 0;
|
|
||||||
++$iters;
|
|
||||||
|
|
||||||
open(FILE, "iw dev $iface station dump 2>&1 |") or die "iw failed";
|
|
||||||
|
|
||||||
while($line = <FILE>)
|
|
||||||
{
|
|
||||||
if($line =~ /Station (\S+) \(on $iface\)/)
|
|
||||||
{
|
|
||||||
if ( $lastseen < 10000 ) { pushAP($signal, $mychan, $key, $myssid, $host, $mac, $mode) }
|
|
||||||
|
|
||||||
$lastseen = 0;
|
|
||||||
$mac = $1;
|
|
||||||
$ip = `grep $mac /proc/net/arp | egrep "^10.*\$" | tail -1`;
|
|
||||||
$mac = uc $mac;
|
|
||||||
if ( $ip ne "" )
|
|
||||||
{
|
|
||||||
$ip =~ s/[ \t].*$// ;
|
|
||||||
chomp($ip);
|
|
||||||
$host = $ip;
|
|
||||||
if( $ip ne "")
|
|
||||||
{
|
|
||||||
$reverse_ip=join ".",reverse(split /\./,$ip);
|
|
||||||
foreach(`nslookup $ip`)
|
|
||||||
{
|
|
||||||
last if ($host) = /^$reverse_ip\.in-addr\.arpa[ \t]+name[ \t]+=[ \t]+(\S+)\.local\.mesh/;
|
|
||||||
}
|
|
||||||
if ( $host eq "" ) { $host = $ip }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { $host = "????" }
|
|
||||||
}
|
|
||||||
|
|
||||||
if($line =~ /signal avg:[ \t]+([-\d]+)/) { $signal = $1 }
|
|
||||||
if($line =~ /inactive time:\t(\d+) ms/) { $lastseen = $1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
close(FILE);
|
|
||||||
if ( $lastseen < 10000 ) { pushAP($signal, $mychan, $key, $myssid, $host, $mac, $mode) }
|
|
||||||
|
|
||||||
sleep 1 if not scalar @list and $loops != 1;
|
|
||||||
|
|
||||||
if(not $batch)
|
|
||||||
{
|
|
||||||
if($avg)
|
|
||||||
{
|
|
||||||
system "clear";
|
|
||||||
printf "Sig Rel Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d\n", $iters;
|
|
||||||
print "--- --- -- - -------------------------------- ----------------- ------------- -----------\n";
|
|
||||||
}
|
|
||||||
elsif($web)
|
|
||||||
{
|
|
||||||
print "<table class=sortable border=1 cellpadding=5>\n";
|
|
||||||
print "<tr><th>Sig</th><th>Chan</th><th>Enc</th><th>SSID</th><th>Hostname</th><th>MAC/BSSID</th><th>802.11 Mode</th></tr>\n";
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
hostcache[mac] = "N/A"
|
||||||
#system "clear";
|
return "N/A"
|
||||||
printf "Sig Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d\n", $iters;
|
end
|
||||||
print "--- -- - -------------------------------- --------------------- ------------- ------------\n";
|
end
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($avg)
|
local avg = false -- average mode
|
||||||
{
|
local batch = false -- batch mode
|
||||||
open(FILE, "| sort -nr");
|
local loops = 0 -- number of times to run 0=inf
|
||||||
foreach $mac (keys %aphash)
|
local raw = false -- raw mode
|
||||||
{
|
local openap = false -- show open ap's
|
||||||
printf FILE "%3d %3d %s",
|
|
||||||
($avgs{"$mac total"} - $avgs{"$mac num"} + 1)/$avgs{"$mac num"},
|
|
||||||
100*$avgs{"$mac num"}/$iters,
|
|
||||||
$aphash{$mac};
|
|
||||||
}
|
|
||||||
close(FILE);
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
elsif($web)
|
|
||||||
{
|
|
||||||
foreach $line (sort { $b <=> $a } @list)
|
|
||||||
{
|
|
||||||
|
|
||||||
# Match "AREDN"
|
local iface = aredn.hardware.get_iface_name("wifi") -- wifi interface
|
||||||
if ( $line =~ /AREDN/) { print "<tr class=\"wscan-row-node\">"}
|
|
||||||
else { print "<tr>"}
|
|
||||||
|
|
||||||
my $i = 0;
|
local iters = 0 -- number of iterations
|
||||||
foreach $val (split /\|/, $line)
|
local avgs = {} -- average statistics
|
||||||
{
|
|
||||||
$val = " " unless $val =~ /\S/;
|
|
||||||
if($i++ == 3) { print "<td>$val</td>" }
|
|
||||||
else { print "<td align=center>$val</td>" }
|
|
||||||
}
|
|
||||||
print "<td> </td>" if $i < 7;
|
|
||||||
print "</tr>\n";
|
|
||||||
}
|
|
||||||
print "</table>\n";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
open(FILE, "| sort -nr");
|
|
||||||
print FILE @list;
|
|
||||||
close(FILE);
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
last if --$loops == 0;
|
local i = 1
|
||||||
}
|
while i <= #arg
|
||||||
|
do
|
||||||
|
local a = arg[i]
|
||||||
|
i = i + 1
|
||||||
|
if a == "-h" then
|
||||||
|
usage()
|
||||||
|
elseif a == "-1" then
|
||||||
|
loops = 1
|
||||||
|
elseif a == "-a" then
|
||||||
|
avg = true
|
||||||
|
elseif a == "-b" then
|
||||||
|
batch = true
|
||||||
|
elseif a == "-o" then
|
||||||
|
openap = true
|
||||||
|
elseif a == "-r" then
|
||||||
|
raw = true
|
||||||
|
elseif a == "-i" then
|
||||||
|
iface = arg[i]
|
||||||
|
i = i + 1
|
||||||
|
elseif a == "-n" then
|
||||||
|
loops = tonumber(arg[i])
|
||||||
|
i = i + 1
|
||||||
|
else
|
||||||
|
die("bad arg " .. a)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not iface or iface == "" then
|
||||||
|
die("bad interface")
|
||||||
|
end
|
||||||
|
|
||||||
|
if raw then
|
||||||
|
os.execute("iw dev " .. iface .. " scan passive")
|
||||||
|
os.execute("iw dev " .. iface .. " station dump")
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
|
||||||
|
if loops == 0 then
|
||||||
|
loops = math.huge
|
||||||
|
end
|
||||||
|
|
||||||
|
local myssid = aredn.info.getSSID()
|
||||||
|
local myfreq = tonumber(aredn.info.getFreq())
|
||||||
|
|
||||||
|
for _ = 1,loops
|
||||||
|
do
|
||||||
|
-- scan start
|
||||||
|
local scanned = {}
|
||||||
|
local f = io.popen("iw dev " .. iface .. " scan passive")
|
||||||
|
if f then
|
||||||
|
local scan
|
||||||
|
for line in f:lines()
|
||||||
|
do
|
||||||
|
local m = line:match("^BSS ([%da-fA-F:]+)")
|
||||||
|
if m then
|
||||||
|
scan = {
|
||||||
|
mac = m,
|
||||||
|
mode = "AP",
|
||||||
|
ssid = "",
|
||||||
|
signal = 0,
|
||||||
|
freq = 0,
|
||||||
|
key = ""
|
||||||
|
}
|
||||||
|
scanned[#scanned + 1] = scan
|
||||||
|
if line:match("joined") then
|
||||||
|
scan.mode = "My Ad-Hoc Network"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
m = line:match("freq: (%d+)")
|
||||||
|
if m then
|
||||||
|
scan.freq = tonumber(m)
|
||||||
|
end
|
||||||
|
m = line:match("SSID: (.+)")
|
||||||
|
if m then
|
||||||
|
scan.ssid = m
|
||||||
|
end
|
||||||
|
m = line:match("signal: ([%d-]+)")
|
||||||
|
if m then
|
||||||
|
scan.signal = tonumber(m)
|
||||||
|
end
|
||||||
|
m = line:match("Group cipher: (.+)")
|
||||||
|
if m then
|
||||||
|
scan.key = m
|
||||||
|
end
|
||||||
|
if line:match("capability: IBSS") and scan.mode == "AP" then
|
||||||
|
scan.mode = "Foreign Ad-Hoc Network"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
local f = io.popen("iw dev " .. iface .. " station dump")
|
||||||
|
if f then
|
||||||
|
local scan
|
||||||
|
for line in f:lines()
|
||||||
|
do
|
||||||
|
local m = line:match("^Station ([%da-fA-F:]+) %(on " .. iface .. "%)")
|
||||||
|
if m then
|
||||||
|
scan = {
|
||||||
|
mac = m,
|
||||||
|
mode = "Connected Ad-Hoc Station",
|
||||||
|
ssid = myssid,
|
||||||
|
signal = 0,
|
||||||
|
freq = myfreq,
|
||||||
|
key = ""
|
||||||
|
}
|
||||||
|
scanned[#scanned + 1] = scan
|
||||||
|
end
|
||||||
|
m = line:match("signal avg:%s+([%d-]+)")
|
||||||
|
if m and scan then
|
||||||
|
scan.signal = tonumber(m)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
-- scan end
|
||||||
|
|
||||||
|
-- update running averages
|
||||||
|
for _, scan in ipairs(scanned)
|
||||||
|
do
|
||||||
|
local v = avgs[scan.mac]
|
||||||
|
if not v then
|
||||||
|
v = { num = 1, total = scan.signal }
|
||||||
|
avgs[scan.mac] = v
|
||||||
|
else
|
||||||
|
v.num = v.num + 1
|
||||||
|
v.total = v.total + scan.signal
|
||||||
|
end
|
||||||
|
v.mac = scan.mac
|
||||||
|
v.mode = scan.mode
|
||||||
|
v.ssid = scan.ssid
|
||||||
|
v.signal = scan.signal
|
||||||
|
v.freq = scan.freq
|
||||||
|
v.key = scan.key
|
||||||
|
end
|
||||||
|
|
||||||
|
if #scanned == 0 and loops ~= 1 then
|
||||||
|
nixio.nanosleep(1, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
iters = iters + 1
|
||||||
|
|
||||||
|
-- create output
|
||||||
|
local output = {}
|
||||||
|
|
||||||
|
if avg then
|
||||||
|
for _, scan in pairs(avgs)
|
||||||
|
do
|
||||||
|
if scan.signal ~= 0 and (not openap or scan.key == "") then
|
||||||
|
local chan = freq_to_chan(scan.freq)
|
||||||
|
local ssid = scan.ssid == "" and "(hidden)" or scan.ssid
|
||||||
|
local key = scan.key == "" and " " or "*"
|
||||||
|
output[#output + 1] = string.format("%3d %3d %3d %s %-32s\t%s\t%s\t%s", math.floor((scan.total - scan.num + 1) / scan.num), math.floor(100 * scan.num / iters), chan, key, ssid, mac_to_host(scan.host), scan.mac:upper(), scan.mode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for _, scan in ipairs(scanned)
|
||||||
|
do
|
||||||
|
if scan.signal ~= 0 and (not openap or scan.key == "") then
|
||||||
|
local chan = freq_to_chan(scan.freq)
|
||||||
|
local ssid = scan.ssid == "" and "(hidden)" or scan.ssid
|
||||||
|
local key = scan.key == "" and " " or "*"
|
||||||
|
output[#output + 1] = string.format("%3d %2d %s %-32s\t%s\t%s\t%s", scan.signal, chan, key, ssid, mac_to_host(scan.host), scan.mac:upper(), scan.mode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(output, function(a,b) return a < b end)
|
||||||
|
|
||||||
|
if not batch then
|
||||||
|
if avg then
|
||||||
|
os.execute("clear")
|
||||||
|
print(string.format("Sig Rel Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d", iters))
|
||||||
|
print("--- --- -- - -------------------------------- ----------------- ------------- -----------")
|
||||||
|
else
|
||||||
|
print(string.format("Sig Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d", iters))
|
||||||
|
print("--- -- - -------------------------------- --------------------- ------------- ------------")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, out in ipairs(output)
|
||||||
|
do
|
||||||
|
print(out)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,335 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
=for comment
|
||||||
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
|
Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
|
||||||
|
2015-04-01 AE6XE update to display neighbor nodes, replace vendor with mode
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub usage
|
||||||
|
{
|
||||||
|
print "usage: wscan [-1abnor] [-i iface]\n";
|
||||||
|
print " -1 run once and quit\n";
|
||||||
|
print " -a average mode\n";
|
||||||
|
print " -b batch mode\n";
|
||||||
|
print " -n <num> number of times to scan\n";
|
||||||
|
print " -o show only open access points\n";
|
||||||
|
print " -r raw mode\n";
|
||||||
|
print " -w produce html output\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub freq_to_chan
|
||||||
|
{
|
||||||
|
my ($freq) = @_;
|
||||||
|
|
||||||
|
if ($freq < 256 )
|
||||||
|
{
|
||||||
|
return $freq;
|
||||||
|
}
|
||||||
|
elsif ($freq == 2484)
|
||||||
|
{
|
||||||
|
return "14";
|
||||||
|
}
|
||||||
|
elsif ($freq == 2407)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
elsif ($freq < 2484)
|
||||||
|
{
|
||||||
|
return ($freq-2407)/5;
|
||||||
|
}
|
||||||
|
elsif ($freq < 5000)
|
||||||
|
{
|
||||||
|
return $freq ; # stay in freq, no ch #s
|
||||||
|
}
|
||||||
|
elsif ($freq < 5380) # these are 5Ghz channels 75 and below
|
||||||
|
{
|
||||||
|
return ($freq-5000)/5 ;
|
||||||
|
}
|
||||||
|
elsif ($freq < 5500) # ch 76 to 99 can only be 3Ghz freq, no part 15 here
|
||||||
|
{
|
||||||
|
return ($freq-2000); # return 3ghz freq (5ghz boards with -2Ghz transverter)
|
||||||
|
}
|
||||||
|
elsif ($freq < 6000)
|
||||||
|
{
|
||||||
|
return ($freq-5000)/5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $freq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub pushAP
|
||||||
|
{
|
||||||
|
my($signal, $freq, $key, $ssid, $host, $mac, $mode) = @_;
|
||||||
|
|
||||||
|
return if $mac eq "";
|
||||||
|
return if $openap and ($key ne "");
|
||||||
|
|
||||||
|
$chan=freq_to_chan($freq);
|
||||||
|
|
||||||
|
if($ssid eq "") { $ssid = "(hidden)" }
|
||||||
|
if($chan eq "") { $chan = "?" }
|
||||||
|
|
||||||
|
if($key eq "") { $key = " " }
|
||||||
|
else { $key = "*" }
|
||||||
|
|
||||||
|
if($avg)
|
||||||
|
{
|
||||||
|
$avgs{"$mac total"} += $signal;
|
||||||
|
$avgs{"$mac num"} += 1;
|
||||||
|
$aphash{$mac} = sprintf "% 3d %s %-32s\t%s\t%s\t%s\n",
|
||||||
|
$chan, $key, $ssid, $host, $mac, $mode;
|
||||||
|
}
|
||||||
|
elsif($web)
|
||||||
|
{
|
||||||
|
push @list, sprintf "% 3d|%d|%s|%s|%s|%s|%s",
|
||||||
|
$signal, $chan, $key, sprintf("&#x%*vX", '&#x',$ssid), $host, $mac, $mode;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
push @list, sprintf "% 3d %2d %s %-32s\t%s\t%s\t%s\n",
|
||||||
|
$signal, $chan, $key, $ssid, $host, $mac, $mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
|
||||||
|
$avg = 0; # average mode
|
||||||
|
$batch = 0; # batch mode
|
||||||
|
$loops = 0; # number of times to run 0=inf
|
||||||
|
$raw = 0; # raw mode
|
||||||
|
$openap = 0; # show open ap's
|
||||||
|
$iface = `uci -q get 'network.wifi.ifname'`; # wireless interface
|
||||||
|
chomp $iface;
|
||||||
|
|
||||||
|
$iters = 0; # number of iterations
|
||||||
|
%avgs = (); # average statistics
|
||||||
|
%aphash = (); # list of ap's for avg mode
|
||||||
|
|
||||||
|
$mychan = `iwinfo $iface info | grep -i channel`;
|
||||||
|
$mychan =~ /Channel:\s+(-*\d+)/;
|
||||||
|
$mychan = ( ! defined $1 || ! int($1) || ! ($1 >= -4 && $1 <= 185) ) ? 0 : $1;
|
||||||
|
|
||||||
|
# ch 76 - 99 are 3ghz since no part 15 usage (5ghz board with -2ghz transverter)
|
||||||
|
if ($mychan >= 76 and $mychan <= 99)
|
||||||
|
{
|
||||||
|
$mychan = ($mychan*5+3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(defined ($arg = shift))
|
||||||
|
{
|
||||||
|
if ($arg eq "-h") { usage() }
|
||||||
|
elsif($arg eq "-1") { $loops = 1 }
|
||||||
|
elsif($arg eq "-a") { $avg = 1 }
|
||||||
|
elsif($arg eq "-b") { $batch = 1 }
|
||||||
|
elsif($arg eq "-o") { $openap = 1 }
|
||||||
|
elsif($arg eq "-r") { $raw = 1 }
|
||||||
|
elsif($arg eq "-i") { $iface = shift }
|
||||||
|
elsif($arg eq "-n") { $loops = shift }
|
||||||
|
elsif($arg eq "-w") { $web = 1 }
|
||||||
|
else { die "bad arg $arg\n" }
|
||||||
|
}
|
||||||
|
|
||||||
|
die "bad interface" if not defined $iface;
|
||||||
|
|
||||||
|
if($raw)
|
||||||
|
{
|
||||||
|
system("iw dev $iface scan passive");
|
||||||
|
system("iw dev $iface station dump");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
$line = `egrep "['\\"].*-(5|10|20)-v[3456]" /etc/config/wireless | head -1`;
|
||||||
|
$line =~ /['"](.*-(5|10|20)-v[3456])/;
|
||||||
|
$myssid = $1;
|
||||||
|
|
||||||
|
open(FILE, "iw dev $iface scan passive 2>&1 |") or die "iw scan failed";
|
||||||
|
$mac = "";
|
||||||
|
$host = "N/A";
|
||||||
|
$lastseen = 0;
|
||||||
|
@list = ();
|
||||||
|
|
||||||
|
while($line = <FILE>)
|
||||||
|
{
|
||||||
|
if($line =~ /BSS\s+(([[:xdigit:]]{2}:){5}[[:xdigit:]]{2})/)
|
||||||
|
{
|
||||||
|
if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $host, $mac, $mode) }
|
||||||
|
$mac = uc $1;
|
||||||
|
|
||||||
|
$mode = "AP";
|
||||||
|
$ssid = "";
|
||||||
|
$signal = 0;
|
||||||
|
$chan = "";
|
||||||
|
$key = "";
|
||||||
|
$lastseen = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($line =~ /BSS(\s+)([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}.*joined/)
|
||||||
|
{
|
||||||
|
$mode = "My Ad-Hoc Network";
|
||||||
|
$chan = $mychan;
|
||||||
|
}
|
||||||
|
if($line =~ /\bSSID: (.*)/) { $ssid = $1 }
|
||||||
|
if($line =~ /\bSSID: unknown/) { $ssid = "unknown" }
|
||||||
|
if($line =~ /\bcapability: (IBSS)/ and $mode eq "AP")
|
||||||
|
{ $mode = "Foreign Ad-Hoc Network" }
|
||||||
|
if($line =~ /\bfreq: (\d+)/) { $chan = $1 }
|
||||||
|
if($line =~ /\bsignal: ([\d-]+)/) { $signal = $1 }
|
||||||
|
if($line =~ /\bGroup cipher:(.+)/) { $key = $1 }
|
||||||
|
if($line =~ /\blast seen: (\d+)/) { $lastseen = $1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
close(FILE);
|
||||||
|
|
||||||
|
if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $host, $mac, $mode) }
|
||||||
|
sleep 1 if not scalar @list and $loops != 1;
|
||||||
|
|
||||||
|
$mac = "";
|
||||||
|
$mode = "Connected Ad-Hoc Station";
|
||||||
|
$signal = 0;
|
||||||
|
$key = "";
|
||||||
|
$lastseen = 0;
|
||||||
|
++$iters;
|
||||||
|
|
||||||
|
open(FILE, "iw dev $iface station dump 2>&1 |") or die "iw failed";
|
||||||
|
|
||||||
|
while($line = <FILE>)
|
||||||
|
{
|
||||||
|
if($line =~ /Station (\S+) \(on $iface\)/)
|
||||||
|
{
|
||||||
|
if ( $lastseen < 10000 ) { pushAP($signal, $mychan, $key, $myssid, $host, $mac, $mode) }
|
||||||
|
|
||||||
|
$lastseen = 0;
|
||||||
|
$mac = $1;
|
||||||
|
$ip = `grep $mac /proc/net/arp | egrep "^10.*\$" | tail -1`;
|
||||||
|
$mac = uc $mac;
|
||||||
|
if ( $ip ne "" )
|
||||||
|
{
|
||||||
|
$ip =~ s/[ \t].*$// ;
|
||||||
|
chomp($ip);
|
||||||
|
$host = $ip;
|
||||||
|
if( $ip ne "")
|
||||||
|
{
|
||||||
|
$reverse_ip=join ".",reverse(split /\./,$ip);
|
||||||
|
foreach(`nslookup $ip`)
|
||||||
|
{
|
||||||
|
last if ($host) = /^$reverse_ip\.in-addr\.arpa[ \t]+name[ \t]+=[ \t]+(\S+)\.local\.mesh/;
|
||||||
|
}
|
||||||
|
if ( $host eq "" ) { $host = $ip }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { $host = "????" }
|
||||||
|
}
|
||||||
|
|
||||||
|
if($line =~ /signal avg:[ \t]+([-\d]+)/) { $signal = $1 }
|
||||||
|
if($line =~ /inactive time:\t(\d+) ms/) { $lastseen = $1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
close(FILE);
|
||||||
|
if ( $lastseen < 10000 ) { pushAP($signal, $mychan, $key, $myssid, $host, $mac, $mode) }
|
||||||
|
|
||||||
|
sleep 1 if not scalar @list and $loops != 1;
|
||||||
|
|
||||||
|
if(not $batch)
|
||||||
|
{
|
||||||
|
if($avg)
|
||||||
|
{
|
||||||
|
system "clear";
|
||||||
|
printf "Sig Rel Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d\n", $iters;
|
||||||
|
print "--- --- -- - -------------------------------- ----------------- ------------- -----------\n";
|
||||||
|
}
|
||||||
|
elsif($web)
|
||||||
|
{
|
||||||
|
print "<table class=sortable border=1 cellpadding=5>\n";
|
||||||
|
print "<tr><th>Sig</th><th>Chan</th><th>Enc</th><th>SSID</th><th>Hostname</th><th>MAC/BSSID</th><th>802.11 Mode</th></tr>\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#system "clear";
|
||||||
|
printf "Sig Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d\n", $iters;
|
||||||
|
print "--- -- - -------------------------------- --------------------- ------------- ------------\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($avg)
|
||||||
|
{
|
||||||
|
open(FILE, "| sort -nr");
|
||||||
|
foreach $mac (keys %aphash)
|
||||||
|
{
|
||||||
|
printf FILE "%3d %3d %s",
|
||||||
|
($avgs{"$mac total"} - $avgs{"$mac num"} + 1)/$avgs{"$mac num"},
|
||||||
|
100*$avgs{"$mac num"}/$iters,
|
||||||
|
$aphash{$mac};
|
||||||
|
}
|
||||||
|
close(FILE);
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
elsif($web)
|
||||||
|
{
|
||||||
|
foreach $line (sort { $b <=> $a } @list)
|
||||||
|
{
|
||||||
|
|
||||||
|
# Match "AREDN"
|
||||||
|
if ( $line =~ /AREDN/) { print "<tr class=\"wscan-row-node\">"}
|
||||||
|
else { print "<tr>"}
|
||||||
|
|
||||||
|
my $i = 0;
|
||||||
|
foreach $val (split /\|/, $line)
|
||||||
|
{
|
||||||
|
$val = " " unless $val =~ /\S/;
|
||||||
|
if($i++ == 3) { print "<td>$val</td>" }
|
||||||
|
else { print "<td align=center>$val</td>" }
|
||||||
|
}
|
||||||
|
print "<td> </td>" if $i < 7;
|
||||||
|
print "</tr>\n";
|
||||||
|
}
|
||||||
|
print "</table>\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
open(FILE, "| sort -nr");
|
||||||
|
print FILE @list;
|
||||||
|
close(FILE);
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
last if --$loops == 0;
|
||||||
|
}
|
|
@ -1,49 +1,53 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
Copyright (C) 2015 Conrad Lara
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
See Contributors file for additional contributors
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation version 3 of the License.
|
the Free Software Foundation version 3 of the License.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Additional Terms:
|
Additional Terms:
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
||||||
See AREDNLicense.txt for more info.
|
See AREDNLicense.txt for more info.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
If importing this code into a new or existing project attribution
|
If importing this code into a new or existing project attribution
|
||||||
to the AREDN project must be added to the source code.
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
You must not misrepresent the origin of the material contained within.
|
You must not misrepresent the origin of the material contained within.
|
||||||
|
|
||||||
Modified versions must be modified to attribute to the original source
|
Modified versions must be modified to attribute to the original source
|
||||||
and be marked in reasonable ways as differentiate it from the original
|
and be marked in reasonable ways as differentiate it from the original
|
||||||
version.
|
version
|
||||||
|
|
||||||
=cut
|
--]]
|
||||||
|
|
||||||
print "Content-type:text\r\n\r\n";
|
require("aredn.utils")
|
||||||
|
|
||||||
$ispermitencblock = `opkg list-installed blockknownencryption|wc -l`;
|
print("Content-type:text\r")
|
||||||
chomp($ispermitencblock);
|
print("\r")
|
||||||
|
|
||||||
if ($ispermitencblock){
|
local ispermitencblock = capture("opkg list-installed blockknownencryption|wc -l"):chomp()
|
||||||
print "Encrypted Traffic: Blocked\n";
|
|
||||||
} else {
|
if ispermitencblock ~= "0" then
|
||||||
print "Encrypted Traffic: Allowed\n";
|
print("Encrypted Traffic: Blocked")
|
||||||
}
|
else
|
||||||
|
print("Encrypted Traffic: Allowed")
|
||||||
|
end
|
||||||
|
|
||||||
|
print("Active firewall rules:")
|
||||||
|
print(capture("/usr/sbin/iptables -L"))
|
||||||
|
|
||||||
print "Active firewall rules:\n";
|
|
||||||
system ("/usr/sbin/iptables -L");
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
print "Content-type:text\r\n\r\n";
|
||||||
|
|
||||||
|
$ispermitencblock = `opkg list-installed blockknownencryption|wc -l`;
|
||||||
|
chomp($ispermitencblock);
|
||||||
|
|
||||||
|
if ($ispermitencblock){
|
||||||
|
print "Encrypted Traffic: Blocked\n";
|
||||||
|
} else {
|
||||||
|
print "Encrypted Traffic: Allowed\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Active firewall rules:\n";
|
||||||
|
system ("/usr/sbin/iptables -L");
|
|
@ -1,206 +1,192 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
Copyright (C) 2015 Conrad Lara
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
See Contributors file for additional contributors
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation version 3 of the License.
|
the Free Software Foundation version 3 of the License.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Additional Terms:
|
Additional Terms:
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
||||||
See AREDNLicense.txt for more info.
|
See AREDNLicense.txt for more info.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
If importing this code into a new or existing project attribution
|
If importing this code into a new or existing project attribution
|
||||||
to the AREDN project must be added to the source code.
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
You must not misrepresent the origin of the material contained within.
|
You must not misrepresent the origin of the material contained within.
|
||||||
|
|
||||||
Modified versions must be modified to attribute to the original source
|
Modified versions must be modified to attribute to the original source
|
||||||
and be marked in reasonable ways as differentiate it from the original
|
and be marked in reasonable ways as differentiate it from the original
|
||||||
version.
|
version
|
||||||
|
|
||||||
=cut
|
--]]
|
||||||
|
|
||||||
BEGIN {push @INC, '/www/cgi-bin'};
|
require("nixio")
|
||||||
use perlfunc;
|
require("aredn.utils")
|
||||||
chomp (${wifiif}=`uci -q get 'network.wifi.ifname'`);
|
require("uci")
|
||||||
$phy=get_wlan2phy("${wifiif}");
|
require("iwinfo")
|
||||||
|
|
||||||
|
|
||||||
@files = ( "/etc/config/",
|
local wifiif = uci.cursor():get("network", "wifi", "ifname")
|
||||||
"/etc/config.mesh/",
|
local phy = iwinfo.nl80211.phyname(wifiif)
|
||||||
"/etc/local/",
|
local mfg = capture("/usr/local/bin/get_hardware_mfg"):chomp()
|
||||||
"/etc/mesh-release",
|
|
||||||
"/tmp/etc/",
|
|
||||||
"/var/run/hosts_olsr",
|
|
||||||
"/tmp/rssi.dat",
|
|
||||||
"/tmp/rssi.log",
|
|
||||||
"/tmp/zombie.log",
|
|
||||||
"/tmp/olsrd.log",
|
|
||||||
"/tmp/manager.log",
|
|
||||||
"/tmp/manager.log.0",
|
|
||||||
"/tmp/AutoDistReset.log",
|
|
||||||
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
|
||||||
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
|
|
||||||
"/etc/board.json"
|
|
||||||
);
|
|
||||||
|
|
||||||
@sensitive = ( "/etc/config/vtun",
|
|
||||||
"/etc/config.mesh/vtun",
|
|
||||||
"/etc/httpd.conf",
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
local files = {
|
||||||
@cmds = ( "cat /proc/cpuinfo",
|
"/etc/config/",
|
||||||
"cat /proc/meminfo",
|
"/etc/config.mesh/",
|
||||||
"df -k",
|
"/etc/local/",
|
||||||
"dmesg",
|
"/etc/mesh-release",
|
||||||
"ifconfig",
|
"/tmp/etc/",
|
||||||
"iptables -t filter -L -v",
|
"/var/run/hosts_olsr",
|
||||||
"iptables -t nat -L -v",
|
"/tmp/rssi.dat",
|
||||||
"iptables -t mangle -L -v",
|
"/tmp/rssi.log",
|
||||||
"ip route list",
|
"/tmp/zombie.log",
|
||||||
"ip route list table 29",
|
"/tmp/olsrd.log",
|
||||||
"ip route list table 30",
|
"/tmp/manager.log",
|
||||||
"ip route list table 31",
|
"/tmp/manager.log.0",
|
||||||
"ip route list table main",
|
"/tmp/AutoDistReset.log",
|
||||||
"ip route list table default",
|
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
||||||
"ip rule list",
|
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
|
||||||
"iwinfo",
|
"/etc/board.json"
|
||||||
"iwinfo ${wifiif} assoclist",
|
}
|
||||||
"iw phy ${phy} info",
|
local sensitive = {
|
||||||
"iw dev ${wifiif} info",
|
"/etc/config/vtun",
|
||||||
"iw dev ${wifiif} scan",
|
"/etc/config.mesh/vtun",
|
||||||
"iw dev ${wifiif} station dump",
|
"/etc/httpd.conf"
|
||||||
"logread",
|
}
|
||||||
"md5sum /www/cgi-bin/*",
|
local cmds = {
|
||||||
"echo /all | nc 127.0.0.1 2006",
|
"cat /proc/cpuinfo",
|
||||||
"opkg list-installed",
|
"cat /proc/meminfo",
|
||||||
"ps -w",
|
"df -k",
|
||||||
"/usr/local/bin/get_hardwaretype",
|
"dmesg",
|
||||||
"/usr/local/bin/get_boardid",
|
"ifconfig",
|
||||||
"/usr/local/bin/get_model",
|
"iptables -t filter -L -v",
|
||||||
"/usr/local/bin/get_hardware_mfg",
|
"iptables -t nat -L -v",
|
||||||
);
|
"iptables -t mangle -L -v",
|
||||||
|
"ip route list",
|
||||||
@cmds_ubnt = (
|
"ip route list table 29",
|
||||||
"cat /dev/mtd0|grep 'U-Boot'|head -n1",
|
"ip route list table 30",
|
||||||
);
|
"ip route list table 31",
|
||||||
|
"ip route list table main",
|
||||||
$FREE_SPACE_TMP=get_free_space("/tmp");
|
"ip route list table default",
|
||||||
|
"ip rule list",
|
||||||
$mfg = `/usr/local/bin/get_hardware_mfg`;
|
"iwinfo",
|
||||||
chomp($mfg);
|
"iwinfo " .. wifiif .. " assoclist",
|
||||||
|
"iw phy " .. phy .. " info",
|
||||||
if ($FREE_SPACE_TMP eq "N/A" || $FREE_SPACE_TMP <= 2*1024) {
|
"iw dev " .. wifiif .. " info",
|
||||||
exit 1;
|
"iw dev " .. wifiif .. " scan",
|
||||||
|
"iw dev " .. wifiif .. " station dump",
|
||||||
|
"logread",
|
||||||
|
"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",
|
||||||
|
}
|
||||||
|
local cmds_ubnt = {
|
||||||
|
"cat /dev/mtd0|grep 'U-Boot'|head -n1"
|
||||||
}
|
}
|
||||||
|
|
||||||
system ("rm", "-r", "-f", "/tmp/sd");
|
-- 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
|
||||||
|
|
||||||
foreach $path (@files) {
|
remove_all("/tmp/sd")
|
||||||
|
|
||||||
next if (! -e $path and ! -d $path);
|
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
|
||||||
|
|
||||||
if ( $path =~ /^\/(.*\/).*\/$/ ) {
|
-- remove sensitive files
|
||||||
my $rpath = $1;
|
for _, path in ipairs(sensitive)
|
||||||
system("mkdir", "-p", "/tmp/sd/$rpath");
|
do
|
||||||
system("cp","-r","-p","$path","/tmp/sd/$rpath");
|
local m = path:match("^/(.*)")
|
||||||
} else {
|
if m then
|
||||||
$path =~ /^(.*\/).*/;
|
remove_all("/tmp/sd/" .. m)
|
||||||
my $sourcepath = $1;
|
end
|
||||||
system("mkdir", "-p", "/tmp/sd/$sourcepath");
|
end
|
||||||
system("cp","-r","-p","$path","/tmp/sd/$path");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
-- 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")
|
||||||
|
|
||||||
#Remove sensitive files
|
local f = io.open("/tmp/sd/data.txt", "w")
|
||||||
foreach $path (@sensitive) {
|
if f then
|
||||||
if ( $path =~ /^\/(.*)/ ) {
|
for _, cmd in ipairs(cmds)
|
||||||
my $sourcepath = $1;
|
do
|
||||||
system("rm", "-r", "-f", "/tmp/sd/$sourcepath");
|
local p = io.popen(cmd)
|
||||||
}
|
if p then
|
||||||
}
|
f:write("========== " .. cmd .. " ==========\n")
|
||||||
|
f:write(p:read("*a"))
|
||||||
|
p:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#Remove passwords from config files
|
if mfg == "Ubiquiti" then
|
||||||
system ("cat /tmp/sd/etc/config/wireless | sed -e 's/ key.*\$/ key \*\*\*\*\*\*/' > /tmp/sd/etc/config/wireless.sav");
|
for _, cmd in ipairs(cmds_ubnt)
|
||||||
unlink "rm /tmp/sd/etc/config/wireless";
|
do
|
||||||
rename "/tmp/sd/etc/config/wireless.sav", "/tmp/sd/etc/config/wireless";
|
local p = io.popen(cmd)
|
||||||
system ("cat /tmp/sd/etc/config.mesh/_setup | sed -e 's/_key =.*\$/_key =/' > /tmp/sd/etc/config.mesh/_setup.sav");
|
if p then
|
||||||
unlink "/tmp/sd/etc/config.mesh/_setup";
|
f:write("========== " .. cmd .. " (UBNT only) ==========\n")
|
||||||
rename "/tmp/sd/etc/config.mesh/_setup.sav", "/tmp/sd/etc/config.mesh/_setup";
|
f:write(p:read("*a"))
|
||||||
|
p:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
system("touch","/tmp/sd/data.txt");
|
os.execute("tar -zcf /tmp/supportdata.tgz -C /tmp/sd ./")
|
||||||
open (my $CMDS_OUT, '>', '/tmp/sd/data.txt') or die "Could not open dump file";
|
-- cleaup the temp files
|
||||||
foreach $cmd (@cmds) {
|
remove_all("/tmp/sd")
|
||||||
print $CMDS_OUT "========== $cmd ==========\n";
|
|
||||||
open(my $CMD_PIPE, "-|", $cmd ) or next;
|
|
||||||
while (<$CMD_PIPE>) {
|
|
||||||
print { $CMDS_OUT } $_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $mfg eq "Ubiquiti" ) {
|
local nodename = capture("uname -n"):chomp()
|
||||||
foreach $cmd (@cmds_ubnt) {
|
local tstamp = capture("date +%Y%m%d%H%M"):chomp()
|
||||||
print $CMDS_OUT "========== $cmd (UBNT only) ==========\n";
|
|
||||||
open(my $CMD_PIPE, "-|", $cmd ) or next;
|
|
||||||
while (<$CMD_PIPE>) {
|
|
||||||
print { $CMDS_OUT } $_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close ($CMDS_OUT);
|
if os.getenv("GATEWAY_INTERFACE") ~= "" then
|
||||||
|
local fn = "supportdata-" .. nodename .. "-" .. tstamp .. ".tgz"
|
||||||
system("tar", "-zcf", "/tmp/supportdata.tgz", "-C", "/tmp/sd", "./");
|
print("Content-type: application/x-gzip\r")
|
||||||
|
print("Content-Disposition: attachment; filename=" .. fn .. "\r")
|
||||||
# Cleanup the temp files
|
print("\r")
|
||||||
system ("rm", "-r", "-f", "/tmp/sd");
|
io.write(read_all("/tmp/supportdata.tgz"))
|
||||||
|
else
|
||||||
$nodename=`uname -n`;
|
local fn = "/tmp/supportdata-" .. nodename .. "-" .. tstamp .. ".tgz"
|
||||||
chomp($nodename);
|
nixio.fs.remove(fn)
|
||||||
$tstamp=`date +%Y%m%d%H%M`;
|
nixio.fs.rename("/tmp/supportdata.tgz", fn)
|
||||||
chomp($tstamp);
|
print("File created: " .. fn)
|
||||||
|
print("Please copy this file and remove from the node")
|
||||||
open(my $SDFH, '<', "/tmp/supportdata.tgz") or exit(1);
|
print("to free up resources.")
|
||||||
binmode $SDFH;
|
end
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
BEGIN {push @INC, '/www/cgi-bin'};
|
||||||
|
use perlfunc;
|
||||||
|
chomp (${wifiif}=`uci -q get 'network.wifi.ifname'`);
|
||||||
|
$phy=get_wlan2phy("${wifiif}");
|
||||||
|
|
||||||
|
|
||||||
|
@files = ( "/etc/config/",
|
||||||
|
"/etc/config.mesh/",
|
||||||
|
"/etc/local/",
|
||||||
|
"/etc/mesh-release",
|
||||||
|
"/tmp/etc/",
|
||||||
|
"/var/run/hosts_olsr",
|
||||||
|
"/tmp/rssi.dat",
|
||||||
|
"/tmp/rssi.log",
|
||||||
|
"/tmp/zombie.log",
|
||||||
|
"/tmp/olsrd.log",
|
||||||
|
"/tmp/manager.log",
|
||||||
|
"/tmp/manager.log.0",
|
||||||
|
"/tmp/AutoDistReset.log",
|
||||||
|
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
|
||||||
|
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
|
||||||
|
"/etc/board.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
@sensitive = ( "/etc/config/vtun",
|
||||||
|
"/etc/config.mesh/vtun",
|
||||||
|
"/etc/httpd.conf",
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@cmds = ( "cat /proc/cpuinfo",
|
||||||
|
"cat /proc/meminfo",
|
||||||
|
"df -k",
|
||||||
|
"dmesg",
|
||||||
|
"ifconfig",
|
||||||
|
"iptables -t filter -L -v",
|
||||||
|
"iptables -t nat -L -v",
|
||||||
|
"iptables -t mangle -L -v",
|
||||||
|
"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",
|
||||||
|
"iwinfo ${wifiif} assoclist",
|
||||||
|
"iw phy ${phy} info",
|
||||||
|
"iw dev ${wifiif} info",
|
||||||
|
"iw dev ${wifiif} scan",
|
||||||
|
"iw dev ${wifiif} station dump",
|
||||||
|
"logread",
|
||||||
|
"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",
|
||||||
|
);
|
||||||
|
|
||||||
|
@cmds_ubnt = (
|
||||||
|
"cat /dev/mtd0|grep 'U-Boot'|head -n1",
|
||||||
|
);
|
||||||
|
|
||||||
|
$FREE_SPACE_TMP=get_free_space("/tmp");
|
||||||
|
|
||||||
|
$mfg = `/usr/local/bin/get_hardware_mfg`;
|
||||||
|
chomp($mfg);
|
||||||
|
|
||||||
|
if ($FREE_SPACE_TMP eq "N/A" || $FREE_SPACE_TMP <= 2*1024) {
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
system ("rm", "-r", "-f", "/tmp/sd");
|
||||||
|
|
||||||
|
foreach $path (@files) {
|
||||||
|
|
||||||
|
next if (! -e $path and ! -d $path);
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#Remove sensitive files
|
||||||
|
foreach $path (@sensitive) {
|
||||||
|
if ( $path =~ /^\/(.*)/ ) {
|
||||||
|
my $sourcepath = $1;
|
||||||
|
system("rm", "-r", "-f", "/tmp/sd/$sourcepath");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#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";
|
||||||
|
|
||||||
|
|
||||||
|
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 } $_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 } $_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close ($CMDS_OUT);
|
||||||
|
|
||||||
|
system("tar", "-zcf", "/tmp/supportdata.tgz", "-C", "/tmp/sd", "./");
|
||||||
|
|
||||||
|
# Cleanup the temp files
|
||||||
|
system ("rm", "-r", "-f", "/tmp/sd");
|
||||||
|
|
||||||
|
$nodename=`uname -n`;
|
||||||
|
chomp($nodename);
|
||||||
|
$tstamp=`date +%Y%m%d%H%M`;
|
||||||
|
chomp($tstamp);
|
||||||
|
|
||||||
|
open(my $SDFH, '<', "/tmp/supportdata.tgz") or exit(1);
|
||||||
|
binmode $SDFH;
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,77 +1,89 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/lua
|
||||||
=for comment
|
--[[
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
Copyright (C) 2015 Conrad Lara
|
Copyright (C) 2021 Tim Wilkinson
|
||||||
See Contributors file for additional contributors
|
Original Perl Copyright (C) 2015 Conrad Lara
|
||||||
|
Original Perl Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
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 free software: you can redistribute it and/or modify
|
This program is distributed in the hope that it will be useful,
|
||||||
it under the terms of the GNU General Public License as published by
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
the Free Software Foundation version 3 of the License.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
You should have received a copy of the GNU General Public License
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
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
|
Additional Terms:
|
||||||
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.
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
See AREDNLicense.txt for more info.
|
If importing this code into a new or existing project attribution
|
||||||
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
You must not misrepresent the origin of the material contained within.
|
||||||
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
|
||||||
|
|
||||||
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
|
require("aredn.http")
|
||||||
|
require("aredn.hardware")
|
||||||
|
local html = require("aredn.html")
|
||||||
|
aredn.info = require("aredn.info")
|
||||||
|
|
||||||
BEGIN {push @INC, '/www/cgi-bin'};
|
local node = aredn.info.get_nvram("node")
|
||||||
use perlfunc;
|
if not node then
|
||||||
|
node = "NOCALL"
|
||||||
|
end
|
||||||
|
|
||||||
http_header();
|
http_header()
|
||||||
html_header("$node system information", 1);
|
html.header(node .. " system information", false)
|
||||||
print "<body><pre>\n";
|
html.print("<body><pre>")
|
||||||
|
html.print(" node: " .. node)
|
||||||
|
html.print("model: " .. aredn.hardware.get_board_id())
|
||||||
|
html.print("")
|
||||||
|
|
||||||
print " node: ", nvram_get("node"), "\n";
|
if aredn.hardware.supported() ~= 1 then
|
||||||
print "model: ", `/usr/local/bin/get_model`, "\n";
|
html.print("<font color=\"red\">!!!! UNSUPPORTED DEVICE !!!!</font>")
|
||||||
|
html.print("boardid: " .. aredn.hardware.get_board_id())
|
||||||
|
if aredn.hardware.supported() == 0 then
|
||||||
|
html.print("<font color=\"red\">Device HAS BEEN TESTED AS UNSUPPORTED</font>")
|
||||||
|
else
|
||||||
|
html.print("<font color=\"red\">Device has not been tested. Please file a ticket with your experiences.</font>")
|
||||||
|
end
|
||||||
|
html.print("")
|
||||||
|
end
|
||||||
|
|
||||||
if ( is_hardware_supported() !=1 ){
|
local f = io.popen("ifconfig -a")
|
||||||
print "<font color=\"red\">!!!! UNSUPPORTED DEVICE !!!!</font>\n";
|
if f then
|
||||||
print "boardid: " , hardware_boardid() , "\n";
|
for line in f:lines()
|
||||||
if ( is_hardware_supported == 0 ) {
|
do
|
||||||
print "<font color=\"red\">Device HAS BEEN TESTED AS UNSUPPORTED</font>\n";
|
local a, b = line:match("^(%S+) .*HWaddr (%S+)")
|
||||||
}
|
if b then
|
||||||
else {
|
html.print(string.format("%-6s %s", a, b))
|
||||||
print "<font color=\"red\">Device has not been tested. Please file a ticket with your experiences.</font>\n";
|
end
|
||||||
}
|
end
|
||||||
print "\n";
|
f:close()
|
||||||
}
|
end
|
||||||
|
|
||||||
foreach(`ifconfig -a`)
|
html.print("")
|
||||||
{
|
html.print("/proc/cpuinfo")
|
||||||
next unless /^(\S+) .*HWaddr (\S+)/;
|
html.print(read_all("/proc/cpuinfo"))
|
||||||
printf "%-6s %s\n", $1, $2;
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n/proc/cpuinfo\n";
|
html.print("nvram")
|
||||||
system "cat /proc/cpuinfo";
|
html.print(capture("uci -c /etc/local/uci show 2>&1"))
|
||||||
|
|
||||||
print "\nnvram\n";
|
html.print("</pre>")
|
||||||
system "uci -c /etc/local/uci show 2>&1";
|
html.footer()
|
||||||
|
html.print("</body></html>")
|
||||||
print "</pre>\n";
|
http_footer()
|
||||||
|
|
||||||
page_footer();
|
|
||||||
print "</body>\n";
|
|
||||||
print "</html>\n";
|
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||||
|
Copyright (C) 2015 Conrad Lara
|
||||||
|
See Contributors file for additional contributors
|
||||||
|
|
||||||
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
BEGIN {push @INC, '/www/cgi-bin'};
|
||||||
|
use perlfunc;
|
||||||
|
|
||||||
|
http_header();
|
||||||
|
html_header("$node system information", 1);
|
||||||
|
print "<body><pre>\n";
|
||||||
|
|
||||||
|
print " node: ", nvram_get("node"), "\n";
|
||||||
|
print "model: ", `/usr/local/bin/get_model`, "\n";
|
||||||
|
|
||||||
|
if ( is_hardware_supported() !=1 ){
|
||||||
|
print "<font color=\"red\">!!!! UNSUPPORTED DEVICE !!!!</font>\n";
|
||||||
|
print "boardid: " , hardware_boardid() , "\n";
|
||||||
|
if ( is_hardware_supported == 0 ) {
|
||||||
|
print "<font color=\"red\">Device HAS BEEN TESTED AS UNSUPPORTED</font>\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "<font color=\"red\">Device has not been tested. Please file a ticket with your experiences.</font>\n";
|
||||||
|
}
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(`ifconfig -a`)
|
||||||
|
{
|
||||||
|
next unless /^(\S+) .*HWaddr (\S+)/;
|
||||||
|
printf "%-6s %s\n", $1, $2;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "\n/proc/cpuinfo\n";
|
||||||
|
system "cat /proc/cpuinfo";
|
||||||
|
|
||||||
|
print "\nnvram\n";
|
||||||
|
system "uci -c /etc/local/uci show 2>&1";
|
||||||
|
|
||||||
|
print "</pre>\n";
|
||||||
|
|
||||||
|
page_footer();
|
||||||
|
print "</body>\n";
|
||||||
|
print "</html>\n";
|
Loading…
Reference in New Issue