source: admin/WebConsole/validacion/html/validacion_ldap.php @ 5d05b06

Last change on this file since 5d05b06 was b6ec162, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#834: Remove all redundant PHP closing tags.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1<?php
2
3function connect_to_ldap(){     
4        $server = "IP_SERVIDOR";
5        $port = '389';
6        $user = "USUARIO";
7        $pass = "PASSWORD";
8               
9        $result = null;
10        $ds=ldap_connect($server,$port);
11        if ($ds){
12                if ($r=@ldap_bind($ds,$user,$pass))
13                        $result = $ds;
14        }
15        return $result;
16}
17       
18function validate_user($user,$password){
19        if (($user=='') || ($password=='')){
20                $result['validation'] = -1;
21        }else{
22                if($ds = connect_to_ldap()){
23                        $dc = "dc=uhu, dc=es";
24                        $search = "uid=".$user;
25                        $sr=@ldap_search($ds,$dc,$search);
26                        $info = @ldap_get_entries($ds, $sr);
27
28                        if ($info["count"]==1){                                 
29                                $thedata = $info[0]["dn"];                                     
30                                if ($r=@ldap_bind($ds,$thedata,$password)){
31                                        $result['validation'] = 1;
32                                        // A parte de la validacion, se podrían coger otros datos...
33                                        /*
34                                        $result['name'] = $info[0]["cn"][0];
35                                        $result['dni'] = $info[0]["uhuuserdni"][0];
36                                        $result['email'] =  $info[0]["mail"][0];
37                                        */
38                                }
39                                else{
40                                        $result['validation'] = -1;
41                                }
42                        }
43                        else{
44                                $result['validation'] = -1;
45                        }                               
46                }
47                ldap_close($ds);
48        }
49        return $result;
50}
51
52/**
53 * Sincroniza una base de datos externa con la de OpenGnsys.
54 * No es necesaria su implementacion, puede dejarse en blanco
55 */
56function synchronize($validation){
57
58}
59
60
61/**
62 * Funcion de validacion para el cliente opengnsys.
63 * Recibe como parametros la variable $_POST proveniente de la pagina de login
64 * debe devolver true o false
65 */
66function validate($VARS){
67        $result=false;
68        $validationInfo = validate_user($VARS["login"], $VARS["password"]);
69        if($validationInfo["validation"] == 1){
70                $result = true;
71        }
72        return $result;
73}
Note: See TracBrowser for help on using the repository browser.