Created a script some time ago. Had almost forgotten all about it when I
found it on my computer, hidden in the deepest caves of Windows 98.
Well, I had given up on the script and now I dont know why. It is a link game
archive. I can search after some links and info I got in a file and now I'm
having problems with the "post new" script.
Its quite long so take your time and help me find out what is wrong. I'm no
expert and terrible at finding errors in script. Is there another smart, fast en
secure way to find errors inside scripts?
Please let me know.
The script(add.cgi):
#!/usr/bin/perl
#
#
# Title: Games Pages
#
# (C) Copyright 2002-2004
# All rights reserved.
print "Content-type:text/html\n\n";
if ({'QUERY_STRING'} eq "write") {
&parseform;
✓
&write;
}
else {
print <<FORMfields;
<html><head><title>Add Games</title></head>
<body>
<h2 align="Center">Add Games</h2>
Wanna add a cool game to our archive? No problem!<br>
Just use the form belove. Fill in the required information(the ones with a
<font color="light blue">*</font> next to it)<br>
and press the Send button! Easy!<p>
<form action="add.cgi?write" method="Post">
<STYLE TYPE="text/css">
TD {
font-size:12
}
</STYLE>
<TABLE BORDER="0" CELLSPACING="0">
<TR>
<TD>The games name:<BR><INPUT TYPE="text" NAME="name"> <FONT
COLOR="lightblue">*</FONT></TD>
<TD>The games link:<BR><INPUT TYPE="text" VALUE="http://"
NAME="link"> <FONT COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD>Picture address:<BR><INPUT TYPE="text"
VALUE="http://www.myhost.com/gamepicture.jpg" NAME="picture"></TD>
<TD>Your rating of the game<BR>(from 1 to 10 where 10 is
best):<BR><INPUT TYPE="text" NAME="rating"> <FONT
COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD>Clicks to start with? (between 1-50)<BR><INPUT TYPE="text"
NAME="clicks"></TD>
<TD>In what category is the game?<BR><SELECT SIZE="1" NAME="cat">
<OPTION>Sport
<OPTION>Action
<OPTION>Adventure
<OPTION>Skiing
<OPTION>Strategy
<OPTION>Car game
<OPTION>Other
</SELECT> <FONT COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD VALIGN="middle">Description (Max 150 letters):<BR><TEXTAREA
WRAP="physical" ROWS="4" COLS="20" NAME="description"></TEXTAREA> <FONT
COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD><INPUT TYPE="submit" VALUE="Send"> <INPUT TYPE="reset"
VALUE="Erase"></TD>
</TABLE>
</form><p>
FORMfields
} # stop else
# the subroutines..
# parse form
sub parseform {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split (/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$value =~ s/\r//g;
$value =~ s/\cM//g;
$FORM{$name} = $value;
}
# the check sub
sub check {
$picture = $FORM{'picture'};
$rating = $FORM{'rating'};
$click = $FORM{'clicks'};
$description = $FORM{'description'};
$lenghtofdesc = length ($description);
# If no title, boooom, error!
if ($FORM{'name'} eq "") {
error("Please write in a name for the game. You must fill in all the fields
marked with a <font color=lightblue>*</font>\n");
}
# Checking if a url has been posted.
elsif ($FORM{'link'} eq "" or $FORM{'link'} eq "http://") {
error("It seems to be a problem with the link to the game's webpage. You
must fill in all the required fields. \n");
}
# Test if the visitor wants to use a picture or not.
if ($FORM{'picture'} eq "http://www.myhost.com/gamepicture.jpg" or $FORM
{'picture'} eq "") {
$picturelink = "noimage.jpg";
}
# Check if the visitor has posted a jpg or a gif image. If not, error.
elsif ($picture !~ /\.jpg$/i or $picture !~ /\.gif$/i) {
error("If you want to use a picture it must be a .jpg or .gif picture. We
don't support .bmp or other types.\n");
}
# Let's find out what the rating is set to and if it has crossed the borders.
if ($FORM{'rating'} eq "") {
error("Please set a rating to the game. A number between 1 and 10 will do
fine. 10 is best, 1 is worst.\n");
}
elsif ($rating !~ /\d/) && ($rating < 1) {
error("You have to write a number between 1 and 10. A game can't be better,
or worse than that!");
}
# Lets take the clicks field:
if ($FORM{'clicks'} eq "") {
$clicks = 1;
}
elsif ($click < 1 or $click > 50) {
error("You'll have to fill in a number between 1 and 50. If you leave the
field blank, the click will be set to 1.\n");
}
# And the last: the description field.
if ($FORM{'description'} eq "") {
error("You must fill in a description! And don't let it be longer than 150
letters.\n");
}
elsif ($description !~ /\w/) {
error("You are using a sign that you ain't allowed to use. Go back and just
use letters and numbers.\n");
}
elsif ($lenghtofdesc > 150) {
error("To long! The description is over 150 characters. Please go back and
try again!\n");
}
} # the sub's finish
####################################
# the write sub
sub write {
# First open the file to get the next number.
$data_file = "data.db";
open (DATA, "$data_file") || error("Could not open $data_file: $!");
@raw_data = <DATA>;
close(DATA);
$lastgame = pop(@raw_data);
chop($lastgame);
($stocknum1,$name1,$link1,$picture1,$description1,$rating1,$clicks1,$cat1)
=split(/\|/, $lastgame);
$newstockmun = $stocknum1 + 1;
open(DATA, ">>data.db") or error("Could not open data.db for writing.
Reason: $!\n"); # open or error.
flock(DATA,2); # lock the file
seek(DATA,0,2); # set the pointer to the end
print DATA "$newstocknum|$FORM{'name'}|$FORM{'link'}|$FORM{'picture'}|$FORM
{'description'}|";
print DATA "$FORM{'rating'}|$FORM{'clicks'}|$FORM{'cat'}";
}
sub error {
my($msg) = @_;
print "<h2>Error</h2>\n":
print $msg;
exit;
}
It has been uploaded in ASCII and chmod 755.
Still cant get it right. It is a software error that comes up when using the
codes above:
Can't continue after import errors at [my path is here but I do not want to
show it] line 2 BEGIN failed--compilation aborted at [my path is here but I do
not want to show it] line 2.
found it on my computer, hidden in the deepest caves of Windows 98.
Well, I had given up on the script and now I dont know why. It is a link game
archive. I can search after some links and info I got in a file and now I'm
having problems with the "post new" script.
Its quite long so take your time and help me find out what is wrong. I'm no
expert and terrible at finding errors in script. Is there another smart, fast en
secure way to find errors inside scripts?
Please let me know.
The script(add.cgi):
#!/usr/bin/perl
#
#
# Title: Games Pages
#
# (C) Copyright 2002-2004
# All rights reserved.
print "Content-type:text/html\n\n";
if ({'QUERY_STRING'} eq "write") {
&parseform;
✓
&write;
}
else {
print <<FORMfields;
<html><head><title>Add Games</title></head>
<body>
<h2 align="Center">Add Games</h2>
Wanna add a cool game to our archive? No problem!<br>
Just use the form belove. Fill in the required information(the ones with a
<font color="light blue">*</font> next to it)<br>
and press the Send button! Easy!<p>
<form action="add.cgi?write" method="Post">
<STYLE TYPE="text/css">
TD {
font-size:12
}
</STYLE>
<TABLE BORDER="0" CELLSPACING="0">
<TR>
<TD>The games name:<BR><INPUT TYPE="text" NAME="name"> <FONT
COLOR="lightblue">*</FONT></TD>
<TD>The games link:<BR><INPUT TYPE="text" VALUE="http://"
NAME="link"> <FONT COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD>Picture address:<BR><INPUT TYPE="text"
VALUE="http://www.myhost.com/gamepicture.jpg" NAME="picture"></TD>
<TD>Your rating of the game<BR>(from 1 to 10 where 10 is
best):<BR><INPUT TYPE="text" NAME="rating"> <FONT
COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD>Clicks to start with? (between 1-50)<BR><INPUT TYPE="text"
NAME="clicks"></TD>
<TD>In what category is the game?<BR><SELECT SIZE="1" NAME="cat">
<OPTION>Sport
<OPTION>Action
<OPTION>Adventure
<OPTION>Skiing
<OPTION>Strategy
<OPTION>Car game
<OPTION>Other
</SELECT> <FONT COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD VALIGN="middle">Description (Max 150 letters):<BR><TEXTAREA
WRAP="physical" ROWS="4" COLS="20" NAME="description"></TEXTAREA> <FONT
COLOR="lightblue">*</FONT></TD>
</TR>
<TR>
<TD><INPUT TYPE="submit" VALUE="Send"> <INPUT TYPE="reset"
VALUE="Erase"></TD>
</TABLE>
</form><p>
FORMfields
} # stop else
# the subroutines..
# parse form
sub parseform {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split (/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$value =~ s/\r//g;
$value =~ s/\cM//g;
$FORM{$name} = $value;
}
# the check sub
sub check {
$picture = $FORM{'picture'};
$rating = $FORM{'rating'};
$click = $FORM{'clicks'};
$description = $FORM{'description'};
$lenghtofdesc = length ($description);
# If no title, boooom, error!
if ($FORM{'name'} eq "") {
error("Please write in a name for the game. You must fill in all the fields
marked with a <font color=lightblue>*</font>\n");
}
# Checking if a url has been posted.
elsif ($FORM{'link'} eq "" or $FORM{'link'} eq "http://") {
error("It seems to be a problem with the link to the game's webpage. You
must fill in all the required fields. \n");
}
# Test if the visitor wants to use a picture or not.
if ($FORM{'picture'} eq "http://www.myhost.com/gamepicture.jpg" or $FORM
{'picture'} eq "") {
$picturelink = "noimage.jpg";
}
# Check if the visitor has posted a jpg or a gif image. If not, error.
elsif ($picture !~ /\.jpg$/i or $picture !~ /\.gif$/i) {
error("If you want to use a picture it must be a .jpg or .gif picture. We
don't support .bmp or other types.\n");
}
# Let's find out what the rating is set to and if it has crossed the borders.
if ($FORM{'rating'} eq "") {
error("Please set a rating to the game. A number between 1 and 10 will do
fine. 10 is best, 1 is worst.\n");
}
elsif ($rating !~ /\d/) && ($rating < 1) {
error("You have to write a number between 1 and 10. A game can't be better,
or worse than that!");
}
# Lets take the clicks field:
if ($FORM{'clicks'} eq "") {
$clicks = 1;
}
elsif ($click < 1 or $click > 50) {
error("You'll have to fill in a number between 1 and 50. If you leave the
field blank, the click will be set to 1.\n");
}
# And the last: the description field.
if ($FORM{'description'} eq "") {
error("You must fill in a description! And don't let it be longer than 150
letters.\n");
}
elsif ($description !~ /\w/) {
error("You are using a sign that you ain't allowed to use. Go back and just
use letters and numbers.\n");
}
elsif ($lenghtofdesc > 150) {
error("To long! The description is over 150 characters. Please go back and
try again!\n");
}
} # the sub's finish
####################################
# the write sub
sub write {
# First open the file to get the next number.
$data_file = "data.db";
open (DATA, "$data_file") || error("Could not open $data_file: $!");
@raw_data = <DATA>;
close(DATA);
$lastgame = pop(@raw_data);
chop($lastgame);
($stocknum1,$name1,$link1,$picture1,$description1,$rating1,$clicks1,$cat1)
=split(/\|/, $lastgame);
$newstockmun = $stocknum1 + 1;
open(DATA, ">>data.db") or error("Could not open data.db for writing.
Reason: $!\n"); # open or error.
flock(DATA,2); # lock the file
seek(DATA,0,2); # set the pointer to the end
print DATA "$newstocknum|$FORM{'name'}|$FORM{'link'}|$FORM{'picture'}|$FORM
{'description'}|";
print DATA "$FORM{'rating'}|$FORM{'clicks'}|$FORM{'cat'}";
}
sub error {
my($msg) = @_;
print "<h2>Error</h2>\n":
print $msg;
exit;
}
It has been uploaded in ASCII and chmod 755.
Still cant get it right. It is a software error that comes up when using the
codes above:
Can't continue after import errors at [my path is here but I do not want to
show it] line 2 BEGIN failed--compilation aborted at [my path is here but I do
not want to show it] line 2.