From 11fc373807b9a14ee14499165b00f5e775d11a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 21:49:15 +0100 Subject: which switch an I on script file. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 web/nms.gathering.org/api/private/which-switch-am-i-on (limited to 'web/nms.gathering.org/api/private/which-switch-am-i-on') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on new file mode 100755 index 0000000..4adfb2b --- /dev/null +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -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(); -- cgit v1.2.3 From 6fa911c8565a54c9b56cfae479a92da094990876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 23:53:46 +0100 Subject: which switch: getting IP and printing it. Need to style with html. --- .../api/private/which-switch-am-i-on | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/api/private/which-switch-am-i-on') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on index 4adfb2b..82436ea 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -5,11 +5,26 @@ use lib '../../../../include'; use nms::web; use strict; use warnings; +use Data::Dumper; -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'); +#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 '88.92.5.67' << subnet4"); $query->execute(); -while (my $ref = $query->fetchrow_hashref()) { - push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; + +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 $addr = $ENV{HTTP_X_FORWARDED_FOR} // $ENV{REMOTE_ADDR}; +print "-:" . $addr ."\n"; + + +# add start html: header + body etc. + +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; } -nms::web::finalize_output(); +# add end html -- cgit v1.2.3 From 4dffc5e5431c83595f2bd102f120ad6def011d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Mon, 21 Mar 2016 10:33:25 +0100 Subject: which switch html finished. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api/private/which-switch-am-i-on') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on index 82436ea..0d3f2b4 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -18,13 +18,23 @@ 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 $addr = $ENV{HTTP_X_FORWARDED_FOR} // $ENV{REMOTE_ADDR}; -print "-:" . $addr ."\n"; - # add start html: header + body etc. +print " + + +"; + +# print address +print "" . $addr ."
"; +# print switch name and distroname. while ( my $ref = $query->fetchrow_hashref() ) { print $ref->{sysname}. " @ " . $ref->{distro}; } # add end html +print " + + +"; -- cgit v1.2.3