499fcc8cb2e06eff5977f57efb32a34c0571d8c8
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= 3;
445 $tmp= get_global('plist');
446 $plist= $tmp->info;
447 asort($plist);
449 /* Generate global options */
450 # $key= "global";
451 # $display.= "<table style='width:100%;border:1px solid #C04040' cellspacing=0 cellpadding=2><tr><td style='background-color:#D88888;height:1.8em' colspan=$cols><b>"._("All objects of this category")."</b></td></tr>";
452 #
453 # $spc= " ";
454 # if ($this->isContainer && $this->aclType != 'base'){
455 # $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
456 # $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
457 # $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
458 # if ($plist[$key]['plSelfModify']){
459 # $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
460 # }
461 # } else {
462 # $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
463 # $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
464 # if ($plist[$key]['plSelfModify']){
465 # $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
466 # }
467 # }
468 #
469 # /* Global options */
470 # $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
471 # $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
472 #
473 # $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td></tr></table><br>";
475 /* Build general objects */
476 foreach ($list as $key => $name){
478 /* Create sub acl if it does not exist */
479 if (!isset($this->aclContents[$key])){
480 $this->aclContents[$key]= array();
481 }
482 if (!isset($this->aclContents[$key][0])){
483 $this->aclContents[$key][0]= '';
484 }
485 $currentAcl= $this->aclContents[$key];
487 /* Object header */
488 $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>";
490 /* Generate options */
491 $spc= " ";
492 if ($this->isContainer && $this->aclType != 'base'){
493 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
494 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
495 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
496 if ($plist[$key]['plSelfModify']){
497 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
498 }
499 } else {
500 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
501 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
502 if ($plist[$key]['plSelfModify']){
503 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
504 }
505 }
507 /* Global options */
508 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
509 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
511 $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td></tr>";
513 /* Walk through the list of attributes */
514 $cnt= 1;
515 $splist= $plist[$key];
516 asort($splist);
517 foreach($splist as $attr => $dsc){
519 /* Skip pl* attributes, they are internal... */
520 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
521 continue;
522 }
524 /* Open table row */
525 if ($cnt == 1){
526 $display.= "<tr>";
527 }
529 /* Close table row */
530 if ($cnt == $cols){
531 $cnt= 1;
532 $rb= "";
533 $end= "</tr>";
534 } else {
535 $cnt++;
536 $rb= "border-right:1px solid #A0A0A0;";
537 $end= "";
538 }
540 /* Collect list of attributes */
541 $state= "";
542 if (isset($currentAcl[$attr])){
543 $state= $currentAcl[$attr];
544 }
545 $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";
546 }
548 /* Fill missing td's if needed */
549 if (--$cnt != $cols && $cnt != 0){
550 $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
551 }
553 $display.= "</table><br>";
554 }
556 return ($display);
557 }
560 function mkchkbx($name, $text, $state= FALSE)
561 {
562 $state= $state?"checked":"";
563 return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
564 }
567 function mkrwbx($name, $state= "")
568 {
569 $rstate= preg_match('/r/', $state)?'checked':'';
570 $wstate= preg_match('/w/', $state)?'checked':'';
571 return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
572 "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
573 }
576 function explodeACL($acl)
577 {
578 list($index, $type)= split(':', $acl);
579 $a= array( $index => array("type" => $type,
580 "members" => acl::extractMembers($acl)));
582 /* Handle different types */
583 switch ($type){
585 case 'psub':
586 case 'sub':
587 case 'one':
588 case 'base':
589 $a[$index]['acl']= acl::extractACL($acl);
590 break;
592 case 'role':
593 echo "Role";
594 break;
596 case 'reset':
597 break;
599 default:
600 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
601 $a= array();
602 }
604 return ($a);
605 }
608 function extractMembers($acl)
609 {
610 global $config;
611 $a= array();
613 /* Rip acl off the string, seperate by ',' and place it in an array */
614 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
615 if ($ms == $acl){
616 return $a;
617 }
618 $ma= split(',', $ms);
620 /* Decode dn's, fill with informations from LDAP */
621 $ldap= $config->get_ldap_link();
622 foreach ($ma as $memberdn){
623 $dn= base64_decode($memberdn);
624 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
626 /* Found entry... */
627 if ($ldap->count()){
628 $attrs= $ldap->fetch();
629 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
630 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
631 } else {
632 $a['G:'.$dn]= $attrs['cn'][0];
633 if (isset($attrs['description'][0])){
634 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
635 }
636 }
638 /* ... or not */
639 } else {
640 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
641 }
642 }
644 return ($a);
645 }
648 function extractACL($acl)
649 {
650 /* Rip acl off the string, seperate by ',' and place it in an array */
651 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
652 $aa= split(',', $as);
653 $a= array();
655 /* Dis-assemble single ACLs */
656 foreach($aa as $sacl){
658 /* Dis-assemble field ACLs */
659 $ao= split('#', $sacl);
660 $gobject= "";
661 foreach($ao as $idx => $ssacl){
663 /* First is department with global acl */
664 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
665 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
666 if ($idx == 0){
667 /* Create hash for this object */
668 $gobject= $object;
669 $a[$gobject]= array();
671 /* Append ACL if set */
672 if ($gacl != ""){
673 $a[$gobject]= array($gacl);
674 }
675 } else {
677 /* All other entries get appended... */
678 list($field, $facl)= split(';', $ssacl);
679 $a[$gobject][$field]= $facl;
680 }
682 }
683 }
685 return ($a);
686 }
689 function assembleAclSummary($entry)
690 {
691 $summary= "";
693 /* Summarize ACL */
694 if (isset($entry['acl'])){
695 $acl= "";
696 foreach ($entry['acl'] as $name => $object){
697 if (count($object)){
698 $acl.= "$name, ";
699 }
700 }
701 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
702 }
704 /* Summarize members */
705 if ($summary != ""){
706 $summary.= ", ";
707 }
708 if (count($entry['members'])){
709 $summary.= _("Members:")." ";
710 foreach ($entry['members'] as $cn){
711 $cn= preg_replace('/ \[.*$/', '', $cn);
712 $summary.= $cn.", ";
713 }
714 } else {
715 $summary.= _("ACL is valid for all users");
716 }
718 return (preg_replace('/, $/', '', $summary));
719 }
722 function loadAclEntry($new= FALSE)
723 {
724 /* New entry gets presets... */
725 if ($new){
726 $this->aclType= 'base';
727 $this->recipients= array();
728 $this->aclContents= array();
729 } else {
730 $acl= $this->gosaAclEntry[$this->currentIndex];
731 $this->aclType= $acl['type'];
732 $this->recipients= $acl['members'];
733 $this->aclContents= $acl['acl'];
734 }
736 $this->wasNewEntry= $new;
737 }
740 function aclPostHandler()
741 {
742 if (isset($_POST['save_acl'])){
743 $this->save();
744 return TRUE;
745 }
747 return FALSE;
748 }
751 function save()
752 {
753 /* Assemble ACL's */
754 $tmp_acl= array();
755 foreach ($this->gosaAclEntry as $prio => $entry){
756 $final= "";
757 $members= "";
758 if (isset($entry['members'])){
759 foreach ($entry['members'] as $key => $dummy){
760 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
761 }
762 }
763 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
765 /* ACL's if needed */
766 if ($entry['type'] != "reset" && $entry['type'] != "role"){
767 $acl= ":";
768 if (isset($entry['acl'])){
769 foreach ($entry['acl'] as $object => $contents){
771 /* Only save, if we've some contents in there... */
772 if (count($contents)){
773 $acl.= $object.";";
775 foreach($contents as $attr => $permission){
777 /* First entry? Its the one for global settings... */
778 if ($attr == '0'){
779 $acl.= $permission;
780 } else {
781 $acl.= '#'.$attr.';'.$permission;
782 }
784 }
785 $acl.= ',';
786 }
788 }
789 }
790 $final.= preg_replace('/,$/', '', $acl);
791 }
793 $tmp_acl[]= $final;
794 }
796 /* Call main method */
797 plugin::save();
799 /* Finally (re-)assign it... */
800 $this->attrs['gosaAclEntry']= $tmp_acl;
802 /* Remove acl from this entry if it is empty... */
803 if (!count($tmp_acl)){
804 /* Remove attribute */
805 if ($this->initially_was_account){
806 $this->attrs['gosaAclEntry']= array();
807 } else {
808 if (isset($this->attrs['gosaAclEntry'])){
809 unset($this->attrs['gosaAclEntry']);
810 }
811 }
813 /* Remove object class */
814 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
815 }
817 /* Do LDAP modifications */
818 $ldap= $this->config->get_ldap_link();
819 $ldap->cd($this->dn);
820 $this->cleanup();
821 $ldap->modify ($this->attrs);
823 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
824 }
827 function remove_from_parent()
828 {
829 }
831 }
833 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
834 ?>