Code

3aa053fa5423b764ba31c460c8449d298bcaac60
[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);
66     $filter->setConverter('INCOMING', 'systemManagement::incomingFilterConverter');
67     $this->registerAction("DaemonEvent_halt", "systemManagement::handleEvent");
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   /*! \brief  Edit the selected system type.
199    *
200    *  @param  String  'action'  The name of the action which was the used as trigger.
201    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
202    *  @param  Array   'all'     A combination of both 'action' and 'target'.
203    */
204   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
205   {
206     if(count($target) == 1){
207       $tInfo = $this->getObjectDefinitions();
208       $headpage = $this->getHeadpage();
209       $dn = $target[0];
210       $type = $tInfo[$headpage->getType($dn)];
211       return(management::editEntry($action,$target,$all,$type['tabClass'],$type['tabDesc'],$type['aclCategory']));
212     }
213   }
216   /*! \brief   Overridden render method of class mangement.
217    *            this allows us to add a release selection box.
218    */
219   function renderList()
220   {
221     $headpage = $this->getHeadpage();
222     $headpage->update();
224     $tD = $this->getObjectDefinitions();
225     $smarty = get_smarty();
226     foreach($tD as $name => $obj){
227       $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
228     }
230     $display = $headpage->render();
231     return($this->getHeader().$display);
232   }
235   public function getObjectDefinitions()
236   {
237     $tabs = array(
238         "FAKE_OC_OpsiHost" => array(
239           "ou"          => "",
240           "plugClass"   => "opsiGeneric",
241           "tabClass"    => "opsi_tabs",
242           "tabDesc"     => "OPSITABS",
243           "aclClass"    => "opsiGeneric",
244           "aclCategory" => "opsi"),
246         "goServer" => array(
247           "ou"          => get_ou('serverRDN'),
248           "plugClass"   => "servgeneric",
249           "tabClass"    => "servtabs",
250           "tabDesc"     => "SERVTABS",
251           "aclClass"    => "servgeneric",
252           "aclCategory" => "server"),
254         "gotoWorkstation" => array(
255           "ou"          => get_ou('workstationRDN'),
256           "plugClass"   => "workgeneric",
257           "tabClass"    => "worktabs",
258           "tabDesc"     => "WORKTABS",
259           "aclClass"    => "workstation",
260           "aclCategory" => "workgeneric"),
262         "gotoTerminal" => array(
263             "ou"          => get_ou('terminalRDN'),
264             "plugClass"   => "termgeneric",
265             "tabClass"    => "termtabs",
266             "tabDesc"     => "TERMTABS",
267             "aclClass"    => "terminal",
268             "aclCategory" => "termgeneric"),
270         "gotoPrinter" => array(
271             "ou"          => get_ou('printerRDN'),
272             "plugClass"   => "printgeneric",
273             "tabClass"    => "printtabs",
274             "tabDesc"     => "PRINTTABS",
275             "aclClass"    => "printer",
276             "aclCategory" => "printgeneric"),
278         "FAKE_OC_NewDevice" => array(
279             "ou"          => get_ou('systemIncomingRDN'),
280             "plugClass"   => "termgeneric",
281             "tabClass"    => "termtabs",
282             "tabDesc"     => "TERMTABS",
283             "aclClass"    => "terminal",
284             "aclCategory" => "termgeneric"),
286         "goFonHardware" => array(
287             "ou"          => get_ou('phoneRDN'),
288             "plugClass"   => "phoneGeneric",
289             "tabClass"    => "phonetabs",
290             "tabDesc"     => "PHONETABS",
291             "aclClass"    => "phone",
292             "aclCategory" => "phoneGeneric"),
294         "FAKE_OC_winstation" => array(
295             "ou"          => get_winstations_ou(),
296             "plugClass"   => "wingeneric",
297             "tabClass"    => "wintabs",
298             "tabDesc"     => "WINTABS",
299             "aclClass"    => "wingeneric",
300             "aclCategory" => "winworkstation"),
302         "ieee802Device" => array(
303             "ou"          => get_ou('componentRDN'),
304             "plugClass"   => "componentGeneric",
305             "tabClass"    => "componenttabs",
306             "tabDesc"     => "COMPONENTTABS",
307             "aclClass"    => "componentGeneric",
308             "aclCategory" => "component"),
309         );
311     // Now map some special types
312     $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
313     $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
314     $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
315     $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
316     $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
317     $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
318     $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
319     $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
320     $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
321     $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
322     $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
323     $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
325     $tabs['FAKE_OC_NewUnknownDevice'] = &$tabs['FAKE_OC_NewDevice'];
327     return($tabs);
328   }
329
330 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
331 ?>