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

The perl script works fine from command line, but the CGI returns 500 error.
#!/usr/bin/perl use Crypt::GPG; use CGI qw(:standard); my $gpg = new Crypt::GPG; $gpg->gpgbin('/usr/bin/gpg'); # The GnuPG executable $to='fake@name.com'; $from= 'fakefake@name.com'; $subject='request'; $ptext = "Primary Applicant:\nOptical Carrier); @ctext = $gpg->encrypt( $ptext, $to ); open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL $ctext[0]; close(MAIL); print <<END; Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html><head> <title>Thank you!</title></head> <body> <h1>Thank you!</h1> <p>Your application received, an encrypted message emailed out to Me:< +br>$ctext[0]<br> You can expect to hear from me soon!</p> </body></html> END
So it works from command line, but gives a 500 error to user via CGI. But if I comment out references to gpg/GPG then the CGO works. So I dont think I have any code errors, it just looks like I have to do something else to enable CGI and crypt::gpg functionality? my hosting platform doesnt provide logs..

Replies are listed 'Best First'.
Re: cannot use Crypt::GPG for CGI
by Anonymous Monk on Jun 15, 2016 at 00:37 UTC

    my hosting platform doesnt provide logs..

    Like CGI Help Guide says  use CGI::Carp qw/ fatalsToBrowser /;

      ah, ok well I did that and the web server now returns
      Can't locate Crypt/GPG.pm in @INC (@INC contains: /usr/local/lib64/per +l5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/per +l5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at emailprequal.c +gi line 3. BEGIN failed--compilation aborted at emailprequal.cgi line 3.
      but i still dont get it. I can run the script from command line and it does everything I want. but it cant do it as a cgi with that "use Crypt::GPG;" in there at the top. even with no crypt::gpg objects in the perl script itself, if that use "use Crypt::GPG;" is there, the CGI webserver errors out.
        Can't locate Crypt/GPG.pm in @INC

        Compare @INC dumped from command line with @INC dumped from a CGI. You may need to add use lib "/some/where/"; to the CGI.

        Also compare $^X in CGI and command line. Your CGI may run using a different perl. In that case, use lib makes things worse (mixing library paths of different perl versions).

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Maybe the module has been (incorrectly) installed local to the root user instead of system-wide? I installed a fresh CentOS 7 VM just a few days ago that seemed to have an SElinux problem that prevented CPAN from installing modules system-wide. That problem went away after setting SElinux to "permissive", which I had to do anyway because... reasons.

        One of the reasons being that I always find SElinux to be a royal pain in the STDOUT.

        -- FloydATC

        Time flies when you don't know what you're doing

Re: cannot use Crypt::GPG for CGI
by stevieb (Canon) on Jun 15, 2016 at 00:38 UTC

    update: sigh... I don't know how I missed the fact that the server doesn't provide any logs... time for bed.

    The first thing that you should do when you get server errors, is check its error log...