Code

fe19f9a7ef7e24253a36cfb8685e47dc39d7e92e
[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 $multiClass= array();
31   var $savedAclContents= array();
34   function acl ($config, $parent, $dn= NULL)
35   {
36     /* Include config object */
37     plugin::plugin($config, $dn);
39     /* Load ACL's */
40     $this->gosaAclEntry= array();
41     if (isset($this->attrs['gosaAclEntry'])){
42       for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
43         $acl= $this->attrs['gosaAclEntry'][$i];
44         $this->gosaAclEntry= array_merge($this->gosaAclEntry, $this->explodeACL($acl));
45       }
46     }
47     ksort($this->gosaAclEntry);
49     /* Save parent - we've to know more about it than other plugins... */
50     $this->parent= $parent;
52     /* Container? */
53     if (preg_match('/^(ou|c|l|dc)=/i', $dn)){
54       $this->isContainer= TRUE;
55     }
57     /* Users */
58     $ui= get_userinfo();
59     $tag= $ui->gosaUnitTag;
60     $ldap= $config->get_ldap_link();
61     $ldap->cd($config->current['BASE']);
62     if ($tag == ""){
63       $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
64     } else {
65       $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
66     }
67     while ($attrs= $ldap->fetch()){
68       $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
69     }
70     ksort($this->users);
72     /* Groups */
73     $ldap->cd($config->current['BASE']);
74     if ($tag == ""){
75       $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
76     } else {
77       $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
78     }
79     while ($attrs= $ldap->fetch()){
80       $dsc= "";
81       if (isset($attrs['description'][0])){
82         $dsc= $attrs['description'][0];
83       }
84       $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
85     }
86     ksort($this->groups);
88     /* Objects */
89     $tmp= get_global('plist');
90     $plist= $tmp->info;
91     if (isset($this->parent) && $this->parent != NULL){
92       $oc= array();
93       foreach ($this->parent->by_object as $key => $obj){
94         $oc= array_merge($oc, $obj->objectclasses);
95       }
96       if (in_array_ics('organizationalUnit', $oc)){
97         $this->isContainer= TRUE;
98       }
99     } else {
100       $oc=  $this->attrs['objectClass'];
101     }
104     /* Extract available categories from plugin info list */
105     foreach ($plist as $class => $acls){
107       /* Only feed categories */
108       if (isset($acls['plCategory'])){
110         /* Find multi homed classes */
111         if (count($acls['plCategory']) > 1){
112           $this->multiClass[]= $class;
113         }
115         /* Walk through supplied list and feed only translated categories */
116         foreach($acls['plCategory'] as $idx => $data){
118           /* Non numeric index means -> base object containing more informations */
119           if (preg_match('/^[0-9]+$/', $idx)){
120             if (!isset($this->ocMapping[$data])){
121               $this->ocMapping[$data]= array();
122               $this->ocMapping[$data][]= '0';
123             }
124             $this->ocMapping[$data][]= $class;
125           } else {
126             if (!isset($this->ocMapping[$idx])){
127               $this->ocMapping[$idx]= array();
128               $this->ocMapping[$idx][]= '0';
129             }
130             $this->ocMapping[$idx][]= $class;
131             $this->aclObjects[$idx]= $data['description'];
133             /* Additionally filter the classes we're interested in in "self edit" mode */
134             if (is_array($data['objectClass'])){
135               foreach($data['objectClass'] as $objectClass){
136                 if (in_array_ics($objectClass, $oc)){
137                   $this->myAclObjects[$class]= $acls['plDescription'];
138                   break;
139                 }
140               }
141             } else {
142               if (in_array_ics($data['objectClass'], $oc)){
143                 $this->myAclObjects[$class]= $acls['plDescription'];
144               }
145             }
146           }
148         }
149       }
150     }
152     /* Sort categories */
153     asort($this->aclObjects);
155     /* Fill acl types */
156     if ($this->isContainer){
157       $this->aclTypes= array("reset" => _("Reset ACLs"),
158                              "one" => _("One level"),
159                              "base" => _("Current object"),
160                              "sub" => _("Complete subtree"),
161                              "psub" => _("Complete subtree (permanent)"));
162                              //"role" => _("Use ACL defined in role"));
163     } else {
164       $this->aclTypes= array("base" => _("Current object"),
165           "role" => _("Use ACL defined in role"));
166     }
167     asort($this->aclTypes);
168     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
169     asort($this->targets);
171     /* Finally - we want to get saved... */
172     $this->is_account= TRUE;
173   }
176   function execute()
177   {
178     /* Call parent execute */
179     plugin::execute();
181     $tmp= get_global('plist');
182     $plist= $tmp->info;
184     /* Handle posts */
185     if (isset($_POST['new_acl'])){
186       $this->dialogState= 'create';
187       $this->dialog= TRUE;
188       $this->currentIndex= count($this->gosaAclEntry);
189       $this->loadAclEntry(TRUE);
190     }
192     $new_acl= array();
193     $aclDialog= FALSE;
194     foreach($_POST as $name => $post){
196       /* Actions... */
197       if (preg_match('/^acl_edit_.*_x/', $name)){
198         $this->dialogState= 'create';
199         $this->dialog= TRUE;
200         $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
201         $this->loadAclEntry();
202         continue;
203       }
204       if (preg_match('/^acl_del_.*_x/', $name)){
205         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
206         continue;
207       }
209       if (preg_match('/^cat_edit_.*_x/', $name)){
210         $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
211         $this->dialogState= 'edit';
212         foreach ($this->ocMapping[$this->aclObject] as $oc){
213           if (isset($this->aclContents[$oc])){
214             $this->savedAclContents[$oc]= $this->aclContents[$oc];
215           }
216         }
217         continue;
218       }
219       if (preg_match('/^cat_del_.*_x/', $name)){
220         $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
221         foreach ($this->ocMapping[$idx] as $key){
222           unset($this->aclContents[$key]);
223         }
224         continue;
225       }
227       /* Sorting... */
228       if (preg_match('/^sortup_.*_x/', $name)){
229         $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
230         if ($index > 0){
231           $tmp= $this->gosaAclEntry[$index];
232           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
233           $this->gosaAclEntry[$index-1]= $tmp;
234         }
235         continue;
236       }
237       if (preg_match('/^sortdown_.*_x/', $name)){
238         $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
239         if ($index < count($this->gosaAclEntry)-1){
240           $tmp= $this->gosaAclEntry[$index];
241           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
242           $this->gosaAclEntry[$index+1]= $tmp;
243         }
244         continue;
245       }
247       /* ACL saving... */
248       if (preg_match('/^acl_.*_[^xy]$/', $name)){
249         $aclDialog= TRUE;
250         list($dummy, $object, $attribute, $value)= split('_', $name);
252         /* Ordinary ACLs */
253         if (!isset($new_acl[$object])){
254           $new_acl[$object]= array();
255         }
256         if (isset($new_acl[$object][$attribute])){
257           $new_acl[$object][$attribute].= $value;
258         } else {
259           $new_acl[$object][$attribute]= $value;
260         }
261       }
262     }
263     
264     /* Only be interested in new acl's, if we're in the right _POST place */
265     if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
266       foreach ($this->ocMapping[$this->aclObject] as $oc){
267         unset($this->aclContents[$oc]);
268         if (isset($new_acl[$oc])){
269           $this->aclContents[$oc]= $new_acl[$oc];
270         }
271       }
272     }
274     /* Save new acl in case of base edit mode */
275     if ($this->aclType == 'base'){
276       $this->aclContents= $new_acl;
277     }
279     /* Cancel new acl? */
280     if (isset($_POST['cancel_new_acl'])){
281       $this->dialogState= 'head';
282       $this->dialog= FALSE;
283       if ($this->wasNewEntry){
284         unset ($this->gosaAclEntry[$this->currentIndex]);
285       }
286     }
288     /* Store ACL in main object? */
289     if (isset($_POST['submit_new_acl'])){
290       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
291       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
292       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
293       $this->dialogState= 'head';
294       $this->dialog= FALSE;
295     }
297     /* Cancel edit acl? */
298     if (isset($_POST['cancel_edit_acl'])){
299       $this->dialogState= 'create';
300       foreach ($this->ocMapping[$this->aclObject] as $oc){
301         if (isset($this->savedAclContents[$oc])){
302           $this->aclContents[$oc]= $this->savedAclContents[$oc];
303         }
304       }
305     }
307     /* Save edit acl? */
308     if (isset($_POST['submit_edit_acl'])){
309       $this->dialogState= 'create';
310     }
312     /* Add acl? */
313     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
314       $this->dialogState= 'edit';
315       $this->savedAclContents= array();
316       foreach ($this->ocMapping[$this->aclObject] as $oc){
317         if (isset($this->aclContents[$oc])){
318           $this->savedAclContents[$oc]= $this->aclContents[$oc];
319         }
320       }
321     }
323     /* Add to list? */
324     if (isset($_POST['add']) && isset($_POST['source'])){
325       foreach ($_POST['source'] as $key){
326         if ($this->target == 'user'){
327           $this->recipients[$key]= $this->users[$key];
328         }
329         if ($this->target == 'group'){
330           $this->recipients[$key]= $this->groups[$key];
331         }
332       }
333       ksort($this->recipients);
334     }
336     /* Remove from list? */
337     if (isset($_POST['del']) && isset($_POST['recipient'])){
338       foreach ($_POST['recipient'] as $key){
339           unset($this->recipients[$key]);
340       }
341     }
343     /* Save common values */
344     foreach (array("aclType", "aclObject", "target") as $key){
345       if (isset($_POST[$key])){
346         $this->$key= validate($_POST[$key]);
347       }
348     }
350     /* Create templating instance */
351     $smarty= get_smarty();
353     if ($this->dialogState == 'head'){
354       /* Draw list */
355       $aclList= new DivSelectBox("aclList");
356       $aclList->SetHeight(450);
357       
358       /* Fill in entries */
359       foreach ($this->gosaAclEntry as $key => $entry){
360         $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
361         $field2= array("string" => $this->assembleAclSummary($entry));
362         $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
363         $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
364         $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
365         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
367         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
368         $aclList->AddEntry(array($field1, $field2, $field3));
369       }
371       $smarty->assign("aclList", $aclList->DrawList());
372     }
374     if ($this->dialogState == 'create'){
375       /* Draw list */
376       $aclList= new DivSelectBox("aclList");
377       $aclList->SetHeight(150);
379       /* Add settings for all categories to the (permanent) list */
380       foreach ($this->aclObjects as $section => $dsc){
381         $summary= "";
382         foreach($this->ocMapping[$section] as $oc){
383           if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
384               $this->aclContents[$oc][0] != ""){
386             $summary.= "$oc, ";
387             continue;
388           }
389           if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
390               $this->aclContents["$section/$oc"][0] != ""){
392             $summary.= "$oc, ";
393             continue;
394           }
395           if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
396             $summary.= "$oc, ";
397           }
398         }
400         /* Set summary... */
401         if ($summary == ""){
402           $summary= '<i>'._("No ACL settings for this category").'</i>';
403         } else {
404           $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
405         }
407         $field1= array("string" => $dsc, "attach" => "style='width:100px'");
408         $field2= array("string" => $summary);
409         $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$section' title='"._("Edit categories ACLs")."'>";
410         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$section' title='"._("Clear categories ACLs")."'>";
411         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
412         $aclList->AddEntry(array($field1, $field2, $field3));
413       }
415       $smarty->assign("aclList", $aclList->DrawList());
416       $smarty->assign("aclType", $this->aclType);
417       $smarty->assign("aclTypes", $this->aclTypes);
418       $smarty->assign("target", $this->target);
419       $smarty->assign("targets", $this->targets);
421       /* Assign possible target types */
422       $smarty->assign("targets", $this->targets);
423       foreach ($this->attributes as $attr){
424         $smarty->assign($attr, $this->$attr);
425       }
428       /* Generate list */
429       $tmp= array();
430       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
431         if ($this->target == $field){
432           foreach ($this->$arr as $key => $value){
433             if (!isset($this->recipients[$key])){
434               $tmp[$key]= $value;
435             }
436           }
437         }
438       }
439       $smarty->assign('sources', $tmp);
440       $smarty->assign('recipients', $this->recipients);
442       /* Acl selector if scope is base */
443       if ($this->aclType == 'base'){
444         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
445       }
446     }
448     if ($this->dialogState == 'edit'){
449       $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
451       /* Collect objects for selected category */
452       $aclObjects= array();
453       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
454         if ($idx == 0){
455           continue;
456         }
457         $aclObjects[$class]= $plist[$class]['plDescription'];
458       }
459       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
460     }
462     /* Show main page */
463     $smarty->assign("dialogState", $this->dialogState);
465     return ($smarty->fetch (get_template_path('acl.tpl')));
466   }
468   
469   function buildAclSelector($list)
470   {
471     $display= "";
472     $cols= 3;
473     $tmp= get_global('plist');
474     $plist= $tmp->info;
475     asort($plist);
477     /* Build general objects */
478     foreach ($list as $key => $name){
480       /* Create sub acl if it does not exist */
481       if (!isset($this->aclContents[$key])){
482         $this->aclContents[$key]= array();
483         $this->aclContents[$key][0]= '';
484       }
485       $currentAcl= $this->aclContents[$key];
487       /* Object header */
488       $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").": $name</b></td></tr>";
490       /* Generate options */
491       $spc= "&nbsp;&nbsp;";
492       if ($this->isContainer && $this->aclType != 'base'){
493         $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
494         $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
495         $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
496         if ($plist[$key]['plSelfModify']){
497           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
498         }
499       } else {
500         $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
501         $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
502         if ($plist[$key]['plSelfModify']){
503           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
504         }
505       }
507       /* Global options */
508       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $currentAcl[0])).$spc;
509       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
511       $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'>&nbsp;".("Complete object:")." $more_options</td></tr>";
513       /* Walk through the list of attributes */
514       $cnt= 1;
515       $splist= $plist[$key]['plProvidedAcls'];
516       asort($splist);
517       foreach($splist as $attr => $dsc){
519         /* Skip pl* attributes, they are internal... */
520         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
521           continue;
522         }
524         /* Open table row */
525         if ($cnt == 1){
526           $display.= "<tr>";
527         }
529         /* Close table row */
530         if ($cnt == $cols){
531           $cnt= 1;
532           $rb= "";
533           $end= "</tr>";
534         } else {
535           $cnt++;
536           $rb= "border-right:1px solid #A0A0A0;";
537           $end= "";
538         }
540         /* Collect list of attributes */
541         $state= "";
542         if (isset($currentAcl[$attr])){
543           $state= $currentAcl[$attr];
544         }
545         $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";
546       }
547       
548       /* Fill missing td's if needed */
549       if (--$cnt != $cols && $cnt != 0){
550        $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
551       }
553       $display.= "</table><br>";
554     }
556     return ($display);
557   }
560   function mkchkbx($name, $text, $state= FALSE)
561   {
562     $state= $state?"checked":"";
563     return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
564   }
567   function mkrwbx($name, $state= "")
568   {
569     $rstate= preg_match('/r/', $state)?'checked':'';
570     $wstate= preg_match('/w/', $state)?'checked':'';
571     return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
572             "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
573   }
576   function explodeACL($acl)
577   {
578     list($index, $type)= split(':', $acl);
579     $a= array( $index => array("type" => $type,
580                                "members" => acl::extractMembers($acl)));
581     
582     /* Handle different types */
583     switch ($type){
585       case 'psub':
586       case 'sub':
587       case 'one':
588       case 'base':
589         $a[$index]['acl']= acl::extractACL($acl);
590         break;
591       
592       case 'role':
593         echo "Role";
594         break;
596       case 'reset':
597         break;
598       
599       default:
600         print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
601         $a= array();
602     }
603     
604     return ($a);
605   }
608   function extractMembers($acl)
609   {
610     global $config;
611     $a= array();
613     /* Rip acl off the string, seperate by ',' and place it in an array */
614     $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
615     if ($ms == $acl){
616       return $a;
617     }
618     $ma= split(',', $ms);
620     /* Decode dn's, fill with informations from LDAP */
621     $ldap= $config->get_ldap_link();
622     foreach ($ma as $memberdn){
623       $dn= base64_decode($memberdn);
624       $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
626       /* Found entry... */
627       if ($ldap->count()){
628         $attrs= $ldap->fetch();
629         if (in_array_ics('gosaAccount', $attrs['objectClass'])){
630           $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
631         } else {
632           $a['G:'.$dn]= $attrs['cn'][0];
633           if (isset($attrs['description'][0])){
634             $a['G:'.$dn].= " [".$attrs['description'][0]."]";
635           }
636         }
638       /* ... or not */
639       } else {
640         $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
641       }
642     }
644     return ($a);
645   }
648   function extractACL($acl)
649   {
650     /* Rip acl off the string, seperate by ',' and place it in an array */
651     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
652     $aa= split(',', $as);
653     $a= array();
655     /* Dis-assemble single ACLs */
656     foreach($aa as $sacl){
657       
658       /* Dis-assemble field ACLs */
659       $ao= split('#', $sacl);
660       $gobject= "";
661       foreach($ao as $idx => $ssacl){
663         /* First is department with global acl */
664         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
665         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
666         if ($idx == 0){
667           /* Create hash for this object */
668           $gobject= $object;
669           $a[$gobject]= array();
671           /* Append ACL if set */
672           if ($gacl != ""){
673             $a[$gobject]= array($gacl);
674           }
675         } else {
677           /* All other entries get appended... */
678           list($field, $facl)= split(';', $ssacl);
679           $a[$gobject][$field]= $facl;
680         }
682       }
683     }
685     return ($a);
686   }
688   
689   function assembleAclSummary($entry)
690   {
691     $summary= "";
693     /* Summarize ACL */
694     if (isset($entry['acl'])){
695       $acl= "";
696       foreach ($entry['acl'] as $name => $object){
697         if (count($object)){
698           $acl.= "$name, ";
699         }
700       }
701       $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
702     }
704     /* Summarize members */
705     if ($summary != ""){
706       $summary.= ", ";
707     }
708     if (count($entry['members'])){
709       $summary.= _("Members:")." ";
710       foreach ($entry['members'] as $cn){
711         $cn= preg_replace('/ \[.*$/', '', $cn);
712         $summary.= $cn.", ";
713       }
714     } else {
715       $summary.= _("ACL is valid for all users");
716     }
718     return (preg_replace('/, $/', '', $summary));
719   }
722   function loadAclEntry($new= FALSE)
723   {
724     /* New entry gets presets... */
725     if ($new){
726       $this->aclType= 'base';
727       $this->recipients= array();
728       $this->aclContents= array();
729     } else {
730       $acl= $this->gosaAclEntry[$this->currentIndex];
731       $this->aclType= $acl['type'];
732       $this->recipients= $acl['members'];
733       $this->aclContents= $acl['acl'];
734     }
736     $this->wasNewEntry= $new;
737   }
740   function aclPostHandler()
741   {
742     if (isset($_POST['save_acl'])){
743       $this->save();
744       return TRUE;
745     }
747     return FALSE;
748   }
751   function save()
752   {
753     /* Assemble ACL's */
754     $tmp_acl= array();
755     foreach ($this->gosaAclEntry as $prio => $entry){
756       $final= "";
757       $members= "";
758       if (isset($entry['members'])){
759         foreach ($entry['members'] as $key => $dummy){
760           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
761         }
762       }
763       $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
765       /* ACL's if needed */
766       if ($entry['type'] != "reset" && $entry['type'] != "role"){
767         $acl= ":";
768         if (isset($entry['acl'])){
769           foreach ($entry['acl'] as $object => $contents){
771             /* Only save, if we've some contents in there... */
772             if (count($contents)){
773               $acl.= $object.";";
775               foreach($contents as $attr => $permission){
777                 /* First entry? Its the one for global settings... */
778                 if ($attr == '0'){
779                   $acl.= $permission;
780                 } else {
781                   $acl.= '#'.$attr.';'.$permission;
782                 }
784               }
785               $acl.= ',';
786             }
787             
788           }
789         }
790         $final.= preg_replace('/,$/', '', $acl);
791       }
793       $tmp_acl[]= $final;
794     } 
796     /* Call main method */
797     plugin::save();
799     /* Finally (re-)assign it... */
800     $this->attrs['gosaAclEntry']= $tmp_acl;
802     /* Remove acl from this entry if it is empty... */
803     if (!count($tmp_acl)){
804       /* Remove attribute */
805       if ($this->initially_was_account){
806         $this->attrs['gosaAclEntry']= array();
807       } else {
808         if (isset($this->attrs['gosaAclEntry'])){
809           unset($this->attrs['gosaAclEntry']);
810         }
811       }
813       /* Remove object class */
814       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
815     }    
817     /* Do LDAP modifications */
818     $ldap= $this->config->get_ldap_link();
819     $ldap->cd($this->dn);
820     $this->cleanup();
821     $ldap->modify ($this->attrs);
823     show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
825     /* Refresh users ACLs */
826     $ui= get_userinfo();
827     $ui->loadACL();
828     $_SESSION['ui']= $ui;
829   }
832   function remove_from_parent()
833   {
834   }
838 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
839 ?>