Forum Moderators: coopster & phranque

Message Too Old, No Replies

CGI to slow bandwith use

Where to edit ,,,,,,,,,

         

CaptainKarl

1:06 am on Dec 27, 2001 (gmt 0)



[perl]
#!/usr/bin/perl
#############################################
# Anti-leech script by Filer from confine.com
#
# Confine.com Programming Team
#############################################
## Edit The Following Variables
# Exact location to your data directory.
# Note: The location does not mean your url.
$datadir = "/data/location/to/the/antileech/file";

# The full URL to antileech.cgi.
$cgi_url = "http://www.yourdomain.com/cgi-bin/antileech.cgi";

# The URL to your website.
$homepage = "http://www.yourdomain.com";

# The title of your website.
$homepagename = "Your Title";

# The password you want to use.
$password = "password";

# Log unauthorized referrers? Y or N
$log = "n";

# The url you want to send unauthorized referrers to. Leave blank to use cgi default.
$bad_url = "";
## End Of Editing
#############################################

#############################################
# Getting the tags off of the URL.
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
($temp, $password2) = split(/=/, $pairs[0]);
($temp, $command) = split(/=/, $pairs[1]);
($temp, @info1) = split(/=/, $pairs[2]);
($temp, @info2) = split(/=/, $pairs[3]);
if ($password2 eq $password) {
if ($command eq "login") { &menu2; }
if ($command eq "save") { &save; }
}
if ($password2) {
&passerror;
}
else {
if ($ENV{'QUERY_STRING'} eq 'help') { &help; }
if (!$ENV{'QUERY_STRING'}) { &menu; }
}
# End of tag getting.
#############################################

#############################################
# Getting the refferer.
$refferer = $ENV{'HTTP_REFERER'};
# Finished getting the refferer.
#############################################

#############################################
# Filtering out the stupid stuff.
$refferer =~ tr/[A-Z]/[a-z]/;
# Finished filtering the stupid stuff.
#############################################

#############################################
# Checking to see if URL has access.
open("data","$datadir/data.dat") ¦¦ &dataerror;
@data = <data>;
close("data");
foreach $i (@data) {
$i =~ s/\s+$//;
$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$refferer =~ s/\s+$//;
$refferer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if (substr($i,0,1) eq '!') { if ($refferer eq $i) { &sendfile; } }
else { if ($refferer =~ m"$i") { &sendfile; } }
}
&antileech;
# End of checking.
#############################################

#############################################
# Find and send file.
sub sendfile {
open("list","$datadir/list.dat") ¦¦ &listerror;
@list = <list>;
close("list");
foreach $i (@list) {
$_ =~ s/\s+$//;
$_ =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
($name, $location) = split(/\¦/, $i);
if ($name eq $ENV{'QUERY_STRING'}) { print "Location: $location\n\n"; }
}
print "Content-type: text/html\n\n";
print "Could not find the desired file.";
exit;
}
# End of find and send.
#############################################

#############################################
# Antileech
sub antileech {
if (($log eq 'y') ¦¦ ($log eq 'Y')) {
open("log", ">>$datadir/antileech.log");
print log "$refferer\n";
close("log");
}
if ($bad_url) { print "Location: $bad_url\n\n"; }
print "Content-type: text/html\n\n";
print "<HTML><BODY>\n";
print "<CENTER>ANTILEECH!</CENTER>\n";
print "<CENTER><A HREF=$homepage>$homepagename</A></CENTER>\n";
print "</BODY></HTML>\n";
exit;
}
# End of antileech
#############################################

#############################################
# The main menu.
sub menu {
print "Content-type: text/html\n\n";
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR>\n";
print "<CENTER>Password:</CENTER><BR>\n";
print "<CENTER><FORM METHOD=POST ACTION=$cgi_url><INPUT TYPE=PASSWORD NAME=password><INPUT TYPE=HIDDEN NAME=COMMAND VALUE=login> <INPUT TYPE=SUBMIT VALUE=Enter></FORM></CENTER>\n";
print "</BODY></HTML>\n";
exit;
}
# End of main menu.
#############################################
# The main menu 2. (Real menu)
sub menu2 {
print "Content-type: text/html\n\n";
open(data,"$datadir/data.dat") ¦¦ &dataerror;
@data = <data>;
close(data);
open(list,"$datadir/list.dat") ¦¦ &listerror;
@list = <list>;
close(list);
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR>\n";
print "<CENTER><FORM METHOD=\"POST\" ACTION=\"$cgi_url\">\n";
print "<TABLE BORDER=1 CELLBORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=500 ALIGN=CENTER>\n";
print "<TR><TH BGCOLOR=\"#808080\">Password</TH></TR>\n";
print "<TR><TD><INPUT TYPE=PASSWORD NAME=password><INPUT TYPE=HIDDEN NAME=command VALUE=save> </TD></TR>\n";
print "<TR><TH BGCOLOR=\"#808080\">Allowed URLs</TH></TR>\n";
print "<TR><TD><TEXTAREA COLS=80 ROWS=20 NAME=data>\n";
foreach $i (@data) {
$i =~ s/\s+$//;
print "$i\n";
}
print "</TEXTAREA></TD></TR>\n";
print "<TR><TH BGCOLOR=\"#808080\">Antileech Files</TH></TR>\n";
print "<TR><TD><TEXTAREA COLS=80 ROWS=20 NAME=list>\n";
foreach $i (@list) {
$i =~ s/\s+$//;
print "$i\n";
}
print "</TEXTAREA></TD></TR>\n";
print "<TR><TD><INPUT TYPE=SUBMIT VALUE=Save><INPUT TYPE=RESET VALUE=Reset></FORM></TD></TR></TABLE>\n";
print "<BR><CENTER><A HREF=\"$cgi_url?help\">Antileech Help</A></CENTER>\n";
print "</BODY></HTML>\n";
exit;
}
# End of main menu 2.
############################################

############################################
# Saving information
sub save {
print "Content-type: text/html\n\n";
foreach $i (@info1) {
$i =~ tr/+/ /;
$i =~ s/ //;
$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ s/\s+$//;
}
foreach $i (@info2) {
$i =~ tr/+/ /;
$i =~ s/ //;
$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ s/\s+$//;
}
open(data,">$datadir/data.dat") ¦¦ &dataerror;
foreach $i (@info1) {
print data "$i\n";
}
close(data);
open(list,">$datadir/list.dat") ¦¦ &listerror;
foreach $i (@info2) {
print list "$i\n";
}
close(list);
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR><BR>\n";
print "<CENTER><FONT SIZE=+2>Information Saved!</FONT></CENTER><BR><CENTER><A HREF=$cgi_url>Click here or back to return!</A></CENTER>\n";
print "</BODY></HTML>\n";
exit;
}
# End of saving information
############################################

############################################
# Password error
sub passerror {
print "Content-type: text/html\n\n";
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR><BR>\n";
print "<CENTER><FONT SIZE=+2>No password supplied or incorrect password.</CENTER>\n";
print "</BODY></HTML>\n";
exit;
}
# End of password error
############################################

############################################
# Data error
sub dataerror {
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR><BR>\n";
print "<CENTER><FONT SIZE=+2>Error: Could not open \"$datadir/data.dat\".</CENTER>\n";
if (-e "$datadir/data.dat") { print "<CENTER>The file seems to exist, however it may not have the proper permissions. Please chmod it to 777 and try again.</CENTER>\n"; }
else { print "<CENTER>The file does not exist, please upload it and chmod it to 777 and try again.</CENTER>\n"; }
print "</BODY></HTML>\n";
exit;
}
# End of data error
############################################

############################################
# List error
sub listerror {
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR><BR>\n";
print "<CENTER><FONT SIZE=+2>Error: Could not open \"$datadir/list.dat\".</CENTER>\n";
if (-e "$datadir/list.dat") { print "<CENTER>The file seems to exist, however it may not have the proper permissions. Please chmod it to 777 and try again.</CENTER>\n"; }
else { print "<CENTER>The file does not exist, please upload it and chmod it to 777 and try again.</CENTER>\n"; }
print "</BODY></HTML>\n";
exit;
}
# End of list error
############################################

############################################
# Help
sub help {
print "Content-type: text/html\n\n";
print "<HTML><BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF VLINK=#FFFFFF ALINK=#808080>\n";
print "<CENTER>Antileech Programmed By <A HREF=http://www.confine.com>Confine.com</A></CENTER><BR><BR>\n";
print "<TABLE BORDER=1 CELLBORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=500 ALIGN=CENTER>\n";
print "<TR><TH BGCOLOR=\"#808080\">Allowed URLs</TH></TR>\n";
print "<TR><TD>This section is where you will put the urls of the sites you want to be able to access the antileech gateway, any url not in this list will cause the antileech gateway to deny service to the site that called it.\n";
print "<BR>Here are some tips on how to add a site to the allowed urls section (Note: Do not include the quotation marks):<br>\n";
print "1. Add \"yoursite.com\". This means that any file/directory on yoursite.com will have access to the antileech.<BR>\n";
print "2. Add \"yoursite.com/warez\". This means that only files/sub-directories in yoursite.com/warez will have access, yoursite.com/apps.html won't work<BR>\n";
print "3. Add \"!http://www.yoursite.com/apps.html\". This means that ONLY [yoursite.com...] will have access! (Note: This must match exactly, even the caps!)\n";
print "</TD></TR>\n";
print "<TR><TH BGCOLOR=\"#808080\">Antileech Files</TH></TR>\n";
print "<TR><TD>This section is where you add the files you want antileech to protect. Any file not in this list will not be protected.<BR>\n";
print "Here are some tips on how to add a file to the list (Note: Do not include the quotation marks):<BR>\n";
print "1. Add \"name\¦http://yoursite.com/warez/stuff.zip\". The \"name\" should be replaced with some sort of name for the file, like photoshop01 to represent the first file of photoshop. The second part should include the FULL url to the file you are protection, like [yoursite.com...]
print "You must include the \¦ (Shift+\\) to separate the two.\n";
print "</TD></TR>\n";
print "<TR><TH BGCOLOR=\"#808080\">Usage</TH></TR>\n";
print "<TR><TD>To protect a file add this to your html file: <A HREF=\"$cgi_url?photoshop01\">Photoshop File 1</A><BR>\n";
print "Where photoshop01 is the name of the file you are protecting, hence (photoshop01¦http://yoursite.com/warez/photoshop01.zip). That means when you create a link and use the name photoshop01, the file that has the name photoshop01 will be sent.\n";
print "</TD></TR></TABLE>\n";
print "</BODY></HTML>\n";
exit;
}
# End of help
############################################
[/perl]

sugarkane

4:09 pm on Dec 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CK - you just need to fill in your own details in the variables that are defined in the first few lines, from $datadir to $bad_url