2015-07-10 20:51:18 -06:00
|
|
|
#!/usr/bin/perl
|
|
|
|
=for comment
|
|
|
|
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
Copyright (C) 2015 Darryl Quinn
|
|
|
|
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 conained 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;
|
|
|
|
|
|
|
|
read_query_string();
|
|
|
|
&json_header();
|
|
|
|
|
|
|
|
|
|
|
|
my %info;
|
2015-07-13 19:32:17 -06:00
|
|
|
$info{"api_version"}="1.0";
|
2015-07-10 20:51:18 -06:00
|
|
|
|
|
|
|
# ============ GENERATE INFO HASH =========
|
|
|
|
$node=nvram_get("node");
|
|
|
|
chomp($node);
|
|
|
|
$info{"node"}=$node;
|
|
|
|
|
|
|
|
$model=`/usr/local/bin/get_model`;
|
|
|
|
chomp($model);
|
|
|
|
$info{"model"}=$model;
|
|
|
|
|
2015-07-13 10:18:53 -06:00
|
|
|
$info{"board_id"}=&hardware_boardid();
|
|
|
|
|
2015-07-10 20:51:18 -06:00
|
|
|
# ------- Firmware Manufacturer
|
|
|
|
if (-e "/www/AREDN.png")
|
|
|
|
{
|
|
|
|
$fw_mfg="AREDN";
|
|
|
|
} else {
|
|
|
|
$fw_mfg = "Other";
|
|
|
|
}
|
|
|
|
$info{"firmware_mfg"}=$fw_mfg;
|
|
|
|
|
|
|
|
$fwver=`cat /etc/mesh-release`;
|
|
|
|
chomp($fwver);
|
|
|
|
$info{"firmware_version"}=$fwver;
|
|
|
|
|
|
|
|
# ------- Tunnel Installed
|
|
|
|
if (-e "/usr/sbin/vtund")
|
|
|
|
{
|
2015-07-13 19:32:17 -06:00
|
|
|
$tunnel_installed="true";
|
2015-07-10 20:51:18 -06:00
|
|
|
} else {
|
2015-07-13 19:32:17 -06:00
|
|
|
$tunnel_installed="false";
|
2015-07-10 20:51:18 -06:00
|
|
|
}
|
|
|
|
$info{"tunnel_installed"}=$tunnel_installed;
|
|
|
|
|
|
|
|
# ------- SSID
|
|
|
|
$line = `grep ssid /etc/config/wireless | tail -1`;
|
|
|
|
$line =~ /['"](.*-(5|10|20)-v[3456])/;
|
|
|
|
$myssid = $1;
|
|
|
|
$myssid =~ /(.*)-(5|10|20)-v[3456]/;
|
|
|
|
$info{"ssid"}=$myssid;
|
|
|
|
|
2015-08-18 20:39:30 -06:00
|
|
|
# ------- Wifi Channel Number
|
|
|
|
$mychan = `uci get wireless.radio0.channel`;
|
|
|
|
chomp($mychan);
|
2015-08-28 19:09:33 -06:00
|
|
|
# 3GHZ channel -> Freq conversion
|
|
|
|
if ($mychan >= 76 and $mychan <= 99) {
|
|
|
|
$info{"channel"}=($mychan * 5) + 3000;
|
|
|
|
} else {
|
|
|
|
$info{"channel"}=$mychan;
|
|
|
|
}
|
2015-08-18 20:39:30 -06:00
|
|
|
|
2015-07-21 11:19:41 -06:00
|
|
|
# ------- Wifi Bandwidth
|
|
|
|
$line = `uci get wireless.radio0.chanbw`;
|
|
|
|
chomp($line);
|
|
|
|
$info{"chanbw"}=$line;
|
|
|
|
|
2015-07-10 20:51:18 -06:00
|
|
|
# ------- ACTIVE TUNNELS
|
|
|
|
$active_tunnel_count=`ifconfig|grep tun|wc -l`;
|
|
|
|
chomp($active_tunnel_count);
|
|
|
|
$info{"active_tunnel_count"}=$active_tunnel_count;
|
|
|
|
|
|
|
|
# ------- LAT/LON
|
|
|
|
$lat=`head -1 /etc/latlon 2>/dev/null`;
|
|
|
|
chomp($lat);
|
|
|
|
$info{"lat"}=$lat;
|
|
|
|
|
|
|
|
$lon=`tail -1 /etc/latlon 2>/dev/null`;
|
|
|
|
chomp($lon);
|
|
|
|
$info{"lon"}=$lon;
|
|
|
|
|
2015-07-13 19:32:17 -06:00
|
|
|
# ------- GRID SQUARE
|
|
|
|
$grid=`head -1 /etc/gridsquare 2>/dev/null`;
|
|
|
|
chomp($grid);
|
|
|
|
$info{"grid_square"}=$grid;
|
|
|
|
|
2015-07-10 20:51:18 -06:00
|
|
|
|
|
|
|
# ----------- GENERATE THE JSON ------------
|
|
|
|
print "{";
|
|
|
|
foreach $ik (keys %info)
|
|
|
|
{
|
|
|
|
print "\"$ik\":\"",$info{$ik},"\",";
|
|
|
|
}
|
|
|
|
|
|
|
|
############## INTERFACES
|
2015-12-12 16:19:52 -07:00
|
|
|
print "\"interfaces\":[";
|
2015-07-10 20:51:18 -06:00
|
|
|
$mystr="";
|
|
|
|
foreach(`ifconfig -a`)
|
|
|
|
{
|
|
|
|
next unless /^(\S+) .*HWaddr (\S+)/;
|
2015-12-12 16:19:52 -07:00
|
|
|
$mystr .= sprintf "{\"name\":\"%s\",", $1;
|
2015-07-10 20:51:18 -06:00
|
|
|
($ip, $mask, $bcast, $net, $cidr) = &get_my_ip($1);
|
|
|
|
$mystr .= sprintf "\"ip\":\"%s\",",$ip;
|
2015-12-12 16:19:52 -07:00
|
|
|
$mystr .= sprintf "\"mac\":\"%s\"}",$2;
|
|
|
|
$mystr .= sprintf ",";
|
2015-07-10 20:51:18 -06:00
|
|
|
}
|
|
|
|
chop($mystr);
|
|
|
|
print $mystr;
|
2015-12-12 16:19:52 -07:00
|
|
|
print "]";
|
2015-07-10 20:51:18 -06:00
|
|
|
############## INTERFACES
|
|
|
|
|
|
|
|
if($parms{"hosts"} )
|
|
|
|
{
|
2015-12-12 16:19:52 -07:00
|
|
|
print ",\"hosts\":[";
|
2015-07-10 20:51:18 -06:00
|
|
|
$mystr="";
|
|
|
|
foreach(`cat /var/run/hosts_olsr`)
|
|
|
|
{
|
|
|
|
$line = $_;
|
|
|
|
next unless /^(\d+\.\d+\.\d+\.\d+)\s*(\S+)/;
|
2016-06-14 12:25:05 -06:00
|
|
|
if ($line !~ /dtdlink|mid[0-9]+\./ ) {
|
2015-12-12 16:19:52 -07:00
|
|
|
$mystr .= sprintf "{\"name\":\"%s\",\"ip\":\"%s\"},",$2,$1;
|
2015-07-10 20:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
chop($mystr);
|
|
|
|
print $mystr;
|
2015-12-12 16:19:52 -07:00
|
|
|
print "]";
|
2015-07-10 20:51:18 -06:00
|
|
|
############## HOSTS
|
|
|
|
}
|
|
|
|
|
|
|
|
print "}"; # ROOT
|
|
|
|
|
|
|
|
##############################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub json_header
|
|
|
|
{
|
|
|
|
# THIS MUST BE ONE LINE!
|
|
|
|
# otherwise an intermittent busybox bug will incorrectly "fix" the generated output
|
|
|
|
# print "HTTP/1.0 200 OK\r\n"; # Not needed under Uhttpd
|
|
|
|
print "Content-type: application/json\r\n";
|
|
|
|
print "Cache-Control: no-store\r\n";
|
|
|
|
print "\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_my_ip
|
|
|
|
{
|
|
|
|
my($ip);
|
|
|
|
foreach(`ifconfig $_[0]`)
|
|
|
|
{
|
|
|
|
next unless /inet addr:([\d\.]+)/;
|
|
|
|
$ip = $1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
return ("none") unless defined $ip;
|
|
|
|
return $ip;
|
2015-11-15 20:28:56 -07:00
|
|
|
}
|