Hey guys,
I have created a very basic Guestbook script that works effectively. I have one problem, I have a spammer who loves to spam my guestbook with adverts so I needed to change my script so that A) The user has to enter a random digit before the message can be posted, and B) it checks the users IP and if the ip has posted a message already then it won't let them post another. THE ONLY PROBLEM I AM HAVING is that basically once a user posts an entry it creates a txt file named under their IP and writes in the file the word "fail". So if the user posts another the script says that if the file says "fail" then dont let them post another entry else let them post. However, my problem is that the ip checker doesnt work and even though "fail" is printed in the txt file, the script will pass anyone even if they have posted already... Please check my script and suggest what i may need to change (if possible accept my very simple method of perl scripting). Thanks
#! /usr/bin/perl
use strict;
use CGI ':standard';
my ($arandom, $acarryrandom);
$arandom = param('random');
$acarryrandom = param('carryrandom');
my $IP = $ENV{'REMOTE_ADDR'};
open (LOG, ">>/path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "";
close (LOG);
open (LOG, "</path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
my @ip = <LOG>;
close (LOG) || Error ('close', 'file');
if (@ip eq "fail") {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>You cannot post another Guestbook entry at this time.</font>";
}
else {
if ($arandom eq $acarryrandom) {
open (LOG, ">/path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "fail";
close (LOG);
my ($aname, $aemail, $acomments, $timedate);
my ($sec, $min, $hour, $mday, $mon, $year)=gmtime;
$aname = param('name');
$aemail = param('email');
$acomments = param('comments');
$timedate = sprintf ('%02d:%02d:%02d <b>(</b>%02d/%02d/%4d<b>)</b> GMT', $hour, $min, $sec, $mday, $mon+1, $year+1900);
open (LOG, ">>/path/TVTown.co.uk/Guestbook/logfile2.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG " <b>Name</b>--<font color=red>$aname <<b>$timedate</b>></font>\n <b>Email</b>--$aemail\n <b>Comments</b>--$acomments\n<b>_____________________</b>\n";
close (LOG);
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P><font color=blue><b><u>Your entry has been added... @ip</u></b></font>";
print "<font face=arial size=2><P><b>Name:</b> $aname";
print "<font face=arial size=2><P><b>Email:</b> $aemail";
print "<font face=arial size=2><P><b>Comments:</b> $acomments\n";
print qq(<HR><A HREF="index.pl">(Add Entry)</A> <A HREF="view.pl">(View Guestbook)</A>);
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}
}
else {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>The digits you typed are incorrect - Click back in your browser and try again.</font>";
}
print "";
}
I have created a very basic Guestbook script that works effectively. I have one problem, I have a spammer who loves to spam my guestbook with adverts so I needed to change my script so that A) The user has to enter a random digit before the message can be posted, and B) it checks the users IP and if the ip has posted a message already then it won't let them post another. THE ONLY PROBLEM I AM HAVING is that basically once a user posts an entry it creates a txt file named under their IP and writes in the file the word "fail". So if the user posts another the script says that if the file says "fail" then dont let them post another entry else let them post. However, my problem is that the ip checker doesnt work and even though "fail" is printed in the txt file, the script will pass anyone even if they have posted already... Please check my script and suggest what i may need to change (if possible accept my very simple method of perl scripting). Thanks
#! /usr/bin/perl
use strict;
use CGI ':standard';
my ($arandom, $acarryrandom);
$arandom = param('random');
$acarryrandom = param('carryrandom');
my $IP = $ENV{'REMOTE_ADDR'};
open (LOG, ">>/path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "";
close (LOG);
open (LOG, "</path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
my @ip = <LOG>;
close (LOG) || Error ('close', 'file');
if (@ip eq "fail") {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>You cannot post another Guestbook entry at this time.</font>";
}
else {
if ($arandom eq $acarryrandom) {
open (LOG, ">/path/TVTown.co.uk/Guestbook/IP/$IP.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "fail";
close (LOG);
my ($aname, $aemail, $acomments, $timedate);
my ($sec, $min, $hour, $mday, $mon, $year)=gmtime;
$aname = param('name');
$aemail = param('email');
$acomments = param('comments');
$timedate = sprintf ('%02d:%02d:%02d <b>(</b>%02d/%02d/%4d<b>)</b> GMT', $hour, $min, $sec, $mday, $mon+1, $year+1900);
open (LOG, ">>/path/TVTown.co.uk/Guestbook/logfile2.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG " <b>Name</b>--<font color=red>$aname <<b>$timedate</b>></font>\n <b>Email</b>--$aemail\n <b>Comments</b>--$acomments\n<b>_____________________</b>\n";
close (LOG);
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P><font color=blue><b><u>Your entry has been added... @ip</u></b></font>";
print "<font face=arial size=2><P><b>Name:</b> $aname";
print "<font face=arial size=2><P><b>Email:</b> $aemail";
print "<font face=arial size=2><P><b>Comments:</b> $acomments\n";
print qq(<HR><A HREF="index.pl">(Add Entry)</A> <A HREF="view.pl">(View Guestbook)</A>);
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}
}
else {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>The digits you typed are incorrect - Click back in your browser and try again.</font>";
}
print "";
}