/
Acl.php
217 lines (185 loc) · 6.95 KB
/
Acl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Copyright 2012-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2012-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
/**
* Special prefs handling for the 'aclmanagement' preference.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2012-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Prefs_Special_Acl implements Horde_Core_Prefs_Ui_Special
{
/**
*/
public function init(Horde_Core_Prefs_Ui $ui)
{
}
/**
*/
public function display(Horde_Core_Prefs_Ui $ui)
{
global $injector, $notification, $page_output, $prefs;
if ($prefs->isLocked('acl')) {
return;
}
$page_output->addScriptFile('prefs/acl.js');
$acl = $injector->getInstance('IMP_Imap_Acl');
$mbox = isset($ui->vars->mbox)
? IMP_Mailbox::formFrom($ui->vars->mbox)
: IMP_Mailbox::get('INBOX');
try {
$curr_acl = $acl->getACL($mbox);
if (!($canEdit = $acl->canEdit($mbox))) {
$notification->push(_("You do not have permission to change access to this mailbox."), 'horde.warning');
}
} catch (IMP_Exception $e) {
$notification->push($e);
$canEdit = false;
$curr_acl = array();
}
$rightslist = $acl->getRights();
$iterator = new IMP_Ftree_IteratorFilter(
$injector->getInstance('IMP_Ftree')
);
$iterator->add($iterator::NONIMAP);
$view = new Horde_View(array(
'templatePath' => IMP_TEMPLATES . '/prefs'
));
$view->addHelper('FormTag');
$view->addHelper('Tag');
$view->addHelper('Text');
$view->canedit = $canEdit;
$view->current = sprintf(_("Current access to %s"), $mbox->display_html);
$view->hasacl = count($curr_acl);
$view->mbox = $mbox->form_to;
$view->options = new IMP_Ftree_Select(array(
'iterator' => $iterator,
'selected' => $mbox
));
if ($view->hasacl) {
$cval = array();
foreach ($curr_acl as $index => $rule) {
$entry = array(
'index' => $index,
'rule' => array()
);
if ($rule instanceof Horde_Imap_Client_Data_AclNegative) {
$entry['negative'] = substr($index, 1);
}
/* Create table of each ACL option for each user granted
* permissions; enabled indicates the right has been given to
* the user. */
$rightsmbox = $acl->getRightsMbox($mbox, $index);
foreach (array_keys($rightslist) as $val) {
$entry['rule'][] = array(
'disable' => !$canEdit || !$rightsmbox[$val],
'on' => $rule[$val],
'val' => $val
);
}
$cval[] = $entry;
}
$view->curr_acl = $cval;
}
$new_user = array();
try {
$auth_imap = $injector->getInstance('IMP_AuthImap');
foreach ((array('anyone') + $auth_imap->listUsers()) as $user) {
if (!isset($curr_acl[$user])) {
$new_user[] = htmlspecialchars($user);
}
}
$view->new_user = $new_user;
} catch (IMP_Exception $e) {
/* Ignore - admin user is not available. */
} catch (Horde_Exception $e) {
$notification->push('Could not authenticate as admin user to obtain ACLs. Perhaps your admin configuration is incorrect in config/backends.local.php?', 'horde.warning');
}
$rights = array();
foreach ($rightslist as $key => $val) {
$val['val'] = $key;
$rights[] = $val;
}
$view->rights = $rights;
$view->width = round(100 / (count($rights) + 2)) . '%';
return $view->render('acl');
}
/**
*/
public function update(Horde_Core_Prefs_Ui $ui)
{
global $injector, $notification, $prefs;
if ($prefs->isLocked('acl') || $ui->vars->change_acl_mbox) {
return false;
}
$acl = $injector->getInstance('IMP_Imap_Acl');
$mbox = IMP_Mailbox::formFrom($ui->vars->mbox);
try {
$curr_acl = $acl->getACL($mbox);
} catch (IMP_Exception $e) {
$notification->push($e);
return;
}
if (!($acl_list = $ui->vars->acl)) {
$acl_list = array();
}
$new_user = $ui->vars->new_user;
if (strlen($new_user) && $ui->vars->new_acl) {
if (isset($acl_list[$new_user])) {
$acl_list[$new_user] = $ui->vars->new_acl;
} else {
try {
$acl->addRights($mbox, $new_user, implode('', $ui->vars->new_acl));
$notification->push(sprintf(_("ACL for \"%s\" successfully created for the mailbox \"%s\"."), $new_user, $mbox->label), 'horde.success');
} catch (IMP_Exception $e) {
$notification->push($e);
}
}
}
foreach ($curr_acl as $index => $rule) {
if (isset($acl_list[$index])) {
/* Check to see if ACL changed, but only compare rights we
* understand. */
$acldiff = $rule->diff(implode('', $acl_list[$index]));
$update = false;
try {
if ($acldiff['added']) {
$acl->addRights($mbox, $index, $acldiff['added']);
$update = true;
}
if ($acldiff['removed']) {
$acl->removeRights($mbox, $index, $acldiff['removed']);
$update = true;
}
if ($update) {
$notification->push(sprintf(_("ACL rights for \"%s\" updated for the mailbox \"%s\"."), $index, $mbox->label), 'horde.success');
}
} catch (IMP_Exception $e) {
$notification->push($e);
}
} else {
/* If we dont see ANY form params, the user deleted all
* rights. */
try {
$acl->removeRights($mbox, $index, null);
$notification->push(sprintf(_("All rights on mailbox \"%s\" successfully removed for \"%s\"."), $mbox->label, $index), 'horde.success');
} catch (IMP_Exception $e) {
$notification->push($e);
}
}
}
return false;
}
}