#!/usr/bin/perl # Libraries use strict; use lib '../../propslib'; use vars qw(%c); use PropsConfig ( ) ; *c = \%PropsConfig::c; use Authen::Users; use CGI qw/:push/; # Global Constants my $props_group = 'props'; # Global Constructors my $q = new CGI; my $auth = new Authen::Users(dbtype => 'SQLite', dbname => "$c{PROPS_REL_PATH}/$c{PROPS_USERS_DB}", create=>1); # Global Variables $q->import_names('in'); # Sanitize Inputs $in::email = CGI::escape($in::email); $in::email =~ s/%40/\@/; # hack to sanitize email but replace the @ sign $in::password = CGI::escape($in::password); $in::fullname = CGI::escape($in::fullname); $in::question = CGI::escape($in::question); $in::question =~ s/%3F/?/g; $in::answer = CGI::escape($in::answer); print $q->header; if ($in::Action eq 'AddUser') { print qq[
]; # Check Required Fields if ( !$in::password || !$in::fullname || !$in::email || !$in::question || !$in::answer ) { print qq[

Failed

All Fields Are Required

]; } else { if ( !valid_email($in::email) ) { print qq[

Failed

Invalid Email Address

$in::email

]; } else { if ( $auth->is_in_table($props_group, $in::email) ) { print qq[

Failed

User Already Exists

]; } else { # Using $in::email as username my $result = $auth->add_user( $props_group, $in::email, $in::password, $in::fullname, $in::email, $in::question, $in::answer); if ($result) { print qq[

Success

User Added

Login now

]; } else { print qq[

Failed

System Error

Please contact administrator

]; } } } } print qq[
]; } else { # Show form (Default Behavior) print < Props User Registration

Props User Registration

Register

Login | Reset Password

EOHTML } # Subroutines sub valid_email { my($addr) = @_; my($domain, $valid); return(0) unless ($addr =~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/); $domain = (split(/@/, $addr))[1]; $valid = 0; open(DNS, "nslookup -q=any $domain |") || return(-1); while () { $valid = 1 if (/^$domain.*\s(mail exchanger|internet address)\s=/); } return($valid); }