#!/usr/bin/perl
##########################################################################
## ##
## The Executer ##
## ------------ ##
## by Jimmy (wordx@hotmail.com) ##
## http://www.smartCGIs.com ##
## ##
## This is a free script, if anyone sold it to you please contact me. ##
## Please DO NOT remove any of the copyrights or links to our site, ##
## they keep this CGI free for everyone. Thanks! ##
## ##
## (c) copyright 2000 SmartCGIs.com ##
##########################################################################
##
# This CGI will use the LWP module to grab the html output from any web file (CGI, HTML, etc.)
# on any server and insert it into your own site. If all you want to do is grab the contents of
# a normal (non-executable) file that is on your server, you only need The Includer. Get it free
# at http://www.smartcgis.com . It has less requirements and is faster.
#
# Tag to use:
# ==========
# Execute CGIs (on your server or externally) with a code like this:
#
# With "http://domain.com/test.cgi" being the URL to the file you want to grab.
##
################################
## Edit the following... ##
################################
# Store the html data for later use?
# 1 = Yes
# 0 = No
# If this CGI will be run often for the same url/file it is best to have this on.
# Instead of connecting to the same url it will store the html for the next time it is requested.
$backup = "0";
# If you said yes above, how often should the data be updated (in seconds)?
# 1 minute = 60 seconds
# 1 hour = 3600 seconds
# 1 day = 86400 seconds
# etc...
$bseconds = "60";
# Optional: To keep others from using your CGI to grab content from any site they want,
# you can specify the URLs that are allowed to be grabbed with this CGI:
# (You can only grab files on the following sites...)
@sites = ('livingsounds.org');
# Example: @sites = ('www.smartcgis.com','fr.smartcgis.com','yahoo.com');
################################
## DO NOT edit anything below ##
################################
use LWP::Simple;
print "Content-type: text/html\n\n";
$url = $ENV{'QUERY_STRING'};
if($url eq "") {
print "document.writeln('( Executer Error: No URL provided. )');\n";
exit;
}
if($sites[0] ne "") {
$found = "1";
foreach $site(@sites) {
if($url =~ /$site/i) { $found = "0"; }
}
if($found eq "1") {
print "document.writeln('( Executer Error: $url Not Approved by Admin. )');\n";
exit;
}
}
if($backup eq 1) {
if(! -e "backup") { mkdir("backup", 0777) || print "document.writeln('
( Excluder Error: Could not create directory \"backup\" ($!). )
Powered by SmartCGIs.com');"; }
$time = time;
open(DATA,"lastbackup.txt");
$btime = ;
close(DATA);
if(($time - $btime) > $bseconds) { &deleteold; }
$eurl = &Encrypt($url,smartcgis,asdfhzxcvnmpoiyk);
if(-e "backup/$eurl") {
open(DATA,"backup/$eurl");
@html = ;
close(DATA);
} else {
$html = get($url);
@html = split(/\n/,$html);
open(DATA,">backup/$eurl");
print DATA $html;
close(DATA);
open(DATA,"backup/$eurl");
@html = ;
close(DATA);
}
} else {
$html = get($url);
@html = split(/\n/,$html);
}
if($html =~ /( Executer Error: Does not work with pages that have frames on them, sorry. )');\n";
exit;
}
$count = 0;
foreach $line(@html) {
$count++;
chomp($line);
$line =~ s/\'/\\\'/g;
print "document.writeln('$line');\n";
}
if($count eq 0) {
print "document.writeln('( Executer Error: Unable to grab data from $url )');\n";
}
# I can't stop you from removing this link to us, but I'd appreciate it if you didn't, this is a free script.
# If you do remove, it'd be nice if you put up some other form of link to SmartCGIs.com on your site, thanks!
sub deleteold {
opendir (DIR, "backup");
@files = grep { // } readdir(DIR);
close (DIR);
foreach $file(@files) { unlink("backup/$file"); }
open(DATA,">lastbackup.txt");
print DATA "$time";
close(DATA);
}
sub Encrypt {
my ($source,$key,$pub_key) = @_;
my ($cr,$index,$char,$key_char,$enc_string,$encode,$first,
$second,$let1,$let2,$encrypted,$escapes) = '';
$source = &rot13($source);
$cr = '·¨ ';
$source =~ s/[\n\f]//g;
$source =~ s/[\r]/$cr/g;
while ( length($key) < length($source) ) { $key .= $key }
$key=substr($key,0,length($source));
while ($index < length($source)) {
$char = substr($source,$index,1);
$key_char = substr($key,$index,1);
$enc_string .= chr(ord($char) ^ ord($key_char));
$index++;
}
for (0..255) { $escapes{chr($_)} = sprintf("%2x", $_); }
$index=0;
while ($index < length($enc_string)) {
$char = substr($enc_string,$index,1);
$encode = $escapes{$char};
$first = substr($encode,0,1);
$second = substr($encode,1,1);
$let1=substr($pub_key, hex($first),1);
$let2=substr($pub_key, hex($second),1);
$encrypted .= "$let1$let2";
$index++;
}
return $encrypted;
}
sub Decrypt {
my ($encrypted, $key, $pub_key) = @_;
$encrypted =~ s/[\n\r\t\f]//eg;
my ($cr,$index,$decode,$decode2,$char,$key_char,$dec_string,$decrypted) = '';
while ( length($key) < length($encrypted) ) { $key .= $key }
$key=substr($key,0,length($encrypted));
while ($index < length($encrypted)) {
$decode = sprintf("%1x", index($pub_key, substr($encrypted,$index,1)));
$index++;
$decode2 = sprintf("%1x", index($pub_key, substr($encrypted,$index,1)));
$index++;
$dec_string .= chr(hex("$decode$decode2"));
}
$index=0;
while( $index < length($dec_string) ) {
$char = substr($dec_string,$index,1);
$key_char = substr($key,$index,1);
$decrypted .= chr(ord($char) ^ ord($key_char));
$index++;
}
$cr = '·¨ ';
$decrypted =~ s/$cr/\r/g;
return &rot13( $decrypted );
}
sub rot13{
my $source = shift (@_);
$source =~ tr /[a-m][n-z]/[n-z][a-m]/;
$source =~ tr /[A-M][N-Z]/[N-Z][A-M]/;
$source = reverse($source);
return $source;
}