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