1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*! \brief ACL management plugin */
24 class acl extends plugin
25 {
26 /* Definitions */
27 var $plHeadline= "Access control";
28 var $plDescription= "Manage access control lists";
30 /* attribute list for save action */
31 var $attributes= array('gosaAclEntry');
32 var $objectclasses= array('gosaAcl');
34 /* Helpers */
35 var $dialogState= "head";
36 var $gosaAclEntry= array();
37 var $aclType= "";
38 var $aclObject= "";
39 var $aclContents= array();
40 var $target= "group";
41 var $aclTypes= array();
42 var $aclObjects= array();
43 var $aclFilter= "";
44 var $aclMyObjects= array();
45 var $users= array();
46 var $roles= array();
47 var $groups= array();
48 var $recipients= array();
49 var $isContainer= FALSE;
50 var $currentIndex= 0;
51 var $wasNewEntry= FALSE;
52 var $ocMapping= array();
53 var $savedAclContents= array();
54 var $myAclObjects = array();
55 var $acl_category = "acl/";
57 function acl (&$config, $parent, $dn= NULL)
58 {
59 /* Include config object */
60 plugin::plugin($config, $dn);
62 /* Load ACL's */
63 $this->gosaAclEntry= array();
64 if (isset($this->attrs['gosaAclEntry'])){
65 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
66 $acl= $this->attrs['gosaAclEntry'][$i];
67 $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
68 }
69 }
70 ksort($this->gosaAclEntry);
72 /* Save parent - we've to know more about it than other plugins... */
73 $this->parent= &$parent;
75 /* Container? */
76 if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
77 $this->isContainer= TRUE;
78 }
80 /* Users */
81 $ui= get_userinfo();
82 $tag= $ui->gosaUnitTag;
83 $ldap= $config->get_ldap_link();
84 $ldap->cd($config->current['BASE']);
85 if ($tag == ""){
86 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
87 } else {
88 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
89 }
90 while ($attrs= $ldap->fetch()){
92 // Allow objects without cn to be listed without causing an error.
93 if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
94 $this->users['U:'.$attrs['dn']]= $attrs['uid'][0];
95 }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
96 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0];
97 }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
98 $this->users['U:'.$attrs['dn']]= $attrs['dn'];
99 }else{
100 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
101 }
103 }
104 ksort($this->users);
106 /* Groups */
107 $ldap->cd($config->current['BASE']);
108 # if ($tag == ""){
109 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
110 # } else {
111 # $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
112 # }
113 while ($attrs= $ldap->fetch()){
114 $dsc= "";
115 if (isset($attrs['description'][0])){
116 $dsc= $attrs['description'][0];
117 }
118 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
119 }
120 $this->groups['G:*']= _("All users");
121 ksort($this->groups);
123 /* Roles */
124 $ldap->cd($config->current['BASE']);
125 # if ($tag == ""){
126 $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
127 # } else {
128 # $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
129 # }
130 while ($attrs= $ldap->fetch()){
131 $dsc= "";
132 if (isset($attrs['description'][0])){
133 $dsc= $attrs['description'][0];
134 }
136 $role_id = $attrs['dn'];
138 $this->roles[$role_id]['acls'] =array();
139 for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
140 $acl= $attrs['gosaAclTemplate'][$i];
141 $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
142 }
143 $this->roles[$role_id]['description'] = $dsc;
144 $this->roles[$role_id]['cn'] = $attrs['cn'][0];
145 }
147 /* Objects */
148 $tmp= session::global_get('plist');
149 $plist= $tmp->info;
150 $cats = array();
151 if (isset($this->parent) && $this->parent !== NULL){
152 $oc= array();
153 foreach ($this->parent->by_object as $key => $obj){
154 $oc= array_merge($oc, $obj->objectclasses);
155 if(isset($obj->acl_category)){
156 $tmp= str_replace("/","",$obj->acl_category);
157 $cats[$tmp] = $tmp;
158 }
159 }
160 if (in_array_ics('organizationalUnit', $oc)){
161 $this->isContainer= TRUE;
162 }
163 } else {
164 $oc= $this->attrs['objectClass'];
165 }
167 /* Extract available categories from plugin info list */
168 foreach ($plist as $class => $acls){
170 /* Only feed categories */
171 if (isset($acls['plCategory'])){
173 /* Walk through supplied list and feed only translated categories */
174 foreach($acls['plCategory'] as $idx => $data){
176 /* Non numeric index means -> base object containing more informations */
177 if (preg_match('/^[0-9]+$/', $idx)){
179 if (!isset($this->ocMapping[$data])){
180 $this->ocMapping[$data]= array();
181 $this->ocMapping[$data][]= '0';
182 }
184 if(isset($cats[$data])){
185 $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
186 }
187 $this->ocMapping[$data][]= $class;
188 } else {
189 if (!isset($this->ocMapping[$idx])){
190 $this->ocMapping[$idx]= array();
191 $this->ocMapping[$idx][]= '0';
192 }
193 $this->ocMapping[$idx][]= $class;
194 $this->aclObjects[$idx]= $data['description'];
196 /* Additionally filter the classes we're interested in in "self edit" mode */
197 if (is_array($data['objectClass'])){
198 foreach($data['objectClass'] as $objectClass){
199 if (in_array_ics($objectClass, $oc)){
200 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
201 break;
202 }
203 }
204 } else {
205 if (in_array_ics($data['objectClass'], $oc)){
206 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
207 }
208 }
209 }
211 }
212 }
213 }
214 $this->aclObjects['all']= '* '._("All categories");
215 $this->ocMapping['all']= array('0' => 'all');
217 /* Sort categories */
218 asort($this->aclObjects);
220 /* Fill acl types */
221 if ($this->isContainer){
222 $this->aclTypes= array("reset" => _("Reset ACLs"),
223 "one" => _("One level"),
224 "base" => _("Current object"),
225 "sub" => _("Complete subtree"),
226 "psub" => _("Complete subtree (permanent)"),
227 "role" => _("Use ACL defined in role"));
228 } else {
229 $this->aclTypes= array("base" => _("Current object"),
230 "role" => _("Use ACL defined in role"));
231 }
232 asort($this->aclTypes);
233 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
234 asort($this->targets);
236 /* Finally - we want to get saved... */
237 $this->is_account= TRUE;
238 }
241 function execute()
242 {
243 /* Call parent execute */
244 plugin::execute();
246 $tmp= session::global_get('plist');
247 $plist= $tmp->info;
249 /* Handle posts */
250 if (isset($_POST['new_acl'])){
251 $this->dialogState= 'create';
252 $this->dialog= TRUE;
253 $this->currentIndex= count($this->gosaAclEntry);
254 $this->loadAclEntry(TRUE);
255 }
257 $new_acl= array();
258 $aclDialog= FALSE;
259 $firstedit= FALSE;
261 /* Act on HTML post and gets here.
262 */
263 if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
264 $id = trim($_GET['id']);
265 $this->dialogState= 'create';
266 $firstedit= TRUE;
267 $this->dialog= TRUE;
268 $this->currentIndex= $id;
269 $this->loadAclEntry();
270 }
272 foreach($_POST as $name => $post){
274 /* Actions... */
275 if (preg_match('/^acl_edit_.*_x/', $name)){
276 $this->dialogState= 'create';
277 $firstedit= TRUE;
278 $this->dialog= TRUE;
279 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
280 $this->loadAclEntry();
281 continue;
282 }
284 if (preg_match('/^cat_edit_.*_x/', $name)){
285 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
286 $this->dialogState= 'edit';
287 foreach ($this->ocMapping[$this->aclObject] as $oc){
288 if (isset($this->aclContents[$oc])){
289 $this->savedAclContents[$oc]= $this->aclContents[$oc];
290 }
291 }
292 continue;
293 }
295 /* Only handle posts, if we allowed to modify ACLs */
296 if(!$this->acl_is_writeable("")){
297 continue;
298 }
300 if (preg_match('/^acl_del_.*_x/', $name)){
301 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
302 continue;
303 }
305 if (preg_match('/^cat_del_.*_x/', $name)){
306 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
307 foreach ($this->ocMapping[$idx] as $key){
308 unset($this->aclContents["$idx/$key"]);
309 }
310 continue;
311 }
313 /* Sorting... */
314 if (preg_match('/^sortup_.*_x/', $name)){
315 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
316 if ($index > 0){
317 $tmp= $this->gosaAclEntry[$index];
318 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
319 $this->gosaAclEntry[$index-1]= $tmp;
320 }
321 continue;
322 }
323 if (preg_match('/^sortdown_.*_x/', $name)){
324 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
325 if ($index < count($this->gosaAclEntry)-1){
326 $tmp= $this->gosaAclEntry[$index];
327 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
328 $this->gosaAclEntry[$index+1]= $tmp;
329 }
330 continue;
331 }
333 /* ACL saving... */
334 if (preg_match('/^acl_.*_[^xy]$/', $name)){
335 list($dummy, $object, $attribute, $value)= explode('_', $name);
337 /* Skip for detection entry */
338 if ($object == 'dummy') {
339 continue;
340 }
342 /* Ordinary ACLs */
343 if (!isset($new_acl[$object])){
344 $new_acl[$object]= array();
345 }
346 if (isset($new_acl[$object][$attribute])){
347 $new_acl[$object][$attribute].= $value;
348 } else {
349 $new_acl[$object][$attribute]= $value;
350 }
351 }
353 // Remember the selected ACL role.
354 if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
355 $this->aclContents = "";
356 $this->aclContents = base64_decode($_POST['selected_role']);
357 }
358 }
360 if(isset($_POST['acl_dummy_0_0_0'])){
361 $aclDialog= TRUE;
362 }
364 if($this->acl_is_writeable("")){
366 /* Only be interested in new acl's, if we're in the right _POST place */
367 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
369 foreach ($this->ocMapping[$this->aclObject] as $oc){
371 if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
372 unset($this->aclContents[$oc]);
373 }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
374 unset($this->aclContents[$this->aclObject.'/'.$oc]);
375 }else{
376 # trigger_error("Huhm?");
377 }
378 if (isset($new_acl[$oc]) && is_array($new_acl)){
379 $this->aclContents[$oc]= $new_acl[$oc];
380 }
381 if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
382 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
383 }
384 }
385 }
387 /* Save new acl in case of base edit mode */
388 if ($this->aclType == 'base' && !$firstedit){
389 $this->aclContents= $new_acl;
390 }
391 }
393 /* Cancel new acl? */
394 if (isset($_POST['cancel_new_acl'])){
395 $this->dialogState= 'head';
396 $this->dialog= FALSE;
397 if ($this->wasNewEntry){
398 unset ($this->gosaAclEntry[$this->currentIndex]);
399 }
400 }
402 /* Save common values */
403 if($this->acl_is_writeable("")){
404 foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
405 if (isset($_POST[$key])){
406 $this->$key= validate($_POST[$key]);
407 }
408 }
409 }
411 /* Store ACL in main object? */
412 if (isset($_POST['submit_new_acl'])){
413 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
414 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
415 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
416 $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
417 $this->dialogState= 'head';
418 $this->dialog= FALSE;
419 }
421 /* Cancel edit acl? */
422 if (isset($_POST['cancel_edit_acl'])){
423 $this->dialogState= 'create';
424 foreach ($this->ocMapping[$this->aclObject] as $oc){
425 if (isset($this->savedAclContents[$oc])){
426 $this->aclContents[$oc]= $this->savedAclContents[$oc];
427 }
428 }
429 }
431 /* Save edit acl? */
432 if (isset($_POST['submit_edit_acl'])){
433 $this->dialogState= 'create';
434 }
436 /* Add acl? */
437 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
438 $this->dialogState= 'edit';
439 $this->savedAclContents= array();
440 foreach ($this->ocMapping[$this->aclObject] as $oc){
441 if (isset($this->aclContents[$oc])){
442 $this->savedAclContents[$oc]= $this->aclContents[$oc];
443 }
444 }
445 }
447 /* Add to list? */
448 if (isset($_POST['add']) && isset($_POST['source'])){
449 foreach ($_POST['source'] as $key){
450 if ($this->target == 'user'){
451 $this->recipients[$key]= $this->users[$key];
452 }
453 if ($this->target == 'group'){
454 $this->recipients[$key]= $this->groups[$key];
455 }
456 }
457 ksort($this->recipients);
458 }
460 /* Remove from list? */
461 if (isset($_POST['del']) && isset($_POST['recipient'])){
462 foreach ($_POST['recipient'] as $key){
463 unset($this->recipients[$key]);
464 }
465 }
467 /* Create templating instance */
468 $smarty= get_smarty();
469 $smarty->assign("acl_readable",$this->acl_is_readable(""));
470 if(!$this->acl_is_readable("")){
471 return ($smarty->fetch (get_template_path('acl.tpl')));
472 }
474 if ($this->dialogState == 'head'){
475 /* Draw list */
476 $aclList= new divSelectBox("aclList");
477 $aclList->SetHeight(450);
479 /* Fill in entries */
480 foreach ($this->gosaAclEntry as $key => $entry){
481 if(!$this->acl_is_readable("")) continue;
483 $action ="";
485 if($this->acl_is_readable("")){
486 $link = "<a href=?plug=".$_GET['plug']."&id=".$key."&act=edit>".$this->assembleAclSummary($entry)."</a>";
487 }else{
488 $link = $this->assembleAclSummary($entry);
489 }
491 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
492 $field2= array("string" => $link);
494 if($this->acl_is_writeable("")){
495 $action.= "<input type='image' name='sortup_$key' alt='up'
496 title='"._("Up")."' src='images/lists/sort-up.png' align='top'>";
497 $action.= "<input type='image' name='sortdown_$key' alt='down'
498 title='"._("Down")."' src='images/lists/sort-down.png'>";
499 }
501 if($this->acl_is_readable("")){
502 $action.= "<input class='center' type='image' src='images/lists/edit.png'
503 alt='"._("Edit")."' name='acl_edit_$key' title='".msgPool::editButton(_("ACL"))."'>";
504 }
505 if($this->acl_is_removeable("")){
506 $action.= "<input class='center' type='image' src='images/lists/trash.png'
507 alt='"._("Delete")."' name='acl_del_$key' title='".msgPool::delButton(_("ACL"))."'>";
508 }
510 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
511 $aclList->AddEntry(array($field1, $field2, $field3));
512 }
514 $smarty->assign("aclList", $aclList->DrawList());
515 }
517 if ($this->dialogState == 'create'){
518 /* Draw list */
519 $aclList= new divSelectBox("aclList");
520 $aclList->SetHeight(150);
522 /* Add settings for all categories to the (permanent) list */
523 foreach ($this->aclObjects as $section => $dsc){
524 $summary= "";
525 foreach($this->ocMapping[$section] as $oc){
526 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
527 $this->aclContents[$oc][0] != ""){
529 $summary.= "$oc, ";
530 continue;
531 }
532 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
533 $summary.= "$oc, ";
534 continue;
535 }
536 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
537 $summary.= "$oc, ";
538 }
539 }
541 /* Set summary... */
542 if ($summary == ""){
543 $summary= '<i>'._("No ACL settings for this category!").'</i>';
544 } else {
545 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
546 }
548 $actions ="";
549 if($this->acl_is_readable("")){
550 $actions= "<input class='center' type='image' src='images/lists/edit.png'
551 alt='"._("Edit")."' name='cat_edit_$section' title='".msgPool::editButton(_("category ACL"))."'>";
552 }
553 if($this->acl_is_removeable()){
554 $actions.= "<input class='center' type='image' src='images/lists/trash.png'
555 alt='"._("Delete")."' name='cat_del_$section' title='".msgPool::delButton(_("category ACL"))."'>";
556 }
558 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
559 $field2= array("string" => $summary);
560 $field3= array("string" => $actions, "attach" => "style='border-right:0px;width:50px'");
561 $aclList->AddEntry(array($field1, $field2, $field3));
562 }
564 $smarty->assign("aclList", $aclList->DrawList());
565 $smarty->assign("aclType", $this->aclType);
566 $smarty->assign("aclFilter", $this->aclFilter);
567 $smarty->assign("aclTypes", $this->aclTypes);
568 $smarty->assign("target", $this->target);
569 $smarty->assign("targets", $this->targets);
571 /* Assign possible target types */
572 $smarty->assign("targets", $this->targets);
573 foreach ($this->attributes as $attr){
574 $smarty->assign($attr, $this->$attr);
575 }
578 /* Generate list */
579 $tmp= array();
580 if ($this->target == "group" && !isset($this->recipients["G:*"])){
581 $tmp["G:*"]= _("All users");
582 }
583 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
584 if ($this->target == $field){
585 foreach ($this->$arr as $key => $value){
586 if (!isset($this->recipients[$key])){
587 $tmp[$key]= $value;
588 }
589 }
590 }
591 }
592 $smarty->assign('sources', $tmp);
593 $smarty->assign('recipients', $this->recipients);
595 /* Acl selector if scope is base */
596 if ($this->aclType == 'base'){
597 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
598 }
600 /* Role selector if scope is base */
601 if ($this->aclType == 'role'){
602 $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
603 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
604 }
605 }
607 if ($this->dialogState == 'edit'){
608 $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
610 /* Collect objects for selected category */
611 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
612 if ($idx == 0){
613 continue;
614 }
615 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
616 }
617 if ($this->aclObject == 'all'){
618 $aclObjects['all']= _("All objects in current subtree");
619 }
621 /* Role selector if scope is base */
622 if ($this->aclType == 'role'){
623 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
624 } else {
625 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
626 }
627 }
629 /* Show main page */
630 $smarty->assign("dialogState", $this->dialogState);
632 /* Assign acls */
633 $smarty->assign("acl_createable",$this->acl_is_createable());
634 $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
635 $smarty->assign("acl_readable" ,$this->acl_is_readable(""));
636 $smarty->assign("acl_removeable",$this->acl_is_removeable());
638 return ($smarty->fetch (get_template_path('acl.tpl')));
639 }
642 function sort_by_priority($list)
643 {
644 $tmp= session::global_get('plist');
645 $plist= $tmp->info;
646 asort($plist);
647 $newSort = array();
649 foreach($list as $name => $translation){
650 $na = preg_replace("/^.*\//","",$name);
651 $prio = 0;
652 if(isset($plist[$na]['plPriority'])){
653 $prio= $plist[$na]['plPriority'] ;
654 }
656 $newSort[$name] = $prio;
657 }
659 asort($newSort);
661 $ret = array();
662 foreach($newSort as $name => $prio){
663 $ret[$name] = $list[$name];
664 }
665 return($ret);
666 }
669 function buildRoleSelector($list)
670 {
671 $D_List =new divSelectBox("Acl_Roles");
673 $selected = $this->aclContents;
674 if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
675 $selected = key($list);
676 }
678 $str ="";
679 foreach($list as $dn => $values){
681 if($dn == $selected){
682 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
683 }else{
684 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
685 }
687 $field1 = array("string" => $option) ;
688 $field2 = array("string" => $values['cn'], "attach" => "style='width:200px;'") ;
689 $field3 = array("string" => $values['description'],"attach" => "style='border-right:0px;'") ;
691 $D_List->AddEntry(array($field1,$field2,$field3));
692 }
693 return($D_List->DrawList());
694 }
697 function buildAclSelector($list)
698 {
699 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
700 $cols= 3;
701 $tmp= session::global_get('plist');
702 $plist= $tmp->info;
703 asort($plist);
705 /* Add select all/none buttons */
706 $style = "style='width:100px;'";
708 if($this->acl_is_writeable("")){
709 $display .= "<input ".$style." type='button' name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" value='Toggle C'>";
710 $display .= "<input ".$style." type='button' name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" value='Toggle M'>";
711 $display .= "<input ".$style." type='button' name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" value='Toggle D'> - ";
712 $display .= "<input ".$style." type='button' name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" value='Toggle R'>";
713 $display .= "<input ".$style." type='button' name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" value='Toggle W'> - ";
715 $display .= "<input ".$style." type='button' name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" value='R+'>";
716 $display .= "<input ".$style." type='button' name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" value='W+'>";
718 $display .= "<br>";
720 $style = "style='width:50px;'";
721 $display .= "<input ".$style." type='button' name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" value='C+'>";
722 $display .= "<input ".$style." type='button' name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" value='C-'>";
723 $display .= "<input ".$style." type='button' name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" value='M+'>";
724 $display .= "<input ".$style." type='button' name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" value='M-'>";
725 $display .= "<input ".$style." type='button' name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" value='D+'>";
726 $display .= "<input ".$style." type='button' name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" value='D-'> - ";
727 $display .= "<input ".$style." type='button' name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" value='R+'>";
728 $display .= "<input ".$style." type='button' name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" value='R-'>";
729 $display .= "<input ".$style." type='button' name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" value='W+'>";
730 $display .= "<input ".$style." type='button' name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" value='W-'> - ";
732 $display .= "<input ".$style." type='button' name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" value='R+'>";
733 $display .= "<input ".$style." type='button' name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" value='R-'>";
734 $display .= "<input ".$style." type='button' name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" value='W+'>";
735 $display .= "<input ".$style." type='button' name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" value='W-'>";
736 }
738 /* Build general objects */
739 $list =$this->sort_by_priority($list);
740 foreach ($list as $key => $name){
742 /* Create sub acl if it does not exist */
743 if (!isset($this->aclContents[$key])){
744 $this->aclContents[$key]= array();
745 }
746 if(!isset($this->aclContents[$key][0])){
747 $this->aclContents[$key][0]= '';
748 }
750 $currentAcl= $this->aclContents[$key];
752 /* Get the overall plugin acls
753 */
754 $overall_acl ="";
755 if(isset($currentAcl[0])){
756 $overall_acl = $currentAcl[0];
757 }
759 // Detect configured plugins
760 $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
762 /* Object header */
763 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
765 if($expand){
766 $back_color = "#C8C8FF";
767 }else{
768 $back_color = "#C8C8C8";
769 }
771 if(session::global_get('js')) {
772 if(isset($_SERVER['HTTP_USER_AGENT']) &&
773 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
774 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
775 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
776 "\n <tr>".
777 "\n <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
778 "\n <td align='right' style='background-color:{$back_color};height:1.8em;'>".
779 "\n <input type='button' onclick=\"$('{$tname}').toggle();\" value='"._("Show/hide advanced settings")."' /></td>".
780 "\n </tr>";
781 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
782 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
783 "\n <tr>".
784 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
785 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
786 "\n <input type='button' onclick=\"$('{$tname}').toggle();\" value='"._("Show/hide advanced settings")."' /></td>".
787 "\n </tr>";
788 } else {
789 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
790 "\n <tr>".
791 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
792 "\n </tr>";
793 }
794 } else {
795 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
796 "\n <tr>".
797 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
798 "\n </tr>";
799 }
801 /* Generate options */
802 $spc= " ";
803 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
804 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
805 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
806 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
807 $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
808 }
810 /* Global options */
811 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $overall_acl)).$spc;
812 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
814 $display.= "\n <tr>".
815 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
816 "\n <td style='background-color:#D4D4D4'> "._("Complete object").": $more_options</td>".
817 "\n </tr>";
819 /* Walk through the list of attributes */
820 $cnt= 1;
821 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
822 if(session::global_get('js')) {
823 if(isset($_SERVER['HTTP_USER_AGENT']) &&
824 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
825 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
826 "\n <td colspan=".$cols.">".
827 "\n <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
828 "\n <table style='width:100%;'>";
829 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
830 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
831 "\n <td colspan=".$cols.">".
832 "\n <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
833 "\n <table style='width:100%;'>";
834 }else{
835 }
836 }
839 foreach($splist as $attr => $dsc){
841 /* Skip pl* attributes, they are internal... */
842 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
843 continue;
844 }
846 /* Open table row */
847 if ($cnt == 1){
848 $display.= "\n <tr>";
849 }
851 /* Close table row */
852 if ($cnt == $cols){
853 $cnt= 1;
854 $rb= "";
855 $end= "\n </tr>";
856 } else {
857 $cnt++;
858 $rb= "border-right:1px solid #A0A0A0;";
859 $end= "";
860 }
862 /* Collect list of attributes */
863 $state= "";
864 if (isset($currentAcl[$attr])){
865 $state= $currentAcl[$attr];
866 }
867 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
868 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
869 }
871 /* Fill missing td's if needed */
872 if (--$cnt != $cols && $cnt != 0){
873 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
874 }
876 if(session::global_get('js')) {
877 if(isset($_SERVER['HTTP_USER_AGENT']) &&
878 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
879 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) ||
880 (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
881 $display.= "\n </table>".
882 "\n </div>".
883 "\n </td>".
884 "\n </tr>";
885 }
886 }
888 $display.= "\n</table><br />\n";
889 }
891 return ($display);
892 }
895 function mkchkbx($name, $text, $state= FALSE)
896 {
897 $state= $state?"checked":"";
898 if($this->acl_is_writeable("")){
899 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
900 return "\n <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
901 "\n <label for='acl_$tname'>$text</label>";
902 }else{
903 return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
904 }
905 }
908 function mkrwbx($name, $state= "")
909 {
910 $rstate= preg_match('/r/', $state)?'checked':'';
911 $wstate= preg_match('/w/', $state)?'checked':'';
912 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
914 if($this->acl_is_writeable("")){
915 return ("\n <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
916 "\n <label for='acl_".$tname."_r'>"._("read")."</label>".
917 "\n <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
918 "\n <label for='acl_".$tname."_w'>"._("write")."</label>");
919 }else{
920 return ("\n <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
921 "\n <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
922 }
923 }
926 static function explodeACL($acl)
927 {
929 $list= explode(':', $acl);
930 if(count($list) == 5){
931 list($index, $type,$member,$permission,$filter)= $list;
932 $filter = base64_decode($filter);
933 }else{
934 $filter = "";
935 list($index, $type,$member,$permission)= $list;
936 }
938 $a= array( $index => array("type" => $type,
939 "filter"=> $filter,
940 "members" => acl::extractMembers($acl,$type == "role")));
942 /* Handle different types */
943 switch ($type){
945 case 'psub':
946 case 'sub':
947 case 'one':
948 case 'base':
949 $a[$index]['acl']= acl::extractACL($acl);
950 break;
952 case 'role':
953 $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
954 break;
956 case 'reset':
957 break;
959 default:
960 msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
961 $a= array();
962 }
963 return ($a);
964 }
967 static function extractMembers($acl,$role = FALSE)
968 {
969 global $config;
970 $a= array();
972 /* Rip acl off the string, seperate by ',' and place it in an array */
973 if($role){
974 $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
975 }else{
976 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
977 }
978 if ($ms == $acl){
979 return $a;
980 }
981 $ma= explode(',', $ms);
983 /* Decode dn's, fill with informations from LDAP */
984 $ldap= $config->get_ldap_link();
985 foreach ($ma as $memberdn){
986 // Check for wildcard here
987 $dn= base64_decode($memberdn);
988 if ($dn != "*") {
989 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
991 /* Found entry... */
992 if ($ldap->count()){
993 $attrs= $ldap->fetch();
994 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
995 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
996 } else {
997 $a['G:'.$dn]= $attrs['cn'][0];
998 if (isset($attrs['description'][0])){
999 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
1000 }
1001 }
1003 /* ... or not */
1004 } else {
1005 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1006 }
1008 } else {
1009 $a['G:*']= sprintf(_("All users"));
1010 }
1011 }
1013 return ($a);
1014 }
1017 static function extractACL($acl)
1018 {
1019 /* Rip acl off the string, seperate by ',' and place it in an array */
1020 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1021 $aa= explode(',', $as);
1022 $a= array();
1024 /* Dis-assemble single ACLs */
1025 foreach($aa as $sacl){
1027 /* Dis-assemble field ACLs */
1028 $ao= explode('#', $sacl);
1029 $gobject= "";
1030 foreach($ao as $idx => $ssacl){
1032 /* First is department with global acl */
1033 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1034 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1035 if ($idx == 0){
1036 /* Create hash for this object */
1037 $gobject= $object;
1038 $a[$gobject]= array();
1040 /* Append ACL if set */
1041 if ($gacl != ""){
1042 $a[$gobject]= array($gacl);
1043 }
1044 } else {
1046 /* All other entries get appended... */
1047 list($field, $facl)= explode(';', $ssacl);
1048 $a[$gobject][$field]= $facl;
1049 }
1051 }
1052 }
1054 return ($a);
1055 }
1058 function assembleAclSummary($entry)
1059 {
1060 $summary= "";
1062 /* Summarize ACL */
1063 if (isset($entry['acl'])){
1064 $acl= "";
1066 if($entry['type'] == "role"){
1068 if(isset($this->roles[$entry['acl']])){
1069 $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1070 }else{
1071 $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1072 }
1073 }else{
1074 foreach ($entry['acl'] as $name => $object){
1075 if (count($object)){
1076 $acl.= "$name, ";
1077 }
1078 }
1079 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1080 }
1081 }
1084 /* Summarize members */
1085 if(!($this instanceOf aclrole)){
1086 if ($summary != ""){
1087 $summary.= ", ";
1088 }
1089 if (count($entry['members'])){
1090 $summary.= _("Members").": ";
1091 foreach ($entry['members'] as $cn){
1092 $cn= preg_replace('/ \[.*$/', '', $cn);
1093 $summary.= $cn.", ";
1094 }
1095 } else {
1096 $summary.= "<font color='red'><i>"._("inactive")." - "._("No members")."</i></font>";
1097 }
1098 }
1099 return (preg_replace('/, $/', '', $summary));
1100 }
1103 function loadAclEntry($new= FALSE)
1104 {
1105 /* New entry gets presets... */
1106 if ($new){
1107 $this->aclType= 'base';
1108 $this->aclFilter= "";
1109 $this->recipients= array();
1110 $this->aclContents= array();
1111 } else {
1112 $acl= $this->gosaAclEntry[$this->currentIndex];
1113 $this->aclType= $acl['type'];
1114 $this->recipients= $acl['members'];
1115 $this->aclContents= $acl['acl'];
1116 $this->aclFilter= $acl['filter'];
1117 }
1119 $this->wasNewEntry= $new;
1120 }
1123 function aclPostHandler()
1124 {
1125 if (isset($_POST['save_acl'])){
1126 $this->save();
1127 return TRUE;
1128 }
1130 return FALSE;
1131 }
1134 function PrepareForCopyPaste($source)
1135 {
1136 plugin::PrepareForCopyPaste($source);
1138 $dn = $source['dn'];
1139 $acl_c = new acl($this->config, $this->parent,$dn);
1140 $this->gosaAclEntry = $acl_c->gosaAclEntry;
1141 }
1144 function save()
1145 {
1146 /* Assemble ACL's */
1147 $tmp_acl= array();
1149 foreach ($this->gosaAclEntry as $prio => $entry){
1150 $final= "";
1151 $members= "";
1152 if (isset($entry['members'])){
1153 foreach ($entry['members'] as $key => $dummy){
1154 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1155 }
1156 }
1158 if($entry['type'] != "role"){
1159 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1160 }else{
1161 $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1162 }
1164 /* ACL's if needed */
1165 if ($entry['type'] != "reset" && $entry['type'] != "role"){
1166 $acl= ":";
1167 if (isset($entry['acl'])){
1168 foreach ($entry['acl'] as $object => $contents){
1170 /* Only save, if we've some contents in there... */
1171 if (count($contents)){
1172 $acl.= $object.";";
1174 foreach($contents as $attr => $permission){
1176 /* First entry? Its the one for global settings... */
1177 if ($attr == '0'){
1178 $acl.= $permission;
1179 } else {
1180 $acl.= '#'.$attr.';'.$permission;
1181 }
1183 }
1184 $acl.= ',';
1185 }
1187 }
1188 }
1189 $final.= preg_replace('/,$/', '', $acl);
1190 }
1192 /* Append additional filter options
1193 */
1194 if(!empty($entry['filter'])){
1195 $final .= ":".base64_encode($entry['filter']);
1196 }
1198 $tmp_acl[]= $final;
1199 }
1201 /* Call main method */
1202 plugin::save();
1204 /* Finally (re-)assign it... */
1205 $this->attrs['gosaAclEntry']= $tmp_acl;
1207 /* Remove acl from this entry if it is empty... */
1208 if (!count($tmp_acl)){
1209 /* Remove attribute */
1210 if ($this->initially_was_account){
1211 $this->attrs['gosaAclEntry']= array();
1212 } else {
1213 if (isset($this->attrs['gosaAclEntry'])){
1214 unset($this->attrs['gosaAclEntry']);
1215 }
1216 }
1218 /* Remove object class */
1219 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1220 }
1222 /* Do LDAP modifications */
1223 $ldap= $this->config->get_ldap_link();
1224 $ldap->cd($this->dn);
1225 $this->cleanup();
1226 $ldap->modify ($this->attrs);
1228 if(count($this->attrs)){
1229 new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1230 }
1232 if (!$ldap->success()){
1233 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1234 }
1236 /* Refresh users ACLs */
1237 $ui= get_userinfo();
1238 $ui->loadACL();
1239 session::global_set('ui',$ui);
1240 }
1243 function remove_from_parent()
1244 {
1245 plugin::remove_from_parent();
1247 /* include global link_info */
1248 $ldap= $this->config->get_ldap_link();
1250 $ldap->cd($this->dn);
1251 $this->cleanup();
1252 $ldap->modify ($this->attrs);
1254 new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1256 /* Optionally execute a command after we're done */
1257 $this->handle_post_events("remove",array("uid" => $this->uid));
1258 }
1261 /* Return plugin informations for acl handling */
1262 static function plInfo()
1263 {
1264 return (array(
1265 "plShortName" => _("ACL"),
1266 "plDescription" => _("ACL")." ("._("Access control list").")",
1267 "plSelfModify" => FALSE,
1268 "plDepends" => array(),
1269 "plPriority" => 0,
1270 "plSection" => array("administration"),
1271 "plCategory" => array("acl" => array("description" => _("ACL")." & "._("ACL roles"),
1272 "objectClass" => array("gosaAcl","gosaRole"))),
1273 "plProvidedAcls"=> array(
1274 // "cn" => _("Role name"),
1275 // "description" => _("Role description")
1276 )
1278 ));
1279 }
1282 /* Remove acls defined for $src */
1283 function remove_acl()
1284 {
1285 acl::remove_acl_for($this->dn);
1286 }
1289 /* Remove acls defined for $src */
1290 static function remove_acl_for($dn)
1291 {
1292 global $config;
1294 $ldap = $config->get_ldap_link();
1295 $ldap->cd($config->current['BASE']);
1296 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1297 $new_entries= array();
1298 while($attrs = $ldap->fetch()){
1299 if (!isset($attrs['gosaAclEntry'])) {
1300 continue;
1301 }
1302 unset($attrs['gosaAclEntry']['count']);
1304 // Remove entry directly
1305 foreach($attrs['gosaAclEntry'] as $id => $entry){
1306 $parts= explode(':',$entry);
1307 $members= explode(',',$parts[2]);
1308 $new_members= array();
1309 foreach($members as $member) {
1310 if (base64_decode($member) != $dn) {
1311 $new_members[]= $member;
1312 } else {
1313 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1314 }
1315 }
1317 /* We can completely remove the entry if there are no members anymore */
1318 if (count($new_members)) {
1319 $parts[2]= implode(",", $new_members);
1320 $new_entries[]= implode(":", $parts);
1321 }
1322 }
1324 // There should be a modification, so write it back
1325 $ldap->cd($attrs['dn']);
1326 $new_attrs= array("gosaAclEntry" => $new_entries);
1327 $ldap->modify($new_attrs);
1328 if (!$ldap->success()){
1329 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1330 }
1331 }
1332 }
1335 function update_acl_membership($src,$dst)
1336 {
1337 $ldap = $this->config->get_ldap_link();
1338 $ldap->cd($this->config->current['BASE']);
1339 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1340 while($attrs = $ldap->fetch()){
1341 $acl = new acl($this->config,$this->parent,$attrs['dn']);
1342 foreach($acl->gosaAclEntry as $id => $entry){
1343 foreach($entry['members'] as $m_id => $member){
1344 if($m_id == "U:".$src){
1345 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1346 $new = "U:".$dst;
1347 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1348 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1349 }
1350 if($m_id == "G:".$src){
1351 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1352 $new = "G:".$dst;
1353 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1354 gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1355 }
1356 }
1357 }
1358 $acl -> save();
1359 }
1360 }
1362 }
1364 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1365 ?>