Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)

Reply
Thread Tools

PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)

 
 
PGPS
Guest
Posts: n/a
 
      11-08-2006
Hi,
1. I have a perl program which logs user inputs. It was working fine on
Linux system.

2. I moved my entire work onto my home PC with XP-Home/Active
Perl/Apache and running the program as a cgi-script. It was working
fine and was able to perform logs as usual, but I was unable to view
it.

3. Apache woudn't display .html files if they are in cgi-bin directory.
I had to move it out to htdocs and change the path of the file in PERL
program to point to the file in htdocs.

4. With this setup, I get an error "Cannot open file" in the error logs
of Apache. I can view the file on the internet, but the program is not
able to open to save the logs.

Can someone tell me what's going on. And how to fix it. Either at
Apache end (to be able to view .html files in cgi-bin directory) OR on
the PERL end, where I want to be able to make the file world writable
and perform logs.

Thanks.

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-08-2006
PGPS wrote:
> 1. I have a perl program which logs user inputs. It was working fine on
> Linux system.
>
> 2. I moved my entire work onto my home PC with XP-Home/Active
> Perl/Apache and running the program as a cgi-script. It was working
> fine and was able to perform logs as usual, but I was unable to view
> it.
>
> 3. Apache woudn't display .html files if they are in cgi-bin directory.


That's how it should be.

> I had to move it out to htdocs and change the path of the file in PERL
> program to point to the file in htdocs.
>
> 4. With this setup, I get an error "Cannot open file" in the error logs
> of Apache. I can view the file on the internet, but the program is not
> able to open to save the logs.
>
> Can someone tell me what's going on. And how to fix it.


Not based on what you've told us.

> Either at
> Apache end (to be able to view .html files in cgi-bin directory) OR on
> the PERL end, where I want to be able to make the file world writable
> and perform logs.


I think there is some fundamental misconception here. The fact that you
cannot read files with your browser when they are located in the cgi-bin
is unrelated to whether they can be opened for writing. Neither of these
things is Perl related.

Nevertheless, if you post some Perl code, somebody may be able to put
you in the right direction.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      11-09-2006

"PGPS" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
..
..
>
> 4. With this setup, I get an error "Cannot open file" in the error logs
> of Apache.


Can you extend that error message to include the name of the file that perl
couldn't open (in case it's not the file you think it was), and to include
the contents of $!.

Cheers,
Rob


 
Reply With Quote
 
PGPS
Guest
Posts: n/a
 
      11-09-2006
X-No-Archive:Yes

Thanks. I put the same question in Apache groups and I got a response
saying that "That's how it should be".

My question is: "What's the solution to get it working". Since, on the
Linux machine, on which I just had a user login (on someone else's
server), I could get it working. So, the configuration was changed. The
problem is not just HTML, I would like all the depended filies like
*.js, *.jpg, *.css, *.gif to be in the same directory as the program.

Anyway, the above is a Apache configuration problem. Below is my PERL
problem.

Below is the code:

open(LOGFILE, ">>/logs.html");
print LOGFILE "Some stuff here\n";
close(LOGFILE);

The error in the apache access logs is something to the effect that
"Cannot open file" and it points to the line number in the PERL program
which has this line:

open(LOGFILE, ">>/logs.html");

DIRECTORY STRUCTURE
[htdocs]
logs.html
[cgi-bin]
[program1]
prog1.cgi

htdocs and cgi-bin directories are in the same parent directory.
htdocs has logs.html file
cgi-bin has a folder called program1 and program1 folder has prog1.cgi



Thanks.

Sisyphus wrote:
> "PGPS" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> .
> .
> >
> > 4. With this setup, I get an error "Cannot open file" in the error logs
> > of Apache.

>
> Can you extend that error message to include the name of the file that perl
> couldn't open (in case it's not the file you think it was), and to include
> the contents of $!.
>
> Cheers,
> Rob


 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      11-09-2006

"PGPS" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
..
..
>
> The error in the apache access logs is something to the effect that
> "Cannot open file" and it points to the line number in the PERL program
> which has this line:
>
> open(LOGFILE, ">>/logs.html");
>


Beats me as to why that error appears in the apache logs.

I could understand it if the line in question was:

open(LOGFILE, ">>/logs.html") or die "Cannot open file";

in which case I would recommend changing it to:

open(LOGFILE, ">>/logs.html") or die "Cannot open file: $!";

(In fact, change it to that even if the code *does* read exactly as you
posted.)

The "$!" bit should provide some hint as to why the failure is occurring.

Cheers,
Rob


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-09-2006
PGPS <(E-Mail Removed)> wrote:

> X-No-Archive:Yes



Why do you want to (attempt to) set no archive?

(it does not work when you include it in the body like that, it
needs to be in the headers.
)


> I would like all the depended filies like
> *.js, *.jpg, *.css, *.gif to be in the same directory as the program.



Why would you like all the dependent files to be in the same
directory as the program?


> The error in the apache access logs is something to the effect that

^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^

Please post the exact text of any messages that you are getting.

The devil is in the details when debugging programs...



Have you seen the Posting Guidelines that are posted here frequently?


[snip TOFU]

--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      11-09-2006
PGPS wrote:
[...]

> open(LOGFILE, ">>/logs.html");


You have a file in your root ( '/' ) directory that's writable by
everyone??? Use the full path to the file.
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-10-2006
(E-Mail Removed) <(E-Mail Removed)> wrote:
> Tad McClellan <(E-Mail Removed)> writes:
>> PGPS <(E-Mail Removed)> wrote:
>>
>> > X-No-Archive:Yes

>>
>>
>> Why do you want to (attempt to) set no archive?
>>
>> (it does not work when you include it in the body like that, it
>> needs to be in the headers.
>> )
>>

>
> I usually parse that as "X-Ignore-Me: Yes"



I have my newsreader parse that as "delete me automatically", but
it only works when it is in a header.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Mumia W. (reading news)
Guest
Posts: n/a
 
      11-10-2006
On 11/09/2006 11:11 AM, PGPS wrote:
> Sisyphus wrote:
>> "PGPS" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) ups.com...
>> .
>> .
>>> 4. With this setup, I get an error "Cannot open file" in the error logs
>>> of Apache.

>> Can you extend that error message to include the name of the file that perl
>> couldn't open (in case it's not the file you think it was), and to include
>> the contents of $!.
>>
>> Cheers,
>> Rob

>
>
> [...] I put the same question in Apache groups and I got a response
> saying that "That's how it should be".
>
> My question is: "What's the solution to get it working". Since, on the
> Linux machine, on which I just had a user login (on someone else's
> server), I could get it working. So, the configuration was changed. The
> problem is not just HTML, I would like all the depended filies like
> *.js, *.jpg, *.css, *.gif to be in the same directory as the program.
>
> Anyway, the above is a Apache configuration problem. Below is my PERL
> problem.
>
> Below is the code:
>
> open(LOGFILE, ">>/logs.html");
> print LOGFILE "Some stuff here\n";
> close(LOGFILE);
>
> The error in the apache access logs is something to the effect that
> "Cannot open file" and it points to the line number in the PERL program
> which has this line:
>
> open(LOGFILE, ">>/logs.html");


Why are you trying to write in the root directory? Does your web-server
has permission to write there?

>
> DIRECTORY STRUCTURE
> [htdocs]
> logs.html
> [cgi-bin]
> [program1]
> prog1.cgi
>
> htdocs and cgi-bin directories are in the same parent directory.
> htdocs has logs.html file
> cgi-bin has a folder called program1 and program1 folder has prog1.cgi
>
>
>
> Thanks.
>


1) The /.../htdocs directory almost certainly has different permissions
than the / (root) directory.

2) Often, web-servers don't have permission to write into their own
..html files because an intruder who manages to break into the web-server
can easily deface the website. You might have to change the permissions
on /.../htdocs/ and deal with the consequences.


--
(E-Mail Removed)

 
Reply With Quote
 
PGPS
Guest
Posts: n/a
 
      11-14-2006
Thank you all. I have been using relative path for my log files. When I
used the absolute path, it worked. The confusion started with my
changing all other paths to relative paths (images, .css etc.) and it
worked fine, except for the log files.

Thanks.
Joe Smith wrote:
> PGPS wrote:
>
> > open(LOGFILE, ">>/logs.html");
> >
> > DIRECTORY STRUCTURE
> > [htdocs]
> > logs.html
> > [cgi-bin]
> > [program1]
> > prog1.cgi

>
> That open() statement is definitely wrong.
>
> my $file = "$ENV{DOCUMENT_ROOT}/logs.html"; # Use full path name
> open(LOGFILE, ">>$file") or die "Cannot append to $file: $!\n";
>
> To access anything in htdocs, you need to either use a hardcoded
> absolute pathname (such as "/var/www/htdocs/logs.html") or use
> an ENV variable (such as what I've shown above).
>
> Remember, when the web server receives a request for "/logs.html"
> (such as from <a href="/logs.html">Log files</a>), it converts that
> string to a file name by using ServerRoot and/or DocumentRoot.
> Your CGI program needs to do the same thing; it cannot simply
> use the string "/logs.html" as it and expect it to work.
>
> -Joe


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get a writable FILE* from RFile in Ruby 1.9.1? bbr322 Ruby 1 04-04-2009 05:41 AM
Home directory not seen as writable in Vista David Sudlow Perl Misc 10 08-03-2007 03:20 PM
Readable/writable database in Perl Eric Perl Misc 8 04-27-2007 03:15 PM
"disallow sticky world writable directory in PATH": Why? Erik Veenstra Ruby 5 12-05-2005 03:58 PM
Active Directory Search fails ("The directory service is unavailab ejcosta ASP .Net Security 2 10-08-2004 09:57 AM



Advertisments