1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) STMicroelectronics, 2008. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* Originally written by Manuel Vacelet, 2008 |
6
|
|
|
* |
7
|
|
|
* This file is a part of Codendi. |
8
|
|
|
* |
9
|
|
|
* Codendi is free software; you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* Codendi is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with Codendi; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
require_once 'pre.php'; |
25
|
|
|
require_once dirname(__FILE__).'/../include/LDAP_ProjectGroupManager.class.php'; |
26
|
|
|
require_once 'www/project/admin/project_admin_utils.php'; |
27
|
|
|
|
28
|
|
|
// Import very long user group may takes very long time. |
29
|
|
|
ini_set('max_execution_time', 0); |
30
|
|
|
|
31
|
|
|
$request = HTTPRequest::instance(); |
32
|
|
|
|
33
|
|
|
// Get group id |
34
|
|
|
$vGroupId = new Valid_GroupId(); |
35
|
|
|
$vGroupId->required(); |
36
|
|
|
if(!$request->valid($vGroupId)) { |
37
|
|
|
exit_error($Language->getText('global','error'), 'No group_id'); |
38
|
|
|
} |
39
|
|
|
$groupId = $request->get('group_id'); |
40
|
|
|
|
41
|
|
|
// Must be a project admin |
42
|
|
|
session_require(array('group' => $groupId, 'admin_flags' => 'A')); |
43
|
|
|
|
44
|
|
|
// Ensure LDAP plugin is active |
45
|
|
|
$pluginManager = PluginManager::instance(); |
46
|
|
|
$ldapPlugin = $pluginManager->getPluginByName('ldap'); |
47
|
|
|
if (!$ldapPlugin || !$pluginManager->isPluginAvailable($ldapPlugin)) { |
48
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Check if user have choosen the preserve members option. |
52
|
|
|
$bindOption = LDAP_GroupManager::BIND_OPTION; |
53
|
|
|
if($request->exist('preserve_members') && $request->get('preserve_members') == 'on') { |
54
|
|
|
$bindOption = LDAP_GroupManager::PRESERVE_MEMBERS_OPTION; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Check if user has checked the Synchronization option. |
58
|
|
|
$synchro = LDAP_GroupManager::NO_SYNCHRONIZATION; |
59
|
|
|
if($request->exist('synchronize') && $request->get('synchronize') == 'on') { |
60
|
|
|
$synchro = LDAP_GroupManager::AUTO_SYNCHRONIZATION; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Get LDAP group name |
64
|
|
|
$vLdapGroup = new Valid_String('ldap_group'); |
65
|
|
|
$vLdapGroup->required(); |
66
|
|
|
if($request->isPost() && $request->valid($vLdapGroup)) { |
67
|
|
|
$ldapGroupManager = new LDAP_ProjectGroupManager($ldapPlugin->getLdap()); |
68
|
|
|
$ldapGroupManager->setId($groupId); |
69
|
|
|
$ldapGroupManager->setGroupName($request->get('ldap_group')); |
70
|
|
|
|
71
|
|
|
if($request->existAndNonEmpty('delete')) { |
72
|
|
|
// |
73
|
|
|
// Remove link between Project Members and LDAP Group |
74
|
|
|
// |
75
|
|
|
$ldapGroupManager->unbindFromBindLdap(); |
76
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
77
|
|
|
|
78
|
|
|
} elseif($request->existAndNonEmpty('update')) { |
79
|
|
|
// |
80
|
|
|
// Perform Project Members <-> LDAP Group synchro |
81
|
|
|
// |
82
|
|
|
$ldapGroupManager->bindWithLdap($bindOption, $synchro); |
83
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
84
|
|
|
|
85
|
|
|
} elseif($request->exist('cancel')) { |
86
|
|
|
// |
87
|
|
|
// Cancel operations |
88
|
|
|
// |
89
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
90
|
|
|
|
91
|
|
|
} else { |
92
|
|
|
// |
93
|
|
|
// Display to user what will be done with project members. |
94
|
|
|
// |
95
|
|
|
$toRemove = $ldapGroupManager->getUsersToBeRemoved($bindOption); |
96
|
|
|
$toAdd = $ldapGroupManager->getUsersToBeAdded($bindOption); |
97
|
|
|
$notImpacted = $ldapGroupManager->getUsersNotImpacted($bindOption); |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
if(is_array($toAdd)) { |
101
|
|
|
// Display |
102
|
|
|
$um = UserManager::instance(); |
103
|
|
|
$hp = Codendi_HTMLPurifier::instance(); |
104
|
|
|
|
105
|
|
|
project_admin_header(array('title' => $GLOBALS['Language']->getText('plugin_ldap','project_members_synchro_title'), 'group' => $groupId)); |
106
|
|
|
echo '<h1>'.$GLOBALS['Language']->getText('plugin_ldap','project_members_synchro_title').'</h1>'; |
107
|
|
|
|
108
|
|
|
echo '<p>'.$GLOBALS['Language']->getText('plugin_ldap', 'project_members_synchro_warning').'</p>'; |
109
|
|
|
echo '<p>'.$GLOBALS['Language']->getText('plugin_ldap', 'group_members_synchro_sumup', array(count($toRemove), count($toAdd), count($notImpacted))).'</p>'; |
110
|
|
|
|
111
|
|
|
echo '<table width="100%">'; |
112
|
|
|
echo '<tr><td width="50%" valign="top">'; |
113
|
|
|
|
114
|
|
|
$GLOBALS['HTML']->box1_top($GLOBALS['Language']->getText('plugin_ldap', 'group_members_synchro_to_remove', array(count($toRemove)))); |
115
|
|
|
echo '<ul>'; |
116
|
|
|
foreach ($toRemove as $userId) { |
|
|
|
|
117
|
|
|
if (($user = $um->getUserById($userId))) { |
118
|
|
|
echo '<li>'.$user->getRealName().' ('.$user->getUserName().')</li>'; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
echo '</ul>'; |
122
|
|
|
$GLOBALS['HTML']->box1_bottom(); |
123
|
|
|
|
124
|
|
|
echo '</td><td width="50%" valign="top">'; |
125
|
|
|
|
126
|
|
|
$GLOBALS['HTML']->box1_top($GLOBALS['Language']->getText('plugin_ldap', 'group_members_synchro_to_add', array(count($toAdd)))); |
127
|
|
|
echo '<ul>'; |
128
|
|
|
foreach ($toAdd as $userId) { |
129
|
|
|
if (($user = $um->getUserById($userId))) { |
130
|
|
|
echo '<li>'.$user->getRealName().' ('.$user->getUserName().')</li>'; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
echo '</ul>'; |
134
|
|
|
$GLOBALS['HTML']->box1_bottom(); |
135
|
|
|
|
136
|
|
|
echo '</tr></td>'; |
137
|
|
|
echo '<tr><td colspan="2" align="center">'; |
138
|
|
|
echo '<form method="post" action="?group_id='.$groupId.'">'; |
139
|
|
|
echo '<input type="hidden" name="ldap_group" value="'.$hp->purify($request->get('ldap_group')).'" />'; |
140
|
|
|
echo '<input type="hidden" name="confirm" value="yes" />'; |
141
|
|
|
if($bindOption == 'preserve_members') { |
142
|
|
|
echo '<input type="hidden" name="preserve_members" value="on" />'; |
143
|
|
|
} |
144
|
|
|
echo '<input type="submit" name="cancel" value="'.$GLOBALS['Language']->getText('global', 'btn_cancel').'" />'; |
145
|
|
|
echo '<input type="submit" name="update" value="'.$GLOBALS['Language']->getText('global', 'btn_update').'" />'; |
146
|
|
|
echo '</form>'; |
147
|
|
|
echo '</td></tr>'; |
148
|
|
|
echo '</table>'; |
149
|
|
|
|
150
|
|
|
project_admin_footer(array()); |
151
|
|
|
} else { |
152
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_ldap', 'invalid_ldap_group_name')); |
153
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} else { |
157
|
|
|
$GLOBALS['Response']->redirect('/project/admin/index.php?group_id='.$groupId); |
158
|
|
|
} |
159
|
|
|
?> |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.