# stunnel workaround
$SIG{CHLD} = "DEFAULT";
$ENV{PERLINIT} = q{
+ $ENV{LC_ALL} = 'en_US.UTF-8';
unshift @INC,(getpwuid($<))[7].'/perl';
# web error handler
$SIG{__DIE__} = $SIG{__WARN__} = sub {
# import from fex.pp
our ($hostname,$debug,$timeout,$max_error,$max_error_handler);
our ($spooldir,@logdir,$docdir,$xkeydir,$akeydir,$lockdir);
-our ($force_https,$default_locale,$bs,$MB,$adlm);
+our ($force_https,$default_locale,$bs,$MB,$adlm,@forbidden_user_agents);
our (@locales);
# load common code (local config: $FEXHOME/lib/fex.ph)
if ($ssl_ra) {
$ENV{PROTO} = 'https';
$ENV{REMOTE_ADDR} = $ra = $ssl_ra;
- if ($ssl_ra =~ /\w:\w/) {
+ if ($ssl_ra =~ /[\w:]:\w/) {
# ($rh) = `host $ssl_ra 2>/dev/null` =~ /name pointer (.+)\.$/;
$^W = 0; eval 'use Socket6'; $^W = 1;
http_error(503) if $@;
# reverse-proxy?
# (only IPv4 support!)
if ($reverse_proxy_ip and $reverse_proxy_ip eq $ra and
- /^\S*(Forwarded|Client-IP|Coming-From)\S*: ([\d.]+)/i
+ /^\S*(Forwarded|Client-IP|Coming-From)\S*: ([\da-f:.]+)/i
) {
$ENV{REMOTE_ADDR} = $ra = $2;
$ENV{REMOTE_HOST} = $rh = gethostbyaddr(inet_aton($ra),AF_INET) || '';
if ($uri =~ /\\|%5c/i) { badchar("\\") }
}
+ my $fua = join('|',@forbidden_user_agents);
+
while ($_ = shift @header) {
# header inquisition!
exit;
}
- if ($header =~ /\nRange:/ and /^User-Agent: (FDM)/) {
- disconnect($1,"499 Download Manager $1 Not Supported",30);
- }
-
- if (/^User-Agent: (Java\/[\d\.]+)/) {
- disconnect($1,"499 User-Agent $1 Not Supported",30);
+ if ($fua and /^User-Agent: ($fua)/) {
+ disconnect($1,"499 User Agent $1 Not Supported",30);
}
if (/^Range:.*,/) {
}
# HTTP header ==> environment variables
- if (/^([\w\-]+):\s*(.+)/s) {
+ if (/^([\w\-_]+):\s*(.+)/s) {
$http_var = $1;
$http_val = $2;
$http_var =~ s/-/_/g;
} else {
$http_val =~ s/\s+/ /g;
if ($http_var =~ /^HTTP_(HOST|VERSION)$/) {
- $http_var = 'X-'.$http_var;
+ $http_var = 'HTTP_X_'.$1;
+ } elsif ($http_var =~ /^PROXY/) {
+ # http://cert.at/warnings/all/20160718.html
+ $http_var = 'HTTP_X_'.$http_var;
} elsif ($http_var !~ /^CONTENT_/) {
$http_var = 'HTTP_'.$http_var;
}
'</body></html>'
));
}
+ fexlog($connect,@log,"REDIRECT $newurl");
if ($rr =~ /^http/) {
exit;
} else {