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-add20
-rwxr-xr-xweb/nms.gathering.org/api/private/comment-change20
-rwxr-xr-xweb/nms.gathering.org/api/private/comments15
-rwxr-xr-xweb/nms.gathering.org/api/private/port-state31
-rwxr-xr-xweb/nms.gathering.org/api/private/switch-add44
5 files changed, 130 insertions, 0 deletions
diff --git a/web/nms.gathering.org/api/private/comment-add b/web/nms.gathering.org/api/private/comment-add
new file mode 100755
index 0000000..beb7b21
--- /dev/null
+++ b/web/nms.gathering.org/api/private/comment-add
@@ -0,0 +1,20 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+use lib '../../../../include';
+use utf8;
+use nms::web;
+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 $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();
+
+$nms::web::cc{'max-age'} = '0';
+$nms::web::cc{'stale-while-revalidate'} = '0';
+$nms::web::json{'state'} = 'ok';
+
+finalize_output();
diff --git a/web/nms.gathering.org/api/private/comment-change b/web/nms.gathering.org/api/private/comment-change
new file mode 100755
index 0000000..ccf336d
--- /dev/null
+++ b/web/nms.gathering.org/api/private/comment-change
@@ -0,0 +1,20 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+use lib '../../../../include';
+use utf8;
+use nms;
+use nms::web;
+use strict;
+use warnings;
+
+my $id = db_safe_quote('comment');
+my $state = db_safe_quote('state');
+
+my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";");
+$q->execute();
+
+$nms::web::cc{'max-age'} = '0';
+$nms::web::cc{'stale-while-revalidate'} = '0';
+$nms::web::json{'state'} = 'ok';
+
+finalize_output();
diff --git a/web/nms.gathering.org/api/private/comments b/web/nms.gathering.org/api/private/comments
new file mode 100755
index 0000000..4adfb2b
--- /dev/null
+++ b/web/nms.gathering.org/api/private/comments
@@ -0,0 +1,15 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '../../../../include';
+use nms::web;
+use strict;
+use warnings;
+
+my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc');
+$query->execute();
+while (my $ref = $query->fetchrow_hashref()) {
+ push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref;
+}
+
+nms::web::finalize_output();
diff --git a/web/nms.gathering.org/api/private/port-state b/web/nms.gathering.org/api/private/port-state
new file mode 100755
index 0000000..6410805
--- /dev/null
+++ b/web/nms.gathering.org/api/private/port-state
@@ -0,0 +1,31 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '../../../../include';
+use nms::web;
+use strict;
+use warnings;
+
+my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, '.$nms::web::ifname.',ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $nms::web::when . ' group by switch,ifname);';
+my $q = $nms::web::dbh->prepare($query);
+$q->execute();
+
+while (my $ref = $q->fetchrow_hashref()) {
+ my @fields = ('ifhighspeed','ifhcoutoctets','ifhcinoctets');
+ foreach my $val (@fields) {
+ $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{$val} = $ref->{$val};
+ }
+ $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{'time'} = $ref->{'time'};
+}
+
+my $q3 = $nms::web::dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $nms::web::when . ' order by switch,time desc');
+
+
+$q3->execute();
+while (my $ref = $q3->fetchrow_hashref()) {
+ my $sysname = $ref->{'sysname'};
+ $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'};
+ $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp_time'} = $ref->{'time'};
+}
+
+finalize_output();
diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add
new file mode 100755
index 0000000..1dc331f
--- /dev/null
+++ b/web/nms.gathering.org/api/private/switch-add
@@ -0,0 +1,44 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+#use CGI qw(fatalsToBrowser);
+use DBI;
+use lib '../../../../include';
+use nms;
+use nms::web qw(%get_params %json finalize_output get_input);
+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 sysname FROM switches WHERE sysname=?");
+my $insert = $nms::web::dbh->prepare("INSERT INTO SWITCHES (ip, sysname, switchtype) VALUES(?,?,'ex2200');");
+
+foreach my $tmp2 (@tmp) {
+ my %switch = %{$tmp2};
+ my $affected = 0;
+
+ $sth->execute( $switch{'sysname'});
+ while ( my @row = $sth->fetchrow_array ) {
+ $affected += 1;
+ }
+
+ if ($affected == 0) {
+ $insert->execute($switch{'mgtmt4'}, $switch{'sysname'});
+ push @added, $switch{'sysname'};
+ } else {
+ push @dups, $switch{'sysname'};
+ }
+}
+$json{'switches_addded'} = \@added;
+$json{'switches_duplicate'} = \@dups;
+
+finalize_output();