Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

permission problems between commandline and CGI

by parkprimus (Sexton)
on Jan 27, 2004 at 22:46 UTC ( #324557=perlquestion: print w/replies, xml ) Need Help??

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

Monks, This is a problem that has been plaguing me for a week now and I am out of ideas. The code below works fine in command line (RH9) but as soon as I try the browser it gives me two errors. Any ideas will be appreciated. Thank you Monks!
#!/usr/bin/perl use CGI qw(:standard); my $cgi = new CGI; $i = 0; $connect = 0; make_connection(); cut_connection(); sub make_html { use Spreadsheet::ParseExcel::Simple; print $cgi->header(); print $cgi->start_html('7513 Interface Descriptions'); print "<H1><center>7513 Interface Descriptions</H1>\n"; print "<Table border = 1>\n"; $xls = Spreadsheet::ParseExcel::Simple->read('/root/FLA_DHRS/S +HRHZ006/7513.xls'); foreach $sheet ($xls->sheets) { while ($sheet->has_data) { @data = $sheet->next_row; print " <tr>\n"; #print "@data\n"; foreach $element (@data) { if ($i <= 2) { print "<td><b><center>$element</td></b></cent +er>\n"; $i++; } else { print "<td><center>$element</t +d></ceneter>\n"; } } print " </tr>\n"; } } print end_html; } sub make_connection { if($connect eq 0) { system("/usr/local/bin/ncpmount -S server -A ip address -V /vol2/ISPSNC/PortAssignments -U username -P password /root/FLA_DHRS/SHRHZ006"); $connect = 1; } else { $connect = 0; error(); } if($connect eq 1) { make_html(); } } sub cut_connection { if ($connect eq 1) { system('ncpumount -S server'); } } sub error { print $cgi->header(); print $cgi->start('Error'); print "<center>"; print "<H2> Error: Could not connect to server </H2>"; print "Please Try again later"; print "<HR></center>"; print end_html; }
Error 1
Cannot to mount on /root/FLA_DHRS/SHRHZ006: Operation not permitted
Error 2
Can't call method "sheets" on an undefined value at /var/www/cgi-bin/perldev/excel.cgi line 22.

Retitled from "Racking My Brain!" by Chady

Replies are listed 'Best First'.
Re: permission problems between commandline and CGI
by Abigail-II (Bishop) on Jan 27, 2004 at 22:54 UTC
    Cannot to mount on /root/FLA_DHRS/SHRHZ006: Operation not permitted
    That's not a Perl error, but an error generated from an external command.
    Can't call method "sheets" on an undefined value at /var/www/cgi-bin/perldev/excel.cgi line 22.
    That means that in $xls->sheets, $xls is undefined. $xls is whatever is returned by Spreadsheet::ParseExcel::Simple->read('/root/FLA_DHRS/SHRHZ006/7513.xls'); You don't check whether that returns an object or not.

    Abigail

Re: permission problems between commandline and CGI
by b10m (Vicar) on Jan 27, 2004 at 22:54 UTC

    I'd say your web daemon user (probably "nobody", or "www") is not allowed to execute `ncpmount`. And the same user is probably also not allowed to jiggle around in /root/ (and there's nothing wrong with that ;).

    You've got to really ask yourself wheter you want to mount something through a webinterface, for it's not very secure.

    --
    b10m
Re: permission problems between commandline and CGI
by borisz (Canon) on Jan 27, 2004 at 23:02 UTC
    This means that the uid/gid pair of your webserver is not allowed to mount something. see chmod/chown or look into your httpd.conf under User and Group settings. The second error looks like a result from the first. You try to read a file that can not reached.
    Boris
subtle details
by Anonymous Monk on Jan 28, 2004 at 01:26 UTC

    As most has been already to varying degrees been pointed out accurately, I will comment on some subtle but essential details (forgive my offtopicness):

    1.) Numerical comparisons are handled by the == comparator
    
    Substitute
    
    
    if ($connect eq 1) { }
    
    with
    
    
    if ($connect) { }
    
    or (unnecessary)
    
    
    if ($connect == 1) { }
    
    2.) Use here docs
    
    Instead of saying
    
    
    print "<center>"; print "<H2> Error: Could not connect to server </H2>"; print "Please Try again later"; print "<HR></center>";
    
    use
    
    
    print <<'HTML'; <center> <H2> Error: Could not connect to server </H2> Please Try again later <HR></center> HTML
    
    3.) use strict && use warnings
    

    Always use strict. Always use warnings. Those will prevent a good amount of self-induced headache; latter should be omitted in ``production" code.

Re: permission problems between commandline and CGI
by eoin (Monk) on Jan 27, 2004 at 23:12 UTC
    "Error 1 Cannot to mount on /root/FLA_DHRS/SHRHZ006: Operation not permitted"
    I'm no expert on these matters but this clearly tells me that you do not have adequit permissions to access this directory. Try moving the file to a directory that you can access.
    "Error 2 Can't call method "sheets" on an undefined value at /var/www/cgi-bin/perldev/excel.cgi line 22."
    You get this error because $xls is undefined because $xls = Spreadsheet::ParseExcel::Simple->read('/root/FLA_DHRS/SHRHZ006/7513.xls') can't set $xls because it can't access the specified file.

    So I think that all you have to do is change the permissions for that directory/file or move the file to another directory, one that you can access.

    Hope it helps
    Eoin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://324557]
Approved by dbwiz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-12-11 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?