-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautenticaLDAP.php
More file actions
86 lines (71 loc) · 3.3 KB
/
autenticaLDAP.php
File metadata and controls
86 lines (71 loc) · 3.3 KB
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
<?php
/**
* En este frame se van cargado cada una de las funcionalidades del sistema
*
* Descripcion Larga
*
* @category
* @package SGD Orfeo
* @subpackage Main
* @author Community
* @author Skina Technologies SAS (http://www.skinatech.com)
* @license GNU/GPL <http://www.gnu.org/licenses/gpl-2.0.html>
* @link http://www.orfeolibre.org
* @version SVN: $Id$
* @since
*/
/* ---------------------------------------------------------+
| INCLUDES |
+--------------------------------------------------------- */
/* ---------------------------------------------------------+
| DEFINICIONES |
+--------------------------------------------------------- */
$ldapServer = '172.16.0.15'; //Nombre o IP del servidor de autenticacion LDAP
$cadenaBusqLDAP = 'dc=esepastosalud, dc=local'; //Cadena de busqueda en el servidor.
$campoBusqLDAP = 'sAMAccountName'; //Campo seleccionado (de las variables LDAP)
$adminLDAP = 'cn=consulta,ou=aplicaciones,dc=unicordoba,dc=edu,dc=co';
$paswLDAP = 'w9NaL0JHOv';
/* ---------------------------------------------------------+
| MAIN |
+--------------------------------------------------------- */
//echo '***********';
if ($connect = ldap_connect($ldapServer)) {
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($connect, $adminLDAP, $paswLDAP);
// enlace a la conexión
if (($bind = ldap_bind($connect, $adminLDAP, $paswLDAP)) == false) {
$mensajeError = "Falla la conexión con el servidor LDAP<br>" . $bind . $connect;
}
// else echo "Estoy conectado ..que bien <br>\n".$bind ;
// busca el usuario
if (($res_id = ldap_search($connect, "$cadenaBusqLDAP", "($campoBusqLDAP=$username)")) == false) {
$mensajeError = "No encontrado el usuario en el Arbol LDAP (" . $res_id . ")" . $username;
}
// else echo "Encontre usuario ..que bien (" . $res_id . ") " . $username."<br>\n " ;
if (ldap_count_entries($connect, $res_id) != 1) {
$mensajeError = "El usuario $username se encontró mas de 1 vez<br>";
// echo $mensajeError.'<br>';
}
// else echo "Solo un usuario encontrado ..que bien <br>\n " ;
if (( $entry_id = ldap_first_entry($connect, $res_id)) == false) {
$mensajeError = "No se obtuvieron resultados<br>";
// echo $mensajeError.'<br>';
}
// else echo "Obtiene el primer resultado ..que bien <br>\n " ;
if (( $user_dn = ldap_get_dn($connect, $entry_id)) == false) {
$mensajeError = "No se puede obtener el dn del usuario<br>";
$noexit = 'si';
// echo $mensajeError.' ***** '.$user_dn.'<br>';
}
// else echo "DN del usuario encontrado..que bien <br>\n ".$user_dn."<br>" ;
/* Autentica el usuario */
if (($link_id = ldap_bind($connect, $user_dn, $password)) == false) {
$mensajeError = "usuario o contraseña incorrectos";
}
// else echo "Usuario conectado ..que bien <br> \n ".$link_id.' ***** '.ldap_bind($connect, $user_dn, $password)."<br>" ;
ldap_close($connect);
} else {
$mensajeError = "no hay conexión a '$ldap_server'";
}
?>