aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly@.no>2016-03-23 01:48:48 +0100
committerKristian Lyngstol <kly@kly@.no>2016-03-23 01:48:48 +0100
commita1fa26ad5b0e2ca68265b4b875169db130af61e2 (patch)
treeffbf38709aee9973036e867ba1d18b49e5c0dcee
parent20c3bd1289c518768eb66a8245ac616ee3c43a07 (diff)
NMS: Move which-switch-am-i-on
-rwxr-xr-xweb/nms.gathering.org/api/public/which-switch-am-i-on (renamed from web/nms.gathering.org/api/read/which-switch-am-i-on)10
1 files changed, 7 insertions, 3 deletions
diff --git a/web/nms.gathering.org/api/read/which-switch-am-i-on b/web/nms.gathering.org/api/public/which-switch-am-i-on
index 0d3f2b4..6c25ab9 100755
--- a/web/nms.gathering.org/api/read/which-switch-am-i-on
+++ b/web/nms.gathering.org/api/public/which-switch-am-i-on
@@ -8,8 +8,7 @@ use warnings;
use Data::Dumper;
#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();
+my $query = $nms::web::dbh->prepare("select * from switches where ? << subnet4");
print "Cache-Control: max-age=0";
print "Content-Type: text/html";
@@ -17,7 +16,11 @@ 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};
+
+my @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR});
+my $addr = $xff[0] // $ENV{REMOTE_ADDR};
+
+$query->execute($addr);
# add start html: header + body etc.
print "
@@ -31,6 +34,7 @@ print "" . $addr ."<br \>";
# print switch name and distroname.
while ( my $ref = $query->fetchrow_hashref() ) {
print $ref->{sysname}. " @ " . $ref->{distro};
+ print "<br />";
}
# add end html