Code

8103ba16e8e4a756dfbf215a447f9113d656eeef
[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]= $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                   if (isset($this->multiClass[$class])){
138                     $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
139                   } else {
140                     $this->myAclObjects[$class]= $acls['plDescription'];
141                   }
142                   break;
143                 }
144               }
145             } else {
146               if (in_array_ics($data['objectClass'], $oc)){
147                 if (isset($this->multiClass[$class])){
148                   $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
149                 } else {
150                   $this->myAclObjects[$class]= $acls['plDescription'];
151                 }
152               }
153             }
154           }
156         }
157       }
158     }
160     /* Sort categories */
161     asort($this->aclObjects);
163     /* Fill acl types */
164     if ($this->isContainer){
165       $this->aclTypes= array("reset" => _("Reset ACLs"),
166                              "one" => _("One level"),
167                              "base" => _("Current object"),
168                              "sub" => _("Complete subtree"),
169                              "psub" => _("Complete subtree (permanent)"));
170                              //"role" => _("Use ACL defined in role"));
171     } else {
172       $this->aclTypes= array("base" => _("Current object"),
173           "role" => _("Use ACL defined in role"));
174     }
175     asort($this->aclTypes);
176     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
177     asort($this->targets);
179     /* Finally - we want to get saved... */
180     $this->is_account= TRUE;
181   }
184   function execute()
185   {
186     /* Call parent execute */
187     plugin::execute();
189     $tmp= get_global('plist');
190     $plist= $tmp->info;
192     /* Handle posts */
193     if (isset($_POST['new_acl'])){
194       $this->dialogState= 'create';
195       $this->dialog= TRUE;
196       $this->currentIndex= count($this->gosaAclEntry);
197       $this->loadAclEntry(TRUE);
198     }
200     $new_acl= array();
201     $aclDialog= FALSE;
202     foreach($_POST as $name => $post){
204       /* Actions... */
205       if (preg_match('/^acl_edit_.*_x/', $name)){
206         $this->dialogState= 'create';
207         $this->dialog= TRUE;
208         $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
209         $this->loadAclEntry();
210         continue;
211       }
212       if (preg_match('/^acl_del_.*_x/', $name)){
213         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
214         continue;
215       }
217       if (preg_match('/^cat_edit_.*_x/', $name)){
218         $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
219         $this->dialogState= 'edit';
220         foreach ($this->ocMapping[$this->aclObject] as $oc){
221           if (isset($this->aclContents[$oc])){
222             $this->savedAclContents[$oc]= $this->aclContents[$oc];
223           }
224         }
225         continue;
226       }
227       if (preg_match('/^cat_del_.*_x/', $name)){
228         $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
229         foreach ($this->ocMapping[$idx] as $key){
230           unset($this->aclContents[$key]);
231         }
232         continue;
233       }
235       /* Sorting... */
236       if (preg_match('/^sortup_.*_x/', $name)){
237         $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
238         if ($index > 0){
239           $tmp= $this->gosaAclEntry[$index];
240           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
241           $this->gosaAclEntry[$index-1]= $tmp;
242         }
243         continue;
244       }
245       if (preg_match('/^sortdown_.*_x/', $name)){
246         $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
247         if ($index < count($this->gosaAclEntry)-1){
248           $tmp= $this->gosaAclEntry[$index];
249           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
250           $this->gosaAclEntry[$index+1]= $tmp;
251         }
252         continue;
253       }
255       /* ACL saving... */
256       if (preg_match('/^acl_.*_[^xy]$/', $name)){
257         $aclDialog= TRUE;
258         list($dummy, $object, $attribute, $value)= split('_', $name);
260         /* Ordinary ACLs */
261         if (!isset($new_acl[$object])){
262           $new_acl[$object]= array();
263         }
264         if (isset($new_acl[$object][$attribute])){
265           $new_acl[$object][$attribute].= $value;
266         } else {
267           $new_acl[$object][$attribute]= $value;
268         }
269       }
270     }
271     
272     /* Only be interested in new acl's, if we're in the right _POST place */
273     if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
274       foreach ($this->ocMapping[$this->aclObject] as $oc){
275         unset($this->aclContents[$oc]);
276         unset($this->aclContents[$this->aclObject.'/'.$oc]);
277         if (isset($new_acl[$oc])){
278           $this->aclContents[$oc]= $new_acl[$oc];
279         }
280         if (isset($new_acl[$this->aclObject.'/'.$oc])){
281           $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
282         }
283       }
284     }
286     /* Save new acl in case of base edit mode */
287     if ($this->aclType == 'base'){
288       $this->aclContents= $new_acl;
289     }
291     /* Cancel new acl? */
292     if (isset($_POST['cancel_new_acl'])){
293       $this->dialogState= 'head';
294       $this->dialog= FALSE;
295       if ($this->wasNewEntry){
296         unset ($this->gosaAclEntry[$this->currentIndex]);
297       }
298     }
300     /* Store ACL in main object? */
301     if (isset($_POST['submit_new_acl'])){
302       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
303       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
304       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
305       $this->dialogState= 'head';
306       $this->dialog= FALSE;
307     }
309     /* Cancel edit acl? */
310     if (isset($_POST['cancel_edit_acl'])){
311       $this->dialogState= 'create';
312       foreach ($this->ocMapping[$this->aclObject] as $oc){
313         if (isset($this->savedAclContents[$oc])){
314           $this->aclContents[$oc]= $this->savedAclContents[$oc];
315         }
316       }
317     }
319     /* Save edit acl? */
320     if (isset($_POST['submit_edit_acl'])){
321       $this->dialogState= 'create';
322     }
324     /* Add acl? */
325     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
326       $this->dialogState= 'edit';
327       $this->savedAclContents= array();
328       foreach ($this->ocMapping[$this->aclObject] as $oc){
329         if (isset($this->aclContents[$oc])){
330           $this->savedAclContents[$oc]= $this->aclContents[$oc];
331         }
332       }
333     }
335     /* Add to list? */
336     if (isset($_POST['add']) && isset($_POST['source'])){
337       foreach ($_POST['source'] as $key){
338         if ($this->target == 'user'){
339           $this->recipients[$key]= $this->users[$key];
340         }
341         if ($this->target == 'group'){
342           $this->recipients[$key]= $this->groups[$key];
343         }
344       }
345       ksort($this->recipients);
346     }
348     /* Remove from list? */
349     if (isset($_POST['del']) && isset($_POST['recipient'])){
350       foreach ($_POST['recipient'] as $key){
351           unset($this->recipients[$key]);
352       }
353     }
355     /* Save common values */
356     foreach (array("aclType", "aclObject", "target") as $key){
357       if (isset($_POST[$key])){
358         $this->$key= validate($_POST[$key]);
359       }
360     }
362     /* Create templating instance */
363     $smarty= get_smarty();
365     if ($this->dialogState == 'head'){
366       /* Draw list */
367       $aclList= new DivSelectBox("aclList");
368       $aclList->SetHeight(450);
369       
370       /* Fill in entries */
371       foreach ($this->gosaAclEntry as $key => $entry){
372         $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
373         $field2= array("string" => $this->assembleAclSummary($entry));
374         $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
375         $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
376         $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
377         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
379         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
380         $aclList->AddEntry(array($field1, $field2, $field3));
381       }
383       $smarty->assign("aclList", $aclList->DrawList());
384     }
386     if ($this->dialogState == 'create'){
387       /* Draw list */
388       $aclList= new DivSelectBox("aclList");
389       $aclList->SetHeight(150);
391       /* Add settings for all categories to the (permanent) list */
392       foreach ($this->aclObjects as $section => $dsc){
393         $summary= "";
394         foreach($this->ocMapping[$section] as $oc){
395           if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
396               $this->aclContents[$oc][0] != ""){
398             $summary.= "$oc, ";
399             continue;
400           }
401           if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
402               $this->aclContents["$section/$oc"][0] != ""){
404             $summary.= "$oc, ";
405             continue;
406           }
407           if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
408             $summary.= "$oc, ";
409           }
410         }
412         /* Set summary... */
413         if ($summary == ""){
414           $summary= '<i>'._("No ACL settings for this category").'</i>';
415         } else {
416           $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
417         }
419         $field1= array("string" => $dsc, "attach" => "style='width:100px'");
420         $field2= array("string" => $summary);
421         $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$section' title='"._("Edit categories ACLs")."'>";
422         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$section' title='"._("Clear categories ACLs")."'>";
423         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
424         $aclList->AddEntry(array($field1, $field2, $field3));
425       }
427       $smarty->assign("aclList", $aclList->DrawList());
428       $smarty->assign("aclType", $this->aclType);
429       $smarty->assign("aclTypes", $this->aclTypes);
430       $smarty->assign("target", $this->target);
431       $smarty->assign("targets", $this->targets);
433       /* Assign possible target types */
434       $smarty->assign("targets", $this->targets);
435       foreach ($this->attributes as $attr){
436         $smarty->assign($attr, $this->$attr);
437       }
440       /* Generate list */
441       $tmp= array();
442       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
443         if ($this->target == $field){
444           foreach ($this->$arr as $key => $value){
445             if (!isset($this->recipients[$key])){
446               $tmp[$key]= $value;
447             }
448           }
449         }
450       }
451       $smarty->assign('sources', $tmp);
452       $smarty->assign('recipients', $this->recipients);
454       /* Acl selector if scope is base */
455       if ($this->aclType == 'base'){
456         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
457       }
458     }
460     if ($this->dialogState == 'edit'){
461       $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
463       /* Collect objects for selected category */
464       $aclObjects= array();
465       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
466         if ($idx == 0){
467           continue;
468         }
469         if (isset($this->multiClass[$class])){
470           $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
471         } else {
472           $aclObjects[$class]= $plist[$class]['plDescription'];
473         }
474       }
475       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
476     }
478     /* Show main page */
479     $smarty->assign("dialogState", $this->dialogState);
481     return ($smarty->fetch (get_template_path('acl.tpl')));
482   }
484   
485   function buildAclSelector($list)
486   {
487     $display= "";
488     $cols= 3;
489     $tmp= get_global('plist');
490     $plist= $tmp->info;
491     asort($plist);
493     /* Build general objects */
494     foreach ($list as $key => $name){
496       /* Create sub acl if it does not exist */
497       if (!isset($this->aclContents[$key])){
498         $this->aclContents[$key]= array();
499         $this->aclContents[$key][0]= '';
500       }
501       $currentAcl= $this->aclContents[$key];
503       /* Object header */
504       $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>";
506       /* Generate options */
507       $spc= "&nbsp;&nbsp;";
508       if ($this->isContainer && $this->aclType != 'base'){
509         $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
510         $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
511         $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
512         if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
513           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
514         }
515       } else {
516         $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
517         $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
518         if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
519           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
520         }
521       }
523       /* Global options */
524       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $currentAcl[0])).$spc;
525       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
527       $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'>&nbsp;".("Complete object:")." $more_options</td></tr>";
529       /* Walk through the list of attributes */
530       $cnt= 1;
531       $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
532       asort($splist);
533       foreach($splist as $attr => $dsc){
535         /* Skip pl* attributes, they are internal... */
536         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
537           continue;
538         }
540         /* Open table row */
541         if ($cnt == 1){
542           $display.= "<tr>";
543         }
545         /* Close table row */
546         if ($cnt == $cols){
547           $cnt= 1;
548           $rb= "";
549           $end= "</tr>";
550         } else {
551           $cnt++;
552           $rb= "border-right:1px solid #A0A0A0;";
553           $end= "";
554         }
556         /* Collect list of attributes */
557         $state= "";
558         if (isset($currentAcl[$attr])){
559           $state= $currentAcl[$attr];
560         }
561         $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";
562       }
563       
564       /* Fill missing td's if needed */
565       if (--$cnt != $cols && $cnt != 0){
566        $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
567       }
569       $display.= "</table><br>";
570     }
572     return ($display);
573   }
576   function mkchkbx($name, $text, $state= FALSE)
577   {
578     $state= $state?"checked":"";
579     return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
580   }
583   function mkrwbx($name, $state= "")
584   {
585     $rstate= preg_match('/r/', $state)?'checked':'';
586     $wstate= preg_match('/w/', $state)?'checked':'';
587     return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
588             "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
589   }
592   function explodeACL($acl)
593   {
594     list($index, $type)= split(':', $acl);
595     $a= array( $index => array("type" => $type,
596                                "members" => acl::extractMembers($acl)));
597     
598     /* Handle different types */
599     switch ($type){
601       case 'psub':
602       case 'sub':
603       case 'one':
604       case 'base':
605         $a[$index]['acl']= acl::extractACL($acl);
606         break;
607       
608       case 'role':
609         echo "Role";
610         break;
612       case 'reset':
613         break;
614       
615       default:
616         print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
617         $a= array();
618     }
619     
620     return ($a);
621   }
624   function extractMembers($acl)
625   {
626     global $config;
627     $a= array();
629     /* Rip acl off the string, seperate by ',' and place it in an array */
630     $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
631     if ($ms == $acl){
632       return $a;
633     }
634     $ma= split(',', $ms);
636     /* Decode dn's, fill with informations from LDAP */
637     $ldap= $config->get_ldap_link();
638     foreach ($ma as $memberdn){
639       $dn= base64_decode($memberdn);
640       $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
642       /* Found entry... */
643       if ($ldap->count()){
644         $attrs= $ldap->fetch();
645         if (in_array_ics('gosaAccount', $attrs['objectClass'])){
646           $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
647         } else {
648           $a['G:'.$dn]= $attrs['cn'][0];
649           if (isset($attrs['description'][0])){
650             $a['G:'.$dn].= " [".$attrs['description'][0]."]";
651           }
652         }
654       /* ... or not */
655       } else {
656         $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
657       }
658     }
660     return ($a);
661   }
664   function extractACL($acl)
665   {
666     /* Rip acl off the string, seperate by ',' and place it in an array */
667     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
668     $aa= split(',', $as);
669     $a= array();
671     /* Dis-assemble single ACLs */
672     foreach($aa as $sacl){
673       
674       /* Dis-assemble field ACLs */
675       $ao= split('#', $sacl);
676       $gobject= "";
677       foreach($ao as $idx => $ssacl){
679         /* First is department with global acl */
680         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
681         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
682         if ($idx == 0){
683           /* Create hash for this object */
684           $gobject= $object;
685           $a[$gobject]= array();
687           /* Append ACL if set */
688           if ($gacl != ""){
689             $a[$gobject]= array($gacl);
690           }
691         } else {
693           /* All other entries get appended... */
694           list($field, $facl)= split(';', $ssacl);
695           $a[$gobject][$field]= $facl;
696         }
698       }
699     }
701     return ($a);
702   }
704   
705   function assembleAclSummary($entry)
706   {
707     $summary= "";
709     /* Summarize ACL */
710     if (isset($entry['acl'])){
711       $acl= "";
712       foreach ($entry['acl'] as $name => $object){
713         if (count($object)){
714           $acl.= "$name, ";
715         }
716       }
717       $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
718     }
720     /* Summarize members */
721     if ($summary != ""){
722       $summary.= ", ";
723     }
724     if (count($entry['members'])){
725       $summary.= _("Members:")." ";
726       foreach ($entry['members'] as $cn){
727         $cn= preg_replace('/ \[.*$/', '', $cn);
728         $summary.= $cn.", ";
729       }
730     } else {
731       $summary.= _("ACL is valid for all users");
732     }
734     return (preg_replace('/, $/', '', $summary));
735   }
738   function loadAclEntry($new= FALSE)
739   {
740     /* New entry gets presets... */
741     if ($new){
742       $this->aclType= 'base';
743       $this->recipients= array();
744       $this->aclContents= array();
745     } else {
746       $acl= $this->gosaAclEntry[$this->currentIndex];
747       $this->aclType= $acl['type'];
748       $this->recipients= $acl['members'];
749       $this->aclContents= $acl['acl'];
750     }
752     $this->wasNewEntry= $new;
753   }
756   function aclPostHandler()
757   {
758     if (isset($_POST['save_acl'])){
759       $this->save();
760       return TRUE;
761     }
763     return FALSE;
764   }
767   function save()
768   {
769     /* Assemble ACL's */
770     $tmp_acl= array();
771     foreach ($this->gosaAclEntry as $prio => $entry){
772       $final= "";
773       $members= "";
774       if (isset($entry['members'])){
775         foreach ($entry['members'] as $key => $dummy){
776           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
777         }
778       }
779       $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
781       /* ACL's if needed */
782       if ($entry['type'] != "reset" && $entry['type'] != "role"){
783         $acl= ":";
784         if (isset($entry['acl'])){
785           foreach ($entry['acl'] as $object => $contents){
787             /* Only save, if we've some contents in there... */
788             if (count($contents)){
789               $acl.= $object.";";
791               foreach($contents as $attr => $permission){
793                 /* First entry? Its the one for global settings... */
794                 if ($attr == '0'){
795                   $acl.= $permission;
796                 } else {
797                   $acl.= '#'.$attr.';'.$permission;
798                 }
800               }
801               $acl.= ',';
802             }
803             
804           }
805         }
806         $final.= preg_replace('/,$/', '', $acl);
807       }
809       $tmp_acl[]= $final;
810     } 
812     /* Call main method */
813     plugin::save();
815     /* Finally (re-)assign it... */
816     $this->attrs['gosaAclEntry']= $tmp_acl;
818     /* Remove acl from this entry if it is empty... */
819     if (!count($tmp_acl)){
820       /* Remove attribute */
821       if ($this->initially_was_account){
822         $this->attrs['gosaAclEntry']= array();
823       } else {
824         if (isset($this->attrs['gosaAclEntry'])){
825           unset($this->attrs['gosaAclEntry']);
826         }
827       }
829       /* Remove object class */
830       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
831     }    
833     /* Do LDAP modifications */
834     $ldap= $this->config->get_ldap_link();
835     $ldap->cd($this->dn);
836     $this->cleanup();
837     $ldap->modify ($this->attrs);
839     show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
841     /* Refresh users ACLs */
842     $ui= get_userinfo();
843     $ui->loadACL();
844     $_SESSION['ui']= $ui;
845   }
848   function remove_from_parent()
849   {
850   }
854 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
855 ?>