Code

centered picture
[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) && $this->parent != NULL){
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     }
103     /* Extract available categories from plugin info list */
104     foreach ($plist as $class => $acls){
106       /* Only feed categories */
107       if (isset($acls['plCategory'])){
109         /* Walk through supplied list and feed only translated categories */
110         foreach($acls['plCategory'] as $idx => $data){
112           /* Non numeric index means -> base object containing more informations */
113           if (preg_match('/^[0-9]+$/', $idx)){
114             if (!isset($this->ocMapping[$data])){
115               $this->ocMapping[$data]= array();
116               $this->ocMapping[$data][]= '0';
117             }
118             $this->ocMapping[$data][]= $class;
119           } else {
120             if (!isset($this->ocMapping[$idx])){
121               $this->ocMapping[$idx]= array();
122               $this->ocMapping[$idx][]= '0';
123             }
124             $this->ocMapping[$idx][]= $class;
125             $this->aclObjects[$idx]= $data['description'];
127             /* Additionally filter the classes we're interested in in "self edit" mode */
128             if (is_array($data['objectClass'])){
129               foreach($data['objectClass'] as $objectClass){
130                 if (in_array_ics($objectClass, $oc)){
131                   $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
132                   break;
133                 }
134               }
135             } else {
136               if (in_array_ics($data['objectClass'], $oc)){
137                 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
138               }
139             }
140           }
142         }
143       }
144     }
145     $this->aclObjects['all']= '*&nbsp;'._("All categories");
146     $this->ocMapping['all']= array('0' => 'all');
148     /* Sort categories */
149     asort($this->aclObjects);
151     /* Fill acl types */
152     if ($this->isContainer){
153       $this->aclTypes= array("reset" => _("Reset ACLs"),
154                              "one" => _("One level"),
155                              "base" => _("Current object"),
156                              "sub" => _("Complete subtree"),
157                              "psub" => _("Complete subtree (permanent)"));
158                              //"role" => _("Use ACL defined in role"));
159     } else {
160       $this->aclTypes= array("base" => _("Current object"),
161           "role" => _("Use ACL defined in role"));
162     }
163     asort($this->aclTypes);
164     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
165     asort($this->targets);
167     /* Finally - we want to get saved... */
168     $this->is_account= TRUE;
169   }
172   function execute()
173   {
174     /* Call parent execute */
175     plugin::execute();
177     $tmp= get_global('plist');
178     $plist= $tmp->info;
180     /* Handle posts */
181     if (isset($_POST['new_acl'])){
182       $this->dialogState= 'create';
183       $this->dialog= TRUE;
184       $this->currentIndex= count($this->gosaAclEntry);
185       $this->loadAclEntry(TRUE);
186     }
188     $new_acl= array();
189     $aclDialog= FALSE;
190     foreach($_POST as $name => $post){
192       /* Actions... */
193       if (preg_match('/^acl_edit_.*_x/', $name)){
194         $this->dialogState= 'create';
195         $this->dialog= TRUE;
196         $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
197         $this->loadAclEntry();
198         continue;
199       }
200       if (preg_match('/^acl_del_.*_x/', $name)){
201         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
202         continue;
203       }
205       if (preg_match('/^cat_edit_.*_x/', $name)){
206         $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
207         $this->dialogState= 'edit';
208         foreach ($this->ocMapping[$this->aclObject] as $oc){
209           if (isset($this->aclContents[$oc])){
210             $this->savedAclContents[$oc]= $this->aclContents[$oc];
211           }
212         }
213         continue;
214       }
215       if (preg_match('/^cat_del_.*_x/', $name)){
216         $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
217         foreach ($this->ocMapping[$idx] as $key){
218           unset($this->aclContents[$key]);
219         }
220         continue;
221       }
223       /* Sorting... */
224       if (preg_match('/^sortup_.*_x/', $name)){
225         $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
226         if ($index > 0){
227           $tmp= $this->gosaAclEntry[$index];
228           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
229           $this->gosaAclEntry[$index-1]= $tmp;
230         }
231         continue;
232       }
233       if (preg_match('/^sortdown_.*_x/', $name)){
234         $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
235         if ($index < count($this->gosaAclEntry)-1){
236           $tmp= $this->gosaAclEntry[$index];
237           $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
238           $this->gosaAclEntry[$index+1]= $tmp;
239         }
240         continue;
241       }
243       /* ACL saving... */
244       if (preg_match('/^acl_.*_[^xy]$/', $name)){
245         $aclDialog= TRUE;
246         list($dummy, $object, $attribute, $value)= split('_', $name);
248         /* Ordinary ACLs */
249         if (!isset($new_acl[$object])){
250           $new_acl[$object]= array();
251         }
252         if (isset($new_acl[$object][$attribute])){
253           $new_acl[$object][$attribute].= $value;
254         } else {
255           $new_acl[$object][$attribute]= $value;
256         }
257       }
258     }
259     
260     /* Only be interested in new acl's, if we're in the right _POST place */
261     if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
262       foreach ($this->ocMapping[$this->aclObject] as $oc){
263         unset($this->aclContents[$oc]);
264         unset($this->aclContents[$this->aclObject.'/'.$oc]);
265         if (isset($new_acl[$oc])){
266           $this->aclContents[$oc]= $new_acl[$oc];
267         }
268         if (isset($new_acl[$this->aclObject.'/'.$oc])){
269           $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$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       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
453         if ($idx == 0){
454           continue;
455         }
456         $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
457       }
458       if ($this->aclObject == 'all'){
459         $aclObjects['all']= _("All objects in current subtree");
460       }
461       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
462     }
464     /* Show main page */
465     $smarty->assign("dialogState", $this->dialogState);
467     return ($smarty->fetch (get_template_path('acl.tpl')));
468   }
470   
471   function buildAclSelector($list)
472   {
473     $display= "";
474     $cols= 3;
475     $tmp= get_global('plist');
476     $plist= $tmp->info;
477     asort($plist);
479     /* Build general objects */
480     foreach ($list as $key => $name){
482       /* Create sub acl if it does not exist */
483       if (!isset($this->aclContents[$key])){
484         $this->aclContents[$key]= array();
485         $this->aclContents[$key][0]= '';
486       }
487       $currentAcl= $this->aclContents[$key];
489       /* Object header */
490       if($_SESSION['js']) {
491         if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
492           $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
493                      "\n  <tr>".
494                      "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
495                      "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
496                      "\n    <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
497                      "\n  </tr>";
498         } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
499           $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
500                      "\n  <tr>".
501                      "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
502                      "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
503                      "\n    <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
504                      "\n  </tr>";
505         } else {
506           $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
507                      "\n  <tr>".
508                      "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
509                      "\n  </tr>";
510         }
511       } else {
512           $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
513                      "\n  <tr>".
514                      "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
515                      "\n  </tr>";
516       }
518       /* Generate options */
519       $spc= "&nbsp;&nbsp;";
520       if ($this->isContainer && $this->aclType != 'base'){
521         $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
522         $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
523         $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
524         if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
525           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
526         }
527       } else {
528         $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
529         $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
530         if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
531           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
532         }
533       }
535       /* Global options */
536       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $currentAcl[0])).$spc;
537       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
539       $display.= "\n  <tr>".
540                  "\n    <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
541                  "\n    <td style='background-color:#D4D4D4'>&nbsp;".("Complete object:")." $more_options</td>".
542                  "\n  </tr>";
544       /* Walk through the list of attributes */
545       $cnt= 1;
546       $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
547       asort($splist);
548       if($_SESSION['js']) {
549         if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
550           $display.= "\n  <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
551                      "\n    <td colspan=".$cols.">".
552                      "\n      <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
553                      "\n        <table style='width:100%;'>";
554         } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
555           $display.= "\n  <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
556                      "\n    <td colspan=".$cols.">".
557                      "\n      <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='position:absolute;overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
558                      "\n        <table style='width:100%;'>";
559         }
560       }
561       foreach($splist as $attr => $dsc){
563         /* Skip pl* attributes, they are internal... */
564         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
565           continue;
566         }
568         /* Open table row */
569         if ($cnt == 1){
570           $display.= "\n  <tr>";
571         }
573         /* Close table row */
574         if ($cnt == $cols){
575           $cnt= 1;
576           $rb= "";
577           $end= "\n  </tr>";
578         } else {
579           $cnt++;
580           $rb= "border-right:1px solid #A0A0A0;";
581           $end= "";
582         }
584         /* Collect list of attributes */
585         $state= "";
586         if (isset($currentAcl[$attr])){
587           $state= $currentAcl[$attr];
588         }
589         $display.= "\n    <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
590                    "\n      <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
591       }
592       
593       /* Fill missing td's if needed */
594       if (--$cnt != $cols && $cnt != 0){
595        $display.= str_repeat("\n    <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
596       }
598       if($_SESSION['js']) {
599         if(isset($_SERVER['HTTP_USER_AGENT']) && (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
600           $display.= "\n        </table>".
601                      "\n      </div>".
602                      "\n    </td>".
603                      "\n  </tr>";
604         }
605       }
607       $display.= "\n</table><br />\n";
608     }
610     return ($display);
611   }
614   function mkchkbx($name, $text, $state= FALSE)
615   {
616     $state= $state?"checked":"";
617     return "\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."' type=checkbox name='acl_$name' $state>".
618            "\n      <label for='acl_$name'>$text</label>";
619   }
622   function mkrwbx($name, $state= "")
623   {
624     $rstate= preg_match('/r/', $state)?'checked':'';
625     $wstate= preg_match('/w/', $state)?'checked':'';
626     return ("\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_r' type=checkbox name='acl_${name}_r' $rstate>".
627             "\n      <label for='acl_${name}_r'>"._("read")."</label>".
628             "\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_w' type=checkbox name='acl_${name}_w' $wstate>".
629             "\n      <label for='acl_${name}_w'>"._("write")."</label>");
630   }
633   function explodeACL($acl)
634   {
635     list($index, $type)= split(':', $acl);
636     $a= array( $index => array("type" => $type,
637                                "members" => acl::extractMembers($acl)));
638     
639     /* Handle different types */
640     switch ($type){
642       case 'psub':
643       case 'sub':
644       case 'one':
645       case 'base':
646         $a[$index]['acl']= acl::extractACL($acl);
647         break;
648       
649       case 'role':
650         echo "Role";
651         break;
653       case 'reset':
654         break;
655       
656       default:
657         print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
658         $a= array();
659     }
660     
661     return ($a);
662   }
665   function extractMembers($acl)
666   {
667     global $config;
668     $a= array();
670     /* Rip acl off the string, seperate by ',' and place it in an array */
671     $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
672     if ($ms == $acl){
673       return $a;
674     }
675     $ma= split(',', $ms);
677     /* Decode dn's, fill with informations from LDAP */
678     $ldap= $config->get_ldap_link();
679     foreach ($ma as $memberdn){
680       $dn= base64_decode($memberdn);
681       $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
683       /* Found entry... */
684       if ($ldap->count()){
685         $attrs= $ldap->fetch();
686         if (in_array_ics('gosaAccount', $attrs['objectClass'])){
687           $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
688         } else {
689           $a['G:'.$dn]= $attrs['cn'][0];
690           if (isset($attrs['description'][0])){
691             $a['G:'.$dn].= " [".$attrs['description'][0]."]";
692           }
693         }
695       /* ... or not */
696       } else {
697         $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
698       }
699     }
701     return ($a);
702   }
705   function extractACL($acl)
706   {
707     /* Rip acl off the string, seperate by ',' and place it in an array */
708     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
709     $aa= split(',', $as);
710     $a= array();
712     /* Dis-assemble single ACLs */
713     foreach($aa as $sacl){
714       
715       /* Dis-assemble field ACLs */
716       $ao= split('#', $sacl);
717       $gobject= "";
718       foreach($ao as $idx => $ssacl){
720         /* First is department with global acl */
721         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
722         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
723         if ($idx == 0){
724           /* Create hash for this object */
725           $gobject= $object;
726           $a[$gobject]= array();
728           /* Append ACL if set */
729           if ($gacl != ""){
730             $a[$gobject]= array($gacl);
731           }
732         } else {
734           /* All other entries get appended... */
735           list($field, $facl)= split(';', $ssacl);
736           $a[$gobject][$field]= $facl;
737         }
739       }
740     }
742     return ($a);
743   }
745   
746   function assembleAclSummary($entry)
747   {
748     $summary= "";
750     /* Summarize ACL */
751     if (isset($entry['acl'])){
752       $acl= "";
753       foreach ($entry['acl'] as $name => $object){
754         if (count($object)){
755           $acl.= "$name, ";
756         }
757       }
758       $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
759     }
761     /* Summarize members */
762     if ($summary != ""){
763       $summary.= ", ";
764     }
765     if (count($entry['members'])){
766       $summary.= _("Members:")." ";
767       foreach ($entry['members'] as $cn){
768         $cn= preg_replace('/ \[.*$/', '', $cn);
769         $summary.= $cn.", ";
770       }
771     } else {
772       $summary.= _("ACL is valid for all users");
773     }
775     return (preg_replace('/, $/', '', $summary));
776   }
779   function loadAclEntry($new= FALSE)
780   {
781     /* New entry gets presets... */
782     if ($new){
783       $this->aclType= 'base';
784       $this->recipients= array();
785       $this->aclContents= array();
786     } else {
787       $acl= $this->gosaAclEntry[$this->currentIndex];
788       $this->aclType= $acl['type'];
789       $this->recipients= $acl['members'];
790       $this->aclContents= $acl['acl'];
791     }
793     $this->wasNewEntry= $new;
794   }
797   function aclPostHandler()
798   {
799     if (isset($_POST['save_acl'])){
800       $this->save();
801       return TRUE;
802     }
804     return FALSE;
805   }
808   function save()
809   {
810     /* Assemble ACL's */
811     $tmp_acl= array();
812     foreach ($this->gosaAclEntry as $prio => $entry){
813       $final= "";
814       $members= "";
815       if (isset($entry['members'])){
816         foreach ($entry['members'] as $key => $dummy){
817           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
818         }
819       }
820       $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
822       /* ACL's if needed */
823       if ($entry['type'] != "reset" && $entry['type'] != "role"){
824         $acl= ":";
825         if (isset($entry['acl'])){
826           foreach ($entry['acl'] as $object => $contents){
828             /* Only save, if we've some contents in there... */
829             if (count($contents)){
830               $acl.= $object.";";
832               foreach($contents as $attr => $permission){
834                 /* First entry? Its the one for global settings... */
835                 if ($attr == '0'){
836                   $acl.= $permission;
837                 } else {
838                   $acl.= '#'.$attr.';'.$permission;
839                 }
841               }
842               $acl.= ',';
843             }
844             
845           }
846         }
847         $final.= preg_replace('/,$/', '', $acl);
848       }
850       $tmp_acl[]= $final;
851     } 
853     /* Call main method */
854     plugin::save();
856     /* Finally (re-)assign it... */
857     $this->attrs['gosaAclEntry']= $tmp_acl;
859     /* Remove acl from this entry if it is empty... */
860     if (!count($tmp_acl)){
861       /* Remove attribute */
862       if ($this->initially_was_account){
863         $this->attrs['gosaAclEntry']= array();
864       } else {
865         if (isset($this->attrs['gosaAclEntry'])){
866           unset($this->attrs['gosaAclEntry']);
867         }
868       }
870       /* Remove object class */
871       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
872     }    
874     /* Do LDAP modifications */
875     $ldap= $this->config->get_ldap_link();
876     $ldap->cd($this->dn);
877     $this->cleanup();
878     $ldap->modify ($this->attrs);
880     show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
882     /* Refresh users ACLs */
883     $ui= get_userinfo();
884     $ui->loadACL();
885     $_SESSION['ui']= $ui;
886   }
889   function remove_from_parent()
890   {
891   }
895 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
896 ?>