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 $!;
}
+ unlink $fifo;
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 {
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;
sub sigexit {
my ($sig) = @_;
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;