Greetings Gracious Monks of the Monastery!

I'm working on a simple newsletter script that receives email addresses from a form and stores them in a file. Here is what I have so far:

#!/usr/bin/perl -wT use strict; use CGI; use Email::Valid; # retrieve form parameter(s) my $q = new CGI; my $tainted_email = $q->param("email"); # check that $tainted_email is valid my $is_valid = Email::Valid->address('$tainted_email'); # if $tainted_email is valid, store the address in $email my $email = ""; if ($is_valid) { $email = $tainted_email; } # grab user information my $ip_address = $ENV{REMOTE_ADDR}; my $referrer = $ENV{HTTP_REFERER}; if ($email) { # store the data in a plain text file open LOG, ">>newsletter.txt" or die "Cannot Access Logfile: $!" print LOG "$email : $ip_address : $referrer\n"; close LOG; } # print thank-you page

The checks based on whether or not $tainted_email is valid seem rather messy to me. My primary concern is validating all the parameters that aren't sent to the script, including the IP address and the referrer. I want to ensure they're of valid structure, and of valid length. I'm also looking for a simple-as-possible storage mechanism for them (escaping issues?).

Also - I don't have access to httpd.conf but I'd like to ensure no one can read the files the info is stored in. Is there a simple way to do this (ie file permissions? I'm not sure what user the webserver is running as), or do I have to have .htaccess files enabled? Thank you for your time :)


In reply to Subscription form script 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.