cbd8a0c19e2ed5966a18649bfddb49a5c09df4d0
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 }
101 foreach ($plist as $class => $acls){
102 if (isset($acls['plDescription'])){
103 /* Only feed categories */
104 if (isset($acls['plDepends']['description'])){
105 $this->aclObjects[$acls['plDepends']['objectClass']]= $acls['plDepends']['description'];
106 }
108 /* Additionally filter the classes we're interested in in "self edit" mode */
109 if (in_array_ics($acls['plDepends']['objectClass'], $oc)){
110 $this->myAclObjects[$class]= $acls['plDescription'];
111 }
112 }
113 }
115 /* Add category for all objects */
116 asort($this->aclObjects);
118 /* Generate mapping object */
119 foreach ($plist as $oc => $pl){
120 if (isset($pl['plDepends']['objectClass'])){
121 $class= $pl['plDepends']['objectClass'];
122 if (!isset($this->ocMapping[$class])){
123 $this->ocMapping[$class]= array();
124 $this->ocMapping[$class][]= '0';
125 }
126 $this->ocMapping[$class][]= $oc;
127 }
128 }
130 /* Fill acl types */
131 if ($this->isContainer){
132 $this->aclTypes= array("reset" => _("Reset ACLs"),
133 "one" => _("One level"),
134 "base" => _("Current object"),
135 "sub" => _("Complete subtree"),
136 "psub" => _("Complete subtree (permanent)"));
137 //"role" => _("Use ACL defined in role"));
138 } else {
139 $this->aclTypes= array("base" => _("Current object"),
140 "role" => _("Use ACL defined in role"));
141 }
142 asort($this->aclTypes);
143 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
144 asort($this->targets);
146 /* Finally - we want to get saved... */
147 $this->is_account= TRUE;
148 }
151 function execute()
152 {
153 /* Call parent execute */
154 plugin::execute();
156 $tmp= get_global('plist');
157 $plist= $tmp->info;
159 /* Handle posts */
160 if (isset($_POST['new_acl'])){
161 $this->dialogState= 'create';
162 $this->dialog= TRUE;
163 $this->currentIndex= count($this->gosaAclEntry);
164 $this->loadAclEntry(TRUE);
165 }
167 $new_acl= array();
168 $aclDialog= FALSE;
169 foreach($_POST as $name => $post){
171 /* Actions... */
172 if (preg_match('/^acl_edit_.*_x/', $name)){
173 $this->dialogState= 'create';
174 $this->dialog= TRUE;
175 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
176 $this->loadAclEntry();
177 continue;
178 }
179 if (preg_match('/^acl_del_.*_x/', $name)){
180 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
181 continue;
182 }
184 if (preg_match('/^cat_edit_.*_x/', $name)){
185 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
186 $this->dialogState= 'edit';
187 foreach ($this->ocMapping[$this->aclObject] as $oc){
188 if (isset($this->aclContents[$oc])){
189 $this->savedAclContents[$oc]= $this->aclContents[$oc];
190 }
191 }
192 continue;
193 }
194 if (preg_match('/^cat_del_.*_x/', $name)){
195 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
196 foreach ($this->ocMapping[$idx] as $key){
197 unset($this->aclContents[$key]);
198 }
199 continue;
200 }
202 /* Sorting... */
203 if (preg_match('/^sortup_.*_x/', $name)){
204 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
205 if ($index > 0){
206 $tmp= $this->gosaAclEntry[$index];
207 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
208 $this->gosaAclEntry[$index-1]= $tmp;
209 }
210 continue;
211 }
212 if (preg_match('/^sortdown_.*_x/', $name)){
213 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
214 if ($index < count($this->gosaAclEntry)-1){
215 $tmp= $this->gosaAclEntry[$index];
216 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
217 $this->gosaAclEntry[$index+1]= $tmp;
218 }
219 continue;
220 }
222 /* ACL saving... */
223 if (preg_match('/^acl_.*_[^xy]$/', $name)){
224 $aclDialog= TRUE;
225 list($dummy, $object, $attribute, $value)= split('_', $name);
227 /* Ordinary ACLs */
228 if (!isset($new_acl[$object])){
229 $new_acl[$object]= array();
230 }
231 if (isset($new_acl[$object][$attribute])){
232 $new_acl[$object][$attribute].= $value;
233 } else {
234 $new_acl[$object][$attribute]= $value;
235 }
236 }
237 }
239 /* Only be interested in new acl's, if we're in the right _POST place */
240 if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
241 foreach ($this->ocMapping[$this->aclObject] as $oc){
242 unset($this->aclContents[$oc]);
243 if (isset($new_acl[$oc])){
244 $this->aclContents[$oc]= $new_acl[$oc];
245 }
246 }
247 }
249 /* Save new acl in case of base edit mode */
250 if ($this->aclType == 'base'){
251 $this->aclContents= $new_acl;
252 }
254 /* Cancel new acl? */
255 if (isset($_POST['cancel_new_acl'])){
256 $this->dialogState= 'head';
257 $this->dialog= FALSE;
258 if ($this->wasNewEntry){
259 unset ($this->gosaAclEntry[$this->currentIndex]);
260 }
261 }
263 /* Store ACL in main object? */
264 if (isset($_POST['submit_new_acl'])){
265 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
266 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
267 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
268 $this->dialogState= 'head';
269 $this->dialog= FALSE;
270 }
272 /* Cancel edit acl? */
273 if (isset($_POST['cancel_edit_acl'])){
274 $this->dialogState= 'create';
275 foreach ($this->ocMapping[$this->aclObject] as $oc){
276 if (isset($this->savedAclContents[$oc])){
277 $this->aclContents[$oc]= $this->savedAclContents[$oc];
278 }
279 }
280 }
282 /* Save edit acl? */
283 if (isset($_POST['submit_edit_acl'])){
284 $this->dialogState= 'create';
285 }
287 /* Add acl? */
288 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
289 $this->dialogState= 'edit';
290 $this->savedAclContents= array();
291 foreach ($this->ocMapping[$this->aclObject] as $oc){
292 if (isset($this->aclContents[$oc])){
293 $this->savedAclContents[$oc]= $this->aclContents[$oc];
294 }
295 }
296 }
298 /* Add to list? */
299 if (isset($_POST['add']) && isset($_POST['source'])){
300 foreach ($_POST['source'] as $key){
301 if ($this->target == 'user'){
302 $this->recipients[$key]= $this->users[$key];
303 }
304 if ($this->target == 'group'){
305 $this->recipients[$key]= $this->groups[$key];
306 }
307 }
308 ksort($this->recipients);
309 }
311 /* Remove from list? */
312 if (isset($_POST['del']) && isset($_POST['recipient'])){
313 foreach ($_POST['recipient'] as $key){
314 unset($this->recipients[$key]);
315 }
316 }
318 /* Save common values */
319 foreach (array("aclType", "aclObject", "target") as $key){
320 if (isset($_POST[$key])){
321 $this->$key= validate($_POST[$key]);
322 }
323 }
325 /* Create templating instance */
326 $smarty= get_smarty();
328 if ($this->dialogState == 'head'){
329 /* Draw list */
330 $aclList= new DivSelectBox("aclList");
331 $aclList->SetHeight(450);
333 /* Fill in entries */
334 foreach ($this->gosaAclEntry as $key => $entry){
335 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
336 $field2= array("string" => $this->assembleAclSummary($entry));
337 $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
338 $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
339 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
340 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
342 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
343 $aclList->AddEntry(array($field1, $field2, $field3));
344 }
346 $smarty->assign("aclList", $aclList->DrawList());
347 }
349 if ($this->dialogState == 'create'){
350 /* Draw list */
351 $aclList= new DivSelectBox("aclList");
352 $aclList->SetHeight(150);
354 /* Add settings for all categories to the (permanent) list */
355 foreach ($this->aclObjects as $oc => $dsc){
356 $summary= "";
357 foreach ($plist as $key => $plugin){
358 if (isset($plugin['plDepends']['objectClass']) && $plugin['plDepends']['objectClass'] == $oc &&
359 isset($this->aclContents[$key])){
360 if (count($this->aclContents[$key]) && isset($this->aclContents[$key][0]) &&
361 $this->aclContents[$key][0] != ""){
362 $summary.= "$key, ";
363 continue;
364 }
365 if (!isset($this->aclContents[$key][0]) && count($this->aclContents[$key])){
366 $summary.= "$key, ";
367 }
368 }
369 }
371 /* Set summary... */
372 if ($summary == ""){
373 $summary= '<i>'._("No ACL settings for this category").'</i>';
374 } else {
375 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
376 }
378 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
379 $field2= array("string" => $summary);
380 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$oc' title='"._("Edit categories ACLs")."'>";
381 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$oc' title='"._("Clear categories ACLs")."'>";
382 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
383 $aclList->AddEntry(array($field1, $field2, $field3));
384 }
386 $smarty->assign("aclList", $aclList->DrawList());
387 $smarty->assign("aclType", $this->aclType);
388 $smarty->assign("aclTypes", $this->aclTypes);
389 $smarty->assign("target", $this->target);
390 $smarty->assign("targets", $this->targets);
392 /* Assign possible target types */
393 $smarty->assign("targets", $this->targets);
394 foreach ($this->attributes as $attr){
395 $smarty->assign($attr, $this->$attr);
396 }
399 /* Generate list */
400 $tmp= array();
401 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
402 if ($this->target == $field){
403 foreach ($this->$arr as $key => $value){
404 if (!isset($this->recipients[$key])){
405 $tmp[$key]= $value;
406 }
407 }
408 }
409 }
410 $smarty->assign('sources', $tmp);
411 $smarty->assign('recipients', $this->recipients);
413 /* Acl selector if scope is base */
414 if ($this->aclType == 'base'){
415 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
416 }
417 }
419 if ($this->dialogState == 'edit'){
420 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
422 /* Collect objects for selected category */
423 $aclObjects= array();
425 foreach ($plist as $class => $acls){
426 if (isset($acls['plDepends']['objectClass']) && $acls['plDepends']['objectClass'] == $this->aclObject){
427 $aclObjects[$class]= $acls['plDescription'];
428 }
429 }
431 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
432 }
434 /* Show main page */
435 $smarty->assign("dialogState", $this->dialogState);
437 return ($smarty->fetch (get_template_path('acl.tpl')));
438 }
441 function buildAclSelector($list)
442 {
443 $display= "";
444 $cols= 4;
445 $tmp= get_global('plist');
446 $plist= $tmp->info;
447 asort($plist);
449 foreach ($list as $key => $name){
451 /* Create sub acl if it does not exist */
452 if (!isset($this->aclContents[$key])){
453 $this->aclContents[$key]= array();
454 }
455 if (!isset($this->aclContents[$key][0])){
456 $this->aclContents[$key][0]= '';
457 }
458 $currentAcl= $this->aclContents[$key];
460 /* Object header */
461 $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>";
463 /* Generate options */
464 $spc= " ";
465 if ($this->isContainer && $this->aclType != 'base'){
466 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
467 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
468 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
469 if ($plist[$key]['plSelfModify']){
470 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
471 }
472 } else {
473 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
474 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), 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 }
480 /* Global options */
481 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
482 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
484 $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td></tr>";
486 /* Walk through the list of attributes */
487 $cnt= 1;
488 $splist= $plist[$key];
489 asort($splist);
490 foreach($splist as $attr => $dsc){
492 /* Skip pl* attributes, they are internal... */
493 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
494 continue;
495 }
497 /* Open table row */
498 if ($cnt == 1){
499 $display.= "<tr>";
500 }
502 /* Close table row */
503 if ($cnt == $cols){
504 $cnt= 1;
505 $rb= "";
506 $end= "</tr>";
507 } else {
508 $cnt++;
509 $rb= "border-right:1px solid #A0A0A0;";
510 $end= "";
511 }
513 /* Collect list of attributes */
514 $state= "";
515 if (isset($currentAcl[$attr])){
516 $state= $currentAcl[$attr];
517 }
518 $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";
519 }
521 /* Fill missing td's if needed */
522 if (--$cnt != $cols && $cnt != 0){
523 $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
524 }
526 $display.= "</table><br>";
527 }
529 return ($display);
530 }
533 function mkchkbx($name, $text, $state= FALSE)
534 {
535 $state= $state?"checked":"";
536 return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
537 }
540 function mkrwbx($name, $state= "")
541 {
542 $rstate= preg_match('/r/', $state)?'checked':'';
543 $wstate= preg_match('/w/', $state)?'checked':'';
544 return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
545 "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
546 }
549 function explodeACL($acl)
550 {
551 list($index, $type)= split(':', $acl);
552 $a= array( $index => array("type" => $type,
553 "members" => acl::extractMembers($acl)));
555 /* Handle different types */
556 switch ($type){
558 case 'psub':
559 case 'sub':
560 case 'one':
561 case 'base':
562 $a[$index]['acl']= acl::extractACL($acl);
563 break;
565 case 'role':
566 echo "Role";
567 break;
569 case 'reset':
570 break;
572 default:
573 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
574 $a= array();
575 }
577 return ($a);
578 }
581 function extractMembers($acl)
582 {
583 global $config;
584 $a= array();
586 /* Rip acl off the string, seperate by ',' and place it in an array */
587 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
588 if ($ms == $acl){
589 return $a;
590 }
591 $ma= split(',', $ms);
593 /* Decode dn's, fill with informations from LDAP */
594 $ldap= $config->get_ldap_link();
595 foreach ($ma as $memberdn){
596 $dn= base64_decode($memberdn);
597 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
599 /* Found entry... */
600 if ($ldap->count()){
601 $attrs= $ldap->fetch();
602 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
603 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
604 } else {
605 $a['G:'.$dn]= $attrs['cn'][0];
606 if (isset($attrs['description'][0])){
607 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
608 }
609 }
611 /* ... or not */
612 } else {
613 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
614 }
615 }
617 return ($a);
618 }
621 function extractACL($acl)
622 {
623 /* Rip acl off the string, seperate by ',' and place it in an array */
624 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
625 $aa= split(',', $as);
626 $a= array();
628 /* Dis-assemble single ACLs */
629 foreach($aa as $sacl){
631 /* Dis-assemble field ACLs */
632 $ao= split('#', $sacl);
633 $gobject= "";
634 foreach($ao as $idx => $ssacl){
636 /* First is department with global acl */
637 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
638 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
639 if ($idx == 0){
640 /* Create hash for this object */
641 $gobject= $object;
642 $a[$gobject]= array();
644 /* Append ACL if set */
645 if ($gacl != ""){
646 $a[$gobject]= array($gacl);
647 }
648 } else {
650 /* All other entries get appended... */
651 list($field, $facl)= split(';', $ssacl);
652 $a[$gobject][$field]= $facl;
653 }
655 }
656 }
658 return ($a);
659 }
662 function assembleAclSummary($entry)
663 {
664 $summary= "";
666 /* Summarize ACL */
667 if (isset($entry['acl'])){
668 $acl= "";
669 foreach ($entry['acl'] as $name => $object){
670 if (count($object)){
671 $acl.= "$name, ";
672 }
673 }
674 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
675 }
677 /* Summarize members */
678 if ($summary != ""){
679 $summary.= ", ";
680 }
681 if (count($entry['members'])){
682 $summary.= _("Members:")." ";
683 foreach ($entry['members'] as $cn){
684 $cn= preg_replace('/ \[.*$/', '', $cn);
685 $summary.= $cn.", ";
686 }
687 } else {
688 $summary.= _("ACL is valid for all users");
689 }
691 return (preg_replace('/, $/', '', $summary));
692 }
695 function loadAclEntry($new= FALSE)
696 {
697 /* New entry gets presets... */
698 if ($new){
699 $this->aclType= 'base';
700 $this->recipients= array();
701 $this->aclContents= array();
702 } else {
703 $acl= $this->gosaAclEntry[$this->currentIndex];
704 $this->aclType= $acl['type'];
705 $this->recipients= $acl['members'];
706 $this->aclContents= $acl['acl'];
707 }
709 $this->wasNewEntry= $new;
710 }
713 function aclPostHandler()
714 {
715 if (isset($_POST['save_acl'])){
716 $this->save();
717 return TRUE;
718 }
720 return FALSE;
721 }
724 function save()
725 {
726 /* Assemble ACL's */
727 $tmp_acl= array();
728 foreach ($this->gosaAclEntry as $prio => $entry){
729 $final= "";
730 $members= "";
731 if (isset($entry['members'])){
732 foreach ($entry['members'] as $key => $dummy){
733 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
734 }
735 }
736 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
738 /* ACL's if needed */
739 if ($entry['type'] != "reset" && $entry['type'] != "role"){
740 $acl= ":";
741 if (isset($entry['acl'])){
742 foreach ($entry['acl'] as $object => $contents){
744 /* Only save, if we've some contents in there... */
745 if (count($contents)){
746 $acl.= $object.";";
748 foreach($contents as $attr => $permission){
750 /* First entry? Its the one for global settings... */
751 if ($attr == '0'){
752 $acl.= $permission;
753 } else {
754 $acl.= '#'.$attr.';'.$permission;
755 }
757 }
758 $acl.= ',';
759 }
761 }
762 }
763 $final.= preg_replace('/,$/', '', $acl);
764 }
766 $tmp_acl[]= $final;
767 }
769 /* Call main method */
770 plugin::save();
772 /* Finally (re-)assign it... */
773 $this->attrs['gosaAclEntry']= $tmp_acl;
775 /* Remove acl from this entry if it is empty... */
776 if (!count($tmp_acl)){
777 /* Remove attribute */
778 if ($this->initially_was_account){
779 $this->attrs['gosaAclEntry']= array();
780 } else {
781 if (isset($this->attrs['gosaAclEntry'])){
782 unset($this->attrs['gosaAclEntry']);
783 }
784 }
786 /* Remove object class */
787 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
788 }
790 /* Do LDAP modifications */
791 $ldap= $this->config->get_ldap_link();
792 $ldap->cd($this->dn);
793 $this->cleanup();
794 $ldap->modify ($this->attrs);
796 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
797 }
800 function remove_from_parent()
801 {
802 }
804 }
806 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
807 ?>