Code

Reenabled system deletion
[gosa.git] / gosa-plugins / systems / admin / systems / class_systemManagement.inc
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 systemManagement extends management
24 {
25   var $plHeadline     = "Systems";
26   var $plDescription  = "List of systems";
27   var $plIcon  = "plugins/systems/images/plugin.png";
29   // Tab definition 
30   protected $tabClass = "";
31   protected $tabType = "";
32   protected $aclCategory = "";
33   protected $aclPlugin   = "";
34   protected $objectName   = "";
36   protected $objectInfo = array();
38   protected $opsi = NULL;
40   function __construct($config,$ui)
41   {
42     $this->config = $config;
43     $this->ui = $ui;
45     // Set storage points 
46     $tD = $this->getObjectDefinitions(); 
47     $sP = array();
48     foreach($tD as $entry){
49       if(!empty($entry['ou']))
50         $sP[] = $entry['ou'];
51     }
52     $this->storagePoints = array_unique($sP);
54 #    // Build filter
55 #    if (session::global_is_set(get_class($this)."_filter")){
56 #      $filter= session::global_get(get_class($this)."_filter");
57 #    } else {
58   $filter = new filter(get_template_path("system-filter.xml", true));
59   $filter->setObjectStorage($this->storagePoints);
60 #    }
61   $this->setFilter($filter);
63   // Build headpage
64   $headpage = new listing(get_template_path("system-list.xml", true));
65   $headpage->setFilter($filter);
67   $filter->setConverter('INCOMING', 'systemManagement::incomingFilterConverter');
69   // Add copy&paste and snapshot handler.
70   if ($this->config->boolValueIsTrue("main", "copyPaste")){
71     $this->cpHandler = new CopyPasteHandler($this->config);
72   }
73   if($this->config->get_cfg_value("enableSnapshots") == "true"){
74     $this->snapHandler = new SnapshotHandler($this->config);
75   }
76   parent::__construct($config, $ui, "systems", $headpage);
77   }
80   /*! \brief    Update filter part for INCOMING.
81    *            Allows us to search for "systemIncomingRDN".
82    */
83   static function incomingFilterConverter($filter)
84   {
85     $rdn = preg_replace("/^[^=]*=/", "", get_ou('systemIncomingRDN'));
86     $rdn = preg_replace("/,.*$/","",$rdn);
87     return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
88   }
90  
91   /*! \brief    Queue selected objects to be removed. 
92    *            Checks ACLs, Locks and ask for confirmation.
93    */
94   protected function removeEntryRequested($action="",$target=array(),$all=array())
95   {
96     $disallowed = array();
97     $this->dns = array();
99     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
101     // Check permissons for each target
102     $tInfo = $this->getObjectDefinitions();
103     $headpage = $this->getHeadpage();
104     foreach($target as $dn){
105       $type = $headpage->getType($dn);
106       if(!isset($tInfo[$type])){
107         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
108       }else{
109         $info = $tInfo[$type];
110         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
111         if(preg_match("/d/",$acl)){
112           $this->dns[] = $dn;
113         }else{
114           $disallowed[] = $dn;
115         }
116       }
117     }
118     if(count($disallowed)){
119       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
120     }
122     // We've at least one entry to delete.
123     if(count($this->dns)){
125       // check locks
126       if ($user= get_multiple_locks($this->dns)){
127         return(gen_locked_message($user,$this->dns));
128       }
130       // Add locks
131       $dns_names = array();
132       foreach($this->dns as $dn){
133         $dns_names[] =LDAP::fix($dn);
134       }
135       add_lock ($this->dns, $this->ui->dn);
137       // Display confirmation dialog.
138       $smarty = get_smarty();
139       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
140       $smarty->assign("multiple", true);
141       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
142     }
143   }
146   /*! \brief  Object removal was confirmed, now remove the requested entries.
147    *
148    *  @param  String  'action'  The name of the action which was the used as trigger.
149    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
150    *  @param  Array   'all'     A combination of both 'action' and 'target'.
151    */
152   function removeEntryConfirmed($action="",$target=array(),$all=array(),
153       $altTabClass="",$altTabType="",$altAclCategory="")
154   {
155     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
157     // Check permissons for each target
158     $tInfo = $this->getObjectDefinitions();
159     $headpage = $this->getHeadpage();
160     $disallowed = array();
161     foreach($this->dns as $key => $dn){
162       $type = $headpage->getType($dn);
163       if(!isset($tInfo[$type])){
164         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
165       }else{
167         $info = $tInfo[$type];
168         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
169         if(preg_match("/d/",$acl)){
171           // Delete the object
172           $this->dn = $dn;
173           $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']], 
174               $this->dn, $info['aclCategory'], true, true);
175           $this->tabObject->set_acl_base($this->dn);
176           $this->tabObject->parent = &$this;
177           $this->tabObject->delete ();
179           // Remove the lock for the current object.
180           del_lock($this->dn);
182         }else{
183           $disallowed[] = $dn;
184           new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
185         }
186       }
187     }
188     if(count($disallowed)){
189       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
190     }
192     // Cleanup
193     $this->remove_lock();
194     $this->closeDialogs();
195   }
198   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
199   {
200     if(count($target) == 1){
201       $tInfo = $this->getObjectDefinitions();
202       $headpage = $this->getHeadpage();
203       $dn = $target[0];
204       $type = $tInfo[$headpage->getType($dn)];
205       return(management::editEntry($action,$target,$all,$type['tabClass'],$type['tabDesc'],$type['aclCategory']));
206     }
207   }
211   /*! \brief   Overridden render method of class mangement.
212    *            this allows us to add a release selection box.
213    */
214   function renderList()
215   {
216     $headpage = $this->getHeadpage();
217     $headpage->update();
219     $tD = $this->getObjectDefinitions();
220     $smarty = get_smarty();
221     foreach($tD as $name => $obj){
222       $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
223     }
225     $display = $headpage->render();
226     return($this->getHeader().$display);
227   }
230   public function getObjectDefinitions()
231   {
232     $tabs = array(
233         "FAKE_OC_OpsiHost" => array(
234           "ou"          => "",
235           "plugClass"   => "opsiGeneric",
236           "tabClass"    => "opsi_tabs",
237           "tabDesc"     => "OPSITABS",
238           "aclClass"    => "opsiGeneric",
239           "aclCategory" => "opsi"),
241         "goServer" => array(
242           "ou"          => get_ou('serverRDN'),
243           "plugClass"   => "servgeneric",
244           "tabClass"    => "servtabs",
245           "tabDesc"     => "SERVTABS",
246           "aclClass"    => "servgeneric",
247           "aclCategory" => "server"),
249         "gotoWorkstation" => array(
250           "ou"          => get_ou('workstationRDN'),
251           "plugClass"   => "workgeneric",
252           "tabClass"    => "worktabs",
253           "tabDesc"     => "WORKTABS",
254           "aclClass"    => "workstation",
255           "aclCategory" => "workgeneric"),
257         "gotoTerminal" => array(
258             "ou"          => get_ou('terminalRDN'),
259             "plugClass"   => "termgeneric",
260             "tabClass"    => "termtabs",
261             "tabDesc"     => "TERMTABS",
262             "aclClass"    => "terminal",
263             "aclCategory" => "termgeneric"),
265         "gotoPrinter" => array(
266             "ou"          => get_ou('printerRDN'),
267             "plugClass"   => "printgeneric",
268             "tabClass"    => "printtabs",
269             "tabDesc"     => "PRINTTABS",
270             "aclClass"    => "printer",
271             "aclCategory" => "printgeneric"),
273         "FAKE_OC_NewDevice" => array(
274             "ou"          => get_ou('systemIncomingRDN'),
275             "plugClass"   => "termgeneric",
276             "tabClass"    => "termtabs",
277             "tabDesc"     => "TERMTABS",
278             "aclClass"    => "terminal",
279             "aclCategory" => "termgeneric"),
281         "goFonHardware" => array(
282             "ou"          => get_ou('phoneRDN'),
283             "plugClass"   => "phoneGeneric",
284             "tabClass"    => "phonetabs",
285             "tabDesc"     => "PHONETABS",
286             "aclClass"    => "phone",
287             "aclCategory" => "phoneGeneric"),
289         "FAKE_OC_winstation" => array(
290             "ou"          => get_winstations_ou(),
291             "plugClass"   => "wingeneric",
292             "tabClass"    => "wintabs",
293             "tabDesc"     => "WINTABS",
294             "aclClass"    => "wingeneric",
295             "aclCategory" => "winworkstation"),
297         "ieee802Device" => array(
298             "ou"          => get_ou('componentRDN'),
299             "plugClass"   => "componentGeneric",
300             "tabClass"    => "componenttabs",
301             "tabDesc"     => "COMPONENTTABS",
302             "aclClass"    => "componentGeneric",
303             "aclCategory" => "component"),
304         );
306     // Now map some special types
307     $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
308     $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
309     $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
310     $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
311     $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
312     $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
313     $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
314     $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
315     $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
316     $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
317     $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
318     $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
320     $tabs['FAKE_OC_NewUnknownDevice'] = &$tabs['FAKE_OC_NewDevice'];
322     return($tabs);
323   }
324
325 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
326 ?>