#!/usr/bin/perl # mirror.cgi # gets the ip of the calling client, and sends an http request # to that client. This is used to browse the client's local web # server while getting around the client's router, in effect # showing the client how their locally-served site functions # from the outside. # Does not support sending post variables, yet. use LWP::UserAgent; ########## Handle the request and build a reflection request: ##### Get the client address $clientip = $ENV{'REMOTE_ADDR'}; ##### Get the requested URL $req_url = ($ENV{'REDIRECT_URL'}) ? $ENV{'REDIRECT_URL'} : ''; ##### Get rid of the leading directory on the local call $req_url =~ s/^\/mirror//gi; ##### Default to 8080, to bypass ISP's 80-filter $serverport = ":8080"; ##### Build the final URI/URL $geturl = "http://".$clientip.$serverport.$req_url; ########## Create a new user agent $ua = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, timeout => 30 ); ########## Create a new request $request = HTTP::Request->new('GET', $geturl); ########## Get the requested page with the new user agent $resultref = $ua->request($request); ########## Print the results ##### Print the returned headers print $resultref->{'_headers'}->as_string(); ##### Print blank line to end headers and begin document entity print "\n"; ##### And here's the body print $resultref->content; ########## exit; ##########