/[drupal]/contributions/modules/ldap_integration/ldapauth.admin.inc
ViewVC logotype

Contents of /contributions/modules/ldap_integration/ldapauth.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Tue Oct 27 14:29:16 2009 UTC (4 weeks, 1 day ago) by miglius
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA2, HEAD
Changes since 1.5: +56 -20 lines
File MIME type: text/x-php
ldap_integration: fixed database table indexes, #612956 by lkeller
1 <?php
2 // $Id: ldapauth.admin.inc,v 1.5 2009/07/28 14:03:05 miglius Exp $
3
4 /**
5 * @file
6 * Module admin page callbacks.
7 */
8
9 //////////////////////////////////////////////////////////////////////////////
10 // ldapauth settings
11
12 /**
13 * Implements the settings page.
14 *
15 * @return
16 * The form structure.
17 */
18 function ldapauth_admin_settings() {
19 $options_login_process = array(
20 LDAPAUTH_AUTH_MIXED => t('Mixed mode. The LDAP authentication is performed only if Drupal authentication fails'),
21 LDAPAUTH_AUTH_EXCLUSIVED => t('LDAP directory only')
22 );
23 $options_login_conflict = array(
24 LDAPAUTH_CONFLICT_LOG => t('Disallow login and log the conflict'),
25 LDAPAUTH_CONFLICT_RESOLVE => t('Associate local account with the LDAP entry')
26 );
27
28 $form['system-options'] = array(
29 '#type' => 'fieldset',
30 '#title' => t('Authentication mode'),
31 '#description' => t('<strong>NOTE:</strong> These settings have no effect on Drupal user with uid 1. The admin account never uses LDAP.'),
32 '#collapsible' => TRUE,
33 '#collapsed' => FALSE,
34 );
35 $form['system-options']['ldapauth_login_process'] = array(
36 '#type' => 'radios',
37 '#title' => t('Choose authentication mode'),
38 '#description' => t('Pick the mode based on the types of user accounts and other configuration decisions. If <i>LDAP directory only</i> option is activated some UI modications will be applied.'),
39 '#default_value' => LDAPAUTH_LOGIN_PROCESS,
40 '#options' => $options_login_process,
41 '#required' => TRUE,
42 );
43 $form['system-options']['ldapauth_login_conflict'] = array(
44 '#type' => 'radios',
45 '#title' => t('Choose user conflict resolve procedure'),
46 '#description' => t('Pick what should be done if the local Drupal account already exists with the same login name.'),
47 '#default_value' => LDAPAUTH_LOGIN_CONFLICT,
48 '#options' => $options_login_conflict,
49 '#required' => TRUE,
50 );
51
52 $form['security-options'] = array(
53 '#type' => 'fieldset',
54 '#title' => t('Security Options'),
55 '#collapsible' => TRUE,
56 '#collapsed' => TRUE,
57 );
58 $form['security-options']['ldapauth_forget_passwords'] = array(
59 '#type' => 'checkbox',
60 '#title' => t('Do not store users\' passwords during sessions'),
61 '#default_value' => LDAPAUTH_FORGET_PASSWORDS,
62 '#description' => t('<p>If you use the <strong>ldapdata</strong> module and want to allow users to modify their LDAP attributes, you have two options:</p><ul><li>Setup a special ldap manager DN that has (limited) permissions to edit the requisite LDAP records - using this method means Drupal\'s built in password reset will work;</li> <li>or allow this module to store the user\'s LDAP password, in clear text, during the session;</li></ul><p>Physically, these passwords are stored in the Drupal\'s session table in clear text. This is not ideal and is not the recomended configuration.</p><p>Unless you need to use the latter configuration, leave this checked.</p>'),
63 );
64 $form['security-options']['ldapauth_sync_passwords'] = array(
65 '#type' => 'checkbox',
66 '#title' => t('Sync LDAP password with the Drupal password'),
67 '#default_value' => LDAPAUTH_SYNC_PASSWORDS,
68 '#description' => t('If checked, then LDAP and Drupal passwords will be syncronized. This might be useful if some other modules need to authenticate against the user password hash stored in Drupal and works only in Mixed mode. It might introduce security issues in the Mixed mode since after deletion of the LDAP account user still be able to login to Drupal with his password. If unsure, leave this unchecked.'),
69 );
70
71 $form['ldap-ui'] = array(
72 '#type' => 'fieldset',
73 '#title' => t('LDAP UI Options'),
74 '#description' => t('<p>Alters LDAP users\' interface only, though admin accounts can still access email and password fields of LDAP users regardless of selections. Does not effect non-LDAP authenticated accounts. </p>'),
75 '#collapsible' => TRUE,
76 '#collapsed' => TRUE,
77 );
78 $form['ldap-ui']['ldapauth_disable_pass_change'] = array(
79 '#type' => 'checkbox',
80 '#title' => t('Remove password change fields from user edit form'),
81 '#default_value' => LDAPAUTH_DISABLE_PASS_CHANGE,
82 '#description' => t('<strong>NOTE:</strong> Request new password feature will be disabled for all users even for the user with uid 1.'),
83 );
84 $options_email_field = array(
85 LDAPAUTH_EMAIL_FIELD_NO => t('Do nothing'),
86 LDAPAUTH_EMAIL_FIELD_REMOVE => t('Remove email field from form'),
87 LDAPAUTH_EMAIL_FIELD_DISABLE => t('Disable email field on form'),
88 );
89 $form['ldap-ui']['ldapauth_alter_email_field'] = array(
90 '#type' => 'radios',
91 '#title' => t('Alter email field on user edit form'),
92 '#description' => t('Remove or disable email field from user edit form for LDAP authenticated users.'),
93 '#default_value' => LDAPAUTH_ALTER_EMAIL_FIELD,
94 '#options' => $options_email_field,
95 '#required' => TRUE,
96 );
97
98 $form['submit'] = array(
99 '#type' => 'submit',
100 '#value' => t('Save configuration'),
101 );
102 $form['reset'] = array(
103 '#type' => 'submit',
104 '#value' => t('Reset to defaults'),
105 );
106 return $form;
107 }
108
109 /**
110 * Submit hook for the settings form.
111 */
112 function ldapauth_admin_settings_submit($form, &$form_state) {
113 $op = $form_state['clicked_button']['#value'];
114 $values = $form_state['values'];
115 switch ($op) {
116 case t('Save configuration'):
117 variable_set('ldapauth_login_process', $values['ldapauth_login_process']);
118 variable_set('ldapauth_login_conflict', $values['ldapauth_login_conflict']);
119 variable_set('ldapauth_forget_passwords', $values['ldapauth_forget_passwords']);
120 variable_set('ldapauth_sync_passwords', $values['ldapauth_sync_passwords']);
121 variable_set('ldapauth_disable_pass_change', $values['ldapauth_disable_pass_change']);
122 variable_set('ldapauth_alter_email_field', $values['ldapauth_alter_email_field']);
123
124 drupal_set_message(t('The configuration options have been saved.'));
125 break;
126 case t('Reset to defaults'):
127 variable_del('ldapauth_login_process');
128 variable_del('ldapauth_login_conflict');
129 variable_del('ldapauth_forget_passwords');
130 variable_del('ldapauth_sync_passwords');
131 variable_del('ldapauth_disable_pass_change');
132 variable_del('ldapauth_alter_email_field');
133
134 drupal_set_message(t('The configuration options have been reset to their default values.'));
135 break;
136 }
137
138 // Rebuild the menu router.
139 menu_rebuild();
140 }
141
142 /**
143 * Implements the LDAP servers list.
144 *
145 * @return
146 * The HTML table with the servers list.
147 */
148 function ldapauth_admin_list() {
149 $form['list'] = array();
150 $result = db_query("SELECT sid, name, status, weight FROM {ldapauth} ORDER BY weight");
151 while ($row = db_fetch_object($result)) {
152 $form['list'][$row->sid] = array(
153 'name' => array('#value' => $row->name),
154 'status' => array('#value' => $row->status),
155 'weight' => array(
156 '#type' => 'weight',
157 '#name' => 'sid_'. $row->sid .'_weight',
158 '#delta' => 10,
159 '#default_value' => $row->weight,
160 ),
161 );
162 }
163
164 $form['submit'] = array(
165 '#type' => 'submit',
166 '#value' => t('Save'),
167 );
168
169 return $form;
170 }
171
172 /**
173 * Submit hook for the servers list form.
174 */
175 function ldapauth_admin_list_submit($form, &$form_state) {
176 $op = $form_state['clicked_button']['#value'];
177 switch ($op) {
178 case t('Save'):
179 foreach ($form_state['clicked_button']['#post'] as $name => $val) {
180 if (preg_match('/^sid_.*_weight/', $name)) {
181 $sid = preg_replace(array('/^sid_/', '/_weight$/'), array('', ''), $name);
182 db_query("UPDATE {ldapauth} SET weight = %d WHERE sid = %d", $val, $sid);
183 }
184 }
185 break;
186 }
187 }
188
189 /**
190 * Implements the LDAP server edit page.
191 *
192 * @param $form_state
193 * A form state array.
194 * @param $op
195 * An operatin - add or edit.
196 * @param $sid
197 * A LDAP server ID.
198 *
199 * @return
200 * The form structure.
201 */
202 function ldapauth_admin_form(&$form_state, $op = NULL, $sid = NULL) {
203 drupal_add_js(drupal_get_path('module', 'ldapauth') .'/ldapauth.admin.js');
204
205 if ($op == "edit" && $sid) {
206 $edit = db_fetch_array(db_query("SELECT * FROM {ldapauth} WHERE sid = %d", $sid));
207 $form['sid'] = array(
208 '#type' => 'hidden',
209 '#value' => $sid,
210 );
211 }
212 else {
213 $edit = array(
214 'name' => '',
215 'server' => '',
216 'port' => '389',
217 'tls' => 0,
218 'encrypted' => 0,
219 'basedn' => '',
220 'user_attr' => LDAPAUTH_DEFAULT_USER_ATTR,
221 'mail_attr' => LDAPAUTH_DEFAULT_MAIL_ATTR,
222 'binddn' => '',
223 'bindpw' => FALSE,
224 'login_php' => '',
225 'filter_php' => '',
226 );
227 }
228
229 $form['server-settings'] = array(
230 '#type' => 'fieldset',
231 '#title' => t('Server settings'),
232 '#collapsible' => TRUE,
233 '#collapsed' => FALSE,
234 );
235 $form['server-settings']['name'] = array(
236 '#type' => 'textfield',
237 '#title' => t('Name'),
238 '#default_value' => $edit['name'],
239 '#description' => t('Choose a <em><strong>unique</strong></em> name for this server configuration.'),
240 '#size' => 50,
241 '#maxlength' => 255,
242 '#required' => TRUE,
243 );
244 $form['server-settings']['server'] = array(
245 '#type' => 'textfield',
246 '#title' => t('LDAP server'),
247 '#default_value' => $edit['server'],
248 '#size' => 50,
249 '#maxlength' => 255,
250 '#description' => t('The domain name or IP address of your LDAP Server.'),
251 '#required' => TRUE,
252 );
253 $form['server-settings']['port'] = array(
254 '#type' => 'textfield',
255 '#title' => t('LDAP port'),
256 '#default_value' => $edit['port'],
257 '#size' => 5,
258 '#maxlength' => 5,
259 '#description' => t('The TCP/IP port on the above server which accepts LDAP connections. Must be an integer.'),
260 );
261 $form['server-settings']['tls'] = array(
262 '#type' => 'checkbox',
263 '#title' => t('Use Start-TLS'),
264 '#default_value' => $edit['tls'],
265 '#description' => t('Secure the connection between the Drupal and the LDAP servers using TLS.<br /><em>Note: To use START-TLS, you must set the LDAP Port to 389.</em>'),
266 );
267 $form['server-settings']['encrypted'] = array(
268 '#type' => 'checkbox',
269 '#title' => t('Store passwords in encrypted form'),
270 '#default_value' => $edit['encrypted'],
271 '#description' => t('Secure the password in LDAP by storing it MD5 encrypted (use with care, as some LDAP directories may do this automatically, what would cause logins problems).'),
272 );
273
274 $form['login-procedure'] = array(
275 '#type' => 'fieldset',
276 '#title' => t('Login procedure'),
277 '#collapsible' => TRUE,
278 '#collapsed' => FALSE,
279 );
280 $form['login-procedure']['basedn'] = array(
281 '#type' => 'textarea',
282 '#title' => t('Base DNs'),
283 '#default_value' => $edit['basedn'],
284 '#cols' => 50,
285 '#rows' => 6,
286 '#description' => t('Base DNs for users. Enter one per line in case you need several of them.'),
287 );
288 $form['login-procedure']['user_attr'] = array(
289 '#type' => 'textfield',
290 '#title' => t('UserName attribute'),
291 '#default_value' => $edit['user_attr'],
292 '#size' => 30,
293 '#maxlength' => 255,
294 '#description' => t('The attribute that holds the users\' login name. (eg. <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">cn</em> for eDir or <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">sAMAccountName</em> for Active Directory).'),
295 );
296 $form['login-procedure']['mail_attr'] = array(
297 '#type' => 'textfield',
298 '#title' => t('Email attribute'),
299 '#default_value' => $edit['mail_attr'],
300 '#size' => 30,
301 '#maxlength' => 255,
302 '#description' => t('The attribute that holds the users\' email address. (eg. <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">mail</em>).'),
303 );
304 $form['login-procedure']['login_php'] = array(
305 '#type' => 'textarea',
306 '#title' => t('PHP to transform login name'),
307 '#default_value' => $edit['login_php'],
308 '#cols' => 25,
309 '#rows' => 5,
310 '#description' => t('Enter PHP to transform login name before it is sent to LDAP for authentication. Careful, bad PHP code here will break your site. If left empty, no name transformation will be done. Change following example code to enable transformation:<br /><code>return $name;</code>'),
311 );
312 $form['login-procedure']['filter_php'] = array(
313 '#type' => 'textarea',
314 '#title' => t('PHP to filter users based on their LDAP data'),
315 '#default_value' => $edit['filter_php'],
316 '#cols' => 25,
317 '#rows' => 5,
318 '#description' => t('Enter PHP to filter users which are allowed to login based on their LDAP data. Careful, bad PHP code here will break your site. If left empty, no filtering will be done. The code should return TRUE to allow authentication. Following example shows how to disallow users without their homeDirectory set:<br /><code>return isset($ldap[\'homeDirectory\']) && isset($ldap[\'homedirectory\'][0]);</code>'),
319 );
320
321 $form['advanced'] = array(
322 '#type' => 'fieldset',
323 '#title' => t('Advanced configuration'),
324 '#description' => t('<p>The process of authentication starts by establishing an anonymous connection to the LDAP directory and looking up for the user on it. Once this user is found, LDAP authentication is performed on them.</p><p>However, some LDAP configurations (specially common in <strong>Active Directory</strong> setups) restrict anonymous searches.</p><p>If your LDAP setup does not allow anonymous searches, or these are restricted in such a way that login names for users cannot be retrieved as a result of them, then you have to specify here a DN//password pair that will be used for these searches.</p><p>For security reasons, this pair should belong to an LDAP account with stripped down permissions.</p>'),
325 '#collapsible' => TRUE,
326 '#collapsed' => FALSE,
327 );
328 if (!$edit['bindpw']) {
329 $form['advanced']['binddn'] = array(
330 '#type' => 'textfield',
331 '#title' => t('DN for non-anonymous search'),
332 '#default_value' => $edit['binddn'],
333 '#size' => 50,
334 '#maxlength' => 255,
335 );
336 $form['advanced']['bindpw'] = array(
337 '#type' => 'password',
338 '#title' => t('Password for non-anonymous search'),
339 '#size' => 12,
340 '#maxlength' => 255,
341 );
342 }
343 else {
344 $form['advanced']['binddn'] = array(
345 '#type' => 'item',
346 '#title' => t('DN for non-anonymous search'),
347 '#value' => $edit['binddn'],
348 );
349 // Give an option to clear the password.
350 $form['advanced']['bindpw_clear'] = array(
351 '#type' => 'checkbox',
352 '#title' => t('Clear current password and change DN'),
353 '#default_value' => FALSE,
354 );
355 }
356 $form['advanced']['test'] = array(
357 '#type' => 'submit',
358 '#value' => t('Test'),
359 '#suffix' => '<div id="test-spinner" style="display: none;">'. theme_image(drupal_get_path('module', 'ldapauth') .'/images/spinner.gif') .'</div><div id="test-message" class="messages" style="display: none;"></div>',
360 );
361
362 $form['submit'] = array(
363 '#type' => 'submit',
364 '#value' => t('Save configuration'),
365 );
366
367 return $form;
368 }
369
370 /**
371 * Validate hook for the LDAP server form.
372 */
373 function ldapauth_admin_form_validate($form, &$form_state) {
374 $values = $form_state['values'];
375
376 if (!isset($values['sid'])) {
377 if (db_fetch_object(db_query("SELECT name FROM {ldapauth} WHERE name = '%s'", $values['name']))) {
378 form_set_error('name', t('An LDAP config with the name %name already exists.', array('%name' => $values['name'])));
379 }
380 }
381 if (!is_numeric($values['port'])) {
382 form_set_error('port', t('The TCP/IP port must be an integer.'));
383 }
384 }
385
386 /**
387 * Submit hook for the LDAP server form.
388 */
389 function ldapauth_admin_form_submit($form, &$form_state) {
390 $op = $form_state['clicked_button']['#value'];
391 $values = $form_state['values'];
392 switch ($op) {
393 case t('Save configuration'):
394 if (!isset($values['sid'])) {
395 db_query("INSERT INTO {ldapauth} (name, status, server, port, tls, encrypted, basedn, user_attr, mail_attr, binddn, bindpw, login_php, filter_php) VALUES ('%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $values['name'], 1, $values['server'], $values['port'], $values['tls'], $values['encrypted'], $values['basedn'], trim($values['user_attr']), trim($values['mail_attr']), $values['binddn'], $values['bindpw'], trim($values['login_php']), trim($values['filter_php']));
396 drupal_set_message(t('LDAP configuration %name has been added.', array('%name' => $values['name'])));
397 watchdog('ldapauth', 'LDAP configuration %name has been added.', array('%name' => $values['name']));
398 }
399 else {
400 if (isset($values['bindpw_clear'])) {
401 db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = %d, tls = %d, encrypted = %d, basedn = '%s', user_attr = '%s', mail_attr = '%s', login_php = '%s', filter_php = '%s' WHERE sid = %d", $values['name'], $values['server'], $values['port'], $values['tls'], $values['encrypted'], $values['basedn'], trim($values['user_attr']), trim($values['mail_attr']), trim($values['login_php']), trim($values['filter_php']), $values['sid']);
402 if ($values['bindpw_clear']) {
403 db_query("UPDATE {ldapauth} SET bindpw = '' WHERE sid = %d", $values['sid']);
404 }
405 }
406 else {
407 db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = %d, tls = %d, encrypted = %d, basedn = '%s', user_attr = '%s', mail_attr = '%s', binddn = '%s', bindpw = '%s', login_php = '%s', filter_php = '%s' WHERE sid = %d", $values['name'], $values['server'], $values['port'], $values['tls'], $values['encrypted'], $values['basedn'], trim($values['user_attr']), trim($values['mail_attr']), $values['binddn'], $values['bindpw'], trim($values['login_php']), trim($values['filter_php']), $values['sid']);
408 }
409 drupal_set_message(t('LDAP Configuration %name has been updated.', array('%name' => $values['name'])));
410 watchdog('ldapauth', 'LDAP Configuration %name has been updated.', array('%name' => $values['name']));
411 }
412
413 $form_state['redirect'] = 'admin/settings/ldap/ldapauth/list';
414 break;
415 case t('Test'):
416 global $_ldapauth_ldap;
417 if (isset($values['sid']) && _ldapauth_init($values['sid'])) {
418 // Try to authenticate.
419 $dn = $_ldapauth_ldap->getOption('binddn');
420 $pass = $_ldapauth_ldap->getOption('bindpw');
421 if (!$_ldapauth_ldap->connect($dn, $pass)) {
422 drupal_set_message(t('Authentication with the LDAP server for the dn %dn and saved password failed.', array('%dn' => $dn)), 'error');
423 }
424 else {
425 drupal_set_message(t('Authentication with the LDAP server for the dn %dn and saved password succeeded.', array('%dn' => $dn)));
426 }
427 }
428 else {
429 drupal_set_message(t('Cannot load server settings. Please save configuration first.'), 'error');
430 }
431 break;
432 }
433 }
434
435 /**
436 * De-activates the LDAP server.
437 *
438 * @param $form_State
439 * A form_state array.
440 * @param $sid
441 * A LDAP server ID.
442 *
443 * @return
444 * Form array.
445 */
446 function ldapauth_admin_deactivate(&$form_state, $sid) {
447 if (is_numeric($sid) && ($name = db_result(db_query("SELECT name from {ldapauth} WHERE sid = %d", $sid)))) {
448 $form['sid'] = array('#type' => 'hidden', '#value' => $sid);
449
450 return confirm_form($form, t('Are you sure you want to de-activate the server %name?', array('%name' => $name)), 'admin/settings/ldap/ldapauth/list', '', t('De-activate'), t('Cancel'));
451 }
452 else {
453 drupal_not_found();
454 exit;
455 }
456 }
457
458 /**
459 * De-activates the LDAP server.
460 *
461 * @return
462 */
463 function ldapauth_admin_deactivate_submit($form, &$form_state) {
464 $sid = $form_state['values']['sid'];
465 $result = db_query("SELECT name from {ldapauth} WHERE sid = %d", $sid);
466 if ($row = db_fetch_object($result)) {
467 db_query("UPDATE {ldapauth} SET status = '0' WHERE sid = %d", $sid);
468 drupal_set_message(t('LDAP Configuration %name has been de-activated.', array('%name' => $row->name)));
469 watchdog('ldapauth', 'LDAP server %name was de-activated.', array('%name' => $row->name));
470 }
471 drupal_goto('admin/settings/ldap/ldapauth/list');
472 }
473
474 /**
475 * Activates the LDAP server.
476 *
477 * @param $form_State
478 * A form_state array.
479 * @param $sid
480 * A LDAP server ID.
481 *
482 * @return
483 * Form array.
484 */
485 function ldapauth_admin_activate(&$form_state, $sid) {
486 if (is_numeric($sid) && ($name = db_result(db_query("SELECT name from {ldapauth} WHERE sid = %d", $sid)))) {
487 $form['sid'] = array('#type' => 'hidden', '#value' => $sid);
488
489 return confirm_form($form, t('Are you sure you want to activate the server %name?', array('%name' => $name)), 'admin/settings/ldap/ldapauth/list', '', t('Activate'), t('Cancel'));
490 }
491 else {
492 drupal_not_found();
493 exit;
494 }
495 }
496
497 /**
498 * Activates the LDAP server.
499 *
500 * @return
501 */
502 function ldapauth_admin_activate_submit($form, &$form_state) {
503 $sid = $form_state['values']['sid'];
504 $result = db_query("SELECT name from {ldapauth} WHERE sid = %d", $sid);
505 if ($row = db_fetch_object($result)) {
506 db_query("UPDATE {ldapauth} SET status = '1' WHERE sid = %d", $sid);
507 drupal_set_message(t('LDAP Configuration %name has been activated.', array('%name' => $row->name)));
508 watchdog('ldapauth', 'LDAP server %name was activated.', array('%name' => $row->name));
509 }
510 drupal_goto('admin/settings/ldap/ldapauth/list');
511 }
512
513 /**
514 * Implements the LDAP server delete page.
515 *
516 * @param $form_state
517 * A form state array.
518 * @param $sid
519 * A LDAP server ID.
520 *
521 * @return
522 * The form structure.
523 */
524 function ldapauth_admin_delete(&$form_state, $sid) {
525 if (is_numeric($sid) && ($name = db_result(db_query("SELECT name from {ldapauth} WHERE sid = %d", $sid)))) {
526 $form = array(
527 'sid' => array('#type' => 'hidden', '#value' => $sid),
528 'name' => array('#type' => 'hidden', '#value' => $name),
529 );
530
531 return confirm_form($form, t('Are you sure you want to delete the LDAP server named %name?', array('%name' => $name)), 'admin/settings/ldap/ldapauth/list', NULL, t('Delete'), t('Cancel'));
532 }
533 else {
534 drupal_not_found();
535 exit;
536 }
537 }
538
539 /**
540 * Submit hook for the LDAP server delete page.
541 */
542 function ldapauth_admin_delete_submit($form, &$form_state) {
543 $values = $form_state['values'];
544 if ($values['confirm'] && $values['sid']) {
545 db_query("DELETE FROM {ldapauth} WHERE sid = %d", $values['sid']);
546 drupal_set_message(t('LDAP Configuration %name has been deleted.', array('%name' => $values['name'])));
547 watchdog('ldapauth', 'LDAP Configuration %name has been deleted.', array('%name' => $values['name']));
548 }
549 drupal_goto('admin/settings/ldap/ldapauth/list');
550 }
551
552 /**
553 * Implements the LDAP admin page.
554 *
555 * @return
556 * The themed HTML page.
557 */
558 function ldapauth_admin_menu_block_page() {
559 return theme('admin_block_content', system_admin_menu_block(menu_get_item()));
560 }
561
562 /**
563 * Implements the AJAX server test.
564 *
565 * @param $sid
566 * LDAP server ID.
567 *
568 * @return
569 * The JSON data.
570 */
571 function _ldapauth_ajax_test($sid) {
572 global $_ldapauth_ldap;
573
574 if (!is_numeric($sid)) {
575 return;
576 }
577
578 _ldapauth_init($sid);
579
580 if ($_POST['bindpw_clear'] == 'undefined') {
581 $binddn = $_POST['binddn'];
582 $bindpw = $_POST['bindpw'];
583 }
584 else {
585 $binddn = $_ldapauth_ldap->getOption('binddn');
586 $bindpw = $_ldapauth_ldap->getOption('bindpw');
587 }
588
589 drupal_json($_ldapauth_ldap->connect($binddn, $bindpw) ? array('status' => 1, 'message' => t('Authentication with the LDAP server succeeded.')) : array('status' => 0, 'message' => t('Authentication with the LDAP server failed.')));
590 exit;
591 }
592

  ViewVC Help
Powered by ViewVC 1.1.2