diff options
Diffstat (limited to 'web/nms.gathering.org/switches-json.pl')
-rwxr-xr-x | web/nms.gathering.org/switches-json.pl | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/web/nms.gathering.org/switches-json.pl b/web/nms.gathering.org/switches-json.pl index 67017b4..2ccb247 100755 --- a/web/nms.gathering.org/switches-json.pl +++ b/web/nms.gathering.org/switches-json.pl @@ -8,17 +8,16 @@ use nms; my $cgi = CGI->new; my $dbh = nms::db_connect(); +my %json = (); my $q = $dbh->prepare('select switch,sysname,placement,zorder from switches natural join placements'); $q->execute(); - -my %json = (); while (my $ref = $q->fetchrow_hashref()) { $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/; my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4); my $sysname = $ref->{'sysname'}; $sysname =~ s/\..*$//; - $json{$ref->{'switch'}} = { + $json{'switches'}{$ref->{'switch'}} = { sysname => $sysname, x => $x2, y => $y2, @@ -27,5 +26,12 @@ while (my $ref = $q->fetchrow_hashref()) { zorder => $ref->{'zorder'} }; } + +my $q = $dbh->prepare('select linknet,switch1,switch2 from linknets'); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + push @{$json{'linknets'}}, $ref; +} + print $cgi->header(-type=>'text/json; charset=utf-8'); print JSON::XS::encode_json(\%json); |