5 use I18N::Langinfo qw'langinfo CODESET';
8 unless ($FEXLIB = $ENV{FEXLIB}) {
10 $FEXLIB = $ENV{FEXHOME}.'/lib';
11 } elsif (-f '/usr/share/fex/lib/fex.ph') {
12 $FEXLIB = '/usr/share/fex/lib';
14 $FEXLIB = dirname(dirname(abs_path($0))).'/lib';
16 $ENV{FEXLIB} = $FEXLIB;
18 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
21 our (@logdir,$spooldir,$debug);
23 # load common code, local config : $HOME/lib/fex.ph
24 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
26 $CTYPE = langinfo(CODESET());
27 binmode(STDOUT,":encoding($CTYPE)");
29 $log = shift || $logdir[0].'/fexsrv.log';
31 $ignore = join('|',qw(
32 (CONNECT|CONTINUE).*(crawl|msnbot|obertux)
33 DISCONNECT:.no.HTTP.request
34 GET.*(favicon|robots\.txt)
35 GET./organization\.gif
38 GET./action-fex-camel\.gif
44 GET./browserconfig\.xml
45 User-Agent:.*(Webnote|FeedFetcher|\w+bot|bot/|Website.Watcher|crawler|spider|searchme|Yandex|Slurp|ScoutJet|findlinks|urlmon|nagios)
47 User-Agent:.Google.favicon
48 From:.*(msnbot|yandex|googlebot|webcrawler)
68 Upgrade-Insecure-Requests:
105 if (-t STDIN or $ENV{GATEWAY_INTERFACE}) {
106 open L,$log or die "$0: $log - $!\n";
111 # binmode(L,":encoding(UTF-8)");
115 next if /(^|\n)($ignore)/i;
116 s/[\x00-\x08\x0B-\x1F\x1F\x80-\x9F]/_/g;
118 foreach $weed (@weed) {
119 while (s/\n$weed.*\n/\n/i) {}
122 if (/^\n*(CONNECT|CONTINUE).*\s\[([\d_]+)\]/i) { $pid = $2 }
123 if (/\n(POST|GET)\s+(\S+)/i) {
128 if (/Content-Length: (\d+)/i) {
130 while ($d =~ s/(\d)(\d\d\d\b)/$1,$2/) {};
131 s/Content-Length: \d+/Content-Length: $d/i;
136 if (m:\nGET /fup/(\w{40,}):) {
138 printf " FROM=\"%s\"\n\n",$1 if /from=([\w\@.-]+)/;
139 } elsif (m:\nGET /fop/(\w+)/:) {
141 my $ddir = "$spooldir/.dkeys/$dkey";
142 $_ = readlink $ddir or next;
143 (undef,$to,$from) = split('/');
144 printf " FROM=\"%s\"\n",$from;
145 printf " TO=\"%s\"\n",$to;
147 if ($comment = slurp("$ddir/comment")) {
148 printf " COMMENT=\"%s\"\n",utf8decode($comment)||'';
150 if (not -f "$ddir/data" and $_ = slurp("$ddir/error")) {
152 print " ERROR=\"$_\"\n";
154 elsif ($size = -s "$ddir/data") {
155 printf " SIZE=%s MB\n",int($size/1024/1024);
158 } elsif (m:\nGET /fup.*skey=(\w+):) {
162 if ($debug and $pid and $post) {
175 # https://rt.cpan.org/Public/Bug/Display.html?id=88592
182 @log = `ls -rt $logdir[0]/.debug/*_${pid}.$cgi 2>/dev/null`;
183 if ($log = $log[-1] and open $log,$log) {
184 binmode($log,":utf8");
187 s/[^\x09\x20-\xFF]/_/g;
188 if (/^Content-Disposition:.*name="FILE".*filename="(.+)"/i) {
189 print " FILE=\"$1\"\n";
190 } elsif (/^Content-Disposition:.*name="(\w+)"/i) {
196 my $vv = utf8decode($v)||$v;
197 $vv =~ s/[\x00-\x1F]/_/g;
198 $vv =~ s/[\x80-\x9F]/_/g;
199 printf " %s=\"%s\"\n",$p,$vv;
200 read_akey($v) if $p eq 'AKEY';
201 read_skey($v) if $p eq 'SKEY';
203 } elsif (/^(Param|Exp): (\w+=".+")/) {
215 my $akey = "$spooldir/.akeys/" . shift;
216 if (my $user = readlink($akey)) {
218 printf " USER=\"%s\"\n",$user;
224 my $skey = "$spooldir/.skeys/" . shift;
225 if (open $skey,$skey) {
227 printf " FROM=\"%s\"\n",$1 if /from=(.+)/;
228 printf " TO=\"%s\"\n",$1 if /to=(.+)/;
237 s/([\xC0-\xDF])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg;