use lib qw(/home/short/lib/perl5/site_perl/5.6.0/i386-linux /home/short/lib/perl5/site_perl/5.6.0 /home/short/lib/perl5/site_perl/i386-linux /home/short/lib/perl5/site_perl /home/short/lib/perl5/5.6.0/i386-linux /home/short/lib/perl5/5.6.0 /home/short/lib/perl5/i386-linux /home/short/lib/perl5);
use Exporter;
-our @EXPORT=qw(&require &a_href &a_href_cz &vskip &img);
+our @EXPORT=qw(&require &a_href &a_href_cz &vskip &img $W);
our @ISA=qw(Exporter);
use WebConfig; # for %WebConfig
use URI::Escape;
require HTTP::BrowserDetect;
require HTTP::Negotiate;
+require Geo::IP;
# Undo 'www/engine/httpd-restart' as it may use obsolete Perl for 'mod_perl'
delete $ENV{"LD_LIBRARY_PATH"};
-my $W;
+our $W;
# $W->{"title"}
# $W->{"head"}
# $W->{"head_css"}
my $urlent=CGI::escapeHTML($url);
if ($url eq $urlent)
{ $r.=$url; }
- elsif ($url!~m#^[a-z]+://#) # $url is our resource
+ elsif (url_is_local $url)
{ $r.=$urlent; }
elsif (defined $W->{"have_ent"} && !$W->{"have_ent"}) # non-ent client
{ $r.=$url; }
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"} || $W->{"r"}->remote_host();
+ $r=~s/^.*,\s*//;
+ return $r;
+}
+
sub is_cz ()
{
- return $W->{"r"}->get_remote_host()=~/[.]cz$/i;
+print STDERR "IP=".remote_ip()."\n";
+ return "CZ" eq Geo::IP->new()->country_code_by_addr(remote_ip());
}
sub a_href_cz ($$;%)