a9b7389ad47c798104ea73be48fe39616bd7462a
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 /* Add select all/none buttons */
507 $style = "style='width:100px;'";
509 $display .= "<input ".$style." type='button' name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" value='Toggle C'>";
510 $display .= "<input ".$style." type='button' name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" value='Toggle M'>";
511 $display .= "<input ".$style." type='button' name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" value='Toggle D'>";
512 $display .= "<input ".$style." type='button' name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" value='Toggle R'>";
513 $display .= "<input ".$style." type='button' name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" value='Toggle W'>";
515 $display .= "<input ".$style." type='button' name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" value='R+'>";
516 $display .= "<input ".$style." type='button' name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" value='W+'>";
518 $display .= "<br>";
520 $style = "style='width:50px;'";
521 $display .= "<input ".$style." type='button' name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" value='C+'>";
522 $display .= "<input ".$style." type='button' name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" value='C-'>";
523 $display .= "<input ".$style." type='button' name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" value='M+'>";
524 $display .= "<input ".$style." type='button' name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" value='M-'>";
525 $display .= "<input ".$style." type='button' name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" value='D+'>";
526 $display .= "<input ".$style." type='button' name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" value='D-'>";
528 /* Build general objects */
530 $list =$this->sort_by_priority($list);
531 foreach ($list as $key => $name){
533 /* Create sub acl if it does not exist */
534 if (!isset($this->aclContents[$key])){
535 $this->aclContents[$key]= array();
536 $this->aclContents[$key][0]= '';
537 }
538 $currentAcl= $this->aclContents[$key];
540 /* Object header */
541 if($_SESSION['js']) {
542 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
543 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
544 "\n <tr>".
545 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
546 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
547 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
548 "\n </tr>";
549 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
550 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
551 "\n <tr>".
552 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
553 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
554 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
555 "\n </tr>";
556 } else {
557 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
558 "\n <tr>".
559 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
560 "\n </tr>";
561 }
562 } else {
563 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
564 "\n <tr>".
565 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
566 "\n </tr>";
567 }
569 /* Generate options */
570 $spc= " ";
571 if ($this->isContainer && $this->aclType != 'base'){
572 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
573 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
574 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
575 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
576 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
577 }
578 } else {
579 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
580 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
581 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
582 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
583 }
584 }
586 /* Global options */
587 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
588 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
590 $display.= "\n <tr>".
591 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
592 "\n <td style='background-color:#D4D4D4'> ".("Complete object:")." $more_options</td>".
593 "\n </tr>";
595 /* Walk through the list of attributes */
596 $cnt= 1;
597 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
598 asort($splist);
599 if($_SESSION['js']) {
600 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
601 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
602 "\n <td colspan=".$cols.">".
603 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
604 "\n <table style='width:100%;'>";
605 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
606 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
607 "\n <td colspan=".$cols.">".
608 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='position:absolute;overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
609 "\n <table style='width:100%;'>";
610 }
611 }
612 foreach($splist as $attr => $dsc){
614 /* Skip pl* attributes, they are internal... */
615 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
616 continue;
617 }
619 /* Open table row */
620 if ($cnt == 1){
621 $display.= "\n <tr>";
622 }
624 /* Close table row */
625 if ($cnt == $cols){
626 $cnt= 1;
627 $rb= "";
628 $end= "\n </tr>";
629 } else {
630 $cnt++;
631 $rb= "border-right:1px solid #A0A0A0;";
632 $end= "";
633 }
635 /* Collect list of attributes */
636 $state= "";
637 if (isset($currentAcl[$attr])){
638 $state= $currentAcl[$attr];
639 }
640 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
641 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
642 }
644 /* Fill missing td's if needed */
645 if (--$cnt != $cols && $cnt != 0){
646 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
647 }
649 if($_SESSION['js']) {
650 if(isset($_SERVER['HTTP_USER_AGENT']) && (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
651 $display.= "\n </table>".
652 "\n </div>".
653 "\n </td>".
654 "\n </tr>";
655 }
656 }
658 $display.= "\n</table><br />\n";
659 }
661 return ($display);
662 }
665 function mkchkbx($name, $text, $state= FALSE)
666 {
667 $state= $state?"checked":"";
668 return "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."' type=checkbox name='acl_$name' $state>".
669 "\n <label for='acl_$name'>$text</label>";
670 }
673 function mkrwbx($name, $state= "")
674 {
675 $rstate= preg_match('/r/', $state)?'checked':'';
676 $wstate= preg_match('/w/', $state)?'checked':'';
677 return ("\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_r' type=checkbox name='acl_${name}_r' $rstate>".
678 "\n <label for='acl_${name}_r'>"._("read")."</label>".
679 "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_w' type=checkbox name='acl_${name}_w' $wstate>".
680 "\n <label for='acl_${name}_w'>"._("write")."</label>");
681 }
684 function explodeACL($acl)
685 {
686 list($index, $type)= split(':', $acl);
687 $a= array( $index => array("type" => $type,
688 "members" => acl::extractMembers($acl)));
690 /* Handle different types */
691 switch ($type){
693 case 'psub':
694 case 'sub':
695 case 'one':
696 case 'base':
697 $a[$index]['acl']= acl::extractACL($acl);
698 break;
700 case 'role':
701 echo "Role";
702 break;
704 case 'reset':
705 break;
707 default:
708 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
709 $a= array();
710 }
712 return ($a);
713 }
716 function extractMembers($acl)
717 {
718 global $config;
719 $a= array();
721 /* Rip acl off the string, seperate by ',' and place it in an array */
722 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
723 if ($ms == $acl){
724 return $a;
725 }
726 $ma= split(',', $ms);
728 /* Decode dn's, fill with informations from LDAP */
729 $ldap= $config->get_ldap_link();
730 foreach ($ma as $memberdn){
731 $dn= base64_decode($memberdn);
732 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
734 /* Found entry... */
735 if ($ldap->count()){
736 $attrs= $ldap->fetch();
737 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
738 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
739 } else {
740 $a['G:'.$dn]= $attrs['cn'][0];
741 if (isset($attrs['description'][0])){
742 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
743 }
744 }
746 /* ... or not */
747 } else {
748 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
749 }
750 }
752 return ($a);
753 }
756 function extractACL($acl)
757 {
758 /* Rip acl off the string, seperate by ',' and place it in an array */
759 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
760 $aa= split(',', $as);
761 $a= array();
763 /* Dis-assemble single ACLs */
764 foreach($aa as $sacl){
766 /* Dis-assemble field ACLs */
767 $ao= split('#', $sacl);
768 $gobject= "";
769 foreach($ao as $idx => $ssacl){
771 /* First is department with global acl */
772 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
773 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
774 if ($idx == 0){
775 /* Create hash for this object */
776 $gobject= $object;
777 $a[$gobject]= array();
779 /* Append ACL if set */
780 if ($gacl != ""){
781 $a[$gobject]= array($gacl);
782 }
783 } else {
785 /* All other entries get appended... */
786 list($field, $facl)= split(';', $ssacl);
787 $a[$gobject][$field]= $facl;
788 }
790 }
791 }
793 return ($a);
794 }
797 function assembleAclSummary($entry)
798 {
799 $summary= "";
801 /* Summarize ACL */
802 if (isset($entry['acl'])){
803 $acl= "";
804 foreach ($entry['acl'] as $name => $object){
805 if (count($object)){
806 $acl.= "$name, ";
807 }
808 }
809 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
810 }
812 /* Summarize members */
813 if ($summary != ""){
814 $summary.= ", ";
815 }
816 if (count($entry['members'])){
817 $summary.= _("Members:")." ";
818 foreach ($entry['members'] as $cn){
819 $cn= preg_replace('/ \[.*$/', '', $cn);
820 $summary.= $cn.", ";
821 }
822 } else {
823 $summary.= _("ACL is valid for all users");
824 }
826 return (preg_replace('/, $/', '', $summary));
827 }
830 function loadAclEntry($new= FALSE)
831 {
832 /* New entry gets presets... */
833 if ($new){
834 $this->aclType= 'base';
835 $this->recipients= array();
836 $this->aclContents= array();
837 } else {
838 $acl= $this->gosaAclEntry[$this->currentIndex];
839 $this->aclType= $acl['type'];
840 $this->recipients= $acl['members'];
841 $this->aclContents= $acl['acl'];
842 }
844 $this->wasNewEntry= $new;
845 }
848 function aclPostHandler()
849 {
850 if (isset($_POST['save_acl'])){
851 $this->save();
852 return TRUE;
853 }
855 return FALSE;
856 }
859 function save()
860 {
861 /* Assemble ACL's */
862 $tmp_acl= array();
863 foreach ($this->gosaAclEntry as $prio => $entry){
864 $final= "";
865 $members= "";
866 if (isset($entry['members'])){
867 foreach ($entry['members'] as $key => $dummy){
868 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
869 }
870 }
871 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
873 /* ACL's if needed */
874 if ($entry['type'] != "reset" && $entry['type'] != "role"){
875 $acl= ":";
876 if (isset($entry['acl'])){
877 foreach ($entry['acl'] as $object => $contents){
879 /* Only save, if we've some contents in there... */
880 if (count($contents)){
881 $acl.= $object.";";
883 foreach($contents as $attr => $permission){
885 /* First entry? Its the one for global settings... */
886 if ($attr == '0'){
887 $acl.= $permission;
888 } else {
889 $acl.= '#'.$attr.';'.$permission;
890 }
892 }
893 $acl.= ',';
894 }
896 }
897 }
898 $final.= preg_replace('/,$/', '', $acl);
899 }
901 $tmp_acl[]= $final;
902 }
904 /* Call main method */
905 plugin::save();
907 /* Finally (re-)assign it... */
908 $this->attrs['gosaAclEntry']= $tmp_acl;
910 /* Remove acl from this entry if it is empty... */
911 if (!count($tmp_acl)){
912 /* Remove attribute */
913 if ($this->initially_was_account){
914 $this->attrs['gosaAclEntry']= array();
915 } else {
916 if (isset($this->attrs['gosaAclEntry'])){
917 unset($this->attrs['gosaAclEntry']);
918 }
919 }
921 /* Remove object class */
922 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
923 }
925 /* Do LDAP modifications */
926 $ldap= $this->config->get_ldap_link();
927 $ldap->cd($this->dn);
928 $this->cleanup();
929 $ldap->modify ($this->attrs);
931 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
933 /* Refresh users ACLs */
934 $ui= get_userinfo();
935 $ui->loadACL();
936 $_SESSION['ui']= $ui;
937 }
940 function remove_from_parent()
941 {
942 }
944 }
946 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
947 ?>