source: extensions/Ldap_Login/admin/configuration.php @ 28534

Last change on this file since 28534 was 28534, checked in by 22decembre, 10 years ago

add function to sync ldap and piwigo groups
ldap groups correspond to webmasters and admin roles

File size: 4.2 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $template;
5$template->set_filenames( array('plugin_admin_content' => dirname(__FILE__).'/configuration.tpl') );
6$template->assign(
7  array(
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',
10    ));
11
12$me = new Ldap();
13$me->load_config();
14$me->ldap_conn();
15//$me = get_plugin_data($plugin_id);
16
17$template->assign('HOST',       $me->config['host']);
18$template->assign('BASEDN',     $me->config['basedn']); // racine !
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']);
23$template->assign('PORT',       $me->config['port']);
24$template->assign('LD_ATTR',    $me->config['ld_attr']);
25$template->assign('LD_GROUP',   $me->config['ld_group']);
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']);
29$template->assign('WEBMASTERS_GROUP',   $me->config['webmasters_group']);
30$template->assign('ADMINS_GROUP',       $me->config['admins_group']);
31
32if (isset($_POST['save'])){
33        $me->config['host']      = $_POST['HOST'];
34        $me->config['basedn']    = $_POST['BASEDN'];
35        $me->config['usersbranch']    = $_POST['USERSBRANCH'];
36        $me->config['groupbranch']    = $_POST['GROUPBRANCH'];
37        $me->config['port']      = $_POST['PORT'];
38        $me->config['ld_attr']   = $_POST['LD_ATTR'];
39        $me->config['ld_group']   = $_POST['LD_GROUP'];
40        $me->config['ld_binddn'] = $_POST['LD_BINDDN'];
41        $me->config['ld_bindpw'] = $_POST['LD_BINDPW'];
42       
43        $me->config['webmasters_group'] = $_POST['WEBMASTERS_GROUP'];
44        $me->config['admins_group'] = $_POST['ADMINS_GROUP'];
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        }
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        }
63}
64
65// Save LDAP configuration
66if (isset($_POST['save'])){
67        $me->save_config();
68}
69
70// Check LDAP configuration
71if (isset($_POST['check_ldap'])){
72#$check = $me->ldap_name($_POST['USERNAME']);
73#$error = $me->check_ldap();
74
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                }
94        }
95        else {
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                }
112        }
113}
114
115$template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content');
116?>
Note: See TracBrowser for help on using the repository browser.