Code

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