##################################################################### # script: db.cgi # # sub change_email_in_records # # # # new subroutine # # # ##################################################################### sub change_email_in_records { # -------------------------------------------------------- # The code below will change the email address in record(s) belonging # to the user. In order to use this, "auth_user_field" set in your # .cfg file. It is best if you use the &get_email modification # as well. my ($userid) = $_[0]; my (@lines, $output, $line, @data); open (DB, "<$db_file_name") or &cgierr("error in change_email. unable to open db file: $db_file_name.\nReason: $!"); if ($db_use_flock) { flock(DB, 1); } @lines = ; # Slurp the database into @lines.. close DB; LINE: foreach $line (@lines) { if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines chomp ($line); @data = &split_decode($line); if ($userid eq $data[$auth_user_field]) { $data[$auth_email_field] = $in{'email'}; %rec = &array_to_hash(0,@data); $line = &join_encode(%rec); } $output .= $line . "\n"; } open (DB, ">$db_file_name") or &cgierr("error in change_email. unable to open db file: $db_file_name.\nReason: $!"); if ($db_use_flock) { flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!"); } print DB $output; close DB; # automatically removes file lock } #################################################################### # In sub admin_display, after # If we have a username, and the admin didn't press inquire, then # we are updating a user. ($in{'username'} && !$in{'inquire'}) and do { open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!"); if ($db_use_flock) { flock(PASS, 1); } @lines = ; close PASS; foreach $pass (@passwds) { # Go through each pass and see if we match.. next if ($pass =~ /^$/); # Skip blank lines. next if ($pass =~ /^#/); # Skip Comment lines. chomp ($pass); ($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $pass); if (($in{'email'} eq $email) && ($in{'username'} ne $userid)) { $message .= "email address already exists."; last CASE; } } ########## # add ########## if ($auth_email_field >= 0) { &change_email_in_records($in{'username'}); } #################################################################### # In sub change_email, after close (MAIL); ########## # add ########## if ($auth_email_field >= 0) { &change_email_in_records($db_userid); }