Code

Updated get_ou it receives values from the config registry now.
[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  = "Manage systems, their services and prepare them for use with GOsa";
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     }
87     $this->storagePoints = array_unique($sP);
89     // Build filter
90     if (session::global_is_set(get_class($this)."_filter")){
91       $filter= session::global_get(get_class($this)."_filter");
92     } else {
93       $filter = new filter(get_template_path("system-filter.xml", true));
94       $filter->setObjectStorage($this->storagePoints);
95     }
96     $this->setFilter($filter);
98     // Build headpage
99     $headpage = new listing(get_template_path("system-list.xml", true));
100     $headpage->registerElementFilter("systemRelease", "systemManagement::systemRelease");
101     $headpage->registerElementFilter("filterSystemDescription", "systemManagement::filterSystemDescription");
102     $headpage->setFilter($filter);
103     $filter->setConverter('systemManagement::incomingFilterConverter');
105     // Register Daemon Events
106     if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
107       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
108       foreach($events['TRIGGERED'] as $name => $data){
109         $this->registerAction("T_".$name,"handleEvent");
110         $this->registerAction("S_".$name,"handleEvent");
111       }
112       $this->registerAction("activateMultiple","activateMultiple");
113     }
114     $this->registerAction("saveEvent","saveEventDialog");
115     $this->registerAction("createISO","createISO");
116     $this->registerAction("initiateISOcreation","initiateISOcreation");
117     $this->registerAction("performIsoCreation","performIsoCreation");
118     $this->registerAction("systemTypeChosen","systemTypeChosen");
119     $this->registerAction("handleActivationQueue","handleActivationQueue");
121     $this->registerAction("new_goServer",         "newEntry");
122     $this->registerAction("new_gotoWorkstation",  "newEntry");
123     $this->registerAction("new_gotoTerminal",     "newEntry");
124     $this->registerAction("new_gotoPrinter",      "newEntry");
125     $this->registerAction("new_goFonHardware",    "newEntry");
126     $this->registerAction("new_ieee802Device",    "newEntry");
127     $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry");
129     $this->registerAction("setPassword", "setPassword");
130     $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed");
132     // Add copy&paste and snapshot handler.
133     if ($this->config->boolValueIsTrue("core", "copyPaste")){
134       $this->cpHandler = new CopyPasteHandler($this->config);
135     }
136     if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
137       $this->snapHandler = new SnapshotHandler($this->config);
138     }
140     // Check if we are able to communicate with the GOsa supprot daemon
141     if(class_available("gosaSupportDaemon")){
142       $o = new gosaSupportDaemon();
143       $this->si_active = $o->connect() && class_available("DaemonEvent");
144     }
146     // Check if we are able to communicate with the GOsa supprot daemon
147     if(class_available("opsi")){
148       $this->opsi = new opsi($this->config);
149     }
150     parent::__construct($config, $ui, "systems", $headpage);
151   }
154   /*! \brief  Act on password change requests.
155    */
156   function setPassword($action,$target)
157   {
158     if(count($target) == 1){
159       $tDefs= $this->getObjectDefinitions();
160       $headpage = $this->getHeadpage();
161       $dn = array_pop($target);
162       $type = $headpage->getType($dn);
163       $entry = $headpage->getEntry($dn);
164       $ui       = get_userinfo();
165       $smarty = get_smarty();
166       if(in_array("FAKE_OC_PWD_changeAble", $entry['objectClass'])){
167         $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
168         $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
169         if(preg_match("/w/",$tabacl)){
170           $this->dn= $dn;
171           set_object_info($this->dn);
172           return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
173         }else{
174           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
175         }
176       }
177     }
178   }
181   /*! \brief  This method is used to queue and process copy&paste actions.
182    *          Allows to copy, cut and paste mutliple entries at once.
183    *  @param  String  'action'  The name of the action which was the used as trigger.
184    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
185    *  @param  Array   'all'     A combination of both 'action' and 'target'.
186    */
187   function copyPasteHandler($action="",$target=array(),$all=array(),
188       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
189   {
190     // Return without any actions while copy&paste handler is disabled.
191     if(!is_object($this->cpHandler))  return("");
193     // Save user input
194     $this->cpHandler->save_object();
196     // Add entries to queue
197     if($action == "copy" || $action == "cut"){
199       $tDefs= $this->getObjectDefinitions();
200       $headpage = $this->getHeadpage();
201       $ui       = get_userinfo();
202       $this->cpHandler->cleanup_queue();
203       foreach($target as $dn){
205         $type = $headpage->getType($dn);
206         $entry = $headpage->getEntry($dn);
207   
208         $aclCategory = $tDefs[$type]['aclCategory'];
209         $aclPlugin = $tDefs[$type]['aclClass'];
210         $tabClass = $tDefs[$type]['tabClass'];
211         $tabType = $tDefs[$type]['tabDesc'];
213         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
214           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
215           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
216         }
217         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
218           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
219           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
220         }
221       }
222     }
224     // Initiate pasting
225     if($action == "paste"){
226       $this->cpPastingStarted = TRUE;
227     }
229     // Display any c&p dialogs, eg. object modifications required before pasting.
230     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
231       $headpage = $this->getHeadpage();
232       $this->cpHandler->SetVar("base",$headpage->getBase());
233       $data = $this->cpHandler->execute();
234       if(!empty($data)){
235         return($data);
236       }
237     }
239     // Automatically disable pasting process since there is no entry left to paste.
240     if(!$this->cpHandler->entries_queued()){
241       $this->cpPastingStarted = FALSE;
242     }
243     return("");
244   }
247   /*! \brief  Password change confirmed, now try to change the systems pwd.
248    */
249   function passwordChangeConfirmed()
250   {
251     $tDefs= $this->getObjectDefinitions();
252     $headpage = $this->getHeadpage();
253     $type = $headpage->getType($this->dn);
254     $entry = $headpage->getEntry($this->dn);
255     $ui       = get_userinfo();
256     $smarty = get_smarty();
258     if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){
259       trigger_error("Tried to change pwd, for invalid object!");
260     }elseif ($_POST['new_password'] != $_POST['repeated_password']){
261       msg_dialog::display(_("Error"), 
262           _("The passwords you've entered as 'New password' and 'Repeated password' do not   match!"), ERROR_DIALOG);
263       return($smarty->fetch(get_template_path('password.tpl', TRUE)));
264     }else{
265       $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
266       $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
268       // Check acls
269       if(!preg_match("/w/",$tabacl)){
270         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
271       }else{
272         $ldap = $this->config->get_ldap_link();
273         $ldap->cd($this->dn);
274         $ldap->cat($this->dn);
275         $old_attrs = $ldap->fetch();
277         $attrs= array();
278         if ($_POST['new_password'] == ""){
280           /* Remove password attribute
281            */
282           if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
283             $attrs['objectClass'] = array();
284             for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
285               if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
286                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
287               }
288             }
289           }
290           $attrs['userPassword']= array();
291         } else {
293           /* Add/modify password attribute
294            */
295           if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
296             $attrs['objectClass'] = array();
297             for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
298               $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
299             }
300             $attrs['objectClass'][] = "simpleSecurityObject";
301           }
303           if(class_available("passwordMethodCrypt")){
304             $pwd_m = new passwordMethodCrypt($this->config);
305             $pwd_m->set_hash("crypt/md5");
306             $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
307           }else{
308             msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
309             $attrs = array();
310           }
311         }
312         $ldap->modify($attrs);
313         if (!$ldap->success()){
314           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
315         }else{
316           if(class_available($tDefs[$type]['plugClass'])){
317             $plug = $tDefs[$type]['plugClass'];
318             $p = new $plug($this->config,$this->dn);
319             $p->handle_post_events("modify");
320           }
321         }
322         new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
323       }
324       set_object_info();
325     }
326   }
329   /*! \brief  The method gets called when somebody clicked the CD icon 
330    *           in the system listing. 
331    *          A confirmation will be shown to acknowledge the creation.
332    */
333   function createISO($action,$target)
334   {
335     if(count($target) == 1){
336       $smarty = get_smarty();
337       $this->dn= array_pop($target);
338       set_object_info($this->dn);
339       return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE)));
341     }
342   }
343  
345   /*! \brief  Once the user has confirmed the ISO creation in 'createISO',
346    *           this method gets called. 
347    *          An iFrame is shown which then used 'performIsoCreation' as contents. 
348    */
349   function initiateISOcreation()
350   {
351     $smarty = get_smarty();
352     $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
353     return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE)));  
354   }
357   /*! \brief  ISO creation confirmed and iFrame is visible, now create the ISO 
358    *           and display the status to fill the iFrame.
359    */
360   function performIsoCreation()
361   {
362     $return_button   = "<form method='get' action='main.php' target='_parent'>
363       <input type='submit' value='"._("Back")."'>
364       <input type='hidden' name='plug' value='".$_GET['plug']."'/>
365       </form>";
367     $dsc   = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
369     /* Get and check command */
370     $command= $this->config->get_cfg_value("workgeneric", "systemIsoHook");
371     if (check_command($command)){
372       @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
374       /* Print out html introduction */
375       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
376         <html>
377         <head>
378         <title></title>
379         <style type="text/css">@import url("themes/default/style.css");</style>
380         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
381         </head>
382         <body style="background: none; margin:4px;" id="body" >
383         <pre>';
385       /* Open process handle and check if it is a valid process */
386       $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
387       if (is_resource($process)) {
388         fclose($pipes[0]);
390         /* Print out returned lines && write JS to scroll down each line */
391         while (!feof($pipes[1])){
392           $cur_dat = fgets($pipes[1], 1024);
393           echo $cur_dat;
394           echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
395           flush();
396         }
397       }
399       /* Get error string && close streams */
400       $buffer= stream_get_contents($pipes[2]);
402       fclose($pipes[1]);
403       fclose($pipes[2]);
404       echo "</pre>";
406       /* Check return code */
407       $ret= proc_close($process);
408       if ($ret != 0){
409         echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
410         echo "<pre style='color:red'>$buffer</pre>";
411       }
412       echo $return_button."<br>";
413     } else {
414       $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
415       echo $tmp;
416       echo $return_button."<br>";
417     }
419     /* Scroll down completly */
420     echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
421     echo '</body></html>';
422     flush();
423     exit;
424   }
427   /*! \brief    Handle GOsa-si events
428    *            All schedules and triggered events are handled here.
429    */
430   function handleEvent($action="",$target=array(),$all=array())
431   {
432     // Detect whether this event is scheduled or triggered.
433     $triggered = TRUE;
434     if(preg_match("/^S_/",$action)){
435       $triggered = FALSE;
436     }
438     // Detect triggere or scheduled actions 
439     $headpage = $this->getHeadpage();
440     $event = preg_replace("/^[TS]_/","",$action); 
441     if(preg_match("/^[TS]_/", $action)){
443       // Send special reinstall action for opsi hosts
444       if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){
445         foreach($target as $key => $dn){
446           $type = $headpage->getType($dn);
448           // Send Reinstall event for opsi hosts
449           if($type == "FAKE_OC_OpsiHost"){
450             $obj = $headpage->getEntry($dn);
451             $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
452             unset($target[$key]);
453           }
454         }
455       }
456     } 
458     // Now send remaining FAI/GOsa-si events here.
459     if(count($target) && $this->si_active){
460       $mac= array();
462       // Collect target mac addresses
463       $ldap = $this->config->get_ldap_link();
464       $tD = $this->getObjectDefinitions();
465       $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
466       $o_queue = new gosaSupportDaemon();
467       foreach($target as $dn){
468         $type = $headpage->getType($dn);
469         if($tD[$type]['sendEvents']){
470           $obj = $headpage->getEntry($dn);
471           if(isset($obj['macAddress'][0])){
472             $mac[] = $obj['macAddress'][0];
473           }
474         }
475       }
477       /* Skip installation or update trigerred events,
478        *  if this entry is currently processing.
479        */
480       if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){
481         foreach($mac as $key => $mac_address){
482           foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
483             $entry['STATUS'] = strtoupper($entry['STATUS']);
484             if($entry['STATUS'] == "PROCESSING" &&
485                 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
486                 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
487               unset($mac[$key]);
489               new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
490               break;
491             }
492           }
493         }
494       }
496       // Prepare event to be added
497       if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){
498         $event = $events['BY_CLASS'][$event];
499         $this->dialogObject = new $event['CLASS_NAME']($this->config);
500         $this->dialogObject->add_targets($mac);
502         if($triggered){
503           $this->dialogObject->set_type(TRIGGERED_EVENT);
504           $o_queue->append($this->dialogObject);
505           if($o_queue->is_error()){
506             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
507           }else{
508             $this->closeDialogs();
509           }
510         }else{
511           $this->dialogObject->set_type(SCHEDULED_EVENT);
512         }
513       }
514     }
515   }
518   /*! \brief  Close all dialogs and reset the activationQueue.
519    */ 
520   function cancelEdit()
521   {
522     management::cancelEdit();
523     $this->activationQueue = array();
524   }
525   
526  
527   /*! \brief  Save event dialogs. 
528    *          And append the new GOsa-si event.
529    */ 
530   function saveEventDialog()
531   {
532     $o_queue = new gosaSupportDaemon();
533     $o_queue->append($this->dialogObject);
534     if($o_queue->is_error()){
535       msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
536     }else{
537       $this->closeDialogs();
538     }
539   }
540  
542   /*! \brief    Update filter part for INCOMING.
543    *            Allows us to search for "systemIncomingRDN".
544    */
545   static function incomingFilterConverter($filter)
546   {
547     $rdn = preg_replace("/^[^=]*=/", "", get_ou("ArpNewDevice", "systemIncomingRDN"));
548     $rdn = preg_replace("/,.*$/","",$rdn);
549     return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
550   }
552  
553   /*! \brief    Queue selected objects to be removed. 
554    *            Checks ACLs, Locks and ask for confirmation.
555    */
556   protected function removeEntryRequested($action="",$target=array(),$all=array())
557   {
558     // Close dialogs and remove locks for currently handled dns
559     $this->cancelEdit();
561     $disallowed = array();
562     $this->dns = array();
564     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
566     // Check permissons for each target
567     $tInfo = $this->getObjectDefinitions();
568     $headpage = $this->getHeadpage();
569     foreach($target as $dn){
570       $type = $headpage->getType($dn);
571       if(!isset($tInfo[$type])){
572         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
573       }else{
574         $info = $tInfo[$type];
575         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
576         if(preg_match("/d/",$acl)){
577           $this->dns[] = $dn;
578         }else{
579           $disallowed[] = $dn;
580         }
581       }
582     }
583     if(count($disallowed)){
584       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
585     }
587     // We've at least one entry to delete.
588     if(count($this->dns)){
590       // check locks
591       if ($user= get_multiple_locks($this->dns)){
592         return(gen_locked_message($user,$this->dns));
593       }
595       // Add locks
596       $dns_names = array();
597       $types = array();
598       $h = $this->getHeadpage();
600       // Build list of object -labels
601       foreach($h->objectTypes as $type){
602         $map[$type['objectClass']]= $type['label'];
603       }
605       foreach($this->dns as $dn){
606         $tmp = $h->getType($dn);
607         if(isset($map[$tmp])){
608           $dns_names[] = '('._($map[$tmp]).')&nbsp;-&nbsp;'.LDAP::fix($dn);
609         }else{
610           $dns_names[] =LDAP::fix($dn);
611         }
612       }
613       add_lock ($this->dns, $this->ui->dn);
615       // Display confirmation dialog.
616       $smarty = get_smarty();
617       $smarty->assign("info", msgPool::deleteInfo($dns_names));
618       return($smarty->fetch(get_template_path('removeEntries.tpl')));
619     }
620   }
623   /*! \brief  Object removal was confirmed, now remove the requested entries.
624    *
625    *  @param  String  'action'  The name of the action which was the used as trigger.
626    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
627    *  @param  Array   'all'     A combination of both 'action' and 'target'.
628    */
629   function removeEntryConfirmed($action="",$target=array(),$all=array(),
630       $altTabClass="",$altTabType="",$altAclCategory="", $aclPlugin="")
631   {
632     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
634     // Check permissons for each target
635     $tInfo = $this->getObjectDefinitions();
636     $headpage = $this->getHeadpage();
637     $disallowed = array();
638     foreach($this->dns as $key => $dn){
639       $type = $headpage->getType($dn);
640       if(!isset($tInfo[$type])){
641         trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
642       }else{
644         $info = $tInfo[$type];
645         $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
646         if(preg_match("/d/",$acl)){
648           // Delete the object
649           $this->dn = $dn;
650           if($info['tabClass'] == "phonetabs"){
651              $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
652              $this->tabObject->set_acl_base($dn);
653              $this->tabObject->by_object['phoneGeneric']->remove_from_parent ();
654           }else{
655             $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']], 
656                 $this->dn, $info['aclCategory'], true, true);
657             $this->tabObject->set_acl_base($this->dn);
658             $this->tabObject->parent = &$this;
659             $this->tabObject->delete ();
660           }
662           // Remove the lock for the current object.
663           del_lock($this->dn);
665         }else{
666           $disallowed[] = $dn;
667           new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion.");
668         }
669       }
670     }
671     if(count($disallowed)){
672       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
673     }
675     // Cleanup
676     $this->remove_lock();
677     $this->closeDialogs();
678   }
681   /*! \brief  Edit the selected system type.
682    *          NewDevice and ArpNewDevice are handled here separately 
683    */
684   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
685   {
686     if(count($target) == 1){
687       $tInfo = $this->getObjectDefinitions();
688       $headpage = $this->getHeadpage();
689       $dn = $target[0];
690       $type =$headpage->getType($dn);
691       $tData = $tInfo[$type];
693       if($type == "FAKE_OC_ArpNewDevice"){
694         if(!class_available("ArpNewDeviceTabs")){
695           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
696         }else{
697           return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
698         }
699       }elseif($type == "FAKE_OC_NewDevice"){
700         if(!class_available("SelectDeviceType")){
701           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
702         }else{
703           $this->activationQueue[$dn] = array();
704           $this->dialogObject = new SelectDeviceType($this->config,$dn);
705           $this->dialogObject->set_acl_category("incoming");
706           $this->skipFooter = TRUE;
707           $this->displayApplyBtn = FALSE;
708           // see condition  -$s_action == "::systemTypeChosen"-  for further handling
709         }
710       }else{
711          return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
712       }
713     }
714   }
717   /*! \brief  Edit the selected system type.
718    *
719    *  @param  String  'action'  The name of the action which was the used as trigger.
720    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
721    *  @param  Array   'all'     A combination of both 'action' and 'target'.
722    */
723   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
724   {
725     $tInfo = $this->getObjectDefinitions();
726     $info = preg_replace("/^new_/","",$action);
727     if(!isset($tInfo[$info])){
728       trigger_error("Unknown action type '".$action."' cant create a new system!");
729     }else{
730       return(management::newEntry($action,$target,$all, 
731           $tInfo[$info]['tabClass'],
732           $tInfo[$info]['tabDesc'],
733           $tInfo[$info]['aclCategory']));
734     }
735   }
738   /*! \brief  Activates all selcted 'NewDevices' at once.
739    *          Enqueues the selected Devices in the activation queue.
740    */
741   function activateMultiple($action,$target)
742   {
743     $headpage = $this->getHeadpage();
744     foreach($target as $dn) {
745       if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
746         $this->activationQueue[$dn] = array();
747       }
748     }
749     if(count($this->activationQueue)){
750       $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
751       $this->skipFooter = TRUE;
752     }
753   }
756   /*! \brief  The system selection dialog was closed. 
757    *          We will now queue the given entry to be activated.
758    */ 
759   function systemTypeChosen()
760   {
761     // Detect the systems target type 
762     $tInfo = $this->getObjectDefinitions();
763     $selected_group = "none";
764     if(isset($_POST['ObjectGroup'])){
765       $selected_group = $_POST['ObjectGroup'];
766     }
767     $selected_system = $_POST['SystemType'];
768     $tmp = array();
769     foreach($this->activationQueue as $dn => $data){
770       $tmp[$dn]['OG'] = $selected_group;
771       $tmp[$dn]['SS'] = $selected_system;
772     }
773     $this->closeDialogs();
774     $this->activationQueue = $tmp;
775     return($this->handleActivationQueue());
776   }
779   /*! \brief  Activate queued goto systems.
780    */
781   function handleActivationQueue()
782   {
783     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
784         'Entries left: '.count($this->activationQueue), "<b>Handling system activation queue!</b>");
786     if(!count($this->activationQueue)) return("");
788     $ldap     = $this->config->get_ldap_link();
789     $pInfo    = $this->getObjectDefinitions(); 
790     $ui       = get_userinfo();
791     $headpage = $this->getHeadpage();
792     $ldap->cd($this->config->current['BASE']);
794     // Walk through systems to activate
795     while(count($this->activationQueue)){
796  
797       // Get next entry 
798       reset($this->activationQueue);
799       $dn = key($this->activationQueue);
800       $data= $this->activationQueue[$dn];
802       // Validate the given system type.
803       if(!isset($data['SS'])) continue;
804       $sysType = $data['SS'];
805       if(!isset($pInfo[$sysType])){
806         trigger_error('Unknown type \''.$sysType.'\'!');
807         continue;
808       }
809       $type = $pInfo[$sysType];
811       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
812           $dn, "<b>Try to activate:</b>");
814       // Get target type definition 
815       $plugClass    = $type["plugClass"];
816       $tabClass     = $type["tabClass"];
817       $aclCategory  = $type["aclCategory"];
818       $tabDesc      = $type["tabDesc"];
820       if(!class_available($tabClass)){
821         msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
822         unset($this->activationQueue[$dn]);
823         continue;
824       }else{
826         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
827             $sysType, "<b>System type:</b>");
829         // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' 
830         $this->dn = $dn;
831         $acls   = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
833         // Check permissions
834         if(!preg_match("/c/",$acls)){
835           unset($this->activationQueue[$dn]);
836           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
838           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
839               $acls, "<b>Insufficient permissions!</b>");
840           continue;
841         }else{
843           // Open object an preset some values like the objects base 
844           del_lock($dn);
845           management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
846           $this->displayApplyBtn = FALSE;
847           $this->tabObject->set_acl_base($headpage->getBase());
849           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
850               $data['OG'], "<b>Selected ogroup:</b>");
852           if($data['OG'] != "none"){
853             $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i", "", $data['OG']);
854             $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base);
855           } else {
856             $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase());
857             $this->tabObject->base = $headpage->getBase();
858           }
860           // Assign some default values for opsi hosts
861           if($this->tabObject instanceOf opsi_tabs){
862             $ldap = $this->config->get_ldap_link();
863             $ldap->cat($dn);
864             $source_attrs = $ldap->fetch();
865             foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
866               if(isset($source_attrs[$src][0])){
867                 $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
868               }
869             }
870             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
871                 "", "<b>OPSI attributes adapted</b>");
872           }
874           // Queue entry to be activated, when it is saved.
875           if($data['OG'] != "none"){
877             // Set gotoMode to active if there was an ogroup selected.
878             $found = false;
879             foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
880               if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
881                 $found = true;
882                 $this->tabObject->by_object[$tab]->gotoMode = $value;
883                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
884                     $tab."->gotoMode = {$value}", "<b>Setting gotoMode to: </b>");
885               }
886             }
887             if(!$found){
888               msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
889             }
891             // Update object group membership
892             $og = new ogroup($this->config,$data['OG']);
893             if($og){
894               $og->AddDelMembership($this->tabObject->dn);
895               $og->save();
896               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
897                   $og->dn, "<b>Adding system to ogroup</b>");
898             }
900             // Set default system specific attributes
901             foreach (array("workgeneric", "termgeneric") as $cls){
902               if (isset($this->tabObject->by_object[$cls])){
903                 $this->tabObject->by_object[$cls]->set_everything_to_inherited();
904                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
905                     $og->dn, "<b>Calling {$cls}->set_everything_to_inherited()</b>");
906               }
907             }
909             // Enable activation
910             foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
911               if (isset($this->tabObject->by_object[$cls])){
912                 $this->tabObject->by_object[$cls]->auto_activate= TRUE;
913                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
914                     $cls, "<b>Setting auto_activate=TRUE for</b>");
915               }
916             }
918             // Enable sending of LDAP events
919             if (isset($this->tabObject->by_object["workstartup"])){
920               $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
921               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
922                   "", "<b>Setting workstartup->gotoLdap_inherit=TRUE</b>");
923             }
924           }
926           // Try to inherit everythin from the selected object group and then save
927           //  the entry, normally this should work without any problems. 
928           // But if there is any, then display the dialogs.
929           if($data['OG'] != "none"){
930             $str = $this->saveChanges();
932             // There was a problem, skip activation here and allow to fix the problems..
933             if(is_object($this->tabObject)){
934               @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
935                   "", "<b>Automatic saving failed, let the user fix the issues now.</b>");
936               return;
937             }
938             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
939                 "", "<b>System activated!</b>");
940           }else{
941             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
942                 "", "<b>Open dialogs now</b>");
943             return;
944           }
945         }
946       }
947     }
948   }
951   /*! \brief  Save object modifications here and any dialogs too.
952    *          After a successfull update of the object data, close
953    *           the dialogs.
954    */
955   protected function saveChanges()
956   {
957     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
958         get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Save</b>");
959  
960     // Handle 'New Unknown Devices' here.
961     if($this->tabObject instanceOf ArpNewDeviceTabs){
962       $this->tabObject->save_object();
964       if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){
965         $message = $this->tabObject->check();
966         if(count($message)){
967           msg_dialog::displayChecks($message);
968         }else{
969           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
970               get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Queued for goto activation</b>");
971           $this->tabObject->save();
972           $this->activationQueue[$this->tabObject->dn]=array();
973           $this->closeDialogs();
974           $this->systemTypeChosen();
975         }
976         return;
977       }
978     }
980     // Try to save changes here.
981     $str = management::saveChanges();
982     if($this->tabObject) return("");
984     // Activate system if required..
985     if(isset($this->activationQueue[$this->last_dn])){
986       $dn = $this->last_tabObject->dn;
987       $this->activate_new_device($dn);
988       unset($this->activationQueue[$this->last_dn]);
989     }
991     /* Post handling for activated systems
992        target opsi -> Remove source.
993        target gosa -> Activate system.
994      */
995     if($this->last_tabObject instanceOf opsi_tabs){
996       $ldap = $this->config->get_ldap_link();
997       $ldap->cd($this->config->current['BASE']);
998       $ldap->rmdir ($this->last_tabObject->dn);
999       @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1000           "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1002       $hostId =  $this->last_tabObject->by_object['opsiGeneric']->hostId;
1003       $mac    =  $this->last_tabObject->by_object['opsiGeneric']->mac;
1004       $this->opsi->job_opsi_activate_client($hostId,$mac);
1006     }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){
1007       $this->activate_new_device($this->last_tabObject->dn);
1008     }
1010     // Avoid using values from an older input dialog
1011     $_POST = array();
1012     $this->handleActivationQueue();
1013   }
1016   /*! \brief  Save object modifications here and any dialogs too.
1017    *          Keep dialogs opened.
1018    */
1019   protected function applyChanges()
1020   {
1021     $str = management::applyChanges();
1022     if($str) return($str);
1024     /* Post handling for activated systems
1025        target opsi -> Remove source.
1026        target gosa -> Activate system.
1027      */
1028     if($this->tabObject instanceOf opsi_tabs){
1029       $ldap = $this->config->get_ldap_link();
1030       $ldap->cd($this->config->current['BASE']);
1031       $ldap->rmdir ($this->tabObject->dn);
1032       @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1033           "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1035       $hostId =  $this->tabObject->by_object['opsiGeneric']->hostId;
1036       $mac    =  $this->tabObject->by_object['opsiGeneric']->mac;
1037       $this->opsi->job_opsi_activate_client($hostId,$mac);
1038       $this->tabObject->set_acl_base($this->dn);
1040     }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){
1041       $this->activate_new_device($this->tabObject->dn);
1042     }
1043   }
1044   
1046   /*! \brief  Sets FAIstate to "install" for "New Devices".
1047     This function is some kind of "Post handler" for activated systems,
1048     it is called directly after the object (workstabs,servtabs) gets saved.
1049     @param  String  $dn   The dn of the newly activated object.
1050     @return Boolean TRUE if activated else FALSE
1051    */
1052   function activate_new_device($dn)
1053   {
1054     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1055         $dn, "<b>Activating system:</b>");
1056     $ldap = $this->config->get_ldap_link();
1057     $ldap->cd($this->config->current['BASE']);
1058     $ldap->cat($dn);
1059     if($ldap->count()){
1060       $attrs = $ldap->fetch();
1061       if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){
1062         $ocs = $attrs['objectClass'];
1063         unset($ocs['count']);
1064         $new_attrs = array();
1065         if(!in_array("FAIobject",$ocs)){
1066           $ocs[] = "FAIobject";
1067           $new_attrs['objectClass'] = $ocs;
1068         }
1069         $new_attrs['FAIstate'] = "install";
1070         $ldap->cd($dn);
1071         $ldap->modify($new_attrs);
1072         if (!$ldap->success()){
1073           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1074                 LDAP_MOD, "activate_new_device($dn)"));
1075           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1076               $dn, "<b>Failed!</b>");
1077         }else{
1078           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1079               $dn, "<b>Success</b>");
1080           return(TRUE);
1081         }
1082       }else{
1083         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1084             $dn, "<b>FAIstate not set to install, this is only done for gotoWorkstation/goServer!</b>");
1085       }
1086     }
1087     return(FALSE);
1088   }
1091   /*! \brief  Opens the snapshot creation dialog for the given target.
1092    *
1093    *  @param  String  'action'  The name of the action which was the used as trigger.
1094    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1095    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1096    */
1097   function createSnapshotDialog($action="",$target=array(),$all=array())
1098   {
1099     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
1101     $pInfo    = $this->getObjectDefinitions();
1102     $headpage = $this->getHeadpage();
1103     foreach($target as $dn){
1105       $entry = $headpage->getEntry($dn);
1106       $type = $headpage->getType($dn);
1107       if(!isset($pInfo[$type])) {
1108         trigger_error('Unknown system type \''.$type.'\'!');
1109         return;
1110       }
1112       if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1113         $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1114         $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']);
1115         $this->dialogObject->parent = &$this;
1117       }else{
1118         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn),
1119             ERROR_DIALOG);
1120       }
1121     }
1122   }
1125   /*! \brief  Displays the "Restore snapshot dialog" for a given target.
1126    *          If no target is specified, open the restore removed object
1127    *           dialog.
1128    *  @param  String  'action'  The name of the action which was the used as trigger.
1129    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1130    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1131    */
1132   function restoreSnapshotDialog($action="",$target=array(),$all=array())
1133   {
1134     // Set current restore base for snapshot handling.
1135     $headpage = $this->getHeadpage();
1136     $pInfo    = $this->getObjectDefinitions();
1137     if(is_object($this->snapHandler)){
1138       $bases = array();
1139       foreach($this->storagePoints as $sp){
1140         $bases[] = $sp.$headpage->getBase();
1141       }
1142     }
1144     // No bases specified? Try base
1145     if(!count($bases)) $bases[] = $this->headpage->getBase();
1147     // No target, open the restore removed object dialog.
1148     if(!count($target)){
1150       $cats = array();
1151       foreach($pInfo as $data){
1152         $cats[] = $data['aclCategory'];
1153       }
1154       $cats = array_unique($cats);
1156       $entry = $headpage->getBase();
1157       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){
1158         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
1159         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
1160         $this->dialogObject->set_snapshot_bases($bases);
1161         $this->dialogObject->display_all_removed_objects = true;
1162         $this->dialogObject->display_restore_dialog = true;
1163         $this->dialogObject->parent = &$this;
1164       }else{
1165         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
1166             ERROR_DIALOG);
1167       }
1168     }else{
1170       // Display the restore points for a given object.
1171       $dn = array_pop($target);
1172       $entry = $headpage->getEntry($dn);
1173       $type = $headpage->getType($dn);
1174       if(!isset($pInfo[$type])) {
1175         trigger_error('Unknown system type \''.$type.'\'!');
1176         return;
1177       }
1179       if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1180         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!");
1181         $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1182         $this->dialogObject->set_snapshot_bases($bases);
1183         $this->dialogObject->display_restore_dialog = true;
1184         $this->dialogObject->parent = &$this;
1185       }else{
1186         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn),
1187             ERROR_DIALOG);
1188       }
1189     }
1190   }
1193   /*! \brief  Restores a snapshot object.
1194    *          The dn of the snapshot entry has to be given as ['target'] parameter.
1195    *
1196    *  @param  String  'action'  The name of the action which was the used as trigger.
1197    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1198    *  @param  Array   'all'     A combination of both 'action' and 'target'.
1199    */
1200   function restoreSnapshot($action="",$target=array(),$all=array())
1201   {
1202     $dn       = array_pop($target);
1203     $this->snapHandler->restore_snapshot($dn);
1204     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!");
1205     $this->closeDialogs();
1206   }
1209   /*! \brief  Detects actions/events send by the ui
1210    *           and the corresponding targets.
1211    */
1212   function detectPostActions()
1213   {
1214     $action= management::detectPostActions();
1215     if(isset($_POST['abort_event_dialog']))  $action['action'] = "cancel";
1216     if(isset($_POST['save_event_dialog']))  $action['action'] = "saveEvent";
1217     if(isset($_POST['cd_create']))  $action['action'] = "initiateISOcreation";
1218     if(isset($_GET['PerformIsoCreation']))  $action['action'] = "performIsoCreation";
1219     if(isset($_POST['SystemTypeAborted']))  $action['action'] = "cancel";
1220     if(isset($_POST['password_cancel']))  $action['action'] = "cancel";
1221     if(isset($_POST['password_finish']))  $action['action'] = "passwordChangeConfirmed";
1223     if(isset($_POST['new_goServer']))  $action['action'] = "new_goServer";
1224     if(isset($_POST['new_gotoWorkstation']))  $action['action'] = "new_gotoWorkstation";
1225     if(isset($_POST['new_gotoTerminal']))  $action['action'] = "new_gotoTerminal";
1226     if(isset($_POST['new_gotoPrinter']))  $action['action'] = "new_gotoPrinter";
1227     if(isset($_POST['new_goFonHardware']))  $action['action'] = "new_goFonHardware";
1228     if(isset($_POST['new_ieee802Device']))  $action['action'] = "new_ieee802Device";
1229     if(isset($_POST['new_FAKE_OC_OpsiHost']))  $action['action'] = "new_FAKE_OC_OpsiHost";
1231     if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
1232       if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
1233     }
1235     if(isset($_POST['systemTypeChosen']))  $action['action'] = "systemTypeChosen";
1237     return($action);
1238   }
1241   /*! \brief   Overridden render method of class management.
1242    *            this allows us to add a release selection box.
1243    */
1244   function renderList()
1245   {
1246     $headpage = $this->getHeadpage();
1247     $headpage->update();
1249     $tD = $this->getObjectDefinitions();
1250     $smarty = get_smarty();
1251     foreach($tD as $name => $obj){
1252       $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
1253     }
1255     $display = $headpage->render();
1256     return($this->getHeader().$display);
1257   }
1260   public function getObjectDefinitions()
1261   {
1262     $tabs = array(
1263         "FAKE_OC_OpsiHost" => array(
1264           "ou"          => "",
1265           "plugClass"   => "opsiGeneric",
1266           "tabClass"    => "opsi_tabs",
1267           "tabDesc"     => "OPSITABS",
1268           "aclClass"    => "opsiGeneric",
1269           "sendEvents"  => TRUE,
1270           "aclCategory" => "opsi"),
1272         "goServer" => array(
1273           "ou"          => get_ou("servgeneric", "serverRDN"),
1274           "plugClass"   => "servgeneric",
1275           "tabClass"    => "servtabs",
1276           "tabDesc"     => "SERVTABS",
1277           "aclClass"    => "servgeneric",
1278           "sendEvents"  => TRUE,
1279           "aclCategory" => "server"),
1281         "gotoWorkstation" => array(
1282           "ou"          => get_ou("workgeneric", "workstationRDN"),
1283           "plugClass"   => "workgeneric",
1284           "tabClass"    => "worktabs",
1285           "tabDesc"     => "WORKTABS",
1286           "aclClass"    => "workgeneric",
1287           "sendEvents"  => TRUE,
1288           "aclCategory" => "workstation"),
1290         "gotoTerminal" => array(
1291             "ou"          => get_ou("termgeneric", "terminalRDN"),
1292             "plugClass"   => "termgeneric",
1293             "tabClass"    => "termtabs",
1294             "sendEvents"  => TRUE,
1295             "tabDesc"     => "TERMTABS",
1296             "aclClass"    => "termgeneric",
1297             "aclCategory" => "terminal"),
1299         "gotoPrinter" => array(
1300             "ou"          => get_ou("printgeneric", "printerRDN"),
1301             "plugClass"   => "printgeneric",
1302             "tabClass"    => "printtabs",
1303             "tabDesc"     => "PRINTTABS",
1304             "aclClass"    => "printgeneric",
1305             "sendEvents"  => FALSE,
1306             "aclCategory" => "printer"),
1308         "FAKE_OC_NewDevice" => array(
1309             "ou"          => get_ou("ArpNewDevice", "systemIncomingRDN"),
1310             "plugClass"   => "termgeneric",
1311             "tabClass"    => "termtabs",
1312             "sendEvents"  => TRUE,
1313             "tabDesc"     => "TERMTABS",
1314             "aclClass"    => "termgeneric",
1315             "aclCategory" => "terminal"),
1317         "goFonHardware" => array(
1318             "ou"          => get_ou("phoneGeneric", "phoneRDN"),
1319             "plugClass"   => "phoneGeneric",
1320             "tabClass"    => "phonetabs",
1321             "tabDesc"     => "PHONETABS",
1322             "sendEvents"  => FALSE,
1323             "aclClass"    => "phoneGeneric",
1324             "aclCategory" => "phone"),
1326         "FAKE_OC_winstation" => array(
1327             "ou"          => get_winstations_ou(),
1328             "plugClass"   => "wingeneric",
1329             "sendEvents"  => TRUE,
1330             "tabClass"    => "wintabs",
1331             "tabDesc"     => "WINTABS",
1332             "aclClass"    => "wingeneric",
1333             "aclCategory" => "winworkstation"),
1335         "ieee802Device" => array(
1336             "ou"          => get_ou("componentGeneric", "componentRDN"),
1337             "plugClass"   => "componentGeneric",
1338             "sendEvents"  => FALSE,
1339             "tabClass"    => "componenttabs",
1340             "tabDesc"     => "COMPONENTTABS",
1341             "aclClass"    => "componentGeneric",
1342             "aclCategory" => "component"),
1343         );
1345     // Now map some special types
1346     $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
1347     $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
1348     $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
1349     $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
1350     $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
1351     $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
1352     $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
1353     $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
1354     $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
1355     $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal'];
1356     $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal'];
1357     $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
1358     $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
1359     $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
1361     $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
1363     return($tabs);
1364   }
1367   static function filterSystemDescription($row,$dn,$pid,$state,$description=array())
1368   {
1369       $dn= LDAP::fix(func_get_arg(1));
1370       $desc = isset($description[0])?$description[0]:"&nbsp;";
1371       $rc = "";
1372       switch($state){
1373         case 'locked' : $rc = "<rowClass:entry-locked/><rowLabel:locked/>"; break;
1374         case 'error' : $rc = "<rowClass:entry-error/><rowLabel:error/>"; break;
1375         case 'busy' : $rc = "<rowClass:entry-busy/><rowLabel:busy/>"; break;
1376         case 'warning' : $rc = "<rowClass:entry-warning/><rowLabel:warning/>"; break;
1377       }
1378       return("<a href='?plug=".$_GET['plug']."&amp;PID={$pid}&amp;act=listing_edit_{$row}' title='{$dn}'>{$desc}</a>{$rc}");
1379   }
1381   static function systemRelease($a,$b,$c,$objectclasses= null,$class= null)
1382   {
1383     global $config;
1385     // No objectclasses set - go ahead
1386     if(!$objectclasses) return("&nbsp;");
1388     // Skip non fai objects
1389     if (!in_array_ics("FAIobject", $objectclasses)) {
1390       return "&nbsp;";
1391     }
1393     // If we've an own fai class, just use this
1394     if ($class && is_array($class)) {
1395       foreach (explode(' ', $class[0]) as $element) {
1396         if ($element[0] == ":") {
1397           return "&nbsp;".image('images/empty.png')."&nbsp;".mb_substr($element, 1);
1398         }
1399       }
1400     }
1402     // Load information if needed
1403     $ldap = $config->get_ldap_link();
1404     $ldap->cd($config->current['BASE']);
1405     $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn'));
1406     while($attrs = $ldap->fetch()){
1407       $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]);
1408       $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]);
1409       $str = "&nbsp;".image('plugins/ogroups/images/ogroup.png', "", $sys)."&nbsp;".$rel;
1410       return($str);
1411     }
1412     
1413     return("&nbsp;");
1414   }
1417   /*! \brief  !! Incoming dummy acls, required to defined acls for incoming objects
1418    */
1419   static function plInfo()
1420   {
1421       return (array(
1422                   "plShortName"   => _("Incoming objects"),
1423                   "plDescription" => _("Incoming objects"),
1424                   "plSelfModify"  => FALSE,
1425                   "plDepends"     => array(),
1426                   "plPriority"    => 99,
1427                   "plSection"     => array("administration"),
1429                   "plProperties" =>
1430                   array(
1431                       array(
1432                           "name"          => "systemRDN",
1433                           "type"          => "rdn",
1434                           "default"       => "ou=systems,",
1435                           "description"   => "The 'systemRDN' statement defines the location where new systems will be created. The default is 'ou=systems,'.",
1436                           "check"         => "gosaProperty::isRdn",
1437                           "migrate"       => "",
1438                           "group"         => "plugin",
1439                           "mandatory"     => FALSE
1440                           )
1441                       ),
1444           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1445                       "objectClass"  => "")),
1446           "plProvidedAcls"=> array()
1447               ));
1448   }
1449
1450 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1451 ?>