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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |