Viewing file: newuser.pl (7.41 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl
###########################################################################
# newuser.pl - Create a new user account
###########################################################################
require "common.pl";
###########################################################################
# Print the header
###########################################################################
if ($button eq $cancel_button) {
&cancel;
}
&print_header;
###########################################################################
# Display the form for user creation
###########################################################################
if ($button ne $create_button) {
print $query->startform($method, $newuser_pl, $CGI::URL_ENCODED);
print "<TABLE BORDER=0><TR><TD>";
print $username_input;
print "</TD><TD>";
print $query->textfield('USERNAME', '', 24);
print "</TD></TR><TR><TD>";
print $pass_input;
print "</TD><TD>";
print $query->password_field('PASSWORD', '', 24);
print "</TD></TR><TR><TD>";
print $verify_input;
print "</TD><TD>";
print $query->password_field('PASS2', '', 24);
print "</TD></TR>";
# 990204 - jrtietsort - added sendmail config check
if ($feature_forward == 1 && $dont_mess_with_sendmail != 1) {
print "<TR><TD>";
print $email_input;
print "</TD><TD>";
print $query->textfield('EMAIL', '', 24);
print "</TD></TR><TR><TD>";
print $popserv_input;
print "</TD><TD>";
print $query->textfield('POPSERVER', '', 24);
print "</TD></TR><TR><TD>";
print $popname_input;
print "</TD><TD>";
print $query->textfield('POPUSERNAME', '', 24);
print "</TD></TR>";
}
print "<TR><TD>";
print $hint_input;
print "</TD><TD>";
print $query->textfield('HINT', '', 24);
print "</TD></TR></TABLE>";
print $query->submit('BUTTON', $create_button);
print $query->submit('BUTTON', $cancel_button);
print $query->endform;
}
if ($button eq $create_button) {
###########################################################################
# Make sure the account doesn't already exist
###########################################################################
dbmopen(%pass, $passdb, 0600) || die "Error opening db $passdb";
dbmopen(%reserved, $reserveddb, 0400) || die "Error opening db $reserveddb";
if ($pass{$username} || ($reserved{$username} == 1)) {
###########################################################################
# Already being used
###########################################################################
print "$username_used_info";
} elsif ($password ne $pass2) {
###########################################################################
# Passwords didn't match
###########################################################################
print "$diff_pass_info";
} elsif (!($username =~ /^\w/) || !($username =~ /^[\w|\d|_|\-|\.]*$/) ){
###########################################################################
# Bad user name
###########################################################################
print "$bad_username_info";
} elsif (index($password," ") >= 0) {
###########################################################################
# Password has a space in it
###########################################################################
print "$pass_invalid_info";
} elsif ($passwd =~ /,/) {
###########################################################################
# Password has a comma in it
###########################################################################
print "$pass_invalid_info";
} elsif (!$username || !$password) {
###########################################################################
# Missed a field
###########################################################################
print "$missing_field_info";
} else {
###########################################################################
# Add the user
###########################################################################
###########################################################################
# Encrypt the password
###########################################################################
$a = time;
chop($a);
srand($a);
$one = int(rand($a)) + 1;
$two = int(rand($a)) + 1;
$salt = "$one$two";
$hashed = crypt($password, $salt);
###########################################################################
# Store the password
###########################################################################
$pass{$username} = $hashed;
###########################################################################
# Store the POP server
###########################################################################
dbmopen(%server, $serverdb, 0600) || die "Error opening db $serverdb";
$server{$username} = $popserver;
dbmclose(%server);
###########################################################################
# Store the POP username
###########################################################################
dbmopen(%popname, $popdb, 0600) || die "Error opening db $popdb";
$popname{$username} = $popusername;
dbmclose(%popname);
###########################################################################
# Store the e-mail address
###########################################################################
dbmopen(%mail, $maildb, 0600) || die "Error opening $maildb";
$mail{$username} = $email;
dbmclose(%mail);
###########################################################################
# Create the virtual domain address
###########################################################################
if ($feature_forward == 1) {
dbmopen(%usertable, $usertable, 0600) || die "Error opening db $usertable";
$newaddress = $username . "\@" . $domain;
$usertable{$newaddress} = $email;
dbmclose(%usertable);
}
###########################################################################
# Store the hint
###########################################################################
dbmopen(%hints, $hintdb, 0600) || die "Error opening db $hintdb";
$hints{$username} = $hint;
dbmclose(%hints);
###########################################################################
# Let them know it worked and let them login
###########################################################################
print "$account_made_info";
print $query->startform($method, $login_pl, $CGI::URL_ENCODED);
print "<TABLE BORDER=\"0\"><TR><TD>";
print $username_input;
print "</TD><TD>";
print $query->hidden('USERNAME', $username);
print $username;
print "</TD></TR><TR><TD>";
print $adpass_input;
print "</TD><TD>";
print $query->hidden('PASSWORD', $password);
print "*****";
if ($feature_forward == 1) {
print "</TD></TR><TR><TD>";
print $poppass_input;
print "</TD><TD>";
print $query->password_field('POPPASS', '', 24);
}
print "</TD></TR></TABLE>\n";
print $query->submit('BUTTON', $login_button);
if($feature_pop == 0){
print $query->submit('BUTTON', $forgot_button);
print $query->reset($reset_button);
}
print $query->endform;
}
###########################################################################
# Close the open databases
###########################################################################
dbmclose(%pass);
dbmclose(%reserved);
}
###########################################################################
# Done
###########################################################################
&print_footer;
|