Code

63f507622bd12441a1a6fc2bbf976b707f025070
[gosa.git] / include / class_acl.inc
1 <?php
3 class acl extends plugin
4 {
5   /* Definitions */
6   var $plHeadline= "Access control";
7   var $plDescription= "This does something";
9   /* attribute list for save action */
10   var $attributes= array('gosaAclEntry');
11   var $objectclasses= array('gosaAcl');
13   /* Helpers */
14   var $dialogState= "head";
15   var $gosaAclEntry= array();
16   var $aclType= "";
17   var $aclObject= "";
18   var $aclContents= array();
19   var $target= "group";
20   var $aclTypes= array();
21   var $aclObjects= array();
22   var $aclMyObjects= array();
23   var $users= array();
24   var $groups= array();
25   var $recipients= array();
26   var $isContainer= FALSE;
27   var $currentIndex= 0;
28   var $wasNewEntry= FALSE;
29   var $ocMapping= array();
30   var $savedAclContents= array();
33   function acl ($config, $parent, $dn= NULL)
34   {
35     /* Include config object */
36     plugin::plugin($config, $dn);
38     /* Load ACL's */
39     $this->gosaAclEntry= array();
40     if (isset($this->attrs['gosaAclEntry'])){
41       for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
42         $acl= $this->attrs['gosaAclEntry'][$i];
43         $this->gosaAclEntry= array_merge($this->gosaAclEntry, $this->explodeACL($acl));
44       }
45     }
46     ksort($this->gosaAclEntry);
48     /* Save parent - we've to know more about it than other plugins... */
49     $this->parent= $parent;
51     /* Container? */
52     if (preg_match('/^(ou|c|l|dc)=/i', $dn)){
53       $this->isContainer= TRUE;
54     }
56     /* Users */
57     $ui= get_userinfo();
58     $tag= $ui->gosaUnitTag;
59     $ldap= $config->get_ldap_link();
60     $ldap->cd($config->current['BASE']);
61     if ($tag == ""){
62       $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
63     } else {
64       $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
65     }
66     while ($attrs= $ldap->fetch()){
67       $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
68     }
69     ksort($this->users);
71     /* Groups */
72     $ldap->cd($config->current['BASE']);
73     if ($tag == ""){
74       $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
75     } else {
76       $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
77     }
78     while ($attrs= $ldap->fetch()){
79       $dsc= "";
80       if (isset($attrs['description'][0])){
81         $dsc= $attrs['description'][0];
82       }
83       $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
84     }
85     ksort($this->groups);
87     /* Objects */
88     $tmp= get_global('plist');
89     $plist= $tmp->info;
90     if (isset($this->parent)){
91       $oc= array();
92       foreach ($this->parent->by_object as $key => $obj){
93         $oc= array_merge($oc, $obj->objectclasses);
94       }
95       if (in_array_ics('organizationalUnit', $oc)){
96         $this->isContainer= TRUE;
97       }
98     } else {
99       $oc=  $this->attrs['objectClass'];
100     }
101     foreach ($plist as $class => $acls){
102       if (isset($acls['plDescription'])){
103         /* Only feed categories */
104         if (isset($acls['plDepends']['description'])){
105           $this->aclObjects[$acls['plDepends']['objectClass']]= $acls['plDepends']['description'];
106         }
108         /* Additionally filter the classes we're interested in in "self edit" mode */
109         if (in_array_ics($acls['plDepends']['objectClass'], $oc)){
110           $this->myAclObjects[$class]= $acls['plDescription'];
111         }
112       }
113     }
114     asort($this->aclObjects);
116     /* Generate mapping object */
117     foreach ($plist as $oc => $pl){
118       if (isset($pl['plDepends']['objectClass'])){
119         $class= $pl['plDepends']['objectClass'];
120         if (!isset($this->ocMapping[$class])){
121           $this->ocMapping[$class]= array();
122         }
123         $this->ocMapping[$class][]= $oc;
124       }
125     }
127     /* Fill acl types */
128     if ($this->isContainer){
129       $this->aclTypes= array("reset" => _("Reset ACLs"),
130                              "one" => _("One level"),
131                              "base" => _("Current object"),
132                              "sub" => _("Complete subtree"),
133                              "psub" => _("Complete subtree (permanent)"),
134                              "role" => _("Use ACL defined in role"));
135     } else {
136       $this->aclTypes= array("base" => _("Current object"),
137           "role" => _("Use ACL defined in role"));
138     }
139     asort($this->aclTypes);
140     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
141     asort($this->targets);
143     /* Finally - we want to get saved... */
144     $this->is_account= TRUE;
145   }
148   function execute()
149   {
150     /* Call parent execute */
151     plugin::execute();
153     $tmp= get_global('plist');
154     $plist= $tmp->info;
156     /* Handle posts */
157     if (isset($_POST['new_acl'])){
158       $this->dialogState= 'create';
159       $this->dialog= TRUE;
160       $this->currentIndex= count($this->gosaAclEntry);
161       $this->loadAclEntry(TRUE);
162     }
164     $new_acl= array();
165     $aclDialog= FALSE;
166     foreach($_POST as $name => $post){
168       /* Actions... */
169       if (preg_match('/^acl_edit_.*_x/', $name)){
170         $this->dialogState= 'create';
171         $this->dialog= TRUE;
172         $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
173         $this->loadAclEntry();
174         continue;
175       }
176       if (preg_match('/^acl_del_.*_x/', $name)){
177         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
178         continue;
179       }
181       if (preg_match('/^cat_edit_.*_x/', $name)){
182         $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
183         $this->dialogState= 'edit';
184         foreach ($this->ocMapping[$this->aclObject] as $oc){
185           if (isset($this->aclContents[$oc])){
186             $this->savedAclContents[$oc]= $this->aclContents[$oc];
187           }
188         }
189         continue;
190       }
191       if (preg_match('/^cat_del_.*_x/', $name)){
192         $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
193         foreach ($this->ocMapping[$idx] as $key){
194           unset($this->aclContents[$key]);
195         }
196         continue;
197       }
199       /* Sorting... */
200       if (preg_match('/^sortup_.*_x/', $name)){
201         $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
202         if ($index > 0){
203           $tmp= $this->gosaAclEntry[$index];
204           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
205           $this->gosaAclEntry[$index-1]= $tmp;
206         }
207         continue;
208       }
209       if (preg_match('/^sortdown_.*_x/', $name)){
210         $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
211         if ($index < count($this->gosaAclEntry)-1){
212           $tmp= $this->gosaAclEntry[$index];
213           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
214           $this->gosaAclEntry[$index+1]= $tmp;
215         }
216         continue;
217       }
219       /* ACL saving... */
220       if (preg_match('/^acl_.*_[^xy]$/', $name)){
221         $aclDialog= TRUE;
222         list($dummy, $object, $attribute, $value)= split('_', $name);
224         /* Ordinary ACLs */
225         if (!isset($new_acl[$object])){
226           $new_acl[$object]= array();
227         }
228         if (isset($new_acl[$object][$attribute])){
229           $new_acl[$object][$attribute].= $value;
230         } else {
231           $new_acl[$object][$attribute]= $value;
232         }
233       }
235     }
236     
237     /* Only be interested in new acl's, if we're in the right _POST place */
238     if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
239       foreach ($this->ocMapping[$this->aclObject] as $oc){
240         unset($this->aclContents[$oc]);
241         if (isset($new_acl[$oc])){
242           $this->aclContents[$oc]= $new_acl[$oc];
243         }
244       }
245     }
247     /* Cancel new acl? */
248     if (isset($_POST['cancel_new_acl'])){
249       $this->dialogState= 'head';
250       $this->dialog= FALSE;
251       if ($this->wasNewEntry){
252         unset ($this->gosaAclEntry[$this->currentIndex]);
253       }
254     }
256     /* Store ACL in mail object? */
257     if (isset($_POST['submit_new_acl'])){
258       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
259       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
260       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
261       $this->dialogState= 'head';
262       $this->dialog= FALSE;
263     }
265     /* Cancel edit acl? */
266     if (isset($_POST['cancel_edit_acl'])){
267       $this->dialogState= 'create';
268       foreach ($this->ocMapping[$this->aclObject] as $oc){
269         if (isset($this->savedAclContents[$oc])){
270           $this->aclContents[$oc]= $this->savedAclContents[$oc];
271         }
272       }
273     }
275     /* Save edit acl? */
276     if (isset($_POST['submit_edit_acl'])){
277       $this->dialogState= 'create';
278     }
280     /* Add acl? */
281     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
282       $this->dialogState= 'edit';
283       $this->savedAclContents= array();
284       foreach ($this->ocMapping[$this->aclObject] as $oc){
285         if (isset($this->aclContents[$oc])){
286           $this->savedAclContents[$oc]= $this->aclContents[$oc];
287         }
288       }
289     }
291     /* Add to list? */
292     if (isset($_POST['add']) && isset($_POST['source'])){
293       foreach ($_POST['source'] as $key){
294         if ($this->target == 'user'){
295           $this->recipients[$key]= $this->users[$key];
296         }
297         if ($this->target == 'group'){
298           $this->recipients[$key]= $this->groups[$key];
299         }
300       }
301       ksort($this->recipients);
302     }
304     /* Remove from list? */
305     if (isset($_POST['del']) && isset($_POST['recipient'])){
306       foreach ($_POST['recipient'] as $key){
307           unset($this->recipients[$key]);
308       }
309     }
311     /* Save common values */
312     foreach (array("aclType", "aclObject", "target") as $key){
313       if (isset($_POST[$key])){
314         $this->$key= validate($_POST[$key]);
315       }
316     }
318     /* Create templating instance */
319     $smarty= get_smarty();
321     if ($this->dialogState == 'head'){
322       /* Draw list */
323       $aclList= new DivSelectBox("aclList");
324       $aclList->SetHeight(450);
325       
326       /* Fill in entries */
327       foreach ($this->gosaAclEntry as $key => $entry){
328         $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
329         $field2= array("string" => $this->assembleAclSummary($entry));
330         $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
331         $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
332         $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
333         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
335         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
336         $aclList->AddEntry(array($field1, $field2, $field3));
337       }
339       $smarty->assign("aclList", $aclList->DrawList());
340     }
342     if ($this->dialogState == 'create'){
343       /* Draw list */
344       $aclList= new DivSelectBox("aclList");
345       $aclList->SetHeight(150);
347       /* Add settings for all categories to the (permanent) list */
348       foreach ($this->aclObjects as $oc => $dsc){
349         $summary= "";
350         foreach ($plist as $key => $plugin){
351           if (isset($plugin['plDepends']['objectClass']) && $plugin['plDepends']['objectClass'] == $oc &&
352               isset($this->aclContents[$key])){
353             if (count($this->aclContents[$key]) && isset($this->aclContents[$key][0]) &&
354                 $this->aclContents[$key][0] != ""){
355               $summary.= "$key, ";
356             }
357           }
358         }
360         /* Set summary... */
361         if ($summary == ""){
362           $summary= _("No ACL settings for this category");
363         } else {
364           $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
365         }
367         $field1= array("string" => $dsc, "attach" => "style='width:100px'");
368         $field2= array("string" => $summary);
369         $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$oc' title='"._("Edit categories ACLs")."'>";
370         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$oc' title='"._("Clear categories ACLs")."'>";
371         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
372         $aclList->AddEntry(array($field1, $field2, $field3));
373       }
375       $smarty->assign("aclList", $aclList->DrawList());
376       $smarty->assign("aclType", $this->aclType);
377       $smarty->assign("aclTypes", $this->aclTypes);
378       $smarty->assign("target", $this->target);
379       $smarty->assign("targets", $this->targets);
381       /* Assign possible target types */
382       $smarty->assign("targets", $this->targets);
383       foreach ($this->attributes as $attr){
384         $smarty->assign($attr, $this->$attr);
385       }
388       /* Generate list */
389       $tmp= array();
390       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
391         if ($this->target == $field){
392           foreach ($this->$arr as $key => $value){
393             if (!isset($this->recipients[$key])){
394               $tmp[$key]= $value;
395             }
396           }
397         }
398       }
399       $smarty->assign('sources', $tmp);
400       $smarty->assign('recipients', $this->recipients);
402       /* Acl selector if scope is base */
403       if ($this->aclType == 'base'){
404         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
405       }
406     }
408     if ($this->dialogState == 'edit'){
409       $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
411       /* Collect objects for selected category */
412       $aclObjects= array();
413       foreach ($plist as $class => $acls){
414         if (isset($acls['plDepends']['objectClass']) && $acls['plDepends']['objectClass'] == $this->aclObject){
415           $aclObjects[$class]= $acls['plDescription'];
416         }
417       }
419       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
420     }
422     /* Show main page */
423     $smarty->assign("dialogState", $this->dialogState);
424     return ($smarty->fetch (get_template_path('acl.tpl')));
425   }
427   
428   function buildAclSelector($list)
429   {
430     $display= "";
431     $cols= 4;
432     $tmp= get_global('plist');
433     $plist= $tmp->info;
434     asort($plist);
436     foreach ($list as $key => $name){
438       /* Create sub acl if it does not exist */
439       if (!isset($this->aclContents[$key])){
440         $this->aclContents[$key]= array();
441       }
442       if (!isset($this->aclContents[$key][0])){
443         $this->aclContents[$key][0]= '';
444       }
445       $currentAcl= $this->aclContents[$key];
447       /* Object header */
448       $display.= "<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2><tr><td style='background-color:#C8C8C8;height:1.8em' colspan=$cols><b>"._("Object").":</b> $name</td></tr>";
450       /* Generate options */
451       $spc= "&nbsp;&nbsp;";
452       if ($this->isContainer && $this->aclType != 'base'){
453         $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
454         $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
455         $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
456         if ($plist[$key]['plSelfModify']){
457           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
458         }
459       } else {
460         $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
461         $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
462         if ($plist[$key]['plSelfModify']){
463           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
464         }
465       }
467       $display.= "<tr><td style='background-color:#E0E0E0' colspan=$cols>$options</td></tr>";
469       /* Walk through the list of attributes */
470       $cnt= 1;
471       $splist= $plist[$key];
472       asort($splist);
473       foreach($splist as $attr => $dsc){
475         /* Skip pl* attributes, they are internal... */
476         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
477           continue;
478         }
480         /* Open table row */
481         if ($cnt == 1){
482           $display.= "<tr>";
483         }
485         /* Close table row */
486         if ($cnt == $cols){
487           $cnt= 1;
488           $rb= "";
489           $end= "</tr>";
490         } else {
491           $cnt++;
492           $rb= "border-right:1px solid #A0A0A0;";
493           $end= "";
494         }
496         /* Collect list of attributes */
497         $state= "";
498         if (isset($currentAcl[$attr])){
499           $state= $currentAcl[$attr];
500         }
501         $display.= "<td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'><b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
502       }
503       
504       /* Fill missing td's if needed */
505       if (--$cnt != $cols){
506        $display.= str_repeat("<td style='border-top:1px solid #A0A0A0'>&nbsp;</td>", $cols-$cnt); 
507       }
509       $display.= "</table><br>";
510     }
512     return ($display);
513   }
516   function mkchkbx($name, $text, $state= FALSE)
517   {
518     $state= $state?"checked":"";
519     return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
520   }
523   function mkrwbx($name, $state= "")
524   {
525     $rstate= preg_match('/r/', $state)?'checked':'';
526     $wstate= preg_match('/w/', $state)?'checked':'';
527     return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
528             "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
529   }
532   function explodeACL($acl)
533   {
534     list($index, $type)= split(':', $acl);
535     $a= array( $index => array("type" => $type,
536                                "members" => acl::extractMembers($acl)));
537     
538     /* Handle different types */
539     switch ($type){
541       case 'psub':
542       case 'sub':
543       case 'one':
544       case 'base':
545         $a[$index]['acl']= acl::extractACL($acl);
546         break;
547       
548       case 'role':
549         echo "Role";
550         break;
552       case 'reset':
553         break;
554       
555       default:
556         print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
557         $a= array();
558     }
559     
560     return ($a);
561   }
564   function extractMembers($acl)
565   {
566     global $config;
567     $a= array();
569     /* Rip acl off the string, seperate by ',' and place it in an array */
570     $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
571     if ($ms == $acl){
572       return $a;
573     }
574     $ma= split(',', $ms);
576     /* Decode dn's, fill with informations from LDAP */
577     $ldap= $config->get_ldap_link();
578     foreach ($ma as $memberdn){
579       $dn= base64_decode($memberdn);
580       $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
582       /* Found entry... */
583       if ($ldap->count()){
584         $attrs= $ldap->fetch();
585         if (in_array_ics('gosaAccount', $attrs['objectClass'])){
586           $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
587         } else {
588           $a['G:'.$dn]= $attrs['cn'][0];
589           if (isset($attrs['description'][0])){
590             $a['G:'.$dn].= " [".$attrs['description'][0]."]";
591           }
592         }
594       /* ... or not */
595       } else {
596         $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
597       }
598     }
600     return ($a);
601   }
604   function extractACL($acl)
605   {
606     /* Rip acl off the string, seperate by ',' and place it in an array */
607     $as= preg_replace('/^[^:]+:[^:]+:[^:]+:(.*)$/', '\1', $acl);
608     $aa= split(',', $as);
609     $a= array();
611     /* Dis-assemble single ACLs */
612     foreach($aa as $sacl){
613       
614       /* Dis-assemble field ACLs */
615       $ao= split('#', $sacl);
616       $gobject= "";
617       foreach($ao as $idx => $ssacl){
619         /* First is department with global acl */
620         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
621         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
622         if ($idx == 0){
623           /* Create hash for this object */
624           $gobject= $object;
625           $a[$gobject]= array();
627           /* Append ACL if set */
628           if ($gacl != ""){
629             $a[$gobject]= array($gacl);
630           }
631         } else {
633           /* All other entries get appended... */
634           list($field, $facl)= split(';', $ssacl);
635           $a[$gobject][$field]= $facl;
636         }
638       }
639     }
641     return ($a);
642   }
644   
645   function assembleAclSummary($entry)
646   {
647     $summary= "";
649     /* Summarize ACL */
650     if (isset($entry['acl'])){
651       $acl= "";
652       foreach ($entry['acl'] as $name => $object){
653         $acl.= "$name, ";
654       }
655       $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
656     }
658     /* Summarize members */
659     if ($summary != ""){
660       $summary.= ", ";
661     }
662     if (count($entry['members'])){
663       $summary.= _("Members:")." ";
664       foreach ($entry['members'] as $cn){
665         $cn= preg_replace('/ \[.*$/', '', $cn);
666         $summary.= $cn.", ";
667       }
668     } else {
669       $summary.= _("ACLs is valid for all users");
670     }
672     return (preg_replace('/, $/', '', $summary));
673   }
676   function loadAclEntry($new= FALSE)
677   {
678     /* New entry gets presets... */
679     if ($new){
680       $this->aclType= 'base';
681       $this->recipients= array();
682       $this->aclContents= array();
683     } else {
684       $acl= $this->gosaAclEntry[$this->currentIndex];
685       $this->aclType= $acl['type'];
686       $this->recipients= $acl['members'];
687       $this->aclContents= $acl['acl'];
688     }
690     $this->wasNewEntry= $new;
691   }
694   function aclPostHandler()
695   {
696     if (isset($_POST['save_acl'])){
697       $this->save();
698       return TRUE;
699     }
701     return FALSE;
702   }
705   function save()
706   {
707     /* Assemble ACL's */
708     $tmp_acl= array();
709     foreach ($this->gosaAclEntry as $prio => $entry){
710       $final= "";
711       $members= "";
712       if (isset($entry['members'])){
713         foreach ($entry['members'] as $key => $dummy){
714           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
715         }
716       }
717       $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
719       /* ACL's if needed */
720       if ($entry['type'] != "reset" && $entry['type'] != "role"){
721         $acl= ":";
722         if (isset($entry['acl'])){
723           foreach ($entry['acl'] as $object => $contents){
724             $acl.= $object.";";
725             
726             foreach($contents as $attr => $permission){
728               /* First entry? Its the one for global settings... */
729               if ($attr == '0'){
730                 $acl.= $permission;
731               } else {
732                 $acl.= '#'.$attr.';'.$permission;
733               }
735             }
736             $acl.= ',';
737             
738           }
739         }
740         $final.= preg_replace('/,$/', '', $acl);
741       }
743       $tmp_acl[]= $final;
744     } 
746     /* Call main method */
747     plugin::save();
749     /* Finally (re-)assign it... */
750     $this->attrs['gosaAclEntry']= $tmp_acl;
752     /* Remove acl from this entry if it is empty... */
753     if (!count($tmp_acl)){
754       /* Remove attribute */
755       if ($this->initially_was_account){
756         $this->attrs['gosaAclEntry']= array();
757       } else {
758         if (isset($this->attrs['gosaAclEntry'])){
759           unset($this->attrs['gosaAclEntry']);
760         }
761       }
763       /* Remove object class */
764       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
765     }    
767     /* Do LDAP modifications */
768     $ldap= $config->get_ldap_link();
769     $ldap->cd($this->dn);
770     $this->cleanup();
771     $ldap->modify ($this->attrs);
773     show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
774   }
777   function remove_from_parent()
778   {
779     echo "remove_from_parent() called";
780   }
784 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
785 ?>