X-Git-Url: http://git.treefish.org/fex.git/blobdiff_plain/e60096926213ce02293a261254ff065cae44c1c8..3aae246cf7f4af7ae49da09e5ed0c180f31f0c12:/cgi-bin/sex?ds=inline diff --git a/cgi-bin/sex b/cgi-bin/sex index 62a914a..c8f28ce 100755 --- a/cgi-bin/sex +++ b/cgi-bin/sex @@ -72,24 +72,24 @@ if ($mode eq 'PUSH') { 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; @@ -98,13 +98,13 @@ if ($mode eq 'PUSH') { 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; @@ -120,7 +120,7 @@ if ($mode eq 'PUSH') { } 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; } @@ -135,13 +135,14 @@ elsif ($mode eq 'POP') { alarm(0); header('200 OK',$type); sexlog($mode); - + while (sysread($fifo,$_,$bs)) { syswrite STDOUT,$_ or die $!; } + unlink $fifo; exit; - -} + +} else { error(405,"Unknown Request"); } @@ -151,28 +152,28 @@ exit; 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; @@ -192,12 +193,12 @@ sub sigdie { 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;