Results 1 to 10 of 11
I might be dating my perl days. 10+ years ago, I could put into any program I desired absolute path and filename to any perl snippet I might wish to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-20-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 31
Perl: require "/var/www/whateverIwish/myfile.pl"
I might be dating my perl days. 10+ years ago, I could put into any program I desired absolute path and filename to any perl snippet I might wish to use and presto any sub in the place is mine to play with... still that way yes? Have @INC not included errors, and all the web talks about are modules.
O.k. might be misstating the effort.
My script does everything it's supposed to from the command line. (it's inside my cgi-bin script area), but when the web browser connects it fails
Can't locate /var/www/library/formgen.pl in @INC
(all my files are mod 755).
at
require "/var/www/library/formgen.pl";
which I wrote a very long time back to assist me in html generation. Refresh my rusty skills, if I've an absolute path, does it matter what path settings are elsewhere? from user or root csh or bsh it does what I think it should.
p.s. formgen.pl does not refer to any other file.
- 11-20-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
The web server (Apache?) is probably not running as root. Are you sure that the web server user (possibly "nobody" - check the output of ps) has access to that file?
try this simple perl CGI script as a test:
Code:#!/usr/bin/perl use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); my $file = "/var/www/library/formgen.pl"; open(FH,'<',$file) or die $!; print "opened file successfully\n"; close(FH);
- 11-20-2012 #3Just Joined!
- Join Date
- Nov 2012
- Posts
- 31
You're right some permission problems:
[Tue Nov 20 11:07:24 2012] [error] [client 10.0.0.3] [Tue Nov 20 11:07:24 2012] showlib.pl: Permission denied at /var/www/cgi-bin/showlib.pl line 6.
at open the file. however both
andCode:sudo -u apache ./showlib.pl
opens the libary succesfully..Code:sudo -u nobody ./showlib.pl
and the library and cgi-bin are on the same www directory with 755 permissions throughout.
if I change the permissions to 750, does nothing from the above code (doesn't show any output to screen)
so somewhere in the cobwebs (at least I remember how to use vi) some way (rsh? rlogin? csh?) to switch from the root to a nobody account, to check the permissions from command line [sighs can't beleive I'm asking about permission problems]
SO STILL THINKING!! The permissons required from the webserver are different from that a command line user. Is there some block of referring to directories outside the apache setup.Last edited by potentsinfo; 11-20-2012 at 03:54 PM.
- 11-20-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
show the output of these commands (run as root):
Also, is SELinux running? Check with:Code:ls -ld /var/www/library/formgen.pl ls -ld /var/www/library/ ls -ld /var/www/ ls -ld /var/
temporarily disable with:Code:getenforce
Code:setenforce 0
- 11-21-2012 #5Just Joined!
- Join Date
- Aug 2011
- Posts
- 7
> require "/var/www/library/formgen.pl";
Being called from a WEB page? Your root directory is no longer /, but the root directory of the WEB site. Probably /library.
It's been several years since I've put PERL in a WEB site. But I see this is the way for PHP requires.
- 11-21-2012 #6Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
- 11-23-2012 #7Just Joined!
- Join Date
- Nov 2012
- Posts
- 31
Grunt Work:
(show lib is the example script uploaded)Code:[root@rd shane]# ls -ld /var/www/library/formgen.pl -rwxr-xr-x. 1 shane shane 5877 Nov 19 22:27 /var/www/library/formgen.pl [root@rd shane]# ls -ld /var/www/library/ drwxr-xr-x. 3 shane shane 4096 Nov 19 22:32 /var/www/library/ [root@rd shane]# ls -ld /var/www/ drwxr-xr-x. 12 shane shane 4096 Nov 19 23:08 /var/www/ [root@rd shane]# ls -ld /var/ drwxr-xr-x. 20 root root 4096 Aug 17 17:08 /var/ [root@rd shane]# ls -ld /var/www/cgi-bin drwxr-xr-x. 3 shane shane 4096 Nov 20 09:59 /var/www/cgi-bin [root@rd shane]# getenforce Enforcing [root@rd shane]# setenforce 0 [root@rd shane]# cd /var/www/cgi-bin [root@rd cgi-bin]# ./showlib.pl opened file successfully
BUT ERROR OUTPUT CHANGED!!!!
Great!!!! and slightly more importantly my first program I was asking about is o.k.!!!Code:[root@rd cgi-bin]# tail -f /var/log/httpd/error_log [Fri Nov 23 16:10:59 2012] [error] [client 10.0.0.3] malformed header from script. Bad header=opened file successfully: showlib.pl
Now, once again showing how dated the programming is…. SELinux? What else is new? Can I modify SELinix to allow my all libraries? or set it to zero?Clearing out the cobwebs. heh... didn't know they were new cobwebs. whew... glad it's something new, thought I'd have to review the basics. Ummmm.. "New" being more than a decade ago. Really, what is new that I should know about?Last edited by atreyu; 11-24-2012 at 01:44 AM. Reason: added CODE tags for readability
- 11-23-2012 #8Just Joined!
- Join Date
- Nov 2012
- Posts
- 31
yep www is only root directory for html files (static pages) or javascript code (code that shows up in 'view source') CGI is a behind the scenes program or application which the programmer directs what output is put to the webpage (print -> view source)
- 11-24-2012 #9Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
that is just b/c the CGI script is not sending the HTTP header first (e.g., print "Content-type:text/html\n\n"). Try your original CGI script.BUT ERROR OUTPUT CHANGED!!!!
Code:[root@rd cgi-bin]# tail -f /var/log/httpd/error_log [Fri Nov 23 16:10:59 2012] [error] [client 10.0.0.3] malformed header from script. Bad header=opened file successfully: showlib.pl
Now you know SELinux is the problem. You can either configure SELinux to allow your scripts (if security of the system is of utmost importance to you), or you can permanently disable it. If you wish to do the former, google for a good guide on SELinux and CGI scripts, I don't know the commands.
If you wish to do the latter, edit this file:
and make sure the following line is there:Code:/etc/selinux/config
then reboot.Code:SELINUX=disabled
SELinux is pretty significant, it has been around for years, but it has just recently starting being enabled by default. You also need to beware of iptables (kernel-based firewall), as it is being enabled by default these days, too. Another interesting kernel feature that is becoming popular is cgroups, used for resource isolation and control.Really, what is new that I should know about?
- 11-24-2012 #10Just Joined!
- Join Date
- Nov 2012
- Posts
- 31
Once again Atreyu, you've resolved my tasks, good think your good at this. Thanks So Much!! Cheers.




