<?php /** * $Id: ajax_vw_user_authentications.php 25142 2014-10-07 12:16:51Z phenxdesign $ * * @category Admin * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: 25142 $ * @link http://www.mediboard.org */ CCanDo::checkEdit(); // Récuperation de l'utilisateur sélectionné $user_id = CValue::get("user_id"); $start = CValue::get("start"); $user = new CUser(); $user->load($user_id); $user->countConnections(); $user_authentication = new CUserAuthentication(); $ds = $user_authentication->getDS(); $where = array("user_id" => $ds->prepare("= ?", $user_id)); $limit = intval($start) . ", 30"; $list = $user_authentication->loadList($where, "datetime_login DESC", $limit); $smarty = new CSmartyDP(); $smarty->assign("list", $list); $smarty->assign("user", $user); $smarty->display("inc_vw_user_authentications.tpl");
/** * $Id$ * * @package Mediboard * @subpackage System * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ */ CCanDo::checkRead(); $start = CValue::get("start", 0); $date_min = CValue::getOrSession("date_min", CMbDT::dateTime("-2 MONTH")); $date_max = CValue::getOrSession("date_max"); $user_id = CValue::getOrSession("user_id"); $user_agent_id = CValue::get("user_agent_id"); $auth = new CUserAuthentication(); $ua = new CUserAgent(); $where = array("datetime_login" => ">= '{$date_min}'"); if ($date_max) { $where[] = "datetime_login <= '{$date_min}'"; } if ($user_id) { $where["user_id"] = "<= '{$user_id}'"; } if ($user_agent_id) { $where["user_agent_id"] = "= '{$user_agent_id}'"; $ua->load($user_agent_id); } $limit = (int) $start . ",100"; $total = $auth->countList($where); /** @var CUserAuthentication[] $auth_list */
/** * Login function, handling standard login, loginas, LDAP connection * Preferences get loaded on success * * @param bool $force_login To allow admin users to login as someone else * * @return boolean Job done */ static function login($force_login = false) { $ldap_connection = CAppUI::conf("admin LDAP ldap_connection"); $allow_login_as_ldap = CAppUI::conf("admin LDAP allow_login_as_admin"); // Login as $loginas = trim(CValue::request("loginas")); $passwordas = trim(CValue::request("passwordas")); // LDAP $ldap_guid = trim(CValue::get("ldap_guid")); // Standard login $username = trim(CValue::request("username")); $password = trim(CValue::request("password")); // Token sign-in $token_hash = trim(CValue::request("token")); // Test login and password validity $user = new CUser(); $user->_is_logging = true; // -------------- Login as: no need to provide a password for administrators if ($loginas) { if (self::$instance->user_type != 1 && !$force_login) { self::setMsg("Auth-failed-loginas-admin", UI_MSG_ERROR); return false; } $username = $loginas; $password = $ldap_connection ? $passwordas : null; if (self::$instance->user_type == 1 && $allow_login_as_ldap) { $password = null; } $user->user_username = $username; $user->_user_password = $password; } elseif ($ldap_connection && $ldap_guid) { try { $user = CLDAP::getFromLDAPGuid($ldap_guid); } catch (Exception $e) { self::setMsg($e->getMessage(), UI_MSG_ERROR); return false; } } elseif ($token_hash) { $token = CViewAccessToken::getByHash($token_hash); if (!$token->isValid()) { self::setMsg("Auth-failed-invalidToken", UI_MSG_ERROR); return false; } $token->useIt(); $token->applyParams(); $user->load($token->user_id); self::$instance->auth_method = "token"; } elseif (self::$auth_info && self::$auth_info->user_id) { $auth = self::$auth_info; $user->load($auth->user_id); self::$instance->auth_method = $auth->auth_method; } else { if (!$username) { self::setMsg("Auth-failed-nousername", UI_MSG_ERROR); return false; } if (!$password) { self::setMsg("Auth-failed-nopassword", UI_MSG_ERROR); return false; } $user->user_username = $username; $user->_user_password = $password; self::$instance->weak_password = self::checkPasswordWeakness($user); } if (!$user->_id) { $user->loadMatchingObject(); self::$instance->auth_method = "basic"; } // User template case if ($user->template) { self::setMsg("Auth-failed-template", UI_MSG_ERROR); return false; } // LDAP case (when not using a ldap_guid), we check is the user in the LDAP directory is still allowed // TODO we shoud check it when using ldap_guid too if ($ldap_connection && $username) { $user_ldap = new CUser(); $user_ldap->user_username = $username; $user_ldap->loadMatchingObject(); $idex = $user_ldap->loadLastId400(CAppUI::conf("admin LDAP ldap_tag")); // The user in linked to the LDAP if ($idex->_id) { $ldap_guid = $idex->id400; $user_ldap->_user_password = $password; $user_ldap->_bound = false; try { $user = CLDAP::login($user_ldap, $ldap_guid); if (!$user->_bound) { self::setMsg("Auth-failed-combination", UI_MSG_ERROR); return false; } } catch (CMbInvalidCredentialsException $e) { self::setMsg($e->getMessage(), UI_MSG_WARNING); return false; } catch (CMbException $e) { // No UI_MSG_ERROR nor $e->stepAjax as it needs to run through! self::setMsg($e->getMessage(), UI_MSG_WARNING); } } } if (!$user->_bound && !self::checkPasswordAttempt($user)) { return false; } $user->user_login_errors = 0; $user->store(); // Put user_group in AppUI self::$instance->user_remote = 1; $ds = CSQLDataSource::get("std"); // We get the user's group if the Mediusers module is installed if ($ds->loadTable("users_mediboard") && $ds->loadTable("groups_mediboard")) { $sql = "SELECT `remote` FROM `users_mediboard` WHERE `user_id` = '{$user->_id}'"; self::$instance->user_remote = $ds->loadResult($sql); $sql = "SELECT `groups_mediboard`.`group_id`\n FROM `groups_mediboard`, `functions_mediboard`, `users_mediboard`\n WHERE `groups_mediboard`.`group_id` = `functions_mediboard`.`group_id`\n AND `functions_mediboard`.`function_id` = `users_mediboard`.`function_id`\n AND `users_mediboard`.`user_id` = '{$user->_id}'"; self::$instance->user_group = $ds->loadResult($sql); } // Test if remote connection is allowed // Get the client and the proxy IP $adress = get_remote_address(); self::$instance->ip = $adress["client"]; self::$instance->proxy = $adress["proxy"]; self::$instance->_is_intranet = is_intranet_ip(self::$instance->ip) && self::$instance->ip != self::conf("system reverse_proxy"); if (!self::$instance->_is_intranet && self::$instance->user_remote == 1 && $user->user_type != 1) { self::setMsg("Auth-failed-user-noremoteaccess", UI_MSG_ERROR); return false; } self::$instance->user_id = $user->_id; // save the last_login dateTime CUserAuthentication::logAuth($user); // <DEPRECATED> self::$instance->user_first_name = $user->user_first_name; self::$instance->user_last_name = $user->user_last_name; self::$instance->user_email = $user->user_email; self::$instance->user_type = $user->user_type; self::$instance->user_last_login = $user->getLastLogin(); // </DEPRECATED> // load the user preferences self::buildPrefs(); return true; }
/** * Get last authentication * * @return CUserAuthentication|null */ function loadRefLastAuth() { if (!$this->_id || !CUserAuthentication::authReady()) { return null; } $authentications = $this->loadBackRefs("authentications", "datetime_login DESC", 1); if (!empty($authentications)) { $this->_ref_last_auth = reset($authentications); } return $this->_ref_last_auth; }