mojo_the_helper has asked for the wisdom of the Perl Monks concerning the following question:

I am getting a 500 Internal Server Error when I try to run the script below. I have got everything pointed in the right direction, but no useful error messages are in site. Any thoughts as to why?
The Code is below
#!/usr/local/bin/perl -wT use strict; ############################################## #Debug use diagnostics; ############################################## use CGI::Pretty qw/:standard/; $CGI::POST_MAX=1024*10; $CGI::DISABLE_UPLOADS = 1; ############################################## #Debug BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } ############################################## delete @ENV{ qw(IFS CDPATH ENV BASH_ENV) }; $ENV{PATH}=""; $ENV{CDPATH}=""; $ENV{ENV}=""; $ENV{BASH_ENV}=""; our $post_data; our $username; our $on_off; our $message; our $path_to_authorize; our @junk; our $runme; our $output; $path_to_authorize = "/home/prieheck/public_html/cgi-bin/vacation_suid +/"; if ($#ARGV < 0) { $post_data=new CGI; $username=$post_data->param('username'); $on_off=$post_data->param('on_off'); $message=$post_data->param('message'); } elsif ($#ARGV > 0) { $username=$ARGV[0]; $on_off=$ARGV[1]; #Patern match for letters and pass ONLY those on as $username $username =~ s/\W//g; if ($username =~ /\A([A-Z0-9]{3,16})\z/i ) { $username = lc($1); $username =~ tr/[A-Z]/[a-z]/; } else { #since username doesnt contain any characters we can use, it i +s now empty $username =""; } #convert to lowercase and check to see if the possible values exis +t $on_off =~ tr/[A-Z]/[a-z]/; if ($on_off eq "on") { $on_off = "on"; } elsif ($on_off eq "off") { $on_off = "off"; } else { #on_off was not correct, it is now empty $on_off = ""; } @junk = (($path_to_authorize . "authorize"), "vacation.pl", $usern +ame, $on_off); if($#ARGV > 1) { $message = join (" ",@ARGV); $message =~ s/$username//; $message =~ s/$on_off//; $message =~ s/\s/ /; #Patern match for letters numbers spaces underscores hyphens a +t signs and periods #pass ONLY those characters on as the message text discarding +the rest if ($message =~ /([-\@\s\w.]+)/) { $message = $1; @junk = (($path_to_authorize . "authorize"), "vacation.pl" +, $username, $on_off, $message); } else { #since message doesnt contain any characters we can use, i +t is now empty $message =""; } } } else { print "Not All Required Values Found\n"; #There were not enough arguments passed. Dieing with error code 1 exit 1; } $runme = join (" ",@junk); $runme =~ s/[;<+>\(\)\{\{\*\|\'\`\&\$\!\#\"]/\ $1/g; &begin_html; $output=`$runme`; print $output; &stop_html; sub begin_html { print start_html( -head=>meta({-http_equiv => 'Content-Type', -content => 'text/html'}), -title=>'Vacation Message Status For $username', -BGCOLOR=>'white', -Link=>'black', -vlink=>'black', -alink=>'black'); print table({ -border=>undef, -width=>'100%'}, Tr( [ td(['Information Technologies']), td({-align=>"right"},['iwu.edu']), ] ) ); print hr; } sub stop_html { print hr; print table({ -border=>undef, -BGCOLOR=>'#005533'}, Tr( [ td({-align=>"center", -style=>"font:white"},['IT @ + IWU']), ] ) ); print hr; print end_html; }
The code for my web form is below incase I have done something foolish in it.
<html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-885 +9-1"> <title>Enable/Disable/Change Your Vacation Message</title> </head> <body bgcolor="white"> <center> <form action="http://cyborg.iwu.edu/~prieheck/cgi-bin/vacation_sui +d/step_through.cgi" method="POST"> <font size="4"> <b>Vacation Message</b><BR> <font color=red> Activating your vacation message sends an autom +ated<BR> response to anyone who e-mails you.</font> </font> <font size="4"> <b> </b> </font> <p> <table border="1" bgcolor="#005533" cellspacing="0" cellpadding="5 +" valign="CENTER"> <tr> <td width="150"> <font color=white> Would you like to?<br> </font> <td bgcolor="silver"> <input type="radio" name="on_off" Value="on" checked>Enable Va +cation Message <input type="radio" name="on_off" Value="off">Disable Vacation + Message </td> <td> <tr> <td width="150"> <font color=white> Your login name? </font> </td> <td bgcolor="silver"> <input type="text" name="username" size="8">@iwu.edu </td> </tr> <tr> <td width="150"> <font color=white> Text to send back as vacation message.<BR> NOTE: use only standard alpha-numeric characters<BR> </font> </td> <td bgcolor="silver"> <TEXTAREA name="message" ROWS=6 COLS=60> I will not be reading my mail for a while. Your mail regarding $SUBJECT will be read when I return. </TEXTAREA> </td> </tr> <tr height="40"> <td colspan="2" height="40"> <input type="submit" name="Submit" value="Submit"> <input type +="reset" value="Clear Form"> <font color=white>Please be patient this will take some time</ +font> </td> </tr> </table> </form> <p> <hr> </center> </body> </html>
Any feedback on this code would be appreciated, however, my primary concern is "why doesn't it work throught the web?" I have tested it off of the command line and it runs fine, just not over http.

Replies are listed 'Best First'.
Re: 500 Error and Carp wont help?
by benn (Vicar) on May 19, 2003 at 15:27 UTC
    Sory if this is a granny-egg-sucking lesson, but have you checked your error logs? Is it executable etc.? Logs know all.....

    Cheers, Ben.

      alas I have my server error logs show as follows, and the script is set to 755 permissions by the way,
      Use of reserved word "our" is deprecated at ./step_through.cgi line 27 + (#1) (D) The indicated bareword is a reserved word. Future versions of + perl may use it as a keyword, so you're better off either explicitly qu +oting the word in a manner appropriate for its context of use, or using +a different name altogether. The warning can be suppressed for subr +outine names by either adding a & prefix, or using a package qualifier, e.g. &our(), or Foo::our(). Global symbol "$post_data" requires explicit package name at ./step_th +rough.cgi line 27 (#2) (F) You've said "use strict vars", which indicates that all variab +les must either be lexically scoped (using "my"), or explicitly qualif +ied to say which package the global variable is in (using "::"). Use of reserved word "our" is deprecated at ./step_through.cgi line 28 + (#1) Global symbol "$username" requires explicit package name at ./step_thr +ough.cgi line 28 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 29 + (#1) Global symbol "$on_off" requires explicit package name at ./step_throu +gh.cgi line 29 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 30 + (#1) Global symbol "$message" requires explicit package name at ./step_thro +ugh.cgi line 30 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 31 + (#1) Global symbol "$path_to_authorize" requires explicit package name at ./step_through.cgi line 31 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 32 + (#1) Bareword "our" not allowed while "strict subs" in use at ./step_throug +h.cgi line 32 (#3) (F) With "strict subs" in use, a bareword is only allowed as a subroutine identifier, in curly brackets or to the left of the "=> +" symbol. Perhaps you need to predeclare a subroutine? Unquoted string "our" may clash with future reserved word at ./step_th +rough.cgi line 32 (#4) (W) You used a bareword that might someday be claimed as a reserve +d word. It's best to put such a word in quotes, or capitalize it somehow, +or insert an underbar into it. You might also declare it as a subroutine. Array found where operator expected at ./step_through.cgi line 32, at +end of line (#5) (S) The Perl lexer knows whether to expect a term or an operator. + If it sees what it knows to be a term when it was expecting to see an op +erator, it gives you this warning. Usually it indicates that an operator +or delimiter was omitted, such as a semicolon. (Do you need to predeclare our?) syntax error at ./step_through.cgi line 32, near "our @junk" Global symbol "@junk" requires explicit package name at ./step_through +.cgi line 32 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 33 + (#1) Global symbol "$runme" requires explicit package name at ./step_throug +h.cgi line 33 (#2) Use of reserved word "our" is deprecated at ./step_through.cgi line 34 + (#1) Global symbol "$output" requires explicit package name at ./step_throu +gh.cgi line 34 (#2) Execution of ./step_through.cgi aborted due to compilation errors (#6) (F) The final summary message when a Perl compilation fails. Uncaught exception from user code: Execution of ./step_through.cgi aborted due to compilation err +ors.
      as you can see these logs make no sense to me otherwise I would know why all of a sudden our is no longer safe to use when it was just fine through a different interface

        Looks like you're trying to use "our" in a version of Perl that doesn't support it. "our" was introduced in Perl 5.6.0 - what version is yours?


        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

        The indicated bareword is a reserved word. Future versions of perl may use it as a keyword...

        ...and indeed they did - version 5.6 onwards. I think you'll either have to update your perl, or use another declaration type - 'my' or 'use vars' etc.
        /me rereads the original post... so it looks like your shebang line is calling an older version of perl than your command line....

        Cheers,Ben

Re: 500 Error and Carp wont help?
by halley (Prior) on May 19, 2003 at 15:36 UTC

    First three things to check are always:

  • Does it have the right line-endings for the httpd server? (dos2unix or perl -pie 's/\x0D//g')
  • Does it have the right mode or permissions to be run by the httpd server's cgi (chmod a+x or su nobody -c)
  • Does the bare minimum script work? Insert the following at the top of the script, immediately after the shebang.
  • print "Content-type: text/plain\n\n"; # two newlines print "It works!\n";

    --
    [ e d @ h a l l e y . c c ]

      Thanks for the feed back, in response to you statements,
      yes it does, thanks for giving me that way to check it though
      yes it does, but never hurts to look into to, and I did
      no it doesn't the lines, any thoughts?