diff options
Diffstat (limited to 'web/api/write')
-rwxr-xr-x | web/api/write/collector | 23 | ||||
-rwxr-xr-x | web/api/write/config | 22 | ||||
-rwxr-xr-x | web/api/write/fap | 19 | ||||
-rwxr-xr-x | web/api/write/networks | 85 | ||||
-rwxr-xr-x | web/api/write/oplog | 22 | ||||
-rwxr-xr-x | web/api/write/switches | 122 |
6 files changed, 0 insertions, 293 deletions
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(); |