1 <?php
3 class acl extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "Access control";
7 var $plDescription= "This does something";
9 /* attribute list for save action */
10 var $attributes= array('gosaAclEntry');
11 var $objectclasses= array('gosaAcl');
13 /* Helpers */
14 var $dialogState= "head";
15 var $gosaAclEntry= array();
16 var $aclType= "";
17 var $aclObject= "";
18 var $aclContents= array();
19 var $target= "group";
20 var $aclTypes= array();
21 var $aclObjects= array();
22 var $aclMyObjects= array();
23 var $users= array();
24 var $groups= array();
25 var $recipients= array();
26 var $isContainer= FALSE;
27 var $currentIndex= 0;
28 var $wasNewEntry= FALSE;
29 var $ocMapping= array();
30 var $savedAclContents= array();
33 function acl ($config, $parent, $dn= NULL)
34 {
35 /* Include config object */
36 plugin::plugin($config, $dn);
38 /* Load ACL's */
39 $this->gosaAclEntry= array();
40 if (isset($this->attrs['gosaAclEntry'])){
41 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
42 $acl= $this->attrs['gosaAclEntry'][$i];
43 $this->gosaAclEntry= array_merge($this->gosaAclEntry, $this->explodeACL($acl));
44 }
45 }
46 ksort($this->gosaAclEntry);
48 /* Save parent - we've to know more about it than other plugins... */
49 $this->parent= $parent;
51 /* Container? */
52 if (preg_match('/^(ou|c|l|dc)=/i', $dn)){
53 $this->isContainer= TRUE;
54 }
56 /* Users */
57 $ui= get_userinfo();
58 $tag= $ui->gosaUnitTag;
59 $ldap= $config->get_ldap_link();
60 $ldap->cd($config->current['BASE']);
61 if ($tag == ""){
62 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
63 } else {
64 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
65 }
66 while ($attrs= $ldap->fetch()){
67 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
68 }
69 ksort($this->users);
71 /* Groups */
72 $ldap->cd($config->current['BASE']);
73 if ($tag == ""){
74 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
75 } else {
76 $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
77 }
78 while ($attrs= $ldap->fetch()){
79 $dsc= "";
80 if (isset($attrs['description'][0])){
81 $dsc= $attrs['description'][0];
82 }
83 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
84 }
85 ksort($this->groups);
87 /* Objects */
88 $tmp= get_global('plist');
89 $plist= $tmp->info;
90 if (isset($this->parent) && $this->parent != NULL){
91 $oc= array();
92 foreach ($this->parent->by_object as $key => $obj){
93 $oc= array_merge($oc, $obj->objectclasses);
94 }
95 if (in_array_ics('organizationalUnit', $oc)){
96 $this->isContainer= TRUE;
97 }
98 } else {
99 $oc= $this->attrs['objectClass'];
100 }
103 /* Extract available categories from plugin info list */
104 foreach ($plist as $class => $acls){
106 /* Only feed categories */
107 if (isset($acls['plCategory'])){
109 /* Walk through supplied list and feed only translated categories */
110 foreach($acls['plCategory'] as $idx => $data){
112 /* Non numeric index means -> base object containing more informations */
113 if (preg_match('/^[0-9]+$/', $idx)){
114 if (!isset($this->ocMapping[$data])){
115 $this->ocMapping[$data]= array();
116 $this->ocMapping[$data][]= '0';
117 }
118 $this->ocMapping[$data][]= $class;
119 } else {
120 if (!isset($this->ocMapping[$idx])){
121 $this->ocMapping[$idx]= array();
122 $this->ocMapping[$idx][]= '0';
123 }
124 $this->ocMapping[$idx][]= $class;
125 $this->aclObjects[$idx]= $data['description'];
127 /* Additionally filter the classes we're interested in in "self edit" mode */
128 if (is_array($data['objectClass'])){
129 foreach($data['objectClass'] as $objectClass){
130 if (in_array_ics($objectClass, $oc)){
131 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
132 break;
133 }
134 }
135 } else {
136 if (in_array_ics($data['objectClass'], $oc)){
137 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
138 }
139 }
140 }
142 }
143 }
144 }
145 $this->aclObjects['all']= '* '._("All categories");
146 $this->ocMapping['all']= array('0' => 'all');
148 /* Sort categories */
149 asort($this->aclObjects);
151 /* Fill acl types */
152 if ($this->isContainer){
153 $this->aclTypes= array("reset" => _("Reset ACLs"),
154 "one" => _("One level"),
155 "base" => _("Current object"),
156 "sub" => _("Complete subtree"),
157 "psub" => _("Complete subtree (permanent)"));
158 //"role" => _("Use ACL defined in role"));
159 } else {
160 $this->aclTypes= array("base" => _("Current object"),
161 "role" => _("Use ACL defined in role"));
162 }
163 asort($this->aclTypes);
164 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
165 asort($this->targets);
167 /* Finally - we want to get saved... */
168 $this->is_account= TRUE;
169 }
172 function execute()
173 {
174 /* Call parent execute */
175 plugin::execute();
177 $tmp= get_global('plist');
178 $plist= $tmp->info;
180 /* Handle posts */
181 if (isset($_POST['new_acl'])){
182 $this->dialogState= 'create';
183 $this->dialog= TRUE;
184 $this->currentIndex= count($this->gosaAclEntry);
185 $this->loadAclEntry(TRUE);
186 }
188 $new_acl= array();
189 $aclDialog= FALSE;
190 foreach($_POST as $name => $post){
192 /* Actions... */
193 if (preg_match('/^acl_edit_.*_x/', $name)){
194 $this->dialogState= 'create';
195 $this->dialog= TRUE;
196 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
197 $this->loadAclEntry();
198 continue;
199 }
200 if (preg_match('/^acl_del_.*_x/', $name)){
201 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
202 continue;
203 }
205 if (preg_match('/^cat_edit_.*_x/', $name)){
206 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
207 $this->dialogState= 'edit';
208 foreach ($this->ocMapping[$this->aclObject] as $oc){
209 if (isset($this->aclContents[$oc])){
210 $this->savedAclContents[$oc]= $this->aclContents[$oc];
211 }
212 }
213 continue;
214 }
215 if (preg_match('/^cat_del_.*_x/', $name)){
216 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
217 foreach ($this->ocMapping[$idx] as $key){
218 unset($this->aclContents["$idx/$key"]);
219 }
220 continue;
221 }
223 /* Sorting... */
224 if (preg_match('/^sortup_.*_x/', $name)){
225 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
226 if ($index > 0){
227 $tmp= $this->gosaAclEntry[$index];
228 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
229 $this->gosaAclEntry[$index-1]= $tmp;
230 }
231 continue;
232 }
233 if (preg_match('/^sortdown_.*_x/', $name)){
234 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
235 if ($index < count($this->gosaAclEntry)-1){
236 $tmp= $this->gosaAclEntry[$index];
237 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
238 $this->gosaAclEntry[$index+1]= $tmp;
239 }
240 continue;
241 }
243 /* ACL saving... */
244 if (preg_match('/^acl_.*_[^xy]$/', $name)){
245 $aclDialog= TRUE;
246 list($dummy, $object, $attribute, $value)= split('_', $name);
248 /* Skip for detection entry */
249 if ($object == 'dummy') {
250 continue;
251 }
253 /* Ordinary ACLs */
254 if (!isset($new_acl[$object])){
255 $new_acl[$object]= array();
256 }
257 if (isset($new_acl[$object][$attribute])){
258 $new_acl[$object][$attribute].= $value;
259 } else {
260 $new_acl[$object][$attribute]= $value;
261 }
262 }
263 }
265 /* Only be interested in new acl's, if we're in the right _POST place */
266 if ($aclDialog && is_array($this->ocMapping[$this->aclObject])){
268 foreach ($this->ocMapping[$this->aclObject] as $oc){
269 unset($this->aclContents[$oc]);
270 unset($this->aclContents[$this->aclObject.'/'.$oc]);
271 if (isset($new_acl[$oc])){
272 $this->aclContents[$oc]= $new_acl[$oc];
273 }
274 if (isset($new_acl[$this->aclObject.'/'.$oc])){
275 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
276 }
277 }
278 }
280 /* Save new acl in case of base edit mode */
281 if ($this->aclType == 'base'){
282 $this->aclContents= $new_acl;
283 }
285 /* Cancel new acl? */
286 if (isset($_POST['cancel_new_acl'])){
287 $this->dialogState= 'head';
288 $this->dialog= FALSE;
289 if ($this->wasNewEntry){
290 unset ($this->gosaAclEntry[$this->currentIndex]);
291 }
292 }
294 /* Store ACL in main object? */
295 if (isset($_POST['submit_new_acl'])){
296 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
297 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
298 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
299 $this->dialogState= 'head';
300 $this->dialog= FALSE;
301 }
303 /* Cancel edit acl? */
304 if (isset($_POST['cancel_edit_acl'])){
305 $this->dialogState= 'create';
306 foreach ($this->ocMapping[$this->aclObject] as $oc){
307 if (isset($this->savedAclContents[$oc])){
308 $this->aclContents[$oc]= $this->savedAclContents[$oc];
309 }
310 }
311 }
313 /* Save edit acl? */
314 if (isset($_POST['submit_edit_acl'])){
315 $this->dialogState= 'create';
316 }
318 /* Add acl? */
319 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
320 $this->dialogState= 'edit';
321 $this->savedAclContents= array();
322 foreach ($this->ocMapping[$this->aclObject] as $oc){
323 if (isset($this->aclContents[$oc])){
324 $this->savedAclContents[$oc]= $this->aclContents[$oc];
325 }
326 }
327 }
329 /* Add to list? */
330 if (isset($_POST['add']) && isset($_POST['source'])){
331 foreach ($_POST['source'] as $key){
332 if ($this->target == 'user'){
333 $this->recipients[$key]= $this->users[$key];
334 }
335 if ($this->target == 'group'){
336 $this->recipients[$key]= $this->groups[$key];
337 }
338 }
339 ksort($this->recipients);
340 }
342 /* Remove from list? */
343 if (isset($_POST['del']) && isset($_POST['recipient'])){
344 foreach ($_POST['recipient'] as $key){
345 unset($this->recipients[$key]);
346 }
347 }
349 /* Save common values */
350 foreach (array("aclType", "aclObject", "target") as $key){
351 if (isset($_POST[$key])){
352 $this->$key= validate($_POST[$key]);
353 }
354 }
356 /* Create templating instance */
357 $smarty= get_smarty();
359 if ($this->dialogState == 'head'){
360 /* Draw list */
361 $aclList= new DivSelectBox("aclList");
362 $aclList->SetHeight(450);
364 /* Fill in entries */
365 foreach ($this->gosaAclEntry as $key => $entry){
366 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
367 $field2= array("string" => $this->assembleAclSummary($entry));
368 $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
369 $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
370 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
371 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
373 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
374 $aclList->AddEntry(array($field1, $field2, $field3));
375 }
377 $smarty->assign("aclList", $aclList->DrawList());
378 }
380 if ($this->dialogState == 'create'){
381 /* Draw list */
382 $aclList= new DivSelectBox("aclList");
383 $aclList->SetHeight(150);
385 /* Add settings for all categories to the (permanent) list */
386 foreach ($this->aclObjects as $section => $dsc){
387 $summary= "";
388 foreach($this->ocMapping[$section] as $oc){
389 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
390 $this->aclContents[$oc][0] != ""){
392 $summary.= "$oc, ";
393 continue;
394 }
395 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
396 $this->aclContents["$section/$oc"][0] != ""){
398 $summary.= "$oc, ";
399 continue;
400 }
401 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
402 $summary.= "$oc, ";
403 }
404 }
406 /* Set summary... */
407 if ($summary == ""){
408 $summary= '<i>'._("No ACL settings for this category").'</i>';
409 } else {
410 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
411 }
413 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
414 $field2= array("string" => $summary);
415 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$section' title='"._("Edit categories ACLs")."'>";
416 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$section' title='"._("Clear categories ACLs")."'>";
417 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
418 $aclList->AddEntry(array($field1, $field2, $field3));
419 }
421 $smarty->assign("aclList", $aclList->DrawList());
422 $smarty->assign("aclType", $this->aclType);
423 $smarty->assign("aclTypes", $this->aclTypes);
424 $smarty->assign("target", $this->target);
425 $smarty->assign("targets", $this->targets);
427 /* Assign possible target types */
428 $smarty->assign("targets", $this->targets);
429 foreach ($this->attributes as $attr){
430 $smarty->assign($attr, $this->$attr);
431 }
434 /* Generate list */
435 $tmp= array();
436 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
437 if ($this->target == $field){
438 foreach ($this->$arr as $key => $value){
439 if (!isset($this->recipients[$key])){
440 $tmp[$key]= $value;
441 }
442 }
443 }
444 }
445 $smarty->assign('sources', $tmp);
446 $smarty->assign('recipients', $this->recipients);
448 /* Acl selector if scope is base */
449 if ($this->aclType == 'base'){
450 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
451 }
452 }
454 if ($this->dialogState == 'edit'){
455 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
457 /* Collect objects for selected category */
458 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
459 if ($idx == 0){
460 continue;
461 }
462 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
463 }
464 if ($this->aclObject == 'all'){
465 $aclObjects['all']= _("All objects in current subtree");
466 }
467 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
468 }
470 /* Show main page */
471 $smarty->assign("dialogState", $this->dialogState);
473 return ($smarty->fetch (get_template_path('acl.tpl')));
474 }
476 function sort_by_priority($list)
477 {
478 $tmp= get_global('plist');
479 $plist= $tmp->info;
480 asort($plist);
482 foreach($list as $name => $translation){
483 $na = preg_replace("/^.*\//","",$name);
484 $prio= $plist[$na]['plPriority'] ;
486 $newSort[$name] = $prio;
487 }
489 asort($newSort);
491 $ret = array();
492 foreach($newSort as $name => $prio){
493 $ret[$name] = $list[$name];
494 }
495 return($ret);
496 }
498 function buildAclSelector($list)
499 {
500 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
501 $cols= 3;
502 $tmp= get_global('plist');
503 $plist= $tmp->info;
504 asort($plist);
506 /* Build general objects */
508 $list =$this->sort_by_priority($list);
509 foreach ($list as $key => $name){
511 /* Create sub acl if it does not exist */
512 if (!isset($this->aclContents[$key])){
513 $this->aclContents[$key]= array();
514 $this->aclContents[$key][0]= '';
515 }
516 $currentAcl= $this->aclContents[$key];
518 /* Object header */
519 if($_SESSION['js']) {
520 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
521 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
522 "\n <tr>".
523 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
524 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
525 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
526 "\n </tr>";
527 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
528 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
529 "\n <tr>".
530 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
531 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
532 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
533 "\n </tr>";
534 } else {
535 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
536 "\n <tr>".
537 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
538 "\n </tr>";
539 }
540 } else {
541 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
542 "\n <tr>".
543 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
544 "\n </tr>";
545 }
547 /* Generate options */
548 $spc= " ";
549 if ($this->isContainer && $this->aclType != 'base'){
550 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
551 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
552 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
553 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
554 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
555 }
556 } else {
557 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
558 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
559 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
560 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
561 }
562 }
564 /* Global options */
565 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
566 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
568 $display.= "\n <tr>".
569 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
570 "\n <td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td>".
571 "\n </tr>";
573 /* Walk through the list of attributes */
574 $cnt= 1;
575 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
576 asort($splist);
577 if($_SESSION['js']) {
578 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
579 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
580 "\n <td colspan=".$cols.">".
581 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
582 "\n <table style='width:100%;'>";
583 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
584 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
585 "\n <td colspan=".$cols.">".
586 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='position:absolute;overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
587 "\n <table style='width:100%;'>";
588 }
589 }
590 foreach($splist as $attr => $dsc){
592 /* Skip pl* attributes, they are internal... */
593 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
594 continue;
595 }
597 /* Open table row */
598 if ($cnt == 1){
599 $display.= "\n <tr>";
600 }
602 /* Close table row */
603 if ($cnt == $cols){
604 $cnt= 1;
605 $rb= "";
606 $end= "\n </tr>";
607 } else {
608 $cnt++;
609 $rb= "border-right:1px solid #A0A0A0;";
610 $end= "";
611 }
613 /* Collect list of attributes */
614 $state= "";
615 if (isset($currentAcl[$attr])){
616 $state= $currentAcl[$attr];
617 }
618 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
619 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
620 }
622 /* Fill missing td's if needed */
623 if (--$cnt != $cols && $cnt != 0){
624 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
625 }
627 if($_SESSION['js']) {
628 if(isset($_SERVER['HTTP_USER_AGENT']) && (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
629 $display.= "\n </table>".
630 "\n </div>".
631 "\n </td>".
632 "\n </tr>";
633 }
634 }
636 $display.= "\n</table><br />\n";
637 }
639 return ($display);
640 }
643 function mkchkbx($name, $text, $state= FALSE)
644 {
645 $state= $state?"checked":"";
646 return "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."' type=checkbox name='acl_$name' $state>".
647 "\n <label for='acl_$name'>$text</label>";
648 }
651 function mkrwbx($name, $state= "")
652 {
653 $rstate= preg_match('/r/', $state)?'checked':'';
654 $wstate= preg_match('/w/', $state)?'checked':'';
655 return ("\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_r' type=checkbox name='acl_${name}_r' $rstate>".
656 "\n <label for='acl_${name}_r'>"._("read")."</label>".
657 "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_w' type=checkbox name='acl_${name}_w' $wstate>".
658 "\n <label for='acl_${name}_w'>"._("write")."</label>");
659 }
662 function explodeACL($acl)
663 {
664 list($index, $type)= split(':', $acl);
665 $a= array( $index => array("type" => $type,
666 "members" => acl::extractMembers($acl)));
668 /* Handle different types */
669 switch ($type){
671 case 'psub':
672 case 'sub':
673 case 'one':
674 case 'base':
675 $a[$index]['acl']= acl::extractACL($acl);
676 break;
678 case 'role':
679 echo "Role";
680 break;
682 case 'reset':
683 break;
685 default:
686 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
687 $a= array();
688 }
690 return ($a);
691 }
694 function extractMembers($acl)
695 {
696 global $config;
697 $a= array();
699 /* Rip acl off the string, seperate by ',' and place it in an array */
700 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
701 if ($ms == $acl){
702 return $a;
703 }
704 $ma= split(',', $ms);
706 /* Decode dn's, fill with informations from LDAP */
707 $ldap= $config->get_ldap_link();
708 foreach ($ma as $memberdn){
709 $dn= base64_decode($memberdn);
710 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
712 /* Found entry... */
713 if ($ldap->count()){
714 $attrs= $ldap->fetch();
715 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
716 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
717 } else {
718 $a['G:'.$dn]= $attrs['cn'][0];
719 if (isset($attrs['description'][0])){
720 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
721 }
722 }
724 /* ... or not */
725 } else {
726 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
727 }
728 }
730 return ($a);
731 }
734 function extractACL($acl)
735 {
736 /* Rip acl off the string, seperate by ',' and place it in an array */
737 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
738 $aa= split(',', $as);
739 $a= array();
741 /* Dis-assemble single ACLs */
742 foreach($aa as $sacl){
744 /* Dis-assemble field ACLs */
745 $ao= split('#', $sacl);
746 $gobject= "";
747 foreach($ao as $idx => $ssacl){
749 /* First is department with global acl */
750 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
751 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
752 if ($idx == 0){
753 /* Create hash for this object */
754 $gobject= $object;
755 $a[$gobject]= array();
757 /* Append ACL if set */
758 if ($gacl != ""){
759 $a[$gobject]= array($gacl);
760 }
761 } else {
763 /* All other entries get appended... */
764 list($field, $facl)= split(';', $ssacl);
765 $a[$gobject][$field]= $facl;
766 }
768 }
769 }
771 return ($a);
772 }
775 function assembleAclSummary($entry)
776 {
777 $summary= "";
779 /* Summarize ACL */
780 if (isset($entry['acl'])){
781 $acl= "";
782 foreach ($entry['acl'] as $name => $object){
783 if (count($object)){
784 $acl.= "$name, ";
785 }
786 }
787 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
788 }
790 /* Summarize members */
791 if ($summary != ""){
792 $summary.= ", ";
793 }
794 if (count($entry['members'])){
795 $summary.= _("Members:")." ";
796 foreach ($entry['members'] as $cn){
797 $cn= preg_replace('/ \[.*$/', '', $cn);
798 $summary.= $cn.", ";
799 }
800 } else {
801 $summary.= _("ACL is valid for all users");
802 }
804 return (preg_replace('/, $/', '', $summary));
805 }
808 function loadAclEntry($new= FALSE)
809 {
810 /* New entry gets presets... */
811 if ($new){
812 $this->aclType= 'base';
813 $this->recipients= array();
814 $this->aclContents= array();
815 } else {
816 $acl= $this->gosaAclEntry[$this->currentIndex];
817 $this->aclType= $acl['type'];
818 $this->recipients= $acl['members'];
819 $this->aclContents= $acl['acl'];
820 }
822 $this->wasNewEntry= $new;
823 }
826 function aclPostHandler()
827 {
828 if (isset($_POST['save_acl'])){
829 $this->save();
830 return TRUE;
831 }
833 return FALSE;
834 }
837 function save()
838 {
839 /* Assemble ACL's */
840 $tmp_acl= array();
841 foreach ($this->gosaAclEntry as $prio => $entry){
842 $final= "";
843 $members= "";
844 if (isset($entry['members'])){
845 foreach ($entry['members'] as $key => $dummy){
846 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
847 }
848 }
849 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
851 /* ACL's if needed */
852 if ($entry['type'] != "reset" && $entry['type'] != "role"){
853 $acl= ":";
854 if (isset($entry['acl'])){
855 foreach ($entry['acl'] as $object => $contents){
857 /* Only save, if we've some contents in there... */
858 if (count($contents)){
859 $acl.= $object.";";
861 foreach($contents as $attr => $permission){
863 /* First entry? Its the one for global settings... */
864 if ($attr == '0'){
865 $acl.= $permission;
866 } else {
867 $acl.= '#'.$attr.';'.$permission;
868 }
870 }
871 $acl.= ',';
872 }
874 }
875 }
876 $final.= preg_replace('/,$/', '', $acl);
877 }
879 $tmp_acl[]= $final;
880 }
882 /* Call main method */
883 plugin::save();
885 /* Finally (re-)assign it... */
886 $this->attrs['gosaAclEntry']= $tmp_acl;
888 /* Remove acl from this entry if it is empty... */
889 if (!count($tmp_acl)){
890 /* Remove attribute */
891 if ($this->initially_was_account){
892 $this->attrs['gosaAclEntry']= array();
893 } else {
894 if (isset($this->attrs['gosaAclEntry'])){
895 unset($this->attrs['gosaAclEntry']);
896 }
897 }
899 /* Remove object class */
900 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
901 }
903 /* Do LDAP modifications */
904 $ldap= $this->config->get_ldap_link();
905 $ldap->cd($this->dn);
906 $this->cleanup();
907 $ldap->modify ($this->attrs);
909 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
911 /* Refresh users ACLs */
912 $ui= get_userinfo();
913 $ui->loadACL();
914 $_SESSION['ui']= $ui;
915 }
918 function remove_from_parent()
919 {
920 }
922 }
924 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
925 ?>