$| = 1;
# import from fex.pp
-our ($tmpdir,$logdir,$timeout,$fra,$bs);
+our ($tmpdir,@logdir,$timeout,$fra,$bs);
# load common code, local config: $HOME/lib/fex.ph
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
chdir $spooldir or error(500,"$spooldir - $!");
-my $debuglog = "$tmpdir/sex.log";
+# my $debuglog = "$tmpdir/sex.log";
my $ra = $ENV{REMOTE_ADDR}||0;
$fra .= '/'.$ENV{HTTP_X_FORWARDED_FOR} if $ENV{HTTP_X_FORWARDED_FOR};
$timeout *= 10;
my $lock = "$stream/lock";
open $lock,'>>',$lock or error(503,"Cannot open $lock : $!");
flock $lock,LOCK_EX|LOCK_NB or error(409,"$stream already in use");
-
+
chmod 0600,$fifo;
unlink "$stream/mode";
unlink "$stream/type";
symlink $pmode,"$stream/mode" if $pmode;
symlink $type, "$stream/type" if $type;
- $SIG{PIPE} = sub {
- sleep 1;
- rmrf($stream);
- exit;
+ $SIG{PIPE} = sub {
+ sleep 1;
+ rmrf($stream);
+ exit;
};
- $SIG{ALRM} = sub {
- syswrite STDOUT,".";
- exit if $!;
- $ALARM = 1;
+ $SIG{ALRM} = sub {
+ syswrite STDOUT,".";
+ exit if $!;
+ $ALARM = 1;
};
- syswrite STDOUT,"HTTP/1.9 199 Hold on";
+ syswrite STDOUT,"HTTP/1.9 199 Hold on";
for (my $i=0;$i<$timeout;$i++) {
alarm(1);
$ALARM = 0;
unless ($ALARM) { error(503,"Cannot open $fifo : $!") }
}
alarm(0);
- syswrite STDOUT,"\r\n";
-
- unless (fileno $fifo) {
+ syswrite STDOUT,"\r\n";
+
+ unless (fileno $fifo) {
rmrf($stream);
error(504,"Timeout");
}
-
+
header('200 OK');
$B = 0;
}
elsif ($mode eq 'POP') {
$stream =~ s:/STDSTR:/PUBLIC: if $id eq 'public';
- unless ($id eq 'public' and (readlink "$stream/mode"||'') eq 'PUBLIC'
+ unless ($id eq 'public' and (readlink "$stream/mode"||'') eq 'PUBLIC'
or $user =~ /^anonymous/) {
&authentificate;
}
alarm(0);
header('200 OK',$type);
sexlog($mode);
-
+
while (sysread($fifo,$_,$bs)) {
syswrite STDOUT,$_ or die $!;
}
exit;
-
-}
+
+}
else {
error(405,"Unknown Request");
}
sub setparam {
my ($v,$vv) = @_;
-
+
$v = uc(despace($v));
$vv = untaint(normalize($vv));
# $param{$v} = $vv;
- if ($v eq 'USER') { $user = lc(despace($vv)) }
- elsif ($v eq 'ID') { $id = despace($vv) }
- elsif ($v eq 'MODE') { $pmode = uc(despace($vv)) }
- elsif ($v eq 'TYPE') { $type = uc(despace($vv)) }
+ if ($v eq 'USER') { $user = lc(despace($vv)) }
+ elsif ($v eq 'ID') { $id = despace($vv) }
+ elsif ($v eq 'MODE') { $pmode = uc(despace($vv)) }
+ elsif ($v eq 'TYPE') { $type = uc(despace($vv)) }
elsif ($v eq 'STREAM') { $stream = normalize_filename($vv) }
- elsif ($v eq 'BS' and $vv =~ /(\d+)/) { $bs = $1 }
+ elsif ($v eq 'BS' and $vv =~ /(\d+)/) { $bs = $1 }
elsif ($v eq 'TIMEOUT' and $vv =~ /(\d+)/) { $timeout = $1 }
elsif ($v eq 'ANONYMOUS') { $id = $user ='anonymous'; $stream = $vv; }
}
sub sexlog {
- if (open my $log,'>>',"$logdir/sex.log") {
- flock $log,LOCK_EX;
- seek $log,0,SEEK_END;
- printf {$log} "%s [%s_%s] %s (%s) %s\n",
- isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,"@_";
- close $log;
+ my $msg = "@_";
+
+ $msg =~ s/\n/ /g;
+ $msg =~ s/\s+$//;
+ $msg = sprintf "%s [%s_%s] %s (%s) %s\n",
+ isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,$msg;
+
+ foreach my $log (@logdir) {
+ if (open $log,'>>',"$log/sex.log") {
+ flock $log,LOCK_EX;
+ seek $log,0,SEEK_END;
+ printf {$log} $msg;
+ close $log;
+ }
}
}
sub sigexit {
my ($sig) = @_;
- if (open my $log,'>>',"$logdir/sex.log") {
- printf {$log} "%s %s (%s) caught SIGNAL %s\n",
- isodate(time),$user||'-',$fra||'-',"@_";
- close $log;
+ my $msg = "@_";
+
+ $msg =~ s/\n/ /g;
+ $msg =~ s/\s+$//;
+ $msg = sprintf "%s %s (%s) caught SIGNAL %s\n",
+ isodate(time),$user||'-',$fra||'-',$msg;
+
+ foreach my $log (@logdir) {
+ if (open $log,'>>',"$log/sex.log") {
+ flock $log,LOCK_EX;
+ seek $log,0,SEEK_END;
+ printf {$log} $msg;
+ close $log;
+ }
}
if ($sig eq 'DIE') {
shift;