91a5dc5695c4d65ad7a487d40d35692269b8b807
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 if (is_array($acls['plDepends']['objectClass'])){
106 foreach($acls['plDepends']['objectClass'] as $oc){
107 $this->aclObjects[$oc]= $acls['plDepends']['description'];
108 }
109 } else {
110 $this->aclObjects[$acls['plDepends']['objectClass']]= $acls['plDepends']['description'];
111 }
112 }
114 /* Additionally filter the classes we're interested in in "self edit" mode */
115 if (is_array($acls['plDepends']['objectClass'])){
116 foreach($acls['plDepends']['objectClass'] as $hoc){
117 if (in_array_ics($hoc, $oc)){
118 $this->myAclObjects[$class]= $acls['plDescription'];
119 break;
120 }
121 }
122 } else {
123 if (in_array_ics($acls['plDepends']['objectClass'], $oc)){
124 $this->myAclObjects[$class]= $acls['plDescription'];
125 }
126 }
127 }
128 }
130 /* Add category for all objects */
131 asort($this->aclObjects);
133 /* Generate mapping object */
134 foreach ($plist as $oc => $pl){
135 if (isset($pl['plDepends']['objectClass'])){
136 if (is_array($pl['plDepends']['objectClass'])){
137 foreach($pl['plDepends']['objectClass'] as $class){
138 if (!isset($this->ocMapping[$class])){
139 $this->ocMapping[$class]= array();
140 }
141 $this->ocMapping[$class][]= $oc;
142 }
143 } else {
144 $class= $pl['plDepends']['objectClass'];
145 if (!isset($this->ocMapping[$class])){
146 $this->ocMapping[$class]= array();
147 }
148 $this->ocMapping[$class][]= $oc;
149 }
150 }
151 }
153 /* Fill acl types */
154 if ($this->isContainer){
155 $this->aclTypes= array("reset" => _("Reset ACLs"),
156 "one" => _("One level"),
157 "base" => _("Current object"),
158 "sub" => _("Complete subtree"),
159 "psub" => _("Complete subtree (permanent)"));
160 //"role" => _("Use ACL defined in role"));
161 } else {
162 $this->aclTypes= array("base" => _("Current object"),
163 "role" => _("Use ACL defined in role"));
164 }
165 asort($this->aclTypes);
166 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
167 asort($this->targets);
169 /* Finally - we want to get saved... */
170 $this->is_account= TRUE;
171 }
174 function execute()
175 {
176 /* Call parent execute */
177 plugin::execute();
179 $tmp= get_global('plist');
180 $plist= $tmp->info;
182 /* Handle posts */
183 if (isset($_POST['new_acl'])){
184 $this->dialogState= 'create';
185 $this->dialog= TRUE;
186 $this->currentIndex= count($this->gosaAclEntry);
187 $this->loadAclEntry(TRUE);
188 }
190 $new_acl= array();
191 $aclDialog= FALSE;
192 foreach($_POST as $name => $post){
194 /* Actions... */
195 if (preg_match('/^acl_edit_.*_x/', $name)){
196 $this->dialogState= 'create';
197 $this->dialog= TRUE;
198 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
199 $this->loadAclEntry();
200 continue;
201 }
202 if (preg_match('/^acl_del_.*_x/', $name)){
203 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
204 continue;
205 }
207 if (preg_match('/^cat_edit_.*_x/', $name)){
208 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
209 $this->dialogState= 'edit';
210 foreach ($this->ocMapping[$this->aclObject] as $oc){
211 if (isset($this->aclContents[$oc])){
212 $this->savedAclContents[$oc]= $this->aclContents[$oc];
213 }
214 }
215 continue;
216 }
217 if (preg_match('/^cat_del_.*_x/', $name)){
218 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
219 foreach ($this->ocMapping[$idx] as $key){
220 unset($this->aclContents[$key]);
221 }
222 continue;
223 }
225 /* Sorting... */
226 if (preg_match('/^sortup_.*_x/', $name)){
227 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
228 if ($index > 0){
229 $tmp= $this->gosaAclEntry[$index];
230 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
231 $this->gosaAclEntry[$index-1]= $tmp;
232 }
233 continue;
234 }
235 if (preg_match('/^sortdown_.*_x/', $name)){
236 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
237 if ($index < count($this->gosaAclEntry)-1){
238 $tmp= $this->gosaAclEntry[$index];
239 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
240 $this->gosaAclEntry[$index+1]= $tmp;
241 }
242 continue;
243 }
245 /* ACL saving... */
246 if (preg_match('/^acl_.*_[^xy]$/', $name)){
247 $aclDialog= TRUE;
248 list($dummy, $object, $attribute, $value)= split('_', $name);
250 /* Ordinary ACLs */
251 if (!isset($new_acl[$object])){
252 $new_acl[$object]= array();
253 }
254 if (isset($new_acl[$object][$attribute])){
255 $new_acl[$object][$attribute].= $value;
256 } else {
257 $new_acl[$object][$attribute]= $value;
258 }
259 }
260 }
262 /* Only be interested in new acl's, if we're in the right _POST place */
263 if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
264 foreach ($this->ocMapping[$this->aclObject] as $oc){
265 unset($this->aclContents[$oc]);
266 if (isset($new_acl[$oc])){
267 $this->aclContents[$oc]= $new_acl[$oc];
268 }
269 }
270 }
272 /* Save new acl in case of base edit mode */
273 if ($this->aclType == 'base'){
274 $this->aclContents= $new_acl;
275 }
277 /* Cancel new acl? */
278 if (isset($_POST['cancel_new_acl'])){
279 $this->dialogState= 'head';
280 $this->dialog= FALSE;
281 if ($this->wasNewEntry){
282 unset ($this->gosaAclEntry[$this->currentIndex]);
283 }
284 }
286 /* Store ACL in main object? */
287 if (isset($_POST['submit_new_acl'])){
288 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
289 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
290 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
291 $this->dialogState= 'head';
292 $this->dialog= FALSE;
293 }
295 /* Cancel edit acl? */
296 if (isset($_POST['cancel_edit_acl'])){
297 $this->dialogState= 'create';
298 foreach ($this->ocMapping[$this->aclObject] as $oc){
299 if (isset($this->savedAclContents[$oc])){
300 $this->aclContents[$oc]= $this->savedAclContents[$oc];
301 }
302 }
303 }
305 /* Save edit acl? */
306 if (isset($_POST['submit_edit_acl'])){
307 $this->dialogState= 'create';
308 }
310 /* Add acl? */
311 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
312 $this->dialogState= 'edit';
313 $this->savedAclContents= array();
314 foreach ($this->ocMapping[$this->aclObject] as $oc){
315 if (isset($this->aclContents[$oc])){
316 $this->savedAclContents[$oc]= $this->aclContents[$oc];
317 }
318 }
319 }
321 /* Add to list? */
322 if (isset($_POST['add']) && isset($_POST['source'])){
323 foreach ($_POST['source'] as $key){
324 if ($this->target == 'user'){
325 $this->recipients[$key]= $this->users[$key];
326 }
327 if ($this->target == 'group'){
328 $this->recipients[$key]= $this->groups[$key];
329 }
330 }
331 ksort($this->recipients);
332 }
334 /* Remove from list? */
335 if (isset($_POST['del']) && isset($_POST['recipient'])){
336 foreach ($_POST['recipient'] as $key){
337 unset($this->recipients[$key]);
338 }
339 }
341 /* Save common values */
342 foreach (array("aclType", "aclObject", "target") as $key){
343 if (isset($_POST[$key])){
344 $this->$key= validate($_POST[$key]);
345 }
346 }
348 /* Create templating instance */
349 $smarty= get_smarty();
351 if ($this->dialogState == 'head'){
352 /* Draw list */
353 $aclList= new DivSelectBox("aclList");
354 $aclList->SetHeight(450);
356 /* Fill in entries */
357 foreach ($this->gosaAclEntry as $key => $entry){
358 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
359 $field2= array("string" => $this->assembleAclSummary($entry));
360 $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
361 $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
362 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
363 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
365 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
366 $aclList->AddEntry(array($field1, $field2, $field3));
367 }
369 $smarty->assign("aclList", $aclList->DrawList());
370 }
372 if ($this->dialogState == 'create'){
373 /* Draw list */
374 $aclList= new DivSelectBox("aclList");
375 $aclList->SetHeight(150);
377 /* Add settings for all categories to the (permanent) list */
378 foreach ($this->aclObjects as $oc => $dsc){
379 $summary= "";
380 foreach ($plist as $key => $plugin){
381 if (isset($plugin['plDepends']['objectClass']) && $plugin['plDepends']['objectClass'] == $oc &&
382 isset($this->aclContents[$key])){
383 if (count($this->aclContents[$key]) && isset($this->aclContents[$key][0]) &&
384 $this->aclContents[$key][0] != ""){
385 $summary.= "$key, ";
386 continue;
387 }
388 if (!isset($this->aclContents[$key][0]) && count($this->aclContents[$key])){
389 $summary.= "$key, ";
390 }
391 }
392 }
394 /* Set summary... */
395 if ($summary == ""){
396 $summary= '<i>'._("No ACL settings for this category").'</i>';
397 } else {
398 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
399 }
401 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
402 $field2= array("string" => $summary);
403 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$oc' title='"._("Edit categories ACLs")."'>";
404 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$oc' title='"._("Clear categories ACLs")."'>";
405 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
406 $aclList->AddEntry(array($field1, $field2, $field3));
407 }
409 $smarty->assign("aclList", $aclList->DrawList());
410 $smarty->assign("aclType", $this->aclType);
411 $smarty->assign("aclTypes", $this->aclTypes);
412 $smarty->assign("target", $this->target);
413 $smarty->assign("targets", $this->targets);
415 /* Assign possible target types */
416 $smarty->assign("targets", $this->targets);
417 foreach ($this->attributes as $attr){
418 $smarty->assign($attr, $this->$attr);
419 }
422 /* Generate list */
423 $tmp= array();
424 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
425 if ($this->target == $field){
426 foreach ($this->$arr as $key => $value){
427 if (!isset($this->recipients[$key])){
428 $tmp[$key]= $value;
429 }
430 }
431 }
432 }
433 $smarty->assign('sources', $tmp);
434 $smarty->assign('recipients', $this->recipients);
436 /* Acl selector if scope is base */
437 if ($this->aclType == 'base'){
438 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
439 }
440 }
442 if ($this->dialogState == 'edit'){
443 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
445 /* Collect objects for selected category */
446 $aclObjects= array();
448 foreach ($plist as $class => $acls){
449 if (isset($acls['plDepends']['objectClass'])){
450 if (is_array($acls['plDepends']['objectClass'])){
451 foreach($acls['plDepends']['objectClass'] as $coc){
452 if ($coc == $this->aclObject){
453 $aclObjects[$class]= $acls['plDescription'];
454 break;
455 }
456 }
457 } else {
458 if ($acls['plDepends']['objectClass'] == $this->aclObject){
459 $aclObjects[$class]= $acls['plDescription'];
460 }
461 }
462 }
463 }
465 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
466 }
468 /* Show main page */
469 $smarty->assign("dialogState", $this->dialogState);
471 return ($smarty->fetch (get_template_path('acl.tpl')));
472 }
475 function buildAclSelector($list)
476 {
477 $display= "";
478 $cols= 3;
479 $tmp= get_global('plist');
480 $plist= $tmp->info;
481 asort($plist);
483 /* Generate global options */
484 # $key= "global";
485 # $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>";
486 #
487 # $spc= " ";
488 # if ($this->isContainer && $this->aclType != 'base'){
489 # $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
490 # $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
491 # $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
492 # if ($plist[$key]['plSelfModify']){
493 # $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
494 # }
495 # } else {
496 # $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
497 # $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
498 # if ($plist[$key]['plSelfModify']){
499 # $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
500 # }
501 # }
502 #
503 # /* Global options */
504 # $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
505 # $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
506 #
507 # $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>";
509 /* Build general objects */
510 foreach ($list as $key => $name){
512 /* Create sub acl if it does not exist */
513 if (!isset($this->aclContents[$key])){
514 $this->aclContents[$key]= array();
515 }
516 if (!isset($this->aclContents[$key][0])){
517 $this->aclContents[$key][0]= '';
518 }
519 $currentAcl= $this->aclContents[$key];
521 /* Object header */
522 $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>";
524 /* Generate options */
525 $spc= " ";
526 if ($this->isContainer && $this->aclType != 'base'){
527 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
528 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
529 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
530 if ($plist[$key]['plSelfModify']){
531 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
532 }
533 } else {
534 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
535 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
536 if ($plist[$key]['plSelfModify']){
537 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
538 }
539 }
541 /* Global options */
542 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
543 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
545 $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td></tr>";
547 /* Walk through the list of attributes */
548 $cnt= 1;
549 $splist= $plist[$key];
550 asort($splist);
551 foreach($splist as $attr => $dsc){
553 /* Skip pl* attributes, they are internal... */
554 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
555 continue;
556 }
558 /* Open table row */
559 if ($cnt == 1){
560 $display.= "<tr>";
561 }
563 /* Close table row */
564 if ($cnt == $cols){
565 $cnt= 1;
566 $rb= "";
567 $end= "</tr>";
568 } else {
569 $cnt++;
570 $rb= "border-right:1px solid #A0A0A0;";
571 $end= "";
572 }
574 /* Collect list of attributes */
575 $state= "";
576 if (isset($currentAcl[$attr])){
577 $state= $currentAcl[$attr];
578 }
579 $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";
580 }
582 /* Fill missing td's if needed */
583 if (--$cnt != $cols && $cnt != 0){
584 $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
585 }
587 $display.= "</table><br>";
588 }
590 return ($display);
591 }
594 function mkchkbx($name, $text, $state= FALSE)
595 {
596 $state= $state?"checked":"";
597 return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
598 }
601 function mkrwbx($name, $state= "")
602 {
603 $rstate= preg_match('/r/', $state)?'checked':'';
604 $wstate= preg_match('/w/', $state)?'checked':'';
605 return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
606 "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
607 }
610 function explodeACL($acl)
611 {
612 list($index, $type)= split(':', $acl);
613 $a= array( $index => array("type" => $type,
614 "members" => acl::extractMembers($acl)));
616 /* Handle different types */
617 switch ($type){
619 case 'psub':
620 case 'sub':
621 case 'one':
622 case 'base':
623 $a[$index]['acl']= acl::extractACL($acl);
624 break;
626 case 'role':
627 echo "Role";
628 break;
630 case 'reset':
631 break;
633 default:
634 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
635 $a= array();
636 }
638 return ($a);
639 }
642 function extractMembers($acl)
643 {
644 global $config;
645 $a= array();
647 /* Rip acl off the string, seperate by ',' and place it in an array */
648 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
649 if ($ms == $acl){
650 return $a;
651 }
652 $ma= split(',', $ms);
654 /* Decode dn's, fill with informations from LDAP */
655 $ldap= $config->get_ldap_link();
656 foreach ($ma as $memberdn){
657 $dn= base64_decode($memberdn);
658 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
660 /* Found entry... */
661 if ($ldap->count()){
662 $attrs= $ldap->fetch();
663 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
664 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
665 } else {
666 $a['G:'.$dn]= $attrs['cn'][0];
667 if (isset($attrs['description'][0])){
668 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
669 }
670 }
672 /* ... or not */
673 } else {
674 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
675 }
676 }
678 return ($a);
679 }
682 function extractACL($acl)
683 {
684 /* Rip acl off the string, seperate by ',' and place it in an array */
685 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
686 $aa= split(',', $as);
687 $a= array();
689 /* Dis-assemble single ACLs */
690 foreach($aa as $sacl){
692 /* Dis-assemble field ACLs */
693 $ao= split('#', $sacl);
694 $gobject= "";
695 foreach($ao as $idx => $ssacl){
697 /* First is department with global acl */
698 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
699 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
700 if ($idx == 0){
701 /* Create hash for this object */
702 $gobject= $object;
703 $a[$gobject]= array();
705 /* Append ACL if set */
706 if ($gacl != ""){
707 $a[$gobject]= array($gacl);
708 }
709 } else {
711 /* All other entries get appended... */
712 list($field, $facl)= split(';', $ssacl);
713 $a[$gobject][$field]= $facl;
714 }
716 }
717 }
719 return ($a);
720 }
723 function assembleAclSummary($entry)
724 {
725 $summary= "";
727 /* Summarize ACL */
728 if (isset($entry['acl'])){
729 $acl= "";
730 foreach ($entry['acl'] as $name => $object){
731 if (count($object)){
732 $acl.= "$name, ";
733 }
734 }
735 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
736 }
738 /* Summarize members */
739 if ($summary != ""){
740 $summary.= ", ";
741 }
742 if (count($entry['members'])){
743 $summary.= _("Members:")." ";
744 foreach ($entry['members'] as $cn){
745 $cn= preg_replace('/ \[.*$/', '', $cn);
746 $summary.= $cn.", ";
747 }
748 } else {
749 $summary.= _("ACL is valid for all users");
750 }
752 return (preg_replace('/, $/', '', $summary));
753 }
756 function loadAclEntry($new= FALSE)
757 {
758 /* New entry gets presets... */
759 if ($new){
760 $this->aclType= 'base';
761 $this->recipients= array();
762 $this->aclContents= array();
763 } else {
764 $acl= $this->gosaAclEntry[$this->currentIndex];
765 $this->aclType= $acl['type'];
766 $this->recipients= $acl['members'];
767 $this->aclContents= $acl['acl'];
768 }
770 $this->wasNewEntry= $new;
771 }
774 function aclPostHandler()
775 {
776 if (isset($_POST['save_acl'])){
777 $this->save();
778 return TRUE;
779 }
781 return FALSE;
782 }
785 function save()
786 {
787 /* Assemble ACL's */
788 $tmp_acl= array();
789 foreach ($this->gosaAclEntry as $prio => $entry){
790 $final= "";
791 $members= "";
792 if (isset($entry['members'])){
793 foreach ($entry['members'] as $key => $dummy){
794 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
795 }
796 }
797 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
799 /* ACL's if needed */
800 if ($entry['type'] != "reset" && $entry['type'] != "role"){
801 $acl= ":";
802 if (isset($entry['acl'])){
803 foreach ($entry['acl'] as $object => $contents){
805 /* Only save, if we've some contents in there... */
806 if (count($contents)){
807 $acl.= $object.";";
809 foreach($contents as $attr => $permission){
811 /* First entry? Its the one for global settings... */
812 if ($attr == '0'){
813 $acl.= $permission;
814 } else {
815 $acl.= '#'.$attr.';'.$permission;
816 }
818 }
819 $acl.= ',';
820 }
822 }
823 }
824 $final.= preg_replace('/,$/', '', $acl);
825 }
827 $tmp_acl[]= $final;
828 }
830 /* Call main method */
831 plugin::save();
833 /* Finally (re-)assign it... */
834 $this->attrs['gosaAclEntry']= $tmp_acl;
836 /* Remove acl from this entry if it is empty... */
837 if (!count($tmp_acl)){
838 /* Remove attribute */
839 if ($this->initially_was_account){
840 $this->attrs['gosaAclEntry']= array();
841 } else {
842 if (isset($this->attrs['gosaAclEntry'])){
843 unset($this->attrs['gosaAclEntry']);
844 }
845 }
847 /* Remove object class */
848 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
849 }
851 /* Do LDAP modifications */
852 $ldap= $this->config->get_ldap_link();
853 $ldap->cd($this->dn);
854 $this->cleanup();
855 $ldap->modify ($this->attrs);
857 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
858 }
861 function remove_from_parent()
862 {
863 }
865 }
867 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
868 ?>