Subversion Repositories ALCASAR

Rev

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

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