2004-11-18 20:01:12 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-11-18 20:01:12 +00:00
|
|
|
|
2007-07-23 20:30:30 +00:00
|
|
|
// email-related utilities.
|
|
|
|
// Don't put specific message text here.
|
|
|
|
|
2004-11-18 20:01:12 +00:00
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../project/project.inc");
|
|
|
|
|
2006-05-09 18:25:15 +00:00
|
|
|
$config = get_config();
|
|
|
|
$master_url = parse_config($config, "<master_url>");
|
|
|
|
|
2006-06-16 23:53:56 +00:00
|
|
|
// Determine if phpmailer is installed and to be used (defined in project.inc)
|
2005-10-01 17:34:09 +00:00
|
|
|
if (isset($USE_PHPMAILER)) {
|
2005-09-30 06:17:43 +00:00
|
|
|
if ($USE_PHPMAILER) {
|
|
|
|
require_once("../inc/phpmailer/class.phpmailer.php");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$USE_PHPMAILER = false;
|
2005-08-29 23:51:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-08 17:46:47 +00:00
|
|
|
// send an email, using PHPMailer or not.
|
2006-07-01 20:03:48 +00:00
|
|
|
//
|
2006-07-05 21:38:08 +00:00
|
|
|
function send_email($user, $subject, $body, $body_html=null) {
|
2005-08-29 23:51:38 +00:00
|
|
|
global $USE_PHPMAILER;
|
|
|
|
global $PHPMAILER_HOST;
|
|
|
|
global $PHPMAILER_MAILER;
|
|
|
|
|
|
|
|
if ($USE_PHPMAILER) {
|
|
|
|
$mail = new PHPMailer();
|
|
|
|
$mail->AddAddress($user->email_addr, $user->name);
|
|
|
|
$mail->Subject = $subject;
|
2006-07-05 21:38:08 +00:00
|
|
|
if ($body_html) {
|
|
|
|
$mail->AltBody = $body;
|
|
|
|
$mail->Body = $body_html;
|
|
|
|
} else {
|
|
|
|
$mail->Body = $body;
|
|
|
|
}
|
2005-08-29 23:51:38 +00:00
|
|
|
$mail->From = EMAIL_FROM;
|
2006-07-05 21:38:08 +00:00
|
|
|
$mail->FromName = EMAIL_FROM_NAME;
|
2005-08-29 23:51:38 +00:00
|
|
|
$mail->Host = $PHPMAILER_HOST;
|
|
|
|
$mail->Mailer = $PHPMAILER_MAILER;
|
2007-12-24 03:45:20 +00:00
|
|
|
if (!$mail->Send()) {
|
2008-05-27 21:26:49 +00:00
|
|
|
echo $mail->ErrorInfo;
|
2007-12-24 03:45:20 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2005-08-29 23:51:38 +00:00
|
|
|
} else {
|
2008-04-15 22:42:23 +00:00
|
|
|
$headers ="";
|
|
|
|
if (defined('EMAIL_FROM') && defined('EMAIL_FROM_NAME')) {
|
|
|
|
$headers = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM.">";
|
|
|
|
} else if (defined('EMAIL_FROM')) {
|
2005-08-29 23:51:38 +00:00
|
|
|
$headers = "From: ". EMAIL_FROM;
|
|
|
|
}
|
|
|
|
return mail($user->email_addr, $subject, $body, $headers);
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 07:42:40 +00:00
|
|
|
|
2006-07-01 20:03:48 +00:00
|
|
|
// Send an email describing an account to the user.
|
|
|
|
// There are a few scenarios:
|
|
|
|
//
|
|
|
|
// 1) the account was created by user via web.
|
|
|
|
// In this case they're currently looking at the "validate account" page
|
|
|
|
// (account_created.php), although they might have strayed
|
|
|
|
// so we need to give them a link.
|
|
|
|
// 2) the account was created administratively
|
|
|
|
// 3) the user requested account key for existing account
|
|
|
|
//
|
2008-09-25 22:03:56 +00:00
|
|
|
function send_auth_email($user) {
|
2006-05-09 18:25:15 +00:00
|
|
|
global $master_url;
|
2004-12-06 22:41:19 +00:00
|
|
|
$body = "";
|
|
|
|
|
2008-09-25 22:03:56 +00:00
|
|
|
$now = time();
|
|
|
|
$x = md5($user->id.$user->authenticator.$now);
|
|
|
|
$x = substr($x, 0, 16);
|
|
|
|
$subject = PROJECT." account information";
|
2009-04-08 17:46:47 +00:00
|
|
|
$body = "This email was sent in response to a request on the ".PROJECT." web site.
|
2004-11-18 20:01:12 +00:00
|
|
|
|
2007-11-20 00:23:02 +00:00
|
|
|
To log in to your ".PROJECT." account, visit:
|
2007-11-20 03:08:35 +00:00
|
|
|
".$master_url."login_action.php?id=$user->id&t=$now&h=$x
|
|
|
|
(This link is valid for 1 day).
|
2007-11-20 00:23:02 +00:00
|
|
|
After logging in, you can change your account's password or email address.
|
2004-12-06 22:41:19 +00:00
|
|
|
";
|
2004-11-18 20:01:12 +00:00
|
|
|
|
2004-12-06 22:41:19 +00:00
|
|
|
$body .= "
|
2007-11-20 00:23:02 +00:00
|
|
|
For further information and assistance with ".PROJECT.", visit
|
2006-09-19 12:57:57 +00:00
|
|
|
$master_url
|
2004-11-18 20:01:12 +00:00
|
|
|
";
|
2005-08-29 23:51:38 +00:00
|
|
|
return send_email($user, $subject, $body);
|
2004-11-18 20:01:12 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 20:03:48 +00:00
|
|
|
// a valid email address is of the form A@B.C
|
|
|
|
// where A, B, C are nonempty,
|
|
|
|
// A and B don't contain @ or .,
|
2006-10-20 20:33:15 +00:00
|
|
|
// and C doesn't contain @ and is at least 2 chars
|
2006-07-01 20:03:48 +00:00
|
|
|
//
|
2004-11-18 20:01:12 +00:00
|
|
|
function is_valid_email_addr($addr) {
|
2006-10-20 20:33:15 +00:00
|
|
|
$pattern = '/^([^@]+)@([^@\.]+)\.([^@]{2,})$/';
|
|
|
|
$match = preg_match($pattern, $addr);
|
|
|
|
return (bool) $match;
|
2004-11-18 20:01:12 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 21:38:08 +00:00
|
|
|
function salted_key($key) {
|
|
|
|
return md5($key.'oogabooga');
|
|
|
|
}
|
|
|
|
|
2010-02-03 17:28:03 +00:00
|
|
|
function opt_out_url($user) {
|
|
|
|
return URL_BASE."opt_out.php?code=".salted_key($user->authenticator)."&userid=$user->id";
|
|
|
|
}
|
2004-11-18 20:01:12 +00:00
|
|
|
?>
|