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 class aclManagement extends plugin
22 {
23 /* Plugin definitions */
24 var $plHeadline = "ACLs";
25 var $plDescription = "This does something";
27 /* Dialog attributes */
28 var $acltabs = NULL;
29 var $ui = NULL;
30 var $acl = "";
31 var $DivListACL = NULL;
33 var $CopyPasteHandler;
34 var $start_pasting_copied_objects = FALSE;
36 function aclManagement(&$config, &$ui)
37 {
38 /* Save configuration for internal use */
39 $this->config = &$config;
40 $this->ui = &$ui;
42 /* Copy & Paste enabled ?*/
43 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
44 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
45 }
47 /* Creat dialog object */
48 $this->DivListACL = new divListACL($this->config,$this);
49 }
52 function execute()
53 {
54 /* Call parent execute */
55 plugin::execute();
57 session::set('LOCK_VARS_TO_USE',array("/^list/","/^id_/","/^list_acl_role_del/","/^list_acl_del/"));
59 $smarty = get_smarty(); // Smarty instance
60 $s_action = ""; // Contains the action to be taken
61 $s_entry = ""; // The value for s_action
63 /* Edit entry button pressed? */
64 if( isset($_GET['act']) && $_GET['act'] == "list_edit_entry" ){
65 $s_action= "edit";
66 $s_entry= validate($_GET['id']);
67 }
69 /* Edit entry button pressed? */
70 if( isset($_GET['act']) && $_GET['act'] == "list_edit_role" ){
71 $s_action= "edit_role";
72 $s_entry= validate($_GET['id']);
73 }
75 $types = array(
76 "del" =>"^list_acl_del",
77 "edit" =>"^list_acl_edit",
78 "del_role" =>"^list_acl_role_del",
79 "edit_role" =>"^list_acl_role_edit",
80 "copy" =>"^copy",
81 "cut" =>"^cut",
82 "copy_multiple"=> "^multiple_copy_objects",
83 "cut_multiple" => "^multiple_cut_objects",
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 /* handle C&P from layers menu */
113 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
114 $s_action = "copy_multiple";
115 }
116 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
117 $s_action = "cut_multiple";
118 }
119 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
120 $s_action = "editPaste";
121 }
123 /* Create options */
124 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "new_acl_role"){
125 $s_action = "new";
126 }
128 /* handle remove from layers menu */
129 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
130 $s_action = "del_multiple";
131 }
133 /********************
134 Copy & Paste Handling ...
135 ********************/
137 /* Display the copy & paste dialog, if it is currently open */
138 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
139 if($ret){
140 return($ret);
141 }
144 /********************
145 * Add new Role entry
146 ********************/
148 if(($s_action == "addrole") && (!isset($this->acltabs->config))){
150 /* Get 'dn' from posted acl, must be unique */
151 $this->dn= "new";
153 /* Check permissions */
154 if(preg_match("/c/",$this->ui->get_permissions($this->DivListACL->selectedBase,"acl/acl"))){
156 /* Register acltabs to trigger edit dialog */
157 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
158 $this->acltabs->set_acl_base($this->DivListACL->selectedBase);
159 }else{
160 msg_dialog::display(_("Permission error"), _("You have no permission to create a new role!"), ERROR_DIALOG);
161 }
162 }
164 /********************
165 Edit existing entry
166 ********************/
168 if (($s_action=="edit" || $s_action=="edit_role") && (!isset($this->acltabs->config))){
170 /* Get 'dn' from posted acl, must be unique */
171 $this->dn= $this->list[trim($s_entry)]['dn'];
173 /* Check permissions */
174 if(preg_match("/r/",$this->ui->get_permissions($this->dn,"acl/acl"))){
176 /* Check locking, save current plugin in 'back_plugin', so
177 the dialog knows where to return. */
178 if (($acl= get_lock($this->dn)) != ""){
179 return(gen_locked_message ($acl, $this->dn));
180 }
182 /* Lock the current entry, so everyone will get the above dialog */
183 add_lock ($this->dn, $this->ui->dn);
185 /* Register acltabs to trigger edit dialog */
186 if($s_action=="edit_role"){
187 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
188 $this->acltabs-> set_acl_base($this->dn);
189 }else{
190 $this->acltabs= new acltab($this->config, NULL,$this->dn);
191 $this->acltabs-> set_acl_base($this->dn);
192 }
194 /* Set ACL and move DN to the headline */
195 session::set('objectinfo',$this->dn);
196 }else{
197 msg_dialog::display(_("Permission error"), _("You have no permission to edit this ACL!"), ERROR_DIALOG);
198 }
199 }
202 /********************
203 Edit canceled
204 ********************/
205 if(isset($_POST['delete_lock'])){
206 del_lock ($this->dn);
207 session::un_set('objectinfo');
208 }
210 /* Reset all relevant data, if we get a _cancel request */
211 if (isset($_POST['edit_cancel'])){
212 if (isset($this->acltabs)){
213 del_lock ($this->dn);
214 unset ($this->acltabs);
215 }
216 $this->acltabs= NULL;
217 session::un_set('objectinfo');
218 }
221 /********************
222 Delete entry requested, display confirm dialog
223 ********************/
225 /* Remove acl was requested */
226 if ($s_action=="del_role"){
228 /* Get 'dn' from posted acl */
229 $this->dn= $this->list[trim($s_entry)]['dn'];
231 /* Check permissions */
232 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"aclroles/aclrole"))){
234 /* Check locking, save current plugin in 'back_plugin', so
235 the dialog knows where to return. */
236 if (($acl= get_lock($this->dn)) != ""){
237 return(gen_locked_message ($acl, $this->dn));
238 }
240 /* Lock the current entry, so nobody will edit it during deletion */
241 add_lock ($this->dn, $this->ui->dn);
242 $smarty->assign("info", sprintf(_("You're about to delete the acl %s."), @LDAP::fix($this->dn)));
243 $smarty->assign("is_role",true);
245 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
246 } else {
248 /* Obviously the acl isn't allowed to delete. Show message and
249 clean session. */
250 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
251 }
252 }
255 /********************
256 Delete entry confirmed
257 ********************/
259 /* Confirmation for deletion has been passed. Acl should be deleted. */
260 if (isset($_POST['delete_acl_role_confirmed'])){
262 /* Check permissions */
263 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"aclroles/aclrole"))){
265 /* Delete request is permitted, perform LDAP action */
266 $this->acltabs= new aclroletab($this->config, NULL,$this->dn);
267 $this->acltabs->delete();
268 unset ($this->acltabs);
269 $this->acltabs= NULL;
270 } else {
272 /* Normally this shouldn't be reached, send some extra
273 logs to notify the administrator */
274 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
276 if(isset($this->ui->uid)){
277 new log("security","aclroles/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick acl role deletion.");
278 }
279 }
281 /* Remove lock file after successfull deletion */
282 del_lock ($this->dn);
283 }
285 /********************
286 Delete entry requested, display confirm dialog
287 ********************/
289 /* Remove acl was requested */
290 if ($s_action=="del"){
292 /* Get 'dn' from posted acl */
293 $this->dn= $this->list[trim($s_entry)]['dn'];
295 /* Check permissions */
296 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"acl/acl"))){
297 /* Check locking, save current plugin in 'back_plugin', so
298 the dialog knows where to return. */
299 if (($acl= get_lock($this->dn)) != ""){
300 session::set('LOCK_VARS_TO_USE',array("/^list_acl_edit/","/^list_acl_del/","/^id_/"));
301 return(gen_locked_message ($acl, $this->dn));
302 }
304 /* Lock the current entry, so nobody will edit it during deletion */
305 add_lock ($this->dn, $this->ui->dn);
306 $smarty->assign("info", sprintf(_("You're about to delete the acl %s."), @LDAP::fix($this->dn)));
307 $smarty->assign("is_role",false);
308 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
309 } else {
311 /* Obviously the acl isn't allowed to delete. Show message and
312 clean session. */
313 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
314 }
315 }
318 /********************
319 Delete entry confirmed
320 ********************/
322 /* Confirmation for deletion has been passed. Acl should be deleted. */
323 if (isset($_POST['delete_acl_confirm'])){
325 /* Check permissions */
326 if(preg_match("/d/",$this->ui->get_permissions($this->dn,"acl/acl"))){
328 /* Delete request is permitted, perform LDAP action */
329 $this->acltabs= new acl($this->config, NULL,$this->dn);
330 $this->acltabs->remove_from_parent();
331 unset ($this->acltabs);
332 $this->acltabs= NULL;
333 } else {
335 /* Normally this shouldn't be reached, send some extra
336 logs to notify the administrator */
337 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
339 if(isset($this->ui->uid)){
340 new log("security","aclroles/".get_class($this),$this->dn,array(),"Warning: '".$this->ui->uid."' tried to trick acl role deletion.");
342 }
343 }
345 /* Remove lock file after successfull deletion */
346 del_lock ($this->dn);
347 }
350 /********************
351 Delete entry Canceled
352 ********************/
354 /* Delete acl canceled? */
355 if (isset($_POST['delete_cancel'])){
356 del_lock ($this->dn);
357 }
360 /********************
361 Edit entry finished (Save)
362 ********************/
364 /* Finish acl edit is triggered by the tabulator dialog, so
365 the acl wants to save edited data. Check and save at this
366 point. */
367 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->acltabs->config))){
369 /* Check tabs, will feed message array */
370 $this->acltabs->save_object();
371 $message= $this->acltabs->check();
373 /* Save, or display error message? */
374 if (count($message) == 0){
376 /* Save acl data to ldap */
377 if($this->acltabs->save() == 1){
378 return;
379 }
381 if (!isset($_POST['edit_apply'])){
383 /* ACl has been saved successfully, remove lock from LDAP. */
384 if ($this->dn != "new"){
385 del_lock ($this->dn);
386 }
388 unset ($this->acltabs);
389 $this->acltabs= NULL;
390 session::un_set('objectinfo');
391 }
392 } else {
393 /* Ok. There seem to be errors regarding to the tab data,
394 show message and continue as usual. */
395 show_errors($message);
396 }
397 }
400 /********************
401 Display subdialog
402 ********************/
405 /* Show tab dialog if object is present */
406 if(isset($this->acltabs->config)){
408 /* Save object */
409 $this->acltabs->save_object();
410 $display= $this->acltabs->execute();
412 /* Don't show buttons if tab dialog requests this */
413 if(isset($this->acltabs)){
415 /* Skip displaying save/cancel if there is a sub dialog open */
416 if (!isset($this->acltabs->dialog) || !$this->acltabs->dialog){
417 $display.= "<p style=\"text-align:right\">\n";
418 // $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
419 $display.= " \n";
421 /* Skip Apply if it is a new entry */
422 #if ($this->dn != "new"){
423 # $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
424 # $display.= " \n";
425 #}
427 // $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
428 $display.= "</p>";
429 }
430 }
431 return ($display);
432 }
434 /* Check if there is a snapshot dialog open */
435 $base = $this->DivListACL->selectedBase;
436 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
437 return($str);
438 }
440 /* Return rendered main page */
441 /* Display dialog with system list */
442 $this->DivListACL->parent = $this;
443 $this->DivListACL->execute();
445 /* Add departments if subsearch is disabled */
446 if(!$this->DivListACL->SubSearch){
447 $this->DivListACL->AddDepartments($this->DivListACL->selectedBase,3,1);
448 }
449 $this->reload();
450 $this->DivListACL->setEntries($this->list);
451 return($this->DivListACL->Draw());
452 }
455 function reload()
456 {
457 /* Get divlist informations from filter part */
458 $Regex = $this->DivListACL -> Regex;
459 $SubSearch = $this->DivListACL -> SubSearch;
460 $base = $this->DivListACL -> selectedBase;
461 $Attrs = array("ou","cn","description","gosaAclEntry","objectClass");
462 $res = array();
463 $tmp = array(); // Will contain temporary results
464 $ldap = $this->config->get_ldap_link();
465 $Filter = "(&(objectClass=gosaACL)(gosaAclEntry=*)(|(cn=".$Regex.")(ou=".$Regex.")))";
466 $FilterRoles= "(&(objectClass=gosaRole)(|(cn=".$Regex.")(ou=".$Regex.")))";
468 /* Fetch following structures, this will be used if !$SubSearch */
469 $fetch_this = array(
470 "ME" => array("TYPE" => "cat" , "FLAGS" => GL_SIZELIMIT ,"BASE"=>""),
471 "SYSTEMS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_ou('systemsou')),
472 "APPS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_ou('applicationou')),
473 "PEOPLE" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_people_ou()),
474 "GROUPS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_groups_ou()));
476 /* Subsearch ? */
477 if($SubSearch){
479 /* Get all object in this base */
480 $Flags = GL_SIZELIMIT | GL_SUBSEARCH;
481 $fetch_base = $base;
482 $tmp = get_list($Filter, "acl", $fetch_base, $Attrs, $Flags);
483 $tmp2 = get_list($FilterRoles, "acl", $fetch_base, $Attrs, $Flags);
484 foreach($tmp as $entry){
485 $res[] = $entry;
486 }
487 foreach($tmp2 as $entry){
488 $res[] = $entry;
489 }
491 }else{
493 $tmp_roles = get_list($FilterRoles, "acl", get_ou('aclroleou').$base, $Attrs,GL_SIZELIMIT);
495 foreach($tmp_roles as $entry){
496 $res[] = $entry;
497 }
499 /* Walk through all possible bases */
500 foreach($fetch_this as $type => $data){
502 /* Get requried attributes */
503 $Flags = $data['FLAGS'];
504 $fetch_base = $data['BASE'].$base;
505 $Type = $data['TYPE'];
507 /* Check if method is cat or search */
508 if($Type == "search"){
509 $tmp = get_list($Filter, "acl", $fetch_base, $Attrs, $Flags);
510 foreach($tmp as $entry){
511 $res[$entry['dn']] = $entry;
512 }
513 }else{
514 $ldap->cat($fetch_base,$Attrs);
515 $attrs = $ldap->fetch();
516 if($attrs && isset($attrs['gosaAclEntry'])){
517 $re2 = preg_replace("/\*/",".*",$Regex);
519 if(!isset($attrs['ou']) && !isset($attrs['cn'])){
520 $namingAttr= preg_replace("/^[^=]*+=([^,]*),.*$/","\\1",$fetch_base);
521 if(preg_match("/".$re2."/i",$namingAttr)){
522 $res[$attrs['dn']] = $attrs;
523 }
524 }elseif( (isset($attrs['cn'][0]) && preg_match("/".$re2."/i",$attrs['cn'][0]))
525 ||(isset($attrs['ou'][0]) && preg_match("/".$re2."/i",$attrs['ou'][0]))){
526 $res[$attrs['dn']] = $attrs;
527 }
528 }
529 }
530 }
531 }
532 $this->list = array_values($res);
533 }
536 function copyPasteHandling_from_queue($s_action,$s_entry)
537 {
538 /* Check if Copy & Paste is disabled */
539 if(!is_object($this->CopyPasteHandler)){
540 return("");
541 }
543 /* Add a single entry to queue */
544 if($s_action == "cut" || $s_action == "copy"){
546 /* Cleanup object queue */
547 $this->CopyPasteHandler->cleanup_queue();
548 $dn = $this->list[$s_entry]['dn'];
550 if(isset($this->list[$s_entry]['objectClass']) && in_array("gosaRole",$this->list[$s_entry]['objectClass'])){
551 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"aclroletab","ACLROLETAB","aclroles");
552 }
553 }
555 /* Add entries to queue */
556 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
558 /* Cleanup object queue */
559 $this->CopyPasteHandler->cleanup_queue();
561 /* Add new entries to CP queue */
562 foreach($this->list_get_selected_items() as $id){
563 $dn = $this->list[$id]['dn'];
565 if(isset($this->list[$id]['objectClass']) && in_array("gosaRole",$this->list[$id]['objectClass'])){
567 if($s_action == "copy_multiple"){
568 $this->CopyPasteHandler->add_to_queue($dn,"copy","aclroletab","ACLROLETAB","aclroles");
569 }
570 if($s_action == "cut_multiple"){
571 $this->CopyPasteHandler->add_to_queue($dn,"cut","aclroletab","ACLROLETAB","aclroles");
572 }
573 }
574 }
575 }
577 /* Start pasting entries */
578 if($s_action == "editPaste"){
579 $this->start_pasting_copied_objects = TRUE;
580 }
581 /* Return C&P dialog */
582 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
584 /* Load entry from queue and set base */
585 $this->CopyPasteHandler->load_entry_from_queue();
586 $this->CopyPasteHandler->SetVar("base",$this->DivListACL->selectedBase);
588 /* Get dialog */
589 $data = $this->CopyPasteHandler->execute();
591 /* Return dialog data */
592 if(!empty($data)){
593 return($data);
594 }
595 }
597 /* Automatically disable status for pasting */
598 if(!$this->CopyPasteHandler->entries_queued()){
599 $this->start_pasting_copied_objects = FALSE;
600 }
601 return("");
602 }
605 function list_get_selected_items()
606 {
607 $ids = array();
608 foreach($_POST as $name => $value){
609 if(preg_match("/^item_selected_[0-9]*$/",$name)){
610 $id = preg_replace("/^item_selected_/","",$name);
611 $ids[$id] = $id;
612 }
613 }
614 return($ids);
615 }
618 function remove_lock()
619 {
620 /* Remove acl lock if a DN is marked as "currently edited" */
621 if (isset($this->acltabs->dn)){
622 del_lock ($this->acltabs->dn);
623 }
624 }
627 function save_object()
628 {
629 /* Handle divlist filter && department selection*/
630 if(!is_object($this->acltabs)){
631 $this->DivListACL->save_object();
632 }
633 }
635 /* A set of disabled and therefore overloaded functions. They are
636 not needed in this class. */
637 function remove_from_parent() { }
638 function check() { }
640 function save() {
641 echo "SAVE ACL";
642 }
644 function adapt_from_template($dn) { }
645 function password_change_needed() { }
648 /* Return departments, that will be included within snapshot detection */
649 function get_used_snapshot_bases()
650 {
651 return(array());
652 }
654 }
655 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
656 ?>