318 |
richard |
1 |
<?php
|
2449 |
tom.houday |
2 |
# $Id: ldap.php 2459 2017-12-10 22:17:52Z richard $
|
|
|
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.";
|
2459 |
richard |
66 |
$l_ldap_submit = "Enregistrer et vérifier";
|
|
|
67 |
$l_ldap_test_service_failed = "Service LDAP injoignable sur ce serveur (vérifiez l'@IP).";
|
|
|
68 |
$l_ldap_test_service_ok = "Un port 389 est actif sur ce serveur";
|
|
|
69 |
$l_ldap_test_connection_failed = "Connexion LDAP impossible (vérifiez le service LDAP sur ce serveur)";
|
|
|
70 |
$l_ldap_test_connection_ok = "Une connexion LDAP a été établie";
|
|
|
71 |
$l_ldap_test_bind_failed = "Echec d'authentification (vérifiez l'utilisateur et le mot de passe)";
|
|
|
72 |
$l_ldap_test_bind_ok = "L'authentification a réussie";
|
|
|
73 |
$l_ldap_test_dn_failed = "Le DN de la base semble incorrect (vérifiez le)";
|
|
|
74 |
$l_ldap_test_dn_ok = "Le DN de la base semble correct";
|
2449 |
tom.houday |
75 |
$l_ldap_error = "erreur LDAP";
|
2459 |
richard |
76 |
$l_ldap_entries = "entrées dans la base";
|
|
|
77 |
$l_ldap_push_config = "Activer cette configuration";
|
2449 |
tom.houday |
78 |
} else { // English
|
2459 |
richard |
79 |
$l_ldap_update = "LDAP settings updated";
|
1672 |
richard |
80 |
$l_ldap_title = "External authentication : LDAP";
|
|
|
81 |
$l_ldap_legend = "LDAP authentication";
|
2459 |
richard |
82 |
$l_ldap_auth_enable_label = "Edit the LDAP configuration :";
|
1672 |
richard |
83 |
$l_ldap_YES = "YES";
|
|
|
84 |
$l_ldap_NO = "NO";
|
1677 |
richard |
85 |
$l_ldap_server_label = "LDAP server :";
|
2459 |
richard |
86 |
$l_ldap_server_text = "IP address of the LDAP server.";
|
|
|
87 |
$l_ldap_base_dn_label = "DN of the base:";
|
|
|
88 |
$l_ldap_base_dn_text = "The DN (Distinguished Name) is used to locate the users information in the directory.<br> e.g. LDAP : 'o=MyCompany,c=US'.<br> e.g. AD : 'cn=Users,dc=server_name,dc=localdomain'";
|
|
|
89 |
$l_ldap_uid_label = "User IDentifier (UID):";
|
|
|
90 |
$l_ldap_uid_text = "Key used to search for a given login identity.<br>e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
|
|
|
91 |
$l_ldap_base_filter_label = "User search filter (optional):";
|
|
|
92 |
$l_ldap_base_filter_text = "You can further limit the searched objects with additional filters.<br> For example 'objectClass=posixGroup' would result in the use of '(&(uid=username)(objectClass=posixGroup))'";
|
|
|
93 |
$l_ldap_user_label = "CN of the user operated by ALCASAR:";
|
|
|
94 |
$l_ldap_user_text = "CN=Common Name. Leave blank to use anonymous binding. Mandatory for AD.<br> e.g. LDAP :'uid=Username,ou=my_lan,o=mycompany,c=US'.<br> e.g. AD : 'username' or 'cn=username,cn=Users,dc=server_name,dc=localdomain'";
|
|
|
95 |
$l_ldap_password_label = "Password:";
|
|
|
96 |
$l_ldap_password_text = "Leave blank to use anonymous binding. Mandatory for AD.";
|
|
|
97 |
$l_ldap_submit = "Save & Check";
|
|
|
98 |
$l_ldap_test_service_failed = "LDAP service is not reachable on that server (check IP)";
|
|
|
99 |
$l_ldap_test_service_ok = "A port 389 is open on this server";
|
|
|
100 |
$l_ldap_test_connection_failed = "LDAP connexion failed (check the LDAP service on this server)";
|
|
|
101 |
$l_ldap_test_connection_ok = "A LDAP connexion is established";
|
|
|
102 |
$l_ldap_test_bind_failed = "LDAP authentication failed (check the LDAP user and password)";
|
|
|
103 |
$l_ldap_test_bind_ok = "Successful authentication";
|
|
|
104 |
$l_ldap_test_dn_failed = "DN of the base seems to be wrong (check it)";
|
|
|
105 |
$l_ldap_test_dn_ok = "DN of the base seems to be ok";
|
2449 |
tom.houday |
106 |
$l_ldap_error = "LDAP error";
|
2459 |
richard |
107 |
$l_ldap_entries = "entries in the base";
|
|
|
108 |
$l_ldap_push_config = "Activate this configuration";
|
1160 |
stephane |
109 |
}
|
318 |
richard |
110 |
|
|
|
111 |
|
2459 |
richard |
112 |
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_uid, $f_ldap_port = 389) {
|
|
|
113 |
// Socket to the LDAP port of the server
|
620 |
stephane |
114 |
if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
|
658 |
stephane |
115 |
// no network connection
|
2459 |
richard |
116 |
return -2;
|
2449 |
tom.houday |
117 |
}
|
|
|
118 |
fclose($sock);
|
1395 |
richard |
119 |
|
2459 |
richard |
120 |
// if ok, Test LDAP connection
|
2449 |
tom.houday |
121 |
$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
|
|
|
122 |
ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
|
|
|
123 |
if (!$ldapconn) {
|
|
|
124 |
// LDAP connection failed
|
2459 |
richard |
125 |
return -1;
|
620 |
stephane |
126 |
}
|
|
|
127 |
|
2459 |
richard |
128 |
// if ok, test a ldap-bind with the user used by ALCASAR
|
2449 |
tom.houday |
129 |
$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
|
|
|
130 |
if (!$ldapbind) {
|
|
|
131 |
// Test LDAP Version 3
|
|
|
132 |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
|
133 |
$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
|
|
|
134 |
if (!$ldapbind) {
|
|
|
135 |
// LDAP Bind failed
|
|
|
136 |
return 0;
|
318 |
richard |
137 |
}
|
2449 |
tom.houday |
138 |
}
|
|
|
139 |
|
2459 |
richard |
140 |
// if ok, try to query the directory of users
|
|
|
141 |
$query = $f_ldap_uid."=*";
|
|
|
142 |
$ldap_result = ldap_search($ldapconn, $f_ldap_basedn, $query);
|
2449 |
tom.houday |
143 |
if (ldap_search($ldapconn, $f_ldap_basedn, $query)) {
|
2459 |
richard |
144 |
$ldap_users_number = ldap_count_entries($ldapconn, $ldap_result);
|
|
|
145 |
return $ldap_users_number;
|
318 |
richard |
146 |
} else {
|
2449 |
tom.houday |
147 |
return 1;
|
318 |
richard |
148 |
}
|
2459 |
richard |
149 |
ldap_unbind($ldapconn);
|
318 |
richard |
150 |
}
|
2449 |
tom.houday |
151 |
|
2451 |
tom.houday |
152 |
$messages = '';
|
2459 |
richard |
153 |
$ldap_can_be_enabled = False;
|
2451 |
tom.houday |
154 |
|
|
|
155 |
if (isset($_POST['auth_enable'])) {
|
|
|
156 |
if ($_POST['auth_enable'] === '1') {
|
|
|
157 |
$varErrors = [];
|
|
|
158 |
if (isset($_POST['ldap_server'])) $ldap_server = $_POST['ldap_server']; else array_push($varErrors, 'Variable error "ldap_server"');
|
|
|
159 |
if (isset($_POST['ldap_base_dn'])) $ldap_base_dn = $_POST['ldap_base_dn']; else array_push($varErrors, 'Variable error "ldap_base_dn"');
|
2459 |
richard |
160 |
if (isset($_POST['ldap_uid'])) $ldap_uid = $_POST['ldap_uid']; else array_push($varErrors, 'Variable error "ldap_uid"');
|
2451 |
tom.houday |
161 |
if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
|
|
|
162 |
if (isset($_POST['ldap_user'])) $ldap_user = $_POST['ldap_user']; else array_push($varErrors, 'Variable error "ldap_user"');
|
|
|
163 |
if (isset($_POST['ldap_password'])) $ldap_password = $_POST['ldap_password']; else array_push($varErrors, 'Variable error "ldap_password"');
|
|
|
164 |
|
|
|
165 |
// Validation
|
|
|
166 |
if (isset($ldap_server)) {
|
|
|
167 |
if ((!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) && (preg_match('/^[a-zA-Z0-9-_.]+$/', $ldap_server))) {
|
|
|
168 |
$ldap_server = gethostbyname($ldap_server);
|
|
|
169 |
}
|
|
|
170 |
if (!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) {
|
|
|
171 |
array_push($varErrors, 'Invalid LDAP server IP');
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
if (!empty($varErrors)) {
|
|
|
176 |
$messages .= '<div style="text-align: center"><br>';
|
|
|
177 |
foreach ($varErrors as $error) {
|
|
|
178 |
$messages .= '<span style="font-weight: bold; color: red;">'.$error.'</span><br>';
|
|
|
179 |
}
|
|
|
180 |
$messages .= '<br></div>';
|
|
|
181 |
} else {
|
|
|
182 |
exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE);
|
|
|
183 |
exec('sed -i '.escapeshellarg("s/^LDAP_SERVER=.*/LDAP_SERVER=$ldap_server/g").' '.CONF_FILE);
|
|
|
184 |
exec('sed -i '.escapeshellarg("s/^LDAP_BASE=.*/LDAP_BASE=$ldap_base_dn/g").' '.CONF_FILE);
|
2459 |
richard |
185 |
exec('sed -i '.escapeshellarg("s/^LDAP_UID=.*/LDAP_UID=$ldap_uid/g").' '.CONF_FILE);
|
2452 |
tom.houday |
186 |
exec('sed -i '.escapeshellarg("s/^LDAP_FILTER=.*/LDAP_FILTER=$ldap_base_filter/g").' '.CONF_FILE);
|
2451 |
tom.houday |
187 |
exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE);
|
|
|
188 |
exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE);
|
|
|
189 |
exec('sudo /usr/local/bin/alcasar-ldap.sh --on');
|
|
|
190 |
|
|
|
191 |
$messages .= '<div style="text-align: center"><br>';
|
2459 |
richard |
192 |
$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
|
2451 |
tom.houday |
193 |
$messages .= '<br></div>';
|
|
|
194 |
}
|
|
|
195 |
} else {
|
|
|
196 |
exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE);
|
|
|
197 |
exec('sudo /usr/local/bin/alcasar-ldap.sh --off');
|
|
|
198 |
|
|
|
199 |
$messages .= '<div style="text-align: center"><br>';
|
2459 |
richard |
200 |
$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>';
|
2451 |
tom.houday |
201 |
$messages .= '<br></div>';
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
// Reload configuration
|
|
|
205 |
$file_conf = fopen(CONF_FILE, 'r');
|
|
|
206 |
if (!$file_conf) {
|
|
|
207 |
exit('Error opening the file '.CONF_FILE);
|
|
|
208 |
}
|
|
|
209 |
while (!feof($file_conf)) {
|
|
|
210 |
$buffer = fgets($file_conf, 4096);
|
|
|
211 |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
|
|
|
212 |
$tmp = explode('=', $buffer, 2);
|
|
|
213 |
$conf[trim($tmp[0])] = trim($tmp[1]);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
fclose($file_conf);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
// LDAP configuration params
|
|
|
220 |
$ldap_status = ($conf['LDAP'] === 'on');
|
|
|
221 |
$ldap_server = $conf['LDAP_SERVER'];
|
2453 |
tom.houday |
222 |
$ldap_user = $conf['LDAP_USER'];
|
2451 |
tom.houday |
223 |
$ldap_password = $conf['LDAP_PASSWORD'];
|
2452 |
tom.houday |
224 |
$ldap_base_dn = $conf['LDAP_BASE'];
|
2459 |
richard |
225 |
$ldap_uid = $conf['LDAP_UID'];
|
2451 |
tom.houday |
226 |
$ldap_base_filter = $conf['LDAP_FILTER'];
|
|
|
227 |
|
2449 |
tom.houday |
228 |
// TODO : check LDAP PHP extension loaded?
|
|
|
229 |
// if (!extension_loaded('ldap')) {
|
|
|
230 |
// exit();
|
|
|
231 |
// }
|
|
|
232 |
|
|
|
233 |
$pos = strpos($ldap_server, '//');
|
|
|
234 |
if ($pos !== false) {
|
|
|
235 |
// TODO : useless?
|
|
|
236 |
$new_ldap_server = explode('//', $ldap_server); // pour discriminer le host et le protocole dans la notation "ldap://192.168.182.10" ou "ldaps://monldap.monentreperise.com"
|
658 |
stephane |
237 |
} else {
|
659 |
richard |
238 |
$new_ldap_server = $ldap_server;
|
658 |
stephane |
239 |
}
|
2449 |
tom.houday |
240 |
if ($ldap_status) {
|
2459 |
richard |
241 |
$serverCheckResult = ldap_checkServerConfig($new_ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_uid);
|
2449 |
tom.houday |
242 |
}
|
1395 |
richard |
243 |
|
2453 |
tom.houday |
244 |
// AJAX LDAP configuration checker
|
|
|
245 |
if (isset($_GET['conf_check'])) {
|
|
|
246 |
$response = [
|
|
|
247 |
'enable' => $ldap_status
|
|
|
248 |
];
|
|
|
249 |
if ($ldap_status || ($_SERVER['REQUEST_METHOD'] === 'POST')) {
|
|
|
250 |
$varErrors = [];
|
|
|
251 |
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
252 |
if (isset($_POST['ldap_server'])) $ldap_server = $_POST['ldap_server']; else array_push($varErrors, 'Variable error "ldap_server"');
|
|
|
253 |
if (isset($_POST['ldap_base_dn'])) $ldap_base_dn = $_POST['ldap_base_dn']; else array_push($varErrors, 'Variable error "ldap_base_dn"');
|
2459 |
richard |
254 |
if (isset($_POST['ldap_uid'])) $ldap_uid = $_POST['ldap_uid']; else array_push($varErrors, 'Variable error "ldap_uid"');
|
2453 |
tom.houday |
255 |
if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else array_push($varErrors, 'Variable error "ldap_base_filter"');
|
|
|
256 |
if (isset($_POST['ldap_user'])) $ldap_user = $_POST['ldap_user']; else array_push($varErrors, 'Variable error "ldap_user"');
|
|
|
257 |
if (isset($_POST['ldap_password'])) $ldap_password = $_POST['ldap_password']; else array_push($varErrors, 'Variable error "ldap_password"');
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
// Validation
|
|
|
261 |
if (isset($ldap_server)) {
|
|
|
262 |
if ((!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) && (preg_match('/^[a-zA-Z0-9-_.]+$/', $ldap_server))) {
|
|
|
263 |
$ldap_server = gethostbyname($ldap_server);
|
|
|
264 |
}
|
|
|
265 |
if (!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ldap_server)) {
|
|
|
266 |
array_push($varErrors, 'Invalid LDAP server IP');
|
|
|
267 |
}
|
|
|
268 |
}
|
|
|
269 |
|
2459 |
richard |
270 |
$response['result'] = (ldap_checkServerConfig($ldap_server, $ldap_user, $ldap_password, $ldap_base_dn, $ldap_uid) > 0);
|
2453 |
tom.houday |
271 |
|
|
|
272 |
if (!empty($varErrors)) {
|
|
|
273 |
$response['errors'] = $varErrors;
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
header('Content-Type: application/json');
|
|
|
278 |
echo json_encode($response);
|
|
|
279 |
exit();
|
|
|
280 |
}
|
|
|
281 |
|
620 |
stephane |
282 |
?>
|
2449 |
tom.houday |
283 |
<!DOCTYPE html>
|
|
|
284 |
<html>
|
|
|
285 |
<head>
|
|
|
286 |
<meta charset="UTF-8">
|
|
|
287 |
<title><?= $l_ldap_title ?></title>
|
|
|
288 |
<link type="text/css" href="/css/style.css" rel="stylesheet">
|
|
|
289 |
<link type="text/css" href="/css/acc.css" rel="stylesheet">
|
|
|
290 |
<link type="text/css" href="/css/ldap.css" rel="stylesheet">
|
|
|
291 |
<script>
|
|
|
292 |
function onLdapStatusChange() {
|
2459 |
richard |
293 |
var listToDisables = ['ldap_server', 'ldap_dn', 'ldap_uid', 'ldap_base_filter', 'ldap_user', 'ldap_password'];
|
318 |
richard |
294 |
|
2453 |
tom.houday |
295 |
if (document.getElementById('auth_enable').value === '1') {
|
2449 |
tom.houday |
296 |
for (var i=0; i<listToDisables.length; i++) {
|
|
|
297 |
document.getElementById(listToDisables[i]).style.backgroundColor = '#ffffff';
|
|
|
298 |
document.getElementById(listToDisables[i]).disabled = false;
|
|
|
299 |
}
|
|
|
300 |
} else {
|
|
|
301 |
for (var i=0; i<listToDisables.length; i++) {
|
|
|
302 |
document.getElementById(listToDisables[i]).style.backgroundColor = '#c0c0c0';
|
|
|
303 |
document.getElementById(listToDisables[i]).disabled = true;
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
}
|
2453 |
tom.houday |
307 |
|
|
|
308 |
function checkConfig() {
|
|
|
309 |
var ldap_config = {
|
|
|
310 |
ldap_status: (document.getElementById('auth_enable').value === '1'),
|
|
|
311 |
ldap_server: document.getElementById('ldap_server').value,
|
|
|
312 |
ldap_user: document.getElementById('ldap_user').value,
|
|
|
313 |
ldap_password: document.getElementById('ldap_password').value,
|
|
|
314 |
ldap_base_dn: document.getElementById('ldap_dn').value,
|
2459 |
richard |
315 |
ldap_uid: document.getElementById('ldap_uid').value,
|
2453 |
tom.houday |
316 |
ldap_base_filter: document.getElementById('ldap_base_filter').value
|
|
|
317 |
};
|
|
|
318 |
|
|
|
319 |
console.log(ldap_config);
|
|
|
320 |
|
|
|
321 |
var params = Object.keys(ldap_config).map( function (k) { return encodeURIComponent(k) + '=' + encodeURIComponent(ldap_config[k]) } ).join('&');
|
|
|
322 |
|
|
|
323 |
var xhr = new XMLHttpRequest();
|
|
|
324 |
xhr.onreadystatechange = function() {
|
|
|
325 |
if (this.readyState == 4) {
|
|
|
326 |
if (this.status == 200) {
|
|
|
327 |
var data = JSON.parse(this.responseText);
|
|
|
328 |
|
|
|
329 |
if (data.result === true) {
|
|
|
330 |
alert('Configuration valide');
|
|
|
331 |
} else {
|
|
|
332 |
alert('Configuration non valide');
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
if (typeof data.errors !== 'undefined') {
|
|
|
336 |
alert(data.errors.join("\n"));
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
console.log(data)
|
|
|
340 |
} else {
|
|
|
341 |
console.log(this.responseText)
|
|
|
342 |
}
|
|
|
343 |
}
|
|
|
344 |
};
|
|
|
345 |
xhr.open('POST', 'ldap.php?conf_check', true);
|
|
|
346 |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
347 |
xhr.send(params);
|
|
|
348 |
}
|
2449 |
tom.houday |
349 |
</script>
|
|
|
350 |
</head>
|
|
|
351 |
<body onLoad="onLdapStatusChange();">
|
|
|
352 |
<div class="panel">
|
|
|
353 |
<div class="panel-header"><?= $l_ldap_legend ?></div>
|
|
|
354 |
<div class="panel-body">
|
2451 |
tom.houday |
355 |
<form name="config_ldap" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
|
2449 |
tom.houday |
356 |
<fieldset>
|
|
|
357 |
<legend>
|
2451 |
tom.houday |
358 |
<?= $messages ?>
|
2449 |
tom.houday |
359 |
<?php if ($ldap_status): ?>
|
|
|
360 |
<div style="text-align: center"><br>
|
|
|
361 |
<?php if ($serverCheckResult === -2): ?>
|
2459 |
richard |
362 |
<span style="color: red"><?= $l_ldap_test_service_failed ?></span>
|
|
|
363 |
<?php elseif ($serverCheckResult === -1): ?>
|
|
|
364 |
<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
|
2449 |
tom.houday |
365 |
<span style="color: red"><?= $l_ldap_test_connection_failed ?></span>
|
|
|
366 |
<?php elseif ($serverCheckResult === 0): ?>
|
2459 |
richard |
367 |
<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
|
|
|
368 |
<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
|
2449 |
tom.houday |
369 |
<span style="color: red"><?= $l_ldap_test_bind_failed ?></span>
|
|
|
370 |
<?php elseif ($serverCheckResult === 1): ?>
|
2459 |
richard |
371 |
<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
|
|
|
372 |
<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
|
|
|
373 |
<span style="color: green"><?= $l_ldap_test_bind_ok ?></span><br>
|
|
|
374 |
<span style="color: red"><?= $l_ldap_test_dn_failed ?></span>
|
|
|
375 |
<?php elseif ($serverCheckResult > 1): ?>
|
|
|
376 |
<span style="color: green"><?= $l_ldap_test_service_ok ?></span><br>
|
|
|
377 |
<span style="color: green"><?= $l_ldap_test_connection_ok ?></span><br>
|
|
|
378 |
<span style="color: green"><?= $l_ldap_test_bind_ok ?></span><br>
|
|
|
379 |
<span style="color: green"><?= $l_ldap_test_dn_ok." ($serverCheckResult $l_ldap_entries)"; $ldap_can_be_enabled = True;?></span>
|
2449 |
tom.houday |
380 |
<?php else: ?>
|
|
|
381 |
<span><?= $l_ldap_error ?></span>
|
|
|
382 |
<?php endif ?>
|
|
|
383 |
<br><br>
|
|
|
384 |
</div>
|
|
|
385 |
<?php endif ?>
|
|
|
386 |
</legend>
|
|
|
387 |
<dl>
|
|
|
388 |
<dt>
|
|
|
389 |
<label for="auth_enable"><?= $l_ldap_auth_enable_label ?></label>
|
|
|
390 |
</dt>
|
|
|
391 |
<dd>
|
|
|
392 |
<select id="auth_enable" name="auth_enable" onchange="onLdapStatusChange();">
|
|
|
393 |
<option value="1"<?= ($ldap_status) ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option>
|
|
|
394 |
<option value="0"<?= (!$ldap_status) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option>
|
|
|
395 |
</select>
|
|
|
396 |
</dd>
|
|
|
397 |
</dl>
|
|
|
398 |
<dl>
|
|
|
399 |
<dt>
|
|
|
400 |
<label for="ldap_server"><?= $l_ldap_server_label ?></label><br>
|
|
|
401 |
<?= $l_ldap_server_text ?>
|
|
|
402 |
</dt>
|
|
|
403 |
<dd>
|
|
|
404 |
<input id="ldap_server" size="40" name="ldap_server" value="<?= htmlspecialchars($ldap_server) ?>">
|
|
|
405 |
</dd>
|
|
|
406 |
</dl>
|
|
|
407 |
<dl>
|
|
|
408 |
<dt>
|
|
|
409 |
<label for="ldap_dn"><?= $l_ldap_base_dn_label ?></label><br>
|
|
|
410 |
<?= $l_ldap_base_dn_text ?>
|
|
|
411 |
</dt>
|
|
|
412 |
<dd>
|
2452 |
tom.houday |
413 |
<input id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>">
|
2449 |
tom.houday |
414 |
</dd>
|
|
|
415 |
</dl>
|
|
|
416 |
<dl>
|
|
|
417 |
<dt>
|
2459 |
richard |
418 |
<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br>
|
|
|
419 |
<?= $l_ldap_uid_text ?>
|
2449 |
tom.houday |
420 |
</dt>
|
|
|
421 |
<dd>
|
2459 |
richard |
422 |
<input id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>">
|
2449 |
tom.houday |
423 |
</dd>
|
|
|
424 |
</dl>
|
|
|
425 |
<dl>
|
|
|
426 |
<dt>
|
|
|
427 |
<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br>
|
|
|
428 |
<?= $l_ldap_base_filter_text ?>
|
|
|
429 |
</dt>
|
|
|
430 |
<dd>
|
|
|
431 |
<input id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?= htmlspecialchars($ldap_base_filter) ?>">
|
|
|
432 |
</dd>
|
|
|
433 |
</dl>
|
|
|
434 |
<dl>
|
|
|
435 |
<dt>
|
|
|
436 |
<label for="ldap_user"><?= $l_ldap_user_label ?></label><br>
|
|
|
437 |
<?= $l_ldap_user_text ?>
|
|
|
438 |
</dt>
|
|
|
439 |
<dd>
|
2453 |
tom.houday |
440 |
<input id="ldap_user" size="40" name="ldap_user" value="<?= htmlspecialchars($ldap_user) ?>">
|
2449 |
tom.houday |
441 |
</dd>
|
|
|
442 |
</dl>
|
|
|
443 |
<dl>
|
|
|
444 |
<dt>
|
|
|
445 |
<label for="ldap_password"><?= $l_ldap_password_label ?></label><br>
|
|
|
446 |
<?= $l_ldap_password_text ?>
|
|
|
447 |
</dt>
|
|
|
448 |
<dd>
|
|
|
449 |
<input id="ldap_password" type="password" size="40" name="ldap_password" value="<?= htmlspecialchars($ldap_password) ?>">
|
|
|
450 |
</dd>
|
|
|
451 |
</dl>
|
|
|
452 |
<p>
|
|
|
453 |
<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit">
|
2459 |
richard |
454 |
<? if ($ldap_can_be_enabled === True) {echo "<input id=\"push_config\" value=\"$l_ldap_push_config\" name=\"push_config_button\">";}?>
|
2449 |
tom.houday |
455 |
</p>
|
|
|
456 |
</fieldset>
|
|
|
457 |
</form>
|
|
|
458 |
</div>
|
|
|
459 |
</div>
|
318 |
richard |
460 |
</body>
|
|
|
461 |
</html>
|