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;
60 var $roleList = NULL;
62 function acl (&$config, $parent, $dn= NULL)
63 {
64 /* Include config object */
65 plugin::plugin($config, $dn);
67 /* Load ACL's */
68 $this->gosaAclEntry= array();
69 if (isset($this->attrs['gosaAclEntry'])){
70 for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
71 $acl= $this->attrs['gosaAclEntry'][$i];
72 $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
73 }
74 }
75 ksort($this->gosaAclEntry);
77 /* Save parent - we've to know more about it than other plugins... */
78 $this->parent= &$parent;
80 /* Container? */
81 if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
82 $this->isContainer= TRUE;
83 }
85 /* Users */
86 $ui= get_userinfo();
87 $tag= $ui->gosaUnitTag;
88 $ldap= $config->get_ldap_link();
89 $ldap->cd($config->current['BASE']);
90 if ($tag == ""){
91 $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
92 } else {
93 $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
94 }
95 while ($attrs= $ldap->fetch()){
97 // Allow objects without cn to be listed without causing an error.
98 if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
99 $this->users['U:'.$attrs['dn']]= $attrs['uid'][0];
100 }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
101 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0];
102 }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
103 $this->users['U:'.$attrs['dn']]= $attrs['dn'];
104 }else{
105 $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
106 }
108 }
109 ksort($this->users);
111 /* Groups */
112 $ldap->cd($config->current['BASE']);
113 # if ($tag == ""){
114 $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
115 # } else {
116 # $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
117 # }
118 while ($attrs= $ldap->fetch()){
119 $dsc= "";
120 if (isset($attrs['description'][0])){
121 $dsc= $attrs['description'][0];
122 }
123 $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
124 }
125 $this->groups['G:*']= _("All users");
126 ksort($this->groups);
128 /* Roles */
129 $ldap->cd($config->current['BASE']);
130 # if ($tag == ""){
131 $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
132 # } else {
133 # $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
134 # }
135 while ($attrs= $ldap->fetch()){
136 $dsc= "";
137 if (isset($attrs['description'][0])){
138 $dsc= $attrs['description'][0];
139 }
141 $role_id = $attrs['dn'];
143 $this->roles[$role_id]['acls'] =array();
144 for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
145 $acl= $attrs['gosaAclTemplate'][$i];
146 $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
147 }
148 $this->roles[$role_id]['description'] = $dsc;
149 $this->roles[$role_id]['cn'] = $attrs['cn'][0];
150 }
152 /* Objects */
153 $tmp= session::global_get('plist');
154 $plist= $tmp->info;
155 $cats = array();
156 if (isset($this->parent) && $this->parent !== NULL){
157 $oc= array();
158 foreach ($this->parent->by_object as $key => $obj){
159 $oc= array_merge($oc, $obj->objectclasses);
160 if(isset($obj->acl_category)){
161 $tmp= str_replace("/","",$obj->acl_category);
162 $cats[$tmp] = $tmp;
163 }
164 }
165 if (in_array_ics('organizationalUnit', $oc)){
166 $this->isContainer= TRUE;
167 }
168 } else {
169 $oc= $this->attrs['objectClass'];
170 }
172 /* Extract available categories from plugin info list */
173 foreach ($plist as $class => $acls){
175 /* Only feed categories */
176 if (isset($acls['plCategory'])){
178 /* Walk through supplied list and feed only translated categories */
179 foreach($acls['plCategory'] as $idx => $data){
181 /* Non numeric index means -> base object containing more informations */
182 if (preg_match('/^[0-9]+$/', $idx)){
184 if (!isset($this->ocMapping[$data])){
185 $this->ocMapping[$data]= array();
186 $this->ocMapping[$data][]= '0';
187 }
189 if(isset($cats[$data])){
190 $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
191 }
192 $this->ocMapping[$data][]= $class;
193 } else {
194 if (!isset($this->ocMapping[$idx])){
195 $this->ocMapping[$idx]= array();
196 $this->ocMapping[$idx][]= '0';
197 }
198 $this->ocMapping[$idx][]= $class;
199 $this->aclObjects[$idx]= $data['description'];
201 /* Additionally filter the classes we're interested in in "self edit" mode */
202 if(!isset($data['objectClass'])) continue;
203 if (is_array($data['objectClass'])){
204 foreach($data['objectClass'] as $objectClass){
205 if (in_array_ics($objectClass, $oc)){
206 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
207 break;
208 }
209 }
210 } else {
211 if (in_array_ics($data['objectClass'], $oc)){
212 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
213 }
214 }
215 }
217 }
218 }
219 }
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.
256 $this->roleList = new sortableListing();
257 $this->roleList->setDeleteable(false);
258 $this->roleList->setEditable(false);
259 $this->roleList->setWidth("100%");
260 $this->roleList->setHeight("120px");
261 $this->roleList->setColspecs(array('20px','*','*'));
262 $this->roleList->setHeader(array(_("Used"),_("Name"),_("Description")));
263 $this->roleList->setDefaultSortColumn(1);
264 $this->roleList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
265 }
268 function updateList()
269 {
270 if(!$this->list){
271 $this->list = new sortableListing($this->gosaAclEntry,array(),TRUE);
272 $this->list->setDeleteable(true);
273 $this->list->setEditable(true);
274 $this->list->setColspecs(array('*'));
275 $this->list->setWidth("100%");
276 $this->list->setHeight("400px");
277 $this->list->setAcl("rwcdm");
278 $this->list->setHeader(array(_("Member"),_("Permissions"),_("Type")));
279 }
282 // Add ACL entries to the listing
283 $lData = array();
284 foreach($this->gosaAclEntry as $id => $entry){
285 $lData[] = $this->convertForListing($entry);
286 }
287 $this->list->setListData($this->gosaAclEntry, $lData);
288 }
291 function convertForListing($entry)
292 {
293 $member = implode($entry['members'],", ");
294 if(isset($entry['acl']) && is_array($entry['acl'])){
295 $acl = implode(array_keys($entry['acl']),", ");
296 }else{
297 $acl="";
298 }
299 return(array('data' => array($member, $acl, $this->aclTypes[$entry['type']])));
300 }
304 function execute()
305 {
306 /* Call parent execute */
307 plugin::execute();
309 $tmp= session::global_get('plist');
310 $plist= $tmp->info;
312 /* Handle posts */
313 if (isset($_POST['new_acl'])){
314 $this->dialogState= 'create';
315 $this->dialog= TRUE;
316 $this->currentIndex= count($this->gosaAclEntry);
317 $this->loadAclEntry(TRUE);
318 }
320 $new_acl= array();
321 $aclDialog= FALSE;
322 $firstedit= FALSE;
324 // Get listing actions. Delete or Edit.
325 $this->list->save_object();
326 $lAction = $this->list->getAction();
327 $this->gosaAclEntry = array_values($this->list->getMaintainedData());
329 /* Act on HTML post and gets here.
330 */
331 if($lAction['action'] == "edit"){
332 $this->currentIndex = $this->list->getKey($lAction['targets'][0]);
333 $this->dialogState= 'create';
334 $firstedit= TRUE;
335 $this->dialog= TRUE;
336 $this->loadAclEntry();
337 }
339 foreach($_POST as $name => $post){
341 /* Actions... */
342 if (preg_match('/^acl_edit_[0-9]*$/', $name)){
343 $this->dialogState= 'create';
344 $firstedit= TRUE;
345 $this->dialog= TRUE;
346 $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
347 $this->loadAclEntry();
348 continue;
349 }
351 if (preg_match('/^cat_edit_.*$/', $name)){
352 $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
353 $this->dialogState= 'edit';
354 foreach ($this->ocMapping[$this->aclObject] as $oc){
355 if (isset($this->aclContents[$oc])){
356 $this->savedAclContents[$oc]= $this->aclContents[$oc];
357 }
358 }
359 continue;
360 }
362 /* Only handle posts, if we allowed to modify ACLs */
363 if(!$this->acl_is_writeable("")){
364 continue;
365 }
367 if (preg_match('/^acl_del_[0-9]*$/', $name)){
368 unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
369 continue;
370 }
372 if (preg_match('/^cat_del_.*$/', $name)){
373 $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
374 foreach ($this->ocMapping[$idx] as $key){
375 if(isset($this->aclContents[$idx]))
376 unset($this->aclContents[$idx]);
377 if(isset($this->aclContents["$idx/$key"]))
378 unset($this->aclContents["$idx/$key"]);
379 }
380 continue;
381 }
383 /* ACL saving... */
384 if (preg_match('/^acl_.*_[^xy]$/', $name)){
385 list($dummy, $object, $attribute, $value)= explode('_', $name);
387 /* Skip for detection entry */
388 if ($object == 'dummy') {
389 continue;
390 }
392 /* Ordinary ACLs */
393 if (!isset($new_acl[$object])){
394 $new_acl[$object]= array();
395 }
396 if (isset($new_acl[$object][$attribute])){
397 $new_acl[$object][$attribute].= $value;
398 } else {
399 $new_acl[$object][$attribute]= $value;
400 }
401 }
403 // Remember the selected ACL role.
404 if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
405 $this->aclContents = "";
406 $this->aclContents = base64_decode($_POST['selected_role']);
407 }else{
408 if(is_string($this->aclContents))
409 $this->aclContents = array();
410 }
411 }
413 if(isset($_POST['acl_dummy_0_0_0'])){
414 $aclDialog= TRUE;
415 }
417 if($this->acl_is_writeable("")){
419 /* Only be interested in new acl's, if we're in the right _POST place */
420 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
422 foreach ($this->ocMapping[$this->aclObject] as $oc){
424 if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
425 unset($this->aclContents[$oc]);
426 }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
427 unset($this->aclContents[$this->aclObject.'/'.$oc]);
428 }else{
429 # trigger_error("Huhm?");
430 }
431 if (isset($new_acl[$oc]) && is_array($new_acl)){
432 $this->aclContents[$oc]= $new_acl[$oc];
433 }
434 if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
435 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
436 }
437 }
438 }
440 /* Save new acl in case of base edit mode */
441 if ($this->aclType == 'base' && !$firstedit){
442 $this->aclContents= $new_acl;
443 }
444 }
446 /* Cancel new acl? */
447 if (isset($_POST['cancel_new_acl'])){
448 $this->dialogState= 'head';
449 $this->dialog= FALSE;
450 if ($this->wasNewEntry){
451 unset ($this->gosaAclEntry[$this->currentIndex]);
452 }
453 }
455 /* Save common values */
456 if($this->acl_is_writeable("")){
457 foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
458 if (isset($_POST[$key])){
459 $this->$key= validate($_POST[$key]);
460 }
461 }
462 }
464 /* Store ACL in main object? */
465 if (isset($_POST['submit_new_acl'])){
466 $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
467 $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
468 $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
469 $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
470 $this->dialogState= 'head';
471 $this->dialog= FALSE;
472 }
474 /* Cancel edit acl? */
475 if (isset($_POST['cancel_edit_acl'])){
476 $this->dialogState= 'create';
477 foreach ($this->ocMapping[$this->aclObject] as $oc){
478 if (isset($this->savedAclContents[$oc])){
479 $this->aclContents[$oc]= $this->savedAclContents[$oc];
480 }
481 }
482 }
484 /* Save edit acl? */
485 if (isset($_POST['submit_edit_acl'])){
486 $this->dialogState= 'create';
487 }
489 /* Add acl? */
490 if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
491 $this->dialogState= 'edit';
492 $this->savedAclContents= array();
493 foreach ($this->ocMapping[$this->aclObject] as $oc){
494 if (isset($this->aclContents[$oc])){
495 $this->savedAclContents[$oc]= $this->aclContents[$oc];
496 }
497 }
498 }
500 /* Add to list? */
501 if (isset($_POST['add']) && isset($_POST['source'])){
502 foreach ($_POST['source'] as $key){
503 if ($this->target == 'user'){
504 $this->recipients[$key]= $this->users[$key];
505 }
506 if ($this->target == 'group'){
507 $this->recipients[$key]= $this->groups[$key];
508 }
509 }
510 ksort($this->recipients);
511 }
513 /* Remove from list? */
514 if (isset($_POST['del']) && isset($_POST['recipient'])){
515 foreach ($_POST['recipient'] as $key){
516 unset($this->recipients[$key]);
517 }
518 }
520 /* Create templating instance */
521 $smarty= get_smarty();
523 $smarty->assign("acl_readable",$this->acl_is_readable(""));
524 if(!$this->acl_is_readable("")){
525 return ($smarty->fetch (get_template_path('acl.tpl')));
526 }
528 if ($this->dialogState == 'head'){
529 $this->updateList();
530 $smarty->assign("aclList", $this->list->render());
531 }
533 if ($this->dialogState == 'create'){
536 if($this->aclType != 'role'){
538 // Create a map of all used sections, this allows us to simply hide the remove button
539 // if no acl is configured for the given section
540 // e.g. ';all;department/country;users/user;
541 $usedList = ";".implode(array_keys($this->aclContents),';').";";
543 /* Add settings for all categories to the (permanent) list */
544 $data = $lData = array();
545 foreach ($this->aclObjects as $section => $dsc){
546 $summary= "";
547 foreach($this->ocMapping[$section] as $oc){
548 if (isset($this->aclContents[$oc]) &&
549 count($this->aclContents[$oc]) &&
550 isset($this->aclContents[$oc][0]) &&
551 $this->aclContents[$oc][0] != ""){
553 $summary.= "$oc, ";
554 continue;
555 }
556 if (isset($this->aclContents["$section/$oc"]) &&
557 count($this->aclContents["$section/$oc"])){
558 $summary.= "$oc, ";
559 continue;
560 }
561 if (isset($this->aclContents[$oc]) &&
562 !isset($this->aclContents[$oc][0]) &&
563 count($this->aclContents[$oc])){
564 $summary.= "$oc, ";
565 }
566 }
568 /* Set summary... */
569 if ($summary == ""){
570 $summary= '<i>'._("No ACL settings for this category!").'</i>';
571 } else {
572 $summary= trim($summary,", ");
573 $summary= " ".sprintf(_("ACLs for: %s"), $summary);
574 }
576 $actions ="";
577 if($this->acl_is_readable("")){
578 $actions.= image('images/lists/edit.png','cat_edit_'.$section,
579 msgPool::editButton(_("category ACL")));
580 }
581 if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
582 $actions.= image('images/lists/trash.png','cat_del_'.$section,
583 msgPool::delButton(_("category ACL")));
584 }
585 $data[] = $section;
586 $lData[] = array('data'=>array($dsc, $summary, $actions));
587 }
588 $this->sectionList->setListData($data,$lData);
589 $this->sectionList->update();
590 $smarty->assign("aclList", $this->sectionList->render());
591 }
593 $smarty->assign("aclType", $this->aclType);
594 $smarty->assign("aclFilter", $this->aclFilter);
595 $smarty->assign("aclTypes", $this->aclTypes);
596 $smarty->assign("target", $this->target);
597 $smarty->assign("targets", $this->targets);
599 /* Assign possible target types */
600 $smarty->assign("targets", $this->targets);
601 foreach ($this->attributes as $attr){
602 $smarty->assign($attr, $this->$attr);
603 }
606 /* Generate list */
607 $tmp= array();
608 if ($this->target == "group" && !isset($this->recipients["G:*"])){
609 $tmp["G:*"]= _("All users");
610 }
611 foreach (array("user" => "users", "group" => "groups") as $field => $arr){
612 if ($this->target == $field){
613 foreach ($this->$arr as $key => $value){
614 if (!isset($this->recipients[$key])){
615 $tmp[$key]= $value;
616 }
617 }
618 }
619 }
620 $smarty->assign('sources', $tmp);
621 $smarty->assign('recipients', $this->recipients);
623 /* Acl selector if scope is base */
624 if ($this->aclType == 'base'){
625 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
626 }
628 /* Role selector if scope is base */
629 if ($this->aclType == 'role'){
630 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
631 }
632 }
634 if ($this->dialogState == 'edit'){
635 $smarty->assign('headline', sprintf(_("Edit ACL for '%s' with scope '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
637 /* Collect objects for selected category */
638 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
639 if ($idx == 0){
640 continue;
641 }
642 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
643 }
645 /* Role selector if scope is base */
646 if ($this->aclType == 'role'){
647 $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
648 } else {
649 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
650 }
651 }
653 /* Show main page */
654 $smarty->assign("dialogState", $this->dialogState);
656 /* Assign acls */
657 $smarty->assign("acl_createable",$this->acl_is_createable());
658 $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
659 $smarty->assign("acl_readable" ,$this->acl_is_readable(""));
660 $smarty->assign("acl_removeable",$this->acl_is_removeable());
662 return ($smarty->fetch (get_template_path('acl.tpl')));
663 }
666 function sort_by_priority($list)
667 {
668 $tmp= session::global_get('plist');
669 $plist= $tmp->info;
670 asort($plist);
671 $newSort = array();
673 foreach($list as $name => $translation){
674 $na = preg_replace("/^.*\//","",$name);
675 $prio = 0;
676 if(isset($plist[$na]['plPriority'])){
677 $prio= $plist[$na]['plPriority'] ;
678 }
680 $newSort[$name] = $prio;
681 }
683 asort($newSort);
685 $ret = array();
686 foreach($newSort as $name => $prio){
687 $ret[$name] = $list[$name];
688 }
689 return($ret);
690 }
693 function buildRoleSelector($list)
694 {
695 $selected = $this->aclContents;
696 if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
697 $selected = key($list);
698 }
700 $data = $lData = array();
701 foreach($list as $dn => $values){
702 if($dn == $selected){
703 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
704 }else{
705 $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
706 }
707 $data[] = postEncode($dn);
708 $lData[] = array('data'=>array($option, $values['cn'], $values['description']));
709 }
710 $this->roleList->setListData($data,$lData);
711 $this->roleList->update();
712 return($this->roleList->render());
713 }
716 function buildAclSelector($list)
717 {
718 $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
719 $cols= 3;
720 $tmp= session::global_get('plist');
721 $plist= $tmp->info;
722 asort($plist);
724 /* Add select all/none buttons */
725 $style = "style='width:100px;'";
727 if($this->acl_is_writeable("")){
728 $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
729 $display .= "<button type='button' ".$style." name='toggle_all_move' onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
730 $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
731 $display .= "<button type='button' ".$style." name='toggle_all_read' onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
732 $display .= "<button type='button' ".$style." name='toggle_all_write' onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
734 $display .= "<button type='button' ".$style." name='toggle_all_sub_read' onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
735 $display .= "<button type='button' ".$style." name='toggle_all_sub_write' onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
737 $display .= "<br>";
739 $style = "style='width:50px;'";
740 $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
741 $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
742 $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
743 $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
744 $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
745 $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
746 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
747 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
748 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
749 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
751 $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
752 $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
753 $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
754 $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
755 }
757 /* Build general objects */
758 $list =$this->sort_by_priority($list);
759 foreach ($list as $key => $name){
761 /* Create sub acl if it does not exist */
762 if (!isset($this->aclContents[$key])){
763 $this->aclContents[$key]= array();
764 }
765 if(!isset($this->aclContents[$key][0])){
766 $this->aclContents[$key][0]= '';
767 }
769 $currentAcl= $this->aclContents[$key];
771 /* Get the overall plugin acls
772 */
773 $overall_acl ="";
774 if(isset($currentAcl[0])){
775 $overall_acl = $currentAcl[0];
776 }
778 // Detect configured plugins
779 $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
781 /* Object header */
782 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
784 if($expand){
785 $back_color = "#C8C8FF";
786 }else{
787 $back_color = "#C8C8C8";
788 }
790 if(isset($_SERVER['HTTP_USER_AGENT']) &&
791 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
792 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
793 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
794 "\n <tr>".
795 "\n <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
796 "\n <td align='right' style='background-color:{$back_color};height:1.8em;'>".
797 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
798 "\n </tr>";
799 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
800 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
801 "\n <tr>".
802 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
803 "\n <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
804 "\n <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
805 "\n </tr>";
806 } else {
807 $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
808 "\n <tr>".
809 "\n <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
810 "\n </tr>";
811 }
813 /* Generate options */
814 $spc= " ";
815 $options= $this->mkchkbx($key."_0_c", _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
816 $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
817 $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
818 if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
819 $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
820 }
822 /* Global options */
823 $more_options= $this->mkchkbx($key."_0_r", _("read"), preg_match('/r/', $overall_acl)).$spc;
824 $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
826 $display.= "\n <tr>".
827 "\n <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
828 "\n <td style='background-color:#D4D4D4'> "._("Complete object").": $more_options</td>".
829 "\n </tr>";
831 /* Walk through the list of attributes */
832 $cnt= 1;
833 $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
834 if(session::global_get('js')) {
835 if(isset($_SERVER['HTTP_USER_AGENT']) &&
836 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
837 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
838 "\n <td colspan=".$cols.">".
839 "\n <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
840 "\n <table style='width:100%;' summary='{$name}'>";
841 } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
842 $display.= "\n <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
843 "\n <td colspan=".$cols.">".
844 "\n <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
845 "\n <table style='width:100%;' summary='{$name}'>";
846 }else{
847 }
848 }
851 foreach($splist as $attr => $dsc){
853 /* Skip pl* attributes, they are internal... */
854 if (preg_match('/^pl[A-Z]+.*$/', $attr)){
855 continue;
856 }
858 /* Open table row */
859 if ($cnt == 1){
860 $display.= "\n <tr>";
861 }
863 /* Close table row */
864 if ($cnt == $cols){
865 $cnt= 1;
866 $rb= "";
867 $end= "\n </tr>";
868 } else {
869 $cnt++;
870 $rb= "border-right:1px solid #A0A0A0;";
871 $end= "";
872 }
874 /* Collect list of attributes */
875 $state= "";
876 if (isset($currentAcl[$attr])){
877 $state= $currentAcl[$attr];
878 }
879 $display.= "\n <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
880 "\n <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
881 }
883 /* Fill missing td's if needed */
884 if (--$cnt != $cols && $cnt != 0){
885 $display.= str_repeat("\n <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'> </td>", $cols-$cnt);
886 }
888 if(session::global_get('js')) {
889 if(isset($_SERVER['HTTP_USER_AGENT']) &&
890 (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) ||
891 (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) ||
892 (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
893 $display.= "\n </table>".
894 "\n </div>".
895 "\n </td>".
896 "\n </tr>";
897 }
898 }
900 $display.= "\n</table><br />\n";
901 }
903 return ($display);
904 }
907 function mkchkbx($name, $text, $state= FALSE)
908 {
909 $state= $state?"checked":"";
910 if($this->acl_is_writeable("")){
911 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
912 return "\n <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
913 "\n <label for='acl_$tname'>$text</label>";
914 }else{
915 return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
916 }
917 }
920 function mkrwbx($name, $state= "")
921 {
922 $rstate= preg_match('/r/', $state)?'checked':'';
923 $wstate= preg_match('/w/', $state)?'checked':'';
924 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
926 if($this->acl_is_writeable("")){
927 return ("\n <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
928 "\n <label for='acl_".$tname."_r'>"._("read")."</label>".
929 "\n <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
930 "\n <label for='acl_".$tname."_w'>"._("write")."</label>");
931 }else{
932 return ("\n <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
933 "\n <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
934 }
935 }
938 static function explodeACL($acl)
939 {
941 $list= explode(':', $acl);
942 if(count($list) == 5){
943 list($index, $type,$member,$permission,$filter)= $list;
944 $filter = base64_decode($filter);
945 }elseif(count($list) == 4){
946 $filter = "";
947 list($index, $type,$member,$permission)= $list;
948 }else{
949 $permission = "";
950 $filter = "";
951 list($index, $type,$member)= $list;
952 }
954 $a= array( $index => array("type" => $type,
955 "filter"=> $filter,
956 "members" => acl::extractMembers($acl,$type == "role")));
958 /* Handle different types */
959 switch ($type){
961 case 'psub':
962 case 'sub':
963 case 'one':
964 case 'base':
965 $a[$index]['acl']= acl::extractACL($acl);
966 break;
968 case 'role':
969 $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
970 break;
972 case 'reset':
973 break;
975 default:
976 msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
977 $a= array();
978 }
979 return ($a);
980 }
983 static function extractMembers($acl,$role = FALSE)
984 {
985 global $config;
986 $a= array();
988 /* Rip acl off the string, seperate by ',' and place it in an array */
989 if($role){
990 $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
991 }else{
992 $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
993 }
994 if ($ms == $acl){
995 return $a;
996 }
997 $ma= explode(',', $ms);
999 /* Decode dn's, fill with informations from LDAP */
1000 $ldap= $config->get_ldap_link();
1001 foreach ($ma as $memberdn){
1002 // Check for wildcard here
1003 $dn= base64_decode($memberdn);
1004 if ($dn != "*") {
1005 $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
1007 /* Found entry... */
1008 if ($ldap->count()){
1009 $attrs= $ldap->fetch();
1010 if (in_array_ics('gosaAccount', $attrs['objectClass'])){
1011 $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
1012 } else {
1013 $a['G:'.$dn]= $attrs['cn'][0];
1014 if (isset($attrs['description'][0])){
1015 $a['G:'.$dn].= " [".$attrs['description'][0]."]";
1016 }
1017 }
1019 /* ... or not */
1020 } else {
1021 $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
1022 }
1024 } else {
1025 $a['G:*']= sprintf(_("All users"));
1026 }
1027 }
1029 return ($a);
1030 }
1033 static function extractACL($acl)
1034 {
1035 /* Rip acl off the string, seperate by ',' and place it in an array */
1036 $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1037 $aa= explode(',', $as);
1038 $a= array();
1040 /* Dis-assemble single ACLs */
1041 foreach($aa as $sacl){
1043 /* Dis-assemble field ACLs */
1044 $ao= explode('#', $sacl);
1045 $gobject= "";
1046 foreach($ao as $idx => $ssacl){
1048 /* First is department with global acl */
1049 $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1050 $gacl= preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1051 if ($idx == 0){
1052 /* Create hash for this object */
1053 $gobject= $object;
1054 $a[$gobject]= array();
1056 /* Append ACL if set */
1057 if ($gacl != ""){
1058 $a[$gobject]= array($gacl);
1059 }
1060 } else {
1062 /* All other entries get appended... */
1063 list($field, $facl)= explode(';', $ssacl);
1064 $a[$gobject][$field]= $facl;
1065 }
1067 }
1068 }
1070 return ($a);
1071 }
1074 function assembleAclSummary($entry)
1075 {
1076 $summary= "";
1078 /* Summarize ACL */
1079 if (isset($entry['acl'])){
1080 $acl= "";
1082 if($entry['type'] == "role"){
1084 if(isset($this->roles[$entry['acl']])){
1085 $summary.= sprintf(_("ACL role: %s"), $this->roles[$entry['acl']]['cn']);
1086 }else{
1087 $summary.= sprintf(_("ACL role: %s"), "<i>"._("unknown ACL role")."</i>");
1088 }
1089 }else{
1090 foreach ($entry['acl'] as $name => $object){
1091 if (count($object)){
1092 $acl.= "$name, ";
1093 }
1094 }
1095 $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1096 }
1097 }
1100 /* Summarize members */
1101 if(!($this instanceOf aclrole)){
1102 if ($summary != ""){
1103 $summary.= ", ";
1104 }
1105 if (count($entry['members'])){
1106 $summary.= _("Members").": ";
1107 foreach ($entry['members'] as $cn){
1108 $cn= preg_replace('/ \[.*$/', '', $cn);
1109 $summary.= $cn.", ";
1110 }
1111 } else {
1112 $summary.= "<font color='red'><i>"._("inactive")." - "._("No members")."</i></font>";
1113 }
1114 }
1115 return (preg_replace('/, $/', '', $summary));
1116 }
1119 function loadAclEntry($new= FALSE)
1120 {
1121 /* New entry gets presets... */
1122 if ($new){
1123 $this->aclType= 'base';
1124 $this->aclFilter= "";
1125 $this->recipients= array();
1126 $this->aclContents= array();
1127 } else {
1128 $acl= $this->gosaAclEntry[$this->currentIndex];
1129 $this->aclType= $acl['type'];
1130 $this->recipients= $acl['members'];
1131 $this->aclContents= (isset($acl['acl'])) ? $acl['acl'] :"";
1132 $this->aclFilter= $acl['filter'];
1133 }
1135 $this->wasNewEntry= $new;
1136 }
1139 function aclPostHandler()
1140 {
1141 if (isset($_POST['save_acl'])){
1142 $this->save();
1143 return TRUE;
1144 }
1146 return FALSE;
1147 }
1150 function PrepareForCopyPaste($source)
1151 {
1152 plugin::PrepareForCopyPaste($source);
1154 $dn = $source['dn'];
1155 $acl_c = new acl($this->config, $this->parent,$dn);
1156 $this->gosaAclEntry = $acl_c->gosaAclEntry;
1157 }
1160 function save()
1161 {
1162 /* Assemble ACL's */
1163 $tmp_acl= array();
1165 foreach ($this->gosaAclEntry as $prio => $entry){
1166 $final= "";
1167 $members= "";
1168 if (isset($entry['members'])){
1169 foreach ($entry['members'] as $key => $dummy){
1170 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1171 }
1172 }
1174 if($entry['type'] != "role"){
1175 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1176 }else{
1177 $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1178 }
1180 /* ACL's if needed */
1181 $final.= ":";
1182 if ($entry['type'] != "reset" && $entry['type'] != "role"){
1183 $acl = "";
1184 if (isset($entry['acl'])){
1185 foreach ($entry['acl'] as $object => $contents){
1187 /* Only save, if we've some contents in there... */
1188 if (count($contents)){
1189 $acl.= $object.";";
1191 foreach($contents as $attr => $permission){
1193 /* First entry? Its the one for global settings... */
1194 if ($attr == '0'){
1195 $acl.= $permission;
1196 } else {
1197 $acl.= '#'.$attr.';'.$permission;
1198 }
1200 }
1201 $acl.= ',';
1202 }
1204 }
1205 }
1206 $final.= preg_replace('/,$/', '', $acl);
1207 }
1209 /* Append additional filter options
1210 */
1211 if(!empty($entry['filter'])){
1212 $final .= ":".base64_encode($entry['filter']);
1213 }
1215 $tmp_acl[]= $final;
1216 }
1218 /* Call main method */
1219 plugin::save();
1221 /* Finally (re-)assign it... */
1222 $this->attrs['gosaAclEntry']= $tmp_acl;
1224 /* Remove acl from this entry if it is empty... */
1225 if (!count($tmp_acl)){
1226 /* Remove attribute */
1227 if ($this->initially_was_account){
1228 $this->attrs['gosaAclEntry']= array();
1229 } else {
1230 if (isset($this->attrs['gosaAclEntry'])){
1231 unset($this->attrs['gosaAclEntry']);
1232 }
1233 }
1235 /* Remove object class */
1236 $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1237 }
1239 /* Do LDAP modifications */
1240 $ldap= $this->config->get_ldap_link();
1241 $ldap->cd($this->dn);
1242 $this->cleanup();
1243 $ldap->modify ($this->attrs);
1245 if(count($this->attrs)){
1246 new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1247 }
1249 if (!$ldap->success()){
1250 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1251 }
1253 /* Refresh users ACLs */
1254 $ui= get_userinfo();
1255 $ui->loadACL();
1256 session::global_set('ui',$ui);
1257 }
1260 function remove_from_parent()
1261 {
1262 plugin::remove_from_parent();
1264 /* include global link_info */
1265 $ldap= $this->config->get_ldap_link();
1267 $ldap->cd($this->dn);
1268 $this->cleanup();
1269 $ldap->modify ($this->attrs);
1271 new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1273 /* Optionally execute a command after we're done */
1274 $this->handle_post_events("remove",array("uid" => $this->uid));
1275 }
1278 /* Return plugin informations for acl handling */
1279 static function plInfo()
1280 {
1281 return (array(
1282 "plShortName" => _("ACL"),
1283 "plDescription" => _("ACL")." ("._("Access control list").")",
1284 "plSelfModify" => FALSE,
1285 "plDepends" => array(),
1286 "plPriority" => 0,
1287 "plSection" => array("administration"),
1288 "plRequirements"=> array('ldapSchema' => array('gosaAcl' => '>=2.7')),
1289 "plCategory" => array("acl" => array("description" => _("ACL")." & "._("ACL roles"),
1290 "objectClass" => array("gosaAcl","gosaRole"))),
1291 "plProvidedAcls"=> array(
1292 "gosaAclEntry" => _("ACL Entries")
1293 )
1295 ));
1296 }
1299 /* Remove acls defined for $src */
1300 function remove_acl()
1301 {
1302 acl::remove_acl_for($this->dn);
1303 }
1306 /* Remove acls defined for $src */
1307 static function remove_acl_for($dn)
1308 {
1309 global $config;
1311 $ldap = $config->get_ldap_link();
1312 $ldap->cd($config->current['BASE']);
1313 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1314 $new_entries= array();
1315 while($attrs = $ldap->fetch()){
1316 if (!isset($attrs['gosaAclEntry'])) {
1317 continue;
1318 }
1319 unset($attrs['gosaAclEntry']['count']);
1321 // Remove entry directly
1322 foreach($attrs['gosaAclEntry'] as $id => $entry){
1323 $parts= explode(':',$entry);
1324 $members= explode(',',$parts[2]);
1325 $new_members= array();
1326 foreach($members as $member) {
1327 if (base64_decode($member) != $dn) {
1328 $new_members[]= $member;
1329 } else {
1330 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1331 }
1332 }
1334 /* We can completely remove the entry if there are no members anymore */
1335 if (count($new_members)) {
1336 $parts[2]= implode(",", $new_members);
1337 $new_entries[]= implode(":", $parts);
1338 }
1339 }
1341 // There should be a modification, so write it back
1342 $ldap->cd($attrs['dn']);
1343 $new_attrs= array("gosaAclEntry" => $new_entries);
1344 $ldap->modify($new_attrs);
1345 if (!$ldap->success()){
1346 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1347 }
1348 }
1349 }
1352 function update_acl_membership($src,$dst)
1353 {
1354 $ldap = $this->config->get_ldap_link();
1355 $ldap->cd($this->config->current['BASE']);
1356 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1357 while($attrs = $ldap->fetch()){
1358 $acl = new acl($this->config,$this->parent,$attrs['dn']);
1359 foreach($acl->gosaAclEntry as $id => $entry){
1360 foreach($entry['members'] as $m_id => $member){
1361 if($m_id == "U:".$src){
1362 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1363 $new = "U:".$dst;
1364 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1365 gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1366 }
1367 if($m_id == "G:".$src){
1368 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1369 $new = "G:".$dst;
1370 $acl->gosaAclEntry[$id]['members'][$new] = $new;
1371 gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1372 }
1373 }
1374 }
1375 $acl -> save();
1376 }
1377 }
1380 // We are only interessted in our own acls ...
1381 function set_acl_category($category)
1382 {
1383 plugin::set_acl_category("acl");
1384 }
1385 }
1387 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1388 ?>