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