X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/97b87610331f53e756d032ad21db786037f921a1..e5c93609849bda051fff54b5d5265af5608c6c69:/cgi-bin/sex?ds=sidebyside diff --git a/cgi-bin/sex b/cgi-bin/sex index 62a914a..ab7abc8 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,13 @@ elsif ($mode eq 'POP') { alarm(0); header('200 OK',$type); sexlog($mode); - + while (sysread($fifo,$_,$bs)) { syswrite STDOUT,$_ or die $!; } exit; - -} + +} else { error(405,"Unknown Request"); } @@ -151,28 +151,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 +192,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;