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 var $list =NULL;
59 var $sectionList = NULL;
61 function acl (&$config, $parent, $dn= NULL)
62 {
63 /* Include config object */
64 plugin::plugin($config, $dn);
66 /* Load ACL's */
67 $this->gosaAclEntry= array();
68 if (isset($this->attrs['gosaAclEntry'])){
69 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
70 $acl= $this->attrs['gosaAclEntry'][$i];
71 $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
72 }
73 }
74 ksort($this->gosaAclEntry);
76 /* Save parent - we've to know more about it than other plugins... */
77 $this->parent= &$parent;
79 /* Container? */
80 if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
81 $this->isContainer= TRUE;
82 }
84 /* Users */
85 $ui= get_userinfo();
86 $tag= $ui->gosaUnitTag;
87 $ldap= $config->get_ldap_link();
88 $ldap->cd($config->current['BASE']);
89 if ($tag == ""){
90 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
91 } else {
92 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
93 }
94 while ($attrs= $ldap->fetch()){
96 // Allow objects without cn to be listed without causing an error.
97 if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
98 $this->users['U:'.$attrs['dn']]= $attrs['uid'][0];
99 }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
100 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0];
101 }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
102 $this->users['U:'.$attrs['dn']]= $attrs['dn'];
103 }else{
104 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
105 }
107 }
108 ksort($this->users);
110 /* Groups */
111 $ldap->cd($config->current['BASE']);
112 # if ($tag == ""){
113 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
114 # } else {
115 # $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
116 # }
117 while ($attrs= $ldap->fetch()){
118 $dsc= "";
119 if (isset($attrs['description'][0])){
120 $dsc= $attrs['description'][0];
121 }
122 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
123 }
124 $this->groups['G:*']= _("All users");
125 ksort($this->groups);
127 /* Roles */
128 $ldap->cd($config->current['BASE']);
129 # if ($tag == ""){
130 $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
131 # } else {
132 # $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
133 # }
134 while ($attrs= $ldap->fetch()){
135 $dsc= "";
136 if (isset($attrs['description'][0])){
137 $dsc= $attrs['description'][0];
138 }
140 $role_id = $attrs['dn'];
142 $this->roles[$role_id]['acls'] =array();
143 for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
144 $acl= $attrs['gosaAclTemplate'][$i];
145 $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
146 }
147 $this->roles[$role_id]['description'] = $dsc;
148 $this->roles[$role_id]['cn'] = $attrs['cn'][0];
149 }
151 /* Objects */
152 $tmp= session::global_get('plist');
153 $plist= $tmp->info;
154 $cats = array();
155 if (isset($this->parent) && $this->parent !== NULL){
156 $oc= array();
157 foreach ($this->parent->by_object as $key => $obj){
158 $oc= array_merge($oc, $obj->objectclasses);
159 if(isset($obj->acl_category)){
160 $tmp= str_replace("/","",$obj->acl_category);
161 $cats[$tmp] = $tmp;
162 }
163 }
164 if (in_array_ics('organizationalUnit', $oc)){
165 $this->isContainer= TRUE;
166 }
167 } else {
168 $oc= $this->attrs['objectClass'];
169 }
171 /* Extract available categories from plugin info list */
172 foreach ($plist as $class => $acls){
174 /* Only feed categories */
175 if (isset($acls['plCategory'])){
177 /* Walk through supplied list and feed only translated categories */
178 foreach($acls['plCategory'] as $idx => $data){
180 /* Non numeric index means -> base object containing more informations */
181 if (preg_match('/^[0-9]+$/', $idx)){
183 if (!isset($this->ocMapping[$data])){
184 $this->ocMapping[$data]= array();
185 $this->ocMapping[$data][]= '0';
186 }
188 if(isset($cats[$data])){
189 $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
190 }
191 $this->ocMapping[$data][]= $class;
192 } else {
193 if (!isset($this->ocMapping[$idx])){
194 $this->ocMapping[$idx]= array();
195 $this->ocMapping[$idx][]= '0';
196 }
197 $this->ocMapping[$idx][]= $class;
198 $this->aclObjects[$idx]= $data['description'];
200 /* Additionally filter the classes we're interested in in "self edit" mode */
201 if (is_array($data['objectClass'])){
202 foreach($data['objectClass'] as $objectClass){
203 if (in_array_ics($objectClass, $oc)){
204 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
205 break;
206 }
207 }
208 } else {
209 if (in_array_ics($data['objectClass'], $oc)){
210 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
211 }
212 }
213 }
215 }
216 }
217 }
218 $this->aclObjects['all']= '* '._("All categories");
219 $this->ocMapping['all']= array('0' => 'all');
221 /* Sort categories */
222 asort($this->aclObjects);
224 /* Fill acl types */
225 if ($this->isContainer){
226 $this->aclTypes= array("reset" => _("Reset ACLs"),
227 "one" => _("One level"),
228 "base" => _("Current object"),
229 "sub" => _("Complete subtree"),
230 "psub" => _("Complete subtree (permanent)"),
231 "role" => _("Use ACL defined in role"));
232 } else {
233 $this->aclTypes= array("base" => _("Current object"),
234 "role" => _("Use ACL defined in role"));
235 }
236 asort($this->aclTypes);
237 $this->targets= array("user" => _("Users"), "group" => _("Groups"));
238 asort($this->targets);
240 /* Finally - we want to get saved... */
241 $this->is_account= TRUE;
243 $this->updateList();
245 // Prepare lists
246 $this->sectionList = new sortableListing();
247 $this->sectionList->setDeleteable(false);
248 $this->sectionList->setEditable(false);
249 $this->sectionList->setWidth("100%");
250 $this->sectionList->setHeight("120px");
251 $this->sectionList->setColspecs(array('200px','*'));
252 $this->sectionList->setHeader(array(_("Section"),_("Description")));
253 $this->sectionList->setDefaultSortColumn(1);
254 $this->sectionList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
255 }
258 function updateList()
259 {
260 if(!$this->list){
261 $this->list = new sortableListing($this->gosaAclEntry,array(),TRUE);
262 $this->list->setDeleteable(true);
263 $this->list->setEditable(true);
264 $this->list->setColspecs(array('*'));
265 $this->list->setWidth("100%");
266 $this->list->setHeight("400px");
267 $this->list->setAcl("rwcdm");
268 $this->list->setHeader(array(_("Member"),_("Permissions"),_("Type")));
269 }
272 // Add ACL entries to the listing
273 $lData = array();
274 foreach($this->gosaAclEntry as $id => $entry){
275 $lData[] = $this->convertForListing($entry);
276 }
277 $this->list->setListData($this->gosaAclEntry, $lData);
278 }
281 function convertForListing($entry)
282 {
283 $member = implode($entry['members'],", ");
284 $acl = implode(array_keys($entry['acl']),", ");
285 $type = implode(array_keys($entry['acl']),", ");
286 return(array('data' => array($member, $acl, $this->aclTypes[$entry['type']])));
287 }
291 function execute()
292 {
293 /* Call parent execute */
294 plugin::execute();
296 $tmp= session::global_get('plist');
297 $plist= $tmp->info;
299 /* Handle posts */
300 if (isset($_POST['new_acl'])){
301 $this->dialogState= 'create';
302 $this->dialog= TRUE;
303 $this->currentIndex= count($this->gosaAclEntry);
304 $this->loadAclEntry(TRUE);
305 }
307 $new_acl= array();
308 $aclDialog= FALSE;
309 $firstedit= FALSE;
311 // Get listing actions. Delete or Edit.
312 $this->list->save_object();
313 $lAction = $this->list->getAction();
314 $this->gosaAclEntry = $this->list->getMaintainedData();
316 /* Act on HTML post and gets here.
317 */
318 if($lAction['action'] == "edit"){
319 $this->currentIndex = $this->list->getKey($lAction['targets'][0]);
320 $this->dialogState= 'create';
321 $firstedit= TRUE;
322 $this->dialog= TRUE;
323 $this->loadAclEntry();
324 }
326 foreach($_POST as $name => $post){
328 /* Actions... */
329 if (preg_match('/^acl_edit_[0-9]*$/', $name)){
330 $this->dialogState= 'create';
331 $firstedit= TRUE;
332 $this->dialog= TRUE;
333 $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
334 $this->loadAclEntry();
335 continue;
336 }
338 if (preg_match('/^cat_edit_.*$/', $name)){
339 $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
340 $this->dialogState= 'edit';
341 foreach ($this->ocMapping[$this->aclObject] as $oc){
342 if (isset($this->aclContents[$oc])){
343 $this->savedAclContents[$oc]= $this->aclContents[$oc];
344 }
345 }
346 continue;
347 }
349 /* Only handle posts, if we allowed to modify ACLs */
350 if(!$this->acl_is_writeable("")){
351 continue;
352 }
354 if (preg_match('/^acl_del_[0-9]*$/', $name)){
355 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
356 continue;
357 }
359 if (preg_match('/^cat_del_.*$/', $name)){
360 $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
361 foreach ($this->ocMapping[$idx] as $key){
362 if(isset($this->aclContents[$idx]))
363 unset($this->aclContents[$idx]);
364 if(isset($this->aclContents["$idx/$key"]))
365 unset($this->aclContents["$idx/$key"]);
366 }
367 continue;
368 }
370 /* ACL saving... */
371 if (preg_match('/^acl_.*_[^xy]$/', $name)){
372 list($dummy, $object, $attribute, $value)= explode('_', $name);
374 /* Skip for detection entry */
375 if ($object == 'dummy') {
376 continue;
377 }
379 /* Ordinary ACLs */
380 if (!isset($new_acl[$object])){
381 $new_acl[$object]= array();
382 }
383 if (isset($new_acl[$object][$attribute])){
384 $new_acl[$object][$attribute].= $value;
385 } else {
386 $new_acl[$object][$attribute]= $value;
387 }
388 }
390 // Remember the selected ACL role.
391 if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
392 $this->aclContents = "";
393 $this->aclContents = base64_decode($_POST['selected_role']);
394 }
395 }
397 if(isset($_POST['acl_dummy_0_0_0'])){
398 $aclDialog= TRUE;
399 }
401 if($this->acl_is_writeable("")){
403 /* Only be interested in new acl's, if we're in the right _POST place */
404 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
406 foreach ($this->ocMapping[$this->aclObject] as $oc){
408 if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
409 unset($this->aclContents[$oc]);
410 }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
411 unset($this->aclContents[$this->aclObject.'/'.$oc]);
412 }else{
413 # trigger_error("Huhm?");
414 }
415 if (isset($new_acl[$oc]) && is_array($new_acl)){
416 $this->aclContents[$oc]= $new_acl[$oc];
417 }
418 if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
419 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
420 }
421 }
422 }
424 /* Save new acl in case of base edit mode */
425 if ($this->aclType == 'base' && !$firstedit){
426 $this->aclContents= $new_acl;
427 }
428 }
430 /* Cancel new acl? */
431 if (isset($_POST['cancel_new_acl'])){
432 $this->dialogState= 'head';
433 $this->dialog= FALSE;
434 if ($this->wasNewEntry){
435 unset ($this->gosaAclEntry[$this->currentIndex]);
436 }
437 }
439 /* Save common values */
440 if($this->acl_is_writeable("")){
441 foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
442 if (isset($_POST[$key])){
443 $this->$key= validate($_POST[$key]);
444 }
445 }
446 }
448 /* Store ACL in main object? */
449 if (isset($_POST['submit_new_acl'])){
450 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
451 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
452 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
453 $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
454 $this->dialogState= 'head';
455 $this->dialog= FALSE;
456 }
458 /* Cancel edit acl? */
459 if (isset($_POST['cancel_edit_acl'])){
460 $this->dialogState= 'create';
461 foreach ($this->ocMapping[$this->aclObject] as $oc){
462 if (isset($this->savedAclContents[$oc])){
463 $this->aclContents[$oc]= $this->savedAclContents[$oc];
464 }
465 }
466 }
468 /* Save edit acl? */
469 if (isset($_POST['submit_edit_acl'])){
470 $this->dialogState= 'create';
471 }
473 /* Add acl? */
474 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
475 $this->dialogState= 'edit';
476 $this->savedAclContents= array();
477 foreach ($this->ocMapping[$this->aclObject] as $oc){
478 if (isset($this->aclContents[$oc])){
479 $this->savedAclContents[$oc]= $this->aclContents[$oc];
480 }
481 }
482 }
484 /* Add to list? */
485 if (isset($_POST['add']) && isset($_POST['source'])){
486 foreach ($_POST['source'] as $key){
487 if ($this->target == 'user'){
488 $this->recipients[$key]= $this->users[$key];
489 }
490 if ($this->target == 'group'){
491 $this->recipients[$key]= $this->groups[$key];
492 }
493 }
494 ksort($this->recipients);
495 }
497 /* Remove from list? */
498 if (isset($_POST['del']) && isset($_POST['recipient'])){
499 foreach ($_POST['recipient'] as $key){
500 unset($this->recipients[$key]);
501 }
502 }
504 /* Create templating instance */
505 $smarty= get_smarty();
506 $smarty->assign("usePrototype", "true");
507 $smarty->assign("acl_readable",$this->acl_is_readable(""));
508 if(!$this->acl_is_readable("")){
509 return ($smarty->fetch (get_template_path('acl.tpl')));
510 }
512 if ($this->dialogState == 'head'){
513 $this->updateList();
514 $smarty->assign("aclList", $this->list->render());
515 }
517 if ($this->dialogState == 'create'){
519 // Create a map of all used sections, this allows us to simply hide the remove button
520 // if no acl is configured for the given section
521 // e.g. ';all;department/country;users/user;
522 $usedList = ";".implode(array_keys($this->aclContents),';').";";
524 /* Add settings for all categories to the (permanent) list */
525 $data = $lData = array();
526 foreach ($this->aclObjects as $section => $dsc){
527 $summary= "";
528 foreach($this->ocMapping[$section] as $oc){
529 if (isset($this->aclContents[$oc]) &&
530 count($this->aclContents[$oc]) &&
531 isset($this->aclContents[$oc][0]) &&
532 $this->aclContents[$oc][0] != ""){
534 $summary.= "$oc, ";
535 continue;
536 }
537 if (isset($this->aclContents["$section/$oc"]) &&
538 count($this->aclContents["$section/$oc"])){
539 $summary.= "$oc, ";
540 continue;
541 }
542 if (isset($this->aclContents[$oc]) &&
543 !isset($this->aclContents[$oc][0]) &&
544 count($this->aclContents[$oc])){
545 $summary.= "$oc, ";
546 }
547 }
549 /* Set summary... */
550 if ($summary == ""){
551 $summary= '<i>'._("No ACL settings for this category!").'</i>';
552 } else {
553 $summary= trim($summary,", ");
554 $summary= " ".sprintf(_("Contains ACLs for these objects: %s"), $summary);
555 }
557 $actions ="";
558 if($this->acl_is_readable("")){
559 $actions.= image('images/lists/edit.png','cat_edit_'.$section,
560 msgPool::editButton(_("category ACL")));
561 }
562 if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
563 $actions.= image('images/lists/trash.png','cat_del_'.$section,
564 msgPool::delButton(_("category ACL")));
565 }
566 $data[] = $section;
567 $lData[] = array('data'=>array($dsc, $summary, $actions));
568 }
569 $this->sectionList->setListData($data,$lData);
570 $this->sectionList->update();
571 $smarty->assign("aclList", $this->sectionList->render());
573 $smarty->assign("aclType", $this->aclType);
574 $smarty->assign("aclFilter", $this->aclFilter);
575 $smarty->assign("aclTypes", $this->aclTypes);
576 $smarty->assign("target", $this->target);
577 $smarty->assign("targets", $this->targets);
579 /* Assign possible target types */
580 $smarty->assign("targets", $this->targets);
581 foreach ($this->attributes as $attr){
582 $smarty->assign($attr, $this->$attr);
583 }
586 /* Generate list */
587 $tmp= array();
588 if ($this->target == "group" && !isset($this->recipients["G:*"])){
589 $tmp["G:*"]= _("All users");
590 }
591 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
592 if ($this->target == $field){
593 foreach ($this->$arr as $key => $value){
594 if (!isset($this->recipients[$key])){
595 $tmp[$key]= $value;
596 }
597 }
598 }
599 }
600 $smarty->assign('sources', $tmp);
601 $smarty->assign('recipients', $this->recipients);
603 /* Acl selector if scope is base */
604 if ($this->aclType == 'base'){
605 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
606 }
608 /* Role selector if scope is base */
609 if ($this->aclType == 'role'){
610 $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
611 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
612 }
613 }
615 if ($this->dialogState == 'edit'){
616 $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
618 /* Collect objects for selected category */
619 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
620 if ($idx == 0){
621 continue;
622 }
623 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
624 }
625 if ($this->aclObject == 'all'){
626 $aclObjects['all']= _("All objects in current subtree");
627 }
629 /* Role selector if scope is base */
630 if ($this->aclType == 'role'){
631 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
632 } else {
633 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
634 }
635 }
637 /* Show main page */
638 $smarty->assign("dialogState", $this->dialogState);
640 /* Assign acls */
641 $smarty->assign("acl_createable",$this->acl_is_createable());
642 $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
643 $smarty->assign("acl_readable" ,$this->acl_is_readable(""));
644 $smarty->assign("acl_removeable",$this->acl_is_removeable());
646 return ($smarty->fetch (get_template_path('acl.tpl')));
647 }
650 function sort_by_priority($list)
651 {
652 $tmp= session::global_get('plist');
653 $plist= $tmp->info;
654 asort($plist);
655 $newSort = array();
657 foreach($list as $name => $translation){
658 $na = preg_replace("/^.*\//","",$name);
659 $prio = 0;
660 if(isset($plist[$na]['plPriority'])){
661 $prio= $plist[$na]['plPriority'] ;
662 }
664 $newSort[$name] = $prio;
665 }
667 asort($newSort);
669 $ret = array();
670 foreach($newSort as $name => $prio){
671 $ret[$name] = $list[$name];
672 }
673 return($ret);
674 }
677 function buildRoleSelector($list)
678 {
679 $D_List =new divSelectBox("Acl_Roles");
681 $selected = $this->aclContents;
682 if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
683 $selected = key($list);
684 }
686 $str ="";
687 foreach($list as $dn => $values){
689 if($dn == $selected){
690 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
691 }else{
692 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
693 }
695 $field1 = array("string" => $option) ;
696 $field2 = array("string" => $values['cn'], "attach" => "style='width:200px;'") ;
697 $field3 = array("string" => $values['description'],"attach" => "style='border-right:0px;'") ;
699 $D_List->AddEntry(array($field1,$field2,$field3));
700 }
701 return($D_List->DrawList());
702 }
705 function buildAclSelector($list)
706 {
707 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
708 $cols= 3;
709 $tmp= session::global_get('plist');
710 $plist= $tmp->info;
711 asort($plist);
713 /* Add select all/none buttons */
714 $style = "style='width:100px;'";
716 if($this->acl_is_writeable("")){
717 $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
718 $display .= "<button type='button' ".$style." name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
719 $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
720 $display .= "<button type='button' ".$style." name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
721 $display .= "<button type='button' ".$style." name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
723 $display .= "<button type='button' ".$style." name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
724 $display .= "<button type='button' ".$style." name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
726 $display .= "<br>";
728 $style = "style='width:50px;'";
729 $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
730 $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
731 $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
732 $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
733 $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
734 $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
735 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
736 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
737 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
738 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
740 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
741 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
742 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
743 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
744 }
746 /* Build general objects */
747 $list =$this->sort_by_priority($list);
748 foreach ($list as $key => $name){
750 /* Create sub acl if it does not exist */
751 if (!isset($this->aclContents[$key])){
752 $this->aclContents[$key]= array();
753 }
754 if(!isset($this->aclContents[$key][0])){
755 $this->aclContents[$key][0]= '';
756 }
758 $currentAcl= $this->aclContents[$key];
760 /* Get the overall plugin acls
761 */
762 $overall_acl ="";
763 if(isset($currentAcl[0])){
764 $overall_acl = $currentAcl[0];
765 }
767 // Detect configured plugins
768 $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
770 /* Object header */
771 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
773 if($expand){
774 $back_color = "#C8C8FF";
775 }else{
776 $back_color = "#C8C8C8";
777 }
779 if(isset($_SERVER['HTTP_USER_AGENT']) &&
780 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
781 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
782 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
783 "\n <tr>".
784 "\n <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
785 "\n <td align='right' style='background-color:{$back_color};height:1.8em;'>".
786 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
787 "\n </tr>";
788 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
789 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
790 "\n <tr>".
791 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
792 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
793 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
794 "\n </tr>";
795 } else {
796 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
797 "\n <tr>".
798 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
799 "\n </tr>";
800 }
802 /* Generate options */
803 $spc= " ";
804 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
805 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
806 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
807 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
808 $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
809 }
811 /* Global options */
812 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $overall_acl)).$spc;
813 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
815 $display.= "\n <tr>".
816 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
817 "\n <td style='background-color:#D4D4D4'> "._("Complete object").": $more_options</td>".
818 "\n </tr>";
820 /* Walk through the list of attributes */
821 $cnt= 1;
822 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
823 if(session::global_get('js')) {
824 if(isset($_SERVER['HTTP_USER_AGENT']) &&
825 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
826 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
827 "\n <td colspan=".$cols.">".
828 "\n <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
829 "\n <table style='width:100%;' summary='{$name}'>";
830 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
831 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
832 "\n <td colspan=".$cols.">".
833 "\n <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
834 "\n <table style='width:100%;' summary='{$name}'>";
835 }else{
836 }
837 }
840 foreach($splist as $attr => $dsc){
842 /* Skip pl* attributes, they are internal... */
843 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
844 continue;
845 }
847 /* Open table row */
848 if ($cnt == 1){
849 $display.= "\n <tr>";
850 }
852 /* Close table row */
853 if ($cnt == $cols){
854 $cnt= 1;
855 $rb= "";
856 $end= "\n </tr>";
857 } else {
858 $cnt++;
859 $rb= "border-right:1px solid #A0A0A0;";
860 $end= "";
861 }
863 /* Collect list of attributes */
864 $state= "";
865 if (isset($currentAcl[$attr])){
866 $state= $currentAcl[$attr];
867 }
868 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
869 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
870 }
872 /* Fill missing td's if needed */
873 if (--$cnt != $cols && $cnt != 0){
874 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
875 }
877 if(session::global_get('js')) {
878 if(isset($_SERVER['HTTP_USER_AGENT']) &&
879 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
880 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) ||
881 (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
882 $display.= "\n </table>".
883 "\n </div>".
884 "\n </td>".
885 "\n </tr>";
886 }
887 }
889 $display.= "\n</table><br />\n";
890 }
892 return ($display);
893 }
896 function mkchkbx($name, $text, $state= FALSE)
897 {
898 $state= $state?"checked":"";
899 if($this->acl_is_writeable("")){
900 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
901 return "\n <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
902 "\n <label for='acl_$tname'>$text</label>";
903 }else{
904 return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
905 }
906 }
909 function mkrwbx($name, $state= "")
910 {
911 $rstate= preg_match('/r/', $state)?'checked':'';
912 $wstate= preg_match('/w/', $state)?'checked':'';
913 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
915 if($this->acl_is_writeable("")){
916 return ("\n <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
917 "\n <label for='acl_".$tname."_r'>"._("read")."</label>".
918 "\n <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
919 "\n <label for='acl_".$tname."_w'>"._("write")."</label>");
920 }else{
921 return ("\n <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
922 "\n <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
923 }
924 }
927 static function explodeACL($acl)
928 {
930 $list= explode(':', $acl);
931 if(count($list) == 5){
932 list($index, $type,$member,$permission,$filter)= $list;
933 $filter = base64_decode($filter);
934 }else{
935 $filter = "";
936 list($index, $type,$member,$permission)= $list;
937 }
939 $a= array( $index => array("type" => $type,
940 "filter"=> $filter,
941 "members" => acl::extractMembers($acl,$type == "role")));
943 /* Handle different types */
944 switch ($type){
946 case 'psub':
947 case 'sub':
948 case 'one':
949 case 'base':
950 $a[$index]['acl']= acl::extractACL($acl);
951 break;
953 case 'role':
954 $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
955 break;
957 case 'reset':
958 break;
960 default:
961 msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
962 $a= array();
963 }
964 return ($a);
965 }
968 static function extractMembers($acl,$role = FALSE)
969 {
970 global $config;
971 $a= array();
973 /* Rip acl off the string, seperate by ',' and place it in an array */
974 if($role){
975 $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
976 }else{
977 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
978 }
979 if ($ms == $acl){
980 return $a;
981 }
982 $ma= explode(',', $ms);
984 /* Decode dn's, fill with informations from LDAP */
985 $ldap= $config->get_ldap_link();
986 foreach ($ma as $memberdn){
987 // Check for wildcard here
988 $dn= base64_decode($memberdn);
989 if ($dn != "*") {
990 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
992 /* Found entry... */
993 if ($ldap->count()){
994 $attrs= $ldap->fetch();
995 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
996 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
997 } else {
998 $a['G:'.$dn]= $attrs['cn'][0];
999 if (isset($attrs['description'][0])){
1000 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
1001 }
1002 }
1004 /* ... or not */
1005 } else {
1006 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1007 }
1009 } else {
1010 $a['G:*']= sprintf(_("All users"));
1011 }
1012 }
1014 return ($a);
1015 }
1018 static function extractACL($acl)
1019 {
1020 /* Rip acl off the string, seperate by ',' and place it in an array */
1021 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1022 $aa= explode(',', $as);
1023 $a= array();
1025 /* Dis-assemble single ACLs */
1026 foreach($aa as $sacl){
1028 /* Dis-assemble field ACLs */
1029 $ao= explode('#', $sacl);
1030 $gobject= "";
1031 foreach($ao as $idx => $ssacl){
1033 /* First is department with global acl */
1034 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1035 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1036 if ($idx == 0){
1037 /* Create hash for this object */
1038 $gobject= $object;
1039 $a[$gobject]= array();
1041 /* Append ACL if set */
1042 if ($gacl != ""){
1043 $a[$gobject]= array($gacl);
1044 }
1045 } else {
1047 /* All other entries get appended... */
1048 list($field, $facl)= explode(';', $ssacl);
1049 $a[$gobject][$field]= $facl;
1050 }
1052 }
1053 }
1055 return ($a);
1056 }
1059 function assembleAclSummary($entry)
1060 {
1061 $summary= "";
1063 /* Summarize ACL */
1064 if (isset($entry['acl'])){
1065 $acl= "";
1067 if($entry['type'] == "role"){
1069 if(isset($this->roles[$entry['acl']])){
1070 $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1071 }else{
1072 $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1073 }
1074 }else{
1075 foreach ($entry['acl'] as $name => $object){
1076 if (count($object)){
1077 $acl.= "$name, ";
1078 }
1079 }
1080 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1081 }
1082 }
1085 /* Summarize members */
1086 if(!($this instanceOf aclrole)){
1087 if ($summary != ""){
1088 $summary.= ", ";
1089 }
1090 if (count($entry['members'])){
1091 $summary.= _("Members").": ";
1092 foreach ($entry['members'] as $cn){
1093 $cn= preg_replace('/ \[.*$/', '', $cn);
1094 $summary.= $cn.", ";
1095 }
1096 } else {
1097 $summary.= "<font color='red'><i>"._("inactive")." - "._("No members")."</i></font>";
1098 }
1099 }
1100 return (preg_replace('/, $/', '', $summary));
1101 }
1104 function loadAclEntry($new= FALSE)
1105 {
1106 /* New entry gets presets... */
1107 if ($new){
1108 $this->aclType= 'base';
1109 $this->aclFilter= "";
1110 $this->recipients= array();
1111 $this->aclContents= array();
1112 } else {
1113 $acl= $this->gosaAclEntry[$this->currentIndex];
1114 $this->aclType= $acl['type'];
1115 $this->recipients= $acl['members'];
1116 $this->aclContents= $acl['acl'];
1117 $this->aclFilter= $acl['filter'];
1118 }
1120 $this->wasNewEntry= $new;
1121 }
1124 function aclPostHandler()
1125 {
1126 if (isset($_POST['save_acl'])){
1127 $this->save();
1128 return TRUE;
1129 }
1131 return FALSE;
1132 }
1135 function PrepareForCopyPaste($source)
1136 {
1137 plugin::PrepareForCopyPaste($source);
1139 $dn = $source['dn'];
1140 $acl_c = new acl($this->config, $this->parent,$dn);
1141 $this->gosaAclEntry = $acl_c->gosaAclEntry;
1142 }
1145 function save()
1146 {
1147 /* Assemble ACL's */
1148 $tmp_acl= array();
1150 foreach ($this->gosaAclEntry as $prio => $entry){
1151 $final= "";
1152 $members= "";
1153 if (isset($entry['members'])){
1154 foreach ($entry['members'] as $key => $dummy){
1155 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1156 }
1157 }
1159 if($entry['type'] != "role"){
1160 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1161 }else{
1162 $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1163 }
1165 /* ACL's if needed */
1166 if ($entry['type'] != "reset" && $entry['type'] != "role"){
1167 $acl= ":";
1168 if (isset($entry['acl'])){
1169 foreach ($entry['acl'] as $object => $contents){
1171 /* Only save, if we've some contents in there... */
1172 if (count($contents)){
1173 $acl.= $object.";";
1175 foreach($contents as $attr => $permission){
1177 /* First entry? Its the one for global settings... */
1178 if ($attr == '0'){
1179 $acl.= $permission;
1180 } else {
1181 $acl.= '#'.$attr.';'.$permission;
1182 }
1184 }
1185 $acl.= ',';
1186 }
1188 }
1189 }
1190 $final.= preg_replace('/,$/', '', $acl);
1191 }
1193 /* Append additional filter options
1194 */
1195 if(!empty($entry['filter'])){
1196 $final .= ":".base64_encode($entry['filter']);
1197 }
1199 $tmp_acl[]= $final;
1200 }
1202 /* Call main method */
1203 plugin::save();
1205 /* Finally (re-)assign it... */
1206 $this->attrs['gosaAclEntry']= $tmp_acl;
1208 /* Remove acl from this entry if it is empty... */
1209 if (!count($tmp_acl)){
1210 /* Remove attribute */
1211 if ($this->initially_was_account){
1212 $this->attrs['gosaAclEntry']= array();
1213 } else {
1214 if (isset($this->attrs['gosaAclEntry'])){
1215 unset($this->attrs['gosaAclEntry']);
1216 }
1217 }
1219 /* Remove object class */
1220 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1221 }
1223 /* Do LDAP modifications */
1224 $ldap= $this->config->get_ldap_link();
1225 $ldap->cd($this->dn);
1226 $this->cleanup();
1227 $ldap->modify ($this->attrs);
1229 if(count($this->attrs)){
1230 new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1231 }
1233 if (!$ldap->success()){
1234 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1235 }
1237 /* Refresh users ACLs */
1238 $ui= get_userinfo();
1239 $ui->loadACL();
1240 session::global_set('ui',$ui);
1241 }
1244 function remove_from_parent()
1245 {
1246 plugin::remove_from_parent();
1248 /* include global link_info */
1249 $ldap= $this->config->get_ldap_link();
1251 $ldap->cd($this->dn);
1252 $this->cleanup();
1253 $ldap->modify ($this->attrs);
1255 new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1257 /* Optionally execute a command after we're done */
1258 $this->handle_post_events("remove",array("uid" => $this->uid));
1259 }
1262 /* Return plugin informations for acl handling */
1263 static function plInfo()
1264 {
1265 return (array(
1266 "plShortName" => _("ACL"),
1267 "plDescription" => _("ACL")." ("._("Access control list").")",
1268 "plSelfModify" => FALSE,
1269 "plDepends" => array(),
1270 "plPriority" => 0,
1271 "plSection" => array("administration"),
1272 "plCategory" => array("acl" => array("description" => _("ACL")." & "._("ACL roles"),
1273 "objectClass" => array("gosaAcl","gosaRole"))),
1274 "plProvidedAcls"=> array(
1275 "gosaAclEntry" => _("Acl entries")
1276 // "description" => _("Role description")
1277 )
1279 ));
1280 }
1283 /* Remove acls defined for $src */
1284 function remove_acl()
1285 {
1286 acl::remove_acl_for($this->dn);
1287 }
1290 /* Remove acls defined for $src */
1291 static function remove_acl_for($dn)
1292 {
1293 global $config;
1295 $ldap = $config->get_ldap_link();
1296 $ldap->cd($config->current['BASE']);
1297 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1298 $new_entries= array();
1299 while($attrs = $ldap->fetch()){
1300 if (!isset($attrs['gosaAclEntry'])) {
1301 continue;
1302 }
1303 unset($attrs['gosaAclEntry']['count']);
1305 // Remove entry directly
1306 foreach($attrs['gosaAclEntry'] as $id => $entry){
1307 $parts= explode(':',$entry);
1308 $members= explode(',',$parts[2]);
1309 $new_members= array();
1310 foreach($members as $member) {
1311 if (base64_decode($member) != $dn) {
1312 $new_members[]= $member;
1313 } else {
1314 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1315 }
1316 }
1318 /* We can completely remove the entry if there are no members anymore */
1319 if (count($new_members)) {
1320 $parts[2]= implode(",", $new_members);
1321 $new_entries[]= implode(":", $parts);
1322 }
1323 }
1325 // There should be a modification, so write it back
1326 $ldap->cd($attrs['dn']);
1327 $new_attrs= array("gosaAclEntry" => $new_entries);
1328 $ldap->modify($new_attrs);
1329 if (!$ldap->success()){
1330 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1331 }
1332 }
1333 }
1336 function update_acl_membership($src,$dst)
1337 {
1338 $ldap = $this->config->get_ldap_link();
1339 $ldap->cd($this->config->current['BASE']);
1340 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1341 while($attrs = $ldap->fetch()){
1342 $acl = new acl($this->config,$this->parent,$attrs['dn']);
1343 foreach($acl->gosaAclEntry as $id => $entry){
1344 foreach($entry['members'] as $m_id => $member){
1345 if($m_id == "U:".$src){
1346 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1347 $new = "U:".$dst;
1348 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1349 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1350 }
1351 if($m_id == "G:".$src){
1352 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1353 $new = "G:".$dst;
1354 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1355 gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1356 }
1357 }
1358 }
1359 $acl -> save();
1360 }
1361 }
1364 // We are only interessted in our own acls ...
1365 function set_acl_category($category)
1366 {
1367 plugin::set_acl_category("acl");
1368 }
1369 }
1371 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1372 ?>