You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
7.1 KiB
206 lines
7.1 KiB
<?php
|
|
#==============================================================================
|
|
# LTB Self Service Password
|
|
#
|
|
# Copyright (C) 2009 Clement OUDOT
|
|
# Copyright (C) 2009 LTB-project.org
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program 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 General Public License for more details.
|
|
#
|
|
# GPL License: http://www.gnu.org/licenses/gpl.txt
|
|
#
|
|
#==============================================================================
|
|
|
|
# This page is called to change password
|
|
|
|
#==============================================================================
|
|
# POST parameters
|
|
#==============================================================================
|
|
# Initiate vars
|
|
$result = "";
|
|
$login = $presetLogin;
|
|
$firstname = "";
|
|
$lastname = "";
|
|
$email = "";
|
|
$password = "";
|
|
$confirmpassword = "";
|
|
$captchaphrase = "";
|
|
$ldap = "";
|
|
$userdn = "";
|
|
if (!isset($pwd_forbidden_chars)) { $pwd_forbidden_chars=""; }
|
|
$mail = "";
|
|
$extended_error_msg = "";
|
|
|
|
if ($use_captcha) {
|
|
if (isset($_POST["captchaphrase"]) and $_POST["captchaphrase"]) { $captchaphrase = strval($_POST["captchaphrase"]); }
|
|
else { $result = "captcharequired"; }
|
|
}
|
|
if (isset($_REQUEST["login"]) and $_REQUEST["login"]) { $login = strval($_REQUEST["login"]); }
|
|
else { $result = "loginrequired"; }
|
|
if (isset($_REQUEST["firstname"]) and $_REQUEST["firstname"]) { $firstname = strval($_REQUEST["firstname"]); }
|
|
else { $result = "firstnamerequired"; }
|
|
if (isset($_REQUEST["lastname"]) and $_REQUEST["lastname"]) { $lastname = strval($_REQUEST["lastname"]); }
|
|
else { $result = "lastnamerequired"; }
|
|
if (isset($_REQUEST["email"]) and $_REQUEST["email"]) { $email = strval($_REQUEST["email"]); }
|
|
else { $result = "emailrequired"; }
|
|
if (isset($_POST["password"]) and $_POST["password"]) { $password = strval($_POST["password"]); }
|
|
else { $result = "passwordrequired"; }
|
|
if (isset($_POST["confirmpassword"]) and $_POST["confirmpassword"]) { $confirmpassword = strval($_POST["confirmpassword"]); }
|
|
else { $result = "confirmpasswordrequired"; }
|
|
if (! isset($_REQUEST["login"]) and ! isset($_POST["email"]) and ! isset($_POST["password"]) and ! isset($_POST["confirmpassword"]))
|
|
{ $result = "emptychangeform"; }
|
|
|
|
# Check the entered username for characters that our installation doesn't support
|
|
if ( $result === "" ) {
|
|
$result = check_username_validity($login,$login_forbidden_chars);
|
|
}
|
|
|
|
# Match new and confirm password
|
|
if ( $password != $confirmpassword ) { $result="nomatch"; }
|
|
|
|
#==============================================================================
|
|
# Check captcha
|
|
#==============================================================================
|
|
if ( $result === "" && $use_captcha ) {
|
|
session_start();
|
|
if ( !check_captcha($_SESSION['phrase'], $captchaphrase) ) {
|
|
$result = "badcaptcha";
|
|
}
|
|
unset($_SESSION['phrase']);
|
|
}
|
|
|
|
#==============================================================================
|
|
# Check old password
|
|
#==============================================================================
|
|
if ( $result === "" ) {
|
|
|
|
# Connect to LDAP
|
|
$ldap = ldap_connect($ldap_url);
|
|
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
|
|
if ( $ldap_starttls && !ldap_start_tls($ldap) ) {
|
|
$result = "ldaperror";
|
|
error_log("LDAP - Unable to use StartTLS");
|
|
} else {
|
|
|
|
# Bind
|
|
if ( isset($ldap_binddn) && isset($ldap_bindpw) ) {
|
|
$bind = ldap_bind($ldap, $ldap_binddn, $ldap_bindpw);
|
|
} else {
|
|
$bind = ldap_bind($ldap);
|
|
}
|
|
|
|
if ( !$bind ) {
|
|
$result = "ldaperror";
|
|
$errno = ldap_errno($ldap);
|
|
if ( $errno ) {
|
|
error_log("LDAP - Bind error $errno (".ldap_error($ldap).")");
|
|
}
|
|
} else {
|
|
|
|
# Search for user
|
|
$ldap_filter = str_replace("{email}", $email, $ldap_filter);
|
|
$search = ldap_search($ldap, $ldap_base, $ldap_filter);
|
|
|
|
$errno = ldap_errno($ldap);
|
|
if ( $errno ) {
|
|
$result = "ldaperror";
|
|
error_log("LDAP - Search error $errno (".ldap_error($ldap).")");
|
|
} else {
|
|
|
|
# Get user DN
|
|
$entry = ldap_first_entry($ldap, $search);
|
|
if ( $entry != false ) {
|
|
$userdn = ldap_get_dn($ldap, $entry);
|
|
if( $userdn ) {
|
|
$result = "userexists";
|
|
error_log("LDAP - User $login found");
|
|
}
|
|
}
|
|
}}}
|
|
}
|
|
|
|
#==============================================================================
|
|
# Check password strength
|
|
#==============================================================================
|
|
if ( $result === "" ) {
|
|
$result = check_password_strength( $password, "" , $pwd_policy_config, $login, $entry );
|
|
}
|
|
|
|
#==============================================================================
|
|
# Build and store token
|
|
#==============================================================================
|
|
if ( $result === "" ) {
|
|
|
|
# Use PHP session to register token
|
|
# We do not generate cookie
|
|
ini_set("session.use_cookies",0);
|
|
ini_set("session.use_only_cookies",1);
|
|
|
|
session_name("token");
|
|
session_start();
|
|
$_SESSION['login'] = $login;
|
|
$_SESSION['firstname'] = $firstname;
|
|
$_SESSION['lastname'] = $lastname;
|
|
$_SESSION['email'] = $email;
|
|
$_SESSION['password'] = $password;
|
|
$_SESSION['time'] = time();
|
|
|
|
if ( $crypt_tokens ) {
|
|
$token = encrypt(session_id(), $keyphrase);
|
|
} else {
|
|
$token = session_id();
|
|
}
|
|
|
|
}
|
|
|
|
#==============================================================================
|
|
# Send token by mail
|
|
#==============================================================================
|
|
if ( $result === "" ) {
|
|
|
|
if ( empty($reset_url) ) {
|
|
|
|
# Build reset by token URL
|
|
$method = "http";
|
|
if ( !empty($_SERVER['HTTPS']) ) { $method .= "s"; }
|
|
$server_name = $_SERVER['SERVER_NAME'];
|
|
$server_port = $_SERVER['SERVER_PORT'];
|
|
$script_name = $_SERVER['SCRIPT_NAME'];
|
|
|
|
# Force server port if non standard port
|
|
if ( ( $method === "http" and $server_port != "80" )
|
|
or ( $method === "https" and $server_port != "443" )
|
|
) {
|
|
$server_name .= ":".$server_port;
|
|
}
|
|
|
|
$reset_url = $method."://".$server_name.$script_name;
|
|
}
|
|
|
|
$reset_url .= "?action=confirmcreate&token=".urlencode($token);
|
|
|
|
if ( !empty($reset_request_log) ) {
|
|
error_log("Send reset URL " . ( $debug ? "$reset_url" : "HIDDEN") . "\n\n", 3, $reset_request_log);
|
|
} else {
|
|
error_log("Send reset URL " . ( $debug ? "$reset_url" : "HIDDEN"));
|
|
}
|
|
|
|
$data = array( "login" => $login, "email" => $email, "url" => $reset_url ) ;
|
|
|
|
# Send message
|
|
if ( send_mail($mailer, $email, $mail_from, $mail_from_name, $messages["resetsubject"], $messages["resetmessage"].$mail_signature, $data) ) {
|
|
$result = "tokensent";
|
|
} else {
|
|
$result = "tokennotsent";
|
|
error_log("Error while sending token to $email (user $login)");
|
|
}
|
|
}
|