#!/usr/bin/perl -T use strict; use warnings; use CGI; ######################## # Set System Variables # ######################## my $w = new CGI; my $redir = new CGI; my $ip = $ENV{REMOTE_ADDR} || 'N/A'; my @errors = (); my $file = time.int rand 1_000_000; ###################### # Set Variable Specs # ###################### my %spec = ( fullname => qr/^ [-.\w\s] {3,30} \z/x, username => qr/^ [A-Za-z] [-.\w]{2,16} \z/x, mothers => qr/^ [-.\w\s] {3,30} \z/x, email => qr/^ [\w\.-]+ \@ (?:[a-z\d-]+\.)+ [a-z\d]+ \z/ix, conditions => qr/^Yes\z/, ); my %fields; ####################### # Check For Bad Input # ####################### foreach( keys %spec ){ my $v = $w->param($_) or do { push @errors => "$_ is not defined.\n"; next }; $v =~ $spec{$_} or do { push @errors => "$_ contains invalid input.\n"; next }; $fields{$_}=$v } if (getpwnam $fields{username}) { push @errors => "username already taken.\n"}; if ($fields{username} =~ m/^administrator|accounts|support|postmaster|webmaster|spam-admin| |technical|billing|sales|misuse|mail|virus-admin|manager|usenet|hostmaster$/) { push @errors => "username already taken.\n"}; print_error( @errors ) if @errors; ################################### # Log User Details For Processing # ################################### open LOGFILE,'>>',"/var/log/tmp/$file" or die "$file opening failed: $!"; print LOGFILE join(',',@fields{qw/fullname username mothers email/},$ip),"\n"; close LOGFILE; ########################## # Display Completed Page # ########################## print $redir->redirect('http://www.foo.com'); ###################### # Display Any Errors # ###################### sub print_error { print $w->header('text/plain'), @_; exit; }