00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: lostpw-confirm.php 5359 2006-02-14 08:47:46Z toddy $
00006 #
00007 # Copyright 1999-2000 (c) The SourceForge Crew
00008 # Copyright 2000-2003 (c) Free Software Foundation
00009 #
00010 # Copyright 2004-2005 (c) Mathieu Roy <yeupou--gnu.org>
00011 # Joxean Koret <joxeankoret--yahoo.es>
00012 #
00013 # The Savane project is free software; you can redistribute it and/or
00014 # modify it under the terms of the GNU General Public License
00015 # as published by the Free Software Foundation; either version 2
00016 # of the License, or (at your option) any later version.
00017 #
00018 # The Savane project is distributed in the hope that it will be useful,
00019 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 # GNU General Public License for more details.
00022 #
00023 # You should have received a copy of the GNU General Public License
00024 # along with the Savane project; if not, write to the Free Software
00025 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00026
00027 require "../include/pre.php";
00028
00029 $form_loginname = addslashes($form_loginname);
00030
00031 # CERN_SPECIFIC: here we also have a speech about AFS which must not be
00032 # hardcoded
00033 if ($GLOBALS['sys_use_pamauth'] == "yes") {
00034 db_query("SELECT user_pw FROM user WHERE user_name='$form_loginname'");
00035 $row_pw = db_fetch_array();
00036 if ($row_pw[user_pw] == 'PAM') {
00037 $HTML->header(array('title'=>"Lost Password Confirmation"));
00038 print "<p>This account uses an AFS password. <strong>You cannot change your
00039 AFS password via Savannah</strong>. Contact the AFS managers.";
00040 $HTML->footer(array());
00041 exit;
00042 }
00043 }
00044 # CERN_SPECIFIC
00045
00046 $confirm_hash = md5($session_hash . strval(time()) . strval(rand()));
00047
00048 ########################
00049 # Account check
00050 $res_user = db_query("SELECT * FROM user WHERE user_name='$form_loginname' AND status='A'");
00051 if (db_numrows($res_user) < 1)
00052 {
00053 exit_error(_("Invalid User"), _("This account does exist or has not been activated"));
00054 }
00055 $row_user = db_fetch_array($res_user);
00056
00057 ########################
00058 # Notification count check:
00059 # This code would allow to define the number of request that can be made
00060 # per hour.
00061 # By default, we set it to one
00062 $notifications_max = 1;
00063 unset($email_notifications);
00064
00065 $res_emails = db_query("SELECT count FROM user_lostpw WHERE user_id='".$row_user['user_id']."' and DAYOFYEAR(date) = DAYOFYEAR(CURRENT_DATE) AND HOUR(DATE) = HOUR(NOW())");
00066
00067 if (db_numrows($res_emails) < 1)
00068 {
00069 $row_emails = 0;
00070 }
00071 else
00072 {
00073 $row_emails = db_fetch_array($res_emails);
00074 $email_notifications = strval($row_emails[0]);
00075 }
00076
00077 if ($email_notifications == 0)
00078 {
00079 # This would be made empty by itself. We could have the login form
00080 # to remove old request.
00081 # But sv_cleaner will take care of it.
00082 $sql = "INSERT INTO user_lostpw VALUES ('".$row_user['user_id']."', CURRENT_TIMESTAMP, 1)";
00083 db_query($sql);
00084 }
00085 else
00086 {
00087 if ($email_notifications >= $notifications_max)
00088 {
00089 exit_error(_("An email for your lost password has already been sent. Please wait one hour and try again."));
00090 }
00091 else
00092 {
00093 $sql = "UPDATE user_lostpw SET
00094 count = count + 1
00095 WHERE
00096 user_id = '".$row_user['user_id']."' and DAYOFYEAR(DATE) = DAYOFYEAR(CURRENT_DATE)
00097 and HOUR(DATE) = HOUR(NOW())";
00098 db_query($sql);
00099 }
00100 }
00101
00102
00103 # If we get here, it is OK to continue
00104
00105 db_query("UPDATE user SET confirm_hash='$confirm_hash' WHERE user_id=$row_user[user_id]");
00106
00107 $message = sprintf(_("Someone (presumably you) on the %s site requested a password change through email verification."),$GLOBALS['sys_default_domain']);
00108 $message .= ' ';
00109 $message .= _("If this was not you, this could pose a security risk for the system.")."\n\n";
00110 $message .= sprintf(_("The request came from %s"),gethostbyaddr($GLOBALS['REMOTE_ADDR']))."\n";
00111 $message .= '(IP: '.$GLOBALS['REMOTE_ADDR'].' port: '.$GLOBALS['REMOTE_PORT'].")\n";
00112 $message .= _("with").' '.$GLOBALS['HTTP_USER_AGENT']."\n\n";
00113 $message .= _("If you requested this verification, visit this URL\nto change your password:")."\n\n";
00114 $message .= $GLOBALS['sys_https_url'].$GLOBALS['sys_home']."account/lostlogin.php?confirm_hash=".$confirm_hash."\n\n";
00115 # There should be a discard procedure
00116 $message .= _("If you did not request this verification, please visit this URL to cancel it.")."\n\n";
00117 $message .= _("In any case make sure that you do not disclose this url to\n somebody else, e.g. do not mail this to a public mailinglist!\n\n");
00118 $message .= sprintf(_("-- the %s team."),$GLOBALS['sys_name'])."\n";
00119
00120 # We should not add i18n to admin messages
00121 $message_for_admin =
00122 "Someone attempted to change a password via email verification\n"
00123 . "on ".$GLOBALS['sys_default_domain']."\n\n"
00124 . "Someone is maybe trying to steal a user account.\n\n"
00125 . "The user affected is ".$form_loginname."\n\n"
00126 . "The request comes from ".gethostbyaddr($GLOBALS['REMOTE_ADDR'])." "
00127 . "(IP: ".$GLOBALS['REMOTE_ADDR']." port: ".$GLOBALS['REMOTE_PORT'].") "
00128 . "with ".$GLOBALS['HTTP_USER_AGENT']."\n\n"
00129 . "Date:"
00130 . gmdate('D, d M Y H:i:s \G\M\T')
00131 . "\n";
00132
00133 sendmail_mail($GLOBALS['sys_mail_replyto']."@".$GLOBALS['sys_mail_domain'],
00134 $row_user['email'],
00135 $GLOBALS['sys_default_domain']." Verification",
00136 $message);
00137
00138 sendmail_mail($GLOBALS['sys_mail_replyto']."@".$GLOBALS['sys_mail_domain'],
00139 $GLOBALS['sys_mail_admin']."@".$GLOBALS['sys_mail_domain'],
00140 "password change - ".$GLOBALS['sys_default_domain'],
00141 $message_for_admin,
00142 0,
00143 "lostpw");
00144
00145 fb(_("Confirmation mailed"));
00146
00147 $HTML->header(array('title'=>_("Lost Password Confirmation")));
00148
00149
00150 print '<p>'._("An email has been sent to the address you have on file.").'</p>';
00151 print '<p>'._("Follow the instructions in the email to change your account password.").'</p>';
00152 ;
00153
00154 $HTML->footer(array());
00155
00156 ?>