I would think there would be a FAQ on how to give your CGIs access to write local files while minimizing security risks. But The Idiot's CGI Guide didn't mention this and pointed to The WWW Security FAQ, which also didn't mention it (that I could see).

So here are some things I consider important:

If, like many of us, asking questions of your web server administrator is difficult, you can figure out a lot about your server configuration with some experiments. Let's assume that your user name is "joe", the root of the web tree or subtree that you have control over is "~/webroot", it is served as "http:://www.x.com/~joe", your CGIs go in "~/webroot/cgi-bin", and they are served as "http://www.x.com/cgi-bin/cgiwrap/joe/script.pl".

cd ~/webroot chmod u=rwx,go=rx . mkdir test cd test chmod u=rwx,go=r . echo "<html><body>Nothing here.</body></html>" >index.html chmod ugo=r index.html mkdir hades chmod u=rw,go=r hades cd .. mkdir cgi-bin cd cgi-bin chmod u=rwx,go=rx .

Now you can put test scripts in your cgi-bin directory and figure out if your server chroot()s, what UID your CGIs run under, etc.

print "Content-type: text/html\r\n\r\n<HTML><BODY><PRE>\n"; print "$< $> $( $) $^X $] $0\n"; print join(":",getpwuid($<)),"\n"; print "$ENV{PATH}\n"; print `/bin/pwd`; # Not for Win32 #OR# print Win32::getcwd(),"\n"; # For Win32 print "</PRE></BODY></HTML>\n"; exit(0);

Then you can try creating files:

print "Content-type: text/html\r\n\r\n<HTML><BODY><PRE>\n"; if( ! chdir("~joe/webroot") ) { print "Can't chdir to ~joe/webroot: $!\n"; } elsif( ! open(TEST,"> hades/emptytest",0777) ) { print "Can't create emptytest: $!\n"; } else { close(TEST); } print "</PRE></BODY></HTML>\n"; exit(0);

Once you get files created, check the ownership and permissions on the created files to double check how your CGIs are being run, for example, what umask is set.

If you don't have shell access, then chmod via FTP will probably have to be run as quote site chmod (use quote help to check this).


In reply to Re: writting new files in perl by tye
in thread writting new files in perl by Anonymous Monk

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.