1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 require_once("tabs_acl_role.inc");
22 require_once("tabs_acl.inc");
24 class aclManagement extends plugin
25 {
26 /* Plugin definitions */
27 var $plHeadline = "ACLs";
28 var $plDescription = "This does something";
30 /* Dialog attributes */
31 var $acltabs = NULL;
32 var $ui = NULL;
33 var $acl = "";
34 var $DivListACL = NULL;
36 var $CopyPasteHandler;
38 function aclManagement($config, $ui)
39 {
40 /* Save configuration for internal use */
41 $this->config = $config;
42 $this->ui = $ui;
44 /* Copy & Paste enabled ?*/
45 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
46 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
47 }
49 /* Creat dialog object */
50 $this->DivListACL = new divListACL($this->config,$this);
51 }
54 function execute()
55 {
56 /* Call parent execute */
57 plugin::execute();
59 $_SESSION['LOCK_VARS_TO_USE'] = array("/^list/","/^id_/","/^list_acl_role_del/","/^list_acl_del/");
61 $smarty = get_smarty(); // Smarty instance
62 $s_action = ""; // Contains the action to be taken
63 $s_entry = ""; // The value for s_action
65 /* Edit entry button pressed? */
66 if( isset($_GET['act']) && $_GET['act'] == "list_edit_entry" ){
67 $s_action= "edit";
68 $s_entry= validate($_GET['id']);
69 }
71 /* Edit entry button pressed? */
72 if( isset($_GET['act']) && $_GET['act'] == "list_edit_role" ){
73 $s_action= "edit_role";
74 $s_entry= validate($_GET['id']);
75 }
77 $types = array(
78 "del" =>"^list_acl_del",
79 "edit" =>"^list_acl_edit",
80 "del_role" =>"^list_acl_role_del",
81 "edit_role" =>"^list_acl_role_edit",
82 "copy" =>"^copy",
83 "cut" =>"^cut",
84 "editPaste" =>"^editPaste",
85 "addrole" =>"^new_acl_role");
87 /* Test relevant POST values */
88 foreach($_POST as $key => $val){
90 /* Get every possible POST combination and set s_action/s_entry accordingly */
91 foreach($types as $act => $name){
93 if (preg_match("/".$name.".*/", $key)){
94 $s_action= $act;
95 $s_entry= preg_replace("/".$name."_/i", "", $key);
96 }
97 }
98 }
100 /* Remove coordinate prefix from POST, required by some browsers */
101 $s_entry= preg_replace("/_.$/", "", $s_entry);
103 /* Seperate possibly encoded tab and entry, default to tab "acl" */
104 if(preg_match("/.*-.*/", $s_entry)){
105 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
106 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
107 }else{
108 $s_tab= "generic";
109 }
112 /********************
113 Copy & Paste Handling ...
114 ********************/
116 /* Only perform copy&paste requests if it is enabled
117 */
118 if($this->CopyPasteHandler){
119 if($str = $this->copyPasteHandling($s_action,$s_entry)){
120 return $str;
121 }
122 }
125 /********************
126 * Add new Role entry
127 ********************/
129 if(($s_action == "addrole") && (!isset($this->acltabs->config))){
131 /* Get 'dn' from posted acl, must be unique */
132 $this->dn= "new";
134 /* Check permissions */
135 if(preg_match("/c/",$this->ui->get_permissions($this->DivListACL->selectedBase,"acl/acl"))){
137 /* Register acltabs to trigger edit dialog */
138 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
139 $this->acltabs->set_acl_base($this->DivListACL->selectedBase);
140 }else{
141 print_red(_("You are not allowed to create a new role."));
142 }
143 }
145 /********************
146 Edit existing entry
147 ********************/
149 if (($s_action=="edit" || $s_action=="edit_role") && (!isset($this->acltabs->config))){
151 /* Get 'dn' from posted acl, must be unique */
152 $this->dn= $this->list[trim($s_entry)]['dn'];
154 /* Check permissions */
155 if(preg_match("/r/",$this->ui->get_permissions($this->dn,"acl/acl"))){
157 /* Check locking, save current plugin in 'back_plugin', so
158 the dialog knows where to return. */
159 if (($acl= get_lock($this->dn)) != ""){
160 return(gen_locked_message ($acl, $this->dn));
161 }
163 /* Lock the current entry, so everyone will get the above dialog */
164 add_lock ($this->dn, $this->ui->dn);
166 /* Register acltabs to trigger edit dialog */
167 if($s_action=="edit_role"){
168 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
169 $this->acltabs-> set_acl_base($this->dn);
170 }else{
171 $this->acltabs= new acltab($this->config, NULL,$this->dn);
172 $this->acltabs-> set_acl_base($this->dn);
173 }
175 /* Set ACL and move DN to the headline */
176 $_SESSION['objectinfo']= $this->dn;
177 }else{
178 print_red(_("You are not allowed to edit this acl."));
179 }
180 }
183 /********************
184 Edit canceled
185 ********************/
186 if(isset($_POST['delete_lock'])){
187 del_lock ($this->dn);
188 unset($_SESSION['objectinfo']);
189 }
191 /* Reset all relevant data, if we get a _cancel request */
192 if (isset($_POST['edit_cancel'])){
193 if (isset($this->acltabs)){
194 del_lock ($this->dn);
195 unset ($this->acltabs);
196 }
197 $this->acltabs= NULL;
198 unset ($_SESSION['objectinfo']);
199 }
202 /********************
203 Delete entry requested, display confirm dialog
204 ********************/
206 /* Remove acl was requested */
207 if ($s_action=="del_role"){
209 /* Get 'dn' from posted acl */
210 $this->dn= $this->list[trim($s_entry)]['dn'];
212 /* Check permissions */
213 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"aclroles/aclrole"))){
215 /* Check locking, save current plugin in 'back_plugin', so
216 the dialog knows where to return. */
217 if (($acl= get_lock($this->dn)) != ""){
218 return(gen_locked_message ($acl, $this->dn));
219 }
221 /* Lock the current entry, so nobody will edit it during deletion */
222 add_lock ($this->dn, $this->ui->dn);
223 $smarty->assign("info", sprintf(_("You're about to delete the acl %s."), @LDAP::fix($this->dn)));
224 $smarty->assign("is_role",true);
226 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
227 } else {
229 /* Obviously the acl isn't allowed to delete. Show message and
230 clean session. */
231 print_red (_("You are not allowed to delete this acl!"));
232 }
233 }
236 /********************
237 Delete entry confirmed
238 ********************/
240 /* Confirmation for deletion has been passed. Acl should be deleted. */
241 if (isset($_POST['delete_acl_role_confirmed'])){
243 /* Check permissions */
244 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"aclroles/aclrole"))){
246 /* Delete request is permitted, perform LDAP action */
247 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
248 $this->acltabs->delete();
249 unset ($this->acltabs);
250 $this->acltabs= NULL;
251 } else {
253 /* Normally this shouldn't be reached, send some extra
254 logs to notify the administrator */
255 print_red (_("You are not allowed to delete this acl role!"));
257 if(isset($this->ui->uid)){
258 @log::log("security","aclroles/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick acl role deletion.");
259 }
260 }
262 /* Remove lock file after successfull deletion */
263 del_lock ($this->dn);
264 }
266 /********************
267 Delete entry requested, display confirm dialog
268 ********************/
270 /* Remove acl was requested */
271 if ($s_action=="del"){
273 /* Get 'dn' from posted acl */
274 $this->dn= $this->list[trim($s_entry)]['dn'];
276 /* Check permissions */
277 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"acl/acl"))){
278 /* Check locking, save current plugin in 'back_plugin', so
279 the dialog knows where to return. */
280 if (($acl= get_lock($this->dn)) != ""){
281 $_SESSION['LOCK_VARS_TO_USE'] = array("/^list_acl_edit/","/^list_acl_del/","/^id_/");
282 return(gen_locked_message ($acl, $this->dn));
283 }
285 /* Lock the current entry, so nobody will edit it during deletion */
286 add_lock ($this->dn, $this->ui->dn);
287 $smarty->assign("info", sprintf(_("You're about to delete the acl %s."), @LDAP::fix($this->dn)));
288 $smarty->assign("is_role",false);
289 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
290 } else {
292 /* Obviously the acl isn't allowed to delete. Show message and
293 clean session. */
294 print_red (_("You are not allowed to delete this acl!"));
295 }
296 }
299 /********************
300 Delete entry confirmed
301 ********************/
303 /* Confirmation for deletion has been passed. Acl should be deleted. */
304 if (isset($_POST['delete_acl_confirm'])){
306 /* Check permissions */
307 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"acl/acl"))){
309 /* Delete request is permitted, perform LDAP action */
310 $this->acltabs= new acl($this->config, NULL,$this->dn);
311 $this->acltabs->remove_from_parent();
312 unset ($this->acltabs);
313 $this->acltabs= NULL;
314 } else {
316 /* Normally this shouldn't be reached, send some extra
317 logs to notify the administrator */
318 print_red (_("You are not allowed to delete this acl!"));
320 if(isset($this->ui->uid)){
321 @log::log("security","aclroles/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick acl role deletion.");
323 }
324 }
326 /* Remove lock file after successfull deletion */
327 del_lock ($this->dn);
328 }
331 /********************
332 Delete entry Canceled
333 ********************/
335 /* Delete acl canceled? */
336 if (isset($_POST['delete_cancel'])){
337 del_lock ($this->dn);
338 }
341 /********************
342 Edit entry finished (Save)
343 ********************/
345 /* Finish acl edit is triggered by the tabulator dialog, so
346 the acl wants to save edited data. Check and save at this
347 point. */
348 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->acltabs->config))){
350 /* Check tabs, will feed message array */
351 $this->acltabs->save_object();
352 $message= $this->acltabs->check();
354 /* Save, or display error message? */
355 if (count($message) == 0){
357 /* Save acl data to ldap */
358 if($this->acltabs->save() == 1){
359 return;
360 }
362 if (!isset($_POST['edit_apply'])){
364 /* ACl has been saved successfully, remove lock from LDAP. */
365 if ($this->dn != "new"){
366 del_lock ($this->dn);
367 }
369 unset ($this->acltabs);
370 $this->acltabs= NULL;
371 unset ($_SESSION['objectinfo']);
372 }
373 } else {
374 /* Ok. There seem to be errors regarding to the tab data,
375 show message and continue as usual. */
376 show_errors($message);
377 }
378 }
381 /********************
382 Display subdialog
383 ********************/
386 /* Show tab dialog if object is present */
387 if(isset($this->acltabs->config)){
389 /* Save object */
390 $this->acltabs->save_object();
391 $display= $this->acltabs->execute();
393 /* Don't show buttons if tab dialog requests this */
394 if(isset($this->acltabs)){
396 /* Skip displaying save/cancel if there is a sub dialog open */
397 if (!isset($this->acltabs->dialog) || !$this->acltabs->dialog){
398 $display.= "<p style=\"text-align:right\">\n";
399 // $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
400 $display.= " \n";
402 /* Skip Apply if it is a new entry */
403 #if ($this->dn != "new"){
404 # $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
405 # $display.= " \n";
406 #}
408 // $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
409 $display.= "</p>";
410 }
411 }
412 return ($display);
413 }
415 /* Check if there is a snapshot dialog open */
416 $base = $this->DivListACL->selectedBase;
417 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
418 return($str);
419 }
421 /* Return rendered main page */
422 /* Display dialog with system list */
423 $this->DivListACL->parent = $this;
424 $this->DivListACL->execute();
426 /* Add departments if subsearch is disabled */
427 if(!$this->DivListACL->SubSearch){
428 $this->DivListACL->AddDepartments($this->DivListACL->selectedBase,3);
429 }
430 $this->reload();
431 $this->DivListACL->setEntries($this->list);
432 return($this->DivListACL->Draw());
433 }
436 function reload()
437 {
438 /* Get divlist informations from filter part */
439 $Regex = $this->DivListACL -> Regex;
440 $SubSearch = $this->DivListACL -> SubSearch;
441 $base = $this->DivListACL -> selectedBase;
442 $Attrs = array("ou","cn","description","gosaAclEntry","objectClass");
443 $res = array();
444 $tmp = array(); // Will contain temporary results
445 $ldap = $this->config->get_ldap_link();
446 $Filter = "(&(objectClass=gosaACL)(gosaAclEntry=*)(|(cn=".$Regex.")(ou=".$Regex.")))";
447 $FilterRoles= "(&(objectClass=gosaRole)(|(cn=".$Regex.")(ou=".$Regex.")))";
449 /* Fetch following structures, this will be used if !$SubSearch */
450 $fetch_this = array(
451 "ME" => array("TYPE" => "cat" , "FLAGS" => GL_SIZELIMIT ,"BASE"=>""),
452 "SYSTEMS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>"ou=systems,"),
453 "APPS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>"ou=apps,"),
454 "PEOPLE" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_people_ou()),
455 "GROUPS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_groups_ou()));
457 /* Subsearch ? */
458 if($SubSearch){
460 /* Get all object in this base */
461 $Flags = GL_SIZELIMIT | GL_SUBSEARCH;
462 $fetch_base = $base;
463 $tmp = get_list($Filter, "acl", $fetch_base, $Attrs, $Flags);
464 $tmp2 = get_list($FilterRoles, "acl", $fetch_base, $Attrs, $Flags);
465 foreach($tmp as $entry){
466 $res[] = $entry;
467 }
468 foreach($tmp2 as $entry){
469 $res[] = $entry;
470 }
472 }else{
474 $tmp_roles = get_list($FilterRoles, "acl", "ou=aclroles,".$base, $Attrs,GL_SIZELIMIT);
476 foreach($tmp_roles as $entry){
477 $res[] = $entry;
478 }
480 /* Walk through all possible bases */
481 foreach($fetch_this as $type => $data){
483 /* Get requried attributes */
484 $Flags = $data['FLAGS'];
485 $fetch_base = $data['BASE'].$base;
486 $Type = $data['TYPE'];
488 /* Check if method is cat or search */
489 if($Type == "search"){
490 $tmp = get_list($Filter, "acl", $fetch_base, $Attrs, $Flags);
491 foreach($tmp as $entry){
492 $res[] = $entry;
493 }
494 }else{
495 $ldap->cat($fetch_base,$Attrs);
496 $attrs = $ldap->fetch();
497 if($attrs && isset($attrs['gosaAclEntry'])){
498 $re2 = preg_replace("/\*/",".*",$Regex);
500 if(!isset($attrs['ou']) && !isset($attrs['cn'])){
501 $namingAttr= preg_replace("/^[^=]*+=([^,]*),.*$/","\\1",$fetch_base);
502 if(preg_match("/".$re2."/i",$namingAttr)){
503 $res[] = $attrs;
504 }
505 }elseif( (isset($attrs['cn'][0]) && preg_match("/".$re2."/i",$attrs['cn'][0]))
506 ||(isset($attrs['ou'][0]) && preg_match("/".$re2."/i",$attrs['ou'][0]))){
507 $res[] = $attrs;
508 }
509 }
510 }
511 }
512 }
513 $this->list = $res;
514 }
517 /* Perform copy & paste requests
518 If copy&paste is in progress this returns a dialog to fix required attributes
519 */
520 function copyPasteHandling($s_action,$s_entry)
521 {
522 /* Paste copied/cutted object in here
523 */
524 $ui = get_userinfo();
525 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
526 $this->CopyPasteHandler->save_object();
527 $this->CopyPasteHandler->SetVar("base",$this->DivListGroup->selectedBase);
528 if($str = $this->CopyPasteHandler->execute()){
529 return( $str);
530 };
531 /* Ensure that the new object is shown in the list now */
532 $this->reload();
533 }
536 /* Copy current object to CopyHandler
537 */
538 if($s_action == "copy"){
540 $dn = $this->list[trim($s_entry)]['dn'];
541 $acl_all = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
542 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
544 $this->CopyPasteHandler->Clear();
545 $obj = new acl($this->config, NULL, $dn, TRUE);
546 $obj->set_acl_base($dn);
547 $objNew = new acl($this->config, NULL,"new", TRUE);
548 $objNew->set_acl_base($dn);
550 $this->CopyPasteHandler->Copy($obj,$objNew);
551 }else{
552 print_red("You are not allowed to copy this entry.");
553 }
554 }
556 /* Copy current object to CopyHandler
557 */
558 if($s_action == "cut"){
560 $dn = $this->list[trim($s_entry)]['dn'];
561 $acl_all = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
562 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
564 $this->CopyPasteHandler->Clear();
565 $obj= new acl($this->config,NULL, $dn, TRUE);
566 $obj->set_acl_base($dn);
567 $this->CopyPasteHandler->Cut($obj);
568 }else{
569 print_red("You are not allowed to cut this entry.");
570 }
571 }
572 }
575 function remove_lock()
576 {
577 /* Remove acl lock if a DN is marked as "currently edited" */
578 if (isset($this->acltabs->dn)){
579 del_lock ($this->acltabs->dn);
580 }
581 }
584 function save_object()
585 {
586 /* Handle divlist filter && department selection*/
587 if(!is_object($this->acltabs)){
588 $this->DivListACL->save_object();
589 }
590 }
592 /* A set of disabled and therefore overloaded functions. They are
593 not needed in this class. */
594 function remove_from_parent() { }
595 function check() { }
597 function save() {
598 echo "SAVE ACL";
599 }
601 function adapt_from_template($dn) { }
602 function password_change_needed() { }
605 /* Return departments, that will be included within snapshot detection */
606 function get_used_snapshot_bases()
607 {
608 return(array());
609 }
611 }
612 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
613 ?>