I can't get the script below to work. Nor can anyone else, judging by the postings at the script's support forum! I've checked that all permissions are correct and the path variables are correct. It is the admin utility for a script Called Tip o the Day, which posts a new daily tip every day to a web page. The admin script (below) allows the user to add new daily tips for the main script to display. I can anly assume there's something uncool about the code. When I tried running the script via Telnet, the debug text pointed to an error near line 30 (The section that's headed "Don't Alter Anything Below This Line") However, I know those debug messages are often misguided. I've tried running it on unix and Win95 servers.
Here's the script.. THANKS A MILLION for any help:
#!/usr/bin/perl
############################################
## ##
## WebHints (Add) ##
## by Darryl Burgdorf ##
## (e-mail burgdorf@awsd.com) ##
## ##
## version: 1.02 ##
## last modified: 1/4/00 ##
## copyright (c) 2000 ##
## ##
## latest version is available from ##
## http://awsd.com/scripts/ ##
## ##
############################################
# ASSIGN THE FOLLOWING VARIABLES
$HintsDir = "hints";
$NewHintsDir = "newhints";
$DataFile = "newhints/lasthint.txt";
$AddURL = "http://127.0.0.1/cgi-bin/daytips/hints_add.pl";
$HintsTitle = "Tip of the Day";
$BodySpec = "";
# DON'T ALTER ANYTHING BELOW THIS LINE
@months =
(January,February,March,April,May,June,
July,August,September,October,November,December);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($val1, $val2) = split(/=/, $pair);
$val1 =~ tr/+/ /;
$val1 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$val2 =~ tr/+/ /;
$val2 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($FORM{$val1}) {
$FORM{$val1} = "$FORM{$val1}, $val2";
}
else {
$FORM{$val1} = $val2;
}
}
print "Content-type: text/html\n\n";
&Get_Date;
if ($FORM{'Hint'}) {
&AddHint;
}
print "<HTML><HEAD><TITLE>$HintsTitle</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=CENTER>Add New Entry</H1>\n";
print "<H2 ALIGN=CENTER>for $date</H2>\n";
print "<CENTER><FORM METHOD=POST ACTION=\"$AddURL\">\n";
print "<INPUT TYPE=HIDDEN NAME=\"Hint\" VALUE=\"$hint\">\n";
print "<P>Title: <INPUT TYPE=TEXT NAME=\"Title\" SIZE=40>\n";
print "<P>Body:\n";
print "<BR><TEXTAREA COLS=80 ROWS=10 NAME=\"Body\" WRAP=VIRTUAL>\n";
print "</TEXTAREA>\n";
print "<P>Does the above text already include HTML tags?\n";
print "<BR><INPUT TYPE=RADIO NAME=\"AddHTML\" VALUE=\"No\"> Yes ";
print "<INPUT TYPE=RADIO NAME=\"AddHTML\" VALUE=\"Yes\" CHECKED> No\n";
print "<P><INPUT TYPE=SUBMIT VALUE=\"Add Entry\">\n";
print "</P></FORM></CENTER></BODY></HTML>\n";
exit;
sub Get_Date {
if ($FORM{'Hint'}) {
$hint = $FORM{'Hint'};
}
elsif (!$hint) {
open (LASTHINT,"$DataFile") || &Error_File;
$hint = <LASTHINT>;
close (LASTHINT);
$hint = $hint+86400;
$time = time;
unless ($hint > $time) {
$hint = $time;
}
}
else {
$hint = $hint+86400;
}
($mday,$mon,$year) = (localtime($hint))[3,4,5];
$year += 1900;
$date = "$mday $months[$mon] $year";
$mon = $mon+1;
if ($mon < 10) { $mon = "0".$mon; }
if ($mday < 10) { $mday = "0".$mday; }
$filename = "$year"."$mon"."$mday".".txt";
if ((!$FORM{'Hint'}) && (-e "$NewHintsDir/$filename")) {
&Get_Date;
}
}
sub AddHint {
$FORM{'Title'} =~ s/\&/\&\;/g;
$FORM{'Title'} =~ s/"/\"\;/g;
$FORM{'Title'} =~ s/</\<\;/g;
$FORM{'Title'} =~ s/>/\>\;/g;
if ($FORM{'AddHTML'} eq "Yes") {
$FORM{'Body'} =~ s/\&/\&\;/g;
$FORM{'Body'} =~ s/"/\"\;/g;
$FORM{'Body'} =~ s/</\<\;/g;
$FORM{'Body'} =~ s/>/\>\;/g;
$FORM{'Body'} =~ s/\cM\n/<BR>/g;
$FORM{'Body'} =~ s/\n\cM/<BR>/g;
$FORM{'Body'} =~ s/\cM/<BR>/g;
$FORM{'Body'} =~ s/\n/<BR>/g;
$FORM{'Body'} =~ s/<BR>\s\s\s+/<BR><BR>/g;
$FORM{'Body'} =~ s/<BR>\t/<BR><BR>/g;
$FORM{'Body'} =~ s/\s+/ /g;
$FORM{'Body'} =~ s/<BR>\s/<BR>/g;
$FORM{'Body'} =~ s/\s<BR>/<BR>/g;
$FORM{'Body'} =~ s/<BR><BR>/<P>/g;
$FORM{'Body'} =~ s/<P><BR>/<P>/g;
$FORM{'Body'} =~ s/<BR>/ /g;
$FORM{'Body'} =~ s/<P>/\n<P>/g;
$FORM{'Body'} =~ s/<P>\n/\n/g;
$FORM{'Body'} = "<P>"."$FORM{'Body'}";
}
unless ($FORM{'Body'} && $FORM{'Title'}) {
print "<HTML><HEAD><TITLE>Oops!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>Incomplete Submission!</H1>\n";
print "<P ALIGN=CENTER>Sorry, but your submission must ";
print "include both a <STRONG>Title</STRONG> and a ";
print "<STRONG>Body</STRONG>! ";
print "Please go "Back" and try again!</P>\n";
print "</BODY></HTML>\n";
exit;
}
open (HINT,">$NewHintsDir/$filename") || &Error_File;
print HINT "TITLE: $FORM{'Title'}\n\n";
print HINT "$FORM{'Body'}\n";
close (HINT);
open (LASTHINT,">$DataFile") || &Error_File;
print LASTHINT "$FORM{'Hint'}";
close (LASTHINT);
print "<HTML><HEAD><TITLE>Entry Added!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>The New Entry Has Been Added!</H1>\n";
print "<P ALIGN=CENTER>"$FORM{'Title'}" ";
print "has successfully been added to the database. ";
print "It will appear on $date.\n";
print "<P ALIGN=CENTER><STRONG>[ To add another entry, ";
print "just "reload" this page! ]</STRONG></P>\n";
print "</BODY></HTML>\n";
exit;
}
sub Error_File {
print "<HTML><HEAD><TITLE>Oops!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>File Error!</H1>\n";
print "<P ALIGN=CENTER>The server encountered an error while ";
print "trying to access a data file! Make sure that the files ";
print "and directories are correctly assigned in the script ";
print "and that all permissions are correct. (The hints ";
print ""counter" file and both hints directories ";
print "should be set world-writable!)</P>\n";
print "</BODY></HTML>\n";
exit;
}
#-------------------------End of script TIA, Alan A
Here's the script.. THANKS A MILLION for any help:
#!/usr/bin/perl
############################################
## ##
## WebHints (Add) ##
## by Darryl Burgdorf ##
## (e-mail burgdorf@awsd.com) ##
## ##
## version: 1.02 ##
## last modified: 1/4/00 ##
## copyright (c) 2000 ##
## ##
## latest version is available from ##
## http://awsd.com/scripts/ ##
## ##
############################################
# ASSIGN THE FOLLOWING VARIABLES
$HintsDir = "hints";
$NewHintsDir = "newhints";
$DataFile = "newhints/lasthint.txt";
$AddURL = "http://127.0.0.1/cgi-bin/daytips/hints_add.pl";
$HintsTitle = "Tip of the Day";
$BodySpec = "";
# DON'T ALTER ANYTHING BELOW THIS LINE
@months =
(January,February,March,April,May,June,
July,August,September,October,November,December);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($val1, $val2) = split(/=/, $pair);
$val1 =~ tr/+/ /;
$val1 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$val2 =~ tr/+/ /;
$val2 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($FORM{$val1}) {
$FORM{$val1} = "$FORM{$val1}, $val2";
}
else {
$FORM{$val1} = $val2;
}
}
print "Content-type: text/html\n\n";
&Get_Date;
if ($FORM{'Hint'}) {
&AddHint;
}
print "<HTML><HEAD><TITLE>$HintsTitle</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=CENTER>Add New Entry</H1>\n";
print "<H2 ALIGN=CENTER>for $date</H2>\n";
print "<CENTER><FORM METHOD=POST ACTION=\"$AddURL\">\n";
print "<INPUT TYPE=HIDDEN NAME=\"Hint\" VALUE=\"$hint\">\n";
print "<P>Title: <INPUT TYPE=TEXT NAME=\"Title\" SIZE=40>\n";
print "<P>Body:\n";
print "<BR><TEXTAREA COLS=80 ROWS=10 NAME=\"Body\" WRAP=VIRTUAL>\n";
print "</TEXTAREA>\n";
print "<P>Does the above text already include HTML tags?\n";
print "<BR><INPUT TYPE=RADIO NAME=\"AddHTML\" VALUE=\"No\"> Yes ";
print "<INPUT TYPE=RADIO NAME=\"AddHTML\" VALUE=\"Yes\" CHECKED> No\n";
print "<P><INPUT TYPE=SUBMIT VALUE=\"Add Entry\">\n";
print "</P></FORM></CENTER></BODY></HTML>\n";
exit;
sub Get_Date {
if ($FORM{'Hint'}) {
$hint = $FORM{'Hint'};
}
elsif (!$hint) {
open (LASTHINT,"$DataFile") || &Error_File;
$hint = <LASTHINT>;
close (LASTHINT);
$hint = $hint+86400;
$time = time;
unless ($hint > $time) {
$hint = $time;
}
}
else {
$hint = $hint+86400;
}
($mday,$mon,$year) = (localtime($hint))[3,4,5];
$year += 1900;
$date = "$mday $months[$mon] $year";
$mon = $mon+1;
if ($mon < 10) { $mon = "0".$mon; }
if ($mday < 10) { $mday = "0".$mday; }
$filename = "$year"."$mon"."$mday".".txt";
if ((!$FORM{'Hint'}) && (-e "$NewHintsDir/$filename")) {
&Get_Date;
}
}
sub AddHint {
$FORM{'Title'} =~ s/\&/\&\;/g;
$FORM{'Title'} =~ s/"/\"\;/g;
$FORM{'Title'} =~ s/</\<\;/g;
$FORM{'Title'} =~ s/>/\>\;/g;
if ($FORM{'AddHTML'} eq "Yes") {
$FORM{'Body'} =~ s/\&/\&\;/g;
$FORM{'Body'} =~ s/"/\"\;/g;
$FORM{'Body'} =~ s/</\<\;/g;
$FORM{'Body'} =~ s/>/\>\;/g;
$FORM{'Body'} =~ s/\cM\n/<BR>/g;
$FORM{'Body'} =~ s/\n\cM/<BR>/g;
$FORM{'Body'} =~ s/\cM/<BR>/g;
$FORM{'Body'} =~ s/\n/<BR>/g;
$FORM{'Body'} =~ s/<BR>\s\s\s+/<BR><BR>/g;
$FORM{'Body'} =~ s/<BR>\t/<BR><BR>/g;
$FORM{'Body'} =~ s/\s+/ /g;
$FORM{'Body'} =~ s/<BR>\s/<BR>/g;
$FORM{'Body'} =~ s/\s<BR>/<BR>/g;
$FORM{'Body'} =~ s/<BR><BR>/<P>/g;
$FORM{'Body'} =~ s/<P><BR>/<P>/g;
$FORM{'Body'} =~ s/<BR>/ /g;
$FORM{'Body'} =~ s/<P>/\n<P>/g;
$FORM{'Body'} =~ s/<P>\n/\n/g;
$FORM{'Body'} = "<P>"."$FORM{'Body'}";
}
unless ($FORM{'Body'} && $FORM{'Title'}) {
print "<HTML><HEAD><TITLE>Oops!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>Incomplete Submission!</H1>\n";
print "<P ALIGN=CENTER>Sorry, but your submission must ";
print "include both a <STRONG>Title</STRONG> and a ";
print "<STRONG>Body</STRONG>! ";
print "Please go "Back" and try again!</P>\n";
print "</BODY></HTML>\n";
exit;
}
open (HINT,">$NewHintsDir/$filename") || &Error_File;
print HINT "TITLE: $FORM{'Title'}\n\n";
print HINT "$FORM{'Body'}\n";
close (HINT);
open (LASTHINT,">$DataFile") || &Error_File;
print LASTHINT "$FORM{'Hint'}";
close (LASTHINT);
print "<HTML><HEAD><TITLE>Entry Added!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>The New Entry Has Been Added!</H1>\n";
print "<P ALIGN=CENTER>"$FORM{'Title'}" ";
print "has successfully been added to the database. ";
print "It will appear on $date.\n";
print "<P ALIGN=CENTER><STRONG>[ To add another entry, ";
print "just "reload" this page! ]</STRONG></P>\n";
print "</BODY></HTML>\n";
exit;
}
sub Error_File {
print "<HTML><HEAD><TITLE>Oops!</TITLE></HEAD>\n";
print "<BODY $BodySpec>\n";
print "<H1 ALIGN=CENTER>File Error!</H1>\n";
print "<P ALIGN=CENTER>The server encountered an error while ";
print "trying to access a data file! Make sure that the files ";
print "and directories are correctly assigned in the script ";
print "and that all permissions are correct. (The hints ";
print ""counter" file and both hints directories ";
print "should be set world-writable!)</P>\n";
print "</BODY></HTML>\n";
exit;
}
#-------------------------End of script TIA, Alan A