aboutsummaryrefslogtreecommitdiffstats
path: root/web/api
diff options
context:
space:
mode:
Diffstat (limited to 'web/api')
-rwxr-xr-xweb/api/public/config31
-rwxr-xr-xweb/api/public/dhcp36
-rwxr-xr-xweb/api/public/dhcp-summary16
-rwxr-xr-xweb/api/public/distro-tree27
-rwxr-xr-xweb/api/public/location44
-rwxr-xr-xweb/api/public/ping35
-rwxr-xr-xweb/api/public/switch-state156
-rwxr-xr-xweb/api/public/switches32
-rwxr-xr-xweb/api/read/networks26
-rwxr-xr-xweb/api/read/oplog36
-rwxr-xr-xweb/api/read/snmp30
-rwxr-xr-xweb/api/read/switches-management52
-rwxr-xr-xweb/api/read/template-list21
-rwxr-xr-xweb/api/write/collector23
-rwxr-xr-xweb/api/write/config22
-rwxr-xr-xweb/api/write/fap19
-rwxr-xr-xweb/api/write/networks85
-rwxr-xr-xweb/api/write/oplog22
-rwxr-xr-xweb/api/write/switches122
19 files changed, 0 insertions, 835 deletions
diff --git a/web/api/public/config b/web/api/public/config
deleted file mode 100755
index 0f0d322..0000000
--- a/web/api/public/config
+++ /dev/null
@@ -1,31 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "3600";
-
-my $hostname = $ENV{'HTTP_HOST'} || "";
-my $q2 = $nms::web::dbh->prepare('select id, publicvhost, shortname, data from config order by id desc limit 1;');
-
-$q2->execute();
-$nms::web::json{'config'}{'data'} = 0;
-$nms::web::json{'config'}{'shortname'} = "notset";
-$nms::web::json{'config'}{'publicvhost'} = "notset";
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'config'} = $ref;
- $nms::web::json{'config'}{'data'} = JSON::XS::decode_json($ref->{'data'});
- if ($ref->{'publicvhost'} eq $hostname) {
- $nms::web::json{'config'}{'public'} = "true";
- } else {
- $nms::web::json{'config'}{'public'} = "false";
- }
-}
-
-finalize_output();
diff --git a/web/api/public/dhcp b/web/api/public/dhcp
deleted file mode 100755
index 3e56f59..0000000
--- a/web/api/public/dhcp
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web qw (%json finalize_output);
-use strict;
-use warnings;
-use Data::Dumper;
-
-nms::web::setwhen('60m');
-#my $q = $nms::web::dbh->prepare('select distinct on (name) extract(epoch from date_trunc(\'second\',time)) as time,name from dhcp join networks on dhcp.network = networks.network where ' . $nms::web::when . ' order by name,time desc;');
-my $q_v4 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 where $nms::web::when order by name,time desc;");
-$q_v4->execute();
-while ( my $ref = $q_v4->fetchrow_hashref() ) {
- my $sysname = $ref->{'sname'};
- $json{'dhcp4'}{$ref->{'name'}} = $ref->{'time'};
-}
-
-my $q_v6 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet6 where $nms::web::when order by name,time desc;");
-$q_v6->execute();
-while ( my $ref = $q_v6->fetchrow_hashref() ) {
- my $sysname = $ref->{'sname'};
- $json{'dhcp6'}{$ref->{'name'}} = $ref->{'time'};
-}
-
-
-#my $q2 = $nms::web::dbh->prepare("select name,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join networks where $nms::web::when group by networks.name;");
-my $q2 = $nms::web::dbh->prepare("SELECT networks.name, count(distinct data->>'clientmac') as clients, count(distinct data->>'clientip') as addresses, count(data->>'clientmac') as acks from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 WHERE $nms::web::when GROUP BY networks.name;");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'networks'}{$ref->{name}} = $ref;
-}
-
-$nms::web::cc{'max-age'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
diff --git a/web/api/public/dhcp-summary b/web/api/public/dhcp-summary
deleted file mode 100755
index beed463..0000000
--- a/web/api/public/dhcp-summary
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /usr/bin/perl
-use lib '/opt/gondul/include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('2h');
-
-my $q2 = $nms::web::dbh->prepare("select count(DISTINCT data ->> 'clientip') as clients, family(inet (data ->> 'clientip')) as family from metrics where $nms::web::when GROUP by family;");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'dhcp'}{$ref->{'family'}} = $ref->{'clients'};
-}
-$nms::web::cc{'max-age'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "15";
-finalize_output();
diff --git a/web/api/public/distro-tree b/web/api/public/distro-tree
deleted file mode 100755
index 49ce607..0000000
--- a/web/api/public/distro-tree
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $q2 = $nms::web::dbh->prepare('select sysname,distro_phy_port,distro_name from switches where placement is not null and distro_name is not null and distro_phy_port is not null and deleted = false');
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
- my $distro = $ref->{'distro_name'};
- my $phy = $ref->{'distro_phy_port'};
- $nms::web::json{'distro-tree-phy'}{$distro}{$phy} = $sysname;
- $nms::web::json{'distro-tree-sys'}{$distro}{$sysname} = $phy;
-}
-
-finalize_output();
diff --git a/web/api/public/location b/web/api/public/location
deleted file mode 100755
index b960bb2..0000000
--- a/web/api/public/location
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-#my $query = $nms::web::dbh->prepare("select * from switches where '185.110.150.7' << subnet4");
-my $query = $nms::web::dbh->prepare("select * from switches where deleted = false and (? << subnet4 or ? << subnet6)");
-
-print "Cache-Control: max-age=0";
-print "Content-Type: text/html";
-print "\n\n";
-
-# get user ip from somewhere.
-# HTTP_X_FORWARDED_FOR is set by varnish. When using varnish, the REMOTE_ADDR will always be localhost.
-
-my @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR});
-my $addr = $xff[0] // $ENV{REMOTE_ADDR};
-
-$query->execute($addr,$addr);
-
-# add start html: header + body etc.
-print "
-<html>
- <body style=\"text-align: center; font-size: 50pt;\">
-";
-
-# print address
-print "" . $addr ."<br \>";
-
-# print switch name and distroname.
-while ( my $ref = $query->fetchrow_hashref() ) {
- print $ref->{sysname}. " @ " . $ref->{distro};
- print "<br />";
-}
-
-# add end html
-print "
- </body>
-</html>
-";
diff --git a/web/api/public/ping b/web/api/public/ping
deleted file mode 100755
index 52dffbc..0000000
--- a/web/api/public/ping
+++ /dev/null
@@ -1,35 +0,0 @@
-#! /usr/bin/perl
-use lib '/opt/gondul/include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('25s');
-
-my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where "
- . $nms::web::when . " group by switch)");
-
-$q->execute();
-while (my $ref = $q->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency4'} = $ref->{'latency_ms'};
- # Get seconds, without decimlas, from timestamp.
- # '00:01:01.435601' => 61 seconds.
- my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} );
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'age4'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
-}
-
-my $q2 = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping_secondary_ip NATURAL JOIN switches WHERE time in (select max(time) from ping where "
- . $nms::web::when . " group by switch)");
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency6'} = $ref->{'latency_ms'};
- # Get seconds, without decimlas, from timestamp.
- # '00:01:01.435601' => 61 seconds.
- my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} );
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'age6'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
-}
-
-$nms::web::cc{'max-age'} = "1";
-$nms::web::cc{'stale-while-revalidate'} = "5";
-finalize_output();
diff --git a/web/api/public/switch-state b/web/api/public/switch-state
deleted file mode 100755
index 2aff40c..0000000
--- a/web/api/public/switch-state
+++ /dev/null
@@ -1,156 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web qw (%json finalize_output);
-use strict;
-use warnings;
-use Data::Dumper;
-
-#my $target = $ENV{REQUEST_URI};
-#$target =~ s/$ENV{SCRIPT_NAME}//;
-#$target =~ s/^\///;
-#my ($switch, $port) = split(/\//,$target,2);
-my $port;
-my $switch;
-my $q;
-
-#if (!defined($switch)) {
- $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . ' group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
-#} else {
-# $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and sysname = ' . $nms::web::dbh->quote($switch) . ';');
-#}
-
-$q->execute();
-while ( my $ref = $q->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
-
- my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
- $json{'switches'}{$sysname}{'clients'}{'live'} = 0;
- $json{'then'}{$sysname}{'clients'}{'live'} = 0;
- for my $porti (keys %{$data{'ports'}}) {
- if (defined($port) and $port ne "" and $port ne $porti) {
- next;
- }
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if ($data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- $smallport =~ s/[0-9-].*$//;
- } else {
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/G:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{'uplinks'}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
- }
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'switches'}{$sysname}{'clients'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{'clients'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{'clients'}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{'clients'}{'total'} += 1;
- }
- }
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- if ($smallport ne "loopback") {
- $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'switches'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- }
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{ifs}{$smallport}{'live'} += 1;
- $json{'switches'}{$sysname}{totals}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{totals}{'total'} += 1;
- }
-
- $json{'switches'}{$sysname}{vcp}{jnxVirtualChassisPortInOctets} = $data{'vcp'}{'jnxVirtualChassisPortInOctets'};
- $json{'switches'}{$sysname}{vcp}{jnxVirtualChassisPortOutOctets} = $data{'vcp'}{'jnxVirtualChassisPortOutOctets'};
- $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.2.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.3.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.4.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.5.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.6.0.0'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1011'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1008'};
- $json{'switches'}{$sysname}{'time'} = $ref->{'time'};
-}
-
-nms::web::setwhen('15m','10m');
-my $q2;
-if (!defined($switch)) {
- $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . ' group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
-} else {
- $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'] and sysname = ' . $nms::web::dbh->quote($switch) . ';');
-}
-
-$q2->execute();
-while ( my $ref = $q2->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
-
- my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
- for my $porti (keys %{$data{'ports'}}) {
- if (defined($port) and $port ne "" and $port ne $porti) {
- next;
- }
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if ($data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- $smallport =~ s/[0-9-].*$//;
- } else {
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/G:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{'uplinks'}{'live'} += 1;
- }
- $json{'then'}{$sysname}{'uplinks'}{'total'} += 1;
- }
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'then'}{$sysname}{'clients'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{'clients'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{'clients'}{'live'} += 1;
- }
- $json{'then'}{$sysname}{'clients'}{'total'} += 1;
- }
- }
-
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- $json{'then'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'then'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{ifs}{$smallport}{'live'} += 1;
- $json{'then'}{$sysname}{totals}{'live'} += 1;
- }
- $json{'then'}{$sysname}{totals}{'total'} += 1;
- }
- $json{'then'}{$sysname}{vcp}{jnxVirtualChassisPortInOctets} = $data{'vcp'}{'jnxVirtualChassisPortInOctets'};
- $json{'then'}{$sysname}{vcp}{jnxVirtualChassisPortOutOctets} = $data{'vcp'}{'jnxVirtualChassisPortOutOctets'};
- $json{'then'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1011'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1008'};
- $json{'then'}{$sysname}{'time'} = $ref->{'time'};
-}
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
-
diff --git a/web/api/public/switches b/web/api/public/switches
deleted file mode 100755
index 9bb63d8..0000000
--- a/web/api/public/switches
+++ /dev/null
@@ -1,32 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $q2 = $nms::web::dbh->prepare('select switch, sysname, tags, distro_name, placement, last_updated from switches where placement is not null and deleted = false');
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/;
- my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);
- my $sysname = $ref->{'sysname'};
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'x'} = $x2;
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2;
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2;
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2;
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'distro_name'} = $ref->{'distro_name'};
- my $data = JSON::XS::decode_json($ref->{'tags'});
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'tags'} = $data;
-}
-
-finalize_output();
diff --git a/web/api/read/networks b/web/api/read/networks
deleted file mode 100755
index 0fbdb15..0000000
--- a/web/api/read/networks
+++ /dev/null
@@ -1,26 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $q2 = $nms::web::dbh->prepare('select name, vlan, networks.tags, switches.sysname as router, subnet4, subnet6, gw4, gw6 from networks left join switches on switches.switch = networks.router');
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- my $name = $ref->{'name'};
- $nms::web::json{'networks'}{$ref->{'name'}} = $ref;
- my $data = JSON::XS::decode_json($ref->{'tags'});
- $nms::web::json{'networks'}{$ref->{'name'}}{'tags'} = $data;
-}
-
-finalize_output();
diff --git a/web/api/read/oplog b/web/api/read/oplog
deleted file mode 100755
index 22e21ac..0000000
--- a/web/api/read/oplog
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web;
-use strict;
-use warnings;
-
-my $filter = '';
-
-if (defined($get_params{'now'})) {
- $filter = "where time < timestamp with time zone 'epoch' + " . db_safe_quote('now') . " * INTERVAL '1 second' ";
-}
-my $query = $nms::web::dbh->prepare('select id,date_trunc(\'second\',time) as timestamp,extract(hour from time) as h, extract(minute from time) as m,systems,username,log from oplog '
- . $filter .
-'order by id desc;');
-$query->execute();
-while (my $ref = $query->fetchrow_hashref()) {
- my %meh;
- if (!defined($ref->{'log'})) {
- next;
- }
- $meh{'time'} = $ref->{'h'} . ":" . $ref->{'m'};
- $meh{'log'} = $ref->{'log'} || "weird?";
- $meh{'username'} = $ref->{'username'} || "undefined";
- $meh{'id'} = $ref->{'id'};
- $meh{'systems'} = $ref->{'systems'};
- $meh{'timestamp'} = $ref->{'timestamp'};
- $meh{'timestamp'} =~ s/ /T/;
- $meh{'timestamp'} =~ s/\+00$/Z/;
- $meh{'timestamp'} =~ s/\+(\d\d)$/+$1:00/;
-
- push @{$nms::web::json{'oplog'}},\%meh;
-}
-
-nms::web::finalize_output();
diff --git a/web/api/read/snmp b/web/api/read/snmp
deleted file mode 100755
index 0865107..0000000
--- a/web/api/read/snmp
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use JSON;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "10";
-
-my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where '
- . $nms::web::when . 'group by switch);');
-
-$q->execute();
-while (my $ref = $q->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
-
- # This is, strictly speaking, redundant. But by doing this, we can
- # re-use the standard methods of finalize_output() and whatnot.
- my $data = JSON::XS::decode_json($ref->{'data'});
-
- $nms::web::json{'snmp'}{$ref->{'sysname'}} = $data;
-}
-
-finalize_output();
diff --git a/web/api/read/switches-management b/web/api/read/switches-management
deleted file mode 100755
index 118ea4d..0000000
--- a/web/api/read/switches-management
+++ /dev/null
@@ -1,52 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-my $target = $ENV{REQUEST_URI};
-$target =~ s/$ENV{SCRIPT_NAME}//;
-$target =~ s/^\///;
-my $switch;
-my $port;
-
-if ($target !~ m/now=/) {
- ($switch, $port) = split(/\//,$target,2);
-}
-
-my $q2;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $limit = '';
-if (defined($switch)) {
- $limit = ' and sysname = ' . $nms::web::dbh->quote($switch);
-}
-
-$q2 = $nms::web::dbh->prepare("select
- switches.sysname,
- host(switches.mgmt_v4_addr) as mgmt_v4_addr,
- host(switches.mgmt_v6_addr) as mgmt_v6_addr,
- switches.mgmt_vlan,
- switches.traffic_vlan,
- switches.poll_frequency,
- switches.last_updated,
- switches.distro_name,
- switches.distro_phy_port,
- switches.community
- from switches where switches.placement is not null and switches.deleted = false $limit;");
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
- $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref;
-}
-
-finalize_output();
diff --git a/web/api/read/template-list b/web/api/read/template-list
deleted file mode 100755
index 81b9986..0000000
--- a/web/api/read/template-list
+++ /dev/null
@@ -1,21 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web;
-use strict;
-use warnings;
-
-my @dirs = ("/opt/gondul/web/templates","/opt/gondul/data/templates");
-
-foreach my $template_dir (@dirs) {
-opendir (DIR, $template_dir) or next;
-while (my $file = readdir(DIR)) {
- next if ($file =~ m/^\./);
- my %meh;
- $meh{'file'} = $file;
-
- push @{$nms::web::json{'templates'}},\%meh;
-}
-}
-nms::web::finalize_output();
diff --git a/web/api/write/collector b/web/api/write/collector
deleted file mode 100755
index eb20e8c..0000000
--- a/web/api/write/collector
+++ /dev/null
@@ -1,23 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-use lib '/opt/gondul/include';
-use utf8;
-use nms;
-use nms::web qw($dbh db_safe_quote get_input finalize_output);
-
-use strict;
-use warnings;
-
-my %input = %{JSON::XS::decode_json(get_input())};
-
-my ($q,$check);
-my $metric = $dbh->prepare("INSERT INTO metrics (src,metadata,data) VALUES(?,?,?)");
-
-$nms::web::cc{'max-age'} = '0';
-$nms::web::cc{'stale-while-revalidate'} = '0';
-$nms::web::json{'state'} = 'ok';
-
-foreach my $entry (@{$input{'data'}}) {
- $metric->execute($input{'src'},JSON::XS::encode_json($input{'metadata'}),JSON::XS::encode_json($entry));
-}
-finalize_output();
diff --git a/web/api/write/config b/web/api/write/config
deleted file mode 100755
index 468bf6a..0000000
--- a/web/api/write/config
+++ /dev/null
@@ -1,22 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-use lib '/opt/gondul/include';
-use utf8;
-use nms;
-use nms::web qw($dbh db_safe_quote get_input finalize_output);
-
-use strict;
-use warnings;
-
-my $in = get_input();
-my %tmp = %{JSON::XS::decode_json($in)};
-
-my $q = $nms::web::dbh->prepare("INSERT INTO config (publicvhost,shortname,data) VALUES(?,?,?);");
-$q->execute($tmp{'publicvhost'},$tmp{'shortname'},JSON::XS::encode_json($tmp{'data'}));
-
-$nms::web::cc{'max-age'} = '0';
-$nms::web::cc{'stale-while-revalidate'} = '0';
-$nms::web::json{'state'} = 'ok';
-
-print "X-ban: /api/public/config\n";
-finalize_output();
diff --git a/web/api/write/fap b/web/api/write/fap
deleted file mode 100755
index 1211349..0000000
--- a/web/api/write/fap
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-fil=/var/log/apache2/kek
-echo 'Content-Type: text/html'
-echo
-echo
-pw="<redacted>"
-sw=$(echo $PATH_INFO | sed 's/^\///')
-POST -H'Content-Type: application/json' https://gondul:${pw}@awx.tg23.gathering.org/api/v2/job_templates/19/launch/ >/dev/null 2>&1 <<_EOF_
-{"credential_passwords":{},"limit":"$sw","extra_vars":{}}
-_EOF_
-ret=$?
-./oplog >/dev/null 2>&1 <<_EOF_
-{"systems": "$sw", "log": "Refap queued in AWX for $sw"}
-_EOF_
-while read; do
- true
-done
-echo '"ok"'
diff --git a/web/api/write/networks b/web/api/write/networks
deleted file mode 100755
index a4a8868..0000000
--- a/web/api/write/networks
+++ /dev/null
@@ -1,85 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-#use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web qw(%get_params %json finalize_output get_input $dbh);
-use strict;
-use warnings;
-use JSON;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "0";
-
-my $in = get_input();
-my @tmp = @{JSON::XS::decode_json($in)};
-
-my @added;
-my @dups;
-
-my $sth = $nms::web::dbh->prepare("SELECT name FROM networks WHERE name=?");
-
-
-my @fields = ('name','subnet4','subnet6','gw4','gw6','router','vlan','tags');
-
-foreach my $tmp2 (@tmp) {
- my %network = %{$tmp2};
- my $affected = 0;
- my %template = ();
- map { $template{$_} = 'DEFAULT' } @fields;
- if (not defined($network{'name'})) {
- next;
- }
-
- $sth->execute( $network{'name'});
- while ( my @row = $sth->fetchrow_array ) {
- $affected += 1;
- }
-
- if ($affected == 0) {
-
- map {
- if (defined ($template{$_})) {
- $template{$_} = $dbh->quote($network{$_});
- }
- } keys %network;
-
- if ($template{'router'} ne 'DEFAULT') {
- $template{'router'} = "(select switch from switches where sysname = $template{'router'})";
- }
- if ($template{'gw4'} eq 'DEFAULT' and $template{'subnet4'} ne 'DEFAULT') {
- $template{'gw4'} = "host(inet $template{'subnet4'} + 1)";
- }
- if ($template{'gw6'} eq 'DEFAULT' and $template{'subnet6'} ne 'DEFAULT') {
- $template{'gw6'} = "host(inet $template{'subnet6'} + 1)";
- }
- if (defined($network{'tags'})) {
- $template{'tags'} = "'[". join(",", map { "\"".$_."\"" } @{$network{'tags'}})."]'";
- }
- $nms::web::dbh->do("INSERT INTO NETWORKS (name, subnet4, subnet6, router, gw4, gw6, vlan, tags) VALUES ($template{'name'}, $template{'subnet4'}, $template{'subnet6'}, $template{'router'}, $template{'gw4'}, $template{'gw6'}, $template{'vlan'}, $template{'tags'});");
- push @added, $network{'name'};
- } else {
- if (defined($network{'tags'})) {
- $network{'tags'} = "[". join(",", map { "\"".$_."\"" } @{$network{'tags'}})."]";
- }
- my @set;
- map {
- if (defined($template{$_})) {
- if ($_ eq "router") {
- push @set, "router=(select switch from switches where sysname = " . $dbh->quote($network{$_}) . ")";
- } else {
- push @set, "$_=" . $dbh->quote($network{$_});
- }
- }
- } keys %network;
- $nms::web::dbh->do("UPDATE networks SET " . join(", ", @set) . "WHERE name=" . $dbh->quote($network{'name'}) . ";");
- push @dups, $network{'name'};
- }
-}
-$json{'networks_addded'} = \@added;
-$json{'networks_updated'} = \@dups;
-
-print "X-ban: /api/.*networks.*\n";
-finalize_output();
diff --git a/web/api/write/oplog b/web/api/write/oplog
deleted file mode 100755
index 73b807b..0000000
--- a/web/api/write/oplog
+++ /dev/null
@@ -1,22 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-use lib '/opt/gondul/include';
-use utf8;
-use nms::web qw($dbh db_safe_quote get_input finalize_output);
-use strict;
-use warnings;
-
-my $in = get_input();
-my %tmp = %{JSON::XS::decode_json($in)};
-
-my $user = $tmp{'user'} || $ENV{'REMOTE_USER'} || "undefined";
-
-my $q = $nms::web::dbh->prepare("INSERT INTO oplog (username, systems, log) values (?,?,?);");
-$q->execute($user, $tmp{'systems'}, $tmp{'log'});
-
-$nms::web::cc{'max-age'} = '0';
-$nms::web::cc{'stale-while-revalidate'} = '0';
-$nms::web::json{'state'} = 'ok';
-
-print "X-ban: /api/read/oplog\n";
-finalize_output();
diff --git a/web/api/write/switches b/web/api/write/switches
deleted file mode 100755
index 470cde1..0000000
--- a/web/api/write/switches
+++ /dev/null
@@ -1,122 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-#use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web qw(%get_params %json finalize_output get_input $dbh);
-use nms::util qw(guess_placement);
-use strict;
-use warnings;
-use JSON;
-use Data::Dumper;
-use nms::oplog qw(oplog);
-
-$nms::web::cc{'max-age'} = "0";
-
-my $in = get_input();
-my @tmp = @{JSON::XS::decode_json($in)};
-
-my @added;
-my @dups;
-
-my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-
-my @fields = ( 'community', 'tags', 'distro_name', 'distro_phy_port', 'mgmt_v4_addr', 'mgmt_v6_addr', 'mgmt_vlan', 'placement', 'poll_frequency', 'sysname', 'traffic_vlan', 'deleted');
-
-sub convertplace
-{
- my %in = %{$_[0]};
- my %out = ();
-
- if (not defined $in{'x1'} and defined($in{'x'})) {
- $out{'x1'} = int($in{'x'});
- $out{'y1'} = int($in{'y'});
- $out{'xx'} = int($in{'x'} + $in{'width'});
- $out{'yy'} = int($in{'y'} + $in{'height'});
- } else {
- return \%in;
- }
- return \%out;
-}
-
-foreach my $tmp2 (@tmp) {
- my %switch = %{$tmp2};
- my $affected = 0;
- my %template = ();
- map { $template{$_} = 'DEFAULT' } @fields;
- if (not defined($switch{'sysname'})) {
- next;
- }
-
- $sth->execute( $switch{'sysname'});
- while ( my @row = $sth->fetchrow_array ) {
- $affected += 1;
- }
-
- if ($affected == 0) {
- my %placement;
- if (not defined ($switch{'placement'})) {
- %placement = guess_placement($switch{'sysname'});
- } else {
- %placement = %{convertplace($switch{'placement'})};
- }
- if (defined($switch{'tags'})) {
- # MY GOD I HATE THIS
- # But I'm too lazy to improve it more for now.
- $switch{'tags'} = "[". join(",", map { "\"".$_."\"" } @{$switch{'tags'}})."]";
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
- my @names;
- my @values;
- map {
- if (defined ($template{$_})) {
- push @names,$_;
- push @values,$dbh->quote($switch{$_});
- }
- } keys %switch;
- $nms::web::dbh->do("INSERT INTO SWITCHES (" . join(",",@names) . ") VALUES (". join(",",@values).");");
- push @added, $switch{'sysname'};
- oplog("\"" . $switch{'sysname'} . "\"", "Switch added: " . $switch{'sysname'});
- } else {
- if (defined($switch{'placement'})) {
- my %placement;
- if ($switch{'placement'} eq "reset") {
- %placement = guess_placement($switch{'sysname'});
- } else {
- %placement = %{convertplace($switch{'placement'})};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
- push @dups, "not really, but: " . $switch{'placement'};
- }
- if (defined($switch{'tags'})) {
- # MY GOD I HATE THIS
- # But I'm too lazy to improve it more for now.
- $switch{'tags'} = "[". join(",", map { "\"".$_."\"" } @{$switch{'tags'}})."]";
- }
- my @set;
- map {
- if (defined($template{$_})) {
- push @set, "$_=" . $dbh->quote($switch{$_});
- }
- } keys %switch;
- $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . " WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";");
- push @dups, $switch{'sysname'};
- }
-}
-$json{'switches_addded'} = \@added;
-$json{'switches_updated'} = \@dups;
-
-print "X-ban: /api/.*switches.*\n";
-finalize_output();