mirror of https://github.com/aredn/aredn.git
enhancement: add services to sysinfo.json api
Change-Id: I09769ef110a6210513efc4bc23908be9ac7ddf6a
This commit is contained in:
parent
8bf9d0948d
commit
5eb457b11a
|
@ -32,6 +32,9 @@
|
||||||
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.
|
||||||
|
|
||||||
|
API VERSIONS:
|
||||||
|
1.0 - initial release
|
||||||
|
1.1 - added services
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
BEGIN {push @INC, '/www/cgi-bin'};
|
BEGIN {push @INC, '/www/cgi-bin'};
|
||||||
|
@ -42,7 +45,7 @@ read_query_string();
|
||||||
|
|
||||||
|
|
||||||
my %info;
|
my %info;
|
||||||
$info{"api_version"}="1.0";
|
$info{"api_version"}="1.1";
|
||||||
|
|
||||||
# ============ GENERATE INFO HASH =========
|
# ============ GENERATE INFO HASH =========
|
||||||
$node=nvram_get("node");
|
$node=nvram_get("node");
|
||||||
|
@ -145,23 +148,55 @@ print "]";
|
||||||
|
|
||||||
if($parms{"hosts"} )
|
if($parms{"hosts"} )
|
||||||
{
|
{
|
||||||
print ",\"hosts\":[";
|
print ",\"hosts\":[";
|
||||||
$mystr="";
|
$mystr="";
|
||||||
foreach(`cat /var/run/hosts_olsr`)
|
$hostsfile="/var/run/hosts_olsr";
|
||||||
{
|
if ( -e $hostsfile)
|
||||||
$line = $_;
|
{
|
||||||
next unless /^(\d+\.\d+\.\d+\.\d+)\s*(\S+)/;
|
if (open(FILE, "<$hostsfile")) {
|
||||||
if ($line !~ /dtdlink|mid[0-9]+\./ ) {
|
while($line = <FILE>)
|
||||||
$mystr .= sprintf "{\"name\":\"%s\",\"ip\":\"%s\"},",$2,$1;
|
{
|
||||||
}
|
next unless $line =~ /^(\d+\.\d+\.\d+\.\d+)\s*(\S+)/;
|
||||||
}
|
if ($line !~ /dtdlink|mid[0-9]+\./ ) {
|
||||||
|
$mystr .= sprintf "{\"name\":\"%s\",\"ip\":\"%s\"},",$2,$1;
|
||||||
chop($mystr);
|
}
|
||||||
print $mystr;
|
}
|
||||||
print "]";
|
close FILE;
|
||||||
############## HOSTS
|
} else {
|
||||||
|
$mystr=sprintf "{\"error\":\"Could not open: %s\"",$hostsfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chop($mystr);
|
||||||
|
print $mystr;
|
||||||
|
print "]";
|
||||||
|
############## HOSTS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($parms{"services"} )
|
||||||
|
{
|
||||||
|
print ",\"services\":[";
|
||||||
|
$mystr="";
|
||||||
|
$servicesfile="/var/run/services_olsr";
|
||||||
|
if ( -e $servicesfile )
|
||||||
|
{
|
||||||
|
if (open(FILE, "<$servicesfile")) {
|
||||||
|
while($line = <FILE>)
|
||||||
|
{
|
||||||
|
next unless $line =~ /^(.*)\|(.+)\|(.*)\t+\s+.*/;
|
||||||
|
$mystr .= sprintf "{\"link\":\"%s\",\"protocol\":\"%s\",\"name\":\"%s\"},",$1,$2,$3;
|
||||||
|
}
|
||||||
|
close FILE ;
|
||||||
|
} else {
|
||||||
|
$mystr=sprintf "{\"error\":\"Could not open: %s\"",$servicesfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chop($mystr);
|
||||||
|
print $mystr;
|
||||||
|
print "]";
|
||||||
|
############## SERVICES
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
print "}"; # ROOT
|
print "}"; # ROOT
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
|
|
Loading…
Reference in New Issue