My guestbook
Here's my guestbook. You can add your own comment using the form at the bottom of the page.
EndOfText if ($action eq 'Add comment') { # process the form submission # and assemble the guestbook entry $name = $query->param('name'); $city = $query->param('city'); $state = $query->param('state'); $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/</g; # untaint variable unless ($name =~ /^([^<]*)$/) { die "couldn't untaint name: $name\n"; } $name = $1; # clean up and fiddle with $from_where $from_where = "$city, $state, $country"; $from_where =~ s/, , /, /; # remove duplicate ', ' $from_where =~ s/^, //; # remove initial ', ' $from_where =~ s/, $//; # remove final ', ' if ($from_where =~ /^[,\s]+$/) { # nothing but commas and whitespace $from_where = 'parts unknown'; } if (length($from_where) > 75) { $from_where = 'somewhere with a really long name'; } # disable HTML tags $from_where =~ s/</g; # untaint variable unless ($from_where =~ /^([^<]*)$/) { die "couldn't untaint from_where: $from_where\n"; } $from_where = $1; # clean up and fiddle with $comment if (length($comment) > 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/</g; # untaint variable unless ($comment =~ /^([^<]*)$/) { die "couldn't untaint comment: $comment\n"; } $comment = $1; # assemble finished guestbook entry $entry = <<"EndOfText";
$name from $from_where wrote:
$comment
EndOfText # open non-destructively, read old entries, write out new sysopen(ENTRIES, "$data_file", O_RDWR) or die "can't open $data_file: $!"; flock(ENTRIES, 2) or die "can't LOCK_EX $data_file: $!"; while(
/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 "can't rewind $data_file: $!"; truncate(ENTRIES, 0) or die "can't truncate $data_file: $!"; print ENTRIES $all_entries or die "can't print to $data_file: $!"; close(ENTRIES) or die "can't close $data_file: $!"; } # display the guestbook open (IN, "$data_file") or die "Can't open $data_file for reading: $!"; flock(IN, 1) or die "Can't get LOCK_SH on $data_file: $!"; while (