R
Robin
#!/usr/bin/perl -wT
use Fcntl qw
flock);
use strict;
use warnings;
use CGI qw
all);
$CGI:
OST_MAX=1024 * 100; # max 100K posts
$CGI:
ISABLE_UPLOADS = 1; # no uploads
$" = '';
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
my $homepage = "http://www.infusedlight.net"; #change this to your homepage
my $string = '<--->';
my $string2 = '<---->';
my $version = '1.0.0';
my $bookfile = 'book.txt';
my $headerfile = 'header.txt';
my $footerfile = 'footer.txt';
my $DATE = getdate();
my @head = gethead ($headerfile);
my @foot = getfoot ($footerfile);
if (url_param ('action') eq "sign")
{
sign();
}
elsif (url_param ('action') eq "dosign")
{
dosign();
}
else
{
if (! -e $bookfile)
{
if (open (BOOKFILE, ">$bookfile"))
{
flock (BOOKFILE, LOCK_EX);
print BOOKFILE '';
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
}
else
{
print header and print "<center><strong>Viewing Guestbook - Version
$version - No guests</strong><hr><a href=\"$homepage\">To
homepage</a></center>" and exit;
}
}
view (1);
}
sub sign
{
print header;
print (@head);
print <<END;
<div align="center">
<p><strong>GBOOK2 - Sign Guestbook - Version $version</strong></p>
<hr size="1">
<form name="form1" method="post" action="gbook.pl?action=dosign">
<table width="85%" border="1" align="center" cellpadding="3"
cellspacing="0" bordercolor="#660000">
<tr>
<td width="50%" bgcolor="#CCCCCC">Your name:</td>
<td width="50%" bgcolor="#999999">
<div align="center">
<input name="name" type="text" id="name">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your email: </td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="email" type="text" id="email">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your web site name (not required):</td>
<td bgcolor="#999999"><div align="center">
<input type="text" name="webname">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your web site URL (not required):</td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="url" type="text" id="url">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your message: </td>
<td bgcolor="#999999"><div align="center">
<textarea name="message" cols="35" rows="4"
id="message"></textarea>
</div></td>
</tr>
<tr>
<td bgcolor="#333399">
<div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td bgcolor="#333399">
<div align="left">
<input type="reset" name="Submit2" value="Reset">
</div></td>
</tr>
</table>
</form>
<hr size="1">
</div>
END
print (@foot);
}
sub dosign
{
if (checkforcookie() eq "true")
{
print header;
print (@head);
print ("<center>You have already signed the guestbook once today.
Please sign it again tommorow.<hr></center>");
print (@foot);
exit;
}
my $name = param ('name');
my $email = param ('email');
my $website = param ('webname') . $string2 . param ('url');
my $message = param ('message');
if (param ('url') !~ /<.*>/ and param ('webname') !~ /<.*>/ and param
('url') !~ /^\s*$/s and param ('webname') !~ /$string2|$string/ and param
('url') !~ /$string2|$string/)
{
my (@url);
@url = split (/$string2/, $website);
if ($url[1] ne '' and $url[0] eq '')
{
$website = <<END;
<a href="$url[1]">$url[1]</a>
END
}
elsif ($url[0] ne '' and $url[1] ne '')
{
$website = <<END;
<a href="$url[1]">$url[0]</a>
END
}
elsif ($url[0] ne '' and $url[1] eq '')
{
$website = 'None';
}
elsif ($url[0] eq '' and $url[1] eq '')
{
$website = 'None';
}
}
else
{
$website = 'None';
}
if ($name !~ /^\s*$/g and $email !~ /^\s*$/g and $message !~ /^\s*$/g and
$email !~ /<.*>/s and param ('webname') !~ /<.*>/g and param ('url') !~
/<.*>/g and $name !~ /<.*>/s and $name !~ /$string/g and $message !~
/$string/g and $website !~ /$string/g and $email !~ /$string/g and $name !~
/$string2/g and $message !~ /$string2/g and $email !~ /$string2/g and param
('webname') !~ /$string2/g and param ('url') !~ /$string2/g)
{
open (BOOKFILE, ">>$bookfile") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (BOOKFILE, LOCK_EX);
print BOOKFILE <<"END";
<div align="center">
<table width="75%" border="1" cellpadding="3" cellspacing="0"
bordercolor="#660000" align="center">
<tr>
<td>Date of message: </td>
<td>$DATE</td>
</tr>
<tr>
<td width="50%">Name:</td>
<td width="50%">$name</td>
</tr>
<tr>
<td width="50%">Email:</td>
<td width="50%">$email</td>
</tr>
<tr>
<td>Website:</td>
<td>$website</td>
</tr>
<tr>
<td>Message:</td>
<td>$message</td>
</tr>
</table>
<hr size="1">
$string
END
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
chmod (0770, $bookfile);
setcookie ("gbook.pl");
exit;
}
else
{
printerror1 ();
}
}
sub view
{
my ($header) = @_;
open (BOOKFILE, $bookfile) or print header and print
"<center><strong>Viewing Guestbook - Version $version - No
guests</strong><hr><a href=\"$homepage\">To homepage</a></center>" and exit;
flock (BOOKFILE, LOCK_SH);
my @contentsofbook=<BOOKFILE>;
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
my $contentsofbook=join('', @contentsofbook);
@contentsofbook = split (/$string/, $contentsofbook);
@contentsofbook = reverse (@contentsofbook);
my $len = @contentsofbook;
$len -= 1;
$len = "No" if ($len == -1);
my $s;
$s = 's' if ($len > 1 or $len eq "No");
print header if ($header);
print (@head);;
print <<END;
<div align="center">
<strong>GBOOK2 - Viewing Guestbook - Version $version - $len
guest$s</strong>
<hr size="1"><a href="$homepage">To homepage</a><br><br>
END
printpages();
print "<br><br>" if (@contentsofbook);
my $content;
my @contentslen;
@contentslen = @contentsofbook[(url_param ('start') - 1) ..
(url_param('end'))] if (url_param ('start') == 1);
@contentslen = @contentsofbook[(url_param ('start')) .. (url_param('end') -
1)] if (url_param ('start') > 10);
if (! @contentsofbook)
{
print "No guests.";
}
if (url_param ('start') ne '' and url ('end') ne '')
{
print @contentslen;
}
else
{
@contentslen = @contentsofbook[0 .. 10];
print @contentslen;
}
printpages();
print "<br><br>";
print <<END;
<a href="$homepage">To homepage</a></div>
END
print (@foot);
exit;
}
sub printpages
{
my ($counter, $counter2, $tempcount);
open (BOOKFILE, $bookfile) or print "An error occured during this
operation. Please try again.";
flock (BOOKFILE, LOCK_SH);
my @contentstoprint = <BOOKFILE>;
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
$counter = 0;
$counter2 =1;
$tempcount = 0;
my $contentstoprint = join ('', @contentstoprint);
@contentstoprint = split (/$string/, $contentstoprint);
@contentstoprint = reverse (@contentstoprint);
my $content1;
print "Pages: [ <a href=\"gbook.pl?start=1&end=10\">1</a> ] " unless (!
@contentstoprint);
foreach $content1 (@contentstoprint)
{
if ($counter == 11)
{
$counter2 += 1;
print "[ <a href=\"gbook.pl?start=$tempcount&end=" , $tempcount + 10 ,
"\">$counter2</a> ] ";
if ($counter2 > 0)
{
$counter = 1;
}
else
{
$counter = 0;
}
}
$tempcount += 1;
$counter += 1;
}
}
sub printerror1
{
print header;
print (@head);
print ("<center>You did not supply the required fields or you used HTML
tags which are not allowed on this guestbook.<hr></center>");
print (@foot);
exit;
}
sub gethead
{
my ($header) = @_;
my @header;
if (-e "$header")
{
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_SH);
@header = <HEADER>;
flock (HEADER, LOCK_UN);
close (HEADER);
}
else
{
open (HEADER, ">$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_EX);
print HEADER <<END;
<html>
<head>
<title>GBOOK2 Version $version</title>
</head>
<body>
END
flock (HEADER, LOCK_UN);
close (HEADER);
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_SH);
@header = <HEADER>;
flock (HEADER, LOCK_UN);
close (HEADER);
}
chmod (0770, $header);
return @header;
}
sub getfoot
{
my ($footer) = @_;
my @footer;
if (-e "$footer")
{
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, LOCK_UN);
close (FOOTER);
}
else
{
open (FOOTER, ">$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_EX);
print FOOTER <<END;
</body></html>
END
close (FOOTER);
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, LOCK_UN);
close (FOOTER);
}
chmod (0770, $footer);
return @footer;
}
sub getdate {
my ($day, $mon, $year)=(localtime)[3,4,5];
$mon++; #month is returned in a 0-11 range
$year +=1900;
my $date = $mon . "/" . $day . "/" . $year;
return $date;
}
sub setcookie
{
my ($redir) = @_;
my $cookie;
$cookie = cookie (-name=>'signed', -value=>"signed", -expires=>'+1d');
print redirect (-url=>"$redir", -cookie=>"$cookie");
}
sub checkforcookie
{
my $cookieflag;
$cookieflag = '';
if (getcookie() eq 'signed')
{
$cookieflag = 'true';
}
return ($cookieflag);
}
sub getcookie
{
my $cookiein;
$cookiein = cookie ('signed');
return $cookiein;
}
-------------
yeah I know the indents suck, but I'm too lazy to clean them up. it's just
my program screws them up.
Later,
-Robin
use Fcntl qw
use strict;
use warnings;
use CGI qw
$CGI:
$CGI:
$" = '';
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
my $homepage = "http://www.infusedlight.net"; #change this to your homepage
my $string = '<--->';
my $string2 = '<---->';
my $version = '1.0.0';
my $bookfile = 'book.txt';
my $headerfile = 'header.txt';
my $footerfile = 'footer.txt';
my $DATE = getdate();
my @head = gethead ($headerfile);
my @foot = getfoot ($footerfile);
if (url_param ('action') eq "sign")
{
sign();
}
elsif (url_param ('action') eq "dosign")
{
dosign();
}
else
{
if (! -e $bookfile)
{
if (open (BOOKFILE, ">$bookfile"))
{
flock (BOOKFILE, LOCK_EX);
print BOOKFILE '';
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
}
else
{
print header and print "<center><strong>Viewing Guestbook - Version
$version - No guests</strong><hr><a href=\"$homepage\">To
homepage</a></center>" and exit;
}
}
view (1);
}
sub sign
{
print header;
print (@head);
print <<END;
<div align="center">
<p><strong>GBOOK2 - Sign Guestbook - Version $version</strong></p>
<hr size="1">
<form name="form1" method="post" action="gbook.pl?action=dosign">
<table width="85%" border="1" align="center" cellpadding="3"
cellspacing="0" bordercolor="#660000">
<tr>
<td width="50%" bgcolor="#CCCCCC">Your name:</td>
<td width="50%" bgcolor="#999999">
<div align="center">
<input name="name" type="text" id="name">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your email: </td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="email" type="text" id="email">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your web site name (not required):</td>
<td bgcolor="#999999"><div align="center">
<input type="text" name="webname">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your web site URL (not required):</td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="url" type="text" id="url">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your message: </td>
<td bgcolor="#999999"><div align="center">
<textarea name="message" cols="35" rows="4"
id="message"></textarea>
</div></td>
</tr>
<tr>
<td bgcolor="#333399">
<div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td bgcolor="#333399">
<div align="left">
<input type="reset" name="Submit2" value="Reset">
</div></td>
</tr>
</table>
</form>
<hr size="1">
</div>
END
print (@foot);
}
sub dosign
{
if (checkforcookie() eq "true")
{
print header;
print (@head);
print ("<center>You have already signed the guestbook once today.
Please sign it again tommorow.<hr></center>");
print (@foot);
exit;
}
my $name = param ('name');
my $email = param ('email');
my $website = param ('webname') . $string2 . param ('url');
my $message = param ('message');
if (param ('url') !~ /<.*>/ and param ('webname') !~ /<.*>/ and param
('url') !~ /^\s*$/s and param ('webname') !~ /$string2|$string/ and param
('url') !~ /$string2|$string/)
{
my (@url);
@url = split (/$string2/, $website);
if ($url[1] ne '' and $url[0] eq '')
{
$website = <<END;
<a href="$url[1]">$url[1]</a>
END
}
elsif ($url[0] ne '' and $url[1] ne '')
{
$website = <<END;
<a href="$url[1]">$url[0]</a>
END
}
elsif ($url[0] ne '' and $url[1] eq '')
{
$website = 'None';
}
elsif ($url[0] eq '' and $url[1] eq '')
{
$website = 'None';
}
}
else
{
$website = 'None';
}
if ($name !~ /^\s*$/g and $email !~ /^\s*$/g and $message !~ /^\s*$/g and
$email !~ /<.*>/s and param ('webname') !~ /<.*>/g and param ('url') !~
/<.*>/g and $name !~ /<.*>/s and $name !~ /$string/g and $message !~
/$string/g and $website !~ /$string/g and $email !~ /$string/g and $name !~
/$string2/g and $message !~ /$string2/g and $email !~ /$string2/g and param
('webname') !~ /$string2/g and param ('url') !~ /$string2/g)
{
open (BOOKFILE, ">>$bookfile") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (BOOKFILE, LOCK_EX);
print BOOKFILE <<"END";
<div align="center">
<table width="75%" border="1" cellpadding="3" cellspacing="0"
bordercolor="#660000" align="center">
<tr>
<td>Date of message: </td>
<td>$DATE</td>
</tr>
<tr>
<td width="50%">Name:</td>
<td width="50%">$name</td>
</tr>
<tr>
<td width="50%">Email:</td>
<td width="50%">$email</td>
</tr>
<tr>
<td>Website:</td>
<td>$website</td>
</tr>
<tr>
<td>Message:</td>
<td>$message</td>
</tr>
</table>
<hr size="1">
$string
END
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
chmod (0770, $bookfile);
setcookie ("gbook.pl");
exit;
}
else
{
printerror1 ();
}
}
sub view
{
my ($header) = @_;
open (BOOKFILE, $bookfile) or print header and print
"<center><strong>Viewing Guestbook - Version $version - No
guests</strong><hr><a href=\"$homepage\">To homepage</a></center>" and exit;
flock (BOOKFILE, LOCK_SH);
my @contentsofbook=<BOOKFILE>;
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
my $contentsofbook=join('', @contentsofbook);
@contentsofbook = split (/$string/, $contentsofbook);
@contentsofbook = reverse (@contentsofbook);
my $len = @contentsofbook;
$len -= 1;
$len = "No" if ($len == -1);
my $s;
$s = 's' if ($len > 1 or $len eq "No");
print header if ($header);
print (@head);;
print <<END;
<div align="center">
<strong>GBOOK2 - Viewing Guestbook - Version $version - $len
guest$s</strong>
<hr size="1"><a href="$homepage">To homepage</a><br><br>
END
printpages();
print "<br><br>" if (@contentsofbook);
my $content;
my @contentslen;
@contentslen = @contentsofbook[(url_param ('start') - 1) ..
(url_param('end'))] if (url_param ('start') == 1);
@contentslen = @contentsofbook[(url_param ('start')) .. (url_param('end') -
1)] if (url_param ('start') > 10);
if (! @contentsofbook)
{
print "No guests.";
}
if (url_param ('start') ne '' and url ('end') ne '')
{
print @contentslen;
}
else
{
@contentslen = @contentsofbook[0 .. 10];
print @contentslen;
}
printpages();
print "<br><br>";
print <<END;
<a href="$homepage">To homepage</a></div>
END
print (@foot);
exit;
}
sub printpages
{
my ($counter, $counter2, $tempcount);
open (BOOKFILE, $bookfile) or print "An error occured during this
operation. Please try again.";
flock (BOOKFILE, LOCK_SH);
my @contentstoprint = <BOOKFILE>;
flock (BOOKFILE, LOCK_UN);
close (BOOKFILE);
$counter = 0;
$counter2 =1;
$tempcount = 0;
my $contentstoprint = join ('', @contentstoprint);
@contentstoprint = split (/$string/, $contentstoprint);
@contentstoprint = reverse (@contentstoprint);
my $content1;
print "Pages: [ <a href=\"gbook.pl?start=1&end=10\">1</a> ] " unless (!
@contentstoprint);
foreach $content1 (@contentstoprint)
{
if ($counter == 11)
{
$counter2 += 1;
print "[ <a href=\"gbook.pl?start=$tempcount&end=" , $tempcount + 10 ,
"\">$counter2</a> ] ";
if ($counter2 > 0)
{
$counter = 1;
}
else
{
$counter = 0;
}
}
$tempcount += 1;
$counter += 1;
}
}
sub printerror1
{
print header;
print (@head);
print ("<center>You did not supply the required fields or you used HTML
tags which are not allowed on this guestbook.<hr></center>");
print (@foot);
exit;
}
sub gethead
{
my ($header) = @_;
my @header;
if (-e "$header")
{
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_SH);
@header = <HEADER>;
flock (HEADER, LOCK_UN);
close (HEADER);
}
else
{
open (HEADER, ">$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_EX);
print HEADER <<END;
<html>
<head>
<title>GBOOK2 Version $version</title>
</head>
<body>
END
flock (HEADER, LOCK_UN);
close (HEADER);
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, LOCK_SH);
@header = <HEADER>;
flock (HEADER, LOCK_UN);
close (HEADER);
}
chmod (0770, $header);
return @header;
}
sub getfoot
{
my ($footer) = @_;
my @footer;
if (-e "$footer")
{
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, LOCK_UN);
close (FOOTER);
}
else
{
open (FOOTER, ">$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_EX);
print FOOTER <<END;
</body></html>
END
close (FOOTER);
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, LOCK_UN);
close (FOOTER);
}
chmod (0770, $footer);
return @footer;
}
sub getdate {
my ($day, $mon, $year)=(localtime)[3,4,5];
$mon++; #month is returned in a 0-11 range
$year +=1900;
my $date = $mon . "/" . $day . "/" . $year;
return $date;
}
sub setcookie
{
my ($redir) = @_;
my $cookie;
$cookie = cookie (-name=>'signed', -value=>"signed", -expires=>'+1d');
print redirect (-url=>"$redir", -cookie=>"$cookie");
}
sub checkforcookie
{
my $cookieflag;
$cookieflag = '';
if (getcookie() eq 'signed')
{
$cookieflag = 'true';
}
return ($cookieflag);
}
sub getcookie
{
my $cookiein;
$cookiein = cookie ('signed');
return $cookiein;
}
-------------
yeah I know the indents suck, but I'm too lazy to clean them up. it's just
my program screws them up.
Later,
-Robin