-
Why doesn't http://www.railsupport.nl/upload work ???
Since the files we're transferred to a different server i get an error 500 when trying to upload a file called text.txt. When i leave the field empty and click upload it has no problems running the script.
I think it's got something to do with them using some kind of wrapper called sBox.
source of sript:
#!/usr/bin/perl
$Data = "$ENV{DOCUMENT_ROOT}/personeel/";
# On your server, create a directory where this program will write the files
# to. Make sure you CHMOD this directory to 777. If you do NOT specify a $Data
# directory, the program will attempt to write to the web root directory.
# NOTE: YOU SHOULD ALWAYS SPECIFY A DIRECTORY TO STORE THE UPLOAD
@good_extensions = ();
# If you want to limit the types of extension that can be uploaded, specify them
# here by adding them to the array. For example, if you wanted to permit only
# the upload of gif's, jpg's and png's, then you would set the above array to
# look like this:
# @good_extensions = ('gif', 'jpg', 'jpeg', 'png');
#
@bad_extensions = ();
# If you want to permit the upload of all file types with only certain exceptions,
# then specify those extensins in the bad_extensions array. This means that if set
# this array to contain .exe, .pl, .cgi files, then the program will only store a
# file if the extension of that file is NOT found in this array.
# To set the array to exclude these sample extensions, you would set it like this:
# @bad_extensions = ('exe', 'cgi', 'pl');
#
# NOTE: If you specify both @good_extensions and @bad_extensions, then
# the settings in @bad_extensions will be ignored and the program will
# use @good_extensions as it's refrence.
$redirect = "http://www.railsupport.nl/ready.html";
# When the upload of files is complete, the program must print someting out on the
# browser screen. Set the $redirect variable to the full URL (don't forget the http://)
# that you want the person taken to once the program is finished. If you don't specify
# a URL here, the program will print out a simple upload summary page.
$max_size = 0;
# Set the maximum size of each file that is permitted. For example, if you only want
# files to be uploaded that are under 50Kb in size, set the value to:
# $max_size = 50;
# If you set the value to zero, remove it or comment it out, then the size of the
# uploaded file will NOT be checked.
$max_num_files = 5;
# You must specify the maximum number of files that can be uploaded at one time. You
# can set this to any number you want but be realistic. The limit before the server
# times out will depend on the maximum size of the upload. I have tested this program
# with ASCII files up to 8MB in size successfully but that was on a particularly
# robust server. I recommend that you set this no higher than 5 if you are going to
# be using this for larger binary files such as images or executables or word docs, etc.
# If you remove, comment out or set this value to zero, the program will default the
# value to 1 file.
$auto_rename = 0;
# This variable tells the program whether or not to over-write or reject like
# named files. Therefore, if you upload a file with a name that already exists
# on the server, set this value for the appropriate following results:
# 0 => Overwrite the existing file
# 1 => Leave existing file in place, serialize the name of the new
# new file (i.e. some_book.doc, some_book1.doc, some_book2.doc, etc)
# 2 => Reject the new file. Leaves the original file in place and rejects
# the new file so that it is not saved.
# The default setting of this var is 0.
#
################################################## #####################################
#
# DO NOT EDIT ANYTHING BELOW THIS LINE
# UNLESS YOU KNOW WHAT YOU ARE DOING
#
if(($ENV{'QUERY_STRING'} =~ /^debug/) && !$no_debug) {
print "Pragma: no-cache\nContent-type: text/html\n\n";
print "<TITLE>PSUpload Demonstration Upload Program - Debug Mode</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\" TEXT=\"#330066\" LINK=\"#336666\" ALINK=\"#336666\" VLINK=\"#336666\" BGCOLOR=\"#FFFFFF\"><FONT SIZE=\"2\" FACE=\"verdana, arial, helvetica\">\n";
print "<CENTER><B><H2>Charity Ware's PSUpload Program</H2></B><BR><BR><TABLE BORDER=0><TR><TD COLSPAN=2><FONT SIZE=\"2\" FACE=\"verdana, arial, helvetica\">\n";
print "<DL><DT><B>Your web root directory appears to be located at:</B><DD>$ENV{'DOCUMENT_ROOT'}<BR><BR><DT><B>You specified directory for storing the uploads is:</B><DD>$Data<BR><BR><DT><B>Your specified directory...</B><DD>\n";
if(-d $Data) {
print "...appears to be a valid directory.<BR><BR>Make sure this \$Data directory is CHMOD 777.\n";
} else {
print "...does not appear to be a valid directory.<BR><BR>\n";
unless($Data =~ /^$ENV{'DOCUMENT_ROOT'}/) {
print "The value you specified in the \$Data variable is incorrect. Please<BR>correct your \$Data variable and run debug again.<BR><BR>\n";
}
}
if($Data =~ /\/$/) {
print "<FONT COLOR=\"#FF0000\">NOTE: Your variable \$Data ends with a trailing slash. Please<BR>remove this trailing slash, upload the program again<BR>and run debug once more to see if you have a valid directory.</FONT><BR><BR>\n";
}
print "</DL><BR><BR></FONT></TD></TR><TR><TD WIDTH=\"50%\" VALIGN=\"TOP\"><FONT SIZE=\"2\" FACE=\"verdana, arial, helvetica\"><B>OS:</B><BR>$^O<BR><BR><B>Perl:</B><BR>$]</FONT></TD><TD VALIGN=\"TOP\"><FONT SIZE=\"2\" FACE=\"verdana, arial, helvetica\"><B>Installed:</B><BR>"; my @inst = split(/\//, $ENV{'SERVER_SOFTWARE'}); print join("<BR>", @inst); print"</FONT></TD></TR></TABLE><BR><BR><BR><BR><A HREF=\"http://www.charityware.ws/\">© 2001, Jim Melanson</A></CENTER><BR><BR></FONT></BODY></HTML>\n";
} else {
use CGI;
$max_num_files ||= 1;
$Data ||= $ENV{'DOCUMENT_ROOT'};
undef @bad_extensions if @good_extensions;
for(my $a = 1; $a <= $max_num_files; $a++) {
my $req = new CGI;
if($req->param("FILE$a")) {
my $file = $req->param("FILE$a");
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;
$filename =~ s/ +/\_/g;
my $proceed_type = 0;
if(@good_extensions) {
foreach(@good_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 1;
last;
}
}
unless($proceed_type) {
push(@was_not_good_type, $filename);
}
}
elsif(@bad_extensions) {
$proceed_type = 1;
foreach(@bad_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 0;
last;
}
}
unless($proceed_type) {
push(@was_a_bad_type, $filename);
}
} else {
$proceed_type = 1;
}
if(($auto_rename == 2) && (-e "$Data/$filename")) {
$proceed_type = 0;
push(@rejected, $filename);
}
if($proceed_type) {
if((-e "$Data/$filename") && ($auto_rename == 1)) {
my $pick_new_name = 1;
my $fore_num = 1;
$filename =~ /^(.+)\.([^\.]+)$/;
my $front = $1;
my $ext = $2;
while($pick_new_name) {
my $test_name = $front . $fore_num . '.' . $ext;
unless(-e "$Data/$test_name") {
$pick_new_name = 0;
$filename = $test_name;
}
$fore_num++;
}
}
if(open(OUTFILE, ">$Data/$filename")) {
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
push(@file_did_save, $filename);
} else {
push(@did_not_save, $filename);
}
}
if($max_size) {
if((-s "$Data/$filename") > ($max_size * 1024)) {
push(@was_too_big, $filename);
unlink("$Data/$filename");
}
}
}
}
print "Pragma: no-cache\n";
if($redirect && ($redirect =~ /^http\:\/\//)) {
print "Location: $redirect\n\n";
} else {
print "Content-type: text/html\n\n";
print "<HEAD><TITLE>PSUpload Results</TITLE></HEAD><BODY><FONT FACE=\"verdana,helvetica,arial\" SIZE=2><BR><BR><CENTER><B><H2>Upload Results</H2></B><HR WIDTH=\"65%\"><BR><BR>\n";
if(@rejected) {print "<B>The following file(s) were not stored as they<BR>were already on the server:<BR><BR>\n"; print join("<BR>", @rejected); print "<BR><BR>\n"}
if(@file_did_save) {print "<B>The following file(s) were saved:<BR><BR>\n"; print join("<BR>", @file_did_save); print "<BR><BR>\n"}
if(@was_not_good_type) {print "<B>The following file(s) were not stored as their file extension<BR>did not match any of the valid extensions specified in the program:<BR><BR>\n"; print join("<BR>", @was_not_good_type); print "<BR><BR>\n"}
if(@was_a_bad_type) {print "<B>The following files were not stored as their file extension<BR>are on the list of extensions not permitted for upload:<BR><BR>\n"; print join("<BR>", @was_a_bad_type); print "<BR><BR>\n"}
if(@was_too_big) {print "<B>The following files were not stored as their file size<BR>exceeded the maximum file size of $max_size Kb.:<BR><BR>\n"; print join("<BR>", @was_too_big); print "<BR><BR>\n"}
if(@did_not_save) {print "<B>The following files were not stored because the<BR>program could not open their destination file:<BR><BR>\n"; print join("<BR>", @did_not_save);print "<BR><BR>\n";
if(!@file_did_save) {print "<FONT COLOR=\"RED\"><B>NOTE: Check to ensure that the \$Data variable reflects the correct<BR>absolute path to the directory these files should be store in.</B></FONT><BR><BR>"}
}
print "<BR><BR><HR WIDTH=\"65%\"><BR><A HREF=\"http://www.charityware.ws/psupload/psupload.shtml/\"><FONT COLOR=\"#C0C0C0\">© 2001, Jim Melanson</FONT></A><BR></BODY></HTML>\n";
}
}
HEEEEEEEEELP!!!!!
-
__OSX powered__
I copied the cgi + your upload html file, changed the "$Data" to a folder wich I did a chmod 777 upload on, no problem at all to upload files.
Are you shure you have set all permissions correctly??
Also: try to set the "$Data" to an absolute path.
-
Originally posted by nucleuz
I copied the cgi + your upload html file, changed the "$Data" to a folder wich I did a chmod 777 upload on, no problem at all to upload files.
Are you shure you have set all permissions correctly??
Also: try to set the "$Data" to an absolute path.
Tried the absolute path thing without success.
I got the script to work on another server too...just seems the cgi-wrapper installed on this server gets in the way.
Ever heard of sbox?....take a look: http://stein.cshl.org/~lstein/sbox/
still puzzled by this
ps. nucleuz, thanks for taking a look at it
-
__OSX powered__
Have you talked to the server admins??
Send them a nice email and ask *politly* what to do with this problem
-
Hi,
one of the features of sbox is the use of chroot. If the feature is enabled, you have to use a path relative to your webspace for the data directory
Musicman
-
Yup, that's what the sysadmin said too. But no result.
Then again, when i called him he didn't even know what sbox is.
So, isn't there a chance they disabled file writing/editing alltogether with sbox?
-
Hi,
I'd suggest to create a series of test scripts to find out what is going on
#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $e (keys %ENV) {
print "$e => $ENV{$e} <br>\n";
}
-------
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$f = "mytest.txt";
die "cannot write: $!\n" if(!open X, ">$f");
print X "just a test\n";
close X;
print "file written";
------
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use POSIX;
print "script running in " . getcwd() . "<br>";
print "user details are " . join(' ', getpwuid($>)) . "<br>";
Musicman
Of course, if the admin does not even know the software they are using, chances are that it is simply misconfigured
-
take a look
http://www.railsupport.nl/cgi-bin/test1.cgi
shouldn't DOCUMENT_ROOT be an absolute path?
http://www.railsupport.nl/cgi-bin/test2.cgi
It doesn't even get to the "can't write" part *edit - this appears to work well now*
http://www.railsupport.nl/cgi-bin/test3.cgi
nothing here either
still no response from the sysadmin either
[Edited by DutchDesign on 06-18-2002 at 11:08 AM]
-
Originally posted by Musicman
print "script running in " . getcwd() . "<br>";
print "user details are " . join(' ', getpwuid($>)) . "<br>";
LOL it made a of it
-
Hi,
in case you actually have a /http directory for your html files, the sbox chroot()s to the directory above it (so your cgi scripts only see a file system consisting of /http and /cgi-bin (probably the same things you see in your ftp program)
You should try to upload a test file for test 2 and chmod it to 666 and repeat that test
a) myfile.txt - file inside the cgi-bin
b) test/myfile.txt - file in a subdirectory of cgi-bin
c) /http/myfile.txt - file inside your webfiles area
The fact that you do not even get an error is a bit unfriendly. Any chance they are at least giving you an error_log to look at)
The fact that both of these do not return probably means that errors are not reported and the perl installation inside the chroot environment is lacking POSIX
BTW: tracing the route to your server, I ended up at a nice "under construction" logo from http://www.infopact.nl
Musicman
-
so i got the test2.cgi working wich means it *is* possible to write files despite the whole sbox thingie.
Still i get an error 500 on http://www.railsupport.nl/cgi-bin/upload.cgi when it is called from the form in http://www.railsupport.nl/upload
http://www.railsupport.nl/cgi-bin/upload.cgi?debug does look fine though.
I checked again if the whole thing functions on another server and it did.
I usually do not program in perl, but could it be the OUTFILE thing that causes the problems?
i'm really staring to pulling my hears out over here.
[Edited by DutchDesign on 06-18-2002 at 11:21 AM]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|