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 class aclrole extends acl
24 {
25 /* Definitions */
26 var $plHeadline= "Access control roles";
27 var $plDescription= "Edit AC roles";
29 /* attribute list for save action */
30 var $attributes= array('gosaAclTemplate',"cn","description");
31 var $objectclasses= array('top','gosaRole');
33 /* Helpers */
34 var $dialogState= "head";
35 var $aclType= "";
36 var $aclObject= "";
37 var $aclContents= array();
38 var $target= "group";
39 var $aclTypes= array();
40 var $aclObjects= array();
41 var $recipients= array();
42 var $isContainer= TRUE;
43 var $currentIndex= 0;
44 var $wasNewEntry= FALSE;
45 var $ocMapping= array();
46 var $savedAclContents= array();
47 var $myAclObjects = array();
49 /* Role attributes */
50 var $gosaAclTemplate= "";
51 var $cn = "";
52 var $orig_cn = "";
53 var $description = "";
54 var $orig_dn;
55 var $orig_base;
56 var $base ="";
58 function aclrole (&$config, $dn= NULL)
59 {
60 /* Include config object */
61 plugin::plugin($config, $dn);
63 if($this->dn == "new"){
64 $this->base = session::get('CurrentMainBase');
65 }else{
66 $this->base = preg_replace("/^[^,]+,[^,]+,/","",$this->dn);
67 new log("view","acl/".get_class($this),$this->dn);
68 }
70 /* Load ACL's */
71 $this->gosaAclTemplate= array();
72 if (isset($this->attrs["gosaAclTemplate"])){
73 for ($i= 0; $i<$this->attrs["gosaAclTemplate"]['count']; $i++){
74 $acl= $this->attrs["gosaAclTemplate"][$i];
75 $this->gosaAclTemplate= array_merge($this->gosaAclTemplate, $this->explodeACL($acl));
76 }
77 }
78 ksort($this->gosaAclTemplate);
80 /* Extract available categories from plugin info list */
81 $tmp= session::get('plist');
82 $plist= $tmp->info;
83 $oc = array();
84 foreach ($plist as $class => $acls){
86 /* Only feed categories */
87 if (isset($acls['plCategory'])){
89 /* Walk through supplied list and feed only translated categories */
90 foreach($acls['plCategory'] as $idx => $data){
92 /* Non numeric index means -> base object containing more informations */
93 if (preg_match('/^[0-9]+$/', $idx)){
94 if (!isset($this->ocMapping[$data])){
95 $this->ocMapping[$data]= array();
96 $this->ocMapping[$data][]= '0';
97 }
98 $this->ocMapping[$data][]= $class;
99 } else {
100 if (!isset($this->ocMapping[$idx])){
101 $this->ocMapping[$idx]= array();
102 $this->ocMapping[$idx][]= '0';
103 }
104 $this->ocMapping[$idx][]= $class;
105 $this->aclObjects[$idx]= $data['description'];
107 /* Additionally filter the classes we're interested in in "self edit" mode */
108 if (is_array($data['objectClass'])){
109 foreach($data['objectClass'] as $objectClass){
110 if (in_array_ics($objectClass, $oc)){
111 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
112 break;
113 }
114 }
115 } else {
116 if (in_array_ics($data['objectClass'], $oc)){
117 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
118 }
119 }
120 }
122 }
123 }
124 }
125 $this->aclObjects['all']= '* '._("All categories");
126 $this->ocMapping['all']= array('0' => 'all');
128 /* Sort categories */
129 asort($this->aclObjects);
131 /* Fill acl types */
132 $this->aclTypes= array( "reset" => _("Reset ACL"),
133 "one" => _("One level"),
134 "base" => _("Current object"),
135 "sub" => _("Complete subtree"),
136 "psub" => _("Complete subtree (permanent)"));
137 asort($this->aclTypes);
139 /* Finally - we want to get saved... */
140 $this->is_account= TRUE;
141 $this->orig_base = $this->base;
142 $this->orig_dn = $this->dn;
143 $this->orig_cn = $this->cn;
144 }
147 function execute()
148 {
149 /* Call parent execute */
150 plugin::execute();
152 /* Base select dialog */
153 $once = true;
154 foreach($_POST as $name => $value){
155 if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
156 $once = false;
157 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
158 $this->dialog->setCurrentBase($this->base);
159 }
160 }
162 /* Dialog handling */
163 if(is_object($this->dialog)){
164 /* Must be called before save_object */
165 $this->dialog->save_object();
167 if($this->dialog->isClosed()){
168 $this->dialog = false;
169 }elseif($this->dialog->isSelected()){
171 /* Check if selected base is valid */
172 $tmp = $this->get_allowed_bases();
173 if(isset($tmp[$this->dialog->isSelected()])){
174 $this->base = $this->dialog->isSelected();
175 }
176 $this->dialog= false;
177 }else{
178 return($this->dialog->execute());
179 }
180 }
182 $tmp= session::get('plist');
183 $plist= $tmp->info;
185 /* Handle posts */
186 if (isset($_POST['new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
187 $this->dialogState= 'create';
188 $this->dialog= TRUE;
189 $this->currentIndex= count($this->gosaAclTemplate);
190 $this->loadAclEntry(TRUE);
191 }
193 $new_acl= array();
194 $aclDialog= FALSE;
195 $firstedit= FALSE;
197 /* Act on HTML post and gets here.
198 */
199 if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
200 $id = trim($_GET['id']);
201 $this->dialogState= 'create';
202 $firstedit= TRUE;
203 $this->dialog= TRUE;
204 $this->currentIndex= $id;
205 $this->loadAclEntry();
206 }
208 foreach($_POST as $name => $post){
210 /* Actions... */
211 if (preg_match('/^acl_edit_.*_x/', $name)){
212 $this->dialogState= 'create';
213 $firstedit= TRUE;
214 $this->dialog= TRUE;
215 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
216 $this->loadAclEntry();
217 continue;
218 }
219 if (preg_match('/^cat_edit_.*_x/', $name)){
220 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
221 $this->dialogState= 'edit';
222 foreach ($this->ocMapping[$this->aclObject] as $oc){
223 if (isset($this->aclContents[$oc])){
224 $this->savedAclContents[$oc]= $this->aclContents[$oc];
225 }
226 }
227 continue;
228 }
230 if(!$this->acl_is_writeable("gosaAclEntry")){
231 continue;
232 }
234 if (preg_match('/^acl_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
235 unset($this->gosaAclTemplate[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
236 continue;
237 }
239 if (preg_match('/^cat_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
240 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
241 foreach ($this->ocMapping[$idx] as $key){
242 unset($this->aclContents["$idx/$key"]);
243 }
244 continue;
245 }
247 /* Sorting... */
248 if (preg_match('/^sortup_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
249 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
250 if ($index > 0){
251 $tmp= $this->gosaAclTemplate[$index];
252 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index-1];
253 $this->gosaAclTemplate[$index-1]= $tmp;
254 }
255 continue;
256 }
257 if (preg_match('/^sortdown_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
258 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
259 if ($index < count($this->gosaAclTemplate)-1){
260 $tmp= $this->gosaAclTemplate[$index];
261 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index+1];
262 $this->gosaAclTemplate[$index+1]= $tmp;
263 }
264 continue;
265 }
267 /* ACL saving... */
268 if (preg_match('/^acl_.*_[^xy]$/', $name) && $this->acl_is_writeable("gosaAclEntry")){
269 list($dummy, $object, $attribute, $value)= split('_', $name);
271 /* Skip for detection entry */
272 if ($object == 'dummy') {
273 continue;
274 }
276 /* Ordinary ACL */
277 if (!isset($new_acl[$object])){
278 $new_acl[$object]= array();
279 }
280 if (isset($new_acl[$object][$attribute])){
281 $new_acl[$object][$attribute].= $value;
282 } else {
283 $new_acl[$object][$attribute]= $value;
284 }
285 }
286 }
288 if(isset($_POST['acl_dummy_0_0_0'])){
289 $aclDialog= TRUE;
290 }
292 /* Only be interested in new acl's, if we're in the right _POST place */
293 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
295 foreach ($this->ocMapping[$this->aclObject] as $oc){
296 unset($this->aclContents[$oc]);
297 unset($this->aclContents[$this->aclObject.'/'.$oc]);
298 if (isset($new_acl[$oc])){
299 $this->aclContents[$oc]= $new_acl[$oc];
300 }
301 if (isset($new_acl[$this->aclObject.'/'.$oc])){
302 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
303 }
304 }
305 }
307 /* Save new acl in case of base edit mode */
308 if (1 == 0 && $this->aclType == 'base' && !$firstedit){
309 $this->aclContents= $new_acl;
310 }
312 /* Cancel new acl? */
313 if (isset($_POST['cancel_new_acl'])){
314 $this->dialogState= 'head';
315 $this->dialog= FALSE;
316 if ($this->wasNewEntry){
317 unset ($this->gosaAclTemplate[$this->currentIndex]);
318 }
319 }
321 /* Store ACL in main object? */
322 if (isset($_POST['submit_new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
323 $this->gosaAclTemplate[$this->currentIndex]['type']= $this->aclType;
324 $this->gosaAclTemplate[$this->currentIndex]['members']= $this->recipients;
325 $this->gosaAclTemplate[$this->currentIndex]['acl']= $this->aclContents;
326 $this->dialogState= 'head';
327 $this->dialog= FALSE;
328 }
330 /* Cancel edit acl? */
331 if (isset($_POST['cancel_edit_acl'])){
332 $this->dialogState= 'create';
333 foreach ($this->ocMapping[$this->aclObject] as $oc){
334 if (isset($this->savedAclContents[$oc])){
335 $this->aclContents[$oc]= $this->savedAclContents[$oc];
336 }
337 }
338 }
340 /* Save edit acl? */
341 if (isset($_POST['submit_edit_acl']) && $this->acl_is_writeable("gosaAclEntry")){
342 $this->dialogState= 'create';
343 }
345 /* Add acl? */
346 if (isset($_POST['add_acl']) && $_POST['aclObject'] != "" && $this->acl_is_writeable("gosaAclEntry")){
347 $this->dialogState= 'edit';
348 $this->savedAclContents= array();
349 foreach ($this->ocMapping[$this->aclObject] as $oc){
350 if (isset($this->aclContents[$oc])){
351 $this->savedAclContents[$oc]= $this->aclContents[$oc];
352 }
353 }
354 }
356 /* Save common values */
357 foreach (array("aclType", "aclObject", "target") as $key){
358 if (isset($_POST[$key]) && $this->acl_is_writeable("gosaAclEntry")){
359 $this->$key= validate($_POST[$key]);
360 }
361 }
363 /* Create templating instance */
364 $smarty= get_smarty();
366 $smarty->assign("bases", $this->get_allowed_bases());
367 $smarty->assign("base_select", $this->base);
369 $tmp = $this->plInfo();
370 foreach($tmp['plProvidedAcls'] as $name => $translation){
371 $smarty->assign($name."ACL",$this->getacl($name));
372 }
374 if ($this->dialogState == 'head'){
375 /* Draw list */
376 $aclList= new divSelectBox("aclList");
377 $aclList->SetHeight(350);
379 /* Fill in entries */
380 foreach ($this->gosaAclTemplate as $key => $entry){
382 if($this->acl_is_readable("")){
383 $link = "<a href=?plug=".$_GET['plug']."&id=".$key."&act=edit>".$this->assembleAclSummary($entry)."</a>";
384 }else{
385 $link = $this->assembleAclSummary($entry);
386 }
388 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
389 $field2= array("string" => $link);
391 $action ="";
392 if($this->acl_is_writeable("gosaAclEntry")){
393 $action.= "<input type='image' name='sortup_$key' alt='up'
394 title='"._("Up")."' src='images/lists/sort-up.png' align='top'>";
395 $action.= "<input type='image' name='sortdown_$key' alt='down'
396 title='"._("Down")."' src='images/lists/sort-down.png'>";
397 }
398 if($this->acl_is_readable("gosaAclEntry")){
399 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("Edit")."' name='acl_edit_$key'
400 title='".msgPool::editButton(_("ACL"))."'>";
401 }
402 if($this->acl_is_writeable("gosaAclEntry")){
403 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("Delete")."' name='acl_del_$key'
404 title='".msgPool::delButton(_("ACL"))."'>";
405 }
407 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
408 $aclList->AddEntry(array($field1, $field2, $field3));
409 }
411 $smarty->assign("aclList", $aclList->DrawList());
412 }
414 if ($this->dialogState == 'create'){
415 /* Draw list */
416 $aclList= new divSelectBox("aclList");
417 $aclList->SetHeight(450);
419 /* Add settings for all categories to the (permanent) list */
420 foreach ($this->aclObjects as $section => $dsc){
421 $summary= "";
422 foreach($this->ocMapping[$section] as $oc){
423 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
424 $this->aclContents[$oc][0] != ""){
426 $summary.= "$oc, ";
427 continue;
428 }
429 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
430 $summary.= "$oc, ";
431 continue;
432 }
433 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
434 $summary.= "$oc, ";
435 }
436 }
438 /* Set summary... */
439 if ($summary == ""){
440 $summary= '<i>'._("No ACL settings for this category").'</i>';
441 } else {
442 $summary= sprintf(_("ACL for these objects: %s"), preg_replace('/, $/', '', $summary));
443 }
445 $action = "";
446 if($this->acl_is_readable("gosaAclEntry")){
447 $action.= "<input class='center' type='image' src='images/lists/edit.png'
448 alt='"._("Edit")."' name='cat_edit_$section' title='"._("Edit category ACL")."'>";
449 }
450 if($this->acl_is_writeable("gosaAclEntry")){
451 $action.= "<input class='center' type='image' src='images/lists/trash.png'
452 alt='"._("Delete")."' name='cat_del_$section' title='"._("Reset category ACL")."'>";
453 }
455 $field1= array("string" => $dsc, "attach" => "style='width:140px'");
456 $field2= array("string" => $summary);
457 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
458 $aclList->AddEntry(array($field1, $field2, $field3));
459 }
461 $smarty->assign("aclList", $aclList->DrawList());
462 $smarty->assign("aclType", $this->aclType);
463 $smarty->assign("aclTypes", $this->aclTypes);
464 $smarty->assign("target", $this->target);
466 if ($this->aclType == 'base'){
467 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
468 }
469 }
471 if ($this->dialogState == 'edit'){
472 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
474 /* Collect objects for selected category */
475 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
476 if ($idx == 0){
477 continue;
478 }
479 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
480 }
481 if ($this->aclObject == 'all'){
482 $aclObjects['all']= _("All objects in current subtree");
483 }
484 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
485 }
487 /* Show main page */
488 $smarty->assign("dialogState", $this->dialogState);
490 /* Assign cn and decription if this is a role */
491 foreach(array("cn","description") as $name){
492 $smarty->assign($name,$this->$name);
493 }
494 return ($smarty->fetch (get_template_path('acl_role.tpl',dirname(__FILE__))));
495 }
497 function sort_by_priority($list)
498 {
499 $tmp= session::get('plist');
500 $plist= $tmp->info;
501 asort($plist);
502 $newSort = array();
504 foreach($list as $name => $translation){
505 $na = preg_replace("/^.*\//","",$name);
506 if (!isset($plist[$na]['plPriority'])){
507 $prio= 0;
508 } else {
509 $prio= $plist[$na]['plPriority'] ;
510 }
512 $newSort[$name] = $prio;
513 }
515 asort($newSort);
517 $ret = array();
518 foreach($newSort as $name => $prio){
519 $ret[$name] = $list[$name];
520 }
521 return($ret);
522 }
524 function loadAclEntry($new= FALSE)
525 {
526 /* New entry gets presets... */
527 if ($new){
528 $this->aclType= 'sub';
529 $this->recipients= array();
530 $this->aclContents= array();
531 } else {
532 $acl= $this->gosaAclTemplate[$this->currentIndex];
533 $this->aclType= $acl['type'];
534 $this->recipients= $acl['members'];
535 $this->aclContents= $acl['acl'];
536 }
538 $this->wasNewEntry= $new;
539 }
542 function aclPostHandler()
543 {
544 if (isset($_POST['save_acl']) && $this->acl_is_writeable("gosaAclEntry")){
545 $this->save();
546 return TRUE;
547 }
549 return FALSE;
550 }
553 function save()
554 {
555 /* Assemble ACL's */
556 $tmp_acl= array();
557 foreach ($this->gosaAclTemplate as $prio => $entry){
558 $final= "";
559 $members= "";
560 if (isset($entry['members'])){
561 foreach ($entry['members'] as $key => $dummy){
562 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
563 }
564 }
565 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
567 /* ACL's if needed */
568 if ($entry['type'] != "reset" && $entry['type'] != "role"){
569 $acl= ":";
570 if (isset($entry['acl'])){
571 foreach ($entry['acl'] as $object => $contents){
573 /* Only save, if we've some contents in there... */
574 if (count($contents)){
575 $acl.= $object.";";
577 foreach($contents as $attr => $permission){
579 /* First entry? Its the one for global settings... */
580 if ($attr == '0'){
581 $acl.= $permission;
582 } else {
583 $acl.= '#'.$attr.';'.$permission;
584 }
586 }
587 $acl.= ',';
588 }
590 }
591 }
592 $final.= preg_replace('/,$/', '', $acl);
593 }
595 $tmp_acl[]= $final;
596 }
598 /* Call main method */
599 plugin::save();
601 /* Finally (re-)assign it... */
602 $this->attrs["gosaAclTemplate"]= $tmp_acl;
604 /* Remove acl from this entry if it is empty... */
605 if (!count($tmp_acl)){
606 /* Remove attribute */
607 if ($this->initially_was_account){
608 $this->attrs["gosaAclTempalte"]= array();
609 } else {
610 if (isset($this->attrs["gosaAclTemplate"])){
611 unset($this->attrs["gosaAclTemplate"]);
612 }
613 }
614 }
616 /* Do LDAP modifications */
617 $ldap= $this->config->get_ldap_link();
619 /* Check if object already exists */
620 $ldap->cat($this->dn);
621 if($ldap->count()){
622 $ldap->cd($this->dn);
623 $this->cleanup();
624 $ldap->modify ($this->attrs);
625 new log("modify","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
626 }else{
627 $ldap->cd($this->config->current['BASE']);
628 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$this->dn));
629 $ldap->cd($this->dn);
630 $ldap->add($this->attrs);
631 new log("create","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
632 }
634 if (!$ldap->success()){
635 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
636 }
638 /* Refresh users ACL */
639 $ui= get_userinfo();
640 $ui->loadACL();
641 session::set('ui',$ui);
642 }
645 function remove_from_parent()
646 {
647 $ldap = $this->config->get_ldap_link();
648 $serach_for = "*:role:".base64_encode($this->dn).":*";
649 $ldap->search ("(&(objectClass=gosaACL)(gosaAclEntry=".$serach_for."))",array('dn','cn','sn','givenName','uid'));
650 $all_names = "";
653 $cnt = 3;
654 while(($attrs = $ldap->fetch()) && $cnt){
655 $name = $attrs['dn'];
656 $name = preg_replace("/[ ]/"," ",$name);
657 $name = "<i>'".$name."'</i>";
658 $all_names .= $name.", ";
659 $cnt --;
660 }
662 if(!empty($all_names)){
663 $all_names = preg_replace("/, $/","",$all_names);
664 if(!$cnt){
665 $all_names .= ", ...";
666 }
667 $all_names = "<span style='text-align:left;'>".$all_names."</span>";
668 msg_dialog::display(_("Object in use"), sprintf(_("This role cannot be removed while it is in use by these objects:")."<br><br>%s", $all_names), WARNING_DIALOG);
669 return;
670 }
672 $ldap->rmDir($this->dn);
673 new log("remove","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
674 if (!$ldap->success()){
675 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
676 }
678 /* Optionally execute a command after we're done */
679 $this->handle_post_events("remove");
681 /* Delete references to object groups */
682 $ldap->cd ($this->config->current['BASE']);
683 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
684 while ($ldap->fetch()){
685 $og= new ogroup($this->config, $ldap->getDN());
686 unset($og->member[$this->dn]);
687 $og->save ();
688 if (!$ldap->success()){
689 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, "", get_class()));
690 }
691 }
692 }
695 function save_object()
696 {
697 plugin::save_object();
698 if(isset($_POST['acl_role_posted'])){
700 /* Get base selection */
701 if(isset($_POST['base'])){
702 $tmp = $this->get_allowed_bases();
703 if(isset($tmp[$_POST['base']])){
704 $this->base = $_POST['base'];
705 }
706 }
707 }
708 }
711 function saveCopyDialog()
712 {
713 if(isset($_POST['cn'])){
714 $this->cn = $_POST['cn'];
715 }
716 }
719 function getCopyDialog()
720 {
721 $smarty = get_smarty();
722 $smarty->assign("cn",$this->cn);
723 $str = $smarty->fetch(get_template_path("paste_role.tpl",TRUE,dirname(__FILE__)));
724 $ret = array();
725 $ret['string'] = $str;
726 $ret['status'] = "";
727 return($ret);
728 }
731 function PrepareForCopyPaste($source)
732 {
733 plugin::PrepareForCopyPaste($source);
735 $source_o = new aclrole($this->config,$source['dn']);
736 $this->gosaAclTemplate = $source_o->gosaAclTemplate;
737 }
740 /* Return plugin informations for acl handling */
741 static function plInfo()
742 {
743 return (array(
744 "plShortName" => _("Role"),
745 "plDescription" => _("Access control roles"),
746 "plSelfModify" => FALSE,
747 "plDepends" => array(),
748 "plPriority" => 0,
749 "plSection" => array("administration"),
750 "plCategory" => array("acl"),
751 "plProvidedAcls" => array(
752 "cn" => _("Name"),
753 "base" => _("Base"),
754 "description" => _("Description"),
755 "gosaAclEntry" => _("Permissions"))
756 ));
757 }
759 function check()
760 {
761 $message = plugin::check();
763 if(empty($this->cn)){
764 $message[] = msgPool::required(_("Name"));
765 }
767 $ldap = $this->config->get_ldap_link();
768 $ldap->cd($this->config->current['BASE']);
769 if($this->cn != $this->orig_cn){
770 $ldap->search("(&(objectClass=gosaRole)(cn=".$this->cn."))");
771 if($ldap->count()) {
772 while($attrs = $ldap->fetch()){
773 if($attrs['dn'] != $this->orig_dn){
774 $message[] = msgPool::duplicated(_("Name"));
775 }
776 }
777 }
778 }
780 if(!count($this->gosaAclTemplate)){
781 $message[] = msgPool::required(_("ACL"));
782 }
784 /* Check if we are allowed to create or move this object
785 */
786 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
787 $message[] = msgPool::permCreate();
788 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
789 $message[] = msgPool::permMove();
790 }
792 return($message);
793 }
795 }
797 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
798 ?>