1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /*! \brief ACL management plugin */
24 class acl extends plugin
25 {
26 /* Definitions */
27 var $plHeadline= "Access control";
28 var $plDescription= "Manage access control lists";
30 /* attribute list for save action */
31 var $attributes= array('gosaAclEntry');
32 var $objectclasses= array('gosaAcl');
34 /* Helpers */
35 var $dialogState= "head";
36 var $gosaAclEntry= array();
37 var $aclType= "";
38 var $aclObject= "";
39 var $aclContents= array();
40 var $target= "group";
41 var $aclTypes= array();
42 var $aclObjects= array();
43 var $aclFilter= "";
44 var $aclMyObjects= array();
45 var $users= array();
46 var $roles= array();
47 var $groups= array();
48 var $recipients= array();
49 var $isContainer= FALSE;
50 var $currentIndex= 0;
51 var $wasNewEntry= FALSE;
52 var $ocMapping= array();
53 var $savedAclContents= array();
54 var $myAclObjects = array();
55 var $acl_category = "acl/";
57 function acl (&$config, $parent, $dn= NULL)
58 {
59 /* Include config object */
60 plugin::plugin($config, $dn);
62 /* Load ACL's */
63 $this->gosaAclEntry= array();
64 if (isset($this->attrs['gosaAclEntry'])){
65 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
66 $acl= $this->attrs['gosaAclEntry'][$i];
67 $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
68 }
69 }
70 ksort($this->gosaAclEntry);
72 /* Save parent - we've to know more about it than other plugins... */
73 $this->parent= &$parent;
75 /* Container? */
76 if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
77 $this->isContainer= TRUE;
78 }
80 /* Users */
81 $ui= get_userinfo();
82 $tag= $ui->gosaUnitTag;
83 $ldap= $config->get_ldap_link();
84 $ldap->cd($config->current['BASE']);
85 if ($tag == ""){
86 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
87 } else {
88 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
89 }
90 while ($attrs= $ldap->fetch()){
92 // Allow objects without cn to be listed without causing an error.
93 if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
94 $this->users['U:'.$attrs['dn']]= $attrs['uid'][0];
95 }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
96 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0];
97 }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
98 $this->users['U:'.$attrs['dn']]= $attrs['dn'];
99 }else{
100 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
101 }
103 }
104 ksort($this->users);
106 /* Groups */
107 $ldap->cd($config->current['BASE']);
108 # if ($tag == ""){
109 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
110 # } else {
111 # $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
112 # }
113 while ($attrs= $ldap->fetch()){
114 $dsc= "";
115 if (isset($attrs['description'][0])){
116 $dsc= $attrs['description'][0];
117 }
118 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
119 }
120 $this->groups['G:*']= _("All users");
121 ksort($this->groups);
123 /* Roles */
124 $ldap->cd($config->current['BASE']);
125 # if ($tag == ""){
126 $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
127 # } else {
128 # $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
129 # }
130 while ($attrs= $ldap->fetch()){
131 $dsc= "";
132 if (isset($attrs['description'][0])){
133 $dsc= $attrs['description'][0];
134 }
136 $role_id = $attrs['dn'];
138 $this->roles[$role_id]['acls'] =array();
139 for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
140 $acl= $attrs['gosaAclTemplate'][$i];
141 $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
142 }
143 $this->roles[$role_id]['description'] = $dsc;
144 $this->roles[$role_id]['cn'] = $attrs['cn'][0];
145 }
147 /* Objects */
148 $tmp= session::global_get('plist');
149 $plist= $tmp->info;
150 $cats = array();
151 if (isset($this->parent) && $this->parent !== NULL){
152 $oc= array();
153 foreach ($this->parent->by_object as $key => $obj){
154 $oc= array_merge($oc, $obj->objectclasses);
155 if(isset($obj->acl_category)){
156 $tmp= str_replace("/","",$obj->acl_category);
157 $cats[$tmp] = $tmp;
158 }
159 }
160 if (in_array_ics('organizationalUnit', $oc)){
161 $this->isContainer= TRUE;
162 }
163 } else {
164 $oc= $this->attrs['objectClass'];
165 }
167 /* Extract available categories from plugin info list */
168 foreach ($plist as $class => $acls){
170 /* Only feed categories */
171 if (isset($acls['plCategory'])){
173 /* Walk through supplied list and feed only translated categories */
174 foreach($acls['plCategory'] as $idx => $data){
176 /* Non numeric index means -> base object containing more informations */
177 if (preg_match('/^[0-9]+$/', $idx)){
179 if (!isset($this->ocMapping[$data])){
180 $this->ocMapping[$data]= array();
181 $this->ocMapping[$data][]= '0';
182 }
184 if(isset($cats[$data])){
185 $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
186 }
187 $this->ocMapping[$data][]= $class;
188 } else {
189 if (!isset($this->ocMapping[$idx])){
190 $this->ocMapping[$idx]= array();
191 $this->ocMapping[$idx][]= '0';
192 }
193 $this->ocMapping[$idx][]= $class;
194 $this->aclObjects[$idx]= $data['description'];
196 /* Additionally filter the classes we're interested in in "self edit" mode */
197 if (is_array($data['objectClass'])){
198 foreach($data['objectClass'] as $objectClass){
199 if (in_array_ics($objectClass, $oc)){
200 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
201 break;
202 }
203 }
204 } else {
205 if (in_array_ics($data['objectClass'], $oc)){
206 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
207 }
208 }
209 }
211 }
212 }
213 }
214 $this->aclObjects['all']= '* '._("All categories");
215 $this->ocMapping['all']= array('0' => 'all');
217 /* Sort categories */
218 asort($this->aclObjects);
220 /* Fill acl types */
221 if ($this->isContainer){
222 $this->aclTypes= array("reset" => _("Reset ACLs"),
223 "one" => _("One level"),
224 "base" => _("Current object"),
225 "sub" => _("Complete subtree"),
226 "psub" => _("Complete subtree (permanent)"),
227 "role" => _("Use ACL defined in role"));
228 } else {
229 $this->aclTypes= array("base" => _("Current object"),
230 "role" => _("Use ACL defined in role"));
231 }
232 asort($this->aclTypes);
233 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
234 asort($this->targets);
236 /* Finally - we want to get saved... */
237 $this->is_account= TRUE;
238 }
241 function execute()
242 {
243 /* Call parent execute */
244 plugin::execute();
246 $tmp= session::global_get('plist');
247 $plist= $tmp->info;
249 /* Handle posts */
250 if (isset($_POST['new_acl'])){
251 $this->dialogState= 'create';
252 $this->dialog= TRUE;
253 $this->currentIndex= count($this->gosaAclEntry);
254 $this->loadAclEntry(TRUE);
255 }
257 $new_acl= array();
258 $aclDialog= FALSE;
259 $firstedit= FALSE;
261 /* Act on HTML post and gets here.
262 */
263 if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
264 $id = trim($_GET['id']);
265 $this->dialogState= 'create';
266 $firstedit= TRUE;
267 $this->dialog= TRUE;
268 $this->currentIndex= $id;
269 $this->loadAclEntry();
270 }
272 foreach($_POST as $name => $post){
274 /* Actions... */
275 if (preg_match('/^acl_edit_[0-9]*$/', $name)){
276 $this->dialogState= 'create';
277 $firstedit= TRUE;
278 $this->dialog= TRUE;
279 $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
280 $this->loadAclEntry();
281 continue;
282 }
284 if (preg_match('/^cat_edit_.*$/', $name)){
285 $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
286 $this->dialogState= 'edit';
287 foreach ($this->ocMapping[$this->aclObject] as $oc){
288 if (isset($this->aclContents[$oc])){
289 $this->savedAclContents[$oc]= $this->aclContents[$oc];
290 }
291 }
292 continue;
293 }
295 /* Only handle posts, if we allowed to modify ACLs */
296 if(!$this->acl_is_writeable("")){
297 continue;
298 }
300 if (preg_match('/^acl_del_[0-9]*$/', $name)){
301 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
302 continue;
303 }
305 if (preg_match('/^cat_del_.*$/', $name)){
306 $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
307 foreach ($this->ocMapping[$idx] as $key){
308 if(isset($this->aclContents[$idx]))
309 unset($this->aclContents[$idx]);
310 if(isset($this->aclContents["$idx/$key"]))
311 unset($this->aclContents["$idx/$key"]);
312 }
313 continue;
314 }
316 /* Sorting... */
317 if (preg_match('/^sortup_[0-9]*$/', $name)){
318 $index= preg_replace('/^sortup_([0-9]*)$/', '\1', $name);
319 if ($index > 0){
320 $tmp= $this->gosaAclEntry[$index];
321 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index-1];
322 $this->gosaAclEntry[$index-1]= $tmp;
323 }
324 continue;
325 }
326 if (preg_match('/^sortdown_[0-9]*$/', $name)){
327 $index= preg_replace('/^sortdown_([0-9]*)$/', '\1', $name);
328 if ($index < count($this->gosaAclEntry)-1){
329 $tmp= $this->gosaAclEntry[$index];
330 $this->gosaAclEntry[$index]= $this->gosaAclEntry[$index+1];
331 $this->gosaAclEntry[$index+1]= $tmp;
332 }
333 continue;
334 }
336 /* ACL saving... */
337 if (preg_match('/^acl_.*_[^xy]$/', $name)){
338 list($dummy, $object, $attribute, $value)= explode('_', $name);
340 /* Skip for detection entry */
341 if ($object == 'dummy') {
342 continue;
343 }
345 /* Ordinary ACLs */
346 if (!isset($new_acl[$object])){
347 $new_acl[$object]= array();
348 }
349 if (isset($new_acl[$object][$attribute])){
350 $new_acl[$object][$attribute].= $value;
351 } else {
352 $new_acl[$object][$attribute]= $value;
353 }
354 }
356 // Remember the selected ACL role.
357 if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
358 $this->aclContents = "";
359 $this->aclContents = base64_decode($_POST['selected_role']);
360 }
361 }
363 if(isset($_POST['acl_dummy_0_0_0'])){
364 $aclDialog= TRUE;
365 }
367 if($this->acl_is_writeable("")){
369 /* Only be interested in new acl's, if we're in the right _POST place */
370 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
372 foreach ($this->ocMapping[$this->aclObject] as $oc){
374 if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
375 unset($this->aclContents[$oc]);
376 }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
377 unset($this->aclContents[$this->aclObject.'/'.$oc]);
378 }else{
379 # trigger_error("Huhm?");
380 }
381 if (isset($new_acl[$oc]) && is_array($new_acl)){
382 $this->aclContents[$oc]= $new_acl[$oc];
383 }
384 if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
385 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
386 }
387 }
388 }
390 /* Save new acl in case of base edit mode */
391 if ($this->aclType == 'base' && !$firstedit){
392 $this->aclContents= $new_acl;
393 }
394 }
396 /* Cancel new acl? */
397 if (isset($_POST['cancel_new_acl'])){
398 $this->dialogState= 'head';
399 $this->dialog= FALSE;
400 if ($this->wasNewEntry){
401 unset ($this->gosaAclEntry[$this->currentIndex]);
402 }
403 }
405 /* Save common values */
406 if($this->acl_is_writeable("")){
407 foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
408 if (isset($_POST[$key])){
409 $this->$key= validate($_POST[$key]);
410 }
411 }
412 }
414 /* Store ACL in main object? */
415 if (isset($_POST['submit_new_acl'])){
416 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
417 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
418 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
419 $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
420 $this->dialogState= 'head';
421 $this->dialog= FALSE;
422 }
424 /* Cancel edit acl? */
425 if (isset($_POST['cancel_edit_acl'])){
426 $this->dialogState= 'create';
427 foreach ($this->ocMapping[$this->aclObject] as $oc){
428 if (isset($this->savedAclContents[$oc])){
429 $this->aclContents[$oc]= $this->savedAclContents[$oc];
430 }
431 }
432 }
434 /* Save edit acl? */
435 if (isset($_POST['submit_edit_acl'])){
436 $this->dialogState= 'create';
437 }
439 /* Add acl? */
440 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
441 $this->dialogState= 'edit';
442 $this->savedAclContents= array();
443 foreach ($this->ocMapping[$this->aclObject] as $oc){
444 if (isset($this->aclContents[$oc])){
445 $this->savedAclContents[$oc]= $this->aclContents[$oc];
446 }
447 }
448 }
450 /* Add to list? */
451 if (isset($_POST['add']) && isset($_POST['source'])){
452 foreach ($_POST['source'] as $key){
453 if ($this->target == 'user'){
454 $this->recipients[$key]= $this->users[$key];
455 }
456 if ($this->target == 'group'){
457 $this->recipients[$key]= $this->groups[$key];
458 }
459 }
460 ksort($this->recipients);
461 }
463 /* Remove from list? */
464 if (isset($_POST['del']) && isset($_POST['recipient'])){
465 foreach ($_POST['recipient'] as $key){
466 unset($this->recipients[$key]);
467 }
468 }
470 /* Create templating instance */
471 $smarty= get_smarty();
472 $smarty->assign("acl_readable",$this->acl_is_readable(""));
473 if(!$this->acl_is_readable("")){
474 return ($smarty->fetch (get_template_path('acl.tpl')));
475 }
477 if ($this->dialogState == 'head'){
478 /* Draw list */
479 $aclList= new divSelectBox("aclList");
480 $aclList->SetHeight(450);
482 /* Fill in entries */
483 foreach ($this->gosaAclEntry as $key => $entry){
484 if(!$this->acl_is_readable("")) continue;
486 $action ="";
488 if($this->acl_is_readable("")){
489 $link = "<a href=?plug=".$_GET['plug']."&id=".$key."&act=edit>".$this->assembleAclSummary($entry)."</a>";
490 }else{
491 $link = $this->assembleAclSummary($entry);
492 }
494 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
495 $field2= array("string" => $link);
497 if($this->acl_is_writeable("")){
498 $action.= image('images/lists/sort-up.png', 'sortup_'.$key,"","top");
499 $action.= image('images/lists/sort-down.png', 'sortdown_'.$key,"","bottom");
500 }
502 if($this->acl_is_readable("")){
503 $action.= image('images/lists/edit.png','acl_edit_'.$key,msgPool::editButton(_("ACL")));
504 }
505 if($this->acl_is_removeable("")){
506 $action.= image('images/lists/trash.png','acl_del_'.$key,msgPool::delButton(_("ACL")));
507 }
509 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
510 $aclList->AddEntry(array($field1, $field2, $field3));
511 }
513 $smarty->assign("aclList", $aclList->DrawList());
514 }
516 if ($this->dialogState == 'create'){
517 /* Draw list */
518 $aclList= new divSelectBox("aclList");
519 $aclList->SetHeight(150);
521 // Create a map of all used sections, this allows us to simply hide the remove button
522 // if no acl is configured for the given section
523 // e.g. ';all;department/country;users/user;
524 $usedList = ";".implode(array_keys($this->aclContents),';').";";
526 /* Add settings for all categories to the (permanent) list */
527 foreach ($this->aclObjects as $section => $dsc){
528 $summary= "";
529 foreach($this->ocMapping[$section] as $oc){
530 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
531 $this->aclContents[$oc][0] != ""){
533 $summary.= "$oc, ";
534 continue;
535 }
536 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
537 $summary.= "$oc, ";
538 continue;
539 }
540 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
541 $summary.= "$oc, ";
542 }
543 }
545 /* Set summary... */
546 if ($summary == ""){
547 $summary= '<i>'._("No ACL settings for this category!").'</i>';
548 } else {
549 $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
550 }
552 $actions ="";
553 if($this->acl_is_readable("")){
554 $actions.= image('images/lists/edit.png','cat_edit_'.$section, msgPool::editButton(_("category ACL")));
555 }
556 if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
557 $actions.= image('images/lists/trash.png','cat_del_'.$section, msgPool::delButton(_("category ACL")));
558 }
560 $field1= array("string" => $dsc, "attach" => "style='width:100px'");
561 $field2= array("string" => $summary);
562 $field3= array("string" => $actions, "attach" => "style='border-right:0px;width:50px'");
563 $aclList->AddEntry(array($field1, $field2, $field3));
564 }
566 $smarty->assign("aclList", $aclList->DrawList());
567 $smarty->assign("aclType", $this->aclType);
568 $smarty->assign("aclFilter", $this->aclFilter);
569 $smarty->assign("aclTypes", $this->aclTypes);
570 $smarty->assign("target", $this->target);
571 $smarty->assign("targets", $this->targets);
573 /* Assign possible target types */
574 $smarty->assign("targets", $this->targets);
575 foreach ($this->attributes as $attr){
576 $smarty->assign($attr, $this->$attr);
577 }
580 /* Generate list */
581 $tmp= array();
582 if ($this->target == "group" && !isset($this->recipients["G:*"])){
583 $tmp["G:*"]= _("All users");
584 }
585 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
586 if ($this->target == $field){
587 foreach ($this->$arr as $key => $value){
588 if (!isset($this->recipients[$key])){
589 $tmp[$key]= $value;
590 }
591 }
592 }
593 }
594 $smarty->assign('sources', $tmp);
595 $smarty->assign('recipients', $this->recipients);
597 /* Acl selector if scope is base */
598 if ($this->aclType == 'base'){
599 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
600 }
602 /* Role selector if scope is base */
603 if ($this->aclType == 'role'){
604 $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
605 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
606 }
607 }
609 if ($this->dialogState == 'edit'){
610 $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
612 /* Collect objects for selected category */
613 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
614 if ($idx == 0){
615 continue;
616 }
617 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
618 }
619 if ($this->aclObject == 'all'){
620 $aclObjects['all']= _("All objects in current subtree");
621 }
623 /* Role selector if scope is base */
624 if ($this->aclType == 'role'){
625 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
626 } else {
627 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
628 }
629 }
631 /* Show main page */
632 $smarty->assign("dialogState", $this->dialogState);
634 /* Assign acls */
635 $smarty->assign("acl_createable",$this->acl_is_createable());
636 $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
637 $smarty->assign("acl_readable" ,$this->acl_is_readable(""));
638 $smarty->assign("acl_removeable",$this->acl_is_removeable());
640 return ($smarty->fetch (get_template_path('acl.tpl')));
641 }
644 function sort_by_priority($list)
645 {
646 $tmp= session::global_get('plist');
647 $plist= $tmp->info;
648 asort($plist);
649 $newSort = array();
651 foreach($list as $name => $translation){
652 $na = preg_replace("/^.*\//","",$name);
653 $prio = 0;
654 if(isset($plist[$na]['plPriority'])){
655 $prio= $plist[$na]['plPriority'] ;
656 }
658 $newSort[$name] = $prio;
659 }
661 asort($newSort);
663 $ret = array();
664 foreach($newSort as $name => $prio){
665 $ret[$name] = $list[$name];
666 }
667 return($ret);
668 }
671 function buildRoleSelector($list)
672 {
673 $D_List =new divSelectBox("Acl_Roles");
675 $selected = $this->aclContents;
676 if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
677 $selected = key($list);
678 }
680 $str ="";
681 foreach($list as $dn => $values){
683 if($dn == $selected){
684 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
685 }else{
686 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
687 }
689 $field1 = array("string" => $option) ;
690 $field2 = array("string" => $values['cn'], "attach" => "style='width:200px;'") ;
691 $field3 = array("string" => $values['description'],"attach" => "style='border-right:0px;'") ;
693 $D_List->AddEntry(array($field1,$field2,$field3));
694 }
695 return($D_List->DrawList());
696 }
699 function buildAclSelector($list)
700 {
701 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
702 $cols= 3;
703 $tmp= session::global_get('plist');
704 $plist= $tmp->info;
705 asort($plist);
707 /* Add select all/none buttons */
708 $style = "style='width:100px;'";
710 if($this->acl_is_writeable("")){
711 $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
712 $display .= "<button type='button' ".$style." name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
713 $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
714 $display .= "<button type='button' ".$style." name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
715 $display .= "<button type='button' ".$style." name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
717 $display .= "<button type='button' ".$style." name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
718 $display .= "<button type='button' ".$style." name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
720 $display .= "<br>";
722 $style = "style='width:50px;'";
723 $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
724 $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
725 $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
726 $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
727 $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
728 $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
729 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
730 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
731 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
732 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
734 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
735 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
736 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
737 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
738 }
740 /* Build general objects */
741 $list =$this->sort_by_priority($list);
742 foreach ($list as $key => $name){
744 /* Create sub acl if it does not exist */
745 if (!isset($this->aclContents[$key])){
746 $this->aclContents[$key]= array();
747 }
748 if(!isset($this->aclContents[$key][0])){
749 $this->aclContents[$key][0]= '';
750 }
752 $currentAcl= $this->aclContents[$key];
754 /* Get the overall plugin acls
755 */
756 $overall_acl ="";
757 if(isset($currentAcl[0])){
758 $overall_acl = $currentAcl[0];
759 }
761 // Detect configured plugins
762 $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
764 /* Object header */
765 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
767 if($expand){
768 $back_color = "#C8C8FF";
769 }else{
770 $back_color = "#C8C8C8";
771 }
773 if(isset($_SERVER['HTTP_USER_AGENT']) &&
774 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
775 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
776 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
777 "\n <tr>".
778 "\n <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
779 "\n <td align='right' style='background-color:{$back_color};height:1.8em;'>".
780 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
781 "\n </tr>";
782 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
783 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
784 "\n <tr>".
785 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
786 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
787 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
788 "\n </tr>";
789 } else {
790 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
791 "\n <tr>".
792 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
793 "\n </tr>";
794 }
796 /* Generate options */
797 $spc= " ";
798 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
799 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
800 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
801 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
802 $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
803 }
805 /* Global options */
806 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $overall_acl)).$spc;
807 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
809 $display.= "\n <tr>".
810 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
811 "\n <td style='background-color:#D4D4D4'> "._("Complete object").": $more_options</td>".
812 "\n </tr>";
814 /* Walk through the list of attributes */
815 $cnt= 1;
816 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
817 if(session::global_get('js')) {
818 if(isset($_SERVER['HTTP_USER_AGENT']) &&
819 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
820 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
821 "\n <td colspan=".$cols.">".
822 "\n <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
823 "\n <table style='width:100%;' summary='{$name}'>";
824 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
825 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
826 "\n <td colspan=".$cols.">".
827 "\n <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
828 "\n <table style='width:100%;' summary='{$name}'>";
829 }else{
830 }
831 }
834 foreach($splist as $attr => $dsc){
836 /* Skip pl* attributes, they are internal... */
837 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
838 continue;
839 }
841 /* Open table row */
842 if ($cnt == 1){
843 $display.= "\n <tr>";
844 }
846 /* Close table row */
847 if ($cnt == $cols){
848 $cnt= 1;
849 $rb= "";
850 $end= "\n </tr>";
851 } else {
852 $cnt++;
853 $rb= "border-right:1px solid #A0A0A0;";
854 $end= "";
855 }
857 /* Collect list of attributes */
858 $state= "";
859 if (isset($currentAcl[$attr])){
860 $state= $currentAcl[$attr];
861 }
862 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
863 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
864 }
866 /* Fill missing td's if needed */
867 if (--$cnt != $cols && $cnt != 0){
868 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
869 }
871 if(session::global_get('js')) {
872 if(isset($_SERVER['HTTP_USER_AGENT']) &&
873 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
874 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) ||
875 (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
876 $display.= "\n </table>".
877 "\n </div>".
878 "\n </td>".
879 "\n </tr>";
880 }
881 }
883 $display.= "\n</table><br />\n";
884 }
886 return ($display);
887 }
890 function mkchkbx($name, $text, $state= FALSE)
891 {
892 $state= $state?"checked":"";
893 if($this->acl_is_writeable("")){
894 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
895 return "\n <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
896 "\n <label for='acl_$tname'>$text</label>";
897 }else{
898 return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
899 }
900 }
903 function mkrwbx($name, $state= "")
904 {
905 $rstate= preg_match('/r/', $state)?'checked':'';
906 $wstate= preg_match('/w/', $state)?'checked':'';
907 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
909 if($this->acl_is_writeable("")){
910 return ("\n <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
911 "\n <label for='acl_".$tname."_r'>"._("read")."</label>".
912 "\n <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
913 "\n <label for='acl_".$tname."_w'>"._("write")."</label>");
914 }else{
915 return ("\n <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
916 "\n <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
917 }
918 }
921 static function explodeACL($acl)
922 {
924 $list= explode(':', $acl);
925 if(count($list) == 5){
926 list($index, $type,$member,$permission,$filter)= $list;
927 $filter = base64_decode($filter);
928 }else{
929 $filter = "";
930 list($index, $type,$member,$permission)= $list;
931 }
933 $a= array( $index => array("type" => $type,
934 "filter"=> $filter,
935 "members" => acl::extractMembers($acl,$type == "role")));
937 /* Handle different types */
938 switch ($type){
940 case 'psub':
941 case 'sub':
942 case 'one':
943 case 'base':
944 $a[$index]['acl']= acl::extractACL($acl);
945 break;
947 case 'role':
948 $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
949 break;
951 case 'reset':
952 break;
954 default:
955 msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
956 $a= array();
957 }
958 return ($a);
959 }
962 static function extractMembers($acl,$role = FALSE)
963 {
964 global $config;
965 $a= array();
967 /* Rip acl off the string, seperate by ',' and place it in an array */
968 if($role){
969 $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
970 }else{
971 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
972 }
973 if ($ms == $acl){
974 return $a;
975 }
976 $ma= explode(',', $ms);
978 /* Decode dn's, fill with informations from LDAP */
979 $ldap= $config->get_ldap_link();
980 foreach ($ma as $memberdn){
981 // Check for wildcard here
982 $dn= base64_decode($memberdn);
983 if ($dn != "*") {
984 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
986 /* Found entry... */
987 if ($ldap->count()){
988 $attrs= $ldap->fetch();
989 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
990 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
991 } else {
992 $a['G:'.$dn]= $attrs['cn'][0];
993 if (isset($attrs['description'][0])){
994 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
995 }
996 }
998 /* ... or not */
999 } else {
1000 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1001 }
1003 } else {
1004 $a['G:*']= sprintf(_("All users"));
1005 }
1006 }
1008 return ($a);
1009 }
1012 static function extractACL($acl)
1013 {
1014 /* Rip acl off the string, seperate by ',' and place it in an array */
1015 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1016 $aa= explode(',', $as);
1017 $a= array();
1019 /* Dis-assemble single ACLs */
1020 foreach($aa as $sacl){
1022 /* Dis-assemble field ACLs */
1023 $ao= explode('#', $sacl);
1024 $gobject= "";
1025 foreach($ao as $idx => $ssacl){
1027 /* First is department with global acl */
1028 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1029 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1030 if ($idx == 0){
1031 /* Create hash for this object */
1032 $gobject= $object;
1033 $a[$gobject]= array();
1035 /* Append ACL if set */
1036 if ($gacl != ""){
1037 $a[$gobject]= array($gacl);
1038 }
1039 } else {
1041 /* All other entries get appended... */
1042 list($field, $facl)= explode(';', $ssacl);
1043 $a[$gobject][$field]= $facl;
1044 }
1046 }
1047 }
1049 return ($a);
1050 }
1053 function assembleAclSummary($entry)
1054 {
1055 $summary= "";
1057 /* Summarize ACL */
1058 if (isset($entry['acl'])){
1059 $acl= "";
1061 if($entry['type'] == "role"){
1063 if(isset($this->roles[$entry['acl']])){
1064 $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1065 }else{
1066 $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1067 }
1068 }else{
1069 foreach ($entry['acl'] as $name => $object){
1070 if (count($object)){
1071 $acl.= "$name, ";
1072 }
1073 }
1074 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1075 }
1076 }
1079 /* Summarize members */
1080 if(!($this instanceOf aclrole)){
1081 if ($summary != ""){
1082 $summary.= ", ";
1083 }
1084 if (count($entry['members'])){
1085 $summary.= _("Members").": ";
1086 foreach ($entry['members'] as $cn){
1087 $cn= preg_replace('/ \[.*$/', '', $cn);
1088 $summary.= $cn.", ";
1089 }
1090 } else {
1091 $summary.= "<font color='red'><i>"._("inactive")." - "._("No members")."</i></font>";
1092 }
1093 }
1094 return (preg_replace('/, $/', '', $summary));
1095 }
1098 function loadAclEntry($new= FALSE)
1099 {
1100 /* New entry gets presets... */
1101 if ($new){
1102 $this->aclType= 'base';
1103 $this->aclFilter= "";
1104 $this->recipients= array();
1105 $this->aclContents= array();
1106 } else {
1107 $acl= $this->gosaAclEntry[$this->currentIndex];
1108 $this->aclType= $acl['type'];
1109 $this->recipients= $acl['members'];
1110 $this->aclContents= $acl['acl'];
1111 $this->aclFilter= $acl['filter'];
1112 }
1114 $this->wasNewEntry= $new;
1115 }
1118 function aclPostHandler()
1119 {
1120 if (isset($_POST['save_acl'])){
1121 $this->save();
1122 return TRUE;
1123 }
1125 return FALSE;
1126 }
1129 function PrepareForCopyPaste($source)
1130 {
1131 plugin::PrepareForCopyPaste($source);
1133 $dn = $source['dn'];
1134 $acl_c = new acl($this->config, $this->parent,$dn);
1135 $this->gosaAclEntry = $acl_c->gosaAclEntry;
1136 }
1139 function save()
1140 {
1141 /* Assemble ACL's */
1142 $tmp_acl= array();
1144 foreach ($this->gosaAclEntry as $prio => $entry){
1145 $final= "";
1146 $members= "";
1147 if (isset($entry['members'])){
1148 foreach ($entry['members'] as $key => $dummy){
1149 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1150 }
1151 }
1153 if($entry['type'] != "role"){
1154 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1155 }else{
1156 $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1157 }
1159 /* ACL's if needed */
1160 if ($entry['type'] != "reset" && $entry['type'] != "role"){
1161 $acl= ":";
1162 if (isset($entry['acl'])){
1163 foreach ($entry['acl'] as $object => $contents){
1165 /* Only save, if we've some contents in there... */
1166 if (count($contents)){
1167 $acl.= $object.";";
1169 foreach($contents as $attr => $permission){
1171 /* First entry? Its the one for global settings... */
1172 if ($attr == '0'){
1173 $acl.= $permission;
1174 } else {
1175 $acl.= '#'.$attr.';'.$permission;
1176 }
1178 }
1179 $acl.= ',';
1180 }
1182 }
1183 }
1184 $final.= preg_replace('/,$/', '', $acl);
1185 }
1187 /* Append additional filter options
1188 */
1189 if(!empty($entry['filter'])){
1190 $final .= ":".base64_encode($entry['filter']);
1191 }
1193 $tmp_acl[]= $final;
1194 }
1196 /* Call main method */
1197 plugin::save();
1199 /* Finally (re-)assign it... */
1200 $this->attrs['gosaAclEntry']= $tmp_acl;
1202 /* Remove acl from this entry if it is empty... */
1203 if (!count($tmp_acl)){
1204 /* Remove attribute */
1205 if ($this->initially_was_account){
1206 $this->attrs['gosaAclEntry']= array();
1207 } else {
1208 if (isset($this->attrs['gosaAclEntry'])){
1209 unset($this->attrs['gosaAclEntry']);
1210 }
1211 }
1213 /* Remove object class */
1214 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1215 }
1217 /* Do LDAP modifications */
1218 $ldap= $this->config->get_ldap_link();
1219 $ldap->cd($this->dn);
1220 $this->cleanup();
1221 $ldap->modify ($this->attrs);
1223 if(count($this->attrs)){
1224 new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1225 }
1227 if (!$ldap->success()){
1228 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1229 }
1231 /* Refresh users ACLs */
1232 $ui= get_userinfo();
1233 $ui->loadACL();
1234 session::global_set('ui',$ui);
1235 }
1238 function remove_from_parent()
1239 {
1240 plugin::remove_from_parent();
1242 /* include global link_info */
1243 $ldap= $this->config->get_ldap_link();
1245 $ldap->cd($this->dn);
1246 $this->cleanup();
1247 $ldap->modify ($this->attrs);
1249 new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1251 /* Optionally execute a command after we're done */
1252 $this->handle_post_events("remove",array("uid" => $this->uid));
1253 }
1256 /* Return plugin informations for acl handling */
1257 static function plInfo()
1258 {
1259 return (array(
1260 "plShortName" => _("ACL"),
1261 "plDescription" => _("ACL")." ("._("Access control list").")",
1262 "plSelfModify" => FALSE,
1263 "plDepends" => array(),
1264 "plPriority" => 0,
1265 "plSection" => array("administration"),
1266 "plCategory" => array("acl" => array("description" => _("ACL")." & "._("ACL roles"),
1267 "objectClass" => array("gosaAcl","gosaRole"))),
1268 "plProvidedAcls"=> array(
1269 // "cn" => _("Role name"),
1270 // "description" => _("Role description")
1271 )
1273 ));
1274 }
1277 /* Remove acls defined for $src */
1278 function remove_acl()
1279 {
1280 acl::remove_acl_for($this->dn);
1281 }
1284 /* Remove acls defined for $src */
1285 static function remove_acl_for($dn)
1286 {
1287 global $config;
1289 $ldap = $config->get_ldap_link();
1290 $ldap->cd($config->current['BASE']);
1291 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1292 $new_entries= array();
1293 while($attrs = $ldap->fetch()){
1294 if (!isset($attrs['gosaAclEntry'])) {
1295 continue;
1296 }
1297 unset($attrs['gosaAclEntry']['count']);
1299 // Remove entry directly
1300 foreach($attrs['gosaAclEntry'] as $id => $entry){
1301 $parts= explode(':',$entry);
1302 $members= explode(',',$parts[2]);
1303 $new_members= array();
1304 foreach($members as $member) {
1305 if (base64_decode($member) != $dn) {
1306 $new_members[]= $member;
1307 } else {
1308 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1309 }
1310 }
1312 /* We can completely remove the entry if there are no members anymore */
1313 if (count($new_members)) {
1314 $parts[2]= implode(",", $new_members);
1315 $new_entries[]= implode(":", $parts);
1316 }
1317 }
1319 // There should be a modification, so write it back
1320 $ldap->cd($attrs['dn']);
1321 $new_attrs= array("gosaAclEntry" => $new_entries);
1322 $ldap->modify($new_attrs);
1323 if (!$ldap->success()){
1324 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1325 }
1326 }
1327 }
1330 function update_acl_membership($src,$dst)
1331 {
1332 $ldap = $this->config->get_ldap_link();
1333 $ldap->cd($this->config->current['BASE']);
1334 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1335 while($attrs = $ldap->fetch()){
1336 $acl = new acl($this->config,$this->parent,$attrs['dn']);
1337 foreach($acl->gosaAclEntry as $id => $entry){
1338 foreach($entry['members'] as $m_id => $member){
1339 if($m_id == "U:".$src){
1340 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1341 $new = "U:".$dst;
1342 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1343 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1344 }
1345 if($m_id == "G:".$src){
1346 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1347 $new = "G:".$dst;
1348 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1349 gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1350 }
1351 }
1352 }
1353 $acl -> save();
1354 }
1355 }
1358 // We are only interessted in our own acls ...
1359 function set_acl_category($category)
1360 {
1361 plugin::set_acl_category("acl");
1362 }
1363 }
1365 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1366 ?>