Gossamer Forum
Home : Products : DBMan : Customization :

Mail to Admin with new user

Quote Reply
Mail to Admin with new user
I am trying to modify the signup so that the admin is notified by e-mail that a new user has signed up and what his/ her login name is. I stole the following from the validate mod but I definately have the syntax wrong if I don't have more wrong. I added the following variables to the authorization section of default.cfg:

# Full path to sendmail on your system
$mailprog = "|/usr/sbin/sendmail";

# Fieldname that contains the email address of the user
$db_email_field = 'e-mail';

# Your email address
$admin_email = '*****.******@******.org';


Here's my feable attempt to write add the mail script to the sub_signup section of db.cgi:

sub signup {
# --------------------------------------------------------
# Allows a user to sign up without admin approval. Must have $auth_signup = 1
# set. The user gets @default_permissions.
#
my $message;

# Check to make sure userid is ok, pw ok, and userid is unique.
unless ((length($in{'userid'}) >= 5) and (length($in{'userid'}) <= 30) and ($in{'userid'} =~ /^[a-zA-Z0-9\.]+$/)) {
$message = "Invalid userid: $in{'userid'}. Must only contain only letters and be less then 30 and greater then 5 characters.";
}
unless ((length($in{'pw'}) >= 3) and (length($in{'pw'}) <= 12)) {
$message = "Invalid pw: '$in{'pw'}'. Must be less then 12 and greater then 3 characters.";
}
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
while (<PASS>) {
/^\Q$in{'userid'}\E:/ and ($message = "userid already exists. Please try another.");
}
unless ($in{'question1'} =~ /griffiths/i) {
$message = "$in{'question1'} is not a correct answer.";
}
unless ($in{'question2'} =~ /west end/i) {
$message = "$in{'question2'} is not a correct answer.";
}
unless ($in{'question3'} =~ /pavilion/i) {
$message = "$in{'question3'} is not a correct answer.";
}
close PASS;
if ($message) {
&html_signup_form ($message);
return;
}

# Add the userid into the file with default permissions.
open (PASS, ">>$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'pw'}, $salt);
my $permissions = join (":", @auth_signup_permissions);

print PASS "$in{'userid'}:$encrypted:$permissions\n";
close PASS;


&html_signup_success;
}

# Send an email to the administrator telling him of the new user.
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: New Record at $html_title\n\n";
print MAIL "A new record was added at $html_title with the following information:\n\n";
foreach $column (@db_cols) {
print MAIL "$column: $rec{$column}\n";
}
print MAIL "\n\n";
close MAIL;




sub get_record {
# --------------------------------------------------------
# Given an ID as


Quote Reply
Re: Mail to Admin with new user In reply to
I would have been better to steal the code from the secure password lookup mod.

Code:

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Account Created\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "An account at $html_title has been created.\n\n";
print MAIL "User ID: $in{'userid'}\n";
print MAIL "Password: $in{'pw'}\n\n";
close (MAIL);
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Mail to Admin with new user In reply to
This is so frustrating. I tried everything I could come up with to give JPDeni a break while her back was injured, but I just can't get it to work. I just don't know the syntax for the code. JPDeni, I pasted your suggestion into the db.cgi at the end of sub_signup so that it looks like this:

my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'pw'}, $salt);
my $permissions = join (":", @auth_signup_permissions);

print PASS "$in{'userid'}:$encrypted:$permissions\n";
close PASS;


open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Account Created\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "An account at $html_title has been created.\n\n";
print MAIL "User ID: $in{'userid'}\n";
print MAIL "Password: $in{'pw'}\n\n";
close (MAIL);


&html_signup_success;
}



sub get_record {
# --------------------------------------------------------
# Given an ID as input, get_record returns a hash of the
# requested record or undefined if not found.

my ($key, $found, $line, @data, $field, $restricted);
$key = $_[0];
$found = 0;
($restricted = 1) if ($auth_modify_own and !$per_admin);


I added these variables to default.cfg so it looks like this:


# Full path and file name of the log file.
$auth_log_file = $db_script_path . "/default.log";
# Full path and file name of the html routines.
require $db_script_path . "/html.pl";
# Full path to sendmail on your system
$mailprog = "|/usr/sbin/sendmail";
# Your email address
$admin_email = 'xxxxx@xxxxxxxxx.xxx';


(I've blanked out the e-mail address). When I put the script back in it comes up with a 500 server error. I remove it and re-FTP it and it works fine, so I know it's not a problem with the transfer. I know that's the location of sendmail for my system but I don't know about the | at the beginning of it which I got from the secure password mod (nor do I know about the -t -oeq which is added afterward in the secure pass mod). I also have the user id defined in my database as username (I still don't quite have a grasp how the auth database and the db database interact - I believe userid is common between them), anyway I tried it as username instead of userid and even removed the password line because I don't need to know that and still nothing. Hope this message isn't too confusing. Thanks again, and JPDeni, I hope you feel better.

P.S. What is the role of the \n in the e-mail part of it.





Quote Reply
Re: Mail to Admin with new user In reply to
The code JPDeni provided:

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Account Created\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "An account at $html_title has been created.\n\n";
print MAIL "User ID: $in{'userid'}\n";
print MAIL "Password: $in{'pw'}\n\n";
close (MAIL);

should be placed in db.cgi right after &html_signup_success;
I don't belive you need the rest of what you have.

The /n adds a newline or line break

If you need more examples, please visit the FAQ noted below
and check under "Email" as there are several examples of sending email during different processes.

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Mail to Admin with new user In reply to
Thanks Lois, I just started from scratch with your e-mail thing from the FAQ and it worked perfectly. I don't know what combination of variables I had incorrect in JPDeni's but this did the trick. Thanks.