| The Small Problem and The Solution
Thanks for reading this and even considering helping me out!
Currently, ResExcellence is spread across two servers.
http://www.ResExcellence.com holds all the text, and http://207.208.148.74/ serves the images and User Contributions.
Several of the items on the main page are inserted using the Apache #include command that automatically reads and displays the selected text file. This works great as long as all the text files are on the main server, but I want to put some text files on other server, and #include won't work across a network.
I beleive it's possible to execute a short perl script that would read the text file from the remote server, and insert it into the html on the main server. The syntax would look like this:
Remote text file on (http://207.208.148.74/):
Main server html (http://www.ResExcellence.com):
The outputed page to the browser would read:
Any help you can offer would be greatly appreciated.
The Solution by Colter Reed.
This perl script works like a #include virtual, but for files on a remote server. The syntax is:
#exec cmd="/path/to/cgi-bin/remote_text.cgi /text_file.txt"
The phrase "/text_file.txt" is the file to be included. This is not a path to the file, but the location in URL format. The entire script is below.
#!/usr/bin/perl
#
# Written and Copyright by Colter Reed
# http://w3.uwyo.edu/~coltreed/
# mailto:c.reed@computer.org
# Version 1.1
#
# CONFIGURATION:
# Enter the IP address of the remote server
$host = "xxx.xxx.xxx.xxx" ;
# That's it. All configured!
# Call the script with the following:
# <!--#exec cmd="/path/to/cgi-bin/remote_text.cgi /text_file.txt"-->
######################################################################
use IO::Socket;
# We need one argument
unless (@ARGV == 1) { die "usage: $0 document" }
$document = shift ; # Document is the first command-line argument
$EOL = "\015\012"; # Formal net language. It's a multi-platform thing
$BLANK = $EOL x 2 ;
# Establish a tcp connection to $host's port 80
$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => "http(80)",
);
# Make sure we're talking to the host, not the Ether
unless ($remote) { die "cannot connect to http daemon on $host" }
$remote->autoflush(1); # I'm not sure what this does...
print $remote "GET $document HTTP/1.0" . $BLANK ; # Request the document
# Check for an appropriate response code
# The response code will be of the format:
#
# HTTP/1.x XXX blahblah
#
# We're interested in the XXX. This is the HTTP result code:
# 200 OK
# 302 Not changed since the last time you looked at it
# 403 Permission denied
# 404 Not found
$status = substr(<$remote>,9,3);
unless ( $status eq "200") {print "[Remote error: $status]\n";exit(1)} ;
# Skip the rest of the response header
while ( length( <$remote> ) > 2 ) {}
# Now we're to the main content
while ( $line = <$remote> ) { # While there are lines left
print $line ; # Pass along the rest
}
close $remote; # Be nice; tell the server you're done
################################################################
This script by Philip Gabbert from GPsMac requires that you have access to the Perl/LPW and Perl/HTTP libraries on your ISP's server.. My ISP did not them installed, but after a quik email, they were up and running the next day.
Invoke the script with the following html:
#!/usr/bin/perl
use LWP::Simple;
use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$redirect = "http://www.yoursite" . $ENV{'PATH_INFO'};
$request = new HTTP::Request('GET', $redirect);
$response = $ua->request($request);
print "Content-type: text/html\n\n";
if ($response->is_success)
{ print $response->content; }
else { print $response->error_as_HTML; }
#################################################################
|