Code

0658fea10ed4dcabfc87129d7b8f852ab46eaa24
[gosa.git] / gosa-core / include / class_acl.inc
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   var $list =NULL;
59   var $sectionList = NULL;
61   function acl (&$config, $parent, $dn= NULL)
62   {
63     /* Include config object */
64     plugin::plugin($config, $dn);
66     /* Load ACL's */
67     $this->gosaAclEntry= array();
68     if (isset($this->attrs['gosaAclEntry'])){
69       for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
70         $acl= $this->attrs['gosaAclEntry'][$i];
71         $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
72       }
73     }
74     ksort($this->gosaAclEntry);
76     /* Save parent - we've to know more about it than other plugins... */
77     $this->parent= &$parent;
79     /* Container? */
80     if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
81       $this->isContainer= TRUE;
82     }
84     /* Users */
85     $ui= get_userinfo();
86     $tag= $ui->gosaUnitTag;
87     $ldap= $config->get_ldap_link();
88     $ldap->cd($config->current['BASE']);
89     if ($tag == ""){
90       $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
91     } else {
92       $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
93     }
94     while ($attrs= $ldap->fetch()){
96       // Allow objects without cn to be listed without causing an error.
97       if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
98         $this->users['U:'.$attrs['dn']]=  $attrs['uid'][0];
99       }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
100         $this->users['U:'.$attrs['dn']]=  $attrs['cn'][0];
101       }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
102         $this->users['U:'.$attrs['dn']]= $attrs['dn'];
103       }else{
104         $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
105       }
107     }
108     ksort($this->users);
110     /* Groups */
111     $ldap->cd($config->current['BASE']);
112 #    if ($tag == ""){
113       $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
114 #    } else {
115 #      $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
116 #    }
117     while ($attrs= $ldap->fetch()){
118       $dsc= "";
119       if (isset($attrs['description'][0])){
120         $dsc= $attrs['description'][0];
121       }
122       $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
123     }
124     $this->groups['G:*']= _("All users");
125     ksort($this->groups);
127     /* Roles */
128     $ldap->cd($config->current['BASE']);
129 #    if ($tag == ""){
130       $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
131 #    } else {
132 #     $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
133 #    }
134     while ($attrs= $ldap->fetch()){
135       $dsc= "";
136       if (isset($attrs['description'][0])){
137         $dsc= $attrs['description'][0];
138       }
140       $role_id = $attrs['dn'];
142       $this->roles[$role_id]['acls'] =array();
143       for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
144         $acl= $attrs['gosaAclTemplate'][$i];
145         $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
146       }
147       $this->roles[$role_id]['description'] = $dsc;
148       $this->roles[$role_id]['cn'] = $attrs['cn'][0];
149     }
151     /* Objects */
152     $tmp= session::global_get('plist');
153     $plist= $tmp->info;
154     $cats = array();
155     if (isset($this->parent) && $this->parent !== NULL){
156       $oc= array();
157       foreach ($this->parent->by_object as $key => $obj){
158         $oc= array_merge($oc, $obj->objectclasses);
159         if(isset($obj->acl_category)){
160                                         $tmp= str_replace("/","",$obj->acl_category);
161           $cats[$tmp] = $tmp;
162         }
163       }
164       if (in_array_ics('organizationalUnit', $oc)){
165         $this->isContainer= TRUE;
166       }
167     } else {
168       $oc=  $this->attrs['objectClass'];
169     }
171     /* Extract available categories from plugin info list */
172     foreach ($plist as $class => $acls){
174       /* Only feed categories */
175       if (isset($acls['plCategory'])){
177         /* Walk through supplied list and feed only translated categories */
178         foreach($acls['plCategory'] as $idx => $data){
180           /* Non numeric index means -> base object containing more informations */
181           if (preg_match('/^[0-9]+$/', $idx)){
183             if (!isset($this->ocMapping[$data])){
184               $this->ocMapping[$data]= array();
185               $this->ocMapping[$data][]= '0';
186             }
188             if(isset($cats[$data])){
189               $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
190             }
191             $this->ocMapping[$data][]= $class;
192           } else {
193             if (!isset($this->ocMapping[$idx])){
194               $this->ocMapping[$idx]= array();
195               $this->ocMapping[$idx][]= '0';
196             }
197             $this->ocMapping[$idx][]= $class;
198             $this->aclObjects[$idx]= $data['description'];
200             /* Additionally filter the classes we're interested in in "self edit" mode */
201             if (is_array($data['objectClass'])){
202               foreach($data['objectClass'] as $objectClass){
203                 if (in_array_ics($objectClass, $oc)){
204                   $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
205                   break;
206                 }
207               }
208             } else {
209               if (in_array_ics($data['objectClass'], $oc)){
210                 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
211               }
212             }
213           }
215         }
216       }
217     }
218     $this->aclObjects['all']= '*&nbsp;'._("All categories");
219     $this->ocMapping['all']= array('0' => 'all');
221     /* Sort categories */
222     asort($this->aclObjects);
224     /* Fill acl types */
225     if ($this->isContainer){
226       $this->aclTypes= array("reset" => _("Reset ACLs"),
227                              "one" => _("One level"),
228                              "base" => _("Current object"),
229                              "sub" => _("Complete subtree"),
230                              "psub" => _("Complete subtree (permanent)"),
231                              "role" => _("Use ACL defined in role"));
232     } else {
233       $this->aclTypes= array("base" => _("Current object"),
234           "role" => _("Use ACL defined in role"));
235     }
236     asort($this->aclTypes);
237     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
238     asort($this->targets);
240     /* Finally - we want to get saved... */
241     $this->is_account= TRUE;
243     $this->updateList();
245     // Prepare lists 
246     $this->sectionList = new sortableListing();
247     $this->sectionList->setDeleteable(false);
248     $this->sectionList->setEditable(false);
249     $this->sectionList->setWidth("100%");
250     $this->sectionList->setHeight("120px");
251     $this->sectionList->setColspecs(array('200px','*'));
252     $this->sectionList->setHeader(array(_("Section"),_("Description")));
253     $this->sectionList->setDefaultSortColumn(1);
254     $this->sectionList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
256     $this->roleList = new sortableListing();
257     $this->roleList->setDeleteable(false);
258     $this->roleList->setEditable(false);
259     $this->roleList->setWidth("100%");
260     $this->roleList->setHeight("120px");
261     $this->roleList->setColspecs(array('20px','*','*'));
262     $this->roleList->setHeader(array(_("Used"),_("Name"),_("Description")));
263     $this->roleList->setDefaultSortColumn(1);
264     $this->roleList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
265   }
267     
268   function updateList()
269   {
270       if(!$this->list){ 
271           $this->list = new sortableListing($this->gosaAclEntry,array(),TRUE);
272           $this->list->setDeleteable(true);
273           $this->list->setEditable(true);
274           $this->list->setColspecs(array('*'));
275           $this->list->setWidth("100%");
276           $this->list->setHeight("400px");
277           $this->list->setAcl("rwcdm");
278           $this->list->setHeader(array(_("Member"),_("Permissions"),_("Type")));
279       }
281  
282     // Add ACL entries to the listing 
283     $lData = array();
284     foreach($this->gosaAclEntry as $id => $entry){
285        $lData[] = $this->convertForListing($entry);
286     }    
287     $this->list->setListData($this->gosaAclEntry, $lData);
288   }
289    
290     
291   function convertForListing($entry)
292   {
293     $member = implode($entry['members'],", ");
294     $acl = implode(array_keys($entry['acl']),", ");
295     $type = implode(array_keys($entry['acl']),", ");
296     return(array('data' => array($member, $acl, $this->aclTypes[$entry['type']])));
297   }
299   
301   function execute()
302   {
303     /* Call parent execute */
304     plugin::execute();
306     $tmp= session::global_get('plist');
307     $plist= $tmp->info;
309     /* Handle posts */
310     if (isset($_POST['new_acl'])){
311       $this->dialogState= 'create';
312       $this->dialog= TRUE;
313       $this->currentIndex= count($this->gosaAclEntry);
314       $this->loadAclEntry(TRUE);
315     }
317     $new_acl= array();
318     $aclDialog= FALSE;
319     $firstedit= FALSE;
321     // Get listing actions. Delete or Edit.
322     $this->list->save_object();
323     $lAction = $this->list->getAction();
324     $this->gosaAclEntry = $this->list->getMaintainedData();
326     /* Act on HTML post and gets here.
327      */
328     if($lAction['action'] == "edit"){
329         $this->currentIndex = $this->list->getKey($lAction['targets'][0]);
330         $this->dialogState= 'create';
331         $firstedit= TRUE;
332         $this->dialog= TRUE;
333         $this->loadAclEntry();
334     }
336     foreach($_POST as $name => $post){
338       /* Actions... */
339       if (preg_match('/^acl_edit_[0-9]*$/', $name)){
340         $this->dialogState= 'create';
341         $firstedit= TRUE;
342         $this->dialog= TRUE;
343         $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
344         $this->loadAclEntry();
345         continue;
346       }
348       if (preg_match('/^cat_edit_.*$/', $name)){
349         $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
350         $this->dialogState= 'edit';
351         foreach ($this->ocMapping[$this->aclObject] as $oc){
352           if (isset($this->aclContents[$oc])){
353             $this->savedAclContents[$oc]= $this->aclContents[$oc];
354           }
355         }
356         continue;
357       }
359       /* Only handle posts, if we allowed to modify ACLs */
360       if(!$this->acl_is_writeable("")){
361         continue;
362       }
364       if (preg_match('/^acl_del_[0-9]*$/', $name)){
365         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
366         continue;
367       }
369       if (preg_match('/^cat_del_.*$/', $name)){
370         $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
371         foreach ($this->ocMapping[$idx] as $key){
372           if(isset($this->aclContents[$idx]))
373             unset($this->aclContents[$idx]);
374           if(isset($this->aclContents["$idx/$key"]))
375             unset($this->aclContents["$idx/$key"]);
376         }
377         continue;
378       }
380       /* ACL saving... */
381       if (preg_match('/^acl_.*_[^xy]$/', $name)){
382         list($dummy, $object, $attribute, $value)= explode('_', $name);
384         /* Skip for detection entry */
385         if ($object == 'dummy') {
386           continue;
387         }
389         /* Ordinary ACLs */
390         if (!isset($new_acl[$object])){
391           $new_acl[$object]= array();
392         }
393         if (isset($new_acl[$object][$attribute])){
394           $new_acl[$object][$attribute].= $value;
395         } else {
396           $new_acl[$object][$attribute]= $value;
397         }
398       }
400       // Remember the selected ACL role.
401       if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
402         $this->aclContents = "";
403         $this->aclContents = base64_decode($_POST['selected_role']);
404       }else{
405           if(is_string($this->aclContents))
406               $this->aclContents = array();
407       }
408     }
410     if(isset($_POST['acl_dummy_0_0_0'])){
411       $aclDialog= TRUE;
412     }
414     if($this->acl_is_writeable("")){
415       
416       /* Only be interested in new acl's, if we're in the right _POST place */
417       if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
419         foreach ($this->ocMapping[$this->aclObject] as $oc){
421           if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
422             unset($this->aclContents[$oc]);
423           }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
424             unset($this->aclContents[$this->aclObject.'/'.$oc]);
425           }else{
426 #          trigger_error("Huhm?");
427           }
428           if (isset($new_acl[$oc]) && is_array($new_acl)){
429             $this->aclContents[$oc]= $new_acl[$oc];
430           }
431           if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
432             $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
433           }
434         }
435       }
437       /* Save new acl in case of base edit mode */
438       if ($this->aclType == 'base' && !$firstedit){
439         $this->aclContents= $new_acl;
440       }
441     }
443     /* Cancel new acl? */
444     if (isset($_POST['cancel_new_acl'])){
445       $this->dialogState= 'head';
446       $this->dialog= FALSE;
447       if ($this->wasNewEntry){
448         unset ($this->gosaAclEntry[$this->currentIndex]);
449       }
450     }
452     /* Save common values */
453     if($this->acl_is_writeable("")){
454       foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
455         if (isset($_POST[$key])){
456           $this->$key= validate($_POST[$key]);
457         }
458       }
459     }
461     /* Store ACL in main object? */
462     if (isset($_POST['submit_new_acl'])){
463       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
464       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
465       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
466       $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
467       $this->dialogState= 'head';
468       $this->dialog= FALSE;
469     }
471     /* Cancel edit acl? */
472     if (isset($_POST['cancel_edit_acl'])){
473       $this->dialogState= 'create';
474       foreach ($this->ocMapping[$this->aclObject] as $oc){
475         if (isset($this->savedAclContents[$oc])){
476           $this->aclContents[$oc]= $this->savedAclContents[$oc];
477         }
478       }
479     }
481     /* Save edit acl? */
482     if (isset($_POST['submit_edit_acl'])){
483       $this->dialogState= 'create';
484     }
486     /* Add acl? */
487     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
488       $this->dialogState= 'edit';
489       $this->savedAclContents= array();
490       foreach ($this->ocMapping[$this->aclObject] as $oc){
491         if (isset($this->aclContents[$oc])){
492           $this->savedAclContents[$oc]= $this->aclContents[$oc];
493         }
494       }
495     }
497     /* Add to list? */
498     if (isset($_POST['add']) && isset($_POST['source'])){
499       foreach ($_POST['source'] as $key){
500         if ($this->target == 'user'){
501           $this->recipients[$key]= $this->users[$key];
502         }
503         if ($this->target == 'group'){
504           $this->recipients[$key]= $this->groups[$key];
505         }
506       }
507       ksort($this->recipients);
508     }
510     /* Remove from list? */
511     if (isset($_POST['del']) && isset($_POST['recipient'])){
512       foreach ($_POST['recipient'] as $key){
513           unset($this->recipients[$key]);
514       }
515     }
517     /* Create templating instance */
518     $smarty= get_smarty();
519     $smarty->assign("usePrototype", "true");
520     $smarty->assign("acl_readable",$this->acl_is_readable(""));
521     if(!$this->acl_is_readable("")){
522       return ($smarty->fetch (get_template_path('acl.tpl')));
523     }
525     if ($this->dialogState == 'head'){
526       $this->updateList();
527       $smarty->assign("aclList", $this->list->render());
528     }
530     if ($this->dialogState == 'create'){
533         if($this->aclType != 'role'){
535             // Create a map of all used sections, this allows us to simply hide the remove button 
536             //  if no acl is configured for the given section 
537             // e.g. ';all;department/country;users/user;
538             $usedList = ";".implode(array_keys($this->aclContents),';').";";
540             /* Add settings for all categories to the (permanent) list */
541             $data = $lData = array();
542             foreach ($this->aclObjects as $section => $dsc){
543                 $summary= "";
544                 foreach($this->ocMapping[$section] as $oc){
545                     if (isset($this->aclContents[$oc]) && 
546                             count($this->aclContents[$oc]) && 
547                             isset($this->aclContents[$oc][0]) &&
548                             $this->aclContents[$oc][0] != ""){
550                         $summary.= "$oc, ";
551                         continue;
552                     }
553                     if (isset($this->aclContents["$section/$oc"]) && 
554                             count($this->aclContents["$section/$oc"])){
555                         $summary.= "$oc, ";
556                         continue;
557                     }
558                     if (isset($this->aclContents[$oc]) && 
559                             !isset($this->aclContents[$oc][0]) && 
560                             count($this->aclContents[$oc])){
561                         $summary.= "$oc, ";
562                     }
563                 }
565                 /* Set summary... */
566                 if ($summary == ""){
567                     $summary= '<i>'._("No ACL settings for this category!").'</i>';
568                 } else {
569                     $summary= trim($summary,", ");
570                     $summary= " ".sprintf(_("Contains ACLs for these objects: %s"), $summary);
571                 }
573                 $actions ="";
574                 if($this->acl_is_readable("")){
575                     $actions.= image('images/lists/edit.png','cat_edit_'.$section, 
576                             msgPool::editButton(_("category ACL")));
577                 }
578                 if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
579                     $actions.= image('images/lists/trash.png','cat_del_'.$section, 
580                             msgPool::delButton(_("category ACL")));
581                 }   
582                 $data[] = $section;
583                 $lData[] = array('data'=>array($dsc, $summary, $actions));
584             }
585             $this->sectionList->setListData($data,$lData);
586             $this->sectionList->update();
587             $smarty->assign("aclList", $this->sectionList->render());
588         }
589     
590       $smarty->assign("aclType", $this->aclType);
591       $smarty->assign("aclFilter", $this->aclFilter);
592       $smarty->assign("aclTypes", $this->aclTypes);
593       $smarty->assign("target", $this->target);
594       $smarty->assign("targets", $this->targets);
596       /* Assign possible target types */
597       $smarty->assign("targets", $this->targets);
598       foreach ($this->attributes as $attr){
599         $smarty->assign($attr, $this->$attr);
600       }
603       /* Generate list */
604       $tmp= array();
605       if ($this->target == "group" && !isset($this->recipients["G:*"])){
606         $tmp["G:*"]= _("All users");
607       }
608       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
609         if ($this->target == $field){
610           foreach ($this->$arr as $key => $value){
611             if (!isset($this->recipients[$key])){
612               $tmp[$key]= $value;
613             }
614           }
615         }
616       }
617       $smarty->assign('sources', $tmp);
618       $smarty->assign('recipients', $this->recipients);
620       /* Acl selector if scope is base */
621       if ($this->aclType == 'base'){
622         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
623       }
625       /* Role selector if scope is base */
626       if ($this->aclType == 'role'){
627         $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
628         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
629       }
630     }
632     if ($this->dialogState == 'edit'){
633       $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
635       /* Collect objects for selected category */
636       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
637         if ($idx == 0){
638           continue;
639         }
640         $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
641       }
642       if ($this->aclObject == 'all'){
643         $aclObjects['all']= _("All objects in current subtree");
644       }
646       /* Role selector if scope is base */
647       if ($this->aclType == 'role'){
648         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
649       } else {
650         $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
651       }
652     }
654     /* Show main page */
655     $smarty->assign("dialogState", $this->dialogState);
656    
657     /* Assign acls */ 
658     $smarty->assign("acl_createable",$this->acl_is_createable());
659     $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
660     $smarty->assign("acl_readable"  ,$this->acl_is_readable(""));
661     $smarty->assign("acl_removeable",$this->acl_is_removeable());
663     return ($smarty->fetch (get_template_path('acl.tpl')));
664   }
667   function sort_by_priority($list)
668   {
669     $tmp= session::global_get('plist');
670     $plist= $tmp->info;
671     asort($plist);
672     $newSort = array();
674     foreach($list as $name => $translation){
675       $na  =  preg_replace("/^.*\//","",$name);
676       $prio = 0;
677       if(isset($plist[$na]['plPriority'])){
678         $prio=  $plist[$na]['plPriority'] ;
679       }
681       $newSort[$name] = $prio;
682     }
684     asort($newSort);
686     $ret = array();
687     foreach($newSort as $name => $prio){
688       $ret[$name] = $list[$name];
689     }
690     return($ret);
691   }
694   function buildRoleSelector($list)
695   {
696     $selected = $this->aclContents;
697     if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
698       $selected = key($list);
699     }
701     $data = $lData = array();
702     foreach($list as $dn => $values){
703       if($dn == $selected){    
704         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
705       }else{
706         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
707       }
708       $data[] = postEncode($dn);
709       $lData[] = array('data'=>array($option, $values['cn'], $values['description']));
710     }
711     $this->roleList->setListData($data,$lData);
712     $this->roleList->update();
713     return($this->roleList->render());
714   } 
717   function buildAclSelector($list)
718   {
719     $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
720     $cols= 3;
721     $tmp= session::global_get('plist');
722     $plist= $tmp->info;
723     asort($plist);
725     /* Add select all/none buttons */
726     $style = "style='width:100px;'";
728     if($this->acl_is_writeable("")){
729       $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
730       $display .= "<button type='button' ".$style." name='toggle_all_move'   onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
731       $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
732       $display .= "<button type='button' ".$style." name='toggle_all_read'   onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
733       $display .= "<button type='button' ".$style." name='toggle_all_write'  onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
735       $display .= "<button type='button' ".$style." name='toggle_all_sub_read'  onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
736       $display .= "<button type='button' ".$style." name='toggle_all_sub_write'  onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
738       $display .= "<br>";
740       $style = "style='width:50px;'";
741       $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
742       $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
743       $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
744       $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
745       $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
746       $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
747       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
748       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
749       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
750       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
752       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
753       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
754       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
755       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
756     }
758     /* Build general objects */
759     $list =$this->sort_by_priority($list);
760     foreach ($list as $key => $name){
762       /* Create sub acl if it does not exist */
763       if (!isset($this->aclContents[$key])){
764         $this->aclContents[$key]= array();
765       }
766       if(!isset($this->aclContents[$key][0])){
767         $this->aclContents[$key][0]= '';
768       }
770       $currentAcl= $this->aclContents[$key];
772       /* Get the overall plugin acls 
773        */
774       $overall_acl ="";
775       if(isset($currentAcl[0])){
776         $overall_acl = $currentAcl[0];
777       }
779       // Detect configured plugins
780       $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
782       /* Object header */
783                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
785       if($expand){
786         $back_color = "#C8C8FF";
787       }else{
788         $back_color = "#C8C8C8";
789       }
791       if(isset($_SERVER['HTTP_USER_AGENT']) && 
792           (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
793           (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
794         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
795           "\n  <tr>".
796           "\n    <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
797           "\n    <td align='right' style='background-color:{$back_color};height:1.8em;'>".
798           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
799           "\n  </tr>";
800       } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
801         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
802           "\n  <tr>".
803           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
804           "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
805           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
806           "\n  </tr>";
807       } else {
808         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
809           "\n  <tr>".
810           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
811           "\n  </tr>";
812       }
814       /* Generate options */
815       $spc= "&nbsp;&nbsp;";
816       $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
817       $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
818       $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
819       if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
820         $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
821       }
823       /* Global options */
824       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $overall_acl)).$spc;
825       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
827       $display.= "\n  <tr>".
828                  "\n    <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
829                  "\n    <td style='background-color:#D4D4D4'>&nbsp;"._("Complete object").": $more_options</td>".
830                  "\n  </tr>";
832       /* Walk through the list of attributes */
833       $cnt= 1;
834       $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
835       if(session::global_get('js')) {
836         if(isset($_SERVER['HTTP_USER_AGENT']) && 
837             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
838           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
839                      "\n    <td colspan=".$cols.">".
840                      "\n      <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
841                      "\n        <table style='width:100%;' summary='{$name}'>";
842         } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
843           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
844                      "\n    <td colspan=".$cols.">".
845                      "\n      <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
846                      "\n        <table style='width:100%;' summary='{$name}'>";
847         }else{
848         }
849       }
851   
852       foreach($splist as $attr => $dsc){
854         /* Skip pl* attributes, they are internal... */
855         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
856           continue;
857         }
859         /* Open table row */
860         if ($cnt == 1){
861           $display.= "\n  <tr>";
862         }
864         /* Close table row */
865         if ($cnt == $cols){
866           $cnt= 1;
867           $rb= "";
868           $end= "\n  </tr>";
869         } else {
870           $cnt++;
871           $rb= "border-right:1px solid #A0A0A0;";
872           $end= "";
873         }
875         /* Collect list of attributes */
876         $state= "";
877         if (isset($currentAcl[$attr])){
878           $state= $currentAcl[$attr];
879         }
880         $display.= "\n    <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
881                    "\n      <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
882       }
883       
884       /* Fill missing td's if needed */
885       if (--$cnt != $cols && $cnt != 0){
886        $display.= str_repeat("\n    <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
887       }
889       if(session::global_get('js')) {
890         if(isset($_SERVER['HTTP_USER_AGENT']) && 
891             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
892             (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) || 
893             (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
894           $display.= "\n        </table>".
895                      "\n      </div>".
896                      "\n    </td>".
897                      "\n  </tr>";
898         }
899       }
901       $display.= "\n</table><br />\n";
902     }
904     return ($display);
905   }
908   function mkchkbx($name, $text, $state= FALSE)
909   {
910     $state= $state?"checked":"";
911     if($this->acl_is_writeable("")){
912                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
913       return "\n      <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
914         "\n      <label for='acl_$tname'>$text</label>";
915     }else{
916       return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
917     }
918   }
921   function mkrwbx($name, $state= "")
922   {
923     $rstate= preg_match('/r/', $state)?'checked':'';
924     $wstate= preg_match('/w/', $state)?'checked':'';
925                 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
926       
927     if($this->acl_is_writeable("")){
928       return ("\n      <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
929           "\n      <label for='acl_".$tname."_r'>"._("read")."</label>".
930           "\n      <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
931           "\n      <label for='acl_".$tname."_w'>"._("write")."</label>");
932     }else{
933       return ("\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
934           "\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
935     }
936   }
939   static function explodeACL($acl)
940   {
942     $list= explode(':', $acl);
943     if(count($list) == 5){
944       list($index, $type,$member,$permission,$filter)= $list;
945       $filter = base64_decode($filter);
946     }else{
947       $filter = "";
948       list($index, $type,$member,$permission)= $list;
949     }
951     $a= array( $index => array("type" => $type,
952                                "filter"=> $filter,
953                                "members" => acl::extractMembers($acl,$type == "role")));
954    
955     /* Handle different types */
956     switch ($type){
958       case 'psub':
959       case 'sub':
960       case 'one':
961       case 'base':
962         $a[$index]['acl']= acl::extractACL($acl);
963         break;
964       
965       case 'role':
966         $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
967         break;
969       case 'reset':
970         break;
971       
972       default:
973         msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
974         $a= array();
975     }
976     return ($a);
977   }
980   static function extractMembers($acl,$role = FALSE)
981   {
982     global $config;
983     $a= array();
985     /* Rip acl off the string, seperate by ',' and place it in an array */
986     if($role){
987       $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
988     }else{
989       $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
990     }
991     if ($ms == $acl){
992       return $a;
993     }
994     $ma= explode(',', $ms);
996     /* Decode dn's, fill with informations from LDAP */
997     $ldap= $config->get_ldap_link();
998     foreach ($ma as $memberdn){
999       // Check for wildcard here
1000       $dn= base64_decode($memberdn);
1001       if ($dn != "*") {
1002         $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
1004         /* Found entry... */
1005         if ($ldap->count()){
1006           $attrs= $ldap->fetch();
1007           if (in_array_ics('gosaAccount', $attrs['objectClass'])){
1008             $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
1009           } else {
1010             $a['G:'.$dn]= $attrs['cn'][0];
1011             if (isset($attrs['description'][0])){
1012               $a['G:'.$dn].= " [".$attrs['description'][0]."]";
1013             }
1014           }
1016         /* ... or not */
1017         } else {
1018           $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1019         }
1021       } else {
1022         $a['G:*']= sprintf(_("All users"));
1023       }
1024     }
1026     return ($a);
1027   }
1030   static function extractACL($acl)
1031   {
1032     /* Rip acl off the string, seperate by ',' and place it in an array */
1033     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1034     $aa= explode(',', $as);
1035     $a= array();
1037     /* Dis-assemble single ACLs */
1038     foreach($aa as $sacl){
1039       
1040       /* Dis-assemble field ACLs */
1041       $ao= explode('#', $sacl);
1042       $gobject= "";
1043       foreach($ao as $idx => $ssacl){
1045         /* First is department with global acl */
1046         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1047         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1048         if ($idx == 0){
1049           /* Create hash for this object */
1050           $gobject= $object;
1051           $a[$gobject]= array();
1053           /* Append ACL if set */
1054           if ($gacl != ""){
1055             $a[$gobject]= array($gacl);
1056           }
1057         } else {
1059           /* All other entries get appended... */
1060           list($field, $facl)= explode(';', $ssacl);
1061           $a[$gobject][$field]= $facl;
1062         }
1064       }
1065     }
1067     return ($a);
1068   }
1070   
1071   function assembleAclSummary($entry)
1072   {
1073     $summary= "";
1075     /* Summarize ACL */
1076     if (isset($entry['acl'])){
1077       $acl= "";
1079       if($entry['type'] == "role"){
1081         if(isset($this->roles[$entry['acl']])){  
1082           $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1083         }else{
1084           $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1085         }
1086       }else{
1087         foreach ($entry['acl'] as $name => $object){
1088           if (count($object)){
1089             $acl.= "$name, ";
1090           }
1091         }
1092         $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1093       }
1094     }
1097     /* Summarize members */
1098     if(!($this instanceOf aclrole)){
1099       if ($summary != ""){
1100         $summary.= ", ";
1101       }
1102       if (count($entry['members'])){
1103         $summary.= _("Members").": ";
1104         foreach ($entry['members'] as $cn){
1105           $cn= preg_replace('/ \[.*$/', '', $cn);
1106           $summary.= $cn.", ";
1107         }
1108       } else {
1109         $summary.= "<font color='red'><i>"._("inactive")."&nbsp;-&nbsp;"._("No members")."</i></font>";
1110       }
1111     }
1112     return (preg_replace('/, $/', '', $summary));
1113   }
1116   function loadAclEntry($new= FALSE)
1117   {
1118     /* New entry gets presets... */
1119     if ($new){
1120       $this->aclType= 'base';
1121       $this->aclFilter= "";
1122       $this->recipients= array();
1123       $this->aclContents= array();
1124     } else {
1125       $acl= $this->gosaAclEntry[$this->currentIndex];
1126       $this->aclType= $acl['type'];
1127       $this->recipients= $acl['members'];
1128       $this->aclContents= $acl['acl'];
1129       $this->aclFilter= $acl['filter'];
1130     }
1132     $this->wasNewEntry= $new;
1133   }
1136   function aclPostHandler()
1137   {
1138     if (isset($_POST['save_acl'])){
1139       $this->save();
1140       return TRUE;
1141     }
1143     return FALSE;
1144   }
1146   
1147   function PrepareForCopyPaste($source)
1148   {
1149     plugin::PrepareForCopyPaste($source);
1150     
1151     $dn = $source['dn'];
1152     $acl_c = new acl($this->config, $this->parent,$dn);
1153     $this->gosaAclEntry = $acl_c->gosaAclEntry;
1154   }
1157   function save()
1158   {
1159     /* Assemble ACL's */
1160     $tmp_acl= array();
1161   
1162     foreach ($this->gosaAclEntry as $prio => $entry){
1163       $final= "";
1164       $members= "";
1165       if (isset($entry['members'])){
1166         foreach ($entry['members'] as $key => $dummy){
1167           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1168         }
1169       }
1171       if($entry['type'] != "role"){
1172         $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1173       }else{
1174         $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1175       }
1177       /* ACL's if needed */
1178       if ($entry['type'] != "reset" && $entry['type'] != "role"){
1179         $acl= ":";
1180         if (isset($entry['acl'])){
1181           foreach ($entry['acl'] as $object => $contents){
1183             /* Only save, if we've some contents in there... */
1184             if (count($contents)){
1185               $acl.= $object.";";
1187               foreach($contents as $attr => $permission){
1189                 /* First entry? Its the one for global settings... */
1190                 if ($attr == '0'){
1191                   $acl.= $permission;
1192                 } else {
1193                   $acl.= '#'.$attr.';'.$permission;
1194                 }
1196               }
1197               $acl.= ',';
1198             }
1199             
1200           }
1201         }
1202         $final.= preg_replace('/,$/', '', $acl);
1203       }
1205       /* Append additional filter options 
1206        */
1207       if(!empty($entry['filter'])){
1208         $final .= ":".base64_encode($entry['filter']);
1209       }
1211       $tmp_acl[]= $final;
1212     } 
1214     /* Call main method */
1215     plugin::save();
1217     /* Finally (re-)assign it... */
1218     $this->attrs['gosaAclEntry']= $tmp_acl;
1220     /* Remove acl from this entry if it is empty... */
1221     if (!count($tmp_acl)){
1222       /* Remove attribute */
1223       if ($this->initially_was_account){
1224         $this->attrs['gosaAclEntry']= array();
1225       } else {
1226         if (isset($this->attrs['gosaAclEntry'])){
1227           unset($this->attrs['gosaAclEntry']);
1228         }
1229       }
1231       /* Remove object class */
1232       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1233     }    
1235     /* Do LDAP modifications */
1236     $ldap= $this->config->get_ldap_link();
1237     $ldap->cd($this->dn);
1238     $this->cleanup();
1239     $ldap->modify ($this->attrs);
1241     if(count($this->attrs)){
1242       new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1243     }
1245     if (!$ldap->success()){
1246       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1247     }
1249     /* Refresh users ACLs */
1250     $ui= get_userinfo();
1251     $ui->loadACL();
1252     session::global_set('ui',$ui);
1253   }
1256   function remove_from_parent()
1257   {
1258     plugin::remove_from_parent();
1260     /* include global link_info */
1261     $ldap= $this->config->get_ldap_link();
1263     $ldap->cd($this->dn);
1264     $this->cleanup();
1265     $ldap->modify ($this->attrs);
1267     new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1269     /* Optionally execute a command after we're done */
1270     $this->handle_post_events("remove",array("uid" => $this->uid));
1271   }
1273   
1274   /* Return plugin informations for acl handling */
1275   static function plInfo()
1276   {
1277     return (array(
1278           "plShortName"   => _("ACL"),
1279           "plDescription" => _("ACL")."&nbsp;("._("Access control list").")",
1280           "plSelfModify"  => FALSE,
1281           "plDepends"     => array(),
1282           "plPriority"    => 0,
1283           "plSection"     => array("administration"),
1284           "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
1285                                                           "objectClass"  => array("gosaAcl","gosaRole"))),
1286           "plProvidedAcls"=> array(
1287             "gosaAclEntry"          => _("Acl entries")
1288 //            "description" => _("Role description")
1289             )
1291           ));
1292   }
1295   /* Remove acls defined for $src */
1296   function remove_acl()
1297   {
1298     acl::remove_acl_for($this->dn);
1299   }
1302   /* Remove acls defined for $src */
1303   static function remove_acl_for($dn)
1304   {                                  
1305     global $config;                  
1307     $ldap = $config->get_ldap_link();
1308     $ldap->cd($config->current['BASE']);
1309     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1310     $new_entries= array();                                                                                      
1311     while($attrs = $ldap->fetch()){                                                                             
1312       if (!isset($attrs['gosaAclEntry'])) {                                                                     
1313         continue;                                                                                               
1314       }                                                                                                         
1315       unset($attrs['gosaAclEntry']['count']);                                                                   
1317       // Remove entry directly
1318       foreach($attrs['gosaAclEntry'] as $id => $entry){
1319         $parts= explode(':',$entry);                     
1320         $members= explode(',',$parts[2]);                
1321         $new_members= array();                         
1322         foreach($members as $member) {                 
1323           if (base64_decode($member) != $dn) {         
1324             $new_members[]= $member;                   
1325           } else {                                     
1326             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1327           }                                                                                                                  
1328         }                                                                                                                    
1330         /* We can completely remove the entry if there are no members anymore */
1331         if (count($new_members)) {                                              
1332           $parts[2]= implode(",", $new_members);                                
1333           $new_entries[]= implode(":", $parts);                                 
1334         }                                                                       
1335       }                                                                         
1337       // There should be a modification, so write it back
1338       $ldap->cd($attrs['dn']);
1339       $new_attrs= array("gosaAclEntry" => $new_entries);
1340       $ldap->modify($new_attrs);
1341       if (!$ldap->success()){
1342         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1343       }
1344     }
1345   }
1348   function update_acl_membership($src,$dst)
1349   {
1350     $ldap = $this->config->get_ldap_link();
1351     $ldap->cd($this->config->current['BASE']);
1352     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1353     while($attrs = $ldap->fetch()){
1354       $acl = new acl($this->config,$this->parent,$attrs['dn']);
1355       foreach($acl->gosaAclEntry as $id => $entry){
1356         foreach($entry['members'] as $m_id => $member){
1357           if($m_id == "U:".$src){
1358             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1359             $new = "U:".$dst;
1360             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1361             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1362           }
1363           if($m_id == "G:".$src){
1364             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1365             $new = "G:".$dst;
1366             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1367             gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1368           }
1369         }
1370       }
1371       $acl -> save();
1372     }
1373   }
1375   
1376   // We are only interessted in our own acls ... 
1377   function set_acl_category($category)
1378   {
1379     plugin::set_acl_category("acl");
1380   }
1383 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1384 ?>