Fixed remote IP detection.
authorshort <>
Fri, 26 Sep 2003 20:44:36 +0000 (20:44 +0000)
committershort <>
Fri, 26 Sep 2003 20:44:36 +0000 (20:44 +0000)
Web.pm

diff --git a/Web.pm b/Web.pm
index 7eacfa0..f6c9a79 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -280,9 +280,22 @@ my($url,$contents,%args)=@_;
        return $r;
 }
 
+sub remote_ip ()
+{
+       # Do not: PerlModule                 Apache::ForwardedFor
+       #         PerlPostReadRequestHandler Apache::ForwardedFor
+       # As 'Apache::ForwardedFor' takes the first of $ENV{"HTTP_X_FORWARDED_FOR"}
+       # while the contents is '127.0.0.1, 213.220.195.171' if client has its own proxy.
+       # We must take the last item ourselves.
+       my $r=$ENV{"HTTP_X_FORWARDED_FOR"};
+       $r=~s/^.*,\s*//;
+       return $r;
+}
+
 sub is_cz ()
 {
-       return "CZ" eq Geo::IP->new()->country_code_by_addr($W->{"r"}->get_remote_host());
+print STDERR "IP=".remote_ip()."\n";
+       return "CZ" eq Geo::IP->new()->country_code_by_addr(remote_ip());
 }
 
 sub a_href_cz ($$;%)