41082b3106b9f17b2e92c18561030ced671d004b
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();
31 var $myAclObjects = 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 $firstedit= FALSE;
191 foreach($_POST as $name => $post){
193 /* Actions... */
194 if (preg_match('/^acl_edit_.*_x/', $name)){
195 $this->dialogState= 'create';
196 $firstedit= TRUE;
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["$idx/$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 /* Skip for detection entry */
251 if ($object == 'dummy') {
252 continue;
253 }
255 /* Ordinary ACLs */
256 if (!isset($new_acl[$object])){
257 $new_acl[$object]= array();
258 }
259 if (isset($new_acl[$object][$attribute])){
260 $new_acl[$object][$attribute].= $value;
261 } else {
262 $new_acl[$object][$attribute]= $value;
263 }
264 }
265 }
267 /* Only be interested in new acl's, if we're in the right _POST place */
268 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
270 foreach ($this->ocMapping[$this->aclObject] as $oc){
271 unset($this->aclContents[$oc]);
272 unset($this->aclContents[$this->aclObject.'/'.$oc]);
273 if (isset($new_acl[$oc])){
274 $this->aclContents[$oc]= $new_acl[$oc];
275 }
276 if (isset($new_acl[$this->aclObject.'/'.$oc])){
277 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
278 }
279 }
280 }
282 /* Save new acl in case of base edit mode */
283 if ($this->aclType == 'base' && !$firstedit){
284 $this->aclContents= $new_acl;
285 }
287 /* Cancel new acl? */
288 if (isset($_POST['cancel_new_acl'])){
289 $this->dialogState= 'head';
290 $this->dialog= FALSE;
291 if ($this->wasNewEntry){
292 unset ($this->gosaAclEntry[$this->currentIndex]);
293 }
294 }
296 /* Store ACL in main object? */
297 if (isset($_POST['submit_new_acl'])){
298 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
299 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
300 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
301 $this->dialogState= 'head';
302 $this->dialog= FALSE;
303 }
305 /* Cancel edit acl? */
306 if (isset($_POST['cancel_edit_acl'])){
307 $this->dialogState= 'create';
308 foreach ($this->ocMapping[$this->aclObject] as $oc){
309 if (isset($this->savedAclContents[$oc])){
310 $this->aclContents[$oc]= $this->savedAclContents[$oc];
311 }
312 }
313 }
315 /* Save edit acl? */
316 if (isset($_POST['submit_edit_acl'])){
317 $this->dialogState= 'create';
318 }
320 /* Add acl? */
321 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
322 $this->dialogState= 'edit';
323 $this->savedAclContents= array();
324 foreach ($this->ocMapping[$this->aclObject] as $oc){
325 if (isset($this->aclContents[$oc])){
326 $this->savedAclContents[$oc]= $this->aclContents[$oc];
327 }
328 }
329 }
331 /* Add to list? */
332 if (isset($_POST['add']) && isset($_POST['source'])){
333 foreach ($_POST['source'] as $key){
334 if ($this->target == 'user'){
335 $this->recipients[$key]= $this->users[$key];
336 }
337 if ($this->target == 'group'){
338 $this->recipients[$key]= $this->groups[$key];
339 }
340 }
341 ksort($this->recipients);
342 }
344 /* Remove from list? */
345 if (isset($_POST['del']) && isset($_POST['recipient'])){
346 foreach ($_POST['recipient'] as $key){
347 unset($this->recipients[$key]);
348 }
349 }
351 /* Save common values */
352 foreach (array("aclType", "aclObject", "target") as $key){
353 if (isset($_POST[$key])){
354 $this->$key= validate($_POST[$key]);
355 }
356 }
358 /* Create templating instance */
359 $smarty= get_smarty();
361 if ($this->dialogState == 'head'){
362 /* Draw list */
363 $aclList= new DivSelectBox("aclList");
364 $aclList->SetHeight(450);
366 /* Fill in entries */
367 foreach ($this->gosaAclEntry as $key => $entry){
368 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:100px'");
369 $field2= array("string" => $this->assembleAclSummary($entry));
370 $action= "<input type='image' name='sortup_$key' alt='up' title='"._("Up")."' src='images/sort_up.png' align='top'>";
371 $action.= "<input type='image' name='sortdown_$key' alt='down' title='"._("Down")."' src='images/sort_down.png'>";
372 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
373 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
375 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
376 $aclList->AddEntry(array($field1, $field2, $field3));
377 }
379 $smarty->assign("aclList", $aclList->DrawList());
380 }
382 if ($this->dialogState == 'create'){
383 /* Draw list */
384 $aclList= new DivSelectBox("aclList");
385 $aclList->SetHeight(150);
387 /* Add settings for all categories to the (permanent) list */
388 foreach ($this->aclObjects as $section => $dsc){
389 $summary= "";
390 foreach($this->ocMapping[$section] as $oc){
391 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
392 $this->aclContents[$oc][0] != ""){
394 $summary.= "$oc, ";
395 continue;
396 }
397 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
398 $this->aclContents["$section/$oc"][0] != ""){
400 $summary.= "$oc, ";
401 continue;
402 }
403 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
404 $summary.= "$oc, ";
405 }
406 }
408 /* Set summary... */
409 if ($summary == ""){
410 $summary= '<i>'._("No ACL settings for this category").'</i>';
411 } else {
412 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
413 }
415 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
416 $field2= array("string" => $summary);
417 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='cat_edit_$section' title='"._("Edit categories ACLs")."'>";
418 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='cat_del_$section' title='"._("Clear categories ACLs")."'>";
419 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
420 $aclList->AddEntry(array($field1, $field2, $field3));
421 }
423 $smarty->assign("aclList", $aclList->DrawList());
424 $smarty->assign("aclType", $this->aclType);
425 $smarty->assign("aclTypes", $this->aclTypes);
426 $smarty->assign("target", $this->target);
427 $smarty->assign("targets", $this->targets);
429 /* Assign possible target types */
430 $smarty->assign("targets", $this->targets);
431 foreach ($this->attributes as $attr){
432 $smarty->assign($attr, $this->$attr);
433 }
436 /* Generate list */
437 $tmp= array();
438 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
439 if ($this->target == $field){
440 foreach ($this->$arr as $key => $value){
441 if (!isset($this->recipients[$key])){
442 $tmp[$key]= $value;
443 }
444 }
445 }
446 }
447 $smarty->assign('sources', $tmp);
448 $smarty->assign('recipients', $this->recipients);
450 /* Acl selector if scope is base */
451 if ($this->aclType == 'base'){
452 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
453 }
455 /* Role selector if scope is base */
456 if ($this->aclType == 'role'){
457 $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
458 }
459 }
461 if ($this->dialogState == 'edit'){
462 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
464 /* Collect objects for selected category */
465 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
466 if ($idx == 0){
467 continue;
468 }
469 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
470 }
471 if ($this->aclObject == 'all'){
472 $aclObjects['all']= _("All objects in current subtree");
473 }
475 /* Role selector if scope is base */
476 if ($this->aclType == 'role'){
477 $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
478 } else {
479 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
480 }
481 }
483 /* Show main page */
484 $smarty->assign("dialogState", $this->dialogState);
486 return ($smarty->fetch (get_template_path('acl.tpl')));
487 }
489 function sort_by_priority($list)
490 {
491 $tmp= get_global('plist');
492 $plist= $tmp->info;
493 asort($plist);
494 $newSort = array();
496 foreach($list as $name => $translation){
497 $na = preg_replace("/^.*\//","",$name);
498 $prio = 0;
499 if(isset($plist[$na]['plPriority'])){
500 $prio= $plist[$na]['plPriority'] ;
501 }
503 $newSort[$name] = $prio;
504 }
506 asort($newSort);
508 $ret = array();
509 foreach($newSort as $name => $prio){
510 $ret[$name] = $list[$name];
511 }
512 return($ret);
513 }
515 function buildAclSelector($list)
516 {
517 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
518 $cols= 3;
519 $tmp= get_global('plist');
520 $plist= $tmp->info;
521 asort($plist);
523 /* Add select all/none buttons */
524 $style = "style='width:100px;'";
526 $display .= "<input ".$style." type='button' name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" value='Toggle C'>";
527 $display .= "<input ".$style." type='button' name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" value='Toggle M'>";
528 $display .= "<input ".$style." type='button' name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" value='Toggle D'> - ";
529 $display .= "<input ".$style." type='button' name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" value='Toggle R'>";
530 $display .= "<input ".$style." type='button' name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" value='Toggle W'> - ";
532 $display .= "<input ".$style." type='button' name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" value='R+'>";
533 $display .= "<input ".$style." type='button' name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" value='W+'>";
535 $display .= "<br>";
537 $style = "style='width:50px;'";
538 $display .= "<input ".$style." type='button' name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" value='C+'>";
539 $display .= "<input ".$style." type='button' name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" value='C-'>";
540 $display .= "<input ".$style." type='button' name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" value='M+'>";
541 $display .= "<input ".$style." type='button' name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" value='M-'>";
542 $display .= "<input ".$style." type='button' name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" value='D+'>";
543 $display .= "<input ".$style." type='button' name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" value='D-'> - ";
544 $display .= "<input ".$style." type='button' name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" value='R+'>";
545 $display .= "<input ".$style." type='button' name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" value='R-'>";
546 $display .= "<input ".$style." type='button' name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" value='W+'>";
547 $display .= "<input ".$style." type='button' name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" value='W-'> - ";
549 $display .= "<input ".$style." type='button' name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" value='R+'>";
550 $display .= "<input ".$style." type='button' name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" value='R-'>";
551 $display .= "<input ".$style." type='button' name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" value='W+'>";
552 $display .= "<input ".$style." type='button' name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" value='W-'>";
554 /* Build general objects */
555 $list =$this->sort_by_priority($list);
556 foreach ($list as $key => $name){
558 /* Create sub acl if it does not exist */
559 if (!isset($this->aclContents[$key])){
560 $this->aclContents[$key]= array();
561 $this->aclContents[$key][0]= '';
562 }
563 $currentAcl= $this->aclContents[$key];
565 /* Object header */
566 if($_SESSION['js']) {
567 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
568 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
569 "\n <tr>".
570 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
571 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
572 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
573 "\n </tr>";
574 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
575 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
576 "\n <tr>".
577 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
578 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
579 "\n <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
580 "\n </tr>";
581 } else {
582 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
583 "\n <tr>".
584 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
585 "\n </tr>";
586 }
587 } else {
588 $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
589 "\n <tr>".
590 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
591 "\n </tr>";
592 }
594 /* Generate options */
595 $spc= " ";
596 if ($this->isContainer && $this->aclType != 'base'){
597 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
598 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
599 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
600 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
601 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
602 }
603 } else {
604 $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
605 $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
606 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
607 $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
608 }
609 }
611 /* Global options */
612 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $currentAcl[0])).$spc;
613 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
615 $display.= "\n <tr>".
616 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
617 "\n <td style='background-color:#D4D4D4'> "._("Complete object").": $more_options</td>".
618 "\n </tr>";
620 /* Walk through the list of attributes */
621 $cnt= 1;
622 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
623 asort($splist);
624 if($_SESSION['js']) {
625 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
626 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
627 "\n <td colspan=".$cols.">".
628 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
629 "\n <table style='width:100%;'>";
630 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
631 $display.= "\n <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
632 "\n <td colspan=".$cols.">".
633 "\n <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='position:absolute;overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
634 "\n <table style='width:100%;'>";
635 }
636 }
637 foreach($splist as $attr => $dsc){
639 /* Skip pl* attributes, they are internal... */
640 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
641 continue;
642 }
644 /* Open table row */
645 if ($cnt == 1){
646 $display.= "\n <tr>";
647 }
649 /* Close table row */
650 if ($cnt == $cols){
651 $cnt= 1;
652 $rb= "";
653 $end= "\n </tr>";
654 } else {
655 $cnt++;
656 $rb= "border-right:1px solid #A0A0A0;";
657 $end= "";
658 }
660 /* Collect list of attributes */
661 $state= "";
662 if (isset($currentAcl[$attr])){
663 $state= $currentAcl[$attr];
664 }
665 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
666 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
667 }
669 /* Fill missing td's if needed */
670 if (--$cnt != $cols && $cnt != 0){
671 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
672 }
674 if($_SESSION['js']) {
675 if(isset($_SERVER['HTTP_USER_AGENT']) && (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
676 $display.= "\n </table>".
677 "\n </div>".
678 "\n </td>".
679 "\n </tr>";
680 }
681 }
683 $display.= "\n</table><br />\n";
684 }
686 return ($display);
687 }
690 function mkchkbx($name, $text, $state= FALSE)
691 {
692 $state= $state?"checked":"";
693 return "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."' type=checkbox name='acl_$name' $state>".
694 "\n <label for='acl_$name'>$text</label>";
695 }
698 function mkrwbx($name, $state= "")
699 {
700 $rstate= preg_match('/r/', $state)?'checked':'';
701 $wstate= preg_match('/w/', $state)?'checked':'';
702 return ("\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_r' type=checkbox name='acl_${name}_r' $rstate>".
703 "\n <label for='acl_${name}_r'>"._("read")."</label>".
704 "\n <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_w' type=checkbox name='acl_${name}_w' $wstate>".
705 "\n <label for='acl_${name}_w'>"._("write")."</label>");
706 }
709 function explodeACL($acl)
710 {
711 list($index, $type)= split(':', $acl);
712 $a= array( $index => array("type" => $type,
713 "members" => acl::extractMembers($acl)));
715 /* Handle different types */
716 switch ($type){
718 case 'psub':
719 case 'sub':
720 case 'one':
721 case 'base':
722 $a[$index]['acl']= acl::extractACL($acl);
723 break;
725 case 'role':
726 echo "Role: $acl";
727 break;
729 case 'reset':
730 break;
732 default:
733 print_red(sprintf(_("Unkown ACL type '%s'. Don't know how to handle it."), $type));
734 $a= array();
735 }
737 return ($a);
738 }
741 function extractMembers($acl)
742 {
743 global $config;
744 $a= array();
746 /* Rip acl off the string, seperate by ',' and place it in an array */
747 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
748 if ($ms == $acl){
749 return $a;
750 }
751 $ma= split(',', $ms);
753 /* Decode dn's, fill with informations from LDAP */
754 $ldap= $config->get_ldap_link();
755 foreach ($ma as $memberdn){
756 $dn= base64_decode($memberdn);
757 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
759 /* Found entry... */
760 if ($ldap->count()){
761 $attrs= $ldap->fetch();
762 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
763 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
764 } else {
765 $a['G:'.$dn]= $attrs['cn'][0];
766 if (isset($attrs['description'][0])){
767 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
768 }
769 }
771 /* ... or not */
772 } else {
773 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
774 }
775 }
777 return ($a);
778 }
781 function extractACL($acl)
782 {
783 /* Rip acl off the string, seperate by ',' and place it in an array */
784 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:(.*)$/', '\1', $acl);
785 $aa= split(',', $as);
786 $a= array();
788 /* Dis-assemble single ACLs */
789 foreach($aa as $sacl){
791 /* Dis-assemble field ACLs */
792 $ao= split('#', $sacl);
793 $gobject= "";
794 foreach($ao as $idx => $ssacl){
796 /* First is department with global acl */
797 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
798 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
799 if ($idx == 0){
800 /* Create hash for this object */
801 $gobject= $object;
802 $a[$gobject]= array();
804 /* Append ACL if set */
805 if ($gacl != ""){
806 $a[$gobject]= array($gacl);
807 }
808 } else {
810 /* All other entries get appended... */
811 list($field, $facl)= split(';', $ssacl);
812 $a[$gobject][$field]= $facl;
813 }
815 }
816 }
818 return ($a);
819 }
822 function assembleAclSummary($entry)
823 {
824 $summary= "";
826 /* Summarize ACL */
827 if (isset($entry['acl'])){
828 $acl= "";
829 foreach ($entry['acl'] as $name => $object){
830 if (count($object)){
831 $acl.= "$name, ";
832 }
833 }
834 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
835 }
837 /* Summarize members */
838 if ($summary != ""){
839 $summary.= ", ";
840 }
841 if (count($entry['members'])){
842 $summary.= _("Members:")." ";
843 foreach ($entry['members'] as $cn){
844 $cn= preg_replace('/ \[.*$/', '', $cn);
845 $summary.= $cn.", ";
846 }
847 } else {
848 $summary.= _("ACL is valid for all users");
849 }
851 return (preg_replace('/, $/', '', $summary));
852 }
855 function loadAclEntry($new= FALSE)
856 {
857 /* New entry gets presets... */
858 if ($new){
859 $this->aclType= 'base';
860 $this->recipients= array();
861 $this->aclContents= array();
862 } else {
863 $acl= $this->gosaAclEntry[$this->currentIndex];
864 $this->aclType= $acl['type'];
865 $this->recipients= $acl['members'];
866 $this->aclContents= $acl['acl'];
867 }
869 $this->wasNewEntry= $new;
870 }
873 function aclPostHandler()
874 {
875 if (isset($_POST['save_acl'])){
876 $this->save();
877 return TRUE;
878 }
880 return FALSE;
881 }
884 function save()
885 {
886 /* Assemble ACL's */
887 $tmp_acl= array();
888 foreach ($this->gosaAclEntry as $prio => $entry){
889 $final= "";
890 $members= "";
891 if (isset($entry['members'])){
892 foreach ($entry['members'] as $key => $dummy){
893 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
894 }
895 }
896 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
898 /* ACL's if needed */
899 if ($entry['type'] != "reset" && $entry['type'] != "role"){
900 $acl= ":";
901 if (isset($entry['acl'])){
902 foreach ($entry['acl'] as $object => $contents){
904 /* Only save, if we've some contents in there... */
905 if (count($contents)){
906 $acl.= $object.";";
908 foreach($contents as $attr => $permission){
910 /* First entry? Its the one for global settings... */
911 if ($attr == '0'){
912 $acl.= $permission;
913 } else {
914 $acl.= '#'.$attr.';'.$permission;
915 }
917 }
918 $acl.= ',';
919 }
921 }
922 }
923 $final.= preg_replace('/,$/', '', $acl);
924 }
926 $tmp_acl[]= $final;
927 }
929 /* Call main method */
930 plugin::save();
932 /* Finally (re-)assign it... */
933 $this->attrs['gosaAclEntry']= $tmp_acl;
935 /* Remove acl from this entry if it is empty... */
936 if (!count($tmp_acl)){
937 /* Remove attribute */
938 if ($this->initially_was_account){
939 $this->attrs['gosaAclEntry']= array();
940 } else {
941 if (isset($this->attrs['gosaAclEntry'])){
942 unset($this->attrs['gosaAclEntry']);
943 }
944 }
946 /* Remove object class */
947 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
948 }
950 /* Do LDAP modifications */
951 $ldap= $this->config->get_ldap_link();
952 $ldap->cd($this->dn);
953 $this->cleanup();
954 $ldap->modify ($this->attrs);
956 show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
958 /* Refresh users ACLs */
959 $ui= get_userinfo();
960 $ui->loadACL();
961 $_SESSION['ui']= $ui;
962 }
965 function remove_from_parent()
966 {
967 }
969 }
971 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
972 ?>