[27036] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | global $template; |
---|
| 5 | $template->set_filenames( array('plugin_admin_content' => dirname(__FILE__).'/configuration.tpl') ); |
---|
| 6 | $template->assign( |
---|
| 7 | array( |
---|
[27284] | 8 | 'PLUGIN_ACTION' => get_root_url().'admin.php?page=plugin-Ldap_Login-configuration', |
---|
| 9 | 'PLUGIN_CHECK' => get_root_url().'admin.php?page=plugin-Ldap_Login-configuration', |
---|
[27036] | 10 | )); |
---|
| 11 | |
---|
| 12 | $me = new Ldap(); |
---|
| 13 | $me->load_config(); |
---|
[28534] | 14 | $me->ldap_conn(); |
---|
[27036] | 15 | //$me = get_plugin_data($plugin_id); |
---|
| 16 | |
---|
| 17 | $template->assign('HOST', $me->config['host']); |
---|
| 18 | $template->assign('BASEDN', $me->config['basedn']); // racine ! |
---|
[28534] | 19 | $template->assign('USERSBRANCH',$me->config['usersbranch']); |
---|
| 20 | $template->assign('GROUPBRANCH',$me->config['groupbranch']); |
---|
| 21 | $template->assign('LD_SEARCH_USERS',$me->config['ld_search_users']); |
---|
| 22 | $template->assign('LD_SEARCH_GROUPS',$me->config['ld_search_groups']); |
---|
[27036] | 23 | $template->assign('PORT', $me->config['port']); |
---|
| 24 | $template->assign('LD_ATTR', $me->config['ld_attr']); |
---|
[28534] | 25 | $template->assign('LD_GROUP', $me->config['ld_group']); |
---|
[27036] | 26 | $template->assign('LD_USE_SSL', $me->config['ld_use_ssl']); |
---|
| 27 | $template->assign('LD_BINDPW', $me->config['ld_bindpw']); |
---|
| 28 | $template->assign('LD_BINDDN', $me->config['ld_binddn']); |
---|
[28534] | 29 | $template->assign('WEBMASTERS_GROUP', $me->config['webmasters_group']); |
---|
| 30 | $template->assign('ADMINS_GROUP', $me->config['admins_group']); |
---|
[27036] | 31 | |
---|
| 32 | if (isset($_POST['save'])){ |
---|
| 33 | $me->config['host'] = $_POST['HOST']; |
---|
| 34 | $me->config['basedn'] = $_POST['BASEDN']; |
---|
[28534] | 35 | $me->config['usersbranch'] = $_POST['USERSBRANCH']; |
---|
| 36 | $me->config['groupbranch'] = $_POST['GROUPBRANCH']; |
---|
[27036] | 37 | $me->config['port'] = $_POST['PORT']; |
---|
| 38 | $me->config['ld_attr'] = $_POST['LD_ATTR']; |
---|
[28534] | 39 | $me->config['ld_group'] = $_POST['LD_GROUP']; |
---|
[27036] | 40 | $me->config['ld_binddn'] = $_POST['LD_BINDDN']; |
---|
| 41 | $me->config['ld_bindpw'] = $_POST['LD_BINDPW']; |
---|
[28534] | 42 | |
---|
| 43 | $me->config['webmasters_group'] = $_POST['WEBMASTERS_GROUP']; |
---|
| 44 | $me->config['admins_group'] = $_POST['ADMINS_GROUP']; |
---|
[27036] | 45 | |
---|
| 46 | if (isset($_POST['LD_USE_SSL'])){ |
---|
| 47 | $me->config['ld_use_ssl'] = True; |
---|
| 48 | } else { |
---|
| 49 | $me->config['ld_use_ssl'] = False; |
---|
| 50 | } |
---|
[28534] | 51 | |
---|
| 52 | if (isset($_POST['LD_SEARCH_GROUPS'])){ |
---|
| 53 | $me->config['ld_search_groups'] = True; |
---|
| 54 | } else { |
---|
| 55 | $me->config['ld_search_groups'] = False; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | if (isset($_POST['LD_SEARCH_USERS'])){ |
---|
| 59 | $me->config['ld_search_users'] = True; |
---|
| 60 | } else { |
---|
| 61 | $me->config['ld_search_users'] = False; |
---|
| 62 | } |
---|
[27036] | 63 | } |
---|
| 64 | |
---|
| 65 | // Save LDAP configuration |
---|
| 66 | if (isset($_POST['save'])){ |
---|
| 67 | $me->save_config(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | // Check LDAP configuration |
---|
| 71 | if (isset($_POST['check_ldap'])){ |
---|
[28534] | 72 | #$check = $me->ldap_name($_POST['USERNAME']); |
---|
| 73 | #$error = $me->check_ldap(); |
---|
[27036] | 74 | |
---|
[28534] | 75 | if ($me->config['users_group']) { |
---|
| 76 | if ($me->user_membership($_POST['USERNAME'],$me->ldap_group($me->config['users_group']))) { |
---|
| 77 | if ($me->ldap_bind_as($_POST['USERNAME'],$_POST['PASSWORD'])){ |
---|
| 78 | // search groups |
---|
| 79 | $group_query = 'SELECT name, id FROM '.GROUPS_TABLE.';'; |
---|
| 80 | $groups = pwg_query($group_query); |
---|
| 81 | $sentence = ''; |
---|
| 82 | |
---|
| 83 | foreach($groups as $group) { |
---|
| 84 | if($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) { |
---|
| 85 | $sentence = $sentence . ', '.$group['name']; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | $template->assign('LD_CHECK_LDAP','<p style="color:green;">Configuration LDAP OK : '.$_POST['USERNAME'].' is in users'.$sentence.' group(s) and can auth. He is a '.$me->ldap_status($_POST['USERNAME']).' user according to the plugin.</p>'); |
---|
| 89 | } |
---|
| 90 | else { |
---|
| 91 | $template->assign('LD_CHECK_LDAP','<p style="color:red;">Error : test '.$me->config['uri'].' '.$me->ldap_name($_POST['USERNAME']).'</p>'); |
---|
| 92 | } |
---|
| 93 | } |
---|
[27036] | 94 | } |
---|
| 95 | else { |
---|
[28534] | 96 | if ($me->ldap_bind_as($_POST['USERNAME'],$_POST['PASSWORD'])){ |
---|
| 97 | // search groups |
---|
| 98 | $group_query = 'SELECT name, id FROM '.GROUPS_TABLE.';'; |
---|
| 99 | $groups = pwg_query($group_query); |
---|
| 100 | $sentence = ''; |
---|
| 101 | |
---|
| 102 | foreach($groups as $group) { |
---|
| 103 | if($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) { |
---|
| 104 | $sentence = $sentence . ', '.$group['name']; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | $template->assign('LD_CHECK_LDAP','<p style="color:green;">Configuration LDAP OK : '.$_POST['USERNAME'].' is in group(s) '.$sentence.' and can auth. He is a '.$me->ldap_status($_POST['USERNAME']).' user according to the plugin.</p>'); |
---|
| 108 | } |
---|
| 109 | else { |
---|
| 110 | $template->assign('LD_CHECK_LDAP','<p style="color:red;">Error : test '.$me->config['uri'].' '.$me->ldap_name($_POST['USERNAME']).'</p>'); |
---|
| 111 | } |
---|
[27036] | 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 116 | ?> |
---|