Code

updated templates
[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  */
24 #
25 # NewDevices 
26 # -> Edit
27 #     |- SelectDeviceType()        (Allows to select target SystemType and OGroup)
28 # -> Save
29 #     |-> systemTypeChosen()       (Queue entry to be activated) 
30 #     |-> handleActivationQueue()  (Now acticvate queued objects)
31 #       |-> Ogroup selected   
32 #       | |-> Try to adapt values from ogroup and save directly.
33 #       |
34 #       |-> NO Ogroup selected
35 #       |  |-> Open dialogs of the target system type and allow modifcations.
36 #       |
37 #       |->activate_new_device()   (Finally activate the device - FAIsate=..)
38 #
39 #
40 # NewArpDevices (NewUnknwonDevices )
41 # -> Edit
42 #     |-> editEntry - ArpNewDeviceTabs
43 # -> Save       
44 #     |-> NO gotoIntegeration 
45 #     | |-> Save DHCP and DNS entries, then remove the source entry from ldap.
46 #     |
47 #     |-> gotoIntegration selected (Handle object like a NewDevice now)
48 #     |-> systemTypeChosen()       (Queue entry to be activated)
49 #     |-> handleActivationQueue()  (Now acticvate queued objects)
50 #       |-> Ogroup selected
51 #       | |-> Try to adapt values from ogroup and save directly.
52 #       |
53 #       |-> NO Ogroup selected
54 #       |  |-> Open dialogs of the target system type and allow modifcations.
55 #       |
56 #       |->activate_new_device()   (Finally activate the device - FAIsate=..)
57 #
58 class systemManagement extends management
59 {
60   var $plHeadline     = "Systems";
61   var $plDescription  = "Systems";
62   var $plIcon  = "plugins/systems/images/plugin.png";
64   // Tab definition 
65   protected $tabClass = "";
66   protected $tabType = "";
67   protected $aclCategory = "";
68   protected $aclPlugin   = "";
69   protected $objectName   = "system";
70   protected $objectInfo = array();
71   protected $opsi = NULL;
72   protected $activationQueue  = array();
74   function __construct($config,$ui)
75   {
76     $this->config = $config;
77     $this->ui = $ui;
79     // Set storage points 
80     $tD = $this->getObjectDefinitions(); 
81     $sP = array();
82     foreach($tD as $entry){
83       if(!empty($entry['ou']))
84         $sP[] = $entry['ou'];
85     }
86     $this->storagePoints = array_unique($sP);
88     // Build filter
89     if (session::global_is_set(get_class($this)."_filter")){
90       $filter= session::global_get(get_class($this)."_filter");
91     } else {
92       $filter = new filter(get_template_path("system-filter.xml", true));
93       $filter->setObjectStorage($this->storagePoints);
94     }
95     $this->setFilter($filter);
97     // Build headpage
98     $headpage = new listing(get_template_path("system-list.xml", true));
99     $headpage->registerElementFilter("systemRelease", "systemManagement::systemRelease");
100     $headpage->setFilter($filter);
101     $filter->setConverter('systemManagement::incomingFilterConverter');
103     // Register Daemon Events
104     if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
105       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
106       foreach($events['TRIGGERED'] as $name => $data){
107         $this->registerAction("T_".$name,"handleEvent");
108         $this->registerAction("S_".$name,"handleEvent");
109       }
110       $this->registerAction("activateMultiple","activateMultiple");
111     }
112     $this->registerAction("saveEvent","saveEventDialog");
113     $this->registerAction("createISO","createISO");
114     $this->registerAction("initiateISOcreation","initiateISOcreation");
115     $this->registerAction("performIsoCreation","performIsoCreation");
116     $this->registerAction("systemTypeChosen","systemTypeChosen");
117     $this->registerAction("handleActivationQueue","handleActivationQueue");
119     $this->registerAction("new_goServer",         "newEntry");
120     $this->registerAction("new_gotoWorkstation",  "newEntry");
121     $this->registerAction("new_gotoTerminal",     "newEntry");
122     $this->registerAction("new_gotoPrinter",      "newEntry");
123     $this->registerAction("new_goFonHardware",    "newEntry");
124     $this->registerAction("new_ieee802Device",    "newEntry");
125     $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry");
127     $this->registerAction("setPassword", "setPassword");
128     $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed");
130     // Add copy&paste and snapshot handler.
131     if ($this->config->boolValueIsTrue("main", "copyPaste")){
132       $this->cpHandler = new CopyPasteHandler($this->config);
133     }
134     if($this->config->get_cfg_value("enableSnapshots") == "true"){
135       $this->snapHandler = new SnapshotHandler($this->config);
136     }
138     // Check if we are able to communicate with the GOsa supprot daemon
139     if(class_available("gosaSupportDaemon")){
140       $o = new gosaSupportDaemon();
141       $this->si_active = $o->connect() && class_available("DaemonEvent");
142     }
144     // Check if we are able to communicate with the GOsa supprot daemon
145     if(class_available("opsi")){
146       $this->opsi = new opsi($this->config);
147     }
148     parent::__construct($config, $ui, "systems", $headpage);
149   }
152   /*! \brief  Act on password change requests.
153    */
154   function setPassword($action,$target)
155   {
156     if(count($target) == 1){
157       $tDefs= $this->getObjectDefinitions();
158       $headpage = $this->getHeadpage();
159       $dn = array_pop($target);
160       $type = $headpage->getType($dn);
161       $entry = $headpage->getEntry($dn);
162       $ui       = get_userinfo();
163       $smarty = get_smarty();
164       if(in_array("FAKE_OC_PWD_changeAble", $entry['objectClass'])){
165         $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
166         $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
167         if(preg_match("/w/",$tabacl)){
168           $this->dn= $dn;
169           set_object_info($this->dn);
170           return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
171         }else{
172           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
173         }
174       }
175     }
176   }
179   /*! \brief  This method is used to queue and process copy&paste actions.
180    *          Allows to copy, cut and paste mutliple entries at once.
181    *  @param  String  'action'  The name of the action which was the used as trigger.
182    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
183    *  @param  Array   'all'     A combination of both 'action' and 'target'.
184    */
185   function copyPasteHandler($action="",$target=array(),$all=array(),
186       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
187   {
188     // Return without any actions while copy&paste handler is disabled.
189     if(!is_object($this->cpHandler))  return("");
191     // Save user input
192     $this->cpHandler->save_object();
194     // Add entries to queue
195     if($action == "copy" || $action == "cut"){
197       $tDefs= $this->getObjectDefinitions();
198       $headpage = $this->getHeadpage();
199       $ui       = get_userinfo();
200       $this->cpHandler->cleanup_queue();
201       foreach($target as $dn){
203         $type = $headpage->getType($dn);
204         $entry = $headpage->getEntry($dn);
205   
206         $aclCategory = $tDefs[$type]['aclCategory'];
207         $aclPlugin = $tDefs[$type]['aclClass'];
208         $tabClass = $tDefs[$type]['tabClass'];
209         $tabType = $tDefs[$type]['tabDesc'];
211         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
212           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
213           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
214         }
215         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
216           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
217           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
218         }
219       }
220     }
222     // Initiate pasting
223     if($action == "paste"){
224       $this->cpPastingStarted = TRUE;
225     }
227     // Display any c&p dialogs, eg. object modifications required before pasting.
228     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
229       $headpage = $this->getHeadpage();
230       $this->cpHandler->SetVar("base",$headpage->getBase());
231       $data = $this->cpHandler->execute();
232       if(!empty($data)){
233         return($data);
234       }
235     }
237     // Automatically disable pasting process since there is no entry left to paste.
238     if(!$this->cpHandler->entries_queued()){
239       $this->cpPastingStarted = FALSE;
240     }
241     return("");
242   }
245   /*! \brief  Password change confirmed, now try to change the systems pwd.
246    */
247   function passwordChangeConfirmed()
248   {
249     $tDefs= $this->getObjectDefinitions();
250     $headpage = $this->getHeadpage();
251     $type = $headpage->getType($this->dn);
252     $entry = $headpage->getEntry($this->dn);
253     $ui       = get_userinfo();
254     $smarty = get_smarty();
256     if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){
257       trigger_error("Tried to change pwd, for invalid object!");
258     }elseif ($_POST['new_password'] != $_POST['repeated_password']){
259       msg_dialog::display(_("Error"), 
260           _("The passwords you've entered as 'New password' and 'Repeated password' do not   match!"), ERROR_DIALOG);
261       return($smarty->fetch(get_template_path('password.tpl', TRUE)));
262     }else{
263       $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
264       $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
266       // Check acls
267       if(!preg_match("/w/",$tabacl)){
268         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
269       }else{
270         $ldap = $this->config->get_ldap_link();
271         $ldap->cd($this->dn);
272         $ldap->cat($this->dn);
273         $old_attrs = $ldap->fetch();
275         $attrs= array();
276         if ($_POST['new_password'] == ""){
278           /* Remove password attribute
279            */
280           if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
281             $attrs['objectClass'] = array();
282             for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
283               if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
284                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
285               }
286             }
287           }
288           $attrs['userPassword']= array();
289         } else {
291           /* Add/modify password attribute
292            */
293           if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
294             $attrs['objectClass'] = array();
295             for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
296               $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
297             }
298             $attrs['objectClass'][] = "simpleSecurityObject";
299           }
301           if(class_available("passwordMethodCrypt")){
302             $pwd_m = new passwordMethodCrypt($this->config);
303             $pwd_m->set_hash("crypt/md5");
304             $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
305           }else{
306             msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
307             $attrs = array();
308           }
309         }
310         $ldap->modify($attrs);
311         if (!$ldap->success()){
312           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
313         }else{
314           if(class_available($tDefs[$type]['plugClass'])){
315             $plug = $tDefs[$type]['plugClass'];
316             $p = new $plug($this->config,$this->dn);
317             $p->handle_post_events("modify");
318           }
319         }
320         new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
321       }
322       set_object_info();
323     }
324   }
327   /*! \brief  The method gets called when somebody clicked the CD icon 
328    *           in the system listing. 
329    *          A confirmation will be shown to acknowledge the creation.
330    */
331   function createISO($action,$target)
332   {
333     if(count($target) == 1){
334       $smarty = get_smarty();
335       $this->dn= array_pop($target);
336       set_object_info($this->dn);
337       return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE)));
339     }
340   }
341  
343   /*! \brief  Once the user has confirmed the ISO creation in 'createISO',
344    *           this method gets called. 
345    *          An iFrame is shown which then used 'performIsoCreation' as contents. 
346    */
347   function initiateISOcreation()
348   {
349     $smarty = get_smarty();
350     $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
351     return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE)));  
352   }
355   /*! \brief  ISO creation confirmed and iFrame is visible, now create the ISO 
356    *           and display the status to fill the iFrame.
357    */
358   function performIsoCreation()
359   {
360     $return_button   = "<form method='get' action='main.php' target='_parent'>
361       <input type='submit' value='"._("Back")."'>
362       <input type='hidden' name='plug' value='".$_GET['plug']."'/>
363       </form>";
365     $dsc   = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
367     /* Get and check command */
368     $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
369     if (check_command($command)){
370       @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
372       /* Print out html introduction */
373       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
374         <html>
375         <head>
376         <title></title>
377         <style type="text/css">@import url("themes/default/style.css");</style>
378         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
379         </head>
380         <body style="background: none; margin:4px;" id="body" >
381         <pre>';
383       /* Open process handle and check if it is a valid process */
384       $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
385       if (is_resource($process)) {
386         fclose($pipes[0]);
388         /* Print out returned lines && write JS to scroll down each line */
389         while (!feof($pipes[1])){
390           $cur_dat = fgets($pipes[1], 1024);
391           echo $cur_dat;
392           echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
393           flush();
394         }
395       }
397       /* Get error string && close streams */
398       $buffer= stream_get_contents($pipes[2]);
400       fclose($pipes[1]);
401       fclose($pipes[2]);
402       echo "</pre>";
404       /* Check return code */
405       $ret= proc_close($process);
406       if ($ret != 0){
407         echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
408         echo "<pre style='color:red'>$buffer</pre>";
409       }
410       echo $return_button."<br>";
411     } else {
412       $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
413       echo $tmp;
414       echo $return_button."<br>";
415     }
417     /* Scroll down completly */
418     echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
419     echo '</body></html>';
420     flush();
421     exit;
422   }
425   /*! \brief    Handle GOsa-si events
426    *            All schedules and triggered events are handled here.
427    */
428   function handleEvent($action="",$target=array(),$all=array())
429   {
430     // Detect whether this event is scheduled or triggered.
431     $triggered = TRUE;
432     if(preg_match("/^S_/",$action)){
433       $triggered = FALSE;
434     }
436     // Detect triggere or scheduled actions 
437     $headpage = $this->getHeadpage();
438     $event = preg_replace("/^[TS]_/","",$action); 
439     if(preg_match("/^[TS]_/", $action)){
441       // Send special reinstall action for opsi hosts
442       if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){
443         foreach($target as $key => $dn){
444           $type = $headpage->getType($dn);
446           // Send Reinstall event for opsi hosts
447           if($type == "FAKE_OC_OpsiHost"){
448             $obj = $headpage->getEntry($dn);
449             $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
450             unset($target[$key]);
451           }
452         }
453       }
454     } 
456     // Now send remaining FAI/GOsa-si events here.
457     if(count($target) && $this->si_active){
458       $mac= array();
460       // Collect target mac addresses
461       $ldap = $this->config->get_ldap_link();
462       $tD = $this->getObjectDefinitions();
463       $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
464       $o_queue = new gosaSupportDaemon();
465       foreach($target as $dn){
466         $type = $headpage->getType($dn);
467         if($tD[$type]['sendEvents']){
468           $obj = $headpage->getEntry($dn);
469           if(isset($obj['macAddress'][0])){
470             $mac[] = $obj['macAddress'][0];
471           }
472         }
473       }
475       /* Skip installation or update trigerred events,
476        *  if this entry is currently processing.
477        */
478       if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){
479         foreach($mac as $key => $mac_address){
480           foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
481             $entry['STATUS'] = strtoupper($entry['STATUS']);
482             if($entry['STATUS'] == "PROCESSING" &&
483                 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
484                 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
485               unset($mac[$key]);
487               new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
488               break;
489             }
490           }
491         }
492       }
494       // Prepare event to be added
495       if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){
496         $event = $events['BY_CLASS'][$event];
497         $this->dialogObject = new $event['CLASS_NAME']($this->config);
498         $this->dialogObject->add_targets($mac);
500         if($triggered){
501           $this->dialogObject->set_type(TRIGGERED_EVENT);
502           $o_queue->append($this->dialogObject);
503           if($o_queue->is_error()){
504             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
505           }else{
506             $this->closeDialogs();
507           }
508         }else{
509           $this->dialogObject->set_type(SCHEDULED_EVENT);
510         }
511       }
512     }
513   }
516   /*! \brief  Close all dialogs and reset the activationQueue.
517    */ 
518   function cancelEdit()
519   {
520     management::cancelEdit();
521     $this->activationQueue = array();
522   }
523   
524  
525   /*! \brief  Save event dialogs. 
526    *          And append the new GOsa-si event.
527    */ 
528   function saveEventDialog()
529   {
530     $o_queue = new gosaSupportDaemon();
531     $o_queue->append($this->dialogObject);
532     if($o_queue->is_error()){
533       msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
534     }else{
535       $this->closeDialogs();
536     }
537   }
538  
540   /*! \brief    Update filter part for INCOMING.
541    *            Allows us to search for "systemIncomingRDN".
542    */
543   static function incomingFilterConverter($filter)
544   {
545     $rdn = preg_replace("/^[^=]*=/", "", get_ou('systemIncomingRDN'));
546     $rdn = preg_replace("/,.*$/","",$rdn);
547     return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
548   }
550  
551   /*! \brief    Queue selected objects to be removed. 
552    *            Checks ACLs, Locks and ask for confirmation.
553    */
554   protected function removeEntryRequested($action="",$target=array(),$all=array())
555   {
556     // Close dialogs and remove locks for currently handled dns
557     $this->cancelEdit();
559     $disallowed = array();
560     $this->dns = array();
562     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
564     // Check permissons for each target
565     $tInfo = $this->getObjectDefinitions();
566     $headpage = $this->getHeadpage();
567     foreach($target as $dn){
568       $type = $headpage->getType($dn);
569       if(!isset($tInfo[$type])){
570         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
571       }else{
572         $info = $tInfo[$type];
573         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
574         if(preg_match("/d/",$acl)){
575           $this->dns[] = $dn;
576         }else{
577           $disallowed[] = $dn;
578         }
579       }
580     }
581     if(count($disallowed)){
582       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
583     }
585     // We've at least one entry to delete.
586     if(count($this->dns)){
588       // check locks
589       if ($user= get_multiple_locks($this->dns)){
590         return(gen_locked_message($user,$this->dns));
591       }
593       // Add locks
594       $dns_names = array();
595       $types = array();
596       $h = $this->getHeadpage();
598       // Build list of object -labels
599       foreach($h->objectTypes as $type){
600         $map[$type['objectClass']]= $type['label'];
601       }
603       foreach($this->dns as $dn){
604         $tmp = $h->getType($dn);
605         if(isset($map[$tmp])){
606           $dns_names[] = '('._($map[$tmp]).')&nbsp;-&nbsp;'.LDAP::fix($dn);
607         }else{
608           $dns_names[] =LDAP::fix($dn);
609         }
610       }
611       add_lock ($this->dns, $this->ui->dn);
613       // Display confirmation dialog.
614       $smarty = get_smarty();
615       $smarty->assign("info", msgPool::deleteInfo($dns_names));
616       return($smarty->fetch(get_template_path('removeEntries.tpl')));
617     }
618   }
621   /*! \brief  Object removal was confirmed, now remove the requested entries.
622    *
623    *  @param  String  'action'  The name of the action which was the used as trigger.
624    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
625    *  @param  Array   'all'     A combination of both 'action' and 'target'.
626    */
627   function removeEntryConfirmed($action="",$target=array(),$all=array(),
628       $altTabClass="",$altTabType="",$altAclCategory="")
629   {
630     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
632     // Check permissons for each target
633     $tInfo = $this->getObjectDefinitions();
634     $headpage = $this->getHeadpage();
635     $disallowed = array();
636     foreach($this->dns as $key => $dn){
637       $type = $headpage->getType($dn);
638       if(!isset($tInfo[$type])){
639         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
640       }else{
642         $info = $tInfo[$type];
643         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
644         if(preg_match("/d/",$acl)){
646           // Delete the object
647           $this->dn = $dn;
648           if($info['tabClass'] == "phonetabs"){
649              $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
650              $this->tabObject->set_acl_base($dn);
651              $this->tabObject->by_object['phoneGeneric']->remove_from_parent ();
652           }else{
653             $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']], 
654                 $this->dn, $info['aclCategory'], true, true);
655             $this->tabObject->set_acl_base($this->dn);
656             $this->tabObject->parent = &$this;
657             $this->tabObject->delete ();
658           }
660           // Remove the lock for the current object.
661           del_lock($this->dn);
663         }else{
664           $disallowed[] = $dn;
665           new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion.");
666         }
667       }
668     }
669     if(count($disallowed)){
670       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
671     }
673     // Cleanup
674     $this->remove_lock();
675     $this->closeDialogs();
676   }
679   /*! \brief  Edit the selected system type.
680    *          NewDevice and ArpNewDevice are handled here separately 
681    */
682   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
683   {
684     if(count($target) == 1){
685       $tInfo = $this->getObjectDefinitions();
686       $headpage = $this->getHeadpage();
687       $dn = $target[0];
688       $type =$headpage->getType($dn);
689       $tData = $tInfo[$type];
691       if($type == "FAKE_OC_ArpNewDevice"){
692         if(!class_available("ArpNewDeviceTabs")){
693           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
694         }else{
695           return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
696         }
697       }elseif($type == "FAKE_OC_NewDevice"){
698         if(!class_available("SelectDeviceType")){
699           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
700         }else{
701           $this->activationQueue[$dn] = array();
702           $this->dialogObject = new SelectDeviceType($this->config,$dn);
703           $this->dialogObject->set_acl_category("incoming");
704           $this->skipFooter = TRUE;
705           $this->displayApplyBtn = FALSE;
706           // see condition  -$s_action == "::systemTypeChosen"-  for further handling
707         }
708       }else{
709          return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
710       }
711     }
712   }
715   /*! \brief  Edit the selected system type.
716    *
717    *  @param  String  'action'  The name of the action which was the used as trigger.
718    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
719    *  @param  Array   'all'     A combination of both 'action' and 'target'.
720    */
721   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
722   {
723     $tInfo = $this->getObjectDefinitions();
724     $info = preg_replace("/^new_/","",$action);
725     if(!isset($tInfo[$info])){
726       trigger_error("Unknown action type '".$action."' cant create a new system!");
727     }else{
728       return(management::newEntry($action,$target,$all, 
729           $tInfo[$info]['tabClass'],
730           $tInfo[$info]['tabDesc'],
731           $tInfo[$info]['aclCategory']));
732     }
733   }
736   /*! \brief  Activates all selcted 'NewDevices' at once.
737    *          Enqueues the selected Devices in the activation queue.
738    */
739   function activateMultiple($action,$target)
740   {
741     $headpage = $this->getHeadpage();
742     foreach($target as $dn) {
743       if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
744         $this->activationQueue[$dn] = array();
745       }
746     }
747     if(count($this->activationQueue)){
748       $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
749       $this->skipFooter = TRUE;
750     }
751   }
754   /*! \brief  The system selection dialog was closed. 
755    *          We will now queue the given entry to be activated.
756    */ 
757   function systemTypeChosen()
758   {
759     // Detect the systems target type 
760     $tInfo = $this->getObjectDefinitions();
761     $selected_group = "none";
762     if(isset($_POST['ObjectGroup'])){
763       $selected_group = $_POST['ObjectGroup'];
764     }
765     $selected_system = $_POST['SystemType'];
766     $tmp = array();
767     foreach($this->activationQueue as $dn => $data){
768       $tmp[$dn]['OG'] = $selected_group;
769       $tmp[$dn]['SS'] = $selected_system;
770     }
771     $this->closeDialogs();
772     $this->activationQueue = $tmp;
773     return($this->handleActivationQueue());
774   }
777   /*! \brief  Activate queued goto systems.
778    */
779   function handleActivationQueue()
780   {
781     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
782         'Entries left: '.count($this->activationQueue), "<b>Handling system activation queue!</b>");
784     if(!count($this->activationQueue)) return("");
786     $ldap     = $this->config->get_ldap_link();
787     $pInfo    = $this->getObjectDefinitions(); 
788     $ui       = get_userinfo();
789     $headpage = $this->getHeadpage();
790     $ldap->cd($this->config->current['BASE']);
792     // Walk through systems to activate
793     while(count($this->activationQueue)){
794  
795       // Get next entry 
796       reset($this->activationQueue);
797       $dn = key($this->activationQueue);
798       $data= $this->activationQueue[$dn];
800       // Validate the given system type.
801       if(!isset($data['SS'])) continue;
802       $sysType = $data['SS'];
803       if(!isset($pInfo[$sysType])){
804         trigger_error('Unknown type \''.$sysType.'\'!');
805         continue;
806       }
807       $type = $pInfo[$sysType];
809       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
810           $dn, "<b>Try to activate:</b>");
812       // Get target type definition 
813       $plugClass    = $type["plugClass"];
814       $tabClass     = $type["tabClass"];
815       $aclCategory  = $type["aclCategory"];
816       $tabDesc      = $type["tabDesc"];
818       if(!class_available($tabClass)){
819         msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
820         unset($this->activationQueue[$dn]);
821         continue;
822       }else{
824         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
825             $sysType, "<b>System type:</b>");
827         // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' 
828         $this->dn = $dn;
829         $acls   = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
831         // Check permissions
832         if(!preg_match("/c/",$acls)){
833           unset($this->activationQueue[$dn]);
834           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
836           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
837               $acls, "<b>Insufficient permissions!</b>");
838           continue;
839         }else{
841           // Open object an preset some values like the objects base 
842           del_lock($dn);
843           management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
844           $this->displayApplyBtn = FALSE;
845           $this->tabObject->set_acl_base($headpage->getBase());
847           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
848               $data['OG'], "<b>Selected ogroup:</b>");
850           if($data['OG'] != "none"){
851             $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou('ogroupRDN'), '/')."/i", "", $data['OG']);
852             $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base);
853           } else {
854             $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase());
855             $this->tabObject->base = $headpage->getBase();
856           }
858           // Assign some default values for opsi hosts
859           if($this->tabObject instanceOf opsi_tabs){
860             $ldap = $this->config->get_ldap_link();
861             $ldap->cat($dn);
862             $source_attrs = $ldap->fetch();
863             foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
864               if(isset($source_attrs[$src][0])){
865                 $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
866               }
867             }
868             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
869                 "", "<b>OPSI attributes adapted</b>");
870           }
872           // Queue entry to be activated, when it is saved.
873           if($data['OG'] != "none"){
875             // Set gotoMode to active if there was an ogroup selected.
876             $found = false;
877             foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
878               if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
879                 $found = true;
880                 $this->tabObject->by_object[$tab]->gotoMode = $value;
881                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
882                     $tab."->gotoMode = {$value}", "<b>Setting gotoMode to: </b>");
883               }
884             }
885             if(!$found){
886               msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
887             }
889             // Update object group membership
890             $og = new ogroup($this->config,$data['OG']);
891             if($og){
892               $og->AddDelMembership($this->tabObject->dn);
893               $og->save();
894               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
895                   $og->dn, "<b>Adding system to ogroup</b>");
896             }
898             // Set default system specific attributes
899             foreach (array("workgeneric", "termgeneric") as $cls){
900               if (isset($this->tabObject->by_object[$cls])){
901                 $this->tabObject->by_object[$cls]->set_everything_to_inherited();
902                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
903                     $og->dn, "<b>Calling {$cls}->set_everything_to_inherited()</b>");
904               }
905             }
907             // Enable activation
908             foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
909               if (isset($this->tabObject->by_object[$cls])){
910                 $this->tabObject->by_object[$cls]->auto_activate= TRUE;
911                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
912                     $cls, "<b>Setting auto_activate=TRUE for</b>");
913               }
914             }
916             // Enable sending of LDAP events
917             if (isset($this->tabObject->by_object["workstartup"])){
918               $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
919               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
920                   "", "<b>Setting workstartup->gotoLdap_inherit=TRUE</b>");
921             }
922           }
924           // Try to inherit everythin from the selected object group and then save
925           //  the entry, normally this should work without any problems. 
926           // But if there is any, then display the dialogs.
927           if($data['OG'] != "none"){
928             $str = $this->saveChanges();
930             // There was a problem, skip activation here and allow to fix the problems..
931             if(is_object($this->tabObject)){
932               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
933                   "", "<b>Automatic saving failed, let the user fix the issues now.</b>");
934               return;
935             }
936             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
937                 "", "<b>System activated!</b>");
938           }else{
939             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
940                 "", "<b>Open dialogs now</b>");
941             return;
942           }
943         }
944       }
945     }
946   }
949   /*! \brief  Save object modifications here and any dialogs too.
950    *          After a successfull update of the object data, close
951    *           the dialogs.
952    */
953   protected function saveChanges()
954   {
955     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
956         get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Save</b>");
957  
958     // Handle 'New Unknown Devices' here.
959     if($this->tabObject instanceOf ArpNewDeviceTabs){
960       $this->tabObject->save_object();
962       if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){
963         $message = $this->tabObject->check();
964         if(count($message)){
965           msg_dialog::displayChecks($message);
966         }else{
967           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
968               get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Queued for goto activation</b>");
969           $this->tabObject->save();
970           $this->activationQueue[$this->tabObject->dn]=array();
971           $this->closeDialogs();
972           $this->systemTypeChosen();
973         }
974         return;
975       }
976     }
978     // Try to save changes here.
979     $str = management::saveChanges();
980     if($this->tabObject) return("");
982     // Activate system if required..
983     if(isset($this->activationQueue[$this->last_dn])){
984       $dn = $this->last_tabObject->dn;
985       $this->activate_new_device($dn);
986       unset($this->activationQueue[$this->last_dn]);
987     }
989     /* Post handling for activated systems
990        target opsi -> Remove source.
991        target gosa -> Activate system.
992      */
993     if($this->last_tabObject instanceOf opsi_tabs){
994       $ldap = $this->config->get_ldap_link();
995       $ldap->cd($this->config->current['BASE']);
996       $ldap->rmdir ($this->last_tabObject->dn);
997       @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
998           "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1000       $hostId =  $this->last_tabObject->by_object['opsiGeneric']->hostId;
1001       $mac    =  $this->last_tabObject->by_object['opsiGeneric']->mac;
1002       $this->opsi->job_opsi_activate_client($hostId,$mac);
1004     }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){
1005       $this->activate_new_device($this->last_tabObject->dn);
1006     }
1008     // Avoid using values from an older input dialog
1009     $_POST = array();
1010     $this->handleActivationQueue();
1011   }
1014   /*! \brief  Save object modifications here and any dialogs too.
1015    *          Keep dialogs opened.
1016    */
1017   protected function applyChanges()
1018   {
1019     $str = management::applyChanges();
1020     if($str) return($str);
1022     /* Post handling for activated systems
1023        target opsi -> Remove source.
1024        target gosa -> Activate system.
1025      */
1026     if($this->tabObject instanceOf opsi_tabs){
1027       $ldap = $this->config->get_ldap_link();
1028       $ldap->cd($this->config->current['BASE']);
1029       $ldap->rmdir ($this->tabObject->dn);
1030       @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1031           "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1033       $hostId =  $this->tabObject->by_object['opsiGeneric']->hostId;
1034       $mac    =  $this->tabObject->by_object['opsiGeneric']->mac;
1035       $this->opsi->job_opsi_activate_client($hostId,$mac);
1037     }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){
1038       $this->activate_new_device($this->tabObject->dn);
1039     }
1040   }
1041   
1043   /*! \brief  Sets FAIstate to "install" for "New Devices".
1044     This function is some kind of "Post handler" for activated systems,
1045     it is called directly after the object (workstabs,servtabs) gets saved.
1046     @param  String  $dn   The dn of the newly activated object.
1047     @return Boolean TRUE if activated else FALSE
1048    */
1049   function activate_new_device($dn)
1050   {
1051     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1052         $dn, "<b>Activating system:</b>");
1053     $ldap = $this->config->get_ldap_link();
1054     $ldap->cd($this->config->current['BASE']);
1055     $ldap->cat($dn);
1056     if($ldap->count()){
1057       $attrs = $ldap->fetch();
1058       if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){
1059         $ocs = $attrs['objectClass'];
1060         unset($ocs['count']);
1061         $new_attrs = array();
1062         if(!in_array("FAIobject",$ocs)){
1063           $ocs[] = "FAIobject";
1064           $new_attrs['objectClass'] = $ocs;
1065         }
1066         $new_attrs['FAIstate'] = "install";
1067         $ldap->cd($dn);
1068         $ldap->modify($new_attrs);
1069         if (!$ldap->success()){
1070           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1071                 LDAP_MOD, "activate_new_device($dn)"));
1072           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1073               $dn, "<b>Failed!</b>");
1074         }else{
1075           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1076               $dn, "<b>Success</b>");
1077           return(TRUE);
1078         }
1079       }else{
1080         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1081             $dn, "<b>FAIstate not set to install, this is only done for gotoWorkstation/goServer!</b>");
1082       }
1083     }
1084     return(FALSE);
1085   }
1088   /*! \brief  Opens the snapshot creation dialog for the given target.
1089    *
1090    *  @param  String  'action'  The name of the action which was the used as trigger.
1091    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1092    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1093    */
1094   function createSnapshotDialog($action="",$target=array(),$all=array())
1095   {
1096     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
1098     $pInfo    = $this->getObjectDefinitions();
1099     $headpage = $this->getHeadpage();
1100     foreach($target as $dn){
1102       $entry = $headpage->getEntry($dn);
1103       $type = $headpage->getType($dn);
1104       if(!isset($pInfo[$type])) {
1105         trigger_error('Unknown system type \''.$type.'\'!');
1106         return;
1107       }
1109       if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1110         $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1111         $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']);
1112         $this->dialogObject->parent = &$this;
1114       }else{
1115         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn),
1116             ERROR_DIALOG);
1117       }
1118     }
1119   }
1122   /*! \brief  Displays the "Restore snapshot dialog" for a given target.
1123    *          If no target is specified, open the restore removed object
1124    *           dialog.
1125    *  @param  String  'action'  The name of the action which was the used as trigger.
1126    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1127    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1128    */
1129   function restoreSnapshotDialog($action="",$target=array(),$all=array())
1130   {
1131     // Set current restore base for snapshot handling.
1132     $headpage = $this->getHeadpage();
1133     $pInfo    = $this->getObjectDefinitions();
1134     if(is_object($this->snapHandler)){
1135       $bases = array();
1136       foreach($this->storagePoints as $sp){
1137         $bases[] = $sp.$headpage->getBase();
1138       }
1139     }
1141     // No bases specified? Try base
1142     if(!count($bases)) $bases[] = $this->headpage->getBase();
1144     // No target, open the restore removed object dialog.
1145     if(!count($target)){
1147       $cats = array();
1148       foreach($pInfo as $data){
1149         $cats[] = $data['aclCategory'];
1150       }
1151       $cats = array_unique($cats);
1153       $entry = $headpage->getBase();
1154       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){
1155         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
1156         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
1157         $this->dialogObject->set_snapshot_bases($bases);
1158         $this->dialogObject->display_all_removed_objects = true;
1159         $this->dialogObject->display_restore_dialog = true;
1160         $this->dialogObject->parent = &$this;
1161       }else{
1162         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
1163             ERROR_DIALOG);
1164       }
1165     }else{
1167       // Display the restore points for a given object.
1168       $dn = array_pop($target);
1169       $entry = $headpage->getEntry($dn);
1170       $type = $headpage->getType($dn);
1171       if(!isset($pInfo[$type])) {
1172         trigger_error('Unknown system type \''.$type.'\'!');
1173         return;
1174       }
1176       if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1177         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!");
1178         $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1179         $this->dialogObject->set_snapshot_bases($bases);
1180         $this->dialogObject->display_restore_dialog = true;
1181         $this->dialogObject->parent = &$this;
1182       }else{
1183         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn),
1184             ERROR_DIALOG);
1185       }
1186     }
1187   }
1190   /*! \brief  Restores a snapshot object.
1191    *          The dn of the snapshot entry has to be given as ['target'] parameter.
1192    *
1193    *  @param  String  'action'  The name of the action which was the used as trigger.
1194    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1195    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1196    */
1197   function restoreSnapshot($action="",$target=array(),$all=array())
1198   {
1199     $dn       = array_pop($target);
1200     $this->snapHandler->restore_snapshot($dn);
1201     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!");
1202     $this->closeDialogs();
1203   }
1206   /*! \brief  Detects actions/events send by the ui
1207    *           and the corresponding targets.
1208    */
1209   function detectPostActions()
1210   {
1211     $action= management::detectPostActions();
1212     if(isset($_POST['abort_event_dialog']))  $action['action'] = "cancel";
1213     if(isset($_POST['save_event_dialog']))  $action['action'] = "saveEvent";
1214     if(isset($_POST['cd_create']))  $action['action'] = "initiateISOcreation";
1215     if(isset($_GET['PerformIsoCreation']))  $action['action'] = "performIsoCreation";
1216     if(isset($_POST['SystemTypeAborted']))  $action['action'] = "cancel";
1217     if(isset($_POST['password_cancel']))  $action['action'] = "cancel";
1218     if(isset($_POST['password_finish']))  $action['action'] = "passwordChangeConfirmed";
1220     if(isset($_POST['new_goServer']))  $action['action'] = "new_goServer";
1221     if(isset($_POST['new_gotoWorkstation']))  $action['action'] = "new_gotoWorkstation";
1222     if(isset($_POST['new_gotoTerminal']))  $action['action'] = "new_gotoTerminal";
1223     if(isset($_POST['new_gotoPrinter']))  $action['action'] = "new_gotoPrinter";
1224     if(isset($_POST['new_goFonHardware']))  $action['action'] = "new_goFonHardware";
1225     if(isset($_POST['new_ieee802Device']))  $action['action'] = "new_ieee802Device";
1226     if(isset($_POST['new_FAKE_OC_OpsiHost']))  $action['action'] = "new_FAKE_OC_OpsiHost";
1228     if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
1229       if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
1230     }
1232     if(isset($_POST['systemTypeChosen']))  $action['action'] = "systemTypeChosen";
1234     return($action);
1235   }
1238   /*! \brief   Overridden render method of class management.
1239    *            this allows us to add a release selection box.
1240    */
1241   function renderList()
1242   {
1243     $headpage = $this->getHeadpage();
1244     $headpage->update();
1246     $tD = $this->getObjectDefinitions();
1247     $smarty = get_smarty();
1248     foreach($tD as $name => $obj){
1249       $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
1250     }
1252     $display = $headpage->render();
1253     return($this->getHeader().$display);
1254   }
1257   public function getObjectDefinitions()
1258   {
1259     $tabs = array(
1260         "FAKE_OC_OpsiHost" => array(
1261           "ou"          => "",
1262           "plugClass"   => "opsiGeneric",
1263           "tabClass"    => "opsi_tabs",
1264           "tabDesc"     => "OPSITABS",
1265           "aclClass"    => "opsiGeneric",
1266           "sendEvents"  => TRUE,
1267           "aclCategory" => "opsi"),
1269         "goServer" => array(
1270           "ou"          => get_ou('serverRDN'),
1271           "plugClass"   => "servgeneric",
1272           "tabClass"    => "servtabs",
1273           "tabDesc"     => "SERVTABS",
1274           "aclClass"    => "servgeneric",
1275           "sendEvents"  => TRUE,
1276           "aclCategory" => "server"),
1278         "gotoWorkstation" => array(
1279           "ou"          => get_ou('workstationRDN'),
1280           "plugClass"   => "workgeneric",
1281           "tabClass"    => "worktabs",
1282           "tabDesc"     => "WORKTABS",
1283           "aclClass"    => "workgeneric",
1284           "sendEvents"  => TRUE,
1285           "aclCategory" => "workstation"),
1287         "gotoTerminal" => array(
1288             "ou"          => get_ou('terminalRDN'),
1289             "plugClass"   => "termgeneric",
1290             "tabClass"    => "termtabs",
1291             "sendEvents"  => TRUE,
1292             "tabDesc"     => "TERMTABS",
1293             "aclClass"    => "termgeneric",
1294             "aclCategory" => "terminal"),
1296         "gotoPrinter" => array(
1297             "ou"          => get_ou('printerRDN'),
1298             "plugClass"   => "printgeneric",
1299             "tabClass"    => "printtabs",
1300             "tabDesc"     => "PRINTTABS",
1301             "aclClass"    => "printgeneric",
1302             "sendEvents"  => FALSE,
1303             "aclCategory" => "printer"),
1305         "FAKE_OC_NewDevice" => array(
1306             "ou"          => get_ou('systemIncomingRDN'),
1307             "plugClass"   => "termgeneric",
1308             "tabClass"    => "termtabs",
1309             "sendEvents"  => TRUE,
1310             "tabDesc"     => "TERMTABS",
1311             "aclClass"    => "termgeneric",
1312             "aclCategory" => "terminal"),
1314         "goFonHardware" => array(
1315             "ou"          => get_ou('phoneRDN'),
1316             "plugClass"   => "phoneGeneric",
1317             "tabClass"    => "phonetabs",
1318             "tabDesc"     => "PHONETABS",
1319             "sendEvents"  => FALSE,
1320             "aclClass"    => "phoneGeneric",
1321             "aclCategory" => "phone"),
1323         "FAKE_OC_winstation" => array(
1324             "ou"          => get_winstations_ou(),
1325             "plugClass"   => "wingeneric",
1326             "sendEvents"  => TRUE,
1327             "tabClass"    => "wintabs",
1328             "tabDesc"     => "WINTABS",
1329             "aclClass"    => "wingeneric",
1330             "aclCategory" => "winworkstation"),
1332         "ieee802Device" => array(
1333             "ou"          => get_ou('componentRDN'),
1334             "plugClass"   => "componentGeneric",
1335             "sendEvents"  => FALSE,
1336             "tabClass"    => "componenttabs",
1337             "tabDesc"     => "COMPONENTTABS",
1338             "aclClass"    => "componentGeneric",
1339             "aclCategory" => "component"),
1340         );
1342     // Now map some special types
1343     $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
1344     $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
1345     $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
1346     $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
1347     $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
1348     $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
1349     $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
1350     $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
1351     $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
1352     $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal'];
1353     $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal'];
1354     $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
1355     $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
1356     $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
1358     $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
1360     return($tabs);
1361   }
1364   static function systemRelease($a,$b,$c,$objectclasses= null,$class= null)
1365   {
1366     global $config;
1368     // No objectclasses set - go ahead
1369     if(!$objectclasses) return("&nbsp;");
1371     // Skip non fai objects
1372     if (!in_array_ics("FAIobject", $objectclasses)) {
1373       return "&nbsp;";
1374     }
1376     // If we've an own fai class, just use this
1377     if ($class && is_array($class)) {
1378       foreach (explode(' ', $class[0]) as $element) {
1379         if ($element[0] == ":") {
1380           return "&nbsp;".image('images/empty.png')."&nbsp;".mb_substr($element, 1);
1381         }
1382       }
1383     }
1385     // Load information if needed
1386     $ldap = $config->get_ldap_link();
1387     $ldap->cd($config->current['BASE']);
1388     $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn'));
1389     while($attrs = $ldap->fetch()){
1390       $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]);
1391       $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]);
1392       $str = "&nbsp;".image('plugins/ogroups/images/ogroup.png', "", $sys)."&nbsp;".$rel;
1393       return($str);
1394     }
1395     
1396     return("&nbsp;");
1397   }
1400   /*! \brief  !! Incoming dummy acls, required to defined acls for incoming objects
1401    */
1402   static function plInfo()
1403   {
1404     return (array(
1405           "plShortName"   => _("Incoming objects"),
1406           "plDescription" => _("Incoming objects"),
1407           "plSelfModify"  => FALSE,
1408           "plDepends"     => array(),
1409           "plPriority"    => 99,
1410           "plSection"     => array("administration"),
1411           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1412               "objectClass"  => "")),
1413           "plProvidedAcls"=> array()
1414           ));
1415   }
1416
1417 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1418 ?>