Current location: Hot Scripts Forums » Programming Languages » Perl » Problem with CGI (500 Internal Server Error) Need Help


Problem with CGI (500 Internal Server Error) Need Help

Reply
  #1 (permalink)  
Old 05-21-06, 10:37 AM
PHP Warner PHP Warner is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with CGI (500 Internal Server Error) Need Help

Hello,

I want to empty selected folder and then remove it.

My code is below:

delete.cgi

Code:
#!/usr/bin/perl
use CGI;
use CGI qw/:standard/;
use Config;
my $cg = new CGI;
my $ID_IDENTIFIER = $cg->param('ID_IDENTIFIER');
#my $FILE_IDENTIFIER = $cg->param('FILE_IDENTIFIER');

my $target_dir = "$c->{target_dir}/$ID_IDENTIFIER";
#my $target_file = "$c->{target_dir}/$ID_IDENTIFIER/$FILE_IDENTIFIER";

&DelData($target_dir);

sub DelData
{
   my ($dir) = @_;
   opendir(DIR, $dir) || die"Hata";
   my @ff = readdir(DIR);
   closedir(DIR);
   for my $fn(@ff)
   {
      unlink("$dir/$fn");
      print("$dir/$fn has been empty");
   }
   rmdir("$dir");
   print("$dir has been deleted");
}
Config.pm
Code:
package Config;

BEGIN
{
use Exporter;
@Config::ISA = qw( Exporter );
@Config::EXPORT = qw( $c );
}

our $c=
{
target_dir => '/usr/home/site/public_html/target',
};
1;
Always giving Internal Server Error. Target dir chmod is 777 and no problem with user groups. Also script chmod is 755.

perl -cw delete.cgi
Syntax OK

How can I fix this, any ideas?

Thanks now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-21-06, 01:30 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
adding this line to the main script:

Code:
use CGI::Carp qw/fatalsToBrowser/;
will redirect most fatal errors to the browser. It's helpfule for debugging scripts.

It looks to me like the first problem and maybe the only problem, is that you have not printed a header before trying to print some data to the browser, change this:

Code:
my $cg = new CGI;
my $ID_IDENTIFIER = $cg->param('ID_IDENTIFIER');
to:

Code:
my $cg = new CGI;
print $cg->header;
my $ID_IDENTIFIER = $cg->param('ID_IDENTIFIER');
and hopefully all will be well.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-21-06, 01:48 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
here's a suggestion for your script:

Code:
#!/usr/bin/perl
use CGI;
use Config;
use File::Path;
my $cg = new CGI;
print $cg->header,$cg->start_html;
my $ID_IDENTIFIER = $cg->param('ID_IDENTIFIER');
#my $FILE_IDENTIFIER = $cg->param('FILE_IDENTIFIER');
my $target_dir = "$c->{target_dir}/$ID_IDENTIFIER";
#my $target_file = "$c->{target_dir}/$ID_IDENTIFIER/$FILE_IDENTIFIER";

rmtree($target_dir, 1, 1);

print $cg->end_html;
see the File:ath module:

http://perldoc.perl.org/File/Path.html

also, passing a filename as a CGI parameter to the script and not doing any validation/taint checking is insecure. If you are the only person with access to the script then I assume you know what you are doing. If this script will be used by the public you will want to do some validation and taint checking on any variables used for possible insecure operations, such as deleting files/directories. Read up here if interested:

http://users.easystreet.com/ovid/cgi...son_three.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-21-06, 04:31 PM
PHP Warner PHP Warner is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Hello ,

I have try to use rmtree but it doesn't work. I added print $cg->header; it works perfect. And also use CGI::Carp qw/fatalsToBrowser/; showed the error on opendir(DIR, $dir)

So I have changed my codes like this:

Code:
#!/usr/bin/perl
use CGI;
use Config;
use File::Path;
my $cg = new CGI;
print $cg->header,$cg->start_html;
my $ID_IDENTIFIER = $cg->param('ID_IDENTIFIER');
my $FILE_IDENTIFIER = $cg->param('FILE_IDENTIFIER');

my $target_dir = "$c->{target_dir}/$ID_IDENTIFIER";
my $target_file = "$c->{target_dir}/$ID_IDENTIFIER/$FILE_IDENTIFIER";

unlink("$target_file");
rmdir("$target_dir");

print("$target_file has been deleted<br>$target_dir removed");

print $cg->end_html;
This works fine. Thank you sooooo much : ).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-21-06, 05:19 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
You're welcome.

If rmtree() doesn't work then you don't need to load the File:ath module
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Internal Server Error jarradyuhas Perl 1 11-14-05 09:41 PM
Local Server - Dreamweaver MX 2004 problem mcrob PHP 1 10-27-05 02:34 PM
Help - CGI Script Installation Problem. senaia Perl 1 05-22-05 12:20 AM
CGI Problem dimitra Perl 1 08-26-04 06:28 PM


All times are GMT -5. The time now is 01:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.