Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Replace Apache

by zeno (Friar)
on Mar 07, 2003 at 21:46 UTC ( #241276=note: print w/replies, xml ) Need Help??


in reply to Replace Apache

Nicely done. I appreciate your sense of humor. I realize you are joking when you say "replacing apache". Here's my attempt to deobfuscate it.

<SPOILER FOLLOWS>
# Modified a little to get the spacing right # and to use strict. # Some of this code looks like an example from # The Perl Cookbook by Tom Christiansen p.606 use strict; use IO::Socket; # Specify the server home directory, port, # and "page found" status my $home_dir="/tmp/"; my $port=1280; my $response="HTTP/1.1 200 OK\nServer: "; $response .= "PimpHTTPD\nConnection: close\n\n"; my $file_name; # Open a listener server on the port we specified my $server=new IO::Socket::INET->new(Listen=>1, LocalPort=>$port)||die("Can't listen: $!"); # Accept equests from the client while(my $client=$server->accept()) { # Read client requests into scalar while(my $request=<$client>) { # Parse the file name to read in from the # GET request $file_name=$1 if($request=~/^GET\s+(\S+)/i); # Request is finished if there is a blank line last if($request=~/^\r?\s*\r?$/); } # Unescape escaped characters in the file name $file_name=~s/%([0-9A-Fa-f][0-9A-Fa-f])/hex($1)/g; # Ignore requests that try to read from the # parent directory. if($file_name =~ /\.\.\//) { $response="INVALID URL" } else { # It's a good file name-- let's read it. # Open the in file and add it to the response. if(open(INFILE,"<$home_dir$file_name")) { while(<INFILE>) { $response.=$_; } close(INFILE); } else { # If we can't open the file, show the error. $response="$home_dir$file_name:$!" } } # Output the response to the client. print $client $response; # Close the client. $client->close; }
-- Zeno - Barcelona Perl Mongers http://barcelona.pm.org http://www.javamonks.org

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://241276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-05-22 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?