1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189:
<?php
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.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. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// 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. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
/**
* Authorization classes, provisioning class file
*
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @license LICENSE.txt
* @category ICMS
* @package Auth
* @version SVN: $Id: Provisionning.php 12313 2013-09-15 21:14:35Z skenow $
*/
/**
* Authentification provisionning class. This class is responsible to
* provide synchronisation method to the user Database
*
* @copyright http://www.xoops.org/ The XOOPS Project
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @since XOOPS
* @category ICMS
* @package Auth
* @author http://www.xoops.org The XOOPS Project
* @author Pierre-Eric MENUET <pemphp@free.fr>
*/
class icms_auth_Provisionning {
private $_auth_instance;
/**
* Gets instance of {@link icms_auth_Provisionning}
* @param object $auth_instance
* @return object $provis_instance {@link icms_auth_Provisionning}
**/
static public function &getInstance(&$auth_instance) {
static $provis_instance;
if (!isset($provis_instance)) {
$provis_instance = new icms_auth_Provisionning($auth_instance);
}
return $provis_instance;
}
/**
* Authentication Service constructor
* @param object $auth_instance {@link icms_auth_Provisionning}
**/
public function __construct(&$auth_instance) {
$this->_auth_instance = &$auth_instance;
global $icmsConfig, $icmsConfigAuth;
foreach ($icmsConfigAuth as $key => $val) {
$this->$key = $val;
}
$this->default_TZ = $icmsConfig['default_TZ'];
$this->theme_set = $icmsConfig['theme_set'];
$this->com_mode = $icmsConfig['com_mode'];
$this->com_order = $icmsConfig['com_order'];
}
/**
* Return a User Object
* @param string $uname Username of the user
* @return mixed icms_member_user_Object {@link icms_member_user_Object} or false if failed
*/
public function geticms_member_user_Object($uname) {
$member_handler = icms::handler('icms_member');
$criteria = new icms_db_criteria_Item('uname', $uname);
$getuser = $member_handler->getUsers($criteria);
if (count($getuser) == 1) {
return $getuser[0];
} else {
return false;
}
}
/**
* Launch the synchronisation process
* @param array $datas Some Data
* @param string $uname Username of the user
* @param string $pwd Password of the user
* @return object icms_member_user_Object {@link icms_member_user_Object}
*/
public function sync($datas, $uname, $pwd = null) {
$icmsUser = $this->geticms_member_user_Object($uname);
if (!$icmsUser) {
// User Database not exists
if ($this->ldap_provisionning) {
$icmsUser = $this->add($datas, $uname, $pwd);
} else $this->_auth_instance->setErrors(0, sprintf(_AUTH_LDAP_XOOPS_USER_NOTFOUND, $uname));
} else {
// User Database exists
if ($this->ldap_provisionning && $this->ldap_provisionning_upd) {
$icmsUser = $this->change($icmsUser, $datas, $uname, $pwd);
}
}
return $icmsUser;
}
/**
* Adds a new user to the system
* @param array $datas Some Data
* @param string $uname Username of the user
* @param string $pwd Password of the user
* @return array $ret
*/
public function add($datas, $uname, $pwd = null) {
$ret = false;
$member_handler = icms::handler('icms_member');
// Create ImpressCMS Database User
$newuser = $member_handler->createUser();
$newuser->setVar('uname', $uname);
$newuser->setVar('pass', md5(stripslashes($pwd)));
//$newuser->setVar('name', utf8_decode($datas[$this->ldap_givenname_attr][0]) . ' ' . utf8_decode($datas[$this->ldap_surname_attr][0]));
//$newuser->setVar('email', $datas[$this->ldap_mail_attr][0]);
$newuser->setVar('rank', 0);
$newuser->setVar('level', 1);
$newuser->setVar('timezone_offset', $this->default_TZ);
$newuser->setVar('theme', $this->theme_set);
$newuser->setVar('umode', $this->com_mode);
$newuser->setVar('uorder', $this->com_order);
$tab_mapping = explode('|', $this->ldap_field_mapping);
foreach ($tab_mapping as $mapping) {
$fields = explode('=', trim($mapping));
if ($fields[0] && $fields[1])
$newuser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
}
if ($member_handler->insertUser($newuser)) {
foreach ($this->ldap_provisionning_group as $groupid) {
$member_handler->addUserToGroup($groupid, $newuser->getVar('uid'));
}
$newuser->unsetNew();
return $newuser;
} else {
redirect_header(ICMS_URL . '/user.php', 5, $newuser->getHtmlErrors());
}
return $ret;
}
/**
* Modify user information
* @param object {@link icms_member_user_Object} reference to icms_member_user_Object Object
* @param array $datas Some Data
* @param string $uname Username of the user
* @param string $pwd Password of the user
* @return object icms_member_user_Object {@link icms_member_user_Object}
*/
public function change(&$icmsUser, $datas, $uname, $pwd = null) {
$ret = false;
$member_handler = icms::handler('icms_member');
$icmsUser->setVar('pass', md5(stripslashes($pwd)));
$tab_mapping = explode('|', $this->ldap_field_mapping);
foreach ($tab_mapping as $mapping) {
$fields = explode('=', trim($mapping));
if ($fields[0] && $fields[1]) {
$icmsUser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
}
}
if ($member_handler->insertUser($icmsUser)) {
return $icmsUser;
} else {
redirect_header(ICMS_URL . '/user.php', 5, $icmsUser->getHtmlErrors());
}
return $ret;
}
}