Code

Updated acl listUpdated acl list
[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     }
219     $this->aclObjects['all']= '*&nbsp;'._("All categories");
220     $this->ocMapping['all']= array('0' => 'all');
222     /* Sort categories */
223     asort($this->aclObjects);
225     /* Fill acl types */
226     if ($this->isContainer){
227       $this->aclTypes= array("reset" => _("Reset ACLs"),
228                              "one" => _("One level"),
229                              "base" => _("Current object"),
230                              "sub" => _("Complete subtree"),
231                              "psub" => _("Complete subtree (permanent)"),
232                              "role" => _("Use ACL defined in role"));
233     } else {
234       $this->aclTypes= array("base" => _("Current object"),
235           "role" => _("Use ACL defined in role"));
236     }
237     asort($this->aclTypes);
238     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
239     asort($this->targets);
241     /* Finally - we want to get saved... */
242     $this->is_account= TRUE;
244     $this->updateList();
246     // Prepare lists 
247     $this->sectionList = new sortableListing();
248     $this->sectionList->setDeleteable(false);
249     $this->sectionList->setEditable(false);
250     $this->sectionList->setWidth("100%");
251     $this->sectionList->setHeight("120px");
252     $this->sectionList->setColspecs(array('200px','*'));
253     $this->sectionList->setHeader(array(_("Section"),_("Description")));
254     $this->sectionList->setDefaultSortColumn(1);
255     $this->sectionList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
257     $this->roleList = new sortableListing();
258     $this->roleList->setDeleteable(false);
259     $this->roleList->setEditable(false);
260     $this->roleList->setWidth("100%");
261     $this->roleList->setHeight("120px");
262     $this->roleList->setColspecs(array('20px','*','*'));
263     $this->roleList->setHeader(array(_("Used"),_("Name"),_("Description")));
264     $this->roleList->setDefaultSortColumn(1);
265     $this->roleList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
266   }
268     
269   function updateList()
270   {
271       if(!$this->list){ 
272           $this->list = new sortableListing($this->gosaAclEntry,array(),TRUE);
273           $this->list->setDeleteable(true);
274           $this->list->setEditable(true);
275           $this->list->setColspecs(array('*'));
276           $this->list->setWidth("100%");
277           $this->list->setHeight("400px");
278           $this->list->setAcl("rwcdm");
279           $this->list->setHeader(array(_("Member"),_("Permissions"),_("Type")));
280       }
282  
283     // Add ACL entries to the listing 
284     $lData = array();
285     foreach($this->gosaAclEntry as $id => $entry){
286        $lData[] = $this->convertForListing($entry);
287     }    
288     $this->list->setListData($this->gosaAclEntry, $lData);
289   }
290    
291     
292   function convertForListing($entry)
293   {
294     $member = implode($entry['members'],", ");
295     $acl = implode(array_keys($entry['acl']),", ");
296     $type = implode(array_keys($entry['acl']),", ");
297     return(array('data' => array($member, $acl, $this->aclTypes[$entry['type']])));
298   }
300   
302   function execute()
303   {
304     /* Call parent execute */
305     plugin::execute();
307     $tmp= session::global_get('plist');
308     $plist= $tmp->info;
310     /* Handle posts */
311     if (isset($_POST['new_acl'])){
312       $this->dialogState= 'create';
313       $this->dialog= TRUE;
314       $this->currentIndex= count($this->gosaAclEntry);
315       $this->loadAclEntry(TRUE);
316     }
318     $new_acl= array();
319     $aclDialog= FALSE;
320     $firstedit= FALSE;
322     // Get listing actions. Delete or Edit.
323     $this->list->save_object();
324     $lAction = $this->list->getAction();
325     $this->gosaAclEntry = array_values($this->list->getMaintainedData());
327     /* Act on HTML post and gets here.
328      */
329     if($lAction['action'] == "edit"){
330         $this->currentIndex = $this->list->getKey($lAction['targets'][0]);
331         $this->dialogState= 'create';
332         $firstedit= TRUE;
333         $this->dialog= TRUE;
334         $this->loadAclEntry();
335     }
337     foreach($_POST as $name => $post){
339       /* Actions... */
340       if (preg_match('/^acl_edit_[0-9]*$/', $name)){
341         $this->dialogState= 'create';
342         $firstedit= TRUE;
343         $this->dialog= TRUE;
344         $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
345         $this->loadAclEntry();
346         continue;
347       }
349       if (preg_match('/^cat_edit_.*$/', $name)){
350         $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
351         $this->dialogState= 'edit';
352         foreach ($this->ocMapping[$this->aclObject] as $oc){
353           if (isset($this->aclContents[$oc])){
354             $this->savedAclContents[$oc]= $this->aclContents[$oc];
355           }
356         }
357         continue;
358       }
360       /* Only handle posts, if we allowed to modify ACLs */
361       if(!$this->acl_is_writeable("")){
362         continue;
363       }
365       if (preg_match('/^acl_del_[0-9]*$/', $name)){
366         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
367         continue;
368       }
370       if (preg_match('/^cat_del_.*$/', $name)){
371         $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
372         foreach ($this->ocMapping[$idx] as $key){
373           if(isset($this->aclContents[$idx]))
374             unset($this->aclContents[$idx]);
375           if(isset($this->aclContents["$idx/$key"]))
376             unset($this->aclContents["$idx/$key"]);
377         }
378         continue;
379       }
381       /* ACL saving... */
382       if (preg_match('/^acl_.*_[^xy]$/', $name)){
383         list($dummy, $object, $attribute, $value)= explode('_', $name);
385         /* Skip for detection entry */
386         if ($object == 'dummy') {
387           continue;
388         }
390         /* Ordinary ACLs */
391         if (!isset($new_acl[$object])){
392           $new_acl[$object]= array();
393         }
394         if (isset($new_acl[$object][$attribute])){
395           $new_acl[$object][$attribute].= $value;
396         } else {
397           $new_acl[$object][$attribute]= $value;
398         }
399       }
401       // Remember the selected ACL role.
402       if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
403         $this->aclContents = "";
404         $this->aclContents = base64_decode($_POST['selected_role']);
405       }else{
406           if(is_string($this->aclContents))
407               $this->aclContents = array();
408       }
409     }
411     if(isset($_POST['acl_dummy_0_0_0'])){
412       $aclDialog= TRUE;
413     }
415     if($this->acl_is_writeable("")){
416       
417       /* Only be interested in new acl's, if we're in the right _POST place */
418       if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
420         foreach ($this->ocMapping[$this->aclObject] as $oc){
422           if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
423             unset($this->aclContents[$oc]);
424           }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
425             unset($this->aclContents[$this->aclObject.'/'.$oc]);
426           }else{
427 #          trigger_error("Huhm?");
428           }
429           if (isset($new_acl[$oc]) && is_array($new_acl)){
430             $this->aclContents[$oc]= $new_acl[$oc];
431           }
432           if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
433             $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
434           }
435         }
436       }
438       /* Save new acl in case of base edit mode */
439       if ($this->aclType == 'base' && !$firstedit){
440         $this->aclContents= $new_acl;
441       }
442     }
444     /* Cancel new acl? */
445     if (isset($_POST['cancel_new_acl'])){
446       $this->dialogState= 'head';
447       $this->dialog= FALSE;
448       if ($this->wasNewEntry){
449         unset ($this->gosaAclEntry[$this->currentIndex]);
450       }
451     }
453     /* Save common values */
454     if($this->acl_is_writeable("")){
455       foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
456         if (isset($_POST[$key])){
457           $this->$key= validate($_POST[$key]);
458         }
459       }
460     }
462     /* Store ACL in main object? */
463     if (isset($_POST['submit_new_acl'])){
464       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
465       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
466       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
467       $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
468       $this->dialogState= 'head';
469       $this->dialog= FALSE;
470     }
472     /* Cancel edit acl? */
473     if (isset($_POST['cancel_edit_acl'])){
474       $this->dialogState= 'create';
475       foreach ($this->ocMapping[$this->aclObject] as $oc){
476         if (isset($this->savedAclContents[$oc])){
477           $this->aclContents[$oc]= $this->savedAclContents[$oc];
478         }
479       }
480     }
482     /* Save edit acl? */
483     if (isset($_POST['submit_edit_acl'])){
484       $this->dialogState= 'create';
485     }
487     /* Add acl? */
488     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
489       $this->dialogState= 'edit';
490       $this->savedAclContents= array();
491       foreach ($this->ocMapping[$this->aclObject] as $oc){
492         if (isset($this->aclContents[$oc])){
493           $this->savedAclContents[$oc]= $this->aclContents[$oc];
494         }
495       }
496     }
498     /* Add to list? */
499     if (isset($_POST['add']) && isset($_POST['source'])){
500       foreach ($_POST['source'] as $key){
501         if ($this->target == 'user'){
502           $this->recipients[$key]= $this->users[$key];
503         }
504         if ($this->target == 'group'){
505           $this->recipients[$key]= $this->groups[$key];
506         }
507       }
508       ksort($this->recipients);
509     }
511     /* Remove from list? */
512     if (isset($_POST['del']) && isset($_POST['recipient'])){
513       foreach ($_POST['recipient'] as $key){
514           unset($this->recipients[$key]);
515       }
516     }
518     /* Create templating instance */
519     $smarty= get_smarty();
520     $smarty->assign("usePrototype", "true");
521     $smarty->assign("acl_readable",$this->acl_is_readable(""));
522     if(!$this->acl_is_readable("")){
523       return ($smarty->fetch (get_template_path('acl.tpl')));
524     }
526     if ($this->dialogState == 'head'){
527       $this->updateList();
528       $smarty->assign("aclList", $this->list->render());
529     }
531     if ($this->dialogState == 'create'){
534         if($this->aclType != 'role'){
536             // Create a map of all used sections, this allows us to simply hide the remove button 
537             //  if no acl is configured for the given section 
538             // e.g. ';all;department/country;users/user;
539             $usedList = ";".implode(array_keys($this->aclContents),';').";";
541             /* Add settings for all categories to the (permanent) list */
542             $data = $lData = array();
543             foreach ($this->aclObjects as $section => $dsc){
544                 $summary= "";
545                 foreach($this->ocMapping[$section] as $oc){
546                     if (isset($this->aclContents[$oc]) && 
547                             count($this->aclContents[$oc]) && 
548                             isset($this->aclContents[$oc][0]) &&
549                             $this->aclContents[$oc][0] != ""){
551                         $summary.= "$oc, ";
552                         continue;
553                     }
554                     if (isset($this->aclContents["$section/$oc"]) && 
555                             count($this->aclContents["$section/$oc"])){
556                         $summary.= "$oc, ";
557                         continue;
558                     }
559                     if (isset($this->aclContents[$oc]) && 
560                             !isset($this->aclContents[$oc][0]) && 
561                             count($this->aclContents[$oc])){
562                         $summary.= "$oc, ";
563                     }
564                 }
566                 /* Set summary... */
567                 if ($summary == ""){
568                     $summary= '<i>'._("No ACL settings for this category!").'</i>';
569                 } else {
570                     $summary= trim($summary,", ");
571                     $summary= " ".sprintf(_("Contains ACLs for these objects: %s"), $summary);
572                 }
574                 $actions ="";
575                 if($this->acl_is_readable("")){
576                     $actions.= image('images/lists/edit.png','cat_edit_'.$section, 
577                             msgPool::editButton(_("category ACL")));
578                 }
579                 if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
580                     $actions.= image('images/lists/trash.png','cat_del_'.$section, 
581                             msgPool::delButton(_("category ACL")));
582                 }   
583                 $data[] = $section;
584                 $lData[] = array('data'=>array($dsc, $summary, $actions));
585             }
586             $this->sectionList->setListData($data,$lData);
587             $this->sectionList->update();
588             $smarty->assign("aclList", $this->sectionList->render());
589         }
590     
591       $smarty->assign("aclType", $this->aclType);
592       $smarty->assign("aclFilter", $this->aclFilter);
593       $smarty->assign("aclTypes", $this->aclTypes);
594       $smarty->assign("target", $this->target);
595       $smarty->assign("targets", $this->targets);
597       /* Assign possible target types */
598       $smarty->assign("targets", $this->targets);
599       foreach ($this->attributes as $attr){
600         $smarty->assign($attr, $this->$attr);
601       }
604       /* Generate list */
605       $tmp= array();
606       if ($this->target == "group" && !isset($this->recipients["G:*"])){
607         $tmp["G:*"]= _("All users");
608       }
609       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
610         if ($this->target == $field){
611           foreach ($this->$arr as $key => $value){
612             if (!isset($this->recipients[$key])){
613               $tmp[$key]= $value;
614             }
615           }
616         }
617       }
618       $smarty->assign('sources', $tmp);
619       $smarty->assign('recipients', $this->recipients);
621       /* Acl selector if scope is base */
622       if ($this->aclType == 'base'){
623         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
624       }
626       /* Role selector if scope is base */
627       if ($this->aclType == 'role'){
628         $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
629         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
630       }
631     }
633     if ($this->dialogState == 'edit'){
634       $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%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       }
643       if ($this->aclObject == 'all'){
644         $aclObjects['all']= _("All objects in current subtree");
645       }
647       /* Role selector if scope is base */
648       if ($this->aclType == 'role'){
649         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
650       } else {
651         $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
652       }
653     }
655     /* Show main page */
656     $smarty->assign("dialogState", $this->dialogState);
657    
658     /* Assign acls */ 
659     $smarty->assign("acl_createable",$this->acl_is_createable());
660     $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
661     $smarty->assign("acl_readable"  ,$this->acl_is_readable(""));
662     $smarty->assign("acl_removeable",$this->acl_is_removeable());
664     return ($smarty->fetch (get_template_path('acl.tpl')));
665   }
668   function sort_by_priority($list)
669   {
670     $tmp= session::global_get('plist');
671     $plist= $tmp->info;
672     asort($plist);
673     $newSort = array();
675     foreach($list as $name => $translation){
676       $na  =  preg_replace("/^.*\//","",$name);
677       $prio = 0;
678       if(isset($plist[$na]['plPriority'])){
679         $prio=  $plist[$na]['plPriority'] ;
680       }
682       $newSort[$name] = $prio;
683     }
685     asort($newSort);
687     $ret = array();
688     foreach($newSort as $name => $prio){
689       $ret[$name] = $list[$name];
690     }
691     return($ret);
692   }
695   function buildRoleSelector($list)
696   {
697     $selected = $this->aclContents;
698     if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
699       $selected = key($list);
700     }
702     $data = $lData = array();
703     foreach($list as $dn => $values){
704       if($dn == $selected){    
705         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
706       }else{
707         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
708       }
709       $data[] = postEncode($dn);
710       $lData[] = array('data'=>array($option, $values['cn'], $values['description']));
711     }
712     $this->roleList->setListData($data,$lData);
713     $this->roleList->update();
714     return($this->roleList->render());
715   } 
718   function buildAclSelector($list)
719   {
720     $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
721     $cols= 3;
722     $tmp= session::global_get('plist');
723     $plist= $tmp->info;
724     asort($plist);
726     /* Add select all/none buttons */
727     $style = "style='width:100px;'";
729     if($this->acl_is_writeable("")){
730       $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
731       $display .= "<button type='button' ".$style." name='toggle_all_move'   onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
732       $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
733       $display .= "<button type='button' ".$style." name='toggle_all_read'   onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
734       $display .= "<button type='button' ".$style." name='toggle_all_write'  onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
736       $display .= "<button type='button' ".$style." name='toggle_all_sub_read'  onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
737       $display .= "<button type='button' ".$style." name='toggle_all_sub_write'  onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
739       $display .= "<br>";
741       $style = "style='width:50px;'";
742       $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
743       $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
744       $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
745       $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
746       $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
747       $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
748       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
749       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
750       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
751       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
753       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
754       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
755       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
756       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
757     }
759     /* Build general objects */
760     $list =$this->sort_by_priority($list);
761     foreach ($list as $key => $name){
763       /* Create sub acl if it does not exist */
764       if (!isset($this->aclContents[$key])){
765         $this->aclContents[$key]= array();
766       }
767       if(!isset($this->aclContents[$key][0])){
768         $this->aclContents[$key][0]= '';
769       }
771       $currentAcl= $this->aclContents[$key];
773       /* Get the overall plugin acls 
774        */
775       $overall_acl ="";
776       if(isset($currentAcl[0])){
777         $overall_acl = $currentAcl[0];
778       }
780       // Detect configured plugins
781       $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
783       /* Object header */
784                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
786       if($expand){
787         $back_color = "#C8C8FF";
788       }else{
789         $back_color = "#C8C8C8";
790       }
792       if(isset($_SERVER['HTTP_USER_AGENT']) && 
793           (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
794           (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
795         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
796           "\n  <tr>".
797           "\n    <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
798           "\n    <td align='right' style='background-color:{$back_color};height:1.8em;'>".
799           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
800           "\n  </tr>";
801       } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
802         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
803           "\n  <tr>".
804           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
805           "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
806           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
807           "\n  </tr>";
808       } else {
809         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
810           "\n  <tr>".
811           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
812           "\n  </tr>";
813       }
815       /* Generate options */
816       $spc= "&nbsp;&nbsp;";
817       $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
818       $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
819       $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
820       if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
821         $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
822       }
824       /* Global options */
825       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $overall_acl)).$spc;
826       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
828       $display.= "\n  <tr>".
829                  "\n    <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
830                  "\n    <td style='background-color:#D4D4D4'>&nbsp;"._("Complete object").": $more_options</td>".
831                  "\n  </tr>";
833       /* Walk through the list of attributes */
834       $cnt= 1;
835       $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
836       if(session::global_get('js')) {
837         if(isset($_SERVER['HTTP_USER_AGENT']) && 
838             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
839           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
840                      "\n    <td colspan=".$cols.">".
841                      "\n      <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
842                      "\n        <table style='width:100%;' summary='{$name}'>";
843         } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
844           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
845                      "\n    <td colspan=".$cols.">".
846                      "\n      <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
847                      "\n        <table style='width:100%;' summary='{$name}'>";
848         }else{
849         }
850       }
852   
853       foreach($splist as $attr => $dsc){
855         /* Skip pl* attributes, they are internal... */
856         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
857           continue;
858         }
860         /* Open table row */
861         if ($cnt == 1){
862           $display.= "\n  <tr>";
863         }
865         /* Close table row */
866         if ($cnt == $cols){
867           $cnt= 1;
868           $rb= "";
869           $end= "\n  </tr>";
870         } else {
871           $cnt++;
872           $rb= "border-right:1px solid #A0A0A0;";
873           $end= "";
874         }
876         /* Collect list of attributes */
877         $state= "";
878         if (isset($currentAcl[$attr])){
879           $state= $currentAcl[$attr];
880         }
881         $display.= "\n    <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
882                    "\n      <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
883       }
884       
885       /* Fill missing td's if needed */
886       if (--$cnt != $cols && $cnt != 0){
887        $display.= str_repeat("\n    <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
888       }
890       if(session::global_get('js')) {
891         if(isset($_SERVER['HTTP_USER_AGENT']) && 
892             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
893             (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) || 
894             (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
895           $display.= "\n        </table>".
896                      "\n      </div>".
897                      "\n    </td>".
898                      "\n  </tr>";
899         }
900       }
902       $display.= "\n</table><br />\n";
903     }
905     return ($display);
906   }
909   function mkchkbx($name, $text, $state= FALSE)
910   {
911     $state= $state?"checked":"";
912     if($this->acl_is_writeable("")){
913                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
914       return "\n      <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
915         "\n      <label for='acl_$tname'>$text</label>";
916     }else{
917       return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
918     }
919   }
922   function mkrwbx($name, $state= "")
923   {
924     $rstate= preg_match('/r/', $state)?'checked':'';
925     $wstate= preg_match('/w/', $state)?'checked':'';
926                 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
927       
928     if($this->acl_is_writeable("")){
929       return ("\n      <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
930           "\n      <label for='acl_".$tname."_r'>"._("read")."</label>".
931           "\n      <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
932           "\n      <label for='acl_".$tname."_w'>"._("write")."</label>");
933     }else{
934       return ("\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
935           "\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
936     }
937   }
940   static function explodeACL($acl)
941   {
943     $list= explode(':', $acl);
944     if(count($list) == 5){
945       list($index, $type,$member,$permission,$filter)= $list;
946       $filter = base64_decode($filter);
947     }else{
948       $filter = "";
949       list($index, $type,$member,$permission)= $list;
950     }
952     $a= array( $index => array("type" => $type,
953                                "filter"=> $filter,
954                                "members" => acl::extractMembers($acl,$type == "role")));
955    
956     /* Handle different types */
957     switch ($type){
959       case 'psub':
960       case 'sub':
961       case 'one':
962       case 'base':
963         $a[$index]['acl']= acl::extractACL($acl);
964         break;
965       
966       case 'role':
967         $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
968         break;
970       case 'reset':
971         break;
972       
973       default:
974         msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
975         $a= array();
976     }
977     return ($a);
978   }
981   static function extractMembers($acl,$role = FALSE)
982   {
983     global $config;
984     $a= array();
986     /* Rip acl off the string, seperate by ',' and place it in an array */
987     if($role){
988       $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
989     }else{
990       $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
991     }
992     if ($ms == $acl){
993       return $a;
994     }
995     $ma= explode(',', $ms);
997     /* Decode dn's, fill with informations from LDAP */
998     $ldap= $config->get_ldap_link();
999     foreach ($ma as $memberdn){
1000       // Check for wildcard here
1001       $dn= base64_decode($memberdn);
1002       if ($dn != "*") {
1003         $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
1005         /* Found entry... */
1006         if ($ldap->count()){
1007           $attrs= $ldap->fetch();
1008           if (in_array_ics('gosaAccount', $attrs['objectClass'])){
1009             $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
1010           } else {
1011             $a['G:'.$dn]= $attrs['cn'][0];
1012             if (isset($attrs['description'][0])){
1013               $a['G:'.$dn].= " [".$attrs['description'][0]."]";
1014             }
1015           }
1017         /* ... or not */
1018         } else {
1019           $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1020         }
1022       } else {
1023         $a['G:*']= sprintf(_("All users"));
1024       }
1025     }
1027     return ($a);
1028   }
1031   static function extractACL($acl)
1032   {
1033     /* Rip acl off the string, seperate by ',' and place it in an array */
1034     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1035     $aa= explode(',', $as);
1036     $a= array();
1038     /* Dis-assemble single ACLs */
1039     foreach($aa as $sacl){
1040       
1041       /* Dis-assemble field ACLs */
1042       $ao= explode('#', $sacl);
1043       $gobject= "";
1044       foreach($ao as $idx => $ssacl){
1046         /* First is department with global acl */
1047         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1048         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1049         if ($idx == 0){
1050           /* Create hash for this object */
1051           $gobject= $object;
1052           $a[$gobject]= array();
1054           /* Append ACL if set */
1055           if ($gacl != ""){
1056             $a[$gobject]= array($gacl);
1057           }
1058         } else {
1060           /* All other entries get appended... */
1061           list($field, $facl)= explode(';', $ssacl);
1062           $a[$gobject][$field]= $facl;
1063         }
1065       }
1066     }
1068     return ($a);
1069   }
1071   
1072   function assembleAclSummary($entry)
1073   {
1074     $summary= "";
1076     /* Summarize ACL */
1077     if (isset($entry['acl'])){
1078       $acl= "";
1080       if($entry['type'] == "role"){
1082         if(isset($this->roles[$entry['acl']])){  
1083           $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1084         }else{
1085           $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1086         }
1087       }else{
1088         foreach ($entry['acl'] as $name => $object){
1089           if (count($object)){
1090             $acl.= "$name, ";
1091           }
1092         }
1093         $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1094       }
1095     }
1098     /* Summarize members */
1099     if(!($this instanceOf aclrole)){
1100       if ($summary != ""){
1101         $summary.= ", ";
1102       }
1103       if (count($entry['members'])){
1104         $summary.= _("Members").": ";
1105         foreach ($entry['members'] as $cn){
1106           $cn= preg_replace('/ \[.*$/', '', $cn);
1107           $summary.= $cn.", ";
1108         }
1109       } else {
1110         $summary.= "<font color='red'><i>"._("inactive")."&nbsp;-&nbsp;"._("No members")."</i></font>";
1111       }
1112     }
1113     return (preg_replace('/, $/', '', $summary));
1114   }
1117   function loadAclEntry($new= FALSE)
1118   {
1119     /* New entry gets presets... */
1120     if ($new){
1121       $this->aclType= 'base';
1122       $this->aclFilter= "";
1123       $this->recipients= array();
1124       $this->aclContents= array();
1125     } else {
1126       $acl= $this->gosaAclEntry[$this->currentIndex];
1127       $this->aclType= $acl['type'];
1128       $this->recipients= $acl['members'];
1129       $this->aclContents= $acl['acl'];
1130       $this->aclFilter= $acl['filter'];
1131     }
1133     $this->wasNewEntry= $new;
1134   }
1137   function aclPostHandler()
1138   {
1139     if (isset($_POST['save_acl'])){
1140       $this->save();
1141       return TRUE;
1142     }
1144     return FALSE;
1145   }
1147   
1148   function PrepareForCopyPaste($source)
1149   {
1150     plugin::PrepareForCopyPaste($source);
1151     
1152     $dn = $source['dn'];
1153     $acl_c = new acl($this->config, $this->parent,$dn);
1154     $this->gosaAclEntry = $acl_c->gosaAclEntry;
1155   }
1158   function save()
1159   {
1160     /* Assemble ACL's */
1161     $tmp_acl= array();
1162   
1163     foreach ($this->gosaAclEntry as $prio => $entry){
1164       $final= "";
1165       $members= "";
1166       if (isset($entry['members'])){
1167         foreach ($entry['members'] as $key => $dummy){
1168           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1169         }
1170       }
1172       if($entry['type'] != "role"){
1173         $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1174       }else{
1175         $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1176       }
1178       /* ACL's if needed */
1179       if ($entry['type'] != "reset" && $entry['type'] != "role"){
1180         $acl= ":";
1181         if (isset($entry['acl'])){
1182           foreach ($entry['acl'] as $object => $contents){
1184             /* Only save, if we've some contents in there... */
1185             if (count($contents)){
1186               $acl.= $object.";";
1188               foreach($contents as $attr => $permission){
1190                 /* First entry? Its the one for global settings... */
1191                 if ($attr == '0'){
1192                   $acl.= $permission;
1193                 } else {
1194                   $acl.= '#'.$attr.';'.$permission;
1195                 }
1197               }
1198               $acl.= ',';
1199             }
1200             
1201           }
1202         }
1203         $final.= preg_replace('/,$/', '', $acl);
1204       }
1206       /* Append additional filter options 
1207        */
1208       if(!empty($entry['filter'])){
1209         $final .= ":".base64_encode($entry['filter']);
1210       }
1212       $tmp_acl[]= $final;
1213     } 
1215     /* Call main method */
1216     plugin::save();
1218     /* Finally (re-)assign it... */
1219     $this->attrs['gosaAclEntry']= $tmp_acl;
1221     /* Remove acl from this entry if it is empty... */
1222     if (!count($tmp_acl)){
1223       /* Remove attribute */
1224       if ($this->initially_was_account){
1225         $this->attrs['gosaAclEntry']= array();
1226       } else {
1227         if (isset($this->attrs['gosaAclEntry'])){
1228           unset($this->attrs['gosaAclEntry']);
1229         }
1230       }
1232       /* Remove object class */
1233       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1234     }    
1236     /* Do LDAP modifications */
1237     $ldap= $this->config->get_ldap_link();
1238     $ldap->cd($this->dn);
1239     $this->cleanup();
1240     $ldap->modify ($this->attrs);
1242     if(count($this->attrs)){
1243       new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1244     }
1246     if (!$ldap->success()){
1247       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1248     }
1250     /* Refresh users ACLs */
1251     $ui= get_userinfo();
1252     $ui->loadACL();
1253     session::global_set('ui',$ui);
1254   }
1257   function remove_from_parent()
1258   {
1259     plugin::remove_from_parent();
1261     /* include global link_info */
1262     $ldap= $this->config->get_ldap_link();
1264     $ldap->cd($this->dn);
1265     $this->cleanup();
1266     $ldap->modify ($this->attrs);
1268     new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1270     /* Optionally execute a command after we're done */
1271     $this->handle_post_events("remove",array("uid" => $this->uid));
1272   }
1274   
1275   /* Return plugin informations for acl handling */
1276   static function plInfo()
1277   {
1278     return (array(
1279           "plShortName"   => _("ACL"),
1280           "plDescription" => _("ACL")."&nbsp;("._("Access control list").")",
1281           "plSelfModify"  => FALSE,
1282           "plDepends"     => array(),
1283           "plPriority"    => 0,
1284           "plSection"     => array("administration"),
1285           "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
1286                                                           "objectClass"  => array("gosaAcl","gosaRole"))),
1287           "plProvidedAcls"=> array(
1288             "gosaAclEntry"          => _("Acl entries")
1289 //            "description" => _("Role description")
1290             )
1292           ));
1293   }
1296   /* Remove acls defined for $src */
1297   function remove_acl()
1298   {
1299     acl::remove_acl_for($this->dn);
1300   }
1303   /* Remove acls defined for $src */
1304   static function remove_acl_for($dn)
1305   {                                  
1306     global $config;                  
1308     $ldap = $config->get_ldap_link();
1309     $ldap->cd($config->current['BASE']);
1310     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1311     $new_entries= array();                                                                                      
1312     while($attrs = $ldap->fetch()){                                                                             
1313       if (!isset($attrs['gosaAclEntry'])) {                                                                     
1314         continue;                                                                                               
1315       }                                                                                                         
1316       unset($attrs['gosaAclEntry']['count']);                                                                   
1318       // Remove entry directly
1319       foreach($attrs['gosaAclEntry'] as $id => $entry){
1320         $parts= explode(':',$entry);                     
1321         $members= explode(',',$parts[2]);                
1322         $new_members= array();                         
1323         foreach($members as $member) {                 
1324           if (base64_decode($member) != $dn) {         
1325             $new_members[]= $member;                   
1326           } else {                                     
1327             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1328           }                                                                                                                  
1329         }                                                                                                                    
1331         /* We can completely remove the entry if there are no members anymore */
1332         if (count($new_members)) {                                              
1333           $parts[2]= implode(",", $new_members);                                
1334           $new_entries[]= implode(":", $parts);                                 
1335         }                                                                       
1336       }                                                                         
1338       // There should be a modification, so write it back
1339       $ldap->cd($attrs['dn']);
1340       $new_attrs= array("gosaAclEntry" => $new_entries);
1341       $ldap->modify($new_attrs);
1342       if (!$ldap->success()){
1343         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1344       }
1345     }
1346   }
1349   function update_acl_membership($src,$dst)
1350   {
1351     $ldap = $this->config->get_ldap_link();
1352     $ldap->cd($this->config->current['BASE']);
1353     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1354     while($attrs = $ldap->fetch()){
1355       $acl = new acl($this->config,$this->parent,$attrs['dn']);
1356       foreach($acl->gosaAclEntry as $id => $entry){
1357         foreach($entry['members'] as $m_id => $member){
1358           if($m_id == "U:".$src){
1359             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1360             $new = "U:".$dst;
1361             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1362             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1363           }
1364           if($m_id == "G:".$src){
1365             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1366             $new = "G:".$dst;
1367             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1368             gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1369           }
1370         }
1371       }
1372       $acl -> save();
1373     }
1374   }
1376   
1377   // We are only interessted in our own acls ... 
1378   function set_acl_category($category)
1379   {
1380     plugin::set_acl_category("acl");
1381   }
1384 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1385 ?>