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

Hi all, I'm having a frustrating error that I'm somewhat confused about. I'm writing a simple perl script as a cgi for a login. I've run through a lot of tests to try to figure out where the error is, but so far it's not been successful. The perl code is as follows:
#!/usr/bin/perl -wT use CGI; use CGI::Cookie; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Fcntl qw(:flock :seek); use Fcntl; use strict; my ( $name, #username they type in $pass, #password they type in $sys_name, #username in the member file $sys_pass, #password in the member file @members, #array of all members $dirto_members_list, #directory to members file $valid_name, #variable to determine name validity $valid_pass, #variable to determine password validity $cookie #cookie used to dtermine if they're log +ged in or not ); $name = param('username'); $pass = param('password'); print header; print start_html('Login Status'); ###################################################################### +### # Check the name & password in the members file ###################################################################### +### $dirto_members_list = "/home/hopefulc/public_html/cgi-bin/koh_members_ +list.cgi"; open (MEM, $dirto_members_list) || die("The File could not be opened!" +); #open the members file flock (MEM, LOCK_SH); seek (MEM, 0, SEEK_SET); @members = <MEM>; chomp (@members); close(MEM); + #close the members file $valid_name = 0; $valid_pass = 0; foreach my $mem (@members) { ($sys_name, $sys_pass) = split (/\|..\|/, $mem); if ($name eq $sys_name) { $valid_name = 1; if ($pass eq $sys_pass) { $valid_pass = 1; print "Congratulations $name, you logged in!\n<br><br>\n"; } else { print "Sorry, you didn't type in the correct password.\n<b +r><br>\n"; } } } ###################################################################### +#### print end_html;
The tests that I've run through include checking the file permissions and setting them to 0755, carefully checking the spelling in the files, checking the html form, and I also ran a slightly modified version of this code from the command line successfully. The annoying Internal Server error that is in the Apache error log is as follows: Mon Jun 16 17:56:46 2008 error client 76.193.171.114 File does not exist: /home/hopefulc/public_html/500.shtml The error seems very simple, except that I know the file does exist. If anyone has any suggestions to help it would be very much appreciated...

Replies are listed 'Best First'.
Re: Perl CGI Apache help...
by marto (Cardinal) on Jun 18, 2008 at 11:32 UTC
    Is this the only entry in the error_log file? It looks as though you are experiencing an HTTP 500 error, and apache is trying to display a 500 error message but can't find the file (/home/hopefulc/public_html/500.shtml). Are you sure this file exists and is readable? Are you doing anything strange in the httpd.conf regards the ErrorDocument directive?

    Martin
Re: Perl CGI Apache help...
by psini (Deacon) on Jun 18, 2008 at 11:32 UTC

    One obvious reason (apart file permission that you already checked) could be that apache (i.e. the user running apache) has no access to the directory in which the file is. Try the command line test from the same user apache is running (on linux/debian it defaults to www-data, on other distro I don't know)

    Second possible cause: apache is not allowed to access files in hat directory. Check apache config file and/or .htaccess

    Careful with that hash Eugene.

Re: Perl CGI Apache help...
by hopefulcd (Initiate) on Jun 18, 2008 at 23:38 UTC
    I've stopped trying to get the entire login file to work and am now just trying to work on it step by step. I made a test.cgi that just tries to open the directory, print out the files in the directory, open a file in the directory, and print all the lines in the file. So far this test file has been failing. I have other cgi files in the same directory that work just fine. The other files, such as a register.cgi, are a lot more complicated than the login.cgi and test.cgi. This is confusing to me because the register.cgi and some others open directories and files just fine (some open the same directory and files that login and test have failed to open). My ISP is running their Apache server on a Linux based OS. I don't think I can gain access to changing anything on the httpd.config file. The I've checked the permissions on the test.cgi and it's 0755. Also, the error log that is really not making sense to me says this:
    [Wed Jun 18 18:07:45 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:07:43 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:06:34 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:04:27 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:04:26 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:01:53 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 18:00:23 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml [Wed Jun 18 17:58:17 2008] [error] [client 76.193.171.114] File does n +ot exist: /home/hopefulc/public_html/500.shtml
    The test.cgi is simpler than the login one that I was initially trying to get to work. The code for it is as follows:
    #!/usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; my ( $dir, #path to directory $dir_file, #sample file in the directory @files, #array of all the files in the directory @lines #array of all the lines in the sample file ); $dir = "/home/hopefulc/public_html/cgi-bin/"; $dir_file = "/home/hopefulc/public_html/cgi-bin/koh_members_list.cgi"; opendir(DIR, $dir) || die("Failed To Open Directory"); @files = readdir(DIR); close(DIR); print header; print start_html("Test CGI"); print "<u><h3>The files in the directory are listed below:</h3></u>\n< +br><br>\n"; foreach my $file (@files) { print "$file\n<br>\n"; } print "<u><h3>The lines in the file are listed below:</h3></u>\n<br><b +r>\n"; open (FILE, $dir_file) || die("Failed To Open File"); @lines = <FILE>; close(FILE); foreach my $line (@lines) { print "$line\n<br>\n"; } print end_html;
    If anyone knows what could or might be causing this, it would be greatly appreciated...
      Are you doing anything strange in the httpd.conf regards the ErrorDocument directive? Either you're copying the wrong error log, or your server is misconfigured
Re: Perl CGI Apache help...
by Anonymous Monk on Jun 18, 2008 at 11:40 UTC
    Whats the name of your program?
Re: Perl CGI Apache help...
by throop (Chaplain) on Jun 18, 2008 at 15:03 UTC
    This is a long shot... but.

    Remember to check the file permissions of the parent directories as well as the file itself. In particular, suppose you use mkdir to create two levels of directory (in a single invocation) and to set permissions. Then the lower directory will have the permissions you intended, but the higher one may not.

    It's a long shot, but it chewed up about one workday for me earlier this year.

    throop

    ps. In listing the error message, you used [] where you should have used &91;&93;. Or put the error message inside <code>