6 use I18N::Langinfo qw'langinfo CODESET';
9 unless ($FEXLIB = $ENV{FEXLIB}) {
11 $FEXLIB = $ENV{FEXHOME}.'/lib';
12 } elsif (-f '/usr/share/fex/lib/fex.ph') {
13 $FEXLIB = '/usr/share/fex/lib';
15 $FEXLIB = dirname(dirname(abs_path($0))).'/lib';
17 $ENV{FEXLIB} = $FEXLIB;
19 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
22 our ($logdir,$spooldir,$debug);
24 # load common code, local config : $HOME/lib/fex.ph
25 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
27 $CTYPE = langinfo(CODESET());
28 binmode(STDOUT,":encoding($CTYPE)");
30 $log = shift || "$logdir/fexsrv.log";
32 $ignore = join('|',qw(
33 (CONNECT|CONTINUE).*(crawl|msnbot|obertux)
34 DISCONNECT:.no.HTTP.request
35 GET.*(favicon|robots\.txt)
36 GET./organization\.gif
39 GET./action-fex-camel\.gif
46 User-Agent:.*(Webnote|FeedFetcher|\w+bot|bot/|Website.Watcher|crawler|spider|searchme|Yandex|Slurp|ScoutJet|findlinks|urlmon|nagios)
48 From:.*(msnbot|yandex|googlebot|webcrawler)
97 if (-t STDIN or $ENV{GATEWAY_INTERFACE}) {
98 open L,$log or die "$0: $log - $!\n";
103 # binmode(L,":encoding(UTF-8)");
107 next if /(^|\n)($ignore)/i;
108 s/[\x00-\x08\x0B-\x1F\x1F\x80-\x9F]/_/g;
110 foreach $weed (@weed) {
111 while (s/\n$weed.*\n/\n/i) {}
113 if (/^\n*(CONNECT|CONTINUE).*\s\[([\d_]+)\]/i) { $pid = $2 }
114 if (/\n(POST|GET)\s+\/(\w+)/i) { $cgi = $2 }
115 if (/Content-Length: (\d+)/i) {
117 while ($d =~ s/(\d)(\d\d\d\b)/$1,$2/) {};
118 s/Content-Length: \d+/Content-Length: $d/i;
123 if (m:\nGET /fup/(\w{40,}):) {
125 printf " FROM=\"%s\"\n\n",$1 if /from=([\w\@.-]+)/;
126 } elsif (m:\nGET /fop/(\w+)/:) {
128 my $ddir = "$spooldir/.dkeys/$dkey";
129 $_ = readlink $ddir or next;
130 (undef,$to,$from) = split('/');
131 printf " FROM=\"%s\"\n",$from;
132 printf " TO=\"%s\"\n",$to;
134 if ($comment = slurp("$ddir/comment")) {
135 printf " COMMENT=\"%s\"\n",decode_utf8($comment,0)||'';
137 if (not -f "$ddir/data" and $_ = slurp("$ddir/error")) {
139 print " ERROR=\"$_\"\n";
141 elsif ($size = -s "$ddir/data") {
142 printf " SIZE=%s MB\n",int($size/1024/1024);
145 } elsif (m:\nGET /fup.*skey=(\w+):) {
151 if ($debug and $pid and $cgi) {
167 @log = `ls -rt $logdir/.debug/*_${pid}.$cgi 2>/dev/null`;
168 if ($log = $log[-1] and open $log,$log) {
169 # binmode($log,":encoding(UTF-8)");
172 if (/^Content-Disposition:.*name="FILE".*filename="(.+)"/i) {
173 print " FILE=\"$1\"\n";
174 } elsif (/^Content-Disposition:.*name="(\w+)"/i) {
179 printf " %s=\"%s\"\n",$p,decode_utf8($v,0)||$v if $v;
180 read_akey($v) if $p eq 'AKEY';
181 read_skey($v) if $p eq 'SKEY';
182 } elsif (/^(Param|Exp): (\w+=".+")/) {
194 my $akey = "$spooldir/.akeys/" . shift;
195 if (my $user = readlink($akey)) {
197 printf " USER=\"%s\"\n",$user;
203 my $skey = "$spooldir/.skeys/" . shift;
204 if (open $skey,$skey) {
206 printf " FROM=\"%s\"\n",$1 if /from=(.+)/;
207 printf " TO=\"%s\"\n",$1 if /to=(.+)/;