Subversion Repositories ALCASAR

Rev

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

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