#!/usr/bin/perl -Tw # print "Content-type: text/html\n\n"; #$sendmail = '/usr/sbin/sendmail'; # where is sendmail? #$recipient = 'andrew.jenkins@dsl.pipex.com'; # who gets the form data? #$sender = 'Anonymous User '; # default sender? #$site_name = 'http://r75.sytes.net'; # name of site to return to afterwards #$site_url = 'http://r75.sytes.net'; # URL of site to return to afterwards $data_file = '/var/www/html/r75/guestbook.txt'; $max_entries = 50; # 0 for infinite. use CGI; use Fcntl; $query = new CGI; unless ($action = $query->param('action')) { $action = 'none'; } print <<"TextEnd"; Guestbook.
Your chance to add your comments or suggestions.

My Guestbook

Well, finally the moron who was destroying this guestbook has gone to find someone else to annoy (although I've lost all my previous comments). So as you've come this far please leave something, nice if possible. Scroll to the bottom of the page where you'll find the required form.
TextEnd if ($action eq 'Add comment') { # process the form submission # and assemble the guestbook entry $name = $query->param('name'); $city = $query->param('city'); $country = $query->param('country'); $comment = $query->param('comment'); # clean up and fiddle with $name unless ($name) { $name = 'Anonymous'; } if (length($name) > 50) { $name = 'Someone with a really long name'; } # disable all HTML tags $name =~ s/ 75) { $from_where = 'somewhere with a really long name'; } # disable HTML tags $from_where =~ s/ 32768) { $comment = '...more than I feel like posting in my guestbook.'; } unless ($comment) { $comment = '...nothing to speak of.'; } # fix line-endings $comment =~ s/\r\n?/\n/g; # lose HTML tags $comment =~ s/$name from $from_where wrote:
$comment


Endof # open non-destructively, read old entries, write out new sysopen(ENTRIES, "$data_file", O_RDWR) or die "can't open $data_ $!"; flock(ENTRIES, 2) or die "can't LOCK_EX $data_ $!"; while() { $all_entries .= $_; } $all_entries .= $entry; if ($max_entries) { # lop the head off the guestbook, if necessary @all_entries = split(/
/i, $all_entries); $entry_count = @all_entries - 1; while ($entry_count > $max_entries) { shift @all_entries; $entry_count = @all_entries - 1; } $all_entries = join('
', @all_entries); } # now write out to $data_file seek(ENTRIES, 0, 0) or die "cannot rewind $data_ $!"; truncate(ENTRIES, 0) or die "cannot truncate $data_ $!"; print ENTRIES $all_entries or die "cannot print to $data_ $!"; close(ENTRIES) or die "cannot close $data_ $!"; } # display the guestbook open (IN, "$data_file") or die "Cannot open $data_file for reading: $!"; flock(IN, 1) or die "Cannot get LOCK_SH on $data_ $!"; while () { print; } close IN or die "Cannot close $data_ $!"; # display the form print <<"EndOfText";

Add a comment to the guestbook (no HTML):

Name:
Town/City:
Country:
Comment:
—> Home Page

—> FAQ's 'n' Fixes

—> Classifieds

—> Parts Suppliers

—> Photos

—> History

—> Contacts





[   Home  |   Contacts   ]

Copyright © 2005 by Andrew David Jenkins.
EndOfText