diff options
Diffstat (limited to 'web/api/write')
-rwxr-xr-x | web/api/write/linknet-add | 32 | ||||
-rwxr-xr-x | web/api/write/oplog | 2 | ||||
-rwxr-xr-x | web/api/write/switch-add | 4 |
3 files changed, 36 insertions, 2 deletions
diff --git a/web/api/write/linknet-add b/web/api/write/linknet-add new file mode 100755 index 0000000..13ccd17 --- /dev/null +++ b/web/api/write/linknet-add @@ -0,0 +1,32 @@ +#! /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 $q = $nms::web::dbh->prepare("INSERT INTO linknets (switch1, switch2) VALUES((SELECT switch FROM switches WHERE sysname = ? LIMIT 1), (SELECT switch FROM switches WHERE sysname = ? LIMIT 1));"); +my $sth = $nms::web::dbh->prepare("SELECT linknet FROM linknets WHERE switch1 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1) and switch2 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1);"); + +$sth->execute($tmp{'switch1'}, $tmp{'switch2'}); +my $affected = 0; +while ( my @row = $sth->fetchrow_array ) { + $affected += 1; +} + +print "X-affected: $affected\n"; +if ($affected eq 0) { + $q->execute($tmp{'switch1'}, $tmp{'switch2'}); +} + +$dbh->commit; +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +print "X-ban: /api/public/.*\n"; +finalize_output(); diff --git a/web/api/write/oplog b/web/api/write/oplog index 736ba2b..73b807b 100755 --- a/web/api/write/oplog +++ b/web/api/write/oplog @@ -9,7 +9,7 @@ use warnings; my $in = get_input(); my %tmp = %{JSON::XS::decode_json($in)}; -my $user = $ENV{'REMOTE_USER'} || "undefined"; +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'}); diff --git a/web/api/write/switch-add b/web/api/write/switch-add index 56e5cb2..f77df0a 100755 --- a/web/api/write/switch-add +++ b/web/api/write/switch-add @@ -11,6 +11,7 @@ use strict; use warnings; use JSON; use Data::Dumper; +use nms::oplog qw(oplog); $nms::web::cc{'max-age'} = "0"; @@ -83,10 +84,11 @@ foreach my $tmp2 (@tmp) { $nms::web::dbh->do("INSERT INTO SWITCHES (mgmt_v4_addr, sysname, poll_frequency, community, lldp_chassis_id, mgmt_v6_addr, placement,subnet4,subnet6,distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'mgmt_v6_addr'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro_name'});"); push @added, $switch{'sysname'}; + oplog("\"" . $switch{'sysname'} . "\"", "Switch added: " . $switch{'sysname'}); } } $json{'switches_addded'} = \@added; -print "X-ban: /api/.*switches.*\n"; +print "X-ban: /api/.*\n"; finalize_output(); |