#!/usr/bin/perl # yuno6.pl - Don Yang (uguu.org) # # 07/31/05 use Socket; use CGI ':standard'; $O = (shift || 80); die $! unless socket(Y, PF_INET, SOCK_STREAM, getprotobyname('tcp')) && bind(Y, sockaddr_in($O, INADDR_ANY)) && listen(Y, 5) && pipe(N, U); binmode Y; binmode N; binmode U; $x = $Y = ''; vec($Y, fileno(Y), 1) = 1; vec($Y, fileno(N), 1) = 1; print "listening on $O\n"; while( select($O = $Y, undef, undef, undef) ) { if( vec($O, fileno(Y), 1) ) { accept O, Y; if( fork ) { close O; } else { close N; binmode O; $N = ''; while( defined(recv O, $O, 1024, 0) ) { $N .= $O; if( ($Y = index($N, "\r\n\r\n")) > 0 ) { $Y += 4; last; } if( ($Y = index($N, "\n\n")) > 0 ) { $Y += 2; last; } } if( $N =~ /^POST / ) { $U = (($N =~ /content-length:\s*(\d+)/i) ? $1 : 0x20000) + $Y - length $N; while( $U > 0 && defined(recv O, $O, $U, 0) ) { $N .= $O; $U -= length $O; } $Y = new CGI(substr $N, $Y); $U = $Y->param('x'); if( $Y->param('f') ne 'reload' ) { $U =~ s/\r\n/\n/g; if( $Y->param('f') ne 'raw' ) { $U =~ s/&/&/g; $U =~ s//>/g; if( $Y->param('f') eq 'post' ) { $U =~ s/\n/
/g; } else { $U = "
\n$U
"; } } $U .= '

' . (scalar localtime); $x = "\n


\n$U$x"; $U = (pack 'I', length $U) . $U; print U $U; } } $N = 'Yuno' . '' . '
' . '


' . '' . '' . '' . '' . "

$x\n"; send O, "HTTP/1.0 200 OK\r\n" . "Content-Type: text/html\r\n" . "Server: Yuno\r\n" . "Connection: close\r\n" . "Content-Length: " . length($N) . "\r\n\r\n" . $N, 0; close O; close U; exit; } } if( vec($O, fileno(N), 1) ) { $N = ''; if( read(N, $O, length(pack 'I', 0), 0) ) { $U = unpack 'I', $O; while( read(N, $O, $U, 0) ) { $N .= $O; last if ($U -= length $O) <= 0; } $x = "\n
\n$N$x"; } } } die $!;