Subversion Repositories ALCASAR

Rev

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

Rev 2714 Rev 2718
1
<?php
1
<?php
2
# $Id: ldap.php 2714 2019-03-10 23:43:22Z tom.houdayer $
2
# $Id: ldap.php 2718 2019-03-11 21:25:44Z tom.houdayer $
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
*****************************************************************/
8
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
8
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
9
 
9
 
10
/****************************************************************
10
/****************************************************************
11
*			FILE reading test			*
11
*			FILE reading test			*
12
*****************************************************************/
12
*****************************************************************/
13
$conf_files = array(CONF_FILE);
13
$conf_files = array(CONF_FILE);
14
foreach ($conf_files as $file) {
14
foreach ($conf_files as $file) {
15
	if (!file_exists($file)) {
15
	if (!file_exists($file)) {
16
		exit("Fichier $file non présent");
16
		exit("Fichier $file non présent");
17
	}
17
	}
18
	if (!is_readable($file)) {
18
	if (!is_readable($file)) {
19
		exit("Vous n'avez pas les droits de lecture sur le fichier $file");
19
		exit("Vous n'avez pas les droits de lecture sur le fichier $file");
20
	}
20
	}
21
}
21
}
22
 
22
 
23
/****************************************************************
23
/****************************************************************
24
*			Read CONF_FILE				*
24
*			Read CONF_FILE				*
25
*****************************************************************/
25
*****************************************************************/
26
$file_conf = fopen(CONF_FILE, 'r');
26
$file_conf = fopen(CONF_FILE, 'r');
27
if (!$file_conf) {
27
if (!$file_conf) {
28
	exit('Error opening the file '.CONF_FILE);
28
	exit('Error opening the file '.CONF_FILE);
29
}
29
}
30
while (!feof($file_conf)) {
30
while (!feof($file_conf)) {
31
	$buffer = fgets($file_conf, 4096);
31
	$buffer = fgets($file_conf, 4096);
32
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
32
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
33
		$tmp = explode('=', $buffer, 2);
33
		$tmp = explode('=', $buffer, 2);
34
		$conf[trim($tmp[0])] = trim($tmp[1]);
34
		$conf[trim($tmp[0])] = trim($tmp[1]);
35
	}
35
	}
36
}
36
}
37
fclose($file_conf);
37
fclose($file_conf);
38
 
38
 
39
/****************************************************************
39
/****************************************************************
40
*			Choice of language			*
40
*			Choice of language			*
41
*****************************************************************/
41
*****************************************************************/
42
$Language = 'en';
42
$Language = 'en';
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			= "Mise à jour des paramètres LDAP effectuée";
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	= "Éditer la configuration 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";
55
	$l_ldap_server_text		= "Adresse IP du serveur";
56
	$l_ldap_base_dn_label		= "DN de la base:";
56
	$l_ldap_base_dn_label		= "DN de la base:";
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'";
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_uid_label		= "Identifiant d'utilisateur (UID):";
58
	$l_ldap_uid_label		= "Identifiant d'utilisateur (UID):";
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'.";
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 des utilisateurs (optionnel):";
60
	$l_ldap_base_filter_label	= "Filtre de recherche des utilisateurs (optionnel):";
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))'";
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		= "CN de l'utilisateur exploité par ALCASAR:";
62
	$l_ldap_user_label		= "CN de l'utilisateur exploité par ALCASAR:";
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'";
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:";
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_ssl_label		= "Connexion chiffré";
66
	$l_ldap_ssl_label		= "Connexion chiffré";
67
	$l_ldap_ssl_text		= "Utiliser une connexion chiffré avec SSL (LDAPS)";
67
	$l_ldap_ssl_text		= "Utiliser une connexion chiffré avec SSL (LDAPS)";
68
	$l_ldap_cert_required_label	= "Vérifier le certificat SSL";
68
	$l_ldap_cert_required_label	= "Vérifier le certificat SSL";
69
	$l_ldap_cert_required_text	= "Vérifier que le serveur LDAP utilise un certificat connu";
69
	$l_ldap_cert_required_text	= "Vérifier que le serveur LDAP utilise un certificat connu";
70
	$l_ldap_cert_label		= "Certificat SSL (CA)";
70
	$l_ldap_cert_label		= "Certificat SSL (CA)";
71
	$l_ldap_cert_text		= "Certificat de l'authorité de certification signant celui du serveur LDAP";
71
	$l_ldap_cert_text		= "Certificat de l'authorité de certification signant celui du serveur LDAP";
-
 
72
	$l_ad_dns_domain_label		= "Nom de domaine interne";
-
 
73
	$l_ad_dns_domain_text		= "Nom de domaine qui sera redirigé vers le serveur DNS de l'annuaire LDAP (vide pour désactivé)";
72
	$l_ldap_cert_status_cur		= "Certificat actuel : ";
74
	$l_ldap_cert_status_cur		= "Certificat actuel : ";
73
	$l_ldap_cert_status_no		= "Aucun certificat installé";
75
	$l_ldap_cert_status_no		= "Aucun certificat installé";
74
	$l_ldap_submit			= "Enregistrer";
76
	$l_ldap_submit			= "Enregistrer";
75
	$l_ldap_test_service_failed	= "Service LDAP injoignable sur ce serveur (vérifiez l'@IP).";
77
	$l_ldap_test_service_failed	= "Service LDAP injoignable sur ce serveur (vérifiez l'@IP).";
76
	$l_ldap_test_service_ok		= "Un port 389 (636 avec SSL) est actif sur ce serveur";
78
	$l_ldap_test_service_ok		= "Un port 389 (636 avec SSL) est actif sur ce serveur";
77
	$l_ldap_test_connection_failed	= "Connexion LDAP impossible (vérifiez le service LDAP sur ce serveur)";
79
	$l_ldap_test_connection_failed	= "Connexion LDAP impossible (vérifiez le service LDAP sur ce serveur)";
78
	$l_ldap_test_connection_ok	= "Une connexion LDAP a été établie";
80
	$l_ldap_test_connection_ok	= "Une connexion LDAP a été établie";
79
	$l_ldap_test_bind_failed	= "Echec d'authentification (vérifiez l'utilisateur et le mot de passe)";
81
	$l_ldap_test_bind_failed	= "Echec d'authentification (vérifiez l'utilisateur et le mot de passe)";
80
	$l_ldap_test_bind_ok		= "L'authentification a réussie";
82
	$l_ldap_test_bind_ok		= "L'authentification a réussie";
81
	$l_ldap_test_dn_failed		= "Le DN de la base semble incorrect (vérifiez le)";
83
	$l_ldap_test_dn_failed		= "Le DN de la base semble incorrect (vérifiez le)";
82
	$l_ldap_test_dn_ok		= "Le DN de la base semble correct";
84
	$l_ldap_test_dn_ok		= "Le DN de la base semble correct";
83
	$l_ldap_error			= "erreur LDAP";
85
	$l_ldap_error			= "erreur LDAP";
84
	$l_ldap_entries			= "entrées dans la base";
86
	$l_ldap_entries			= "entrées dans la base";
85
	$l_ldap_cert_cn_diff_dn		= "Le CommonName du certificat (§cert_domainName§) est différent du nom de domaine du serveur";
87
	$l_ldap_cert_cn_diff_dn		= "Le CommonName du certificat (§cert_domainName§) est différent du nom de domaine du serveur";
86
	$l_check			= "Vérifier cette configuration";
88
	$l_check			= "Vérifier cette configuration";
87
	$l_checkingConf			= "Vérification de cette configuration...";
89
	$l_checkingConf			= "Vérification de cette configuration...";
88
} else {				// English
90
} else {				// English
89
	$l_ldap_update			= "LDAP settings updated";
91
	$l_ldap_update			= "LDAP settings updated";
90
	$l_ldap_title			= "External authentication : LDAP";
92
	$l_ldap_title			= "External authentication : LDAP";
91
	$l_ldap_legend			= "LDAP authentication";
93
	$l_ldap_legend			= "LDAP authentication";
92
	$l_ldap_auth_enable_label	= "Edit the LDAP configuration :";
94
	$l_ldap_auth_enable_label	= "Edit the LDAP configuration :";
93
	$l_ldap_YES			= "YES";
95
	$l_ldap_YES			= "YES";
94
	$l_ldap_NO			= "NO";
96
	$l_ldap_NO			= "NO";
95
	$l_ldap_server_label		= "LDAP server :";
97
	$l_ldap_server_label		= "LDAP server :";
96
	$l_ldap_server_text		= "IP address of the LDAP server.";
98
	$l_ldap_server_text		= "IP address of the LDAP server.";
97
	$l_ldap_base_dn_label		= "DN of the base:";
99
	$l_ldap_base_dn_label		= "DN of the base:";
98
	$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'";
100
	$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'";
99
	$l_ldap_uid_label		= "User IDentifier (UID):";
101
	$l_ldap_uid_label		= "User IDentifier (UID):";
100
	$l_ldap_uid_text		= "Key used to search for a given login identity.<br>e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
102
	$l_ldap_uid_text		= "Key used to search for a given login identity.<br>e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
101
	$l_ldap_base_filter_label	= "User search filter (optional):";
103
	$l_ldap_base_filter_label	= "User search filter (optional):";
102
	$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))'";
104
	$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))'";
103
	$l_ldap_user_label		= "CN of the user operated by ALCASAR:";
105
	$l_ldap_user_label		= "CN of the user operated by ALCASAR:";
104
	$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'";
106
	$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'";
105
	$l_ldap_password_label		= "Password:";
107
	$l_ldap_password_label		= "Password:";
106
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Mandatory for AD.";
108
	$l_ldap_password_text		= "Leave blank to use anonymous binding. Mandatory for AD.";
107
	$l_ldap_ssl_label		= "Secure connection";
109
	$l_ldap_ssl_label		= "Secure connection";
108
	$l_ldap_ssl_text		= "Use an encrypted connection with SSL (LDAPS)";
110
	$l_ldap_ssl_text		= "Use an encrypted connection with SSL (LDAPS)";
109
	$l_ldap_cert_required_label	= "Check the SSL certificate";
111
	$l_ldap_cert_required_label	= "Check the SSL certificate";
110
	$l_ldap_cert_required_text	= "Verify that the LDAP server uses a trusted certificate";
112
	$l_ldap_cert_required_text	= "Verify that the LDAP server uses a trusted certificate";
111
	$l_ldap_cert_label		= "SSL certificate (CA)";
113
	$l_ldap_cert_label		= "SSL certificate (CA)";
112
	$l_ldap_cert_text		= "Certificate of the certification authority that signed the LDAP server certificate";
114
	$l_ldap_cert_text		= "Certificate of the certification authority that signed the LDAP server certificate";
-
 
115
	$l_ad_dns_domain_label		= "Internal domain name";
-
 
116
	$l_ad_dns_domain_text		= "Domain name that will be forwarded to the DNS server of the LDAP directory (empty for disabled)";
113
	$l_ldap_cert_status_cur		= "Current certificate:";
117
	$l_ldap_cert_status_cur		= "Current certificate:";
114
	$l_ldap_cert_status_no		= "No certificate imported";
118
	$l_ldap_cert_status_no		= "No certificate imported";
115
	$l_ldap_submit			= "Save";
119
	$l_ldap_submit			= "Save";
116
	$l_ldap_test_service_failed	= "LDAP service is not reachable on that server (check IP)";
120
	$l_ldap_test_service_failed	= "LDAP service is not reachable on that server (check IP)";
117
	$l_ldap_test_service_ok		= "A port 389 (636 with SSL) is open on this server";
121
	$l_ldap_test_service_ok		= "A port 389 (636 with SSL) is open on this server";
118
	$l_ldap_test_connection_failed	= "LDAP connexion failed (check the LDAP service on this server)";
122
	$l_ldap_test_connection_failed	= "LDAP connexion failed (check the LDAP service on this server)";
119
	$l_ldap_test_connection_ok	= "A LDAP connexion is established";
123
	$l_ldap_test_connection_ok	= "A LDAP connexion is established";
120
	$l_ldap_test_bind_failed	= "LDAP authentication failed (check the LDAP user and password)";
124
	$l_ldap_test_bind_failed	= "LDAP authentication failed (check the LDAP user and password)";
121
	$l_ldap_test_bind_ok		= "Successful authentication";
125
	$l_ldap_test_bind_ok		= "Successful authentication";
122
	$l_ldap_test_dn_failed		= "DN of the base seems to be wrong (check it)";
126
	$l_ldap_test_dn_failed		= "DN of the base seems to be wrong (check it)";
123
	$l_ldap_test_dn_ok		= "DN of the base seems to be ok";
127
	$l_ldap_test_dn_ok		= "DN of the base seems to be ok";
124
	$l_ldap_cert_cn_diff_dn		= "Certificate CommonName (§cert_domainName§) is different from the server domain name";
128
	$l_ldap_cert_cn_diff_dn		= "Certificate CommonName (§cert_domainName§) is different from the server domain name";
125
	$l_ldap_error			= "LDAP error";
129
	$l_ldap_error			= "LDAP error";
126
	$l_ldap_entries			= "entries in the base";
130
	$l_ldap_entries			= "entries in the base";
127
	$l_check			= "Check this config";
131
	$l_check			= "Check this config";
128
	$l_checkingConf			= "Checking this configuration...";
132
	$l_checkingConf			= "Checking this configuration...";
129
}
133
}
130
 
134
 
-
 
135
// AJAX LDAP assitant
-
 
136
if (isset($_GET['assistant'])) {
-
 
137
	$response = [
-
 
138
		'values' => []
-
 
139
	];
-
 
140
	if (!isset($_POST['ldap_server'])) exit();
-
 
141
	$ldap_server = $_POST['ldap_server'];
-
 
142
 
-
 
143
	// Check port 389 & 636
-
 
144
	if (!$sock = @fsockopen($ldap_server, 389, $num, $error, 2)) {
-
 
145
		$ldap_port_389 = false;
-
 
146
		$ldap_srv_389  = false;
-
 
147
	} else {
-
 
148
		$ldap_port_389 = true;
-
 
149
		fclose($sock);
-
 
150
	}
-
 
151
	if (!$sock = @fsockopen($ldap_server, 636, $num, $error, 2)) {
-
 
152
		$ldap_port_636 = false;
-
 
153
		$ldap_srv_636  = false;
-
 
154
		$ldap_ssl      = false;
-
 
155
	} else {
-
 
156
		$ldap_port_636 = true;
-
 
157
		$ldap_ssl      = true;
-
 
158
		fclose($sock);
-
 
159
	}
-
 
160
 
-
 
161
	if (!$ldap_port_389 && !$ldap_port_636) {
-
 
162
		$response['result'] = -2;
-
 
163
 
-
 
164
		header('Content-Type: application/json');
-
 
165
		echo json_encode($response);
-
 
166
		exit();
-
 
167
	}
-
 
168
 
-
 
169
	// Check LDAP service
-
 
170
	if ($ldap_port_636) {
-
 
171
if (PHP_VERSION_ID >= 70100):
-
 
172
		// Set LDAP SSL options
-
 
173
		ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
-
 
174
endif;
-
 
175
		$ldapconn = @ldap_connect('ldaps://'.$ldap_server);
-
 
176
		if (!$ldapconn) {
-
 
177
			$ldap_srv_636 = false;
-
 
178
		} else {
-
 
179
			ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
-
 
180
 
-
 
181
			// Bind anonymous
-
 
182
			$ldap_srv_636 = true;
-
 
183
			if (!@ldap_bind($ldapconn, '', '')) {
-
 
184
				ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
-
 
185
				if (!@ldap_bind($ldapconn, '', '')) {
-
 
186
					$ldap_srv_636 = false;
-
 
187
				}
-
 
188
			}
-
 
189
		}
-
 
190
 
-
 
191
		if ($ldap_srv_636) {
-
 
192
			$ldap_data    = @ldap_read($ldapconn, '', 'objectClass=*', ['dnsHostName','rootDomainNamingContext','supportedCapabilities']);
-
 
193
			$ldap_rootDSE = @ldap_get_entries($ldapconn, $ldap_data);
-
 
194
 
-
 
195
			try {
-
 
196
				$response['values']['isAD'] = in_array('1.2.840.113556.1.4.800', $ldap_rootDSE[0]['supportedcapabilities']);
-
 
197
			} catch (Exception $e) {
-
 
198
				$response['values']['isAD'] = false;
-
 
199
			}
-
 
200
 
-
 
201
			if ($response['values']['isAD']) {
-
 
202
				try {
-
 
203
					$response['values']['ldap_base_dn'] = $ldap_rootDSE[0]['rootdomainnamingcontext'][0];
-
 
204
 
-
 
205
					if ($response['values']['ldap_base_dn']) {
-
 
206
						$response['values']['int_dns_domain'] = str_replace('DC=', '', str_replace(',DC=', '.', $response['values']['ldap_base_dn']));
-
 
207
					}
-
 
208
 
-
 
209
					$response['values']['ldap_base_dn'] = 'CN=Users,'.$response['values']['ldap_base_dn'];
-
 
210
				} catch (Exception $e) { }
-
 
211
 
-
 
212
				try {
-
 
213
					$response['values']['ldap_server_domain'] = $ldap_rootDSE[0]['dnshostname'][0];
-
 
214
				} catch (Exception $e) { }
-
 
215
			}
-
 
216
		}
-
 
217
	}
-
 
218
	$response['values']['ldap_srv_636'] = $ldap_srv_636;
-
 
219
 
-
 
220
	if (!$ldap_srv_636) {
-
 
221
		$ldapconn = @ldap_connect('ldap://'.$ldap_server);
-
 
222
		if (!$ldapconn) {
-
 
223
			$ldap_srv_389 = false;
-
 
224
		} else {
-
 
225
			ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
-
 
226
 
-
 
227
			// Bind anonymous
-
 
228
			$ldap_srv_389 = true;
-
 
229
			if (!@ldap_bind($ldapconn, '', '')) {
-
 
230
				ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
-
 
231
				if (!@ldap_bind($ldapconn, '', '')) {
-
 
232
					$ldap_srv_389 = false;
-
 
233
				}
-
 
234
			}
-
 
235
		}
-
 
236
 
-
 
237
		if ($ldap_srv_389) {
-
 
238
			$ldap_data    = @ldap_read($ldapconn, '', 'objectClass=*', ['dnsHostName','rootDomainNamingContext','supportedCapabilities']);
-
 
239
			$ldap_rootDSE = @ldap_get_entries($ldapconn, $ldap_data);
-
 
240
 
-
 
241
			try {
-
 
242
				$response['values']['isAD'] = in_array('1.2.840.113556.1.4.800', $ldap_rootDSE[0]['supportedcapabilities']);
-
 
243
			} catch (Exception $e) {
-
 
244
				$response['values']['isAD'] = false;
-
 
245
			}
-
 
246
 
-
 
247
			if ($response['values']['isAD']) {
-
 
248
				try {
-
 
249
					$response['values']['ldap_base_dn'] = $ldap_rootDSE[0]['rootdomainnamingcontext'][0];
-
 
250
 
-
 
251
					if ($response['values']['ldap_base_dn']) {
-
 
252
						$response['values']['int_dns_domain'] = str_replace('DC=', '', str_replace(',DC=', '.', $response['values']['ldap_base_dn']));
-
 
253
					}
-
 
254
 
-
 
255
					$response['values']['ldap_base_dn'] = 'CN=Users,'.$response['values']['ldap_base_dn'];
-
 
256
				} catch (Exception $e) { }
-
 
257
 
-
 
258
				try {
-
 
259
					$response['values']['ldap_server_domain'] = $ldap_rootDSE[0]['dnshostname'][0];
-
 
260
				} catch (Exception $e) { }
-
 
261
			}
-
 
262
		}
-
 
263
		$response['values']['ldap_srv_389'] = $ldap_srv_389;
-
 
264
	}
-
 
265
 
-
 
266
	if (!$ldap_srv_636 && !$ldap_srv_389) {
-
 
267
		$response['result'] = -1;
-
 
268
 
-
 
269
		header('Content-Type: application/json');
-
 
270
		echo json_encode($response);
-
 
271
		exit();
-
 
272
	}
-
 
273
 
-
 
274
	$response['result'] = 0;
-
 
275
	header('Content-Type: application/json');
-
 
276
	echo json_encode($response);
-
 
277
	exit();
-
 
278
}
-
 
279
 
131
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_base_filter, $f_ldap_uid, $f_ldap_ssl, $f_ldap_cert, $f_ldap_cert_required) {
280
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_base_filter, $f_ldap_uid, $f_ldap_ssl, $f_ldap_cert, $f_ldap_cert_required) {
132
	// Socket to the LDAP port of the server
281
	// Socket to the LDAP port of the server
133
	if (!$sock = @fsockopen($f_ldap_server, (($f_ldap_ssl) ? 636 : 389), $num, $error, 2)) {
282
	if (!$sock = @fsockopen($f_ldap_server, (($f_ldap_ssl) ? 636 : 389), $num, $error, 2)) {
134
		// no network connection
283
		// no network connection
135
		return -2;
284
		return -2;
136
	}
285
	}
137
	fclose($sock);
286
	fclose($sock);
138
 
287
 
-
 
288
if (PHP_VERSION_ID >= 70100):
139
	// Set LDAP SSL options
289
	// Set LDAP SSL options
140
	if ($f_ldap_ssl) {
290
	if ($f_ldap_ssl) {
141
		if ($f_ldap_cert_required) {
291
		if ($f_ldap_cert_required) {
142
			if ($f_ldap_cert) {
292
			if ($f_ldap_cert) {
143
				ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, $f_ldap_cert);
293
				ldap_set_option(null, LDAP_OPT_X_TLS_CACERTFILE, $f_ldap_cert);
144
			}
294
			}
145
			ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
295
			ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
146
 
296
 
147
		} else {
297
		} else {
148
			ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
298
			ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
149
		}
299
		}
150
	}
300
	}
-
 
301
endif;
151
 
302
 
152
	// if ok, Test LDAP connection
303
	// if ok, Test LDAP connection
153
	$ldapconn = @ldap_connect((($f_ldap_ssl)?'ldaps':'ldap').'://'.$f_ldap_server);
304
	$ldapconn = @ldap_connect((($f_ldap_ssl)?'ldaps':'ldap').'://'.$f_ldap_server);
154
	if (!$ldapconn) {
305
	if (!$ldapconn) {
155
		// LDAP connection failed
306
		// LDAP connection failed
156
		return -1;
307
		return -1;
157
	}
308
	}
158
 
309
 
159
	ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
310
	ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
160
 
311
 
161
	// if ok, test a ldap-bind with the user used by ALCASAR
312
	// if ok, test a ldap-bind with the user used by ALCASAR
162
	$ldapbind = @ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
313
	$ldapbind = @ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
163
	if (!$ldapbind) {
314
	if (!$ldapbind) {
164
		// Test LDAP Version 3
315
		// Test LDAP Version 3
165
		ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
316
		ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
166
		$ldapbind = @ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
317
		$ldapbind = @ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
167
		if (!$ldapbind) {
318
		if (!$ldapbind) {
168
			// LDAP Bind failed
319
			// LDAP Bind failed
169
			return 0;
320
			return 0;
170
		}
321
		}
171
	}
322
	}
172
 
323
 
173
	// if ok, try to query the directory of users
324
	// if ok, try to query the directory of users
174
	$filter = ((!empty($f_ldap_base_filter)) ? $f_ldap_base_filter : '&');
325
	$filter = ((!empty($f_ldap_base_filter)) ? $f_ldap_base_filter : '&');
175
	$query = "(&($f_ldap_uid=*)($filter))";
326
	$query = "(&($f_ldap_uid=*)($filter))";
176
	$ldap_result = @ldap_search($ldapconn, $f_ldap_basedn, $query);
327
	$ldap_result = @ldap_search($ldapconn, $f_ldap_basedn, $query);
177
	if ($ldap_result) {
328
	if ($ldap_result) {
178
		$ldap_users_count = ldap_count_entries($ldapconn, $ldap_result);
329
		$ldap_users_count = ldap_count_entries($ldapconn, $ldap_result);
179
		return ($ldap_users_count + 2);
330
		return ($ldap_users_count + 2);
180
	} else {
331
	} else {
181
		return 1;
332
		return 1;
182
	}
333
	}
183
	ldap_unbind($ldapconn);
334
	ldap_unbind($ldapconn);
184
}
335
}
185
 
336
 
186
$messages = '';
337
$messages = '';
187
$LDAPS_CERT_LOC = '/etc/raddb/certs/alcasar-ldaps.crt';
338
$LDAPS_CERT_LOC = '/etc/raddb/certs/alcasar-ldaps.crt';
188
 
339
 
189
if (isset($_POST['auth_enable'])) {
340
if (isset($_POST['auth_enable'])) {
190
	if ($_POST['auth_enable'] === '1') {
341
	if ($_POST['auth_enable'] === '1') {
191
		// TODO : need to translate messages
342
		// TODO : need to translate messages
192
		$varErrors = [];
343
		$varErrors = [];
193
		if (isset($_POST['ldap_server']))        $ldap_server        = $_POST['ldap_server'];        else array_push($varErrors, 'Variable error "ldap_server"');
344
		if (isset($_POST['ldap_server']))        $ldap_server        = $_POST['ldap_server'];        else array_push($varErrors, 'Variable error "ldap_server"');
194
		if (isset($_POST['ldap_base_dn']))       $ldap_base_dn       = $_POST['ldap_base_dn'];       else array_push($varErrors, 'Variable error "ldap_base_dn"');
345
		if (isset($_POST['ldap_base_dn']))       $ldap_base_dn       = $_POST['ldap_base_dn'];       else array_push($varErrors, 'Variable error "ldap_base_dn"');
195
		if (isset($_POST['ldap_uid']))           $ldap_uid           = $_POST['ldap_uid'];           else array_push($varErrors, 'Variable error "ldap_uid"');
346
		if (isset($_POST['ldap_uid']))           $ldap_uid           = $_POST['ldap_uid'];           else array_push($varErrors, 'Variable error "ldap_uid"');
196
		if (isset($_POST['ldap_base_filter']))   $ldap_base_filter   = $_POST['ldap_base_filter'];   else array_push($varErrors, 'Variable error "ldap_base_filter"');
347
		if (isset($_POST['ldap_base_filter']))   $ldap_base_filter   = $_POST['ldap_base_filter'];   else array_push($varErrors, 'Variable error "ldap_base_filter"');
197
		if (isset($_POST['ldap_user']))          $ldap_user          = $_POST['ldap_user'];          else array_push($varErrors, 'Variable error "ldap_user"');
348
		if (isset($_POST['ldap_user']))          $ldap_user          = $_POST['ldap_user'];          else array_push($varErrors, 'Variable error "ldap_user"');
198
		if (isset($_POST['ldap_password']))      $ldap_password      = $_POST['ldap_password'];      else array_push($varErrors, 'Variable error "ldap_password"');
349
		if (isset($_POST['ldap_password']))      $ldap_password      = $_POST['ldap_password'];      else array_push($varErrors, 'Variable error "ldap_password"');
199
		if (isset($_POST['ldap_ssl']))           $ldap_ssl           = $_POST['ldap_ssl'];           //else array_push($varErrors, 'Variable error "ldap_ssl"');
350
		if (isset($_POST['ldap_ssl']))           $ldap_ssl           = $_POST['ldap_ssl'];           //else array_push($varErrors, 'Variable error "ldap_ssl"');
200
		if (isset($_FILES['ldap_cert']))         $ldap_cert          = $_FILES['ldap_cert'];         //else array_push($varErrors, 'Variable error "ldap_cert"');
351
		if (isset($_FILES['ldap_cert']))         $ldap_cert          = $_FILES['ldap_cert'];         //else array_push($varErrors, 'Variable error "ldap_cert"');
201
		if (isset($_POST['ldap_cert_required'])) $ldap_cert_required = $_POST['ldap_cert_required']; //else array_push($varErrors, 'Variable error "ldap_cert_required"');
352
		if (isset($_POST['ldap_cert_required'])) $ldap_cert_required = $_POST['ldap_cert_required']; //else array_push($varErrors, 'Variable error "ldap_cert_required"');
202
 
353
 
203
		if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
354
		if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
204
			if ($ldap_cert_required === 'on') {
355
			if ($ldap_cert_required === 'on') {
205
				$certificateInfos = openssl_x509_parse(file_get_contents($ldap_cert['tmp_name']));
356
				$certificateInfos = openssl_x509_parse(file_get_contents($ldap_cert['tmp_name']));
206
				if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
357
				if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
207
					$cert_domainName = implode('.', array_reverse($matches[1]));
358
					$cert_domainName = implode('.', array_reverse($matches[1]));
208
					if ($cert_domainName !== $ldap_server) {
359
					if ($cert_domainName !== $ldap_server) {
209
						array_push($varErrors, str_replace("§cert_domainName§", $cert_domainName, $l_ldap_cert_cn_diff_dn));
360
						array_push($varErrors, str_replace("§cert_domainName§", $cert_domainName, $l_ldap_cert_cn_diff_dn));
210
					}
361
					}
211
				}
362
				}
212
			}
363
			}
213
		}
364
		}
214
 
365
 
215
		if (!empty($varErrors)) { 
366
		if (!empty($varErrors)) { 
216
			foreach ($varErrors as $error) {
367
			foreach ($varErrors as $error) {
217
				$messages .= '<span style="font-weight: bold; color: red;">'.$error.'</span><br>';
368
				$messages .= '<span style="font-weight: bold; color: red;">'.$error.'</span><br>';
218
			}
369
			}
219
		} else {
370
		} else {
220
			exec('sed -i '.escapeshellarg("s/^LDAP_SERVER=.*/LDAP_SERVER=$ldap_server/g").' '.CONF_FILE);
371
			exec('sed -i '.escapeshellarg("s/^LDAP_SERVER=.*/LDAP_SERVER=$ldap_server/g").' '.CONF_FILE);
221
			exec('sed -i '.escapeshellarg("s/^LDAP_BASE=.*/LDAP_BASE=$ldap_base_dn/g").' '.CONF_FILE);
372
			exec('sed -i '.escapeshellarg("s/^LDAP_BASE=.*/LDAP_BASE=$ldap_base_dn/g").' '.CONF_FILE);
222
			exec('sed -i '.escapeshellarg("s/^LDAP_UID=.*/LDAP_UID=$ldap_uid/g").' '.CONF_FILE);
373
			exec('sed -i '.escapeshellarg("s/^LDAP_UID=.*/LDAP_UID=$ldap_uid/g").' '.CONF_FILE);
223
			exec('sed -i '.escapeshellarg("s/^LDAP_FILTER=.*/LDAP_FILTER=$ldap_base_filter/g").' '.CONF_FILE);
374
			exec('sed -i '.escapeshellarg("s/^LDAP_FILTER=.*/LDAP_FILTER=$ldap_base_filter/g").' '.CONF_FILE);
224
			exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE);
375
			exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE);
225
			exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE);
376
			exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE);
226
			exec('sed -i '.escapeshellarg("s/^LDAP_SSL=.*/LDAP_SSL=$ldap_ssl/g").' '.CONF_FILE);
377
			exec('sed -i '.escapeshellarg("s/^LDAP_SSL=.*/LDAP_SSL=$ldap_ssl/g").' '.CONF_FILE);
-
 
378
			if (isset($ldap_cert_required)) {
227
			exec('sed -i '.escapeshellarg("s/^LDAP_CERT_REQUIRED=.*/LDAP_CERT_REQUIRED=$ldap_cert_required/g").' '.CONF_FILE);
379
				exec('sed -i '.escapeshellarg("s/^LDAP_CERT_REQUIRED=.*/LDAP_CERT_REQUIRED=$ldap_cert_required/g").' '.CONF_FILE);
-
 
380
			}
228
			exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE);
381
			exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE);
229
			if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
382
			if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
230
				exec('sudo /usr/local/bin/alcasar-ldap.sh --import-cert '.escapeshellarg($ldap_cert['tmp_name']));
383
				exec('sudo /usr/local/bin/alcasar-ldap.sh --import-cert '.escapeshellarg($ldap_cert['tmp_name']));
231
			}
384
			}
232
			exec('sudo /usr/local/bin/alcasar-ldap.sh --on');
385
			exec('sudo /usr/local/bin/alcasar-ldap.sh --on');
233
			$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
386
			$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
-
 
387
 
-
 
388
			if ((isset($_POST['ad_dns_domain'])) && ($_POST['ad_dns_domain'] !== $conf['INT_DNS_DOMAIN'])) {
-
 
389
				if (filter_var($ldap_server, FILTER_VALIDATE_IP) !== false) {
-
 
390
					$ldap_server_ip = $ldap_server;
-
 
391
				} else {
-
 
392
					$ldap_server_ip = gethostbyname($ldap_server);
-
 
393
				}
-
 
394
				if (filter_var($ldap_server_ip, FILTER_VALIDATE_IP) !== false) {
-
 
395
					file_put_contents(CONF_FILE, str_replace('INT_DNS_IP='.$conf['INT_DNS_IP'],         'INT_DNS_IP='.$ldap_server_ip,             file_get_contents(CONF_FILE)));
-
 
396
					file_put_contents(CONF_FILE, str_replace('INT_DNS_DOMAIN='.$conf['INT_DNS_DOMAIN'], 'INT_DNS_DOMAIN='.$_POST['ad_dns_domain'], file_get_contents(CONF_FILE)));
-
 
397
					if (!empty($_POST['ad_dns_domain'])) {
-
 
398
						exec('sudo /usr/local/bin/alcasar-dns-local.sh --on');
-
 
399
					} else {
-
 
400
						exec('sudo /usr/local/bin/alcasar-dns-local.sh --off');
-
 
401
					}
-
 
402
				}
-
 
403
			}
234
		}
404
		}
235
	} else {
405
	} else {
236
		exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE);
406
		exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE);
237
		exec('sudo /usr/local/bin/alcasar-ldap.sh --off');
407
		exec('sudo /usr/local/bin/alcasar-ldap.sh --off');
238
		$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
408
		$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
-
 
409
 
-
 
410
		if ((isset($_POST['ad_dns_domain'])) && (empty($_POST['ad_dns_domain']))) {
-
 
411
			exec('sudo /usr/local/bin/alcasar-dns-local.sh --off');
-
 
412
		}
239
	}
413
	}
240
 
414
 
241
	// Reload configuration
415
	// Reload configuration
242
	$file_conf = fopen(CONF_FILE, 'r');
416
	$file_conf = fopen(CONF_FILE, 'r');
243
	if (!$file_conf) {
417
	if (!$file_conf) {
244
		exit('Error opening the file '.CONF_FILE);
418
		exit('Error opening the file '.CONF_FILE);
245
	}
419
	}
246
	while (!feof($file_conf)) {
420
	while (!feof($file_conf)) {
247
		$buffer = fgets($file_conf, 4096);
421
		$buffer = fgets($file_conf, 4096);
248
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
422
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
249
			$tmp = explode('=', $buffer, 2);
423
			$tmp = explode('=', $buffer, 2);
250
			$conf[trim($tmp[0])] = trim($tmp[1]);
424
			$conf[trim($tmp[0])] = trim($tmp[1]);
251
		}
425
		}
252
	}
426
	}
253
	fclose($file_conf);
427
	fclose($file_conf);
254
}
428
}
255
 
429
 
256
// LDAP configuration params
430
// LDAP configuration params
257
$ldap_status        = ($conf['LDAP'] === 'on');
431
$ldap_status        = ($conf['LDAP'] === 'on');
258
$ldap_server        = $conf['LDAP_SERVER'];
432
$ldap_server        = $conf['LDAP_SERVER'];
259
$ldap_user          = $conf['LDAP_USER'];
433
$ldap_user          = $conf['LDAP_USER'];
260
$ldap_password      = $conf['LDAP_PASSWORD'];
434
$ldap_password      = $conf['LDAP_PASSWORD'];
261
$ldap_base_dn       = $conf['LDAP_BASE'];
435
$ldap_base_dn       = $conf['LDAP_BASE'];
262
$ldap_uid	    = $conf['LDAP_UID'];
436
$ldap_uid	    = $conf['LDAP_UID'];
263
$ldap_base_filter   = $conf['LDAP_FILTER'];
437
$ldap_base_filter   = $conf['LDAP_FILTER'];
264
$ldap_ssl           = ($conf['LDAP_SSL'] === 'on');
438
$ldap_ssl           = ($conf['LDAP_SSL'] === 'on');
265
$ldap_cert_required = ($conf['LDAP_CERT_REQUIRED'] === 'on');
439
$ldap_cert_required = ($conf['LDAP_CERT_REQUIRED'] === 'on');
266
 
440
 
267
$ldap_cert_subject = NULL;
441
$ldap_cert_subject = null;
268
if (file_exists($LDAPS_CERT_LOC)) {
442
if (file_exists($LDAPS_CERT_LOC)) {
269
	$certificateInfos = openssl_x509_parse(file_get_contents($LDAPS_CERT_LOC));
443
	$certificateInfos = openssl_x509_parse(file_get_contents($LDAPS_CERT_LOC));
270
	if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
444
	if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
271
		$ldap_cert_subject = implode('.', array_reverse($matches[1]));
445
		$ldap_cert_subject = implode('.', array_reverse($matches[1]));
272
	}
446
	}
273
}
447
}
274
 
448
 
275
// AJAX LDAP configuration checker
449
// AJAX LDAP configuration checker
276
if (isset($_GET['conf_check'])) {
450
if (isset($_GET['conf_check'])) {
277
	$response = [
451
	$response = [
278
		'enable' => $ldap_status
452
		'enable' => $ldap_status
279
	];
453
	];
280
	if ($ldap_status || ($_SERVER['REQUEST_METHOD'] === 'POST')) {
454
	if ($ldap_status || ($_SERVER['REQUEST_METHOD'] === 'POST')) {
281
		$varErrors = [];
455
		$varErrors = [];
282
		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
456
		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
283
			// TODO : need to translate messages
457
			// TODO : need to translate messages
284
			if (isset($_POST['ldap_server']))        $ldap_server        = $_POST['ldap_server'];                   else array_push($varErrors, 'Variable error "ldap_server"');
458
			if (isset($_POST['ldap_server']))        $ldap_server        = $_POST['ldap_server'];                   else array_push($varErrors, 'Variable error "ldap_server"');
285
			if (isset($_POST['ldap_base_dn']))       $ldap_base_dn       = $_POST['ldap_base_dn'];                  else array_push($varErrors, 'Variable error "ldap_base_dn"');
459
			if (isset($_POST['ldap_base_dn']))       $ldap_base_dn       = $_POST['ldap_base_dn'];                  else array_push($varErrors, 'Variable error "ldap_base_dn"');
286
			if (isset($_POST['ldap_uid']))           $ldap_uid           = $_POST['ldap_uid'];                      else array_push($varErrors, 'Variable error "ldap_uid"');
460
			if (isset($_POST['ldap_uid']))           $ldap_uid           = $_POST['ldap_uid'];                      else array_push($varErrors, 'Variable error "ldap_uid"');
287
			if (isset($_POST['ldap_base_filter']))   $ldap_base_filter   = $_POST['ldap_base_filter'];              else array_push($varErrors, 'Variable error "ldap_base_filter"');
461
			if (isset($_POST['ldap_base_filter']))   $ldap_base_filter   = $_POST['ldap_base_filter'];              else array_push($varErrors, 'Variable error "ldap_base_filter"');
288
			if (isset($_POST['ldap_user']))          $ldap_user          = $_POST['ldap_user'];                     else array_push($varErrors, 'Variable error "ldap_user"');
462
			if (isset($_POST['ldap_user']))          $ldap_user          = $_POST['ldap_user'];                     else array_push($varErrors, 'Variable error "ldap_user"');
289
			if (isset($_POST['ldap_password']))      $ldap_password      = $_POST['ldap_password'];                 else array_push($varErrors, 'Variable error "ldap_password"');
463
			if (isset($_POST['ldap_password']))      $ldap_password      = $_POST['ldap_password'];                 else array_push($varErrors, 'Variable error "ldap_password"');
290
			if (isset($_POST['ldap_ssl']))           $ldap_ssl           = ($_POST['ldap_ssl'] === 'on');           //else array_push($varErrors, 'Variable error "ldap_ssl"');
464
			if (isset($_POST['ldap_ssl']))           $ldap_ssl           = ($_POST['ldap_ssl'] === 'on');           //else array_push($varErrors, 'Variable error "ldap_ssl"');
291
			if (isset($_FILES['ldap_cert']))         $ldap_cert          = $_FILES['ldap_cert'];                    //else array_push($varErrors, 'Variable error "ldap_cert"');
465
			if (isset($_FILES['ldap_cert']))         $ldap_cert          = $_FILES['ldap_cert'];                    //else array_push($varErrors, 'Variable error "ldap_cert"');
292
			if (isset($_POST['ldap_cert_required'])) $ldap_cert_required = ($_POST['ldap_cert_required'] === 'on'); //else array_push($varErrors, 'Variable error "ldap_cert_required"');
466
			if (isset($_POST['ldap_cert_required'])) $ldap_cert_required = ($_POST['ldap_cert_required'] === 'on'); //else array_push($varErrors, 'Variable error "ldap_cert_required"');
293
		}
467
		}
294
 
468
 
295
		if (($ldap_cert_required) && isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
469
		if (($ldap_cert_required) && isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
296
			$ldap_cert_tmpFilename = $ldap_cert['tmp_name'];
470
			$ldap_cert_tmpFilename = $ldap_cert['tmp_name'];
297
		} else {
471
		} else {
298
			$ldap_cert_tmpFilename = NULL;
472
			$ldap_cert_tmpFilename = null;
299
		}
473
		}
300
 
474
 
301
		if (!empty($varErrors)) {
475
		if (!empty($varErrors)) {
302
			$response['errors'] = $varErrors;
476
			$response['errors'] = $varErrors;
303
		} else {
477
		} else {
304
			$result = ldap_checkServerConfig($ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_base_filter, $ldap_uid, $ldap_ssl, $ldap_cert_tmpFilename, $ldap_cert_required);
478
			$result = ldap_checkServerConfig($ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_base_filter, $ldap_uid, $ldap_ssl, $ldap_cert_tmpFilename, $ldap_cert_required);
305
 
479
 
306
			if (($result === 0) && ($ldap_ssl && $ldap_cert_required && ((isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) || (file_exists($LDAPS_CERT_LOC))))) {
480
			if (($result === 0) && ($ldap_ssl && $ldap_cert_required && ((isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) || (file_exists($LDAPS_CERT_LOC))))) {
307
				if (filter_var($ldap_server, FILTER_VALIDATE_IP) !== false) {
481
				if (filter_var($ldap_server, FILTER_VALIDATE_IP) !== false) {
308
					if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
482
					if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) {
309
						$certificateInfos = openssl_x509_parse(file_get_contents($ldap_cert['tmp_name']));
483
						$certificateInfos = openssl_x509_parse(file_get_contents($ldap_cert['tmp_name']));
310
					} else {
484
					} else {
311
						$certificateInfos = openssl_x509_parse(file_get_contents($LDAPS_CERT_LOC));
485
						$certificateInfos = openssl_x509_parse(file_get_contents($LDAPS_CERT_LOC));
312
					}
486
					}
313
					if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
487
					if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) {
314
						$cert_domainName = implode('.', array_reverse($matches[1]));
488
						$cert_domainName = implode('.', array_reverse($matches[1]));
315
						if ($cert_domainName !== $ldap_server) {
489
						if ($cert_domainName !== $ldap_server) {
316
							$response['warnings'][] = str_replace("§cert_domainName§", $cert_domainName, $l_ldap_cert_cn_diff_dn);
490
							$response['warnings'][] = str_replace("§cert_domainName§", $cert_domainName, $l_ldap_cert_cn_diff_dn);
317
						}
491
						}
318
					}
492
					}
319
					$res = ldap_checkServerConfig($cert_domainName, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_base_filter, $ldap_uid, $ldap_ssl, $ldap_cert_tmpFilename, $ldap_cert_required);
493
					$res = ldap_checkServerConfig($cert_domainName, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_base_filter, $ldap_uid, $ldap_ssl, $ldap_cert_tmpFilename, $ldap_cert_required);
320
					if ($res > 1) {
494
					if ($res > 1) {
321
						$result = $res;
495
						$result = $res;
322
					}
496
					}
323
					$result = max($result, $res);
497
					$result = max($result, $res);
324
				}
498
				}
325
			}
499
			}
326
 
500
 
327
			$response['result'] = $result;
501
			$response['result'] = $result;
328
		}
502
		}
329
	}
503
	}
330
 
504
 
331
	header('Content-Type: application/json');
505
	header('Content-Type: application/json');
332
	echo json_encode($response);
506
	echo json_encode($response);
333
	exit();
507
	exit();
334
}
508
}
335
 
509
 
336
?>
510
?>
337
<!DOCTYPE html>
511
<!DOCTYPE html>
338
<html>
512
<html>
339
<head>
513
<head>
340
	<meta charset="UTF-8">
514
	<meta charset="UTF-8">
341
	<title><?= $l_ldap_title ?></title>
515
	<title><?= $l_ldap_title ?></title>
342
	<link type="text/css" href="/css/style.css" rel="stylesheet">
516
	<link type="text/css" href="/css/style.css" rel="stylesheet">
343
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
517
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
344
	<link type="text/css" href="/css/ldap.css" rel="stylesheet">
518
	<link type="text/css" href="/css/ldap.css" rel="stylesheet">
345
	<script>
519
	<script>
346
	function onLdapStatusChange() {
520
	function onLdapStatusChange() {
347
		var listToDisables = ['ldap_server', 'ldap_dn', 'ldap_uid', 'ldap_base_filter', 'ldap_user', 'ldap_password', 'ldap_ssl', 'ldap_cert_required', 'ldap_cert'];
521
		var listToDisables = ['ldap_server', 'ldap_dn', 'ldap_uid', 'ldap_base_filter', 'ldap_user', 'ldap_password', 'ldap_ssl', 'ldap_cert_required', 'ldap_cert'];
348
		var formSubmit = document.querySelector('form input[type="submit"]');
522
		var formSubmit = document.querySelector('form input[type="submit"]');
349
		var btn_checkConf = document.getElementById('btn-checkconf');
523
		var btn_checkConf = document.getElementById('btn-checkconf');
350
		var isChecked = false;
524
		var isChecked = false;
351
 
525
 
352
		if (document.getElementById('auth_enable').value === '1') {
526
		if (document.getElementById('auth_enable').value === '1') {
353
			for (var i=0; i<listToDisables.length; i++) {
527
			for (var i=0; i<listToDisables.length; i++) {
354
				document.getElementById(listToDisables[i]).style.backgroundColor = null;
528
				document.getElementById(listToDisables[i]).style.backgroundColor = null;
355
				document.getElementById(listToDisables[i]).disabled = false;
529
				document.getElementById(listToDisables[i]).disabled = false;
356
			}
530
			}
357
			if (document.getElementById('ldap_ssl').value === 'off') {
531
			if (document.getElementById('ldap_ssl').value === 'off') {
358
				document.getElementById('ldap_cert_required').style.backgroundColor = '#c0c0c0';
532
				document.getElementById('ldap_cert_required').style.backgroundColor = '#c0c0c0';
359
				document.getElementById('ldap_cert_required').disabled = true;
533
				document.getElementById('ldap_cert_required').disabled = true;
360
				document.getElementById('ldap_cert').style.backgroundColor = '#c0c0c0';
534
				document.getElementById('ldap_cert').style.backgroundColor = '#c0c0c0';
361
				document.getElementById('ldap_cert').disabled = true;
535
				document.getElementById('ldap_cert').disabled = true;
362
			}
536
			}
363
			else if (document.getElementById('ldap_cert_required').value === 'off') {
537
			else if (document.getElementById('ldap_cert_required').value === 'off') {
364
				document.getElementById('ldap_cert').style.backgroundColor = '#c0c0c0';
538
				document.getElementById('ldap_cert').style.backgroundColor = '#c0c0c0';
365
				document.getElementById('ldap_cert').disabled = true;
539
				document.getElementById('ldap_cert').disabled = true;
366
			}
540
			}
367
			formSubmit.style.display = 'none';
541
			formSubmit.style.display = 'none';
368
			btn_checkConf.style.display = null;
542
			btn_checkConf.style.display = null;
369
			<?php if (PHP_VERSION_ID < 70100): ?>
543
<?php if (PHP_VERSION_ID < 70100): ?>
370
			// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released
544
			// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released
371
			formSubmit.style.display = null;
545
			formSubmit.style.display = null;
372
			<?php endif; ?>
546
<?php endif; ?>
373
		} else {
547
		} else {
374
			for (var i=0; i<listToDisables.length; i++) {
548
			for (var i=0; i<listToDisables.length; i++) {
375
				document.getElementById(listToDisables[i]).style.backgroundColor = '#c0c0c0';
549
				document.getElementById(listToDisables[i]).style.backgroundColor = '#c0c0c0';
376
				document.getElementById(listToDisables[i]).disabled = true;
550
				document.getElementById(listToDisables[i]).disabled = true;
377
			}
551
			}
378
			formSubmit.style.display = null;
552
			formSubmit.style.display = null;
379
			btn_checkConf.style.display = 'none';
553
			btn_checkConf.style.display = 'none';
380
		}
554
		}
381
	}
555
	}
382
 
556
 
383
	function checkConfig() {
557
	function checkConfig() {
384
		var messagesElem = document.querySelector('fieldset > legend > div');
558
		var messagesElem = document.querySelector('fieldset > legend > div');
385
		var formSubmit   = document.querySelector('form input[type="submit"]');
559
		var formSubmit   = document.querySelector('form input[type="submit"]');
386
		var btn_checkConf = document.getElementById('btn-checkconf');
560
		var btn_checkConf = document.getElementById('btn-checkconf');
387
		var form = document.getElementById('form-config_ldap');
561
		var form = document.getElementById('form-config_ldap');
388
		var post_data = new FormData(form);
562
		var post_data = new FormData(form);
389
		post_data.delete('auth_enable');
563
		post_data.delete('auth_enable');
390
 
564
 
391
		messagesElem.innerHTML = '<?= $l_checkingConf ?>';
565
		messagesElem.innerHTML = '<?= $l_checkingConf ?>';
392
 
566
 
393
		var xhr = new XMLHttpRequest();
567
		var xhr = new XMLHttpRequest();
394
		xhr.onreadystatechange = function() {
568
		xhr.onreadystatechange = function() {
395
			if (this.readyState == 4) {
569
			if (this.readyState == 4) {
396
				if (this.status == 200) {
570
				if (this.status == 200) {
397
					var data = JSON.parse(this.responseText);
571
					var data = JSON.parse(this.responseText);
398
 
572
 
399
					var messages = '';
573
					var messages = '';
400
 
574
 
401
					if (typeof data.result !== 'undefined') {
575
					if (typeof data.result !== 'undefined') {
402
						if (data.result === -2) {
576
						if (data.result === -2) {
403
							messages += "<span style=\"color: red\"><?= $l_ldap_test_service_failed ?></span>";
577
							messages += "<span style=\"color: red\"><?= $l_ldap_test_service_failed ?></span>";
404
						} else {
578
						} else {
405
							messages += "<span style=\"color: green\"><?= $l_ldap_test_service_ok ?></span>";
579
							messages += "<span style=\"color: green\"><?= $l_ldap_test_service_ok ?></span>";
406
							if (data.result === -1) {
580
							if (data.result === -1) {
407
								messages += "<br><span style=\"color: red\"><?= $l_ldap_test_connection_failed ?></span>";
581
								messages += "<br><span style=\"color: red\"><?= $l_ldap_test_connection_failed ?></span>";
408
							} else {
582
							} else {
409
								messages += "<br><span style=\"color: green\"><?= $l_ldap_test_connection_ok ?></span>";
583
								messages += "<br><span style=\"color: green\"><?= $l_ldap_test_connection_ok ?></span>";
410
								if (data.result === 0) {
584
								if (data.result === 0) {
411
									messages += "<br><span style=\"color: red\"><?= $l_ldap_test_bind_failed ?></span>";
585
									messages += "<br><span style=\"color: red\"><?= $l_ldap_test_bind_failed ?></span>";
412
								} else {
586
								} else {
413
									messages += "<br><span style=\"color: green\"><?= $l_ldap_test_bind_ok ?></span>";
587
									messages += "<br><span style=\"color: green\"><?= $l_ldap_test_bind_ok ?></span>";
414
									if (data.result === 1) {
588
									if (data.result === 1) {
415
										messages += "<br><span style=\"color: red\"><?= $l_ldap_test_dn_failed ?></span>";
589
										messages += "<br><span style=\"color: red\"><?= $l_ldap_test_dn_failed ?></span>";
416
									} else {
590
									} else {
417
										messages += "<br><span style=\"color: green\"><?= $l_ldap_test_dn_ok ?> (" + (data.result - 2) + " <?= $l_ldap_entries?>)</span>";
591
										messages += "<br><span style=\"color: green\"><?= $l_ldap_test_dn_ok ?> (" + (data.result - 2) + " <?= $l_ldap_entries?>)</span>";
418
									}
592
									}
419
								}
593
								}
420
							}
594
							}
421
						}
595
						}
422
					}
596
					}
423
 
597
 
424
					if (data.result > 1) {
598
					if (data.result > 1) {
425
						formSubmit.style.display = null;
599
						formSubmit.style.display = null;
426
						btn_checkConf.style.display = 'none';
600
						btn_checkConf.style.display = 'none';
427
					} else {
601
					} else {
428
						formSubmit.style.display = 'none';
602
						formSubmit.style.display = 'none';
429
						btn_checkConf.style.display = null;
603
						btn_checkConf.style.display = null;
430
					}
604
					}
431
					<?php if (PHP_VERSION_ID < 70100): ?>
605
<?php if (PHP_VERSION_ID < 70100): ?>
432
					// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released
606
					// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released
433
					formSubmit.style.display = null;
607
					formSubmit.style.display = null;
434
					<?php endif; ?>
608
<?php endif; ?>
435
 
609
 
436
					if (typeof data.errors !== 'undefined') {
610
					if (typeof data.errors !== 'undefined') {
437
						messages = '<span style=\"color: red\">' + data.errors.join('</span><br><span style=\"color: red\">') + '</span><br>';
611
						messages = '<span style=\"color: red\">' + data.errors.join('</span><br><span style=\"color: red\">') + '</span><br>';
438
					}
612
					}
439
					if (typeof data.warnings !== 'undefined') {
613
					if (typeof data.warnings !== 'undefined') {
440
						messages += '<br><span style=\"color: orange\">' + data.warnings.join('</span><br><span style=\"color: orange\">') + '</span><br>';
614
						messages += '<br><span style=\"color: orange\">' + data.warnings.join('</span><br><span style=\"color: orange\">') + '</span><br>';
441
					}
615
					}
442
 
616
 
443
					messagesElem.innerHTML = messages;
617
					messagesElem.innerHTML = messages;
444
				} else {
618
				} else {
445
					messagesElem.innerHTML = 'server error';
619
					messagesElem.innerHTML = 'server error';
446
				}
620
				}
447
			}
621
			}
448
		};
622
		};
449
		xhr.open('POST', 'ldap.php?conf_check', true);
623
		xhr.open('POST', 'ldap.php?conf_check', true);
450
		xhr.send(post_data);
624
		xhr.send(post_data);
451
	}
625
	}
-
 
626
 
-
 
627
	function launchAssistant() {
-
 
628
		var messagesElem = document.querySelector('fieldset > legend > div');
-
 
629
		var dom_ldap_server        = document.getElementById('ldap_server');
-
 
630
		var dom_ldap_ssl           = document.getElementById('ldap_ssl');
-
 
631
		var dom_ldap_cert_required = document.getElementById('ldap_cert_required');
-
 
632
		var dom_ldap_dn            = document.getElementById('ldap_dn');
-
 
633
		var dom_ldap_uid           = document.getElementById('ldap_uid');
-
 
634
		var dom_ad_dns_domain      = document.getElementById('ad_dns_domain');
-
 
635
		post_data = 'ldap_server='+dom_ldap_server.value;
-
 
636
 
-
 
637
		var xhr = new XMLHttpRequest();
-
 
638
		xhr.onreadystatechange = function() {
-
 
639
			if (this.readyState == 4) {
-
 
640
				if (this.status == 200) {
-
 
641
					var data = JSON.parse(this.responseText);
-
 
642
					var messages = '';
-
 
643
 
-
 
644
					if (typeof data.result !== 'undefined') {
-
 
645
						if (data.result === -2) {
-
 
646
							messages += "<span style=\"color: red\"><?= $l_ldap_test_service_failed ?></span>";
-
 
647
						} else if (data.result === -1) {
-
 
648
							messages += "<br><span style=\"color: red\"><?= $l_ldap_test_connection_failed ?></span>";
-
 
649
						} else if (data.result === 0) {
-
 
650
							if ((typeof data.values.int_dns_domain !== 'undefined') && (dom_ad_dns_domain.value === '')) {
-
 
651
								dom_ad_dns_domain.value = data.values.int_dns_domain
-
 
652
							}
-
 
653
							if ((typeof data.values.ldap_base_dn !== 'undefined') && (dom_ldap_dn.value === '')) {
-
 
654
								dom_ldap_dn.value = data.values.ldap_base_dn
-
 
655
							}
-
 
656
							if (dom_ldap_uid.value === '') {
-
 
657
								if (data.values.isAD === true) {
-
 
658
									dom_ldap_uid.value = 'sAMAccountName';
-
 
659
								} else {
-
 
660
									dom_ldap_uid.value = 'uid';
-
 
661
								}
-
 
662
							}
-
 
663
							if (data.values.ldap_srv_636 === true) {
-
 
664
								dom_ldap_ssl.value = 'on'
-
 
665
								if ((typeof data.values.ldap_server_domain !== 'undefined') && (dom_ldap_cert_required.value === 'on')) {
-
 
666
									dom_ldap_server.value = data.values.ldap_server_domain
-
 
667
								}
-
 
668
							} else {
-
 
669
								if (dom_ldap_ssl.value === 'on') {
-
 
670
									dom_ldap_ssl.value = 'off';
-
 
671
								}
-
 
672
							}
-
 
673
							onLdapStatusChange();
-
 
674
						}
-
 
675
					}
-
 
676
 
-
 
677
					messagesElem.innerHTML = messages;
-
 
678
				} else {
-
 
679
					messagesElem.innerHTML = 'server error';
-
 
680
				}
-
 
681
			}
-
 
682
		};
-
 
683
		xhr.open('POST', 'ldap.php?assistant', true);
-
 
684
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
-
 
685
		xhr.send(post_data);
-
 
686
	}
452
	</script>
687
	</script>
453
</head>
688
</head>
454
<body onLoad="onLdapStatusChange();">
689
<body onLoad="onLdapStatusChange();">
455
	<div class="panel">
690
	<div class="panel">
456
		<div class="panel-header"><?= $l_ldap_legend ?></div>
691
		<div class="panel-header"><?= $l_ldap_legend ?></div>
457
		<div class="panel-body">
692
		<div class="panel-body">
458
			<form id="form-config_ldap" name="config_ldap" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
693
			<form id="form-config_ldap" name="config_ldap" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
459
				<fieldset>
694
				<fieldset>
460
					<legend>
695
					<legend>
461
						<br>
696
						<br>
462
						<div style="text-align: center">
697
						<div style="text-align: center">
463
							<?php if ($messages): ?>
698
							<?php if ($messages): ?>
464
								<?= $messages ?>
699
								<?= $messages ?>
465
							<?php endif; ?>
700
							<?php endif; ?>
466
						</div>
701
						</div>
467
					</legend>
702
					</legend>
468
					<dl>
703
					<dl>
469
						<dt>
704
						<dt>
470
							<label for="auth_enable"><?= $l_ldap_auth_enable_label ?></label>
705
							<label for="auth_enable"><?= $l_ldap_auth_enable_label ?></label>
471
						</dt>
706
						</dt>
472
						<dd>
707
						<dd>
473
							<select id="auth_enable" name="auth_enable" onchange="onLdapStatusChange();">
708
							<select id="auth_enable" name="auth_enable" onchange="onLdapStatusChange();">
474
								<option value="1"<?= ($ldap_status)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
709
								<option value="1"<?= ($ldap_status)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
475
								<option value="0"<?= (!$ldap_status) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
710
								<option value="0"<?= (!$ldap_status) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
476
							</select>
711
							</select>
477
						</dd>
712
						</dd>
478
					</dl>
713
					</dl>
479
					<dl>
714
					<dl>
480
						<dt>
715
						<dt>
481
							<label for="ldap_server"><?= $l_ldap_server_label ?></label><br>
716
							<label for="ldap_server"><?= $l_ldap_server_label ?></label><br>
482
							<?= $l_ldap_server_text ?>
717
							<?= $l_ldap_server_text ?>
483
						</dt>
718
						</dt>
484
						<dd>
719
						<dd>
485
							<input type="text" id="ldap_server" size="40" name="ldap_server" value="<?= htmlspecialchars($ldap_server) ?>" oninput="onLdapStatusChange();">
720
							<input type="text" id="ldap_server" size="40" name="ldap_server" value="<?= htmlspecialchars($ldap_server) ?>" oninput="onLdapStatusChange();"> <button onclick="launchAssistant(); return false;"><?= 'Assistant' ?></button>
486
						</dd>
721
						</dd>
487
					</dl>
722
					</dl>
488
					<dl>
723
					<dl>
489
						<dt>
724
						<dt>
490
							<label for="ldap_dn"><?= $l_ldap_base_dn_label ?></label><br>
725
							<label for="ldap_ssl"><?= $l_ldap_ssl_label ?></label><br>
491
							<?= $l_ldap_base_dn_text ?>
726
							<?= $l_ldap_ssl_text ?><br>
492
						</dt>
727
						</dt>
493
						<dd>
728
						<dd>
494
							<input type="text" id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>" oninput="onLdapStatusChange();">
729
							<select id="ldap_ssl" name="ldap_ssl" onchange="onLdapStatusChange();">
-
 
730
								<option value="on"<?= ($ldap_ssl)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
-
 
731
								<option value="off"<?= (!$ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
-
 
732
							</select>
495
						</dd>
733
						</dd>
496
					</dl>
734
					</dl>
497
					<dl>
735
					<dl>
498
						<dt>
736
						<dt>
499
							<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br>
737
							<label for="ldap_cert_required"><?= $l_ldap_cert_required_label ?></label><br>
500
							<?= $l_ldap_uid_text ?>
738
							<?= $l_ldap_cert_required_text ?><br>
501
						</dt>
739
						</dt>
502
						<dd>
740
						<dd>
503
							<input type="text" id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>" oninput="onLdapStatusChange();">
741
							<select id="ldap_cert_required" name="ldap_cert_required" onchange="onLdapStatusChange();">
-
 
742
								<option value="on"<?= ($ldap_cert_required)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
-
 
743
								<option value="off"<?= (!$ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
-
 
744
							</select>
504
						</dd>
745
						</dd>
505
					</dl>
746
					</dl>
506
					<dl>
747
					<dl>
507
						<dt>
748
						<dt>
508
							<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br>
749
							<label for="ldap_cert"><?= $l_ldap_cert_label ?></label><br>
509
							<?= $l_ldap_base_filter_text ?>
750
							<?= $l_ldap_cert_text ?><br>
-
 
751
							<?= (($ldap_cert_subject) ? "$l_ldap_cert_status_cur $ldap_cert_subject" : $l_ldap_cert_status_no ) ?>
510
						</dt>
752
						</dt>
511
						<dd>
753
						<dd>
512
							<input type="text" id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?= htmlspecialchars($ldap_base_filter) ?>" oninput="onLdapStatusChange();">
754
							<input type="file" id="ldap_cert" name="ldap_cert" oninput="onLdapStatusChange();">
513
						</dd>
755
						</dd>
514
					</dl>
756
					</dl>
515
					<dl>
757
					<dl>
516
						<dt>
758
						<dt>
517
							<label for="ldap_user"><?= $l_ldap_user_label ?></label><br>
759
							<label for="ldap_user"><?= $l_ldap_user_label ?></label><br>
518
							<?= $l_ldap_user_text ?>
760
							<?= $l_ldap_user_text ?>
519
						</dt>
761
						</dt>
520
						<dd>
762
						<dd>
521
							<input type="text" id="ldap_user" size="40" name="ldap_user" value="<?= htmlspecialchars($ldap_user) ?>" oninput="onLdapStatusChange();">
763
							<input type="text" id="ldap_user" size="40" name="ldap_user" value="<?= htmlspecialchars($ldap_user) ?>" oninput="onLdapStatusChange();">
522
						</dd>
764
						</dd>
523
					</dl>
765
					</dl>
524
					<dl>
766
					<dl>
525
						<dt>
767
						<dt>
526
							<label for="ldap_password"><?= $l_ldap_password_label ?></label><br>
768
							<label for="ldap_password"><?= $l_ldap_password_label ?></label><br>
527
							<?= $l_ldap_password_text ?>
769
							<?= $l_ldap_password_text ?>
528
						</dt>
770
						</dt>
529
						<dd>
771
						<dd>
530
							<input type="password" id="ldap_password" size="40" name="ldap_password" value="<?= htmlspecialchars($ldap_password) ?>" oninput="onLdapStatusChange();">
772
							<input type="password" id="ldap_password" size="40" name="ldap_password" value="<?= htmlspecialchars($ldap_password) ?>" oninput="onLdapStatusChange();">
531
						</dd>
773
						</dd>
532
					</dl>
774
					</dl>
533
					<dl>
775
					<dl>
534
						<dt>
776
						<dt>
535
							<label for="ldap_ssl"><?= $l_ldap_ssl_label ?></label><br>
777
							<label for="ldap_dn"><?= $l_ldap_base_dn_label ?></label><br>
536
							<?= $l_ldap_ssl_text ?><br>
778
							<?= $l_ldap_base_dn_text ?>
537
						</dt>
779
						</dt>
538
						<dd>
780
						<dd>
539
							<select id="ldap_ssl" name="ldap_ssl" onchange="onLdapStatusChange();">
781
							<input type="text" id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>" oninput="onLdapStatusChange();">
540
								<option value="on"<?= ($ldap_ssl)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
-
 
541
								<option value="off"<?= (!$ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
-
 
542
							</select>
-
 
543
						</dd>
782
						</dd>
544
					</dl>
783
					</dl>
545
					<dl>
784
					<dl>
546
						<dt>
785
						<dt>
547
							<label for="ldap_cert_required"><?= $l_ldap_cert_required_label ?></label><br>
786
							<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br>
548
							<?= $l_ldap_cert_required_text ?><br>
787
							<?= $l_ldap_uid_text ?>
549
						</dt>
788
						</dt>
550
						<dd>
789
						<dd>
551
							<select id="ldap_cert_required" name="ldap_cert_required" onchange="onLdapStatusChange();">
790
							<input type="text" id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>" oninput="onLdapStatusChange();">
552
								<option value="on"<?= ($ldap_cert_required)  ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
-
 
553
								<option value="off"<?= (!$ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
-
 
554
							</select>
-
 
555
						</dd>
791
						</dd>
556
					</dl>
792
					</dl>
557
					<dl>
793
					<dl>
558
						<dt>
794
						<dt>
559
							<label for="ldap_cert"><?= $l_ldap_cert_label ?></label><br>
795
							<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br>
560
							<?= $l_ldap_cert_text ?><br>
796
							<?= $l_ldap_base_filter_text ?>
561
							<?= (($ldap_cert_subject) ? "$l_ldap_cert_status_cur $ldap_cert_subject" : $l_ldap_cert_status_no ) ?>
-
 
562
						</dt>
797
						</dt>
563
						<dd>
798
						<dd>
564
							<input type="file" id="ldap_cert" name="ldap_cert" oninput="onLdapStatusChange();">
799
							<input type="text" id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?= htmlspecialchars($ldap_base_filter) ?>" oninput="onLdapStatusChange();">
-
 
800
						</dd>
-
 
801
					</dl>
-
 
802
					<dl>
-
 
803
						<dt>
-
 
804
							<label for="ad_dns_domain"><?= $l_ad_dns_domain_label ?></label><br>
-
 
805
							<?= $l_ad_dns_domain_text ?>
-
 
806
						</dt>
-
 
807
						<dd>
-
 
808
							<input type="text" id="ad_dns_domain" size="40" name="ad_dns_domain" value="<?= htmlspecialchars($conf['INT_DNS_DOMAIN']) ?>" oninput="onLdapStatusChange();">
565
						</dd>
809
						</dd>
566
					</dl>
810
					</dl>
567
					<p>
811
					<p>
568
						<button id="btn-checkconf" onclick="checkConfig(); return false;"><?= $l_check ?></button>
812
						<button id="btn-checkconf" onclick="checkConfig(); return false;"><?= $l_check ?></button>
569
						<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit">
813
						<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit">
570
					</p>
814
					</p>
571
				</fieldset>
815
				</fieldset>
572
			</form>
816
			</form>
573
		</div>
817
		</div>
574
	</div>
818
	</div>
575
</body>
819
</body>
576
</html>
820
</html>
577
 
821