Code

3c2b052f4ce518de9f461479be2f42f2c36d4f7c
[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 $info['tabClass']($this->config, $this->config->data['TABS'][$info['tabDesc']], $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);
705             if(!isset($tInfo[$type])){
706                 msg_dialog::display(_("Information"),sprintf(_("The object-type '%s' cannot be managed with your setup of GOsa, please install the required  plugins!"), $type), ERROR_DIALOG);
707                 return;
708             }
710             $tData = $tInfo[$type];
712             if($type == "FAKE_OC_ArpNewDevice"){
713                 if(!class_available("ArpNewDeviceTabs")){
714                     msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
715                 }else{
716                     return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
717                 }
718             }elseif($type == "FAKE_OC_NewDevice"){
719                 if(!class_available("SelectDeviceType")){
720                     msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
721                 }else{
722                     $this->activationQueue[$dn] = array();
723                     $this->dialogObject = new SelectDeviceType($this->config,$dn);
724                     $this->dialogObject->set_acl_category("incoming");
725                     $this->skipFooter = TRUE;
726                     $this->displayApplyBtn = FALSE;
727                     // see condition  -$s_action == "::systemTypeChosen"-  for further handling
728                 }
729             }else{
730                 return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
731             }
732         }
733     }
736     /*! \brief  Edit the selected system type.
737      *
738      *  @param  String  'action'  The name of the action which was the used as trigger.
739      *  @param  Array   'target'  A list of object dns, which should be affected by this method.
740      *  @param  Array   'all'     A combination of both 'action' and 'target'.
741      */
742     function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
743     {
744         $tInfo = $this->getObjectDefinitions();
745         $info = preg_replace("/^new_/","",$action);
746         if(!isset($tInfo[$info])){
747             trigger_error("Unknown action type '".$action."' cant create a new system!");
748         }else{
749             return(management::newEntry($action,$target,$all, 
750                         $tInfo[$info]['tabClass'],
751                         $tInfo[$info]['tabDesc'],
752                         $tInfo[$info]['aclCategory']));
753         }
754     }
757     /*! \brief  Activates all selcted 'NewDevices' at once.
758      *          Enqueues the selected Devices in the activation queue.
759      */
760     function activateMultiple($action,$target)
761     {
762         $headpage = $this->getHeadpage();
763         foreach($target as $dn) {
764             if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
765                 $this->activationQueue[$dn] = array();
766             }
767         }
768         if(count($this->activationQueue)){
769             $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
770             $this->skipFooter = TRUE;
771         }
772     }
775     /*! \brief  The system selection dialog was closed. 
776      *          We will now queue the given entry to be activated.
777      */ 
778     function systemTypeChosen()
779     {
780         // Detect the systems target type 
781         $tInfo = $this->getObjectDefinitions();
782         $selected_group = "none";
783         if(isset($_POST['ObjectGroup'])){
784             $selected_group = get_post('ObjectGroup');
785         }
786         $selected_system = get_post('SystemType');
787         $tmp = array();
788         foreach($this->activationQueue as $dn => $data){
789             $tmp[$dn]['OG'] = $selected_group;
790             $tmp[$dn]['SS'] = $selected_system;
791         }
792         $this->closeDialogs();
793         $this->activationQueue = $tmp;
794         return($this->handleActivationQueue());
795     }
798     /*! \brief  Activate queued goto systems.
799      */
800     function handleActivationQueue()
801     {
802         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
803                 'Entries left: '.count($this->activationQueue), "<b>Handling system activation queue!</b>");
805         if(!count($this->activationQueue)) return("");
807         $ldap     = $this->config->get_ldap_link();
808         $pInfo    = $this->getObjectDefinitions(); 
809         $ui       = get_userinfo();
810         $headpage = $this->getHeadpage();
811         $ldap->cd($this->config->current['BASE']);
813         // Walk through systems to activate
814         while(count($this->activationQueue)){
816             // Get next entry 
817             reset($this->activationQueue);
818             $dn = key($this->activationQueue);
819             $data= $this->activationQueue[$dn];
821             // Validate the given system type.
822             if(!isset($data['SS'])) continue;
823             $sysType = $data['SS'];
824             if(!isset($pInfo[$sysType])){
825                 trigger_error('Unknown type \''.$sysType.'\'!');
826                 continue;
827             }
828             $type = $pInfo[$sysType];
830             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
831                     $dn, "<b>Try to activate:</b>");
833             // Get target type definition 
834             $plugClass    = $type["plugClass"];
835             $tabClass     = $type["tabClass"];
836             $aclCategory  = $type["aclCategory"];
837             $tabDesc      = $type["tabDesc"];
839             if(!class_available($tabClass)){
840                 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
841                 unset($this->activationQueue[$dn]);
842                 continue;
843             }else{
845                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
846                         $sysType, "<b>System type:</b>");
848                 // Load permissions for selected 'dn' and check if we're allowed to create this 'dn' 
849                 $this->dn = $dn;
850                 $acls   = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
852                 // Check permissions
853                 if(!preg_match("/c/",$acls)){
854                     unset($this->activationQueue[$dn]);
855                     msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
857                     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
858                             $acls, "<b>Insufficient permissions!</b>");
859                     continue;
860                 }else{
862                     // Open object an preset some values like the objects base 
863                     del_lock($dn);
864                     management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
865                     $this->displayApplyBtn = FALSE;
866                     $this->tabObject->set_acl_base($headpage->getBase());
868                     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
869                             $data['OG'], "<b>Selected ogroup:</b>");
871                     if($data['OG'] != "none"){
872                         $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i", "", $data['OG']);
873                         $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base);
874                     } else {
875                         $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase());
876                         $this->tabObject->base = $headpage->getBase();
877                     }
879                     // Assign some default values for opsi hosts
880                     if($this->tabObject instanceOf opsi_tabs){
881                         $ldap = $this->config->get_ldap_link();
882                         $ldap->cat($dn);
883                         $source_attrs = $ldap->fetch();
884                         foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
885                             if(isset($source_attrs[$src][0])){
886                                 $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
887                             }
888                         }
889                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
890                                 "", "<b>OPSI attributes adapted</b>");
891                     }
893                     // Queue entry to be activated, when it is saved.
894                     if($data['OG'] != "none"){
896                         // Set gotoMode to active if there was an ogroup selected.
897                         $found = false;
898                         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
899                             if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
900                                 $found = true;
901                                 $this->tabObject->by_object[$tab]->gotoMode = $value;
902                                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
903                                         $tab."->gotoMode = {$value}", "<b>Setting gotoMode to: </b>");
904                             }
905                         }
906                         if(!$found){
907                             msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
908                         }
910                         // Update object group membership
911                         $og = new ogroup($this->config,$data['OG']);
912                         if($og){
913                             $og->AddDelMembership($this->tabObject->dn);
914                             $og->save();
915                             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
916                                     $og->dn, "<b>Adding system to ogroup</b>");
917                         }
919                         // Set default system specific attributes
920                         foreach (array("workgeneric", "termgeneric") as $cls){
921                             if (isset($this->tabObject->by_object[$cls])){
922                                 $this->tabObject->by_object[$cls]->set_everything_to_inherited();
923                                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
924                                         $og->dn, "<b>Calling {$cls}->set_everything_to_inherited()</b>");
925                             }
926                         }
928                         // Enable activation
929                         foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
930                             if (isset($this->tabObject->by_object[$cls])){
931                                 $this->tabObject->by_object[$cls]->auto_activate= TRUE;
932                                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
933                                         $cls, "<b>Setting auto_activate=TRUE for</b>");
934                             }
935                         }
937                         // Enable sending of LDAP events
938                         if (isset($this->tabObject->by_object["workstartup"])){
939                             $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
940                             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
941                                     "", "<b>Setting workstartup->gotoLdap_inherit=TRUE</b>");
942                         }
943                     }
945                     // Try to inherit everythin from the selected object group and then save
946                     //  the entry, normally this should work without any problems. 
947                     // But if there is any, then display the dialogs.
948                     if($data['OG'] != "none"){
949                         $str = $this->saveChanges();
951                         // There was a problem, skip activation here and allow to fix the problems..
952                         if(is_object($this->tabObject)){
953                             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
954                                     "", "<b>Automatic saving failed, let the user fix the issues now.</b>");
955                             return;
956                         }
957                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
958                                 "", "<b>System activated!</b>");
959                     }else{
960                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
961                                 "", "<b>Open dialogs now</b>");
962                         return;
963                     }
964                 }
965             }
966         }
967     }
970     /*! \brief  Save object modifications here and any dialogs too.
971      *          After a successfull update of the object data, close
972      *           the dialogs.
973      */
974     protected function saveChanges()
975     {
976         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
977                 get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Save</b>");
979         // Handle 'New Unknown Devices' here.
980         if($this->tabObject instanceOf ArpNewDeviceTabs){
981             $this->tabObject->save_object();
983             if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){
984                 $message = $this->tabObject->check();
985                 if(count($message)){
986                     msg_dialog::displayChecks($message);
987                 }else{
988                     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
989                             get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Queued for goto activation</b>");
990                     $this->tabObject->save();
991                     $this->activationQueue[$this->tabObject->dn]=array();
992                     $this->closeDialogs();
993                     $this->systemTypeChosen();
994                 }
995                 return;
996             }
997         }
999         // Try to save changes here.
1000         $str = management::saveChanges();
1001         if($this->tabObject) return("");
1003         // Activate system if required..
1004         if(isset($this->activationQueue[$this->last_dn])){
1005             $dn = $this->last_tabObject->dn;
1006             $this->activate_new_device($dn);
1007             unset($this->activationQueue[$this->last_dn]);
1008         }
1010         /* Post handling for activated systems
1011            target opsi -> Remove source.
1012            target gosa -> Activate system.
1013          */
1014         if($this->last_tabObject instanceOf opsi_tabs){
1015             $ldap = $this->config->get_ldap_link();
1016             $ldap->cd($this->config->current['BASE']);
1017             $ldap->rmdir ($this->last_tabObject->dn);
1018             @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1019                     "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1021             $hostId =  $this->last_tabObject->by_object['opsiGeneric']->hostId;
1022             $mac    =  $this->last_tabObject->by_object['opsiGeneric']->mac;
1023             $this->opsi->job_opsi_activate_client($hostId,$mac);
1025         }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){
1026             $this->activate_new_device($this->last_tabObject->dn);
1027         }
1029         // Avoid using values from an older input dialog
1030         $_POST = array();
1031         $this->handleActivationQueue();
1032     }
1035     /*! \brief  Save object modifications here and any dialogs too.
1036      *          Keep dialogs opened.
1037      */
1038     protected function applyChanges()
1039     {
1040         $str = management::applyChanges();
1041         if($str) return($str);
1043         /* Post handling for activated systems
1044            target opsi -> Remove source.
1045            target gosa -> Activate system.
1046          */
1047         if($this->tabObject instanceOf opsi_tabs){
1048             $ldap = $this->config->get_ldap_link();
1049             $ldap->cd($this->config->current['BASE']);
1050             $ldap->rmdir ($this->tabObject->dn);
1051             @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1052                     "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1054             $hostId =  $this->tabObject->by_object['opsiGeneric']->hostId;
1055             $mac    =  $this->tabObject->by_object['opsiGeneric']->mac;
1056             $this->opsi->job_opsi_activate_client($hostId,$mac);
1057             $this->tabObject->set_acl_base($this->dn);
1059         }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){
1060             $this->activate_new_device($this->tabObject->dn);
1061         }
1062     }
1065     /*! \brief  Sets FAIstate to "install" for "New Devices".
1066       This function is some kind of "Post handler" for activated systems,
1067       it is called directly after the object (workstabs,servtabs) gets saved.
1068       @param  String  $dn   The dn of the newly activated object.
1069       @return Boolean TRUE if activated else FALSE
1070      */
1071     function activate_new_device($dn)
1072     {
1073         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1074                 $dn, "<b>Activating system:</b>");
1075         $ldap = $this->config->get_ldap_link();
1076         $ldap->cd($this->config->current['BASE']);
1077         $ldap->cat($dn);
1078         if($ldap->count()){
1079             $attrs = $ldap->fetch();
1080             if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){
1081                 $ocs = $attrs['objectClass'];
1082                 unset($ocs['count']);
1083                 $new_attrs = array();
1084                 if(!in_array_strict("FAIobject",$ocs)){
1085                     $ocs[] = "FAIobject";
1086                     $new_attrs['objectClass'] = $ocs;
1087                 }
1088                 $new_attrs['FAIstate'] = "install";
1089                 $ldap->cd($dn);
1090                 $ldap->modify($new_attrs);
1091                 if (!$ldap->success()){
1092                     msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1093                                 LDAP_MOD, "activate_new_device($dn)"));
1094                     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1095                             $dn, "<b>Failed!</b>");
1096                 }else{
1097                     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1098                             $dn, "<b>Success</b>");
1099                     return(TRUE);
1100                 }
1101             }else{
1102                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1103                         $dn, "<b>FAIstate not set to install, this is only done for gotoWorkstation/goServer!</b>");
1104             }
1105         }
1106         return(FALSE);
1107     }
1110     /*! \brief  Opens the snapshot creation dialog for the given target.
1111      *
1112      *  @param  String  'action'  The name of the action which was the used as trigger.
1113      *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1114      *  @param  Array   'all'     A combination of both 'action' and 'target'.
1115      */
1116     function createSnapshotDialog($action="",$target=array(),$all=array())
1117     {
1118         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
1120         $pInfo    = $this->getObjectDefinitions();
1121         $headpage = $this->getHeadpage();
1122         foreach($target as $dn){
1124             $entry = $headpage->getEntry($dn);
1125             $type = $headpage->getType($dn);
1126             if(!isset($pInfo[$type])) {
1127                 trigger_error('Unknown system type \''.$type.'\'!');
1128                 return;
1129             }
1131             if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1132                 $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1133                 $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']);
1134                 $this->dialogObject->parent = &$this;
1136             }else{
1137                 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn),
1138                         ERROR_DIALOG);
1139             }
1140         }
1141     }
1144     /*! \brief  Displays the "Restore snapshot dialog" for a given target.
1145      *          If no target is specified, open the restore removed object
1146      *           dialog.
1147      *  @param  String  'action'  The name of the action which was the used as trigger.
1148      *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1149      *  @param  Array   'all'     A combination of both 'action' and 'target'.
1150      */
1151     function restoreSnapshotDialog($action="",$target=array(),$all=array())
1152     {
1153         // Set current restore base for snapshot handling.
1154         $headpage = $this->getHeadpage();
1155         $pInfo    = $this->getObjectDefinitions();
1156         if(is_object($this->snapHandler)){
1157             $bases = array();
1158             foreach($this->storagePoints as $sp){
1159                 $bases[] = $sp.$headpage->getBase();
1160             }
1161         }
1163         // No bases specified? Try base
1164         if(!count($bases)) $bases[] = $this->headpage->getBase();
1166         // No target, open the restore removed object dialog.
1167         if(!count($target)){
1169             $cats = array();
1170             foreach($pInfo as $data){
1171                 $cats[] = $data['aclCategory'];
1172             }
1173             $cats = array_unique($cats);
1175             $entry = $headpage->getBase();
1176             if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){
1177                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
1178                 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
1179                 $this->dialogObject->set_snapshot_bases($bases);
1180                 $this->dialogObject->display_all_removed_objects = true;
1181                 $this->dialogObject->display_restore_dialog = true;
1182                 $this->dialogObject->parent = &$this;
1183             }else{
1184                 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
1185                         ERROR_DIALOG);
1186             }
1187         }else{
1189             // Display the restore points for a given object.
1190             $dn = array_pop($target);
1191             $entry = $headpage->getEntry($dn);
1192             $type = $headpage->getType($dn);
1193             if(!isset($pInfo[$type])) {
1194                 trigger_error('Unknown system type \''.$type.'\'!');
1195                 return;
1196             }
1198             if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1199                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!");
1200                 $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1201                 $this->dialogObject->set_snapshot_bases($bases);
1202                 $this->dialogObject->display_restore_dialog = true;
1203                 $this->dialogObject->parent = &$this;
1204             }else{
1205                 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn),
1206                         ERROR_DIALOG);
1207             }
1208         }
1209     }
1212     /*! \brief  Restores a snapshot object.
1213      *          The dn of the snapshot entry has to be given as ['target'] parameter.
1214      *
1215      *  @param  String  'action'  The name of the action which was the used as trigger.
1216      *  @param  Array   'target'  A list of object dns, which should be affected by this method.
1217      *  @param  Array   'all'     A combination of both 'action' and 'target'.
1218      */
1219     function restoreSnapshot($action="",$target=array(),$all=array())
1220     {
1221         $dn       = array_pop($target);
1222         $this->snapHandler->restore_snapshot($dn);
1223         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!");
1224         $this->closeDialogs();
1225     }
1228     /*! \brief  Detects actions/events send by the ui
1229      *           and the corresponding targets.
1230      */
1231     function detectPostActions()
1232     {
1233         $action= management::detectPostActions();
1234         if(isset($_POST['abort_event_dialog']))  $action['action'] = "cancel";
1235         if(isset($_POST['save_event_dialog']))  $action['action'] = "saveEvent";
1236         if(isset($_POST['cd_create']))  $action['action'] = "initiateISOcreation";
1237         if(isset($_GET['PerformIsoCreation']))  $action['action'] = "performIsoCreation";
1238         if(isset($_POST['SystemTypeAborted']))  $action['action'] = "cancel";
1239         if(isset($_POST['password_cancel']))  $action['action'] = "cancel";
1240         if(isset($_POST['password_finish']))  $action['action'] = "passwordChangeConfirmed";
1242         if(isset($_POST['new_goServer']))  $action['action'] = "new_goServer";
1243         if(isset($_POST['new_gotoWorkstation']))  $action['action'] = "new_gotoWorkstation";
1244         if(isset($_POST['new_gotoTerminal']))  $action['action'] = "new_gotoTerminal";
1245         if(isset($_POST['new_gotoPrinter']))  $action['action'] = "new_gotoPrinter";
1246         if(isset($_POST['new_goFonHardware']))  $action['action'] = "new_goFonHardware";
1247         if(isset($_POST['new_ieee802Device']))  $action['action'] = "new_ieee802Device";
1248         if(isset($_POST['new_FAKE_OC_OpsiHost']))  $action['action'] = "new_FAKE_OC_OpsiHost";
1250         if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
1251             if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
1252         }
1254         if(isset($_POST['systemTypeChosen']))  $action['action'] = "systemTypeChosen";
1256         return($action);
1257     }
1260     /*! \brief   Overridden render method of class management.
1261      *            this allows us to add a release selection box.
1262      */
1263     function renderList()
1264     {
1265         $headpage = $this->getHeadpage();
1266         $headpage->update();
1268         $tD = $this->getObjectDefinitions();
1269         $smarty = get_smarty();
1270         foreach($tD as $name => $obj){
1271             $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
1272         }
1274         $display = $headpage->render();
1275         return($this->getHeader().$display);
1276     }
1279     public function getObjectDefinitions()
1280     {
1281         $tabs = array(
1282                 "device" => array(
1283                     "ou"          => get_ou('Device','GOsaDeviceRDN'),
1284                     "plugClass"   => "Device",
1285                     "tabClass"    => "DeviceTab",
1286                     "tabDesc"     => "NEWDEVICETABS",
1287                     "aclClass"    => "Device",
1288                     "sendEvents"  => FALSE,
1289                     "aclCategory" => "Device"),
1291                 "FAKE_OC_OpsiHost" => array(
1292                     "ou"          => "",
1293                     "plugClass"   => "opsiGeneric",
1294                     "tabClass"    => "opsi_tabs",
1295                     "tabDesc"     => "OPSITABS",
1296                     "aclClass"    => "opsiGeneric",
1297                     "sendEvents"  => TRUE,
1298                     "aclCategory" => "opsi"),
1300                 "goServer" => array(
1301                     "ou"          => get_ou("servgeneric", "serverRDN"),
1302                     "plugClass"   => "servgeneric",
1303                     "tabClass"    => "servtabs",
1304                     "tabDesc"     => "SERVTABS",
1305                     "aclClass"    => "servgeneric",
1306                     "sendEvents"  => TRUE,
1307                     "aclCategory" => "server"),
1309                 "gotoWorkstation" => array(
1310                     "ou"          => get_ou("workgeneric", "workstationRDN"),
1311                     "plugClass"   => "workgeneric",
1312                     "tabClass"    => "worktabs",
1313                     "tabDesc"     => "WORKTABS",
1314                     "aclClass"    => "workgeneric",
1315                     "sendEvents"  => TRUE,
1316                     "aclCategory" => "workstation"),
1318                 "gotoTerminal" => array(
1319                         "ou"          => get_ou("termgeneric", "terminalRDN"),
1320                         "plugClass"   => "termgeneric",
1321                         "tabClass"    => "termtabs",
1322                         "sendEvents"  => TRUE,
1323                         "tabDesc"     => "TERMTABS",
1324                         "aclClass"    => "termgeneric",
1325                         "aclCategory" => "terminal"),
1327                 "gotoPrinter" => array(
1328                         "ou"          => get_ou("printgeneric", "printerRDN"),
1329                         "plugClass"   => "printgeneric",
1330                         "tabClass"    => "printtabs",
1331                         "tabDesc"     => "PRINTTABS",
1332                         "aclClass"    => "printgeneric",
1333                         "sendEvents"  => FALSE,
1334                         "aclCategory" => "printer"),
1336                 "FAKE_OC_NewDevice" => array(
1337                         "ou"          => get_ou("ArpNewDevice", "systemIncomingRDN"),
1338                         "plugClass"   => "termgeneric",
1339                         "tabClass"    => "termtabs",
1340                         "sendEvents"  => TRUE,
1341                         "tabDesc"     => "TERMTABS",
1342                         "aclClass"    => "termgeneric",
1343                         "aclCategory" => "terminal"),
1345                 "goFonHardware" => array(
1346                         "ou"          => get_ou("phoneGeneric", "phoneRDN"),
1347                         "plugClass"   => "phoneGeneric",
1348                         "tabClass"    => "phonetabs",
1349                         "tabDesc"     => "PHONETABS",
1350                         "sendEvents"  => FALSE,
1351                         "aclClass"    => "phoneGeneric",
1352                         "aclCategory" => "phone"),
1354                 "FAKE_OC_winstation" => array(
1355                         "ou"          => get_winstations_ou(),
1356                         "plugClass"   => "wingeneric",
1357                         "sendEvents"  => TRUE,
1358                         "tabClass"    => "wintabs",
1359                         "tabDesc"     => "WINTABS",
1360                         "aclClass"    => "wingeneric",
1361                         "aclCategory" => "winworkstation"),
1363                 "ieee802Device" => array(
1364                         "ou"          => get_ou("componentGeneric", "componentRDN"),
1365                         "plugClass"   => "componentGeneric",
1366                         "sendEvents"  => FALSE,
1367                         "tabClass"    => "componenttabs",
1368                         "tabDesc"     => "COMPONENTTABS",
1369                         "aclClass"    => "componentGeneric",
1370                         "aclCategory" => "component"),
1371                 );
1373         // Now map some special types
1374         $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
1375         $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
1376         $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
1377         $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
1378         $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
1379         $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
1380         $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
1381         $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
1382         $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
1383         $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal'];
1384         $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal'];
1385         $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
1386         $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
1387         $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
1389         $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
1392         // Remove those types, we cannot handle at the moment due to lack of 
1393         //  installed GOsa-plugins.
1394         foreach($tabs as $name => $tab){
1396             if(!class_available($tab['plugClass'])) {
1397                 unset($tabs[$name]);
1398             }
1399         }
1401         return($tabs);
1402     }
1405     static function filterSystemDescription($row,$dn,$pid,$state = '',$description=array())
1406     {
1407         $dn= LDAP::fix(func_get_arg(1));
1408         $desc = isset($description[0])?set_post($description[0]):"";
1409     
1410         $rc = "";
1411         switch($state){
1412             case 'locked' : $rc = "<rowClass:entry-locked/><rowLabel:locked/>"; break;
1413             case 'error' : $rc = "<rowClass:entry-error/><rowLabel:error/>"; break;
1414             case 'busy' : $rc = "<rowClass:entry-busy/><rowLabel:busy/>"; break;
1415             case 'warning' : $rc = "<rowClass:entry-warning/><rowLabel:warning/>"; break;
1416         }
1417         return("<a href='?plug=".$_GET['plug']."&amp;PID={$pid}&amp;act=listing_edit_{$row}' title='{$dn}'>".$desc."</a>{$rc}");
1418     }
1421     static function filterLink()
1422     {
1423         $result= "&nbsp;";
1424         $row= func_get_arg(0);
1425         $pid= func_get_arg(4);
1426         $dn= LDAP::fix(func_get_arg(1));
1427         $params= array(func_get_arg(2));
1429         // Collect sprintf params
1430         for ($i = 3;$i < func_num_args();$i++) {
1431             $val= func_get_arg($i);
1432             if (is_array($val)){
1433                 $params[]= $val[0];
1434                 continue;
1435             }
1436             $params[]= $val;
1437         }
1439         $result= "&nbsp;";
1440         $trans= call_user_func_array("sprintf", $params);
1441         if ($trans != "") {
1442             return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>".$trans."</a>");
1443         }
1444         return $result;
1445     }
1448     static function systemRelease($a,$b,$c,$objectclasses= null,$class= null)
1449     {
1450         global $config;
1452         // No objectclasses set - go ahead
1453         if(!$objectclasses) return("&nbsp;");
1455         // Skip non fai objects
1456         if (!in_array_ics("FAIobject", $objectclasses)) {
1457             return "&nbsp;";
1458         }
1460         // If we've an own fai class, just use this
1461         if ($class && is_array($class)) {
1462             foreach (explode(' ', $class[0]) as $element) {
1463                 if ($element[0] == ":") {
1464                     return "&nbsp;".image('images/empty.png')."&nbsp;".mb_substr($element, 1);
1465                 }
1466             }
1467         }
1469         // Load information if needed
1470         $ldap = $config->get_ldap_link();
1471         $ldap->cd($config->current['BASE']);
1472         $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn'));
1473         while($attrs = $ldap->fetch()){
1474             $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]);
1475             $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]);
1476             $str = "&nbsp;".image('plugins/ogroups/images/ogroup.png', "", $sys)."&nbsp;".$rel;
1477             return($str);
1478         }
1480         return("&nbsp;");
1481     }
1484     /*! \brief  !! Incoming dummy acls, required to defined acls for incoming objects
1485      */
1486     static function plInfo()
1487     {
1488         return (array(
1489                     "plShortName"   => _("Incoming objects"),
1490                     "plDescription" => _("Incoming objects"),
1491                     "plSelfModify"  => FALSE,
1492                     "plDepends"     => array(),
1493                     "plPriority"    => 99,
1494                     "plSection"     => array("administration"),
1496                     "plProperties" =>
1497                     array(
1498                         array(
1499                             "name"          => "systemRDN",
1500                             "type"          => "rdn",
1501                             "default"       => "ou=systems,",
1502                             "description"   => _("RDN for system storage."),
1503                             "check"         => "gosaProperty::isRdn",
1504                             "migrate"       => "migrate_systemRDN",
1505                             "group"         => "plugin",
1506                             "mandatory"     => FALSE
1507                             )
1508                         ),
1511             "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"))),
1512             "plProvidedAcls"=> array()
1513                 ));
1514     }
1515
1516 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1517 ?>