#!/usr/bin/perl -T use strict; use warnings; use CGI; my $w = new CGI; my $ip = $ENV{REMOTE_ADDR} || 'N/A'; my @errors = (); my $file = time.int rand 1_000_000; my %spec = ( username => qr#^[A-Za-z][-.\w]{2,29}$#, domain => qr#^(a|c|f|h|ho|i|k|o|s|x)\.com$#, email => qr#^[\w\.\-]+\@(?:[a-z\d\-]+\.)+[a-z\d]+$#i, service => qr#^Yes|No$#, conditions => qr#^Yes$#, ); my %fields; foreach( keys %spec ){ my $v = $w->param($_) or do { push @errors => "$_ not defined"; next }; $v =~ $spec{$_} or do { push @errors => "$_ invalid input"; next }; $fields{$_}=$v } print_error( @errors ) if @errors; open LOGFILE,'>>',"var/log/accounts/$file" or die "$file opening failed: $!"; print LOGFILE join(',',@fields{qw/username domain email service/},$ip),"\n"; close LOGFILE; print $w->header('text/plain'), "done"; sub print_error { print $w->header('text/plain'), @_; exit; }