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:
Tim Wilkinson 2022-03-08 19:22:07 -08:00 committed by GitHub
parent 922a74d574
commit a0e7749b1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1551 additions and 746 deletions

View File

@ -1,12 +1,11 @@
#!/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
Original Perl Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors 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 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.
@ -32,110 +31,78 @@
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 --]]
# do the initial setup of the essential nvram variables -- do the initial setup of the essential nvram variables
# node - node name -- node - node name
# mac2 - last 3 bytes of wifi mac address in the form ddd.ddd.ddd -- 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 -- 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 -- intended to run every boot but it should only actually do anything
# on the first boot -- on the first boot
sub fail require("aredn.utils")
{ require("iwinfo")
open(ERR, ">>/tmp/nvram_errors"); require("aredn.hardware")
print ERR "@_\n"; local aredn_info = require('aredn.info')
close(ERR);
die "@_\n";
}
sub get_wlan2phy local wifi_mac = aredn_info.get_nvram("wifimac")
{ local mac2 = aredn_info.get_nvram("mac2")
my ($wlan) = $1; local node = aredn_info.get_nvram("node")
my ($phy) = ""; local dtdmac = aredn_info.get_nvram("dtdmac")
return "phy0" unless $wlan;
foreach(`iwinfo $wlan info`)
{
next unless /^.*PHY name:\s*([a-z0-4]+)/;
$phy = $1;
}
return $phy;
}
$commit = 0; local hardware_mac
$wifiif = `uci -q get network.wifi.ifname`; if wifi_mac == "" or mac2 == "" then
$phy = get_wlan2phy("$wifiif"); local phy
for i = 1,5
do
local f = io.popen("iwinfo " .. get_ifname("wifi") .. " info")
if f then
for line in f:lines()
do
phy = line:match("PHY name:%s*([a-z0-4]+)")
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
# Added new wifimac parm, the radio* wont startup without it, use the path location in wifi config if wifi_mac == "" then
# Actually it just needs some path to get to the radio. aredn_info.set_nvram("wifimac", hardware_mac)
end
chomp ($wifi_mac = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.wifimac`); if mac2 == "" then
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
if($wifi_mac eq "") if node == "" then
{ aredn_info.set_nvram("node", "NOCALL-" .. mac2:gsub("%.", "-"))
open(FILE, "/sys/class/ieee80211/${phy}/macaddress") or fail("ERROR: wireless mac not available"); end
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;
}
if dtdmac == "" then
chomp ($mac2 = `uci -c /etc/local/uci/ -q get hsmmmesh.settings.mac2`); 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)")
aredn_info.set_nvram("dtdmac", string.format("%d.%d.%d", tonumber(a, 16), tonumber(b, 16), tonumber(c, 16)))
if($mac2 eq "") end
{
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;

View File

@ -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;

View File

@ -1,12 +1,11 @@
#!/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
Original Perl Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors 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 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.
@ -32,19 +31,18 @@
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 --]]
unless(defined ($pw = shift)) if #arg ~= 1 then
{ io.stderr:write("usage: setpasswd <password>\nthis sets both the system and website paswords\n")
print STDERR "\nusage: setpasswd <password>\n"; os.exit(-1)
print STDERR "this sets both the system and website paswords\n\n"; end
exit 1;
}
$pw2 = $pw; local pw = arg[1]:gsub("'", "\\'")
$pw2 =~ s/'/'\\''/g; local f = io.popen("{ echo '" .. pw .. "'; sleep 1; echo '" .. pw .. "'; } | passwd")
system "{ echo '$pw2'; sleep 1; echo '$pw2'; } | passwd > /dev/null\n"; f:read("*a")
f:close()
print STDERR "passwords changed.\n"; io.stderr:write("passwords changed.\n")

View File

@ -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";

View File

@ -1,10 +1,11 @@
#!/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
@ -33,303 +34,282 @@
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)
{ function freq_to_chan(freq)
return "14"; local chan = freq
} if chan < 256 then
elsif ($freq == 2407) elseif chan == 2484 then
{ return 14
return 0; elseif chan == 2407 then
} return 0
elsif ($freq < 2484) elseif chan < 2484 then
{ return (chan - 2407) / 5
return ($freq-2407)/5; elseif chan < 5000 then
} elseif chan < 5380 then
elsif ($freq < 5000) return (chan - 5000) / 5
{ elseif chan < 5500 then
return $freq ; # stay in freq, no ch #s return chan - 2000
} elseif chan < 6000 then
elsif ($freq < 5380) # these are 5Ghz channels 75 and below return (chan - 5000) / 5
{ end
return ($freq-5000)/5 ; return "?"
} end
elsif ($freq < 5500) # ch 76 to 99 can only be 3Ghz freq, no part 15 here
{ -- load arp cache
return ($freq-2000); # return 3ghz freq (5ghz boards with -2Ghz transverter) local arpcache = {}
} arptable(function(a)
elsif ($freq < 6000) arpcache[a["HW address"]] = a["IP address"]
{ end)
return ($freq-5000)/5;
} local hostcache = {}
function mac_to_host(mac)
if not mac then
return "N/A"
end
local host = hostcache[mac]
if host then
return host
end
local ip = arpcache[mac]
if ip then
hostname = ip
local f = io.popen("nslookup " .. ip)
if f then
for line in f:lines()
do
local m = line:match("name = (.*)%.local%.mesh")
if m then
f:close()
hostcache[mac] = m
return m
end
end
f:close()
end
else else
{ hostcache[mac] = "N/A"
return $freq; return "N/A"
} end
} end
sub pushAP local avg = false -- average mode
{ local batch = false -- batch mode
my($signal, $freq, $key, $ssid, $host, $mac, $mode) = @_; local loops = 0 -- number of times to run 0=inf
local raw = false -- raw mode
local openap = false -- show open ap's
return if $mac eq ""; local iface = aredn.hardware.get_iface_name("wifi") -- wifi interface
return if $openap and ($key ne "");
$chan=freq_to_chan($freq); local iters = 0 -- number of iterations
local avgs = {} -- average statistics
if($ssid eq "") { $ssid = "(hidden)" } local i = 1
if($chan eq "") { $chan = "?" } while i <= #arg
do
if($key eq "") { $key = " " } local a = arg[i]
else { $key = "*" } i = i + 1
if a == "-h" then
if($avg) usage()
{ elseif a == "-1" then
$avgs{"$mac total"} += $signal; loops = 1
$avgs{"$mac num"} += 1; elseif a == "-a" then
$aphash{$mac} = sprintf "% 3d %s %-32s\t%s\t%s\t%s\n", avg = true
$chan, $key, $ssid, $host, $mac, $mode; elseif a == "-b" then
} batch = true
elsif($web) elseif a == "-o" then
{ openap = true
push @list, sprintf "% 3d|%d|%s|%s|%s|%s|%s", elseif a == "-r" then
$signal, $chan, $key, sprintf("&#x%*vX", '&#x',$ssid), $host, $mac, $mode; raw = true
} elseif a == "-i" then
iface = arg[i]
i = i + 1
elseif a == "-n" then
loops = tonumber(arg[i])
i = i + 1
else else
{ die("bad arg " .. a)
push @list, sprintf "% 3d %2d %s %-32s\t%s\t%s\t%s\n", end
$signal, $chan, $key, $ssid, $host, $mac, $mode; 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
$avg = 0; # average mode end
$batch = 0; # batch mode m = line:match("freq: (%d+)")
$loops = 0; # number of times to run 0=inf if m then
$raw = 0; # raw mode scan.freq = tonumber(m)
$openap = 0; # show open ap's end
$iface = `uci -q get 'network.wifi.ifname'`; # wireless interface m = line:match("SSID: (.+)")
chomp $iface; if m then
scan.ssid = m
$iters = 0; # number of iterations end
%avgs = (); # average statistics m = line:match("signal: ([%d-]+)")
%aphash = (); # list of ap's for avg mode if m then
scan.signal = tonumber(m)
$mychan = `iwinfo $iface info | grep -i channel`; end
$mychan =~ /Channel:\s+(-*\d+)/; m = line:match("Group cipher: (.+)")
$mychan = ( ! defined $1 || ! int($1) || ! ($1 >= -4 && $1 <= 185) ) ? 0 : $1; if m then
scan.key = m
# ch 76 - 99 are 3ghz since no part 15 usage (5ghz board with -2ghz transverter) end
if ($mychan >= 76 and $mychan <= 99) if line:match("capability: IBSS") and scan.mode == "AP" then
{ scan.mode = "Foreign Ad-Hoc Network"
$mychan = ($mychan*5+3000); end
} end
f:close()
while(defined ($arg = shift)) end
{ local f = io.popen("iw dev " .. iface .. " station dump")
if ($arg eq "-h") { usage() } if f then
elsif($arg eq "-1") { $loops = 1 } local scan
elsif($arg eq "-a") { $avg = 1 } for line in f:lines()
elsif($arg eq "-b") { $batch = 1 } do
elsif($arg eq "-o") { $openap = 1 } local m = line:match("^Station ([%da-fA-F:]+) %(on " .. iface .. "%)")
elsif($arg eq "-r") { $raw = 1 } if m then
elsif($arg eq "-i") { $iface = shift } scan = {
elsif($arg eq "-n") { $loops = shift } mac = m,
elsif($arg eq "-w") { $web = 1 } mode = "Connected Ad-Hoc Station",
else { die "bad arg $arg\n" } ssid = myssid,
} signal = 0,
freq = myfreq,
die "bad interface" if not defined $iface; key = ""
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;
} }
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
if($line =~ /BSS(\s+)([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}.*joined/) -- update running averages
{ for _, scan in ipairs(scanned)
$mode = "My Ad-Hoc Network"; do
$chan = $mychan; local v = avgs[scan.mac]
} if not v then
if($line =~ /\bSSID: (.*)/) { $ssid = $1 } v = { num = 1, total = scan.signal }
if($line =~ /\bSSID: unknown/) { $ssid = "unknown" } avgs[scan.mac] = v
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
{ v.num = v.num + 1
#system "clear"; v.total = v.total + scan.signal
printf "Sig Ch E SSID Hostname MAC/BSSID 802.11 Mode %6d\n", $iters; end
print "--- -- - -------------------------------- --------------------- ------------- ------------\n"; 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($avg) if #scanned == 0 and loops ~= 1 then
{ nixio.nanosleep(1, 0)
open(FILE, "| sort -nr"); end
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" iters = iters + 1
if ( $line =~ /&#x41&#x52&#x45&#x44&#x4E/) { print "<tr class=\"wscan-row-node\">"}
else { print "<tr>"}
my $i = 0; -- create output
foreach $val (split /\|/, $line) local output = {}
{
$val = "&nbsp;" unless $val =~ /\S/; if avg then
if($i++ == 3) { print "<td>$val</td>" } for _, scan in pairs(avgs)
else { print "<td align=center>$val</td>" } do
} if scan.signal ~= 0 and (not openap or scan.key == "") then
print "<td>&nbsp;</td>" if $i < 7; local chan = freq_to_chan(scan.freq)
print "</tr>\n"; local ssid = scan.ssid == "" and "(hidden)" or scan.ssid
} local key = scan.key == "" and " " or "*"
print "</table>\n"; 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)
exit; end
} end
else else
{ for _, scan in ipairs(scanned)
open(FILE, "| sort -nr"); do
print FILE @list; if scan.signal ~= 0 and (not openap or scan.key == "") then
close(FILE); local chan = freq_to_chan(scan.freq)
print "\n"; 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
last if --$loops == 0; 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

335
files/usr/local/bin/wscan.pl Executable file
View File

@ -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 =~ /&#x41&#x52&#x45&#x44&#x4E/) { print "<tr class=\"wscan-row-node\">"}
else { print "<tr>"}
my $i = 0;
foreach $val (split /\|/, $line)
{
$val = "&nbsp;" unless $val =~ /\S/;
if($i++ == 3) { print "<td>$val</td>" }
else { print "<td align=center>$val</td>" }
}
print "<td>&nbsp;</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;
}

View File

@ -1,8 +1,9 @@
#!/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
Original Perl Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors 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
@ -30,20 +31,23 @@
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");

49
files/www/cgi-bin/fwinfo.pl Executable file
View File

@ -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");

View File

@ -1,8 +1,9 @@
#!/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
Original Perl Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors 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
@ -30,17 +31,23 @@
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")
local phy = iwinfo.nl80211.phyname(wifiif)
local mfg = capture("/usr/local/bin/get_hardware_mfg"):chomp()
local files = {
"/etc/config/",
"/etc/config.mesh/", "/etc/config.mesh/",
"/etc/local/", "/etc/local/",
"/etc/mesh-release", "/etc/mesh-release",
@ -56,16 +63,14 @@ $phy=get_wlan2phy("${wifiif}");
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to", "/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to", "/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
"/etc/board.json" "/etc/board.json"
); }
local sensitive = {
@sensitive = ( "/etc/config/vtun", "/etc/config/vtun",
"/etc/config.mesh/vtun", "/etc/config.mesh/vtun",
"/etc/httpd.conf", "/etc/httpd.conf"
); }
local cmds = {
"cat /proc/cpuinfo",
@cmds = ( "cat /proc/cpuinfo",
"cat /proc/meminfo", "cat /proc/meminfo",
"df -k", "df -k",
"dmesg", "dmesg",
@ -81,11 +86,11 @@ $phy=get_wlan2phy("${wifiif}");
"ip route list table default", "ip route list table default",
"ip rule list", "ip rule list",
"iwinfo", "iwinfo",
"iwinfo ${wifiif} assoclist", "iwinfo " .. wifiif .. " assoclist",
"iw phy ${phy} info", "iw phy " .. phy .. " info",
"iw dev ${wifiif} info", "iw dev " .. wifiif .. " info",
"iw dev ${wifiif} scan", "iw dev " .. wifiif .. " scan",
"iw dev ${wifiif} station dump", "iw dev " .. wifiif .. " station dump",
"logread", "logread",
"md5sum /www/cgi-bin/*", "md5sum /www/cgi-bin/*",
"echo /all | nc 127.0.0.1 2006", "echo /all | nc 127.0.0.1 2006",
@ -95,112 +100,93 @@ $phy=get_wlan2phy("${wifiif}");
"/usr/local/bin/get_boardid", "/usr/local/bin/get_boardid",
"/usr/local/bin/get_model", "/usr/local/bin/get_model",
"/usr/local/bin/get_hardware_mfg", "/usr/local/bin/get_hardware_mfg",
); }
local cmds_ubnt = {
@cmds_ubnt = ( "cat /dev/mtd0|grep 'U-Boot'|head -n1"
"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"); -- 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"
}
}

206
files/www/cgi-bin/supporttool.pl Executable file
View File

@ -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"
}
}

View File

@ -1,12 +1,12 @@
#!/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
Original Perl Copyright (C) 2015 Conrad Lara
Original Perl Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
See Contributors file for additional contributors 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 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.
@ -32,46 +32,58 @@
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("aredn.http")
use perlfunc; require("aredn.hardware")
local html = require("aredn.html")
aredn.info = require("aredn.info")
http_header(); local node = aredn.info.get_nvram("node")
html_header("$node system information", 1); if not node then
print "<body><pre>\n"; node = "NOCALL"
end
print " node: ", nvram_get("node"), "\n"; http_header()
print "model: ", `/usr/local/bin/get_model`, "\n"; html.header(node .. " system information", false)
html.print("<body><pre>")
html.print(" node: " .. node)
html.print("model: " .. aredn.hardware.get_board_id())
html.print("")
if ( is_hardware_supported() !=1 ){ if aredn.hardware.supported() ~= 1 then
print "<font color=\"red\">!!!! UNSUPPORTED DEVICE !!!!</font>\n"; html.print("<font color=\"red\">!!!! UNSUPPORTED DEVICE !!!!</font>")
print "boardid: " , hardware_boardid() , "\n"; html.print("boardid: " .. aredn.hardware.get_board_id())
if ( is_hardware_supported == 0 ) { if aredn.hardware.supported() == 0 then
print "<font color=\"red\">Device HAS BEEN TESTED AS UNSUPPORTED</font>\n"; html.print("<font color=\"red\">Device HAS BEEN TESTED AS UNSUPPORTED</font>")
} else
else { html.print("<font color=\"red\">Device has not been tested. Please file a ticket with your experiences.</font>")
print "<font color=\"red\">Device has not been tested. Please file a ticket with your experiences.</font>\n"; end
} html.print("")
print "\n"; end
}
foreach(`ifconfig -a`) local f = io.popen("ifconfig -a")
{ if f then
next unless /^(\S+) .*HWaddr (\S+)/; for line in f:lines()
printf "%-6s %s\n", $1, $2; do
} local a, b = line:match("^(%S+) .*HWaddr (%S+)")
if b then
html.print(string.format("%-6s %s", a, b))
end
end
f:close()
end
print "\n/proc/cpuinfo\n"; html.print("")
system "cat /proc/cpuinfo"; html.print("/proc/cpuinfo")
html.print(read_all("/proc/cpuinfo"))
print "\nnvram\n"; html.print("nvram")
system "uci -c /etc/local/uci show 2>&1"; html.print(capture("uci -c /etc/local/uci show 2>&1"))
print "</pre>\n"; html.print("</pre>")
html.footer()
page_footer(); html.print("</body></html>")
print "</body>\n"; http_footer()
print "</html>\n";

77
files/www/cgi-bin/sysinfo.pl Executable file
View File

@ -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";