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

Discussion in 'Perl Misc' started by PGPS, Nov 8, 2006.

  1. PGPS

    PGPS Guest

    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.
    PGPS, Nov 8, 2006
    #1
    1. Advertising

  2. Re: PERL can't open file for logging (world writable directory WindowsXP Home/ Active Perl / Apache)

    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
    Gunnar Hjalmarsson, Nov 8, 2006
    #2
    1. Advertising

  3. PGPS

    Sisyphus Guest

    "PGPS" <> wrote in message
    news:...
    ..
    ..
    >
    > 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
    Sisyphus, Nov 9, 2006
    #3
  4. PGPS

    PGPS Guest

    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" <> wrote in message
    > news:...
    > .
    > .
    > >
    > > 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
    PGPS, Nov 9, 2006
    #4
  5. PGPS

    Sisyphus Guest

    "PGPS" <> wrote in message
    news:...
    ..
    ..
    >
    > 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
    Sisyphus, Nov 9, 2006
    #5
  6. PGPS <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 9, 2006
    #6
  7. PGPS

    J. Gleixner Guest

    Re: PERL can't open file for logging (world writable directory WindowsXP Home/ Active Perl / Apache)

    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.
    J. Gleixner, Nov 9, 2006
    #7
  8. <> wrote:
    > Tad McClellan <> writes:
    >> PGPS <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 10, 2006
    #8
  9. Re: PERL can't open file for logging (world writable directory WindowsXP Home/ Active Perl / Apache)

    On 11/09/2006 11:11 AM, PGPS wrote:
    > Sisyphus wrote:
    >> "PGPS" <> wrote in message
    >> news:...
    >> .
    >> .
    >>> 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.


    --
    Mumia W. (reading news), Nov 10, 2006
    #9
  10. PGPS

    PGPS Guest

    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
    PGPS, Nov 14, 2006
    #10
  11. PGPS

    PGPS Guest

    X-No-Archive: YES
    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
    PGPS, Nov 14, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Ohlsen
    Replies:
    18
    Views:
    289
    Yukihiro Matsumoto
    Nov 27, 2003
  2. Jim Freeze
    Replies:
    3
    Views:
    108
    WATANABE Hirofumi
    Feb 17, 2004
  3. Erik Veenstra
    Replies:
    5
    Views:
    204
    Yukihiro Matsumoto
    Dec 5, 2005
  4. Sean Harre

    "insecure world writable" fix ?

    Sean Harre, Jul 20, 2006, in forum: Ruby
    Replies:
    7
    Views:
    126
    Fabian Streitel
    Sep 1, 2009
  5. David Sudlow

    Home directory not seen as writable in Vista

    David Sudlow, Aug 3, 2007, in forum: Perl Misc
    Replies:
    10
    Views:
    186
    Clenna Lumina
    Aug 3, 2007
Loading...

Share This Page