Subversion Repositories ALCASAR

Rev

Rev 2453 | Rev 2460 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2453 Rev 2459
Line 1... Line 1...
1
<?php
1
<?php
2
# $Id: ldap.php 2453 2017-12-06 00:06:41Z tom.houdayer $
2
# $Id: ldap.php 2459 2017-12-10 22:17:52Z richard $
3
 
3
 
4
/* written by steweb57, Rexy & Tom HOUDAYER */
4
/* written by steweb57, Rexy & Tom HOUDAYER */
5
/****************************************************************
5
/****************************************************************
6
*			GLOBAL FILE PATHS			*
6
*			GLOBAL FILE PATHS			*
7
*****************************************************************/
7
*****************************************************************/
Line 43... Line 43...
43
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
43
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
44
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
44
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
45
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
45
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
46
}
46
}
47
if ($Language === 'fr') {		// French
47
if ($Language === 'fr') {		// French
48
	$l_ldap_update_sucess		= "Mise à jour des paramètres LDAP réalisée avec succès";
48
	$l_ldap_update			= "Mise à jour des paramètres LDAP effectuée";
49
	$l_ldap_title			= "Authentification externe : LDAP";
49
	$l_ldap_title			= "Authentification externe : LDAP";
50
	$l_ldap_legend			= "Authentification LDAP";
50
	$l_ldap_legend			= "Authentification LDAP";
51
	$l_ldap_auth_enable_label	= "Activer l'authentification LDAP:";
51
	$l_ldap_auth_enable_label	= "Éditer la configuration LDAP:";
52
	$l_ldap_YES			= "OUI";
52
	$l_ldap_YES			= "OUI";
53
	$l_ldap_NO			= "NON";
53
	$l_ldap_NO			= "NON";
54
	$l_ldap_server_label		= "Serveur LDAP:";
54
	$l_ldap_server_label		= "Serveur LDAP:";
55
	$l_ldap_server_text		= "Adresse IP du serveur LDAP";
55
	$l_ldap_server_text		= "Adresse IP du serveur";
56
	$l_ldap_base_dn_label		= "DN de la base LDAP:";
56
	$l_ldap_base_dn_label		= "DN de la base:";
57
	$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'";
57
	$l_ldap_base_dn_text		= "Le DN (Distinguished Name) définit où se situent les informations des utilisateurs dans l'annuaire.<br> - Exemple LDAP: 'o=mycompany, c=FR'.<br> - Exemple AD 'cn=Users,dc=server_name,dc=localdomain'";
58
	$l_ldap_filter_label		= "Identifiant LDAP:";
58
	$l_ldap_uid_label		= "Identifiant d'utilisateur (UID):";
59
	$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'.";
59
	$l_ldap_uid_text		= "Clé utilisée pour rechercher un identifiant de connexion.<br> - Exemple LDAP: 'uid', 'sn', etc.<br> - Pour A.D. mettre 'sAMAccountName'.";
60
	$l_ldap_base_filter_label	= "Filtre de recherche d'utilisateurs LDAP:";
60
	$l_ldap_base_filter_label	= "Filtre de recherche des utilisateurs (optionnel):";
61
	$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))'";
61
	$l_ldap_base_filter_text	= "Vous pouvez limiter les objets recherchés avec des filtres additionnels.<br> Exemple 'objectClass=posixGroup' ajouterait le filtre '(&amp;(uid=username)(objectClass=posixGroup))'";
62
	$l_ldap_user_label		= "Utilisateur LDAP:";
62
	$l_ldap_user_label		= "CN de l'utilisateur exploité par ALCASAR:";
63
	$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'";
63
	$l_ldap_user_text		= "CN=Common Name. Laissez vide pour utiliser un accès invité (ou anonyme). Obligatoire sur un AD.<br> - Exemple LDAP : 'uid=username,ou=my_lan,o=mycompany,c=FR'.<br> - Exemple AD : 'username' ou 'cn=username,cn=Users,dc=server_name,dc=localdomain'";
64
	$l_ldap_password_label		= "Mot de passe LDAP:";
64
	$l_ldap_password_label		= "Mot de passe:";
65
	$l_ldap_password_text		= "Laissez vide pour un accès invité (ou anonyme). Obligatoire sur un AD.";
65
	$l_ldap_password_text		= "Laissez vide pour un accès invité (ou anonyme). Obligatoire sur un AD.";
66
	$l_ldap_submit			= "Enregistrer";
66
	$l_ldap_submit			= "Enregistrer et vérifier";
67
	$l_ldap_reset			= "Annuler";
67
	$l_ldap_test_service_failed	= "Service LDAP injoignable sur ce serveur (vérifiez l'@IP).";
68
	$l_ldap_test_network_failed	= "Pas de connectivité réseau avec le serveur LDAP.";
68
	$l_ldap_test_service_ok		= "Un port 389 est actif sur ce serveur";
69
	$l_ldap_test_connection_failed	= "Impossible de se connecter au serveur LDAP.";
69
	$l_ldap_test_connection_failed	= "Connexion LDAP impossible (vérifiez le service LDAP sur ce serveur)";
70
	$l_ldap_test_bind_ok		= "Connexion LDAP réussie...";
70
	$l_ldap_test_connection_ok	= "Une connexion LDAP a été établie";
71
	$l_ldap_test_bind_failed	= "Echec d'authentification sur le serveur LDAP... Vérifiez votre configuration";
71
	$l_ldap_test_bind_failed	= "Echec d'authentification (vérifiez l'utilisateur et le mot de passe)";
72
	$l_ldap_test_dn_ok		= "DN semble bon";
72
	$l_ldap_test_bind_ok		= "L'authentification a réussie";
-
 
73
	$l_ldap_test_dn_failed		= "Le DN de la base semble incorrect (vérifiez le)";
73
	$l_ldap_test_dn_failed		= "DN semble mauvais";
74
	$l_ldap_test_dn_ok		= "Le DN de la base semble correct";
74
	$l_ldap_error			= "erreur LDAP";
75
	$l_ldap_error			= "erreur LDAP";
-
 
76
	$l_ldap_entries			= "entrées dans la base";
-
 
77
	$l_ldap_push_config		= "Activer cette configuration";
75
} else {				// English
78
} else {				// English
76
	$l_ldap_update_sucess		= "Successfull LDAP settings update";
79
	$l_ldap_update			= "LDAP settings updated";
77
	$l_ldap_title			= "External authentication : LDAP";
80
	$l_ldap_title			= "External authentication : LDAP";
78
	$l_ldap_legend			= "LDAP authentication";
81
	$l_ldap_legend			= "LDAP authentication";
79
	$l_ldap_auth_enable_label	= "Use LDAP authentication :";
82
	$l_ldap_auth_enable_label	= "Edit the LDAP configuration :";
80
	$l_ldap_YES			= "YES";
83
	$l_ldap_YES			= "YES";
81
	$l_ldap_NO			= "NO";
84
	$l_ldap_NO			= "NO";
82
	$l_ldap_server_label		= "LDAP server :";
85
	$l_ldap_server_label		= "LDAP server :";
83
	$l_ldap_server_text		= "This is the IP address of the LDAP server.";
86
	$l_ldap_server_text		= "IP address of the LDAP server.";
84
	$l_ldap_base_dn_label		= "LDAP base dn:";
87
	$l_ldap_base_dn_label		= "DN of the base:";
85
	$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'";
88
	$l_ldap_base_dn_text		= "The DN (Distinguished Name) is used to locate the users information in the directory.<br> e.g. LDAP : 'o=MyCompany,c=US'.<br> e.g. AD : 'cn=Users,dc=server_name,dc=localdomain'";
86
	$l_ldap_filter_label		= "LDAP uid:";
89
	$l_ldap_uid_label		= "User IDentifier (UID):";
87
	$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'.";
90
	$l_ldap_uid_text		= "Key used to search for a given login identity.<br>e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
88
	$l_ldap_base_filter_label	= "LDAP user filter:";
91
	$l_ldap_base_filter_label	= "User search filter (optional):";
89
	$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))'";
92
	$l_ldap_base_filter_text	= "You can further limit the searched objects with additional filters.<br> For example 'objectClass=posixGroup' would result in the use of '(&amp;(uid=username)(objectClass=posixGroup))'";
90
	$l_ldap_user_label		= "LDAP user dn:";
93
	$l_ldap_user_label		= "CN of the user operated by ALCASAR:";
91
	$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'";
94
	$l_ldap_user_text		= "CN=Common Name. Leave blank to use anonymous binding. Mandatory for AD.<br> e.g. LDAP :'uid=Username,ou=my_lan,o=mycompany,c=US'.<br> e.g. AD : 'username' or 'cn=username,cn=Users,dc=server_name,dc=localdomain'";
92
	$l_ldap_password_label		= "LDAP password:";
95
	$l_ldap_password_label		= "Password:";
93
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Required for AD.";
96
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Mandatory for AD.";
94
	$l_ldap_submit			= "Save";
97
	$l_ldap_submit			= "Save & Check";
95
	$l_ldap_reset			= "Reset";
98
	$l_ldap_test_service_failed	= "LDAP service is not reachable on that server (check IP)";
96
	$l_ldap_test_network_failed	= "LDAP server is not reachable.";
99
	$l_ldap_test_service_ok		= "A port 389 is open on this server";
97
	$l_ldap_test_connection_failed	= "LDAP connexion failed...";
100
	$l_ldap_test_connection_failed	= "LDAP connexion failed (check the LDAP service on this server)";
98
	$l_ldap_test_bind_ok		= "LDAP connexion success...";
101
	$l_ldap_test_connection_ok	= "A LDAP connexion is established";
99
	$l_ldap_test_bind_failed	= "LDAP authentication failed...Check your ldap setup...";
102
	$l_ldap_test_bind_failed	= "LDAP authentication failed (check the LDAP user and password)";
-
 
103
	$l_ldap_test_bind_ok		= "Successful authentication";
100
	$l_ldap_test_dn_ok              = "DN seems to be right";
104
	$l_ldap_test_dn_failed          = "DN of the base seems to be wrong (check it)";
101
	$l_ldap_test_dn_failed          = "DN seems to be wrong";
105
	$l_ldap_test_dn_ok              = "DN of the base seems to be ok";
102
	$l_ldap_error			= "LDAP error";
106
	$l_ldap_error			= "LDAP error";
-
 
107
	$l_ldap_entries			= "entries in the base";
-
 
108
	$l_ldap_push_config		= "Activate this configuration";
103
}
109
}
104
 
110
 
105
 
111
 
106
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_filter, $f_ldap_port = 389) {
112
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_uid, $f_ldap_port = 389) {
107
	// Test connect to the LDAP server
113
	// Socket to the LDAP port of the server
108
	if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
114
	if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
109
		// no network connection
115
		// no network connection
110
		return -1;
116
		return -2;
111
	}
117
	}
112
	fclose($sock);
118
	fclose($sock);
113
 
119
 
114
	// Test connect to the LDAP server
120
	// if ok, Test LDAP connection
115
	$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
121
	$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
116
	ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
122
	ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
117
	if (!$ldapconn) {
123
	if (!$ldapconn) {
118
		// LDAP connection failed
124
		// LDAP connection failed
119
		return -2;
125
		return -1;
120
	}
126
	}
121
 
127
 
-
 
128
	// if ok, test a ldap-bind with the user used by ALCASAR
122
	$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
129
	$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
123
	if (!$ldapbind) {
130
	if (!$ldapbind) {
124
		// Test LDAP Version 3
131
		// Test LDAP Version 3
125
		ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
132
		ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
126
		$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
133
		$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
127
 
-
 
128
		if (!$ldapbind) {
134
		if (!$ldapbind) {
129
			// LDAP Bind failed
135
			// LDAP Bind failed
130
			return 0;
136
			return 0;
131
		}
137
		}
132
	}
138
	}
133
	ldap_unbind($ldapconn);
-
 
134
 
139
 
135
	// try search
140
	// if ok, try to query the directory of users
136
	$query = $f_ldap_filter.'=*';
141
	$query = $f_ldap_uid."=*";
-
 
142
	$ldap_result = ldap_search($ldapconn, $f_ldap_basedn, $query);
137
	if (ldap_search($ldapconn, $f_ldap_basedn, $query)) {
143
	if (ldap_search($ldapconn, $f_ldap_basedn, $query)) {
-
 
144
		$ldap_users_number = ldap_count_entries($ldapconn, $ldap_result);
138
		return 2;
145
		return $ldap_users_number;
139
	} else {
146
	} else {
140
		return 1;
147
		return 1;
141
	}
148
	}
-
 
149
	ldap_unbind($ldapconn);
142
}
150
}
143
 
151
 
144
$messages = '';
152
$messages = '';
-
 
153
$ldap_can_be_enabled = False;
145
 
154
 
146
if (isset($_POST['auth_enable'])) {
155
if (isset($_POST['auth_enable'])) {
147
	if ($_POST['auth_enable'] === '1') {
156
	if ($_POST['auth_enable'] === '1') {
148
		$varErrors = [];
157
		$varErrors = [];
149
		if (isset($_POST['ldap_server']))      $ldap_server      = $_POST['ldap_server'];      else array_push($varErrors, 'Variable error "ldap_server"');
158
		if (isset($_POST['ldap_server']))      $ldap_server      = $_POST['ldap_server'];      else array_push($varErrors, 'Variable error "ldap_server"');
150
		if (isset($_POST['ldap_base_dn']))     $ldap_base_dn     = $_POST['ldap_base_dn'];     else array_push($varErrors, 'Variable error "ldap_base_dn"');
159
		if (isset($_POST['ldap_base_dn']))     $ldap_base_dn     = $_POST['ldap_base_dn'];     else array_push($varErrors, 'Variable error "ldap_base_dn"');
151
		if (isset($_POST['ldap_filter']))      $ldap_filter      = $_POST['ldap_filter'];      else array_push($varErrors, 'Variable error "ldap_filter"');
160
		if (isset($_POST['ldap_uid']))      $ldap_uid      = $_POST['ldap_uid'];      else array_push($varErrors, 'Variable error "ldap_uid"');
152
		if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
161
		if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
153
		if (isset($_POST['ldap_user']))        $ldap_user        = $_POST['ldap_user'];        else array_push($varErrors, 'Variable error "ldap_user"');
162
		if (isset($_POST['ldap_user']))        $ldap_user        = $_POST['ldap_user'];        else array_push($varErrors, 'Variable error "ldap_user"');
154
		if (isset($_POST['ldap_password']))    $ldap_password    = $_POST['ldap_password'];    else array_push($varErrors, 'Variable error "ldap_password"');
163
		if (isset($_POST['ldap_password']))    $ldap_password    = $_POST['ldap_password'];    else array_push($varErrors, 'Variable error "ldap_password"');
155
 
164
 
156
		// Validation
165
		// Validation
Line 171... Line 180...
171
			$messages .= '<br></div>';
180
			$messages .= '<br></div>';
172
		} else {
181
		} else {
173
			exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE);
182
			exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE);
174
			exec('sed -i '.escapeshellarg("s/^LDAP_SERVER=.*/LDAP_SERVER=$ldap_server/g").' '.CONF_FILE);
183
			exec('sed -i '.escapeshellarg("s/^LDAP_SERVER=.*/LDAP_SERVER=$ldap_server/g").' '.CONF_FILE);
175
			exec('sed -i '.escapeshellarg("s/^LDAP_BASE=.*/LDAP_BASE=$ldap_base_dn/g").' '.CONF_FILE);
184
			exec('sed -i '.escapeshellarg("s/^LDAP_BASE=.*/LDAP_BASE=$ldap_base_dn/g").' '.CONF_FILE);
176
			exec('sed -i '.escapeshellarg("s/^LDAP_UID=.*/LDAP_UID=$ldap_filter/g").' '.CONF_FILE);
185
			exec('sed -i '.escapeshellarg("s/^LDAP_UID=.*/LDAP_UID=$ldap_uid/g").' '.CONF_FILE);
177
			exec('sed -i '.escapeshellarg("s/^LDAP_FILTER=.*/LDAP_FILTER=$ldap_base_filter/g").' '.CONF_FILE);
186
			exec('sed -i '.escapeshellarg("s/^LDAP_FILTER=.*/LDAP_FILTER=$ldap_base_filter/g").' '.CONF_FILE);
178
			exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE);
187
			exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE);
179
			exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE);
188
			exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE);
180
			exec('sudo /usr/local/bin/alcasar-ldap.sh --on');
189
			exec('sudo /usr/local/bin/alcasar-ldap.sh --on');
181
 
190
 
182
			$messages .= '<div style="text-align: center"><br>';
191
			$messages .= '<div style="text-align: center"><br>';
183
			$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update_sucess.'</span><br>';
192
			$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
184
			$messages .= '<br></div>';
193
			$messages .= '<br></div>';
185
		}
194
		}
186
	} else {
195
	} else {
187
		exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE);
196
		exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE);
188
		exec('sudo /usr/local/bin/alcasar-ldap.sh --off');
197
		exec('sudo /usr/local/bin/alcasar-ldap.sh --off');
189
 
198
 
190
		$messages .= '<div style="text-align: center"><br>';
199
		$messages .= '<div style="text-align: center"><br>';
191
		$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update_sucess.'</span><br>';
200
		$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
192
		$messages .= '<br></div>';
201
		$messages .= '<br></div>';
193
	}
202
	}
194
 
203
 
195
	// Reload configuration
204
	// Reload configuration
196
	$file_conf = fopen(CONF_FILE, 'r');
205
	$file_conf = fopen(CONF_FILE, 'r');
Line 211... Line 220...
211
$ldap_status      = ($conf['LDAP'] === 'on');
220
$ldap_status      = ($conf['LDAP'] === 'on');
212
$ldap_server      = $conf['LDAP_SERVER'];
221
$ldap_server      = $conf['LDAP_SERVER'];
213
$ldap_user        = $conf['LDAP_USER'];
222
$ldap_user        = $conf['LDAP_USER'];
214
$ldap_password    = $conf['LDAP_PASSWORD'];
223
$ldap_password    = $conf['LDAP_PASSWORD'];
215
$ldap_base_dn     = $conf['LDAP_BASE'];
224
$ldap_base_dn     = $conf['LDAP_BASE'];
216
$ldap_filter      = $conf['LDAP_UID'];
225
$ldap_uid	  = $conf['LDAP_UID'];
217
$ldap_base_filter = $conf['LDAP_FILTER'];
226
$ldap_base_filter = $conf['LDAP_FILTER'];
218
 
227
 
219
// TODO : check LDAP PHP extension loaded?
228
// TODO : check LDAP PHP extension loaded?
220
// if (!extension_loaded('ldap')) {
229
// if (!extension_loaded('ldap')) {
221
// 	exit();
230
// 	exit();
Line 227... Line 236...
227
	$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"
236
	$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"
228
} else {
237
} else {
229
	$new_ldap_server = $ldap_server;
238
	$new_ldap_server = $ldap_server;
230
}
239
}
231
if ($ldap_status) {
240
if ($ldap_status) {
232
	$serverCheckResult = ldap_checkServerConfig($new_ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_filter);
241
	$serverCheckResult = ldap_checkServerConfig($new_ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_uid);
233
}
242
}
234
 
243
 
235
// AJAX LDAP configuration checker
244
// AJAX LDAP configuration checker
236
if (isset($_GET['conf_check'])) {
245
if (isset($_GET['conf_check'])) {
237
	$response = [
246
	$response = [
Line 240... Line 249...
240
	if ($ldap_status || ($_SERVER['REQUEST_METHOD'] === 'POST')) {
249
	if ($ldap_status || ($_SERVER['REQUEST_METHOD'] === 'POST')) {
241
		$varErrors = [];
250
		$varErrors = [];
242
		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
251
		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
243
			if (isset($_POST['ldap_server']))      $ldap_server      = $_POST['ldap_server'];      else array_push($varErrors, 'Variable error "ldap_server"');
252
			if (isset($_POST['ldap_server']))      $ldap_server      = $_POST['ldap_server'];      else array_push($varErrors, 'Variable error "ldap_server"');
244
			if (isset($_POST['ldap_base_dn']))     $ldap_base_dn     = $_POST['ldap_base_dn'];     else array_push($varErrors, 'Variable error "ldap_base_dn"');
253
			if (isset($_POST['ldap_base_dn']))     $ldap_base_dn     = $_POST['ldap_base_dn'];     else array_push($varErrors, 'Variable error "ldap_base_dn"');
245
			if (isset($_POST['ldap_filter']))      $ldap_filter      = $_POST['ldap_filter'];      else array_push($varErrors, 'Variable error "ldap_filter"');
254
			if (isset($_POST['ldap_uid']))      $ldap_uid      = $_POST['ldap_uid'];      else array_push($varErrors, 'Variable error "ldap_uid"');
246
			if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
255
			if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
247
			if (isset($_POST['ldap_user']))        $ldap_user        = $_POST['ldap_user'];        else array_push($varErrors, 'Variable error "ldap_user"');
256
			if (isset($_POST['ldap_user']))        $ldap_user        = $_POST['ldap_user'];        else array_push($varErrors, 'Variable error "ldap_user"');
248
			if (isset($_POST['ldap_password']))    $ldap_password    = $_POST['ldap_password'];    else array_push($varErrors, 'Variable error "ldap_password"');
257
			if (isset($_POST['ldap_password']))    $ldap_password    = $_POST['ldap_password'];    else array_push($varErrors, 'Variable error "ldap_password"');
249
		}
258
		}
250
 
259
 
Line 256... Line 265...
256
			if (!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) {
265
			if (!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) {
257
				array_push($varErrors, 'Invalid LDAP server IP');
266
				array_push($varErrors, 'Invalid LDAP server IP');
258
			}
267
			}
259
		}
268
		}
260
 
269
 
261
		$response['result'] = (ldap_checkServerConfig($ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_filter) > 0);
270
		$response['result'] = (ldap_checkServerConfig($ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_uid) > 0);
262
 
271
 
263
		if (!empty($varErrors)) {
272
		if (!empty($varErrors)) {
264
			$response['errors'] = $varErrors;
273
			$response['errors'] = $varErrors;
265
		}
274
		}
266
	}
275
	}
Line 279... Line 288...
279
	<link type="text/css" href="/css/style.css" rel="stylesheet">
288
	<link type="text/css" href="/css/style.css" rel="stylesheet">
280
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
289
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
281
	<link type="text/css" href="/css/ldap.css" rel="stylesheet">
290
	<link type="text/css" href="/css/ldap.css" rel="stylesheet">
282
	<script>
291
	<script>
283
	function onLdapStatusChange() {
292
	function onLdapStatusChange() {
284
		var listToDisables = ['ldap_server', 'ldap_dn', 'ldap_filter', 'ldap_base_filter', 'ldap_user', 'ldap_password'];
293
		var listToDisables = ['ldap_server', 'ldap_dn', 'ldap_uid', 'ldap_base_filter', 'ldap_user', 'ldap_password'];
285
 
294
 
286
		if (document.getElementById('auth_enable').value === '1') {
295
		if (document.getElementById('auth_enable').value === '1') {
287
			for (var i=0; i<listToDisables.length; i++) {
296
			for (var i=0; i<listToDisables.length; i++) {
288
				document.getElementById(listToDisables[i]).style.backgroundColor = '#ffffff';
297
				document.getElementById(listToDisables[i]).style.backgroundColor = '#ffffff';
289
				document.getElementById(listToDisables[i]).disabled = false;
298
				document.getElementById(listToDisables[i]).disabled = false;
Line 301... Line 310...
301
			ldap_status:     (document.getElementById('auth_enable').value === '1'),
310
			ldap_status:     (document.getElementById('auth_enable').value === '1'),
302
			ldap_server:      document.getElementById('ldap_server').value,
311
			ldap_server:      document.getElementById('ldap_server').value,
303
			ldap_user:        document.getElementById('ldap_user').value,
312
			ldap_user:        document.getElementById('ldap_user').value,
304
			ldap_password:    document.getElementById('ldap_password').value,
313
			ldap_password:    document.getElementById('ldap_password').value,
305
			ldap_base_dn:     document.getElementById('ldap_dn').value,
314
			ldap_base_dn:     document.getElementById('ldap_dn').value,
306
			ldap_filter:      document.getElementById('ldap_filter').value,
315
			ldap_uid:      document.getElementById('ldap_uid').value,
307
			ldap_base_filter: document.getElementById('ldap_base_filter').value
316
			ldap_base_filter: document.getElementById('ldap_base_filter').value
308
		};
317
		};
309
 
318
 
310
		console.log(ldap_config);
319
		console.log(ldap_config);
311
 
320
 
Line 348... Line 357...
348
					<legend>
357
					<legend>
349
						<?= $messages ?>
358
						<?= $messages ?>
350
						<?php if ($ldap_status): ?>
359
						<?php if ($ldap_status): ?>
351
							<div style="text-align: center"><br>
360
							<div style="text-align: center"><br>
352
								<?php if ($serverCheckResult === -2): ?>
361
								<?php if ($serverCheckResult === -2): ?>
353
									<span style="color: red"><?= $l_ldap_test_connection_failed ?></span>
362
									<span style="color: red"><?= $l_ldap_test_service_failed ?></span>
354
								<?php elseif ($serverCheckResult === -1): ?>
363
								<?php elseif ($serverCheckResult === -1): ?>
-
 
364
									<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
355
									<span style="color: red"><?= $l_ldap_test_network_failed ?></span>
365
									<span style="color: red"><?= $l_ldap_test_connection_failed ?></span>
356
								<?php elseif ($serverCheckResult === 0): ?>
366
								<?php elseif ($serverCheckResult === 0): ?>
-
 
367
									<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
-
 
368
									<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
357
									<span style="color: red"><?= $l_ldap_test_bind_failed ?></span>
369
									<span style="color: red"><?= $l_ldap_test_bind_failed ?></span>
358
								<?php elseif ($serverCheckResult === 1): ?>
370
								<?php elseif ($serverCheckResult === 1): ?>
359
										<span style="color: green"><?= $l_ldap_test_bind_ok ?></span>
371
									<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
-
 
372
									<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
360
										<br>";
373
									<span style="color: green"><?= $l_ldap_test_bind_ok ?></span><br>
361
										<span style="color: red"><?= $l_ldap_test_dn_failed ?></span>
374
									<span style="color: red"><?= $l_ldap_test_dn_failed ?></span>
362
								<?php elseif ($serverCheckResult === 2): ?>
375
								<?php elseif ($serverCheckResult > 1): ?>
363
										<span style="color: green"><?= $l_ldap_test_bind_ok ?></span>
376
									<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
364
										<br>";
377
									<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
365
										<span style="color: green"><?= $l_ldap_test_dn_ok ?></span>
378
									<span style="color: green"><?= $l_ldap_test_bind_ok ?></span><br>
-
 
379
									<span style="color: green"><?= $l_ldap_test_dn_ok." ($serverCheckResult $l_ldap_entries)"; $ldap_can_be_enabled = True;?></span>
366
								<?php else: ?>
380
								<?php else: ?>
367
									<span><?= $l_ldap_error ?></span>
381
									<span><?= $l_ldap_error ?></span>
368
								<?php endif ?>
382
								<?php endif ?>
369
								<br><br>
383
								<br><br>
370
							</div>
384
							</div>
Line 399... Line 413...
399
							<input id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>">
413
							<input id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>">
400
						</dd>
414
						</dd>
401
					</dl>
415
					</dl>
402
					<dl>
416
					<dl>
403
						<dt>
417
						<dt>
404
							<label for="ldap_filter"><?= $l_ldap_filter_label ?></label><br>
418
							<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br>
405
							<?= $l_ldap_filter_text ?>
419
							<?= $l_ldap_uid_text ?>
406
						</dt>
420
						</dt>
407
						<dd>
421
						<dd>
408
							<input id="ldap_filter" size="40" name="ldap_filter" value="<?= htmlspecialchars($ldap_filter) ?>">
422
							<input id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>">
409
						</dd>
423
						</dd>
410
					</dl>
424
					</dl>
411
					<dl>
425
					<dl>
412
						<dt>
426
						<dt>
413
							<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br>
427
							<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br>
Line 435... Line 449...
435
							<input id="ldap_password" type="password" size="40" name="ldap_password" value="<?= htmlspecialchars($ldap_password) ?>">
449
							<input id="ldap_password" type="password" size="40" name="ldap_password" value="<?= htmlspecialchars($ldap_password) ?>">
436
						</dd>
450
						</dd>
437
					</dl>
451
					</dl>
438
					<p>
452
					<p>
439
						<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit">
453
						<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit">
440
						<input id="reset" type="reset" value="<?= $l_ldap_reset ?>" name="reset">
454
						<? if ($ldap_can_be_enabled === True) {echo "<input id=\"push_config\" value=\"$l_ldap_push_config\" name=\"push_config_button\">";}?>
441
						<button onclick="checkConfig(); return false;">Check [BETA]</button>
-
 
442
					</p>
455
					</p>
443
				</fieldset>
456
				</fieldset>
444
			</form>
457
			</form>
445
		</div>
458
		</div>
446
	</div>
459
	</div>