Welcome!

The Perl CGI script is being run under the userid of the webserver (I'm assuming this is Apache under FreeBSD or Linux?), not your own. The directory where your file is to be created/opened needs to be writable by the webserver.

First, find out what userid the httpd daemons are running as:
$ ps -aux | grep httpd root 17714 0.0 0.2 5184 4456 ?? Ss 7Jun06 0:12.49 /usr/lo +cal/sbin/httpd www 17715 0.0 0.4 9164 8272 ?? I 7Jun06 0:00.24 /usr/lo +cal/sbin/httpd www 17716 0.0 0.4 8744 7864 ?? I 7Jun06 0:00.15 /usr/lo +cal/sbin/httpd www 17717 0.0 0.4 8768 7996 ?? I 7Jun06 0:00.19 /usr/lo +cal/sbin/httpd www 17724 0.0 0.4 8748 7788 ?? I 7Jun06 0:00.19 /usr/lo +cal/sbin/httpd www 17756 0.0 0.4 8772 7820 ?? I 7Jun06 0:00.20 /usr/lo +cal/sbin/httpd dwilde 7928 0.0 0.0 1512 988 p7 S+ 6:28AM 0:00.00 grep ht +tpd
You'll note that the primary (on my system) is running as root, the rest as user 'www'. Therefore, the directory on the filesystem -- and it should be fully specified, such as '/var/web/root/logs/mylog.log' -- needs to be writable by www, or whatever your server is set up as. Apache configurations are very flexible, and it's equally likely your server will be running under user 'nobody'. In any event, make writing possible:
$ su Password: # chown www /var/web/root/logs # chmod 744 /var/web/root/logs # exit $
As has been mentioned, allowing somebody to open a file on your server and write to it can cause mucho heartburn. Be very careful what you allow and who you allow to do it. I'd suggest that you force the directory and only allow the filename to be chosen:
my $subject = param('subject'); open (LOG, ">/var/web/root/logs/$subject") || die "Error opening file +: $!\n";
And make sure that your script is limited as to how much information can be written to the file. Bear in mind that Perl can be used to poke a webserver as well as being poked, and some nasty little script kiddie will surely use it to do so at some point in your life. =8^O

Don Wilde
"There's more than one level to any answer."

In reply to Re: use variable as name for new file by samizdat
in thread use variable as name for new file by Zcity

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.