CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need Simple Pearl Script Help

 



WallyW
Deleted

May 27, 2000, 9:04 AM

Post #1 of 3 (641 views)
Need Simple Pearl Script Help Can't Post

I have been using the free script that comes with FFA Blaster (www.submitad.com) for my FFA page. However, I have been unable to get the bademail.txt file to work. It just doesn't seem to check for bademails.

I am on a UNIX system, and I have both link.pl and bademail.txt in my cgi-bin/links directory, set chmod to 755 and 666 respectively, ftp'd using ascii and checked to make sure there are no blank lines in bademail.txt using Windows WordPad. Otherwise, the script works fine for me. Below is the cgi code relating to the check of bademail.txt. I moved the "close (FILE);" command from directly to under "@bademail = <FILE>;" to the end of this section but that didn't help. I even tried giving the bademail.txt file name the complete server path. Any ideas would be appreciated!

Wally

# Check for BANNED email addresses.
#########################################################

open (FILE, "bademail.txt");
@bademail = <FILE>;

foreach (@bademail) {

chomp $_;
$temp = $_;

if ($email =~ /\s$temp\s/i) {

print "Content-type: text/html\n\n";
print "<html><head><title>Sorry, You can NOT post a link using that email address!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Sorry, You can NOT post a link using that email address!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
close (FILE);
exit;

}

}

close (FILE);



Cure
User

May 26, 2000, 10:33 PM

Post #2 of 3 (641 views)
Re: Need Simple Pearl Script Help [In reply to] Can't Post

Hi

#!/usr/bin/perl

use CGI;
$q = CGI->new;
print $q->header;
$ban = $q->param('ban');
open (FILE, "ban.txt") or die $!;
while (<FILE> ) {
chomp;
if (/^$ban$/i)
{
print qq~
<html><head><title>Sorry, You can NOT post a link using that email address!</title></head>
<body bgcolor=white><br><center><font size=5 color=blue>
<b>Sorry, You can NOT post a link using that email address!</b></font><br><br>
<b>Please hit your browsers back button and try again.</b></center><br></body></html>
~;
}}
close (FILE);


Cure


[This message has been edited by Cure (edited 05-27-2000).]


WallyW
Deleted

May 27, 2000, 11:20 AM

Post #3 of 3 (641 views)
Re: Need Simple Pearl Script Help [In reply to] Can't Post

Thanks but after replacing that portion of the code with yours, I kept getting a page saying "programa: no-cache (and my links page url) when the script would finish. Also, I assumed ban.txt was to be replaced with my bademail.txt file name. I have pasted the entire code below. Maybe you can see how it integrates. (The script is offered free even though there is a copywrite. I could not get a response from the creator)
Thanks.
Wally

---------------------
#!/usr/local/bin/perl

# Be sure the above path is correct for your server!

##############################################################################
# This script was generated by FFA Blaster Version 1.5.72
#
# Download your own copy of FFA Blaster, loaded with features like:
# * Autoposts your ads to thousands FFA pages
# * Supports batch mode postings
# * Easy-to-use interface. Start posting within 2 minutes
# * Built-in FFA page script generator
# * Automatically installs your FFA page on your server
# * FREE version available!
# * And much, much more...
#
# Download1: http://www.SubmitAd.com/files/blaster1.exe
# Homesite1: http://www.SubmitAd.com
# Download2: http://www.FFAblaster.com/files/blaster1.exe
# Homesite2: http://www.FFAblaster.com
#
# Please add your FFA page to our database and you will start receive postings
# within a couple of minutes!
# http://www.submitad.com/submitffa.htm
#
# FFA Blaster requries that you are running Windows 95/98.
# Copyright 1998-99 SPCK Software - All rights reserved
##############################################################################

##############################################################################
# YOU EDIT THESE VARIABLES IN THE FFA BLASTER SOFTWARE BEFORE THIS SCRIPT IS
# GENERATED! YOU MUST HAVE CORRECT VARIABLES HERE FOR THE SCRIPT TO WORK
##############################################################################

# The domain that your links page resides on.
$domain = "profitbooks.com";

# Server path to your links.html file.
$htmlpath = "/home/pspr/web/ffa/links.html";

# URL of your links.html file.
$htmlurl = "http://www.profitbooks.com/ffa/links.html";

# Maximum number of links per section.
$maxlinks = 25;

# Send confirmation email? 0 for no, 1 for yes.
$sendemail = 1;

# Server path of sendmail or equivalent.
$mailprog = "/usr/bin/sendmail";

# This will be the name the confirmation email is from.
$fromname = "Profit Source";

# This will be the address the confirmation email is from.
# Perl requires a \ before the @ sign so we insert it here.
$fromemail = "pspr\@mima.zzn.com";

# This will be the subject of the confirmation email.
$subject = "Get 300 In Your Downline In 30 days!";

# Save email addresses of sumbitter to file? 0 for no, 1 for yes.
$saveemail = 1;

# Server path to your collect.txt file where email addresses of submitter is saved
$emaildatabase = "/home/pspr/web/cgi-bin/links/collect.txt";

# Holds total number of postings. located in same directory as the script
$CountFile = "links.num";

##############################################################################
# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!!!
##############################################################################

##############################################################################
# Read in the POSTed variables.
##############################################################################

read (STDIN, $input, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $input);

foreach $pair (@pairs) {

($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<([^>]|\n)*>//g;
$value =~ s/<//g;
$value =~ s/>//g;
$value =~ s/\*/\\\*/g;
$value =~ s/\+/\\\+/g;
$FORM{$name} = $value;
}

##############################################################################

$title = $FORM{'title'};
$url = $FORM{'url'};
$email = $FORM{'email'};
$section = $FORM{'section'};

$refer = $ENV{'HTTP_REFERER'};
$remote = $ENV{'REMOTE_ADDR'};

##############################################################################
# Make sure the user entered a title for their link.
##############################################################################

if ($title eq '') {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Forgot To Enter Your Site's Title!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Forgot To Enter Your Site's Title!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Make sure the title is not longer than 85 characters.
##############################################################################

if (length($title) > 85) {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, Your Title Is Longer Than 85 Characters!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, Your Title Is Longer Than 60 Characters!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Check for restricted words in the title.
##############################################################################

open (FILE, "badwords.txt");
@badwords = <FILE>;

foreach (@badwords) {

chomp $_;
$temp = $_;

if ($title =~ /\s$temp\s/i &#0124; &#0124; $title =~ /^$temp\s/i &#0124; &#0124; $title =~ /\s$temp$/i) {

print "Content-type: text/html\n\n";
print "<html><head><title>Sorry, There's A Restricted Word In Your Title!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Sorry, There's A Restricted Word In Your Title!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
close (FILE);
exit;

}

}

close (FILE);

##############################################################################
# Check for BANNED email addresses.
##############################################################################

open (FILE, "bademail.txt");
@bademail = <FILE>;

foreach (@bademail) {

chomp $_;
$temp = $_;

if ($email =~ /\s$temp\s/i) {

print "Content-type: text/html\n\n";
print "<html><head><title>Sorry, You can NOT post a link using that email address!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Sorry, You can NOT post a link using that email address!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
close (FILE);
exit;

}

}

close (FILE);

##############################################################################
# Make sure user entered their URL.
##############################################################################

if ($url eq 'http://') {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Forgot To Enter Your Site's URL!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Forgot To Enter Your Site's URL!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Make sure user entered a valid URL.
##############################################################################

if ($url !~ /^(f|ht)tp:\/\/\w+\.\w+/) {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Entered An Invalid URL!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Entered An Invalid URL!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Make sure the url does not contain html coding.
##############################################################################

if ($url =~ / / &#0124; &#0124; $url =~ /"/ &#0124; &#0124; $url =~ /'/ &#0124; &#0124; $url =~ /01/ &#0124; &#0124; $url =~ /02/ &#0124; &#0124; $url =~ /03/ &#0124; &#0124; $url =~ /04/ &#0124; &#0124; $url =~ /05/ &#0124; &#0124; $url =~ /06/ &#0124; &#0124; $url =~ /07/ &#0124; &#0124; $url =~ /08/ &#0124; &#0124; $url =~ /09/ &#0124; &#0124; $url =~ /10/ &#0124; &#0124; $url =~ /11/ &#0124; &#0124; $url =~ /12/ &#0124; &#0124; $url =~ /\r/ ) {


print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Entered A URL with HTML Coding - That is not allowed on this FFA Page -
We do not want this FFA Page Bloated with Bold, Flashing, Color Titles!
</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Entered A URL with HTML Coding - That is not allowed on this FFA Page -
We do not want this FFA Page Bloated with Bold, Flashing, Color Titles!
</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try
again.</b></center><br>\n";
exit;

}

##############################################################################
# Check for restricted URLs.
##############################################################################

open (FILE, "badurls.txt");
@badurls = <FILE>;

foreach (@badurls) {

chomp $_;
$temp = $_;

if ($url =~ /$temp/i) {

print "Content-type: text/html\n\n";
print "<html><head><title>Sorry, You Can't Post A Link To That URL Here!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Sorry, You Can't Post A Link To That URL Here!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
close (FILE);
exit;

}

}

close (FILE);

##############################################################################
# Make sure the user entered their email address.
##############################################################################

if ($email eq '') {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Forgot To Enter Your Email Address!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Forgot To Enter Your Email Address!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Make sure the user entered a valid email address format.
##############################################################################

if ($email !~ /^[\w\d][\w\d\,\.\-]*\@([\w\d\-]+\.)+([a-zA-Z]{3}|[a-zA-Z]{2})$/) {

print "Content-type: text/html\n\n";
print "<html><head><title>Ooops, You Entered An Invalid Email Address!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Ooops, You Entered An Invalid Email Address!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}

##############################################################################
# Preparing to see if link already exists in another form.
##############################################################################

$shorturl = substr ($url,7);
if ($shorturl =~ /^www/) { $sld = substr ($shorturl,4); }
else { $sld = 'www.' . $shorturl; }
$url2 = 'http://' . $sld;

##############################################################################
# Read in links.html file and process the submission.
##############################################################################

$i=1;
$j=0;

%sections = ("busi","FreeStuff","comp","Business","educ","Computers","ente","Entertainment","gove","Merchandise","misc","Miscellaneous","pers","Personal");

open(FILE,"+>>$htmlpath");
flock(FILE, 2);
# rewind to beginning and read entire file
seek (FILE, 0, 0);
@lines = <FILE>;

foreach $line (@lines) {
if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {
if ($line =~ /$url/ &#0124; &#0124; $line =~ /$url2/ &#0124; &#0124; $line =~ /$title/) {

print "Content-type: text/html\n\n";
print "<html><head><title>Sorry, That Link Already Exists On This Page!</title></head>\n";
print "<body bgcolor=white><br><center><font size=5 color=blue>\n";
print "<b>Sorry, That Link Already Exists On This Page!</b></font><br><br>\n";
print "<b>Please hit your browser's \"back\" button and try again.</b></center><br>\n";
exit;

}
$i++;
}
}

##############################################################################
# Increase counter that holds total number of postings by 1
##############################################################################
open (ADNUM, "+<$CountFile");
flock (ADNUM, 2);

$AdNum = <ADNUM>;
chomp $AdNum;
$AdNum++;
seek (ADNUM,0,0);
print ADNUM "$AdNum\n";
close(ADNUM);

##############################################################################
# rewind to beginning again and empty the file
seek (FILE, 0, 0);
truncate (FILE, 0);

##############################################################################
# Loop through the links.html file line by line.

foreach $line (@lines) {

if ($line =~ /<!--time-->/) {

@months = ('January','February','March','April','May','June','July','August','September','October','November','December');

@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];

if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }

$date = "on $days[$wday], $months[$mon] $mday, 19$year at $hour:$min:$sec";
print FILE "<!--time--><b>The last link was added $date by $remote.</b><br>\n";

}

elsif ($line =~ /<!--number-->/) {

print FILE "<!--number--><b>Currently there are <i>$i</i> links on this page (of a total of <i>$AdNum</i> posted)!</b><br>\n";

}

elsif ($line =~ /<!--maxlinks-->/) {

print FILE "<!--maxlinks--><b>Each section is limited to <i>$maxlinks</i> links, new links are placed on top!</b><br>\n";

}

elsif ($line =~ /<!--power-->/) {

print FILE "<!--power--><b>This page is created and powered by <a href=\"http:\/\/www.submitad.com\/blaster.htm\">FFA Blaster!</a></b><br><br><hr><br>\n";

}

elsif (substr($line,0,4) ne "<li>") { print FILE $line; }

##############################################################################
# Final check allows only $maxlinks per section.

else { if ($j < $maxlinks ) { print FILE $line; $j++; }

}

foreach $tag ( keys %sections) {

if ($line =~ /<!--$tag-->/) { $j=0; }

if ( ($section eq $sections{$tag}) && ($line =~ /<!--$tag-->/) ) {

$url =~ s/\\\*/\*/g;
$url =~ s/\\\+/\+/g;

$title =~ s/\\\*/\*/g;
$title =~ s/\\\+/\+/g;

print FILE "<li><a href=\"$url\">$title</a>\n";
$j++;

}
}
}
close(FILE);

###############################################################################
# Save email address to file.
###############################################################################
unless ($saveemail == 0) {

open (FILE,"$emaildatabase");
@lines = <FILE>;
close(FILE);

chomp $email;
$match = 0;
foreach $line (@lines) {
chomp $line;
if ($line eq $email) {
$match = 1;
}
}

# If no match we add the new email address
if (! $match) {
open (FILE,">>$emaildatabase");
flock(FILE, 2);
print FILE "$email\n";
close(FILE);
}
}

###############################################################################
# Send confirmation email
###############################################################################

unless ($sendemail == 0) {

open (EMAIL, "email.txt");
@body = <EMAIL>;
close (EMAIL);

open(MAIL,"|$mailprog -t");

print MAIL "To: $email\n";
print MAIL "From: $fromemail ($fromname)\n";
print MAIL "Subject: $subject\n\n";

print MAIL "Title: $title\n";
print MAIL "URL: $url\n";
print MAIL "Section: $section\n";
print MAIL "Submitted by: $email\n\n\n";

foreach (@body) { print MAIL "$_"; }

print MAIL " \n";

close (MAIL);

}

##############################################################################
# All done, send user back to links.html
##############################################################################

print "Pragma: no-cache\n";
print "Location: $htmlurl\n\n";

exit;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives