PDA

View Full Version : I cannot figure out the error in this script?


BlasTech
08-05-2004, 06:01 AM
Hello. First time poster. I don't know much about Perl I'll be upfront and honest.

I downloaded an uploader program from here (http://www.perlscriptsjavascripts.com/perl/upload_lite/index.html) (I hope this isn't advertising that site, if so I'll remove the link I just wanted to show the script I'm using) and wanted to use it on my site. I've gotten it to work fine on one site and then I went to try and make it work on another. To my dismay no matter what I do I cannot get it to work on the other site even though I've only changed one line on the script, which is just the upload path. My provider assures me the servers are the same so that I shouldn't have any problem with it on one server vs. another.

Like I say I can get it to work on one site no problem, and have done everything the same on the other site, so I know I've done the CHMOD correct on all the directories, I've got the correct path to Perl and everything else. Yet, I get this error so I must be doing something wrong?

This is the error I get:

Can't locate CGI.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at upload.cgi line 164. BEGIN failed--compilation aborted at upload.cgi line 164.

The code is too long to post here according to the preview so I'll just post what I've changed in the script and then up to a little past the error and see if anyone can tell the problem. The full source is available from the site I've linked to above if it needs to be looked at. I haven't changed anything below where it says 'end user edits'. I know cgi works on the site because I've used a tester which tells me so (available here (http://www.palmbeachgmc.com/cgi-bin/myserver.cgi)

The link to my site and the error is here (http://www.palmbeachgmc.com/cgi-bin/upload.cgi)

Anyway I'm stumped! Please help!

The code is as follows:

#!/usr/bin/perl

# Installation Instructions
# http://www.perlscriptsjavascripts.com/perl/upload_lite/users_guide.html

# To order a custom install, please visit our "Secure order" page
# and enter the standard installation fee in the "Custom Quote" field

####################################################################
#
# Upload Lite.
# ©2002, PerlscriptsJavaScripts.com
#
# Requirements: Perl5 WINDOWS NT or UNIX
# Created: Febuary , 2001
# Author: John Krinelos
# Version: 3.23
#
# Based on Upload Gold, first release : September 2001
#
# This script is free, as long as this header and any copyright messages
# remains in tact. To remove copyright messages from public web pages you
# must purchase copyright removal.
# http://www.perlscriptsjavascripts.com/copyright_fees.html
#
# Agent for copyright :
# Gene Volovich
# Law Partners,
# 140 Queen St.
# Melbourne
# Ph. +61 3 9602 2266
# gvolovich@lawpartners.com.au
# http://www.lawpartners.com.au/
#
####################################################################

# START USER EDITS

# absolute path to folder files will be uploaded to.
# WINDOWS users, your path would like something like : images\\uploads
# UNIX users, your path would like something like : /home/www/images/uploads
# do not end the path with any slashes and if you're on a UNIX serv, make sure
# you CHMOD each folder in the path to 777

$dir = "/home/palmbe00/domains/palmbeachgmc.com/public_html/testuploads";
#$dir = "d:\\html\\users\\html\\images";

# absolute URL to folder files will be uploaded to
$folder = "http://www.palmbeachgmc.com/testuploads/";

# maximum file size allowed (kilo bytes)
$max = 100;

# for security reasons, enter your domain name.
# this is so uploads may only occur from your domain
# enter any part of your domain name, or leave this
# blank if you don't mind other web sites using your copy
$domain = "";

# if a file is successfully uploaded, enter a URL to redirect to.
# leave this blank to have the default message printed. If using
# this var, it must begin with http
$redirect = "";

# if you would like to be notified of uploads, enter your email address
# between the SINGLE quotes. leave this blank if you would not like to be notified
$notify = 'you@yourserver.com';

# UNIX users, if you entered a value for $notify, you must also enter your
# server's sendmail path. It usually looks something like : /usr/sbin/sendmail
$send_mail_path = "/usr/sbin/sendmail";

# WINDOWS users, if you entered a value for $notify, you must also enter your
# server's SMTP path. It usually looks something like : mail.servername.com
$smtp_path = "mail.yourserver.com";

# set to 1 if you would like all files in the directory printed to the web page
# after a successful upload (only printed if redirect is off). Set to 0 if you
# do not want filenames printed to web page
$print_contents = 1;

# allow overwrites? 1 = yes, 0 = no (0 will rename file with a number on the end, the
# highest number is the latest file)
$overwrite = 0;

# file types allowed, enter each type on a new line
# Enter the word "ALL" in uppercase, to accept all file types.
@types = qw~

txt
jpeg
jpg
gif

~;

BEGIN {
$| = 1;
open (STDERR, ">&STDOUT");
print qq~Content-type: text/html\n\n~;
}

####################################################
# END USER EDITS
####################################################

$folder =~ s/(\/|\\)$//ig;

$OS = $^O; # operating system name
if($OS =~ /darwin/i) { $isUNIX = 1; }
elsif($OS =~ /win/i) { $isWIN = 1; }
else {$isUNIX = 1;}

if($isWIN){ $S{S} = "\\\\"; }
else { $S{S} = "/";} # seperator used in paths

$ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";

unless (-d "$dir"){
mkdir ("$dir", 0777); # unless the dir exists, make it ( and chmod it on UNIX )
chmod(0777, "$dir");
}

unless (-d "$dir"){
# if there still is no dir, the path entered by the user is wrong and the upload will fail
&PrintHead; #print the header

# get the Win root
$ENV{PATH_INFO} =~ s/\//$S{S}/gi;
$ENV{PATH_TRANSLATED} =~ s/$ENV{PATH_INFO}//i;

print qq~
<table width="600">
<tr>
<td>

<font face="Arial" size="2">
<b>The path you entered is incorrect.</b> You entered : "$dir"
<p>
Your root path is (UNIX): $ENV{DOCUMENT_ROOT}
<p>
Your root path is (WINDOWS): $ENV{PATH_TRANSLATED}
<p>
Your path should contain your root path followed by a slash followed by the
destination folder's name. If you are on a WINDOWS server, each slash should
be escaped. Eg. each seperator should look like this : \\\\
<p>
Sometimes, the root returned is not the full path to your web space. In this case
you should either check with your host or if you are using an FTP client such as
CuteFTP, change to the folder you are trying to upload to and look at the path you
have taken. You can see this just above the list of files on your server.
You must use the same path in the \$dir variable.
</font>

</td>
</tr>
</table>
~;

&PrintFoot; # print the footer
exit;
}

use CGI; # load the CGI.pm module
my $GET = new CGI; # create a new object
my @VAL = $GET->param; #get all form field names

###############################################
###############################################



Anyway there is more code below that but it is aborting there at upload.cgi line so I don't know if you need the rest of the code. I just know I didn't change it or anything.

I've only opened the script with DzSoft Perl Editor so I don't think there would be any markup problems or anything. I've transfered it via WSFTP using the ASCII mode and CHMOD everything correctly.

Thanks for any help coders!

-BlasTech

MattJakel
08-05-2004, 06:30 AM
Ok that probably means that the perl module CGI.pm is not installed on your server. This is a standard module for most hosts so I'm a bit surprised... are you running this on a free server? Anyway, the workaround is to rewrite that code without using CGI.pm by replacing this:


use CGI; # load the CGI.pm module
my $GET = new CGI; # create a new object
my @VAL = $GET->param; #get all form field names


with this:


read($STDIN, $form_info, $ENV{'CONTENT_LENGTH'});
foreach $pair (split (/&/, $form_info)) {
($key, $value) = split (/=/, $pair);
$value =~ s/%(..)/pack ("C", hex ($1))/eg;
push @VAL, $value;
}


That basically does manually what CGI.pm does for you. If you still get the error, it means that CGI.pm is used later on too, so you will need to show us more code.

Hope this helps!
Matt

BlasTech
08-05-2004, 09:49 AM
MattJakel-

You may be on to something.

Click here (http://www.palmbeachgmc.com/cgi-bin/myserver.cgi) and scroll to the bottom to see the installed modules. I don't see CGI even installed. (but then again I don't have a clue as to what those modules mean)

No it is not a free server and I was told everything that was installed on the server that has the working script was also on this one.

So from that list do you think this is my problem? And if that is my problem, how come the 'myserver.cgi' link above worked if the cgi module isn't installed? (as I said I'm not a Perl guy lol)

Thanks!

-BlasTech