aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/api/private
diff options
context:
space:
mode:
Diffstat (limited to 'web/nms.gathering.org/api/private')
-rwxr-xr-xweb/nms.gathering.org/api/private/comment-add11
-rwxr-xr-xweb/nms.gathering.org/api/private/comment-change10
-rwxr-xr-xweb/nms.gathering.org/api/private/port-state2
-rwxr-xr-xweb/nms.gathering.org/api/private/switch-add78
-rwxr-xr-xweb/nms.gathering.org/api/private/switches-management2
5 files changed, 83 insertions, 20 deletions
diff --git a/web/nms.gathering.org/api/private/comment-add b/web/nms.gathering.org/api/private/comment-add
index beb7b21..2f8b0b7 100755
--- a/web/nms.gathering.org/api/private/comment-add
+++ b/web/nms.gathering.org/api/private/comment-add
@@ -2,13 +2,16 @@
# vim:ts=8:sw=8
use lib '../../../../include';
use utf8;
-use nms::web;
+use nms::web qw($dbh db_safe_quote get_input finalize_output);
use strict;
use warnings;
-my $data = db_safe_quote('comment');
-my $switch = db_safe_quote('switch');
-my $user = $dbh->quote($cgi->remote_user() || "undefined");
+my $in = get_input();
+my %tmp = %{JSON::XS::decode_json($in)};
+
+my $data = $dbh->quote($tmp{'comment'});
+my $switch = $dbh->quote($tmp{'switch'});
+my $user = $dbh->quote($ENV{'REMOTE_USER'} || "undefined");
my $q = $nms::web::dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)");
$q->execute();
diff --git a/web/nms.gathering.org/api/private/comment-change b/web/nms.gathering.org/api/private/comment-change
index ccf336d..fb7da54 100755
--- a/web/nms.gathering.org/api/private/comment-change
+++ b/web/nms.gathering.org/api/private/comment-change
@@ -3,12 +3,16 @@
use lib '../../../../include';
use utf8;
use nms;
-use nms::web;
+use nms::web qw($dbh db_safe_quote get_input finalize_output);
+
use strict;
use warnings;
-my $id = db_safe_quote('comment');
-my $state = db_safe_quote('state');
+my $in = get_input();
+my %tmp = %{JSON::XS::decode_json($in)};
+
+my $id = $dbh->quote($tmp{'comment'});
+my $state = $dbh->quote($tmp{'state'});
my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";");
$q->execute();
diff --git a/web/nms.gathering.org/api/private/port-state b/web/nms.gathering.org/api/private/port-state
index 1f30181..8c6b64c 100755
--- a/web/nms.gathering.org/api/private/port-state
+++ b/web/nms.gathering.org/api/private/port-state
@@ -27,5 +27,7 @@ while (my $ref = $q3->fetchrow_hashref()) {
$nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'};
$nms::web::json{'switches'}{$ref->{'sysname'}}{'temp_time'} = $ref->{'time'};
}
+$nms::web::cc{'max-age'} = '2';
+$nms::web::cc{'stale-while-revalidate'} = '120';
finalize_output();
diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add
index af8db38..92479f0 100755
--- a/web/nms.gathering.org/api/private/switch-add
+++ b/web/nms.gathering.org/api/private/switch-add
@@ -6,6 +6,7 @@ use DBI;
use lib '../../../../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;
@@ -21,13 +22,32 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip');
+my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'placement');
+
+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 ) {
@@ -35,27 +55,61 @@ foreach my $tmp2 (@tmp) {
}
if ($affected == 0) {
+ my %placement;
+ if (not defined ($switch{'placement'})) {
+ %placement = guess_placement($switch{'sysname'});
+ } else {
+ %placement = %{convertplace($switch{'placement'})};
+ }
+ if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
+ $switch{'ip'} = $switch{'mgtmt4'};
+ }
+ my ($x1,$x2,$y1,$y2);
+ $x1 = $placement{'x1'};
+ $y1 = $placement{'y1'};
+ $x2 = $placement{'xx'};
+ $y2 = $placement{'yy'};
+ $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
+
map {
if (defined ($template{$_})) {
- $template{$_} = $dbh->quote($switch{$_});
+ $template{$_} = $dbh->quote($switch{$_});
}
} keys %switch;
+
+
+ $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});");
+ push @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 = $switch{'placement'}{'x1'};
- $y1 = $switch{'placement'}{'y1'};
- $x2 = $switch{'placement'}{'xx'};
- $y2 = $switch{'placement'}{'yy'};
- my $place = "(($x1,$y1),($x2,$y2))";
- $template{'placement'} = $place;
+ $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'};
}
- $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'});");
- push @added, $switch{'sysname'};
- } else {
+ if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
+ $switch{'ip'} = $switch{'mgtmt4'};
+ }
+ 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_duplicate'} = \@dups;
+$json{'switches_updated'} = \@dups;
finalize_output();
diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management
index 474f674..a598824 100755
--- a/web/nms.gathering.org/api/private/switches-management
+++ b/web/nms.gathering.org/api/private/switches-management
@@ -12,7 +12,7 @@ use Data::Dumper;
$nms::web::cc{'max-age'} = "60";
-my $q2 = $nms::web::dbh->prepare('select sysname,ip,switchtype,poll_frequency,community,last_updated from switches ');
+my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,last_updated from switches ');
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {