Subversion Repositories ALCASAR

Rev

Rev 1672 | Rev 1677 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1672 Rev 1673
1
<?php
1
<?php
2
require_once("lib/alcasar/freeradius/siteconfig.php");
2
require_once("lib/alcasar/freeradius/siteconfig.php");
3
require_once("lib/alcasar/freeradius/ldapconfig.php");
3
require_once("lib/alcasar/freeradius/ldapconfig.php");
4
 
4
 
5
/* written by steweb57 */
5
/* written by steweb57 */
6
/****************************************************************
6
/****************************************************************
7
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION	*
7
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION	*
8
*****************************************************************/
8
*****************************************************************/
9
 
9
 
10
define ("ALCASAR_RADIUS_SITE", "/etc/raddb/sites-available/alcasar");
10
define ("ALCASAR_RADIUS_SITE", "/etc/raddb/sites-available/alcasar");
11
define ("ALCASAR_RADIUS_MODULE_LDAP", "/etc/raddb/modules/ldap");
11
define ("ALCASAR_RADIUS_MODULE_LDAP", "/etc/raddb/modules/ldap");
12
 
12
 
13
/****************************************************************
13
/****************************************************************
14
*			Choice of language			*
14
*			Choice of language			*
15
*****************************************************************/
15
*****************************************************************/
16
 
16
 
17
$Language = 'en';
17
$Language = 'en';
18
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
18
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
19
	$Langue	= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
19
	$Langue	= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
20
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
20
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
21
if($Language == 'fr'){
21
if($Language == 'fr'){
22
	$l_file				= "Fichier ";
22
	$l_file				= "Fichier ";
23
	$l_not_found			= " non présent";
23
	$l_not_found			= " non présent";
24
	$l_no_writing_right_on_file	= "Vous n'avez pas les droits d'écriture sur le fichier ";
24
	$l_no_writing_right_on_file	= "Vous n'avez pas les droits d'écriture sur le fichier ";
25
	$l_ldap_update_sucess		= "Mise à jour des paramètres LDAP réalisée avec succès";
25
	$l_ldap_update_sucess		= "Mise à jour des paramètres LDAP réalisée avec succès";
26
	$l_ldap_title			= "Authentification externe : LDAP";
26
	$l_ldap_title			= "Authentification externe : LDAP";
27
	$l_ldap_legend			= "Authentification LDAP";
27
	$l_ldap_legend			= "Authentification LDAP";
28
	$l_ldap_auth_enable_label	= "Activer l'authentification LDAP:";
28
	$l_ldap_auth_enable_label	= "Activer l'authentification LDAP:";
29
	$l_ldap_YES			= "OUI";
29
	$l_ldap_YES			= "OUI";
30
	$l_ldap_NO			= "NON";
30
	$l_ldap_NO			= "NON";
31
	$l_ldap_server_label		= "Nom du serveur LDAP:";
31
	$l_ldap_server_label		= "Nom du serveur LDAP:";
32
	$l_ldap_server_text		= "Nom ou IP du serveur LDAP éventuel.";
32
	$l_ldap_server_text		= "Nom ou IP du serveur LDAP éventuel.";
33
	$l_ldap_base_dn_label		= "DN de la base LDAP:";
33
	$l_ldap_base_dn_label		= "DN de la base LDAP:";
34
	$l_ldap_base_dn_text		= "DN est le 'Distinguished Name', il situe les informations utilisateurs, exemple: 'o=Mon entreprise, c=FR'.";
34
	$l_ldap_base_dn_text		= "DN est le 'Distinguished Name', il définit où se situent les informations des utilisateurs dans l'annuaire. Exemple LDAP: 'o=mycompany, c=FR'. Exemple AD 'ou=my_lan,dc=server_name,dc=localdomain'";
35
	$l_ldap_filter_label		= "Identifiant LDAP:";
35
	$l_ldap_filter_label		= "Identifiant LDAP:";
36
	$l_ldap_filter_text		= "Clé utilisée pour la recherche d'un identifiant de connexion, exemple: 'uid', 'sn', etc. Pour un AD mettre 'sAMAccountName'.";
36
	$l_ldap_filter_text		= "Clé utilisée lors de la recherche d'un identifiant de connexion, exemple: 'uid', 'sn', etc. Pour un AD mettre 'sAMAccountName'.";
37
	$l_ldap_base_filter_label	= "Filtre de l'utilisateur LDAP:";
37
	$l_ldap_base_filter_label	= "Filtre de recherche d'utilisateurs LDAP:";
38
	$l_ldap_base_filter_text	= "Sur option, vous pouvez en plus limiter les objets recherchés avec des filtres additionnels. Par exemple 'objectClass=posixGroup' aurait comme conséquence l'utilisation de '(&amp;(uid=username)(objectClass=posixGroup))'";
38
	$l_ldap_base_filter_text	= "En option, vous pouvez limiter les objets recherchés avec des filtres additionnels. Par exemple 'objectClass=posixGroup' aurait comme conséquence l'utilisation de '(&amp;(uid=username)(objectClass=posixGroup))'";
39
	$l_ldap_user_label		= "Utilisateur LDAP:";
39
	$l_ldap_user_label		= "Utilisateur LDAP:";
40
	$l_ldap_user_text		= "Laissez vide pour utiliser un accès invité. Si renseigné, ALCASAR se connectera au serveur LDAP en tant qu'un utilisateur spécifié, exemple: 'uid=Utilisateur,ou=MonUnité,o=MaCompagnie,c=FR'. Requis pour les serveurs possédant un Active Directory.";
40
	$l_ldap_user_text		= "Nom d'utilisateur utilisé par ALCASAR pour se connecter au serveur LDAP. Laissez vide pour utiliser un accès invité (ou anomyme). Obligatoire sur un AD. exemple LDAP : 'uid=username,ou=my_lan,o=mycompany,c=FR'. Exemple AD : cn=username,ou=my_lan,dc=server_name,dc=localdomain'";
41
	$l_ldap_password_label		= "Mot de passe LDAP:";
41
	$l_ldap_password_label		= "Mot de passe LDAP:";
42
	$l_ldap_password_text		= "Laissez vide pour un accès invité. Sinon, indiquez le mot de passe de connexion. Requis pour les serveurs possédant un Active Directory.";
42
	$l_ldap_password_text		= "Laissez vide pour un accès invité (ou anonyme). Obligatoire sur un AD.";
43
	$l_ldap_submit			= "Enregistrer";
43
	$l_ldap_submit			= "Enregistrer";
44
	$l_ldap_reset			= "Annuler";
44
	$l_ldap_reset			= "Annuler";
45
	$l_ldap_test_network_failed	= "Pas de connectivité réseau avec le serveur LDAP.";
45
	$l_ldap_test_network_failed	= "Pas de connectivité réseau avec le serveur LDAP.";
46
	$l_ldap_test_connection_failed	= "Impossible de se connecter au serveur LDAP.";
46
	$l_ldap_test_connection_failed	= "Impossible de se connecter au serveur LDAP.";
47
	$l_ldap_test_bind_ok		= "Connexion LDAP réussie...";
47
	$l_ldap_test_bind_ok		= "Connexion LDAP réussie...";
48
	$l_ldap_test_bind_failed	= "Echec d'authentification sur le serveur LDAP...Vérifiez votre configuration ldap...";
48
	$l_ldap_test_bind_failed	= "Echec d'authentification sur le serveur LDAP... Vérifiez votre configuration";
49
	$l_ldap_test_dn_ok		= "DN semble bon";
49
	$l_ldap_test_dn_ok		= "DN semble bon";
50
	$l_ldap_test_dn_failed		= "DN semble mauvais";
50
	$l_ldap_test_dn_failed		= "DN semble mauvais";
51
} else {
51
} else {
52
	$l_file				= "File ";
52
	$l_file				= "File ";
53
	$l_not_found			= " not found";
53
	$l_not_found			= " not found";
54
	$l_no_writing_right_on_file	= "You have no writting permission on the file ";
54
	$l_no_writing_right_on_file	= "You have no writting permission on the file ";
55
	$l_ldap_update_sucess		= "Successfull LDAP settings update";
55
	$l_ldap_update_sucess		= "Successfull LDAP settings update";
56
	$l_ldap_title			= "External authentication : LDAP";
56
	$l_ldap_title			= "External authentication : LDAP";
57
	$l_ldap_legend			= "LDAP authentication";
57
	$l_ldap_legend			= "LDAP authentication";
58
	$l_ldap_auth_enable_label	= "Use LDAP authentication :";
58
	$l_ldap_auth_enable_label	= "Use LDAP authentication :";
59
	$l_ldap_YES			= "YES";
59
	$l_ldap_YES			= "YES";
60
	$l_ldap_NO			= "NO";
60
	$l_ldap_NO			= "NO";
61
	$l_ldap_server_label		= "LDAP server name:";
61
	$l_ldap_server_label		= "LDAP server name:";
62
	$l_ldap_server_text		= "This is the hostname or IP address of the LDAP server.";
62
	$l_ldap_server_text		= "This is the hostname or IP address of the LDAP server.";
63
	$l_ldap_base_dn_label		= "LDAP base dn:";
63
	$l_ldap_base_dn_label		= "LDAP base dn:";
64
	$l_ldap_base_dn_text		= "This is the 'Distinguished Name', locating the user information, e.g. 'o=My Company,c=US'.";
64
	$l_ldap_base_dn_text		= "This is the 'Distinguished Name', locating the user information in the directory. e.g. LDAP : 'o=MyCompany,c=US'. e.g. AD : 'ou=my_lan,dc=server_name,dc=localdomain'";
65
	$l_ldap_filter_label		= "LDAP uid:";
65
	$l_ldap_filter_label		= "LDAP uid:";
66
	$l_ldap_filter_text		= "This is the key under which to search for a given login identity, e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
66
	$l_ldap_filter_text		= "This is the key used to search for a given login identity, e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
67
	$l_ldap_base_filter_label	= "LDAP user filter:";
67
	$l_ldap_base_filter_label	= "LDAP user filter:";
68
	$l_ldap_base_filter_text	= "Optionally you can further limit the searched objects with additional filters. For example 'objectClass=posixGroup' would result in the use of '(&amp;(uid=username)(objectClass=posixGroup))'";
68
	$l_ldap_base_filter_text	= "Optionally you can further limit the searched objects with additional filters. For example 'objectClass=posixGroup' would result in the use of '(&amp;(uid=username)(objectClass=posixGroup))'";
69
	$l_ldap_user_label		= "LDAP user dn:";
69
	$l_ldap_user_label		= "LDAP user dn:";
70
	$l_ldap_user_text		= "Leave blank to use anonymous binding. If filled, ALCASAR uses the specified distinguished name on login attempts to find the correct user, e.g. 'uid=Username,ou=MyUnit,o=MyCompany,c=US'. Required for Active Directory Servers.";
70
	$l_ldap_user_text		= "Username used by ALCASAR to connect to the LDAP server. Leave blank to use anonymous binding. Required for AD. e.g. LDAP :'uid=Username,ou=my_lan,o=mycompany,c=US'. e.g. AD : cn=username,ou=my_lan,dc=server_name,dc=localdomain'";
71
	$l_ldap_password_label		= "LDAP password:";
71
	$l_ldap_password_label		= "LDAP password:";
72
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Else fill in the password for the above user. Required for Active Directory Servers.";
72
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Required for AD.";
73
	$l_ldap_submit			= "Save";
73
	$l_ldap_submit			= "Save";
74
	$l_ldap_reset			= "Reset";
74
	$l_ldap_reset			= "Reset";
75
	$l_ldap_test_network_failed	= "LDAP server is not reachable.";
75
	$l_ldap_test_network_failed	= "LDAP server is not reachable.";
76
	$l_ldap_test_connection_failed	= "LDAP connexion failed...";
76
	$l_ldap_test_connection_failed	= "LDAP connexion failed...";
77
	$l_ldap_test_bind_ok		= "LDAP connexion success...";
77
	$l_ldap_test_bind_ok		= "LDAP connexion success...";
78
	$l_ldap_test_bind_failed	= "LDAP authentication failed...Check your ldap setup...";
78
	$l_ldap_test_bind_failed	= "LDAP authentication failed...Check your ldap setup...";
79
	$l_ldap_test_dn_ok              = "DN seems to be right";
79
	$l_ldap_test_dn_ok              = "DN seems to be right";
80
	$l_ldap_test_dn_failed          = "DN seems to be wrong";
80
	$l_ldap_test_dn_failed          = "DN seems to be wrong";
81
}
81
}
82
/********************************************************
82
/********************************************************
83
*		TEST DES FICHIERS DE CONFIGURATION	*
83
*		TEST DES FICHIERS DE CONFIGURATION	*
84
*********************************************************/
84
*********************************************************/
85
 
85
 
86
//Test de présence et des droits en lecture des fichiers de configuration.
86
//Test de présence et des droits en lecture des fichiers de configuration.
87
if (!file_exists(ALCASAR_RADIUS_SITE)){
87
if (!file_exists(ALCASAR_RADIUS_SITE)){
88
	exit($l_file.ALCASAR_RADIUS_SITE.$l_not_found);
88
	exit($l_file.ALCASAR_RADIUS_SITE.$l_not_found);
89
}
89
}
90
if (!file_exists(ALCASAR_RADIUS_MODULE_LDAP)){
90
if (!file_exists(ALCASAR_RADIUS_MODULE_LDAP)){
91
	exit($l_file.ALCASAR_RADIUS_MODULE_LDAP.$l_not_found);
91
	exit($l_file.ALCASAR_RADIUS_MODULE_LDAP.$l_not_found);
92
}
92
}
93
if (!is_readable(ALCASAR_RADIUS_SITE)){
93
if (!is_readable(ALCASAR_RADIUS_SITE)){
94
	exit($l_no_writing_right_on_file.ALCASAR_RADIUS_SITE);
94
	exit($l_no_writing_right_on_file.ALCASAR_RADIUS_SITE);
95
}
95
}
96
if (!is_readable(ALCASAR_RADIUS_MODULE_LDAP)){
96
if (!is_readable(ALCASAR_RADIUS_MODULE_LDAP)){
97
	exit($l_no_writing_right_on_file.ALCASAR_RADIUS_MODULE_LDAP);
97
	exit($l_no_writing_right_on_file.ALCASAR_RADIUS_MODULE_LDAP);
98
}
98
}
99
 
99
 
100
/********************************************************
100
/********************************************************
101
*		VARIABLES DE FORMULAIRE			*
101
*		VARIABLES DE FORMULAIRE			*
102
*********************************************************/
102
*********************************************************/
103
 
103
 
104
if (isset($_GET['erreur'])&&(!($_GET['erreur']==""))) $erreur = $_GET['erreur']; else $erreur = false;//valeur de $erreur non controlée car ne sert qu'un afficher un msg.
104
if (isset($_GET['erreur'])&&(!($_GET['erreur']==""))) $erreur = $_GET['erreur']; else $erreur = false;//valeur de $erreur non controlée car ne sert qu'un afficher un msg.
105
if (isset($_GET['update'])&&($_GET['update']=="ok")) $update = true; else $update = false;
105
if (isset($_GET['update'])&&($_GET['update']=="ok")) $update = true; else $update = false;
106
 
106
 
107
$message = "";
107
$message = "";
108
if ((bool)$erreur){ 
108
if ((bool)$erreur){ 
109
	$message = "<div align=\"center\"><br>";
109
	$message = "<div align=\"center\"><br>";
110
	$message.="<strong><font color=\"red\">".$erreur."</font></strong><br>";
110
	$message.="<strong><font color=\"red\">".$erreur."</font></strong><br>";
111
	$message.="<br></div>";
111
	$message.="<br></div>";
112
}else{
112
}else{
113
	if ($update){
113
	if ($update){
114
		$message = "<div align=\"center\"><br>";
114
		$message = "<div align=\"center\"><br>";
115
		$message.="<strong><font color=\"green\">$l_ldap_update_sucess</font><br></strong>";
115
		$message.="<strong><font color=\"green\">$l_ldap_update_sucess</font><br></strong>";
116
		$message.="<br></div>";
116
		$message.="<br></div>";
117
	}
117
	}
118
}
118
}
119
 
119
 
120
/****************************************************************
120
/****************************************************************
121
*			VARIABLES RESULTATS			*
121
*			VARIABLES RESULTATS			*
122
*****************************************************************/
122
*****************************************************************/
123
//Création des variables nécessaires
123
//Création des variables nécessaires
124
//variables ldap
124
//variables ldap
125
$ldap_on		= "";
125
$ldap_on		= "";
126
$ldap_server	= ""; 	//IP ou nom DNS du seveur LDAP (ou AD)
126
$ldap_server	= ""; 	//IP ou nom DNS du seveur LDAP (ou AD)
127
						//par défaut : server = "ldap.your.domain"
127
						//par défaut : server = "ldap.your.domain"
128
$ldap_identity	= "";	//nom d'utilisateur qui intérroge le ldap (vide = anonyme)
128
$ldap_identity	= "";	//nom d'utilisateur qui intérroge le ldap (vide = anonyme)
129
						//par défaut : # identity = "cn=admin,o=My Org,c=UA"
129
						//par défaut : # identity = "cn=admin,o=My Org,c=UA"
130
$ldap_password	= "";	//mot de passe de l'utilisateur intérrogeant le ldap
130
$ldap_password	= "";	//mot de passe de l'utilisateur intérrogeant le ldap
131
						//par défaut : # password = mypass
131
						//par défaut : # password = mypass
132
$ldap_basedn	= "";	//DN de base ou l'on recherchera les utilisateurs 
132
$ldap_basedn	= "";	//DN de base ou l'on recherchera les utilisateurs 
133
						//par défaut : basedn = "o=My Org,c=UA"
133
						//par défaut : basedn = "o=My Org,c=UA"
134
$ldap_filter	= "";	//permet entre autre de déterminer l'attribut utilisé pour la recherche d'un utilisateur dans LDAP
134
$ldap_filter	= "";	//permet entre autre de déterminer l'attribut utilisé pour la recherche d'un utilisateur dans LDAP
135
						//attribut uid pour un ldap standard, samaccountname pour AD
135
						//attribut uid pour un ldap standard, samaccountname pour AD
136
						//par défaut : filter = "(uid=%{Stripped-User-Name:-%{User-Name}})"
136
						//par défaut : filter = "(uid=%{Stripped-User-Name:-%{User-Name}})"
137
$ldap_base_filter = "";	//
137
$ldap_base_filter = "";	//
138
						//par défaut : # base_filter = "(objectclass=radiusprofile)"
138
						//par défaut : # base_filter = "(objectclass=radiusprofile)"
139
 
139
 
140
/********************************************************
140
/********************************************************
141
*		Fichier ALCASAR_RADIUS_SITE		*
141
*		Fichier ALCASAR_RADIUS_SITE		*
142
*********************************************************/
142
*********************************************************/
143
$site = new siteConfig();
143
$site = new siteConfig();
144
$site->load(ALCASAR_RADIUS_SITE);
144
$site->load(ALCASAR_RADIUS_SITE);
145
$ldap_on = $site->authorize->ldap;
145
$ldap_on = $site->authorize->ldap;
146
 
146
 
147
/********************************************************
147
/********************************************************
148
*		Fichier ALCASAR_RADIUS_MODULE_LDAP	*
148
*		Fichier ALCASAR_RADIUS_MODULE_LDAP	*
149
*********************************************************/
149
*********************************************************/
150
//Lecture du fichier /etc/raddb/modules/ldap
150
//Lecture du fichier /etc/raddb/modules/ldap
151
$ldap = new ldapConfig();
151
$ldap = new ldapConfig();
152
$ldap->load(ALCASAR_RADIUS_MODULE_LDAP);
152
$ldap->load(ALCASAR_RADIUS_MODULE_LDAP);
153
$ldap_server		= $ldap->host;		// others options only in alcasar 3.x ($ldap->server)
153
$ldap_server		= $ldap->host;		// others options only in alcasar 3.x ($ldap->server)
154
$ldap_identity		= $ldap->identity;
154
$ldap_identity		= $ldap->identity;
155
$ldap_password		= $ldap->password;
155
$ldap_password		= $ldap->password;
156
$ldap_basedn		= $ldap->basedn;
156
$ldap_basedn		= $ldap->basedn;
157
$ldap_filter		= $ldap->uid;		// others options only in alcasar 3.x ($ldap->filter)
157
$ldap_filter		= $ldap->uid;		// others options only in alcasar 3.x ($ldap->filter)
158
$ldap_base_filter	= $ldap->base_filter;
158
$ldap_base_filter	= $ldap->base_filter;
159
 
159
 
160
function ldap_test($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_filter, $f_ldap_port = "389"){
160
function ldap_test($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_filter, $f_ldap_port = "389"){
161
	// Test du serveur
161
	// Test du serveur
162
	if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
162
	if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
163
		// no network connection
163
		// no network connection
164
		return -1;
164
		return -1;
165
	} else {
165
	} else {
166
		fclose($sock);
166
		fclose($sock);
167
		// Connexion au serveur LDAP
167
		// Connexion au serveur LDAP
168
		$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
168
		$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
169
		ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
169
		ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
170
		if ($ldapconn) {
170
		if ($ldapconn) {
171
			$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
171
			$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
172
			if ($ldapbind) {
172
			if ($ldapbind) {
173
				// LDAP Bind success
173
				// LDAP Bind success
174
				//try search
174
				//try search
175
				$query = $f_ldap_filter."=*";
175
				$query = $f_ldap_filter."=*";
176
				if($search = ldap_search($ldapconn, $f_ldap_basedn, $query)){
176
				if($search = ldap_search($ldapconn, $f_ldap_basedn, $query)){
177
				 	ldap_unbind($ldapconn);      
177
				 	ldap_unbind($ldapconn);      
178
					return 2;
178
					return 2;
179
				} else {
179
				} else {
180
					ldap_unbind($ldapconn);
180
					ldap_unbind($ldapconn);
181
					return 1;
181
					return 1;
182
				}
182
				}
183
			} else {
183
			} else {
184
				// Test LDAP Version 3
184
				// Test LDAP Version 3
185
				ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
185
				ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
186
				$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
186
				$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
187
				if ($ldapbind) {
187
				if ($ldapbind) {
188
					// LDAP Bind success
188
					// LDAP Bind success
189
					//try search
189
					//try search
190
					$query = $f_ldap_filter."=*";
190
					$query = $f_ldap_filter."=*";
191
					if($search = ldap_search($ldapconn, $f_ldap_basedn, $query)){
191
					if($search = ldap_search($ldapconn, $f_ldap_basedn, $query)){
192
						ldap_unbind($ldapconn);
192
						ldap_unbind($ldapconn);
193
						return 2;
193
						return 2;
194
					} else {
194
					} else {
195
				ldap_unbind($ldapconn);
195
				ldap_unbind($ldapconn);
196
				return 1;
196
				return 1;
197
					}
197
					}
198
				} else {
198
				} else {
199
					// LDAP Bind failed
199
					// LDAP Bind failed
200
					return 0;
200
					return 0;
201
				}
201
				}
202
			}
202
			}
203
		} else {
203
		} else {
204
			// LDAP connection failed
204
			// LDAP connection failed
205
			return -2;
205
			return -2;
206
		}
206
		}
207
 
207
 
208
	}
208
	}
209
}
209
}
210
 
210
 
211
/********************************
211
/********************************
212
*		TO DO		*
212
*		TO DO		*
213
*********************************/
213
*********************************/
214
//internationnalisation à mettre en haut du fichier pour internationnaliser les erreurs de script!
214
//internationnalisation à mettre en haut du fichier pour internationnaliser les erreurs de script!
215
?>
215
?>
216
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
216
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
217
<html><!-- written by steweb57 -->
217
<html><!-- written by steweb57 -->
218
<head>
218
<head>
219
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
219
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
220
<title><?php echo $l_ldap_title; ?></title>
220
<title><?php echo $l_ldap_title; ?></title>
221
<link rel="stylesheet" href="/css/style.css" type="text/css">
221
<link rel="stylesheet" href="/css/style.css" type="text/css">
222
<link rel="stylesheet" href="/css/ldap.css" type="text/css">
222
<link rel="stylesheet" href="/css/ldap.css" type="text/css">
223
<script language="javascript">
223
<script language="javascript">
224
function testLdapActif(){
224
function testLdapActif(){
225
	//List des ID des éléments à désactiver
225
	//List des ID des éléments à désactiver
226
	var listToDisables = new Array("ldap_server","ldap_dn","ldap_filter","ldap_base_filter","ldap_user","ldap_password");
226
	var listToDisables = new Array("ldap_server","ldap_dn","ldap_filter","ldap_base_filter","ldap_user","ldap_password");
227
 
227
 
228
	if (document.getElementById("auth_enable").value == "1"){
228
	if (document.getElementById("auth_enable").value == "1"){
229
		for (var i=0;i<listToDisables.length;i++){
229
		for (var i=0;i<listToDisables.length;i++){
230
			document.getElementById(listToDisables[i]).style.backgroundColor ="#ffffff";
230
			document.getElementById(listToDisables[i]).style.backgroundColor ="#ffffff";
231
			document.getElementById(listToDisables[i]).disabled = false;
231
			document.getElementById(listToDisables[i]).disabled = false;
232
		}
232
		}
233
	} else {
233
	} else {
234
		for (var i=0;i<listToDisables.length;i++){
234
		for (var i=0;i<listToDisables.length;i++){
235
			document.getElementById(listToDisables[i]).style.backgroundColor ="#c0c0c0";
235
			document.getElementById(listToDisables[i]).style.backgroundColor ="#c0c0c0";
236
			document.getElementById(listToDisables[i]).disabled = true;
236
			document.getElementById(listToDisables[i]).disabled = true;
237
		}
237
		}
238
	}
238
	}
239
}
239
}
240
</script>
240
</script>
241
</head>
241
</head>
242
<body onLoad="testLdapActif();">
242
<body onLoad="testLdapActif();">
243
<table width="100%" border=0 cellspacing=0 cellpadding=0>
243
<table width="100%" border=0 cellspacing=0 cellpadding=0>
244
<tr><th><?php echo $l_ldap_legend; ?></th></tr>
244
<tr><th><?php echo $l_ldap_legend; ?></th></tr>
245
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width=1 height=2></td></tr>
245
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width=1 height=2></td></tr>
246
</table>
246
</table>
247
<table width="100%" border=1 cellspacing=0 cellpadding=1>
247
<table width="100%" border=1 cellspacing=0 cellpadding=1>
248
<tr><td valign="middle" align="left">
248
<tr><td valign="middle" align="left">
249
<form name="config_ldap" method="post" action="update_ldap.php">
249
<form name="config_ldap" method="post" action="update_ldap.php">
250
<fieldset>
250
<fieldset>
251
<legend>
251
<legend>
252
<?php
252
<?php
253
echo $message;
253
echo $message;
254
$pos = strpos($ldap_server, "//");
254
$pos = strpos($ldap_server, "//");
255
if ($pos!==false){
255
if ($pos!==false){
256
	$new_ldap_server = explode("//",$ldap_server); //pour discriminer le host et le protocole dans la notation "ldap://192.168.182.10" ou "ldaps://monldap.monentreperise.com"
256
	$new_ldap_server = explode("//",$ldap_server); //pour discriminer le host et le protocole dans la notation "ldap://192.168.182.10" ou "ldaps://monldap.monentreperise.com"
257
} else {
257
} else {
258
	$new_ldap_server = $ldap_server;
258
	$new_ldap_server = $ldap_server;
259
}
259
}
260
if (($ldap_on == "ldap") && (function_exists('ldap_connect'))){
260
if (($ldap_on == "ldap") && (function_exists('ldap_connect'))){
261
	echo "<div align='center'><br>";	
261
	echo "<div align='center'><br>";	
262
 
262
 
263
	switch(ldap_test($new_ldap_server, $ldap_identity, $ldap_password, $ldap_basedn, $ldap_filter)){
263
	switch(ldap_test($new_ldap_server, $ldap_identity, $ldap_password, $ldap_basedn, $ldap_filter)){
264
		case -2:
264
		case -2:
265
			echo "<font color='red'>".$l_ldap_test_connection_failed."</font>";
265
			echo "<font color='red'>".$l_ldap_test_connection_failed."</font>";
266
			break;
266
			break;
267
		case -1:
267
		case -1:
268
			echo "<font color='red'>".$l_ldap_test_network_failed."</font>";
268
			echo "<font color='red'>".$l_ldap_test_network_failed."</font>";
269
			break;
269
			break;
270
		case 0:
270
		case 0:
271
			echo "<font color='red'>".$l_ldap_test_bind_failed."</font>";
271
			echo "<font color='red'>".$l_ldap_test_bind_failed."</font>";
272
			break;
272
			break;
273
		case 1:
273
		case 1:
274
			echo "<font color='green'>".$l_ldap_test_bind_ok."</font>";
274
			echo "<font color='green'>".$l_ldap_test_bind_ok."</font>";
275
			echo "<br>";
275
			echo "<br>";
276
			echo "<font color='red'>".$l_ldap_test_dn_failed."</font>";
276
			echo "<font color='red'>".$l_ldap_test_dn_failed."</font>";
277
			break;
277
			break;
278
		case 2:
278
		case 2:
279
			echo "<font color='green'>".$l_ldap_test_bind_ok."</font>";
279
			echo "<font color='green'>".$l_ldap_test_bind_ok."</font>";
280
			echo "<br>";
280
			echo "<br>";
281
			echo "<font color='green'>".$l_ldap_test_dn_ok."</font>";
281
			echo "<font color='green'>".$l_ldap_test_dn_ok."</font>";
282
		break;
282
		break;
283
		default:
283
		default:
284
			echo "LDAP error";
284
			echo "LDAP error";
285
	}
285
	}
286
	echo "<br><br></div>"; 
286
	echo "<br><br></div>"; 
287
}
287
}
288
?>
288
?>
289
</legend>
289
</legend>
290
<dl>
290
<dl>
291
  <dt>
291
  <dt>
292
    <label for="auth_enable"><?php echo $l_ldap_auth_enable_label; ?></label>
292
    <label for="auth_enable"><?php echo $l_ldap_auth_enable_label; ?></label>
293
  </dt>
293
  </dt>
294
  <dd>
294
  <dd>
295
    <select id="auth_enable" name="auth_enable" onchange="testLdapActif();">
295
    <select id="auth_enable" name="auth_enable" onchange="testLdapActif();">
296
	<?php if ($ldap_on == "ldap") { 
296
	<?php if ($ldap_on == "ldap") { 
297
      echo "<option value=\"1\" selected=\"selected\">$l_ldap_YES</option>";
297
      echo "<option value=\"1\" selected=\"selected\">$l_ldap_YES</option>";
298
      echo "<option value=\"0\">$l_ldap_NO</option>";	
298
      echo "<option value=\"0\">$l_ldap_NO</option>";	
299
	}else{
299
	}else{
300
      echo "<option value=\"1\">$l_ldap_YES</option>";
300
      echo "<option value=\"1\">$l_ldap_YES</option>";
301
      echo "<option value=\"0\" selected=\"selected\">$l_ldap_NO</option>";
301
      echo "<option value=\"0\" selected=\"selected\">$l_ldap_NO</option>";
302
	}?>
302
	}?>
303
    </select>
303
    </select>
304
  </dd>
304
  </dd>
305
</dl>
305
</dl>
306
<dl>
306
<dl>
307
  <dt>
307
  <dt>
308
    <label for="ldap_server"><?php echo $l_ldap_server_label; ?></label>
308
    <label for="ldap_server"><?php echo $l_ldap_server_label; ?></label>
309
    <br>
309
    <br>
310
    <?php echo $l_ldap_server_text; ?></dt>
310
    <?php echo $l_ldap_server_text; ?></dt>
311
  <dd>
311
  <dd>
312
    <input id="ldap_server" size="40" name="ldap_server" value="<?php echo htmlspecialchars($ldap_server); ?>">
312
    <input id="ldap_server" size="40" name="ldap_server" value="<?php echo htmlspecialchars($ldap_server); ?>">
313
  </dd>
313
  </dd>
314
</dl>
314
</dl>
315
<dl>
315
<dl>
316
  <dt>
316
  <dt>
317
    <label for="ldap_dn"><?php echo $l_ldap_base_dn_label; ?></label>
317
    <label for="ldap_dn"><?php echo $l_ldap_base_dn_label; ?></label>
318
    <br>
318
    <br>
319
    <?php echo $l_ldap_base_dn_text; ?></dt>
319
    <?php echo $l_ldap_base_dn_text; ?></dt>
320
  <dd>
320
  <dd>
321
    <input id="ldap_dn" size="40" name="ldap_base_dn" value="<?php echo htmlspecialchars($ldap_basedn); ?>">
321
    <input id="ldap_dn" size="40" name="ldap_base_dn" value="<?php echo htmlspecialchars($ldap_basedn); ?>">
322
  </dd>
322
  </dd>
323
</dl>
323
</dl>
324
<dl>
324
<dl>
325
  <dt>
325
  <dt>
326
    <label for="ldap_filter"><?php echo $l_ldap_filter_label; ?></label>
326
    <label for="ldap_filter"><?php echo $l_ldap_filter_label; ?></label>
327
    <br>
327
    <br>
328
    <?php echo $l_ldap_filter_text; ?></dt>
328
    <?php echo $l_ldap_filter_text; ?></dt>
329
  <dd>
329
  <dd>
330
    <input id="ldap_filter" size="40" name="ldap_filter" value="<?php echo htmlspecialchars($ldap_filter); ?>">
330
    <input id="ldap_filter" size="40" name="ldap_filter" value="<?php echo htmlspecialchars($ldap_filter); ?>">
331
  </dd>
331
  </dd>
332
</dl>
332
</dl>
333
<dl>
333
<dl>
334
  <dt>
334
  <dt>
335
    <label for="ldap_base_filter"><?php echo $l_ldap_base_filter_label; ?></label>
335
    <label for="ldap_base_filter"><?php echo $l_ldap_base_filter_label; ?></label>
336
    <br>
336
    <br>
337
    <?php echo $l_ldap_base_filter_text; ?></dt>
337
    <?php echo $l_ldap_base_filter_text; ?></dt>
338
  <dd>
338
  <dd>
339
    <input id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?php echo htmlspecialchars($ldap_base_filter); ?>">
339
    <input id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?php echo htmlspecialchars($ldap_base_filter); ?>">
340
  </dd>
340
  </dd>
341
</dl>
341
</dl>
342
<dl>
342
<dl>
343
  <dt>
343
  <dt>
344
    <label for="ldap_user"><?php echo $l_ldap_user_label; ?></label>
344
    <label for="ldap_user"><?php echo $l_ldap_user_label; ?></label>
345
    <br>
345
    <br>
346
    <?php echo $l_ldap_user_text; ?></dt>
346
    <?php echo $l_ldap_user_text; ?></dt>
347
  <dd>
347
  <dd>
348
    <input id="ldap_user" size="40" name="ldap_user" value="<?php echo htmlspecialchars($ldap_identity); ?>">
348
    <input id="ldap_user" size="40" name="ldap_user" value="<?php echo htmlspecialchars($ldap_identity); ?>">
349
  </dd>
349
  </dd>
350
</dl>
350
</dl>
351
<dl>
351
<dl>
352
  <dt>
352
  <dt>
353
    <label for="ldap_password"><?php echo $l_ldap_password_label; ?></label>
353
    <label for="ldap_password"><?php echo $l_ldap_password_label; ?></label>
354
    <br>
354
    <br>
355
    <?php echo $l_ldap_password_text; ?></dt>
355
    <?php echo $l_ldap_password_text; ?></dt>
356
  <dd>
356
  <dd>
357
    <input id="ldap_password" type="password" size="40" name="ldap_password" value="<?php echo htmlspecialchars($ldap_password);?>">
357
    <input id="ldap_password" type="password" size="40" name="ldap_password" value="<?php echo htmlspecialchars($ldap_password);?>">
358
  </dd>
358
  </dd>
359
</dl>
359
</dl>
360
<p>
360
<p>
361
  <input id="submit" type="submit" value="<?php echo $l_ldap_submit; ?>" name="submit">
361
  <input id="submit" type="submit" value="<?php echo $l_ldap_submit; ?>" name="submit">
362
 
362
 
363
  <input id="reset" type="reset" value="<?php echo $l_ldap_reset; ?>" name="reset">
363
  <input id="reset" type="reset" value="<?php echo $l_ldap_reset; ?>" name="reset">
364
</p>
364
</p>
365
 
365
 
366
</fieldset>
366
</fieldset>
367
</form>
367
</form>
368
<br>
368
<br>
369
</td></tr>
369
</td></tr>
370
</table>
370
</table>
371
</body>
371
</body>
372
</html>
372
</html>
373
 
373