Code

Updated css und div framework.
[gosa.git] / plugins / admin / acl / class_aclManagement.inc
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_/");
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     }
110    
111  
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"))){
156       
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"){
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,"acl/acl"))){
214         /* Check locking, save current plugin in 'back_plugin', so
215            the dialog knows where to return. */
216         if (($acl= get_lock($this->dn)) != ""){
217           $_SESSION['LOCK_VARS_TO_USE'] = array("/^list_acl_edit/","/^list_acl_del/","/^id_/");
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         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
225       } else {
227         /* Obviously the acl isn't allowed to delete. Show message and
228            clean session. */
229         print_red (_("You are not allowed to delete this acl!"));
230       }
231     }
234     /********************
235       Delete entry confirmed 
236      ********************/
238     /* Confirmation for deletion has been passed. Acl should be deleted. */
239     if (isset($_POST['delete_acl_confirmed'])){
241       /* Check permissions */
242       if(preg_match("/d/",$this->ui->get_permissions($this->dn,"acl/acl"))){
244         /* Delete request is permitted, perform LDAP action */
245         $this->acltabs= new acl($this->config, NULL,$this->dn);
246         $this->acltabs->delete ();
247         gosa_log ("ACL object '".$this->dn."' has been removed");
248         unset ($this->acltabs);
249         $this->acltabs= NULL;
250       } else {
252         /* Normally this shouldn't be reached, send some extra
253            logs to notify the administrator */
254         print_red (_("You are not allowed to delete this acl!"));
256         if(isset($this->ui->uid)){
257           gosa_log ("Warning: '".$this->ui->uid."' tried to trick acl deletion.");
258         }
259       }
261       /* Remove lock file after successfull deletion */
262       del_lock ($this->dn);
263     }
265     
266     /********************
267       Delete entry Canceled 
268      ********************/
270     /* Delete acl canceled? */
271     if (isset($_POST['delete_cancel'])){
272       del_lock ($this->dn);
273     }
276     /********************
277       Edit entry finished (Save) 
278      ********************/
280     /* Finish acl edit is triggered by the tabulator dialog, so
281        the acl wants to save edited data. Check and save at this
282        point. */
283     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->acltabs->config))){
285       /* Check tabs, will feed message array */
286       $this->acltabs->save_object();
287       $message= $this->acltabs->check();
289       /* Save, or display error message? */
290       if (count($message) == 0){
292         /* Save acl data to ldap */
293         if($this->acltabs->save() == 1){
294           gosa_log ("ACL object '".$this->dn."' saving failed.");
295           return;
296         }
297         gosa_log ("ACL object '".$this->dn."' has been saved");
299         if (!isset($_POST['edit_apply'])){
301           /* ACl has been saved successfully, remove lock from LDAP. */
302           if ($this->dn != "new"){
303             del_lock ($this->dn);
304           }
306           unset ($this->acltabs);
307           $this->acltabs= NULL;
308           unset ($_SESSION['objectinfo']);
309         }
310       } else {
311         /* Ok. There seem to be errors regarding to the tab data,
312            show message and continue as usual. */
313         show_errors($message);
314       }
315     }
318     /********************
319       Display subdialog 
320      ********************/
323     /* Show tab dialog if object is present */
324     if(isset($this->acltabs->config)){
325       
326       /* Save object */
327       $this->acltabs->save_object();
328       $display= $this->acltabs->execute();
330       /* Don't show buttons if tab dialog requests this */
331       if(isset($this->acltabs)){
333         /* Skip displaying save/cancel if there is a sub dialog open */
334         if (!isset($this->acltabs->dialog) || !$this->acltabs->dialog){
335           $display.= "<p style=\"text-align:right\">\n";
336 //          $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
337           $display.= "&nbsp;\n";
339           /* Skip Apply if it is a new entry */
340           #if ($this->dn != "new"){
341           #  $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
342           #  $display.= "&nbsp;\n";
343           #}
345   //        $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
346           $display.= "</p>";
347         }
348       }
349       return ($display);
350     }
351     
352     /* Check if there is a snapshot dialog open */
353     $base = $this->DivListACL->selectedBase;
354     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
355       return($str);
356     }
357   
358     /* Return rendered main page */
359         /* Display dialog with system list */
360     $this->DivListACL->parent = $this;
361     $this->DivListACL->execute();
363     /* Add departments if subsearch is disabled */
364     if(!$this->DivListACL->SubSearch){
365       $this->DivListACL->AddDepartments($this->DivListACL->selectedBase,3);
366     }
367     $this->reload();
368     $this->DivListACL->setEntries($this->list);
369     return($this->DivListACL->Draw());
370   }
373   function reload()
374   {
375     /* Get divlist informations from filter part */
376     $Regex      = $this->DivListACL -> Regex;
377     $SubSearch  = $this->DivListACL -> SubSearch;
378     $base       = $_SESSION['CurrentMainBase']; 
379     $Attrs      = array("ou","cn","description","gosaAclEntry","objectClass");
380     $res        = array();
381     $tmp        = array();                                    // Will contain temporary results 
382     $ldap       = $this->config->get_ldap_link();
383     $Filter     = "(&(objectClass=gosaACL)(gosaAclEntry=*)(|(cn=".$Regex.")(ou=".$Regex.")))";
384     $FilterRoles= "(&(objectClass=gosaRole)(|(cn=".$Regex.")(ou=".$Regex.")))";
386     /* Fetch following structures, this will be used if !$SubSearch */
387     $fetch_this = array(
388       "ME"      => array("TYPE" => "cat"    , "FLAGS" => GL_SIZELIMIT                ,"BASE"=>""),
389       "SYSTEMS" => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>"ou=systems,"),
390       "APPS"    => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>"ou=apps,"),
391       "PEOPLE"  => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_people_ou()),
392       "GROUPS"  => array("TYPE" => "search" , "FLAGS" => GL_SIZELIMIT | GL_SUBSEARCH ,"BASE"=>get_groups_ou()));
394     /* Subsearch ? */
395     if($SubSearch){
397       /* Get all object in this base */
398       $Flags        = GL_SIZELIMIT | GL_SUBSEARCH;
399       $fetch_base   = $base;
400       $tmp  = get_list($Filter,   "acl", $fetch_base, $Attrs, $Flags);
401       $tmp2 = get_list($FilterRoles,  "acl", $fetch_base, $Attrs, $Flags);
402       foreach($tmp as $entry){
403         $res[] = $entry;
404       }
405       foreach($tmp2 as $entry){
406         $res[] = $entry;
407       }
409     }else{
411       $tmp_roles = get_list($FilterRoles,  "acl", "ou=aclroles,".$base, $Attrs,GL_SIZELIMIT);
413       foreach($tmp_roles as $entry){
414         $res[] = $entry;
415       }
417       /* Walk through all possible bases */
418       foreach($fetch_this as $type => $data){
420         /* Get requried attributes */
421         $Flags        = $data['FLAGS'];
422         $fetch_base   = $data['BASE'].$base;
423         $Type         = $data['TYPE'];
425         /* Check if method is cat or search */
426         if($Type == "search"){
427           $tmp = get_list($Filter, "acl", $fetch_base, $Attrs, $Flags);
428           foreach($tmp as $entry){
429             $res[] = $entry;
430           }
431         }else{
432           $ldap->cat($fetch_base,$Attrs);
433           if($ldap->count())          {
434             $attrs = $ldap->fetch();
435             $re2 = preg_replace("/\*/",".*",$Regex);
436             if( (isset($attrs['cn'][0]) && preg_match("/".$re2."/i",$attrs['cn'][0]))
437                |(isset($attrs['ou'][0]) && preg_match("/".$re2."/i",$attrs['ou'][0]))){
439               $res[] = $attrs;
440             }
441           }
442         }
443       }
444     }
445     $this->list = $res;
446   }
449   /* Perform copy & paste requests
450      If copy&paste is in progress this returns a dialog to fix required attributes
451    */
452   function copyPasteHandling($s_action,$s_entry)
453   {
454     /* Paste copied/cutted object in here
455      */
456     $ui = get_userinfo();
457     if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
458       $this->CopyPasteHandler->save_object();
459       $this->CopyPasteHandler->SetVar("base",$this->DivListGroup->selectedBase);
460       if($str = $this->CopyPasteHandler->execute()){
461         return( $str);
462       };
463       /* Ensure that the new object is shown in the list now */
464       $this->reload();
465     }
468     /* Copy current object to CopyHandler
469      */
470     if($s_action == "copy"){
472       $dn  = $this->list[trim($s_entry)]['dn'];
473       $acl_all  = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
474       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
476         $this->CopyPasteHandler->Clear();
477         $obj    = new acl($this->config, NULL, $dn, TRUE);
478         $obj->set_acl_base($dn);
479         $objNew = new acl($this->config, NULL,"new", TRUE);
480         $objNew->set_acl_base($dn);
482         $this->CopyPasteHandler->Copy($obj,$objNew);
483       }else{
484         print_red("You are not allowed to copy this entry.");
485       }
486     }
488     /* Copy current object to CopyHandler
489      */
490     if($s_action == "cut"){
492       $dn = $this->list[trim($s_entry)]['dn'];
493       $acl_all  = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
494       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
496         $this->CopyPasteHandler->Clear();
497         $obj= new acl($this->config,NULL, $dn, TRUE);
498         $obj->set_acl_base($dn);
499         $this->CopyPasteHandler->Cut($obj);
500       }else{
501         print_red("You are not allowed to cut this entry.");
502       }
503     }
504   }
507   function remove_lock()
508   {
509     /* Remove acl lock if a DN is marked as "currently edited" */
510     if (isset($this->acltabs->dn)){
511       del_lock ($this->acltabs->dn);
512     }
513   }
516   function save_object()
517   {
518     /* Handle divlist filter && department selection*/
519     if(!is_object($this->acltabs)){
520       $this->DivListACL->save_object();
521     }
522   }
524   /* A set of disabled and therefore overloaded functions. They are
525      not needed in this class. */
526   function remove_from_parent() { } 
527   function check() { } 
529   function save() {
530     echo "SAVE ACL";
531   } 
533   function adapt_from_template($dn) { } 
534   function password_change_needed() { } 
537   /* Return departments, that will be included within snapshot detection */
538   function get_used_snapshot_bases()
539   {
540     return(array());
541   }  
543
544 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
545 ?>