diff options
author | Magnus Kirø <magnuskiro@gmail.com> | 2016-03-20 23:53:46 +0100 |
---|---|---|
committer | Magnus Kirø <magnuskiro@gmail.com> | 2016-03-20 23:53:46 +0100 |
commit | 6fa911c8565a54c9b56cfae479a92da094990876 (patch) | |
tree | ff393dcc62edc490201db7c38df6ae1a8b31fc95 | |
parent | 11fc373807b9a14ee14499165b00f5e775d11a59 (diff) |
which switch: getting IP and printing it. Need to style with html.
-rwxr-xr-x | web/nms.gathering.org/api/private/which-switch-am-i-on | 23 |
1 files changed, 19 insertions, 4 deletions
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 |