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