~;
}
$table_row;
}
sub get_number {
my $num;
open(NUMBER,"$counter")
or my_die("Error in function get_number during read",$!);
flock(NUMBER,2);
$num = ;
flock(NUMBER,8);
close(NUMBER);
$num++;
open(NUMBER,">$counter")
or my_die("Error in function get_number during write",$!);
flock(NUMBER,2);
print NUMBER $num;
flock(NUMBER,8);
close(NUMBER);
$num;
}
sub display_output {
my %name = (
HEADER => $header,
SUBHEADER => $sub_header,
HTMLOUTPUT => $html_output
);
# Open template and read in
open(TEMPLATE,"$booktemplate") or my_die("can't open $booktemplate",$!);
{
local($/) = undef;
$template = ;
}
close(TEMPLATE);
$template =~ s/\$([A-Z]+)/$name{$1}/g;
print $template;
}
sub get_date {
local($date,$localtime);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) {
$sec = "0$sec";
}
if ($min < 10) {
$min = "0$min";
}
if ($hour < 10) {
$hour = "0$hour";
}
if ($mon < 10) {
$mon = "0$mon";
}
if ($mday < 10) {
$mday = "0$mday";
}
$month = ($mon + 1);
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
$localtime = "$hour\:$min\:$sec";
$date = "$month/$mday/$year";
chop($date) if ($date =~ /\n$/);
chop($local) if ($local =~ /\n$/);
($date,$localtime);
}
sub send_all_mails {
if ($send_mail_to_admin eq "on") {
$mail_output .= qq~
You have a new entry in your guestbook:
Name: $in{'Name'}
Email: $in{'Email'}
Location: $in{'Location'}
Country: $in{'Country'}
URL: http://$in{'Homepage'}
Time: $date
Comments: $in{'Comment'}
~;
sendmail($mailprog,$in{'Email'},$admin_email,
"New Entry in your Guestbook",
$mail_output,$datadir,$smtp_server);
}
# This line of code uses Matt Wright's Check Email Script
if (&email_check($in{'Email'}) && $send_mail_to_guest eq "on") {
sendmail($mailprog,$admin_email,$in{'Email'},
"Thank you for signing our guestbook", $thank_you_message,$datadir,$smtp_server);
$html_output .= "We also sent you an e-mail to thank you.";
}
elsif (&email_check($in{'Email'}) && $send_mail_to_guest ne "on") {
$html_output .= "";
}
else {
$html_output .= "Note that we can't send you a thank you note
via e-mail because your e-mail address was invalid";
}
}
#####
# function trim
# trim words that are certain size in length
#####
sub trim {
my $string = shift;
my @sentence = split(/\s+/,$string);
my $j = 0;
my $word_length_max = 40;
foreach $word (@sentence) {
my $s_length = length($word);
if ($s_length > $word_length_max) {
my $num = int($s_length / $word_length_max);
for ($i=0;$i<$num;$i++) {
$sentence[$j] = substr($word,0,$word_length_max-1) . '-';
$j++;
}
$char_index += $word_length_max;
$sentence[$j] = substr($word,0,-1);
$j++;
}
else {
$sentence[$j] = $word;
$j++;
}
}
$string = join(" ",@sentence);
return $string;
}
############################################################################
# #
# email_check() Version 1.0 #
# Written by Matthew Wright mattw@worldwidemart.com #
# Created 8/1/96 Last Modified 3/23/97 #
# #
# Copyright 1997 Craig Patchett & Matthew Wright. All Rights Reserved. #
# This subroutine is part of The CGI/Perl Cookbook from John Wiley & Sons. #
# License to use this program or install it on a server (in original or #
# modified form) is granted only to those who have purchased a copy of The #
# CGI/Perl Cookbook. (This notice must remain as part of the source code.) #
# #
# Function: Checks an email address to see if it passes a simple #
# syntax check. (This routine will not check to see if the #
# address is an actual address.) #
# #
# Usage: &email_check($email_address); #
# #
# Variables: $email_address -- String containing the address to check #
# Example: 'someone@somewhere.com' #
# #
# Returns: 0 if the email address is invalid #
# 1 if the address is in a valid format #
# #
# Uses Globals: None #
# #
# Files Created: None #
# #
############################################################################
sub email_check {
local($email) = $_[0];
# Check that the email address doesn't have 2 @ signs, a .., a @., a
# .@ or begin or end with a .
if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/ ||
# Allow anything before the @, but only letters numbers, dashes and
# periods after it. Also check to make sure the address ends in 2 or
# three letters after a period and allow for it to be enclosed in []
# such as [164.104.50.1]
($email !~ /^.+\@localhost$/ &&
$email !~ /^.+\@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) {
return(0);
}
# If it passed the above test, it is valid.
else {
return(1);
}
}
sub sendmail {
my ($mailprog,$from,$to,$subject,$message,$dir,$smtp_server) = @_;
# Open The Mail Program
unless ($platform eq 'NT') {
open(MAIL,"|$mailprog -t") or
my_die("Error in subroutine send_mail: Can't open $mailprog",$!);
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close (MAIL);
}
else {
#prepare mail message to send
my (@output,$status);
my $temp_name = get_session_id();
my $temp_file = "$dir/$temp_name.emn";
$output[0] = $message;
writedata($temp_file,\@output);
$status = `$mailprog $temp_file -s \"$subject\" -f $from -t $to -server $smtp_server`;
unlink($temp_file);
}
}
####
#
# subroutine my_die
#
####
sub my_die {
my($my_mesg, $sys_mesg) = @_;
print "\n";
print qq~
$my_mesgSCRIPT ERROR!!!
There was an error in processing your request.
Following is the error message: