123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- require_once api_get_path(SYS_PATH).'main/auth/cas/cas_var.inc.php';
- require_once api_get_path(SYS_PATH).'main/auth/external_login/ldap.inc.php';
- require_once api_get_path(SYS_PATH).'main/auth/external_login/functions.inc.php';
- function cas_configured()
- {
- global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
- $res = false;
- if (!empty($cas_auth_ver) && !empty($cas_auth_server) && !empty($cas_auth_port)) {
- $res = true;
- }
- return $res;
- }
- function cas_is_authenticated()
- {
- global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
- global $PHPCAS_CLIENT;
- global $logout;
- if (!cas_configured()) {
- return;
- }
- if (!is_object($PHPCAS_CLIENT)) {
- phpCAS::client($cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri);
- phpCAS::setNoCasServerValidation();
- }
- $auth = phpCAS::checkAuthentication();
- if ($auth) {
- $login = trim(phpCAS::getUser());
-
-
- if (!$logout) {
-
- $tab_user_info = api_get_user_info($login);
-
- if (is_array($tab_user_info)) {
-
- if (api_get_setting("update_user_info_cas_with_ldap") == "true") {
- $ldapuser = extldap_authenticate($login, 'nopass', true);
- if ($ldapuser !== false) {
- $chamilo_user = extldap_get_chamilo_user($ldapuser);
- $chamilo_user['user_id'] = $tab_user_info['user_id'];
- $chamilo_user['status'] = $tab_user_info['status'];
- UserManager::update_user(
- $chamilo_user["user_id"],
- $chamilo_user["firstname"],
- $chamilo_user["lastname"],
- $login,
- null,
- null,
- $chamilo_user["email"],
- $chamilo_user["status"],
- '',
- '',
- '',
- '',
- 1,
- null,
- 0,
- null,
- ''
- );
- }
- }
- return $login;
- }
- else {
-
- $user_added = false;
- switch (api_get_setting("cas_add_user_activate")) {
- case PLATFORM_AUTH_SOURCE:
-
- $userdata = get_lang("EditInProfil");
- UserManager::create_user(
- $userdata,
- $userdata,
- '5',
- $userdata,
- $login,
- 'casplaceholder',
- '',
- '',
- '',
- '',
- CAS_AUTH_SOURCE
- );
- $user_added = $login;
- break;
- case LDAP_AUTH_SOURCE:
-
-
-
-
- $ldapuser = extldap_authenticate($login, 'nopass', true);
- if ($ldapuser !== false) {
- $chamilo_user = extldap_get_chamilo_user($ldapuser);
- $chamilo_user['username'] = $login;
- $chamilo_user['auth_source'] = CAS_AUTH_SOURCE;
- $chamilo_uid = external_add_user($chamilo_user);
- $user_added = $login;
- }
- break;
- default:
- break;
- }
- return $user_added;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return $login;
- } else {
- return false;
- }
- }
- function cas_logout($uinfo = null, $location = null)
- {
- global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
- global $PHPCAS_CLIENT;
- if (!is_object($PHPCAS_CLIENT)) {
- phpCAS::client($cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri);
- phpCAS::setNoCasServerValidation();
- }
- if (!isset($location)) {
- $location = api_get_path(WEB_PATH);
- }
- phpCAS::logoutWithRedirectService($location);
- }
- function get_cas_direct_URL($in_course_code)
- {
- return api_get_path(WEB_PATH).'main/auth/cas/logincas.php?firstpage='.$in_course_code;
- }
- function getCASLogoHTML()
- {
- $out_res = "";
- if (api_get_setting("casLogoURL") != "") {
- $out_res = "<img src='".api_get_setting("casLogoURL")."' alt='CAS Logo' />";
- }
- return $out_res;
- }
|