1 <?php
3 class acl extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "Access control";
7 var $plDescription= "This does something";
9 /* attribute list for save action */
10 var $attributes= array('gosaAclEntry');
11 var $objectclasses= array('gosaAcl');
13 /* Helpers */
14 var $dialogState= "head";
15 var $gosaAclEntry= array();
16 var $aclType= "";
17 var $aclObject= "";
18 var $aclContents= array();
19 var $target= "group";
20 var $aclTypes= array();
21 var $aclObjects= array();
22 var $aclMyObjects= array();
23 var $users= array();
24 var $groups= array();
25 var $recipients= array();
26 var $isContainer= FALSE;
27 var $currentIndex= 0;
28 var $wasNewEntry= FALSE;
29 var $ocMapping= array();
30 var $savedAclContents= array();
33 function acl ($config, $parent, $dn= NULL)
34 {
35 /* Include config object */
36 plugin::plugin($config, $dn);
38 /* Load ACL's */
39 $this->gosaAclEntry= array();
40 if (isset($this->attrs['gosaAclEntry'])){
41 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
42 $acl= $this->attrs['gosaAclEntry'][$i];
43 $this->gosaAclEntry= array_merge($this->gosaAclEntry, $this->explodeACL($acl));
44 }
45 }
46 ksort($this->gosaAclEntry);
48 /* Save parent - we've to know more about it than other plugins... */
49 $this->parent= $parent;
51 /* Container? */
52 if (preg_match('/^(ou|c|l|dc)=/i', $dn)){
53 $this->isContainer= TRUE;
54 }
56 /* Users */
57 $ui= get_userinfo();
58 $tag= $ui->gosaUnitTag;
59 $ldap= $config->get_ldap_link();
60 $ldap->cd($config->current['BASE']);
61 if ($tag == ""){
62 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
63 } else {
64 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
65 }
66 while ($attrs= $ldap->fetch()){
67 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
68 }
69 ksort($this->users);
71 /* Groups */
72 $ldap->cd($config->current['BASE']);
73 if ($tag == ""){
74 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
75 } else {
76 $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
77 }
78 while ($attrs= $ldap->fetch()){
79 $dsc= "";
80 if (isset($attrs['description'][0])){
81 $dsc= $attrs['description'][0];
82 }
83 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
84 }
85 ksort($this->groups);
87 /* Objects */
88 $tmp= get_global('plist');
89 $plist= $tmp->info;
90 if (isset($this->parent)){
91 $oc= array();
92 foreach ($this->parent->by_object as $key => $obj){
93 $oc= array_merge($oc, $obj->objectclasses);
94 }
95 if (in_array_ics('organizationalUnit', $oc)){
96 $this->isContainer= TRUE;
97 }
98 } else {
99 $oc= $this->attrs['objectClass'];
100 }
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 (in_array_ics($data['objectClass'], $oc)){
129 $this->myAclObjects[$class]= $acls['plDescription'];
130 }
131 }
133 }
134 }
135 }
137 /* Sort categories */
138 asort($this->aclObjects);
141 /* Fill acl types */
142 if ($this->isContainer){
143 $this->aclTypes= array("reset" => _("Reset ACLs"),
144 "one" => _("One level"),
145 "base" => _("Current object"),
146 "sub" => _("Complete subtree"),
147 "psub" => _("Complete subtree (permanent)"));
148 //"role" => _("Use ACL defined in role"));
149 } else {
150 $this->aclTypes= array("base" => _("Current object"),
151 "role" => _("Use ACL defined in role"));
152 }
153 asort($this->aclTypes);
154 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
155 asort($this->targets);
157 /* Finally - we want to get saved... */
158 $this->is_account= TRUE;
159 }
162 function execute()
163 {
164 /* Call parent execute */
165 plugin::execute();
167 $tmp= get_global('plist');
168 $plist= $tmp->info;
170 /* Handle posts */
171 if (isset($_POST['new_acl'])){
172 $this->dialogState= 'create';
173 $this->dialog= TRUE;
174 $this->currentIndex= count($this->gosaAclEntry);
175 $this->loadAclEntry(TRUE);
176 }
178 $new_acl= array();
179 $aclDialog= FALSE;
180 foreach($_POST as $name => $post){
182 /* Actions... */
183 if (preg_match('/^acl_edit_.*_x/', $name)){
184 $this->dialogState= 'create';
185 $this->dialog= TRUE;
186 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
187 $this->loadAclEntry();
188 continue;
189 }
190 if (preg_match('/^acl_del_.*_x/', $name)){
191 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
192 continue;
193 }
195 if (preg_match('/^cat_edit_.*_x/', $name)){
196 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
197 $this->dialogState= 'edit';
198 foreach ($this->ocMapping[$this->aclObject] as $oc){
199 if (isset($this->aclContents[$oc])){
200 $this->savedAclContents[$oc]= $this->aclContents[$oc];
201 }
202 }
203 continue;
204 }
205 if (preg_match('/^cat_del_.*_x/', $name)){
206 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
207 foreach ($this->ocMapping[$idx] as $key){
208 unset($this->aclContents[$key]);
209 }
210 continue;
211 }
213 /* Sorting... */
214 if (preg_match('/^sortup_.*_x/', $name)){
215 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
216 if ($index > 0){
217 $tmp= $this->gosaAclEntry[$index];
218 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
219 $this->gosaAclEntry[$index-1]= $tmp;
220 }
221 continue;
222 }
223 if (preg_match('/^sortdown_.*_x/', $name)){
224 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
225 if ($index < count($this->gosaAclEntry)-1){
226 $tmp= $this->gosaAclEntry[$index];
227 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
228 $this->gosaAclEntry[$index+1]= $tmp;
229 }
230 continue;
231 }
233 /* ACL saving... */
234 if (preg_match('/^acl_.*_[^xy]$/', $name)){
235 $aclDialog= TRUE;
236 list($dummy, $object, $attribute, $value)= split('_', $name);
238 /* Ordinary ACLs */
239 if (!isset($new_acl[$object])){
240 $new_acl[$object]= array();
241 }
242 if (isset($new_acl[$object][$attribute])){
243 $new_acl[$object][$attribute].= $value;
244 } else {
245 $new_acl[$object][$attribute]= $value;
246 }
247 }
248 }
250 /* Only be interested in new acl's, if we're in the right _POST place */
251 if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
252 foreach ($this->ocMapping[$this->aclObject] as $oc){
253 unset($this->aclContents[$oc]);
254 if (isset($new_acl[$oc])){
255 $this->aclContents[$oc]= $new_acl[$oc];
256 }
257 }
258 }
260 /* Save new acl in case of base edit mode */
261 if ($this->aclType == 'base'){
262 $this->aclContents= $new_acl;
263 }
265 /* Cancel new acl? */
266 if (isset($_POST['cancel_new_acl'])){
267 $this->dialogState= 'head';
268 $this->dialog= FALSE;
269 if ($this->wasNewEntry){
270 unset ($this->gosaAclEntry[$this->currentIndex]);
271 }
272 }
274 /* Store ACL in main object? */
275 if (isset($_POST['submit_new_acl'])){
276 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
277 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
278 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
279 $this->dialogState= 'head';
280 $this->dialog= FALSE;
281 }
283 /* Cancel edit acl? */
284 if (isset($_POST['cancel_edit_acl'])){
285 $this->dialogState= 'create';
286 foreach ($this->ocMapping[$this->aclObject] as $oc){
287 if (isset($this->savedAclContents[$oc])){
288 $this->aclContents[$oc]= $this->savedAclContents[$oc];
289 }
290 }
291 }
293 /* Save edit acl? */
294 if (isset($_POST['submit_edit_acl'])){
295 $this->dialogState= 'create';
296 }
298 /* Add acl? */
299 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
300 $this->dialogState= 'edit';
301 $this->savedAclContents= array();
302 foreach ($this->ocMapping[$this->aclObject] as $oc){
303 if (isset($this->aclContents[$oc])){
304 $this->savedAclContents[$oc]= $this->aclContents[$oc];
305 }
306 }
307 }
309 /* Add to list? */
310 if (isset($_POST['add']) && isset($_POST['source'])){
311 foreach ($_POST['source'] as $key){
312 if ($this->target == 'user'){
313 $this->recipients[$key]= $this->users[$key];
314 }
315 if ($this->target == 'group'){
316 $this->recipients[$key]= $this->groups[$key];
317 }
318 }
319 ksort($this->recipients);
320 }
322 /* Remove from list? */
323 if (isset($_POST['del']) && isset($_POST['recipient'])){
324 foreach ($_POST['recipient'] as $key){
325 unset($this->recipients[$key]);
326 }
327 }
329 /* Save common values */
330 foreach (array("aclType", "aclObject", "target") as $key){
331 if (isset($_POST[$key])){
332 $this->$key= validate($_POST[$key]);
333 }
334 }
336 /* Create templating instance */
337 $smarty= get_smarty();
339 if ($this->dialogState == 'head'){
340 /* Draw list */
341 $aclList= new DivSelectBox("aclList");
342 $aclList->SetHeight(450);
344 /* Fill in entries */
345 foreach ($this->gosaAclEntry as $key => $entry){
346 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
347 $field2= array("string" => $this->assembleAclSummary($entry));
348 $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
349 $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
350 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
351 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
353 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
354 $aclList->AddEntry(array($field1, $field2, $field3));
355 }
357 $smarty->assign("aclList", $aclList->DrawList());
358 }
360 if ($this->dialogState == 'create'){
361 /* Draw list */
362 $aclList= new DivSelectBox("aclList");
363 $aclList->SetHeight(150);
365 /* Add settings for all categories to the (permanent) list */
366 foreach ($this->aclObjects as $section => $dsc){
367 $summary= "";
368 foreach($this->ocMapping[$section] as $oc){
369 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
370 $this->aclContents[$oc][0] != ""){
371 $summary.= "$oc, ";
372 continue;
373 }
374 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
375 $summary.= "$oc, ";
376 }
377 }
379 /* Set summary... */
380 if ($summary == ""){
381 $summary= '<i>'._("No ACL settings for this category").'</i>';
382 } else {
383 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
384 }
386 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
387 $field2= array("string" => $summary);
388 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$section' title='"._("Edit categories ACLs")."'>";
389 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$section' title='"._("Clear categories ACLs")."'>";
390 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
391 $aclList->AddEntry(array($field1, $field2, $field3));
392 }
394 $smarty->assign("aclList", $aclList->DrawList());
395 $smarty->assign("aclType", $this->aclType);
396 $smarty->assign("aclTypes", $this->aclTypes);
397 $smarty->assign("target", $this->target);
398 $smarty->assign("targets", $this->targets);
400 /* Assign possible target types */
401 $smarty->assign("targets", $this->targets);
402 foreach ($this->attributes as $attr){
403 $smarty->assign($attr, $this->$attr);
404 }
407 /* Generate list */
408 $tmp= array();
409 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
410 if ($this->target == $field){
411 foreach ($this->$arr as $key => $value){
412 if (!isset($this->recipients[$key])){
413 $tmp[$key]= $value;
414 }
415 }
416 }
417 }
418 $smarty->assign('sources', $tmp);
419 $smarty->assign('recipients', $this->recipients);
421 /* Acl selector if scope is base */
422 if ($this->aclType == 'base'){
423 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
424 }
425 }
427 if ($this->dialogState == 'edit'){
428 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
430 /* Collect objects for selected category */
431 $aclObjects= array();
432 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
433 if ($idx == 0){
434 continue;
435 }
436 $aclObjects[$class]= $plist[$class]['plDescription'];
437 }
438 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
439 }
441 /* Show main page */
442 $smarty->assign("dialogState", $this->dialogState);
444 return ($smarty->fetch (get_template_path('acl.tpl')));
445 }
448 function buildAclSelector($list)
449 {
450 $display= "";
451 $cols= 3;
452 $tmp= get_global('plist');
453 $plist= $tmp->info;
454 asort($plist);
456 /* Build general objects */
457 foreach ($list as $key => $name){
459 /* Create sub acl if it does not exist */
460 if (!isset($this->aclContents[$key])){
461 $this->aclContents[$key]= array();
462 $this->aclContents[$key][0]= '';
463 }
464 $currentAcl= $this->aclContents[$key];
466 /* Object header */
467 $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>";
469 /* Generate options */
470 $spc= " ";
471 if ($this->isContainer && $this->aclType != 'base'){
472 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
473 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
474 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
475 if ($plist[$key]['plSelfModify']){
476 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
477 }
478 } else {
479 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
480 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
481 if ($plist[$key]['plSelfModify']){
482 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
483 }
484 }
486 /* Global options */
487 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
488 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
490 $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td></tr>";
492 /* Walk through the list of attributes */
493 $cnt= 1;
494 $splist= $plist[$key]['plProvidedAcls'];
495 asort($splist);
496 foreach($splist as $attr => $dsc){
498 /* Skip pl* attributes, they are internal... */
499 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
500 continue;
501 }
503 /* Open table row */
504 if ($cnt == 1){
505 $display.= "<tr>";
506 }
508 /* Close table row */
509 if ($cnt == $cols){
510 $cnt= 1;
511 $rb= "";
512 $end= "</tr>";
513 } else {
514 $cnt++;
515 $rb= "border-right:1px solid #A0A0A0;";
516 $end= "";
517 }
519 /* Collect list of attributes */
520 $state= "";
521 if (isset($currentAcl[$attr])){
522 $state= $currentAcl[$attr];
523 }
524 $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";
525 }
527 /* Fill missing td's if needed */
528 if (--$cnt != $cols && $cnt != 0){
529 $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
530 }
532 $display.= "</table><br>";
533 }
535 return ($display);
536 }
539 function mkchkbx($name, $text, $state= FALSE)
540 {
541 $state= $state?"checked":"";
542 return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
543 }
546 function mkrwbx($name, $state= "")
547 {
548 $rstate= preg_match('/r/', $state)?'checked':'';
549 $wstate= preg_match('/w/', $state)?'checked':'';
550 return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
551 "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
552 }
555 function explodeACL($acl)
556 {
557 list($index, $type)= split(':', $acl);
558 $a= array( $index => array("type" => $type,
559 "members" => acl::extractMembers($acl)));
561 /* Handle different types */
562 switch ($type){
564 case 'psub':
565 case 'sub':
566 case 'one':
567 case 'base':
568 $a[$index]['acl']= acl::extractACL($acl);
569 break;
571 case 'role':
572 echo "Role";
573 break;
575 case 'reset':
576 break;
578 default:
579 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
580 $a= array();
581 }
583 return ($a);
584 }
587 function extractMembers($acl)
588 {
589 global $config;
590 $a= array();
592 /* Rip acl off the string, seperate by ',' and place it in an array */
593 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
594 if ($ms == $acl){
595 return $a;
596 }
597 $ma= split(',', $ms);
599 /* Decode dn's, fill with informations from LDAP */
600 $ldap= $config->get_ldap_link();
601 foreach ($ma as $memberdn){
602 $dn= base64_decode($memberdn);
603 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
605 /* Found entry... */
606 if ($ldap->count()){
607 $attrs= $ldap->fetch();
608 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
609 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
610 } else {
611 $a['G:'.$dn]= $attrs['cn'][0];
612 if (isset($attrs['description'][0])){
613 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
614 }
615 }
617 /* ... or not */
618 } else {
619 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
620 }
621 }
623 return ($a);
624 }
627 function extractACL($acl)
628 {
629 /* Rip acl off the string, seperate by ',' and place it in an array */
630 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
631 $aa= split(',', $as);
632 $a= array();
634 /* Dis-assemble single ACLs */
635 foreach($aa as $sacl){
637 /* Dis-assemble field ACLs */
638 $ao= split('#', $sacl);
639 $gobject= "";
640 foreach($ao as $idx => $ssacl){
642 /* First is department with global acl */
643 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
644 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
645 if ($idx == 0){
646 /* Create hash for this object */
647 $gobject= $object;
648 $a[$gobject]= array();
650 /* Append ACL if set */
651 if ($gacl != ""){
652 $a[$gobject]= array($gacl);
653 }
654 } else {
656 /* All other entries get appended... */
657 list($field, $facl)= split(';', $ssacl);
658 $a[$gobject][$field]= $facl;
659 }
661 }
662 }
664 return ($a);
665 }
668 function assembleAclSummary($entry)
669 {
670 $summary= "";
672 /* Summarize ACL */
673 if (isset($entry['acl'])){
674 $acl= "";
675 foreach ($entry['acl'] as $name => $object){
676 if (count($object)){
677 $acl.= "$name, ";
678 }
679 }
680 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
681 }
683 /* Summarize members */
684 if ($summary != ""){
685 $summary.= ", ";
686 }
687 if (count($entry['members'])){
688 $summary.= _("Members:")." ";
689 foreach ($entry['members'] as $cn){
690 $cn= preg_replace('/ \[.*$/', '', $cn);
691 $summary.= $cn.", ";
692 }
693 } else {
694 $summary.= _("ACL is valid for all users");
695 }
697 return (preg_replace('/, $/', '', $summary));
698 }
701 function loadAclEntry($new= FALSE)
702 {
703 /* New entry gets presets... */
704 if ($new){
705 $this->aclType= 'base';
706 $this->recipients= array();
707 $this->aclContents= array();
708 } else {
709 $acl= $this->gosaAclEntry[$this->currentIndex];
710 $this->aclType= $acl['type'];
711 $this->recipients= $acl['members'];
712 $this->aclContents= $acl['acl'];
713 }
715 $this->wasNewEntry= $new;
716 }
719 function aclPostHandler()
720 {
721 if (isset($_POST['save_acl'])){
722 $this->save();
723 return TRUE;
724 }
726 return FALSE;
727 }
730 function save()
731 {
732 /* Assemble ACL's */
733 $tmp_acl= array();
734 foreach ($this->gosaAclEntry as $prio => $entry){
735 $final= "";
736 $members= "";
737 if (isset($entry['members'])){
738 foreach ($entry['members'] as $key => $dummy){
739 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
740 }
741 }
742 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
744 /* ACL's if needed */
745 if ($entry['type'] != "reset" && $entry['type'] != "role"){
746 $acl= ":";
747 if (isset($entry['acl'])){
748 foreach ($entry['acl'] as $object => $contents){
750 /* Only save, if we've some contents in there... */
751 if (count($contents)){
752 $acl.= $object.";";
754 foreach($contents as $attr => $permission){
756 /* First entry? Its the one for global settings... */
757 if ($attr == '0'){
758 $acl.= $permission;
759 } else {
760 $acl.= '#'.$attr.';'.$permission;
761 }
763 }
764 $acl.= ',';
765 }
767 }
768 }
769 $final.= preg_replace('/,$/', '', $acl);
770 }
772 $tmp_acl[]= $final;
773 }
775 /* Call main method */
776 plugin::save();
778 /* Finally (re-)assign it... */
779 $this->attrs['gosaAclEntry']= $tmp_acl;
781 /* Remove acl from this entry if it is empty... */
782 if (!count($tmp_acl)){
783 /* Remove attribute */
784 if ($this->initially_was_account){
785 $this->attrs['gosaAclEntry']= array();
786 } else {
787 if (isset($this->attrs['gosaAclEntry'])){
788 unset($this->attrs['gosaAclEntry']);
789 }
790 }
792 /* Remove object class */
793 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
794 }
796 /* Do LDAP modifications */
797 $ldap= $this->config->get_ldap_link();
798 $ldap->cd($this->dn);
799 $this->cleanup();
800 $ldap->modify ($this->attrs);
802 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
803 }
806 function remove_from_parent()
807 {
808 }
810 }
812 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
813 ?>