#!/bin/perl # ############################### ## addguestCH141 ################################ ## This script, which I denoted "addguest", is called by submitting an entry ## from the guestbook page. This script mails the owner that a person has ## signed the guest book, unless no name is specified, in which case an ## error page is shown to the guest. Otherwise the guest gets a thank you ## page with a pointer to his name in the guestbook, the guestbook itself, ## and the return page specified. ################################ # # keys: name, from, email, html, pname, note, comment # QUERY_STRING should be of the form: # http://domain/scriptname?owner?guestpage?returnpage # W3 root addresses (http version & server version) no trailing slashes $wwwroot = "http://www.colby.edu"; # This is the DocumentRoot of the W3 server, needed for root guestbooks only $wwwserverroot = "/data/htdocs"; # domain name for addressing $domain = "\@colby.edu"; # mail program that is opened with a pipe $mailprog = "/usr/lib/sendmail -t -oi -oem"; # This gets the necessary info from the QUERY_STRING ($owner, $guestpage, $returnpage) = split('\?', $ENV{QUERY_STRING}); die "Content-type: text/plain\n\nLack of information sent to script, stopped" unless ($owner && $guestpage); if ($owner ne "root") { @val = getpwnam($owner); $dir = @val[7]; if (!$dir) { die "Content-type: text/plain\n\n$owner is not a valid user, stopped"; } $returnpage = "$wwwroot/~$owner/$returnpage"; $htmlpage = "$wwwroot/~$owner/$guestpage"; $guestpage = "$dir/public_html/$guestpage"; $address = "$owner$domain"; } else { $dir = $wwwserverroot; $returnpage = "$wwwroot/$returnpage"; $htmlpage = "$wwwroot/$guestpage"; $guestpage = "$dir/$guestpage"; $owner = "bpmundy"; $address = "$owner$domain"; } $date = `date`; chop $date; # Get info from form and parse it read(STDIN, $raw_data, $ENV{CONTENT_LENGTH}); $items = split('&', $raw_data); for ($i = 0; $i < $items; $i++) { ($key,$value) = split('=', $_[$i]); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $data{"$key"} = $value; } $rname = $data{name}; $rname =~ tr/ /+/; $rname =~ tr/[A-Z]/[a-z]/; if ($data{name}) { if (!$data{pname}) { $data{pname} = $data{html}; } open(GUESTS, ">> $guestpage") || die "Content-type: text/plain\n\nCan't open forum: $!\n"; print GUESTS "
\n";
print GUESTS "\n";
print GUESTS "Entered: $date
\n\n";
close(GUESTS);
print <
$data{name},
You can, if you'd like, read your entry (you may need to reload the page) in
the context of the ongoing discussion or just return
to the General Chemistry page.