#!/usr/bin/perl ############################################################### # index.cgi - AutoGuestbook_db v2.52 - released 12/16/99 # # This script runs a guestbook on your site. # This script by Anatoli Vichniakov - copyright 1998. # ############################################################### # CONFIGURATION SECTION ############################################################### # Path to directory. $datapath = '/var/www/html/sc/gb'; # This is the URL version of the path above. $dataurl = 'http://www.shieldcam.com/gb'; # Password to access log file. $password = 'willchange'; # The name of database file. # You may rename before go on public. $datafile = 'datafile.txt'; # This is a log file. # You may rename before go on public. $log_file = 'guestlog.html'; # This is a ban list file containing IPs of banned users. # You may rename before go on public. $ban_file = 'banlist.txt'; # Write to log file. $uselog = 'yes'; # If you want the full log set if to 'yes'. $fullog = 'yes'; # Maximum number of records to show on the guestbook main page. $max_records = 5; # After initial testing, set this to 'yes', # if your server allows file locking, this will reduce errors. $lockon = 'no'; # This is the adjustment to your displayed hour. $timefix = 0; # This is the time zone of your displayed time. $zone = 'ET'; # Location of e-mail program. $mail_program = '/usr/sbin/sendmail'; # Set to 'yes', if you want to get notification via e-mail. $notification = 'yes'; # E-mail where to send notification. $sitemail = 'hanse@shieldcam.com'; # Subject that would be sent to webmaster with new posting. $subject_notify = 'You have new entry to Guestbook'; # Set to 'yes', if you want to send e-mail to user who posted the message. $remote_mail = 'no'; # Subject that would be sent to user after posting. $subject_mail_user = 'Automatic response from Guestbook on Amnesia.net. Here is what you posted in our Guestbook.'; # First(main) page template file. $guestbook_template = 'template/guestbook.txt'; # Add record template file. $adrecord_template = 'template/adrecord.txt'; # Format message template file. $message_template = 'template/message.txt'; # Preview template file $preview_template = 'template/prrecord.txt'; # Edit message template file. $remtext_template = 'template/remtext.txt'; # Search template file. $search_template = 'template/search.txt'; # This is the name of template file containing the page for banned guests. $exitban_template = 'template/exitban.txt'; ################## guestbook archive service ################### # A number of records to show on the archive page. $records_archive = 9999; # Archive page template file. $archive_template = 'template/archive.txt'; ################### guestbook e-mail service #################### # Set to 'yes' if you want to enable e-mail service. $mail_service = 'yes'; # Subject in the e-mail form. $subject = 'Everyday Demo guestbook e-mail service at Amnesia.net'; # Time interval between e-mail sendings(sec.*min.*hours*days). $mail_time = 60*60*24; # Mail List Service config file. $mailservice = 'mservice.txt'; # This is a file containing users e-mail addresses. # You may rename before go on public. $mail_list = 'maillist.txt'; # E-mail subject template file. $mail_subject = 'template/mailsubj.txt'; # E-mail list body template file. $mailrec_template = 'template/mailrec.txt'; # If no function entry template file. $no_function_template = 'template/noregfun.txt'; # If no name or e-mail entry template file. $no_register_template = 'template/noregist.txt'; # Successful addition to mailing list template file. $add_to_list = 'template/adtolist.txt'; # Successful addition to mailing list html template file. $add_user = 'template/useraded.txt'; # Successful removal from mailing list template file. $remove_from_list = 'template/remvlist.txt'; # Successful removal from mailing list html template file. $remove_user = 'template/userremv.txt'; # END OF CONFIGURATION. ############################################################### # OPTIONS SECTION # The program can create backup copy of database file every time # e-mail list service runs. For this option you need e-mail service enabled. # Do you want backup? ('yes', 'no') $backup = 'yes'; # The name of backup file. $backupfile = 'datafile.bak'; # This is the list of naughty words, and what you want to convert them to. %badwords = (fuck => 'hug', shit => 'pudding', pecker => 'puppy', asshole => 'angel', bitch => 'nice person', cunt => 'stop watch', ' cock' => ' earlobe', 'cock!' => 'socks!', cocksucker => 'sweetheart', pussy => 'portable wishwasher', ' tit' => ' toe'); ################ define additional variables ################## # Body tag config $bodytag=''; # END OF OPTIONS SECTION # You do not need to change anything below. ############################################################### # Load the CGI.pm module into the program use CGI qw (:standard); use CGI::Carp qw(fatalsToBrowser); $q = new CGI; # Set variables for flock function $EXCLUSIVE = 2; $UNLOCK = 8; # Get the Date for Entry $now_string = localtime; @thetime = split(/ +/,$now_string); @theclock = split(/:/,$thetime[3]); $hour = $theclock[0]; $hour += $timefix; $hour -= 24 if ($hour >= 24); $hour += 24 if ($hour < 0); $xm = ($hour > 11) ? 'pm' : 'am'; $hour = 12 if ($hour == 0); $hour -= 12 if ($hour > 12); $date_local = "$thetime[0] $thetime[1] $thetime[2] $hour:$theclock[1]$xm $zone"; ############################################################### # Get the info from the calling Web page and store the # results in the appropriate variables ############################################################### $action = $q->param(action); $post = $q->param(post); $preview = $q->param(preview); $realname = $q->param(realname); $realname = '' unless ($realname); $user_email = $q->param(user_email); $user_email = '' unless ($user_email); $user_email = '' unless ($user_email =~ /.*\@.*\..*/); $open = '<'; $open = '' unless ($user_email); $close = '>'; $close = '' unless ($user_email); $comments = $q->param(comments); $comments = '' unless ($comments); $comments =~ s/\cM//g; $comments =~ s/\n\n/

/g; $comments =~ s/\n/
/g; # Censor bad words for(keys(%badwords)){ $realname =~ s/$_/$badwords{$_}/gi; } for(keys(%badwords)){ $user_email =~ s/$_/$badwords{$_}/gi; } for(keys(%badwords)){ $comments =~ s/$_/$badwords{$_}/gi; } ############################################################### # Check what task to execute and proceed ############################################################### # First of all check if guest is not in the ban list. &check_ban; if($preview) { # Log the error. &log('no_name') if (($uselog eq 'yes') and (!$realname)); # Check if username exists. &add_record("(You did not enter your Name.)", "realname") unless ($realname); # Log the error. &log('no_comments') if (($uselog eq 'yes') and (!$comments)); # Check if user email exists. &add_record("(You did not enter your Text.)", "comments") unless ($comments); # Preview the message. &preview; # Log the preview. &log('preview') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } if($post) { # Check if admin loging in. # Log the admin access. &log('admin_log') if (($uselog eq 'yes') and ($fullog eq 'yes') and ($realname eq $password)); &admin if ($realname eq $password); # Log the error. &log('no_name') if (($uselog eq 'yes') and (!$realname)); # Check if username exists. &add_record("(You did not enter your Name.)", "realname") unless ($realname); # Log the error. &log('no_comments') if (($uselog eq 'yes') and (!$comments)); # Check if user email exists. &add_record("(You did not enter your Text.)", "comments") unless ($comments); # Preview the message. &post; # Remove tags. $realname =~ s/<.*?>//g; $comments =~ s/<.*?>//g; # Notify webmaster. &mail_webmaster if ($notification eq 'yes'); # Send e-mail to user. &mail_user if (($remote_mail eq 'yes') and ($user_email)); # Log the new entry. &log('entry') if ($uselog eq 'yes'); # Return to the main page. print "Location: $dataurl/index.html\n\n"; exit; } elsif($action =~ /add_record/i){ # Add the record to database. &add_record("(Do not forget to enter your Name and your text.)", "realname"); } elsif($action =~ /edit_text/i){ $num_message = $q->param(num_message); # Admin functions to edit and delete current record. &edit_text; exit; } elsif($action =~ /search_form/i){ # Get the number of pages in the archive(and open database). &pages_in_archive; # Load the search form. &search_form; # Log the search page was loaded. &log('load_search') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } elsif($action =~ /search_database/i){ # Get the number of pages in the archive(and open database). &pages_in_archive; # Search function. $search_for = $q->param('search_for'); $search_field = $q->param('search_field'); $search_for = "\." if $search_for eq ""; &search_database($search_for); $count = @results; if($count < 1) { &no_match; } else { &multiple_match; } exit; } elsif($action =~ /remove_text/i){ $pwd = $q->param('pwd'); # Log the access denied. &log('access_denied') if (($uselog eq 'yes') and ($pwd ne $password)); &access_denied unless ($pwd eq $password); $search_for = $q->param('num_message'); $search_field = 'counter'; &search_database($search_for); &delete_record; # Log the delete entry. &log('delete') if ($uselog eq 'yes'); exit; } elsif($action =~ /modify_record/i){ $pwd = $q->param('pwd'); # Log the access denied. &log('access_denied') if (($uselog eq 'yes') and ($pwd ne $password)); &access_denied unless ($pwd eq $password); $num_message = $q->param('num_message'); &modify_record; # Log the edit entry. &log('edit') if ($uselog eq 'yes'); exit; } elsif($action =~ /archive/i){ # Load archive. $page = $q->param('page'); $page = 0 unless ($page); &archive($page); # Log the archive was loaded. &log('load_archive') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } elsif($action =~ /addremove/i){ # Subscribe and unsubscribe to mailing list. if ($mail_service eq 'yes') { $addremove_choice = $q->param('addremove_choice'); $name = $q->param('name'); $email = $q->param('email'); # Check for valid e-mail address. $email = '' unless ($email =~ /.*\@.*\..*/); # Log the no_register_what. &log('no_register_what') if (($uselog eq 'yes') and (!$addremove_choice) and ($fullog eq 'yes')); &no_register_what unless $addremove_choice; # Log the no name for register. &log('no_register') if (($uselog eq 'yes') and (!$name) and ($fullog eq 'yes')); &no_register unless $name; # Log the no email for register. &log('no_register') if (($uselog eq 'yes') and (!$email) and ($fullog eq 'yes')); &no_register unless $email; &add_remove; } else { &no_mail_service; # Log the no_mail_service. &log('no_mail_service') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } } elsif($action =~ /view_log/i){ # View log file. &view_log; exit; } elsif($action =~ /clear_log/i){ # Clear log file. &clear_log; exit; } elsif($action =~ /view_ban_list/i){ # View ban file. &view_ban_list; exit; } elsif($action =~ /update_ban_list/i){ # Update ban file. $banlist = $q->param('banlist'); &update_ban_list; exit; } elsif($action =~ /view_mail_list/i){ # View mail file. &view_mail_list; exit; } elsif($action =~ /update_mail_list/i){ # Update mail file. $maillist = $q->param('maillist'); &update_mail_list; exit; } elsif($action =~ /ban_current/i){ # Ban oner of current message. $pwd = $q->param('pwd'); # Log the access denied. &log('access_denied') if (($uselog eq 'yes') and ($pwd ne $password)); &access_denied unless ($pwd eq $password); $current_ip = $q->param('current_ip'); &ban_current_user; # Log a user was banned. &log('banned') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } elsif($action =~ /modify_database/i){ # Modify database file. $database_size = $q->param('database_size'); # Open database file. &open_database; # Leave one line if request is higher or equal to number of records. if ($database_size >= $num_lines) { $database_size = $num_lines; } elsif ($database_size <= 0) { $database_size = 0; } &do_modify_database; &admin; exit; } # Print the default page. else { # Check if it is a time to send mail list. &mailservice if ($mail_service eq 'yes'); # Check if a database file is not empty(server error). $database_backup = $datapath."/".$backupfile; &check_database if (($mail_service eq 'yes') and (-e $database_backup)); # Check the time-line. &send_maillist if (($time_to_mail < $^T) and ($mail_service eq 'yes')); &do_backup if (($time_to_mail < $^T) and ($mail_service eq 'yes') and ($backup eq 'yes')); # Get the number of pages in the archive(and open database). &pages_in_archive; &print_default; # Log the visit. &log('visit') if (($uselog eq 'yes') and ($fullog eq 'yes')); exit; } exit; ############################################################### # Subroutines ############################################################### ############################################################### # Load the default page ############################################################### sub print_default { # Open template file. &open_template($guestbook_template); # Print the header of HTML file. print $q->header; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*add_record\*/$ENV{'SCRIPT_NAME'}\?action=add_record/g; $line =~ s/\*search\*/$ENV{'SCRIPT_NAME'}\?action=search_form/g; $line =~ s/\*load_archive\*/$ENV{'SCRIPT_NAME'}\?action=archive&page=$pages_archive/g; $line =~ s/\*path\*/$dataurl/g; print "$line\n"; } # End of foreach. # Limit the $max_records if not acceptable. if ($max_records > $num_lines) {$max_records = $num_lines} # Print all messages from database. for ($i = 0; $i < $max_records; $i++) { foreach $stuff (@data[$i]) { chomp($stuff); ($msg_counter[$i], $current_name[$i], $current_email[$i], $current_date[$i], $current_time[$i], $current_ip[$i], $current_comments[$i]) = split(/\|/,$stuff); # Open template file to format the message. open(DATA, "$datapath/$message_template") or die "Error opening message_template: $!\n"; @data_template = ; close(DATA); chomp(@data_template); # Format the message. foreach $data_template (@data_template){ $data_template =~ s/\*path\*/$dataurl/g; $data_template =~ s/\*number\*/$msg_counter[$i]/g; $data_template =~ s/\*realname\*/$current_name[$i]/g; if($current_email[$i]) { $data_template =~ s/\*user_email\*/$current_email[$i]/g; $data_template =~ s/\*open\*//g; } # End of if. else { $data_template =~ s/\*user_email\*//g; $data_template =~ s/\*open\*//g; $data_template =~ s/\*close\*//g; } # End of else. $data_template =~ s/\*admin_function\*/$ENV{'SCRIPT_NAME'}\?action=edit_text/g; $data_template =~ s/\*date_local\*/$current_date[$i]/g; $data_template =~ s/\*comments\*/$current_comments[$i]/g; print "$data_template\n"; } # End of foreach. } # End of foreach. } # End of for. # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Load guestbook add record page ############################################################### sub add_record { # Displayed text. $warning = $_[0]; # Field to set the focus on. $field = $_[1]; # Open template file. &open_template($adrecord_template); # Print the header of HTML file. print $q->header; foreach $line (@lines){ $line =~ s/\*warning\*/$warning/g; $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; $line =~ s/\*field\*/$field/g; $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*realname\*/$realname/g; $line =~ s/\*user_email\*/$user_email/g; $line =~ s/\*comments\*/$comments/g; print "$line\n"; } # End of foreach. # Print the end of HTML file. print $q->end_html; exit; } # End of subroutine. ############################################################### # Load guestbook preview page ############################################################### sub preview { # Open template file. &open_template($preview_template); # Print the header of HTML file. print $q->header; foreach $line (@lines){ $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*date_local\*/$date_local/g; $line =~ s/\*realname\*/$realname/g; $line =~ s/\*user_email\*/$user_email/g; $line =~ s/\*comments\*/$comments/g; $line =~ s/\*open\*/$open/g; $line =~ s/\*close\*/$close/g; print "$line\n"; } # End of foreach. # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Load guestbook add record page ############################################################### sub post { # Get user address. $remotehost = $ENV{'REMOTE_HOST'}; $remotehost = $ENV{'REMOTE_ADDR'} unless $remotehost; # Open database file. &open_database; # Find the last $msg_counter and increment it for the next record. # The number of the last record. $i = 0; ($msg_counter) = split(/\|/,@data[$i]); $counter = $msg_counter + 1; $record = join '|', $counter,$realname,$user_email,$date_local,$^T,$remotehost,$comments; # Open database file for append. open (DB,">>$datapath/$datafile") or die "Error opening datafile: $!\n"; if ($lockon eq 'yes'){flock DB, $EXCLUSIVE}; seek DB, 0, 2; print DB "$record\n"; if ($lockon eq 'yes'){flock DB, $UNLOCK}; close(DB); } # End of subroutine. ############################################################### # Search function ############################################################### sub search_form { # Open template file. &open_template($search_template); # Print the header of HTML file. print $q->header; # Message responce. $message = 'Type a keyword you want to search for,
choose the category and press the search button.'; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*add_record\*/$ENV{'SCRIPT_NAME'}\?action=add_record/g; $line =~ s/\*search\*/$ENV{'SCRIPT_NAME'}\?action=search_form/g; $line =~ s/\*load_archive\*/$ENV{'SCRIPT_NAME'}\?action=archive&page=$pages_archive/g; $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; $line =~ s/\*message\*/$message/g; $line =~ s/\*search_for\*//g; $line =~ s/\*all_checked\*/checked/g; $line =~ s/\*name_checked\*//g; $line =~ s/\*email_checked\*//g; $line =~ s/\*num_checked\*//g; $line =~ s/\*msg_checked\*//g; print "$line\n"; } # End of foreach. # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Search function ############################################################### sub search_database{ my $search_for = $_[0]; open(DB, "$datapath/$datafile") or die "Error opening datafile: $!\n"; while(){ if($search_field eq "all"){ if(/$search_for/oi){push @results, $_}; } else { ($counter,$realname,$user_email,$date_local,$time_local,$user_ip,$comments)=split(/\|/); if(${$search_field} =~ /$search_for/oi){push @results, $_}; } # End of else. } # End of while. close (DB); # Reverse array to show last messages on the top. @results = reverse(@results); } # End of subroutine. ############################################################### sub multiple_match{ # Open template file. &open_template($search_template); # Print the header of HTML file. print $q->header; # Message responce. $message = 'You searched for: '.$search_for.'. '.$count.' matches are found.'; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*add_record\*/$ENV{'SCRIPT_NAME'}\?action=add_record/g; $line =~ s/\*search\*/$ENV{'SCRIPT_NAME'}\?action=search_form/g; $line =~ s/\*load_archive\*/$ENV{'SCRIPT_NAME'}\?action=archive&page=$pages_archive/g; $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; $line =~ s/\*message\*/$message/g; $line =~ s/\*search_for\*/$search_for/g; # Set default on the radio button. if ($search_field eq 'all') { $line =~ s/\*all_checked\*/checked/g; } else { $line =~ s/\*all_checked\*//g; } if ($search_field eq 'realname') { $line =~ s/\*name_checked\*/checked/g; } else { $line =~ s/\*name_checked\*//g; } if ($search_field eq 'user_email') { $line =~ s/\*email_checked\*/checked/g; } else { $line =~ s/\*email_checked\*//g; } if ($search_field eq 'counter') { $line =~ s/\*num_checked\*/checked/g; } else { $line =~ s/\*num_checked\*//g; } if ($search_field eq 'comments') { $line =~ s/\*msg_checked\*/checked/g; } else { $line =~ s/\*msg_checked\*//g; } print "$line\n"; } # End of foreach. # A number of lines $found_records = $#results + 1; # Print found messages from database. for ($i = 0; $i < $found_records; $i++) { foreach $stuff (@results[$i]) { chomp($stuff); ($msg_counter[$i], $current_name[$i], $current_email[$i], $current_date[$i], $current_time[$i], $current_ip[$i], $current_comments[$i]) = split(/\|/,$stuff); # Open template file to format the message. open(DATA, "$datapath/$message_template") or die "Error opening message_template: $!\n"; @data_template = ; close(DATA); chomp(@data_template); # Format the message. foreach $data_template (@data_template){ $data_template =~ s/\*path\*/$dataurl/g; $data_template =~ s/\*number\*/$msg_counter[$i]/g; $data_template =~ s/\*realname\*/$current_name[$i]/g; if($current_email[$i]) { $data_template =~ s/\*user_email\*/$current_email[$i]/g; $data_template =~ s/\*open\*//g; } # End of if. else { $data_template =~ s/\*user_email\*//g; $data_template =~ s/\*open\*//g; $data_template =~ s/\*close\*//g; } # End of else. $data_template =~ s/\*admin_function\*/$ENV{'SCRIPT_NAME'}\?action=edit_text/g; $data_template =~ s/\*date_local\*/$current_date[$i]/g; $data_template =~ s/\*comments\*/$current_comments[$i]/g; print "$data_template\n"; } # End of foreach. } # End of foreach. } # End of for. # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### sub no_match{ # Open template file. &open_template($search_template); # Print the header of HTML file. print $q->header; # Message responce. $message = 'There were no matches for: '.$search_for.'. Please try again.'; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*add_record\*/$ENV{'SCRIPT_NAME'}\?action=add_record/g; $line =~ s/\*search\*/$ENV{'SCRIPT_NAME'}\?action=search_form/g; $line =~ s/\*load_archive\*/$ENV{'SCRIPT_NAME'}\?action=archive&page=$pages_archive/g; $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; $line =~ s/\*message\*/$message/g; $line =~ s/\*search_for\*/$search_for/g; # Set default on the radio button. if ($search_field eq 'all') { $line =~ s/\*all_checked\*/checked/g; } else { $line =~ s/\*all_checked\*//g; } if ($search_field eq 'realname') { $line =~ s/\*name_checked\*/checked/g; } else { $line =~ s/\*name_checked\*//g; } if ($search_field eq 'user_email') { $line =~ s/\*email_checked\*/checked/g; } else { $line =~ s/\*email_checked\*//g; } if ($search_field eq 'counter') { $line =~ s/\*num_checked\*/checked/g; } else { $line =~ s/\*num_checked\*//g; } if ($search_field eq 'comments') { $line =~ s/\*msg_checked\*/checked/g; } else { $line =~ s/\*msg_checked\*//g; } print "$line\n"; } # End of foreach. # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Edit and delete current record ############################################################### sub edit_text { # Open template file. &open_template($remtext_template); # Print the header of HTML file. print $q->header; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*path\*/$dataurl/g; print "$line\n"; } # End of foreach. open(DB, "$datapath/$datafile") or die "Error opening datafile: $!\n"; while(){ ($msg_counter,$current_name,$current_email,$current_date,$current_time,$current_ip,$current_comments)=split(/\|/); # Find the match. if($msg_counter =~ /$num_message/oi){ # Open template file to format the message. open(DATA, "$datapath/$message_template"); @data_template = ; close(DATA); chomp(@data_template); # Format the message. foreach $data_template (@data_template){ $data_template =~ s/\*path\*/$dataurl/g; $data_template =~ s/\*number\*/$msg_counter/g; $data_template =~ s/\*realname\*/$current_name/g; if($current_email) { $data_template =~ s/\*user_email\*/$current_email/g; $data_template =~ s/\*open\*//g; } # End of if. else { $data_template =~ s/\*user_email\*//g; $data_template =~ s/\*open\*//g; $data_template =~ s/\*close\*//g; } # End of else. $data_template =~ s/\*admin_function\*/$ENV{'SCRIPT_NAME'}/g; $data_template =~ s/\*date_local\*/$current_date/g; $data_template =~ s/\*comments\*/$current_comments/g; print "$data_template\n"; } # End of foreach. last; } # End of if. } # End of while. # Print the form. print "

\n"; print "\n"; # Print the form with the selected message in the textarea. print "\n"; # Print the form with ban user function. print "\n"; print "
\n"; print "
\n"; print "Do you want to delete this message\?
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "You can edit this message.
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Delete the record ############################################################### sub delete_record { # The name of database file. $tempfile = 'datafile.tmp'; $tempfile = $datapath."/".$tempfile; $database = $datapath."/".$datafile; system "cp $database $tempfile"; open(DB, $database) or die "Error opening database: $!\n"; open (TEMP, ">$tempfile") or die "Error opening tempfile(delete record): $!\n"; if ($lockon eq 'yes'){flock TEMP, $EXCLUSIVE}; while(){ $match=""; ($msg_counter,$current_name,$current_email,$current_date,$current_time,$current_ip,$current_comments)=split(/\|/); if($msg_counter == $search_for){$match=1;} print TEMP $_ unless ($match == 1); } # End of while loop. close(TEMP); close(DB); if ($lockon eq 'yes'){flock DB, $EXCLUSIVE}; unlink($database); rename($tempfile,$database); if ($lockon eq 'yes'){flock DB, $UNLOCK}; if ($lockon eq 'yes'){flock TEMP, $UNLOCK}; # Print the header of HTML file. print $q->header; print "The Message was deleted.$bodytag\n"; print "

"; print "The Message was deleted.
"; print "Back to Guestbook"; print "
"; # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Modify the record ############################################################### sub modify_record { # The name of database file. $tempfile = 'datafile.tmp'; $tempfile = $datapath."/".$tempfile; $database = $datapath."/".$datafile; system "cp $database $tempfile"; open(DB, $database) or die "Error opening database: $!\n"; open (TEMP, ">$tempfile") or die "Error opening tempfile(modify record): $!\n"; if ($lockon eq 'yes'){flock TEMP, $EXCLUSIVE}; while(){ $match=""; ($msg_counter,$current_name,$current_email,$current_date,$current_time,$current_ip,$current_comments)=split(/\|/); if($msg_counter == $num_message) { $record = join '|', $num_message,$current_name,$current_email,$current_date,$current_time,$current_ip,$comments; print TEMP "$record\n"; } else { print TEMP $_; } # End of if. } # End of while loop. close(TEMP); close(DB); if ($lockon eq 'yes'){flock DB, $EXCLUSIVE}; unlink($database); rename($tempfile,$database); if ($lockon eq 'yes'){flock DB, $UNLOCK}; if ($lockon eq 'yes'){flock TEMP, $UNLOCK}; # Print the header of HTML file. print $q->header; print "The Message was modified.$bodytag\n"; print "

"; print "The Message was modified.
"; print "Back to Guestbook"; print "
"; # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Modify the record ############################################################### sub access_denied { print "Content-type: text/html\n\n"; print "ACCESS DENIED.$bodytag\n"; print "

"; print "The Password is wrong. You do not have access to this function.
"; print "Back to Guestbook"; print "
"; print ''; exit; } # End of subroutine. ############################################################### # Archive function ############################################################### sub archive { # Get requested page number. $page = $_[0]; # Open template file. &open_template($archive_template); # Get the number of pages in the archive(and open database). &pages_in_archive; # Check if requested page exists. if ($page > $pages_archive) { $page = 0; &archive($page); exit; } # Print the header of HTML file. print $q->header; # Write the line of HTML file. foreach $line (@lines){ $line =~ s/\*path\*/$dataurl/g; $line =~ s/\*counter\*/$pages_archive/g; $line =~ s/\*page\*/$page/g; $line =~ s/\*program\*/$ENV{'SCRIPT_NAME'}/g; print "$line\n"; } # End of foreach. @data = reverse(@data); # First record on this page. $first_record = ($page - 1) * $records_archive - 1; # Last record on this page. $last_record = $first_record + $records_archive; # Check the limit. $last_record = ($num_lines - $max_records - 1) if ($last_record > ($num_lines - $max_records - 1)); if ($page ne 0) { # Load messages. # Print selected messages from the database. for ($i = $last_record; $i > $first_record; $i--) { foreach $stuff (@data[$i]) { chomp($stuff); ($msg_counter[$i], $current_name[$i], $current_email[$i], $current_date[$i], $current_time[$i], $current_ip[$i], $current_comments[$i]) = split(/\|/,$stuff); # Open template file to format the message. open(DATA, "$datapath/$message_template") or die "Error opening message_template: $!\n"; @data_template = ; close(DATA); chomp(@data_template); # Format the message. foreach $data_template (@data_template){ $data_template =~ s/\*path\*/$dataurl/g; $data_template =~ s/\*number\*/$msg_counter[$i]/g; $data_template =~ s/\*realname\*/$current_name[$i]/g; if($current_email[$i]) { $data_template =~ s/\*user_email\*/$current_email[$i]/g; $data_template =~ s/\*open\*//g; } # End of if. else { $data_template =~ s/\*user_email\*//g; $data_template =~ s/\*open\*//g; $data_template =~ s/\*close\*//g; } # End of else. $data_template =~ s/\*admin_function\*/$ENV{'SCRIPT_NAME'}\?action=edit_text/g; $data_template =~ s/\*date_local\*/$current_date[$i]/g; $data_template =~ s/\*comments\*/$current_comments[$i]/g; print "$data_template\n"; } # End of foreach. } # End of foreach. } # End of for. # Print the end of page. } # End of if. print<       Copyright © Amnesia.net, 1999.
      All Rights Reserved.
HTML # Print the end of HTML file. print $q->end_html; } # End of subroutine. ############################################################### # Notify webmaster ############################################################### sub mail_webmaster { # Get user address. $remotehost = $ENV{'REMOTE_HOST'}; $remotehost = $ENV{'REMOTE_ADDR'} unless $remotehost; open (MAIL, "|$mail_program $sitemail") || die "Can't open $mail_program!\n"; print MAIL "Subject: $subject_notify\n"; print MAIL "To: $sitename < $sitemail >\n"; print MAIL "From: $sitename < $sitemail >\n"; print MAIL "$subject_notify\n"; print MAIL "_____________________________________________________\n"; print MAIL "$realname" ; print MAIL " <$user_email>\n"; print MAIL "$comments\n"; print MAIL "$date_local\n"; print MAIL "$remotehost\n"; close (MAIL); return; } ############################################################### # Send e-mail to user ############################################################### sub mail_user { open (MAIL, "|$mail_program $user_email") || die "Can't open $mail_program!\n"; print MAIL "Subject: $subject_mail_user\n"; print MAIL "To: $realname < $user_email >\n"; print MAIL "From: $sitename < $sitemail >\n"; print MAIL "$subject_mail_user\n"; print MAIL "_____________________________________________________\n"; print MAIL "$realname" ; print MAIL " <$user_email>\n"; print MAIL "$comments\n"; print MAIL "$date_local\n"; close (MAIL); return; } ############################################################### # A number of pages in the archive sub pages_in_archive { # Open database file. &open_database; # Count pages according to a number of records in the archive. # and a number of records to show on the archive page. # A number of records in the archive. $archive_records = $num_lines - $max_records; # Get the number of pages in archive. $arl = ($archive_records/$records_archive); $aint = int ($archive_records/$records_archive); # Adjust a number of pages. if ($arl > $aint) { $pages_archive = $aint + 1; } else { $pages_archive = $aint; } return; } # End of subroutine. ############################################################### # Open template file Sub ############################################################### sub open_template { $file = $_[0]; open(TEMPLATE, "$datapath/$file") or die "Error opening $file: $!\n"; @lines =