Code

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