Code

9e0862d0b975ef2d7b6163a72246e6a540ef9824
[gosa.git] / trunk / gosa-plugins / systems / admin / systems / class_systemManagement.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class systems extends plugin
24 {
25   /* Definitions */
26   var $plHeadline     = "Systems";
27   var $plDescription  = "This does something";
28   var $plIcon         = "plugins/systems/images/plugin.png";
29   var $departments    = array();
31   /* Dialog attributes */
32   var $systab   = NULL;
33   var $terminals= array();
34   var $ui       = NULL;
35   var $DivListSystem;
36   var $start_pasting_copied_objects = FALSE;
37   var $CopyPasteHandler   = NULL;
39   /* Arp hanlding activated */
40   var $arp_handling_active = FALSE;
41   var $last_action = "";
43   var $dns = array();
45   var $system_activation_object = ""; // The object to activate (NewDevice)
46   var $fai_activated  = FALSE;
47   var $si_active      = FALSE;
49   var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
51   var $opsi = NULL;
53   function systems (&$config, $ui)
54   {
55     /* Save configuration for internal use */
56     $this->config= $config;
57     $this->ui= $ui;
59     /* Add FAIstate to attributes if FAI is activated */
60     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
61     if(!empty($tmp)){
62       $this->fai_activated = TRUE;
63     }
65     /* Copy & Paste enabled ?*/
66     if ($this->config->get_cfg_value("copyPaste") == "true"){
67       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
68     }
70     /* Check whether the arp handling active or not */
71     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
72       $this->arp_handling_active = TRUE;
73     }
75     /* Check if we are able to communicate with the GOsa supprot daemon 
76      */
77     if(class_available("gosaSupportDaemon")){
78       $o = new gosaSupportDaemon();
79       $this->si_active = $o->connect() && class_available("DaemonEvent");
80     }
82     /* Check if we are able to communicate with the GOsa supprot daemon 
83      */
84     if(class_available("opsi")){
85       $this->opsi = new opsi($this->config);
86     }
88     /* Creat dialog object */
89     $this->DivListSystem = new divListSystem($this->config,$this);
90   }
93   function execute()
94   {
95     /* Call parent execute */
96     plugin::execute();
98     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
100     /********************
101       Check for functional posts, edit|delete|add|... system devices 
102      ********************/
103     $s_action     = "";                       // Contains the action to proceed
104     $s_entry      = "";                       // The value for s_action
105     $base_back    = "";                       // The Link for Backbutton
106     $smarty       = get_smarty();
108     /* Test Posts */
109     foreach($_POST as $key => $val){
110       // Post for delete
111       if(preg_match("/system_del.*/",$key)){
112         $s_action = "del";
113         $s_entry  = preg_replace("/system_del_/i","",$key);
114         // Post for edit
115       }elseif(preg_match("/system_edit_.*/",$key)){
116         $s_action="edit";
117         $s_entry  = preg_replace("/system_edit_/i","",$key);
118         // Post for new
119       }elseif(preg_match("/system_new.*/",$key)){
120         $s_action="new";
121       }elseif(preg_match("/system_tplnew.*/i",$key)){
122         $s_action="new_tpl";
123       }elseif(preg_match("/system_setpwd_.*/i",$key)){
124         $s_action="change_pw";
125         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
126       }elseif(preg_match("/gen_cd_.*/i",$key)){
127         $s_action="gen_cd";
128         $s_entry  = preg_replace("/gen_cd_/i","",$key);
129       }elseif(preg_match("/^copy_.*/",$key)){
130         $s_action="copy";
131         $s_entry  = preg_replace("/^copy_/i","",$key);
132       }elseif(preg_match("/^cut_.*/",$key)){
133         $s_action="cut";
134         $s_entry  = preg_replace("/^cut_/i","",$key);
135       }
136     }
137    
138     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
139     $s_entry  = preg_replace("/_.$/","",$s_entry);
141     /* Edit was requested by pressing the name(link) of an item */
142     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
143       $s_action ="edit";
144       $s_entry  = $_GET['id'];
145     }
146     /* Create options */
147     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
148       $s_action = "newsystem";
149       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
150     }
152     /* handle C&P from layers menu */
153     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
154       $s_action = "copy_multiple";
155     }
156     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
157       $s_action = "cut_multiple";
158     }
159     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
160       $s_action = "editPaste";
161     }
163     /* Handle daemon events */
164     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
165       $s_action = $_POST['menu_action'];
166     }
167     
168     /* Handle daemon events */
169     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
170       $s_action = $_POST['menu_action'];
171     }
173     /* handle remove from layers menu */
174     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
175       $s_action = "del_multiple";
176     }
177     
178     /* Handle instant actions from layers menu */
179     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
180             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
181               $s_action = "${act}_multiple";
182             }
183     }
185     /* Activate multiple machines */
186     if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
187       $s_action = "activate_multiple";
188     }
190     /* Check for exeeded sizelimit */
191     if (($message= check_sizelimit()) != ""){
192       return($message);
193     }
195     /* Try to get informations about what kind of system to create */
196     if ($s_action=="new") {
197       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
198     }
200     /* Incoming handling  
201      * If someone made a systemtype and ogroup selection 
202      * Display the new requested entry type ... servtab  in case of server and so on.
203      */
204     if(isset($_POST['SystemTypeChoosen'])){
205       $s_action = "SelectedSystemType";
206     }
208     /********************
209       Copy & Paste Handling  ...
210      ********************/
212     /* Display the copy & paste dialog, if it is currently open */
213     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
214     if($ret){
215       return($ret);
216     }
217   
219     /********************
220       Create FAI CD ...   
221      ********************/
222     if ($s_action=="gen_cd"){
223       $this->dn= $this->terminals[$s_entry]['dn'];
224       set_object_info($this->dn);
225       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
226     }
229     /* Start CD-Creation */
230     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
231       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
232       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
233     }
236     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
238       $return_button   = "<form method='get' action='main.php' target='_parent'>
239         <input type='submit' value='"._("Back")."'>
240         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
241         </form>";
243       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
245       /* Get and check command */
246       $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
247       
248       if (check_command($command)){
249         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
251         /* Print out html introduction */
252         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
253           <html>
254           <head>
255           <title></title>
256           <style type="text/css">@import url("themes/default/style.css");</style>
257           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
258           </head>
259           <body style="background: none; margin:4px;" id="body" >
260           <pre>';
262         /* Open process handle and check if it is a valid process */
263         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
264         if (is_resource($process)) {
265           fclose($pipes[0]);
267           /* Print out returned lines && write JS to scroll down each line */
268           while (!feof($pipes[1])){
269             $cur_dat = fgets($pipes[1], 1024);
270             echo $cur_dat;
271             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
272             flush();
273           }
274         }
276         /* Get error string && close streams */
277         $buffer= stream_get_contents($pipes[2]);
279         fclose($pipes[1]);
280         fclose($pipes[2]);
281         echo "</pre>";
283         /* Check return code */
284         $ret= proc_close($process);
285         if ($ret != 0){
286           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
287           echo "<pre style='color:red'>$buffer</pre>";
288         }
292         echo $return_button."<br>";
294       } else {
295         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
296         echo $tmp;
297       }
299       /* Scroll down completly */
300       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
301       echo '</body></html>';
302       flush();
303       exit;
304     }
307     /********************
308       New Device handling  (Ogroup/System select dialog.)
309      ********************/
311     /*  All objects that have to be activated are listed in 
312           $this->system_activation_object[] = "dn";
313       
314         If there is an object group selected we simply adopt all
315          settings from these group and then directly save the entry again.
316         If no object group was selected, then we keep the "edit" dialog of 
317          the target system opened to allow to edit the objects attributes.
318      */
319   
320     if($s_action == "SelectedSystemType"){
322       /* Possible destination system types 
323        */
324       $tabs = $this->get_tab_defs();
326       /* Remember dialog selection.
327        */
328       $selected_group = $_POST['ObjectGroup'];
329       $selected_system = $_POST['SystemType'];
331       $this->systab = NULL;
333       /* Check if system type exists. It should! */
334       if(isset($tabs[$selected_system])){
336         /* Get tab informations */
337         $class    = $tabs[$selected_system]["CLASS"];
338         $tabname  = $tabs[$selected_system]["TABNAME"];
339         $tabclass = $tabs[$selected_system]["TABCLASS"];
340         $acl_cat  = $tabs[$selected_system]["ACLC"];
343         if(!class_available($tabclass)){
344           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
345         }else{
347           /* Go through all objects that should be activated 
348               Contains alls object dns that have to be activated ("New Devices" not unknown)
349             */
350           foreach($this->system_activation_object as $key => $dn){
352             /* Remove entry from list, to avoid page-reload problems */
353             unset($this->system_activation_object[$key]);
355             /* Load permissions for selected 'dn' and check if
356                we're allowed to create this 'dn' */
357             $this->dn = $dn;
358             $ui       = get_userinfo();
359             $tabacl   = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
361             /* We are allowed to create the requested system type */
362             if(preg_match("/c/",$tabacl)){
363               $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
364               $this->systab->set_acl_base($this->DivListSystem->selectedBase);
365               $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
366               $this->systab->base = $this->DivListSystem->selectedBase;
368               /* This will be used when the object is saved, to set FAIstate to 'install'
369                   and to preset maybe other attributes.
370                */
371               $this->systab->was_activated = TRUE;
373               /* Assign some default values for opsi hosts 
374                */
375               if($this->systab instanceOf opsi_tabs){
376                 $ldap = $this->config->get_ldap_link();
377                 $ldap->cat($dn);
378                 $source_attrs = $ldap->fetch();
379                 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
380                   if(isset($source_attrs[$src][0])){
381                     $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
382                   }
383                 }
384               }
386               if($selected_group != "none"){
388                 /*******
389                  * Set gotoMode to active if there was an ogroup selected. 
390                  */
391                 $found = false;
392                 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
393                   if(isset($this->systab->by_object[$tab]->gotoMode)) {
394                     $found = true;
395                     $this->systab->by_object[$tab]->gotoMode = $value;
396                   }
397                 }
398                 if(!$found){
399                   msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
400                 }
402                 /*******
403                  * Update object group membership
404                  */
405                 $og = new ogroup($this->config,$selected_group);
406                 if($og){
407                   $og->AddDelMembership($this->systab->dn);
408                   $og->save();
409                 }
411                 /*******
412                  * Enable inheritance
413                  */
414                 foreach (array("workgeneric", "termgeneric") as $cls){
415                   if (isset($this->systab->by_object[$cls])){
416                     $this->systab->by_object[$cls]->member_of_ogroup = true;
417                     $this->systab->by_object[$cls]->set_everything_to_inherited();
418                     $this->systab->by_object[$cls]->save();
419                   }
420                 }
422                 // Enable activation
423                 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
424                   if (isset($this->systab->by_object[$cls])){
425                     $this->systab->by_object[$cls]->auto_activate= TRUE;
426                   }
427                 }
428               }
430               /* Don't save directly if there is no objectGroup selected.
431                  The user will then be able to configure the missing attributes 
432                  on his own.
433                */
434               if($selected_group != "none"){
435                 $this->systab->save();
436     
437                 /* Post handling for activated new devices 
438                  */
439                 $this->activate_new_device($this->systab->dn);
440                 $this->systab = NULL;
442                 if(!isset($ldap)){
443                   $ldap = $this->config->get_ldap_link();
444                 }
445                 $ldap->cd ($this->dn);
446                 $ldap->cat($this->dn, array('dn'));
447                 if(count($ldap->fetch())){
448                   $ldap->cd($this->dn);
449                   $ldap->rmDir($this->dn);
450                 }
451               }
452             }else{
453               msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
454             }
455           }
456         }
457       }
458     }
461     if (isset($_POST['create_system'])||$s_action=="newsystem") {
462     
463       $this->last_action = "";
464   
465       /* If the current entry is an incoming object 
466        * $sw = System type as posted in new incoming handling dialog 
467        */ 
468       if(isset($_POST['system'])){
469         $sw = $_POST['system'];
470       }else{
471         $sw = $s_entry;
472       }
473       $this->dn= "new";
475       $tabs = $this->get_tab_defs();
476   
477       if(isset($tabs[$sw])){
478         $class    = $tabs[$sw]["CLASS"];
479         $tabname  = $tabs[$sw]["TABNAME"];
480         $tabclass = $tabs[$sw]["TABCLASS"];
481         $acl_cat  = $tabs[$sw]["ACLC"];
483         /* Load permissions for selected 'dn' and check if
484            we're allowed to remove this 'dn' */
485         $ui       = get_userinfo();
486         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
487         if(preg_match("/c/",$tabacl)){
489           if(!class_available($tabclass)){
490             msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
491           }else{
492             $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
493             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
494             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
495             $this->systab->base = $this->DivListSystem->selectedBase;
496           }
497         }else{
498           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
499         }
500       }
501     }
503     /********************
504       System activation
505      ********************/
507     /* User wants to edit data? */
508     if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
509       $this->system_activation_object = array();
510       foreach($this->list_get_selected_items() as $id) {
511         $obj = $this->terminals[$id];
512         $type= $this->get_system_type($obj);
513         if($type == "NewDevice"){
514           $this->system_activation_object[] = $obj['dn'];
515         }
516       }
517       if(count($this->system_activation_object)){
518         $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
519       }
520     }
523     /********************
524       Edit system ...   
525      ********************/
527     /* User wants to edit data? */
528     if (($s_action == "edit") && (!isset($this->systab->config))){
529       $this->last_action = "";
530       $this->dn= $this->terminals[$s_entry]['dn'];
532       /* Check locking, save current plugin in 'back_plugin', so
533          the dialog knows where to return. */
534       if (($user= get_lock($this->dn)) != ""){
535         return(gen_locked_message ($user, $this->dn,TRUE));
536       }
538       /* Find out more about the object type */
539       $attrs = $this->terminals[$s_entry];
540       $type= $this->get_system_type($attrs);
541      
542       /* Lock the current entry, so everyone will get the
543          above dialog */
544       $tabs = $this->get_tab_defs();
546       if($type == "ArpNewDevice"){
547         if(!class_available("ArpNewDeviceTabs")){
548           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
549         }else{
550           add_lock ($this->dn, $this->ui->dn);
551           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
552         }
553       }elseif($type == "NewDevice"){
554         if(!class_available("SelectDeviceType")){
555           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
556         }else{
557           add_lock ($this->dn, $this->ui->dn);
558           $this->system_activation_object= array($this->dn);
559           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
561           // see condition  -$s_action == "SelectedSystemType"-  for further handling
562         }
563       }elseif(isset($tabs[$type])){
565         $class    = $tabs[$type]["CLASS"];
566         $acl_cat  = $tabs[$type]["ACLC"];
567         $tabclass = $tabs[$type]["TABCLASS"];
569         if(!class_available($tabclass)){
570           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
571         }else{
572           add_lock ($this->dn, $this->ui->dn);
573           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
574           $this->systab->set_acl_base($this->dn);
575           set_object_info($this->dn);
576         }
577       }else{ 
578         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
579         $this->remove_lock();
580       }
581     }
584     /********************
585       Change password ...   
586      ********************/
588     /* Set terminals root password */
589     if ($s_action=="change_pw"){
590       $tabs = $this->get_tab_defs();
592       $dn   = $this->terminals[$s_entry]['dn'];
593       $type = $this->get_system_type($this->terminals[$s_entry]);
595       $class    = $tabs[$type]["CLASS"];
596       $acl      = $tabs[$type]["ACL"];
597       $tabclass = $tabs[$type]["TABCLASS"];
598       $ui       = get_userinfo();
599       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
600       if(preg_match("/w/",$tabacl)){
601         $this->dn= $this->terminals[$s_entry]['dn'];
602         set_object_info($this->dn);
603         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
604       }else{
605         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
606       }
607     }
610     /********************
611       Password change finish, but check if entered data is ok 
612      ********************/
614     /* Correctly specified? */
615     if (isset($_POST['password_finish'])){
616       if ($_POST['new_password'] != $_POST['repeated_password']){
617         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
618         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
619       }
620     }
622     /********************
623       Password change finish
624      ********************/
626     /* Change terminal password */
627     if (isset($_POST['password_finish']) && 
628         $_POST['new_password'] == $_POST['repeated_password']){
630       /* Check if user is allowed to set password */
631       $tabs = $this->get_tab_defs();
633       $type = "";
634       foreach($this->terminals as $terminal){
635         if($terminal['dn'] == $this->dn){
636           $type  = $this->get_system_type($terminal);
637           break;
638         } 
639       }
641       /* Type detected */
642       $allow_for = array("terminal","workstation","server","component");
643       if(!empty($type) && in_array($type,$allow_for)){
645         /* Get infos */
646         $plug     = $tabs[$type]["TABNAME"];
647         $acl      = $tabs[$type]["ACL"];
648         $tabclass = $tabs[$type]["TABCLASS"];
649    
650         /* Get acls */
651         $ui       = get_userinfo();
652         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
654         /* Check acls */
655         if(preg_match("/w/",$tabacl)){
656           $ldap = $this->config->get_ldap_link();
657           $ldap->cd($this->dn);
658           $ldap->cat($this->dn);
659           $old_attrs = $ldap->fetch();
661           $attrs= array();
662           if ($_POST['new_password'] == ""){
664             /* Remove password attribute 
665              */
666             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
667               $attrs['objectClass'] = array();
668               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
669                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
670                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
671                 }
672               }
673             }
674             $attrs['userPassword']= array();
675           } else {
677             /* Add/modify password attribute 
678              */
679             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
680               $attrs['objectClass'] = array();
681               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
682                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
683               }
684               $attrs['objectClass'][] = "simpleSecurityObject";
685             }
687             if(class_available("passwordMethodCrypt")){
688               $pwd_m = new passwordMethodCrypt($this->config);
689               $pwd_m->set_hash("crypt/md5");
690               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
691             }else{
692               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
693               $attrs = array();
694             }
695           }
696           $ldap->modify($attrs);
697           if (!$ldap->success()){
698             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
699           }else{
700             if(class_available($plug)){ 
701               $p = new $plug($this->config,$this->dn);
702               $p->handle_post_events("modify");
703             }
704           }
705   
706           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
707         }else{
708           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
709         }
710       }else{
711         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
712       }
713       set_object_info();
714     }
717     /********************
718       Delete system cancel
719      ********************/
721     /* Delete terminal canceled? */
722     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
723       $this->remove_lock();
724       set_object_info();
725     }
728     /********************
729       Action(s) for MULTIPLE
730      ********************/
732     /********************
733       SCHEDULE action in GOsa Daemon
734      ********************/
736     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
737       $this->dns = array();
738       $ids = $this->list_get_selected_items();
740       /* Handle opsi actions */
741       if($s_action == "trigger_event_DaemonEvent_reinstall"){
742         foreach($ids as $key => $id){
743           if($this->terminals[$id]['type'] == "O"){
744             $obj = $this->terminals[$id];
745             $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
746             unset($ids[$key]);
747           }
748         }
749       }
751       if(count($ids) && class_available("DaemonEvent")){
752         $mac= array();
754         /* Collect target mac addresses */
755         $ldap = $this->config->get_ldap_link();
756         foreach($ids as $id){
757           $type = $this->get_system_type($this->terminals[$id]);
758           if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
759           if(isset($this->terminals[$id]['macAddress'][0])){
760             $mac[] = $this->terminals[$id]['macAddress'][0];
761           }else{
762             $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
763             $attrs= $ldap->fetch();
764             if (isset($attrs['macAddress'][0])){
765               $mac[]= $attrs['macAddress'][0];
766             }
767           }
768         }
769         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
770         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
771         $o_queue = new gosaSupportDaemon();
773         /* Skip installation or update trigerred events, 
774          *  if this entry is currently processing.
775          */
776         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
777           foreach($mac as $key => $mac_address){
778             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
780               $entry['STATUS'] = strtoupper($entry['STATUS']);
781               if($entry['STATUS'] == "PROCESSING" && 
782                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
783                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
784                 unset($mac[$key]);
786                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
787                 break;
788               }
789             }
790           }
791         }        
793         /* Prepare event to be added 
794          */
795         if(count($mac) && isset($events['BY_CLASS'][$type])){
796           $event = $events['BY_CLASS'][$type];
797           $this->systab = new $event['CLASS_NAME']($this->config);
798           $this->systab->add_targets($mac);
799           if(preg_match("/trigger_event/",$s_action)){
800             $this->systab->set_type(TRIGGERED_EVENT);
801           }else{
802             $this->systab->set_type(SCHEDULED_EVENT);
803           }
804         }
805       }
806     }
808     /* Insert scheduled events into queue */
809     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
810       $this->systab->save_object();
812       /* Save event 
813        */
814       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
815         $o_queue = new gosaSupportDaemon();
816         $o_queue->append($this->systab);
817         if($o_queue->is_error()){
818           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
819         }else{
820           $this->systab = FALSE;
821         }
822       }
823       if(isset($_POST['abort_event_dialog'])){
824         $this->systab = FALSE;
825       }
826     }
829     /********************
830       Delete MULTIPLE entries requested, display confirm dialog
831      ********************/
833     if ($s_action=="del_multiple" || $s_action == "del"){
834       $this->dns = array();
836       if($s_action == "del_multiple"){
837         $ids = $this->list_get_selected_items();
838       }else{
839         $ids = array($s_entry);
840       }
842       $ui = get_userinfo();
843       $tabs = $this->get_tab_defs();
845       if(count($ids)){
847         $disallowed = array();
848         foreach($ids as $id){
850           /* Get 'dn' from posted termlinst */
851           $attrs  = $this->terminals[$id];
852           $type   = $this->get_system_type($attrs);
853           $dn     = $attrs['dn'];
854           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
855           if(preg_match("/d/",$acl)){
856             $this->dns[$id] = $dn;
857           }else{
858             $disallowed[] = $dn;
859           }
860         }
862         if(count($disallowed)){
863           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
864         }
866         if(count($this->dns)){
868           if ($user= get_multiple_locks($this->dns)){
869             return(gen_locked_message($user,$this->dns));
870           }
872           $dns_names = array();
873           foreach($this->dns as $dn){
874             add_lock ($dn, $this->ui->dn);
875             $dns_names[] = LDAP::fix($dn);
876           }
878           /* Lock the current entry, so nobody will edit it during deletion */
879           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
880           $smarty->assign("multiple", true);
881           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
882         }
883       }
884     }
887     /********************
888       Delete MULTIPLE entries confirmed
889      ********************/
891     /* Confirmation for deletion has been passed. Users should be deleted. */
892     if (isset($_POST['delete_multiple_system_confirm'])){
894       $ui = get_userinfo();
895       $tabs = $this->get_tab_defs();
897       /* Remove user by user and check acls before removeing them */
898       foreach($this->dns as $key => $dn){
900         /* Get 'dn' from posted termlinst */
901         $attrs    = $this->terminals[$key];
902         $type= $this->get_system_type($attrs);
904         /* get object type */
905         $tabtype  = "termtabs";
906         $tabobj   = "TERMTABS";
907         $tabacl   = "";
908         if(isset($tabs[$type])){
909           $tabtype = $tabs[$type]['TABCLASS'];
910           $tabobj  = $tabs[$type]['CLASS'];
911           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
913           /* Load permissions for selected 'dn' and check if
914              we're allowed to remove this 'dn' */
915           if(preg_match("/d/",$tabacl)){ 
917             /* Delete request is permitted, perform LDAP action */
918             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
919               $this->systab= new termgeneric($this->config, $dn);
920               $this->systab->set_acl_base($dn);
921               $this->systab->set_acl_category("terminal");
922               $this->systab->remove_from_parent();
923             }elseif($tabtype=="phonetabs"){
924               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
925               $this->systab->set_acl_base($dn);
926               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
927             }else{
928               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
929               $this->systab->set_acl_base($dn);
930               $this->systab->delete();
931             }
932             unset ($this->systab);
933             $this->systab= NULL;
935           } else {
936             /* Normally this shouldn't be reached, send some extra
937                logs to notify the administrator */
938             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
939             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
940           }
941         }
943         /* Remove lock file after successfull deletion */
944         $this->remove_lock();
945         $this->dns = array();
946       }
947     }
949     /********************
950       Delete MULTIPLE entries Canceled
951      ********************/
953     /* Remove lock */
954    if(isset($_POST['delete_multiple_system_cancel'])){
956      /* Remove lock file after successfull deletion */
957      $this->remove_lock();
958      $this->dns = array();
959    }
962     /********************
963       Edit system type finished, check if everything went ok
964      ********************/
965     /* Finish user edit is triggered by the tabulator dialog, so
966        the user wants to save edited data. Check and save at this
967        point. */
969     /* Dirty workaround - MSG_DIALOG - OK
970       If a message dialog is shown and we press 'OK'
971        then try to save again.
972      */
973     foreach($_POST as $name => $value){
974       if(preg_match("/^MSG_OK/",$name)){
975         $_POST[$this->last_action] = TRUE;
976       }
977     }
979     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
981       /* If the save routine gets interrupted by a confirm dialog, 
982           store last action so we can trigger it again after 'Ok' was pressed.
983          (This is the case if a system gets modified while it is installing - GOsa si)
984        */
985       $this->last_action = ""; 
986       if(isset($_POST['edit_finish'])){
987         $this->last_action = "edit_finish"; 
988       }elseif(isset($_POST['edit_apply'])){
989         $this->last_action = "edit_apply";
990       }
992       /* Check tabs, will feed message array */
993       $message = $this->systab->check();
995       /* Save, or display error message? */
996       if (count($message) == 0){
997         $this->systab->save();
999         /* Post handling for activated systems 
1000             target opsi -> Remove source.
1001             target gosa -> Activate system.
1002          */
1003         if($this->systab instanceOf opsi_tabs && $this->systab->was_activated){
1004           $ldap = $this->config->get_ldap_link();
1005           $ldap->cd($this->config->current['BASE']);
1006           $ldap->rmdir ($this->systab->dn);
1007           @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1009           $hostId =  $this->systab->by_object['opsiGeneric']->hostId;
1010           $mac    =  $this->systab->by_object['opsiGeneric']->mac;
1011           $this->opsi->job_opsi_activate_client($hostId,$mac);
1013         }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1014           $this->activate_new_device($this->systab->dn);
1015         }
1017         /* Terminal has been saved successfully, remove lock from LDAP. */
1018         if (!isset($_POST['edit_apply'])){
1019           if ($this->dn != "new"){
1020             $this->remove_lock();
1021           }
1023           unset ($this->systab);
1024           $this->systab= NULL;
1025           set_object_info();
1026         }else{
1027       
1028           /* Reinitialize tab */
1029           if($this->systab instanceof tabs){
1030             $this->systab->re_init();
1031           }
1032         }
1033       } else {
1034         /* Ok. There seem to be errors regarding to the tab data,
1035            show message and continue as usual. */
1036         msg_dialog::displayChecks($message);
1037       }
1038     }
1041     /********************
1042       Edit system was canceled 
1043      ********************/
1044     /* Cancel dialogs */
1045     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1046       if (isset($this->systab)){
1047         $this->remove_lock();
1048         unset ($this->systab);
1049       }
1050       $this->systab= NULL;
1051       set_object_info();
1052     }
1054     /********************
1055       Display edit dialog, or some other
1056      ********************/
1058     /* Show tab dialog if object is present */
1059     if (isset($this->systab->config)){
1061       if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1062         $this->systab->save_object();
1063       }
1065       $display= $this->systab->execute();
1067       /* Don't show buttons if tab dialog requests this */
1069       $dialog     = FALSE;
1070       $hide_apply = $this->dn == "new";
1071       $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1072       if(is_object($this->systab) && !isset($this->systab->by_object)){
1073         $dialog = TRUE;
1074         $hide_apply = TRUE;
1075       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1076         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1077         if($dia === TRUE || is_object($dia)){
1078           $dialog = TRUE;
1079         }  
1080       }
1081       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1082         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1083         $dialog = TRUE;
1084       }
1086       if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1087         $display.= "<p style=\"text-align:right\">
1088           <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1089           </p>";
1090       }elseif (!$dialog){
1091         $display.= "<p style=\"text-align:right\">\n";
1092         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1093         $display.= "&nbsp;\n";
1094         if (!$hide_apply){
1095           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1096           $display.= "&nbsp;\n";
1097         }
1098         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1099         $display.= "</p>";
1100       }
1101       return ($display);
1102     }
1104     /* Check if there is a snapshot dialog open */
1105     $base = $this->DivListSystem->selectedBase;
1106     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1107       return($str);
1108     }
1110     /* Display dialog with system list */
1111     $this->DivListSystem->parent = $this;
1112     $this->DivListSystem->execute();
1114     /* Add departments if subsearch is disabled */
1115     if(!$this->DivListSystem->SubSearch){
1117       /* Add FAIstate to attributes if FAI is activated */
1118       if($this->fai_activated){
1119         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1120       }else{
1121         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1122       }
1123     }
1124     $this->reload();
1125     $this->DivListSystem->setEntries($this->terminals);
1126     return($this->DivListSystem->Draw());
1127   }
1130   /* Return departments, that will be included within snapshot detection */
1131   function get_used_snapshot_bases()
1132   {
1133     $tmp = array();
1135     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1137     $tabs = array(
1138         "terminal"        => get_ou('terminalRDN'),
1139         "workstation"     => get_ou('workstationRDN'),
1140         "incoming"        => get_ou('systemIncomingRDN'),
1141         "server"          => get_ou('serverRDN'),
1142         "printer"         => get_ou('printerRDN'),
1143         "phone"           => get_ou('phoneRDN'),
1144         "winworkstation"  => get_winstations_ou(),
1145         "component"       => get_ou('componentRDN')
1146         ); 
1148     foreach($tabs as $acl_cat => $dn){
1150       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1151       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1152         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1153       }
1154     }
1155     return($tmp); 
1156   }
1159   function remove_from_parent()
1160   {
1161     /* Optionally execute a command after we're done */
1162     $this->postremove();
1163   }
1166   /* Save data to object */
1167   function save_object()
1168   {
1169     $this->DivListSystem->save_object();
1170     if(is_object($this->CopyPasteHandler)){
1171       $this->CopyPasteHandler->save_object();
1172     }
1173   }
1176   /* Check values */
1177   function check()
1178   {
1179   }
1182   /* Save to LDAP */
1183   function save()
1184   {
1185   }
1187   function adapt_from_template($dn, $skip= array())
1188   {
1189   }
1191   function password_change_needed()
1192   {
1193   }
1195   function reload()
1196   {
1197     /* some var init */
1198     $ui = get_userinfo();
1199     $res              = array();
1200     $this->terminals  = array();
1201     $userregex        = "";
1202     $opsi_clients     = array();
1204     /* Set base for all searches */
1205     $base=  $this->DivListSystem->selectedBase;
1207     /* Prepare samba class name */
1208     $samba  ="";
1209     if ($this->DivListSystem->ShowWinWorkstations){
1210       if ($this->config->get_cfg_value("sambaversion") == "3"){
1211         $samba= "sambaSamAccount";
1212       } else {
1213         $samba= "sambaAccount";
1214       }
1215     }
1217     /* This array represents the combination between checkboxes and search filters */
1218     $objs = array( 
1219         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverRDN')),
1220         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalRDN')),
1221         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerRDN')),
1222         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentRDN')),
1223         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneRDN')),
1224         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1225         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1227     /* Include the 'Display Systems of user' attribute */ 
1228     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1229       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1230     }
1232     /* Attributes to fetch */
1233     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1234     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1236     /* Add FAIstate to attributes if FAI is activated */
1237     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1238     if(!empty($tmp)){
1239       $sys_attrs[] = "FAIstate";
1240     }    
1242     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1243     foreach($objs as $checkBox => $oc){
1245       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1246         if($this->DivListSystem->SubSearch){
1247           if($oc['CLASS'] != ""){
1248             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1249             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1250             $res = array_merge($res,$new_res);
1251           }
1252         }else{
1253           /* User filter? */
1254           if($oc['CLASS'] != ""){
1255             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")";
1256             /* Decide weither to search in description and CN or only in the CN */
1257             if ($this->DivListSystem->DescSearch) {
1258               $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1259             }
1260             else {
1261               $filter = $filter . "(cn=".$this->DivListSystem->Regex."))";
1262             }
1263             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1264           }
1265         }
1266       } 
1267     }
1269     /* Search for incoming objects */ 
1270     $filter = "(|(&".$userregex."(objectClass=goHard)";
1271     if ($this->DivListSystem->DescSearch) {
1272       $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1273     }
1274     else {
1275       $filter = $filter . "(cn=".$this->DivListSystem->Regex.")))";
1276     }
1277     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$this->config->get_cfg_value('base'),$sys_attrs, GL_SIZELIMIT));
1279     /* Append opsi systems, the opsi extension have to installed.
1280         (Only, if we are allowed to view opsi hosts)
1281      */
1282     if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1283       $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1284       if(preg_match("/r/",$o_acl)){
1285         $opsi_clients = $this->opsi->get_hosts_for_system_management();
1286         if($this->opsi->is_error()){
1287           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1288         }
1289       }
1290     }
1291     
1292     /* Get all gotoTerminal's */
1293     $t_id = 0;
1294     $opsi_map  = array();
1295     foreach ($res as $value){
1297       $tmp= $value['dn'];
1298       $add= "";
1300       /* Extract base */
1301       foreach($objs as $obj){
1302         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1303           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1304         }
1305       }
1307       /* Create a string containing the last part of the department. */
1308       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1309       if(empty($dn_name)){
1310         $dn_name = "/";
1311       }
1313       /* check if current object is a new one */
1314       if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1315         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1316           $add= "- "._("New terminal");
1317         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1318           $add= "- "._("New workstation");
1319         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1320           $add= "- "._("Unknown device");
1321         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1322           $add= "- "._("New Device");
1323         }
1324       } 
1326       /* Detect type of object and create an entry for $this->terminals */
1327       $terminal = array();
1329        if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1331          /* check acl */
1332          $terminal             = $value;
1333          $terminal['type']     = "O";
1335        } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1337         /* check acl */
1338         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1339         if($add != "" || preg_match("/r/",$acl)) {
1340           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1341             $terminal             = $value;
1342             $terminal['type']     = "T";
1343             $terminal['is_new']   = $add;
1344           } else {
1345             $terminal             = $value;
1346             $terminal['type']     = "D";
1347             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1348             $terminal['location'] = array_search($tmp, $this->config->departments); 
1349           }
1350         }
1351       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1353         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1354         if($add != "" || preg_match("/r/",$acl)) {
1355           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1356             $terminal             = $value;
1357             $terminal['type']     = "L";
1358             $terminal['is_new']   = $add;
1359           } else {
1360             $terminal             = $value;
1361             $terminal['type']     = "D";
1362             $terminal['location'] = array_search($tmp, $this->config->departments);
1363             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1364           }
1365 #          if (isset($value["FAIstate"][0])){
1366 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1367 #          }
1368         }
1369       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1370        
1371    
1372         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1373         if($add != "" || preg_match("/r/",$acl)) {
1375           $terminal             = $value;
1376           $terminal['type']     = "P";
1377         }
1378       } elseif (in_array_ics('goServer', $value["objectClass"])){
1380         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1381         if($add != "" || preg_match("/r/",$acl)) {
1383           $terminal             = $value;
1384           $terminal['type']     = "S";
1385 #          if (isset($value["FAIstate"][0])){
1386 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1387 #          }
1388         }
1389       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1391         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1392         if($add != "" || preg_match("/r/",$acl)) {
1394           $terminal             = $value;
1395           $terminal['type']     = "F";
1396         }
1397       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1399         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1400                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1401                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1402         if($add != "" || preg_match("/r/",$acl)) {
1404           $terminal = $value;
1405           $terminal['type']   = "Q";
1406           $terminal['is_new'] = $add;
1407         }
1408       } elseif (in_array_ics('ieee802Device', $value["objectClass"]) && 
1409         !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1410         $type= "winstation";
1411         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1412         if($add != "" || preg_match("/r/",$acl)) {
1414           $terminal             = $value;
1415           $terminal['type']     = "C";
1416         }
1417       } else{
1419         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1420         if (isset($value['sambaDomainName'])){
1421           $domain= " [".$value['sambaDomainName'][0]."]";
1422         } else {
1423           $domain= "";
1424         }
1425         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1426         if($add != "" || preg_match("/r/",$acl)) {
1427           $terminal=$value;
1428           $terminal['type']     ="W";
1429           $terminal['domain']   = $name.$domain;
1430         }
1431       }
1433       /* Append collected data to the host list.
1434        */
1435       if(count($terminal)){
1436         $t_id ++ ;
1437         $this->terminals[$t_id]=$terminal;
1438         $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1439       }
1440     }
1443     /* Merge real hosts with opsi hosts.
1444        If there is a samba host, then merge it with the opsi host,
1445         to avoid duplicate entries.
1446      */
1447     foreach($opsi_clients as $entry){
1448       if(isset($opsi_map[$entry['cn'][0]])){
1449         continue;
1450       }
1451       $terminal             = $entry;
1452       $terminal['type']     = "O";
1453       $this->terminals[] = $terminal;
1454     }
1456     $tmp  =array();
1457     $tmp2 =array();
1458     foreach($this->terminals as $tkey => $val ){
1459       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1460       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1461     }
1462     natcasesort($tmp2);
1463     $this->terminals=array();
1464     foreach($tmp2 as $val){
1465       $this->terminals[]=$tmp[$val];
1466     }
1467     reset ($this->terminals);
1468   }
1470   function remove_lock()
1471   {
1472     if (isset($this->systab->dn)){
1473       del_lock ($this->systab->dn);
1474     }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1475       del_lock($this->dn);
1476     }
1477     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1478       del_lock($this->dns);
1479     }
1480   }
1483   function copyPasteHandling_from_queue($s_action,$s_entry)
1484   {
1485     /* Check if Copy & Paste is disabled */
1486     if(!is_object($this->CopyPasteHandler)){
1487       return("");
1488     }
1490     $ui = get_userinfo();
1491     
1492     $tabs = $this->get_tab_defs();
1494     /* Add a single entry to queue */
1495     if($s_action == "cut" || $s_action == "copy"){
1497       /* Cleanup object queue */
1498       $this->CopyPasteHandler->cleanup_queue();
1499       $dn     = $this->terminals[$s_entry]['dn'];
1500       $oc     = $this->terminals[$s_entry]['objectClass'];
1501       $type   = $this->get_system_type($this->terminals[$s_entry]);
1503       $tab_o  = $tabs[$type]['CLASS'];
1504       $tab_c  = $tabs[$type]['TABCLASS'];
1505       $acl_c  = $tabs[$type]['TABNAME'];
1506       $acl    = $tabs[$type]['ACLC'];
1508       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1509         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1510       }
1511       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1512         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1513       }
1514     }
1516     /* Add entries to queue */
1517     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1519       /* Cleanup object queue */
1520       $this->CopyPasteHandler->cleanup_queue();
1522       /* Add new entries to CP queue */
1523       foreach($this->list_get_selected_items() as $id){
1524         $dn = $this->terminals[$id]['dn'];
1525         $oc = $this->terminals[$id]['objectClass']; 
1526         $type = $this->get_system_type($this->terminals[$id]);
1528         if(isset($tabs[$type])){
1529           $tab_o  = $tabs[$type]['CLASS'];
1530           $tab_c  = $tabs[$type]['TABCLASS'];
1531           $acl_c  = $tabs[$type]['TABNAME'];
1532           $acl    = $tabs[$type]['ACLC'];
1534           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1535             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1536           }
1537           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1538             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1539           }
1540         }
1541       }
1542     }
1544     /* Start pasting entries */
1545     if($s_action == "editPaste"){
1546       $this->start_pasting_copied_objects = TRUE;
1547     }
1548   
1549     /* Return C&P dialog */
1550     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1552       /* Get dialog */
1553       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1554       $data = $this->CopyPasteHandler->execute();
1556       /* Return dialog data */
1557       if(!empty($data)){
1558         return($data);
1559       }
1560     }
1562     /* Automatically disable status for pasting */
1563     if(!$this->CopyPasteHandler->entries_queued()){
1564       $this->start_pasting_copied_objects = FALSE;
1565     }
1566     return("");
1567   }
1570   function get_system_type($attrs)
1571   {
1572     $classes = $attrs['objectClass'];
1574     $type= "";
1575     if (in_array_ics('gosa_opsi_client', $classes)){
1576       $type= "opsi_client";
1577     }elseif (in_array_ics('sambaAccount', $classes) ||
1578         in_array_ics('sambaSamAccount', $classes)){
1579       $type= "winstation";
1580     }elseif (in_array_ics('ieee802Device', $classes)){
1581       $type= "component";
1582     }elseif (in_array_ics('gotoTerminal', $classes)){
1583       $type= "terminal";
1584     }elseif (in_array_ics('gotoWorkstation', $classes)){
1585       $type= "workstation";
1586     }elseif (in_array_ics('gotoPrinter', $classes)){
1587       $type= "printer";
1588     }elseif (in_array_ics('goFonHardware', $classes)){
1589       $type= "phone";
1590     }elseif (in_array_ics('goServer', $classes)){
1591       $type= "server";
1592     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1593       $type= "ArpNewDevice";
1594     }elseif (in_array_ics('GOhard', $classes)){
1595       $type= "NewDevice";
1596     }
1597     return ($type);
1598   }
1601   function convert_list($input)
1602   {
1603     $temp= "";
1605     $conv= array(
1606         "D" => array("plugins/systems/images/select_default.png",_("Template")),
1607         "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1608         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1609         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1611         "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1613         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1614         "S" => array("plugins/systems/images/select_server.png",_("Server")),
1615         "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1617         "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1618         "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1619         "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1621         "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1622         "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1623         "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1625         "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1626         "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1628         "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1629         "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1630         "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1632     /* Add opsi client to system types */
1633     if($this->opsi != NULL){
1634         $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1635     }
1637     /* Use locked icons 
1638      */
1639     if( in_array($input['type'],array("S","T","L")) && 
1640         isset($input['gotoMode'][0]) && 
1641         preg_match("/locked/",$input['gotoMode'][0])){
1642       $input['type'].="X";
1643     } elseif(in_array($input['type'],array("S","L")) &&
1644         isset($input['FAIstate'][0])){
1646     /* Add FAI state icons 
1647      */
1648       $type= "";
1649       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1650         case 'error':
1651           $type= 'E';
1652           break;
1653         case 'installing':
1654         case 'install':
1655         case 'sysinfo':
1656         case 'softupdate':
1657         case 'scheduledupdate':
1658           $type= 'B';
1659           break;
1660       }
1662       $input['type'].= $type;
1663     }   
1665     /* Use new images if object is from incoming 
1666      */
1667     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1668       $input['type']="N".$input['type'];
1669     }
1671     /* Check which flags this objects uses 
1672      */
1673     foreach ($conv  as $key => $value){
1674       $found = TRUE;
1675       if(strlen($key) != strlen($input['type'])) {
1676         $found = FALSE;
1677       }
1678       for($i = 0 ; $i < strlen($key) ; $i++){
1679         if(!preg_match("/".$key[$i]."/",$input['type'])){
1680           $found = FALSE;
1681         }
1682      }
1684       if($found){
1685         $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1686         $tmp['class']=$key;
1687         return $tmp;
1688       }
1689     }
1690   }
1693   function list_get_selected_items()
1694   {
1695     $ids = array();
1696     foreach($_POST as $name => $value){
1697       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1698         $id   = preg_replace("/^item_selected_/","",$name);
1699         $ids[$id] = $id;
1700       }
1701     }
1702     return($ids);
1703   }
1706   public function get_tab_defs()
1707   {
1708     $tabs = array(
1709         "incoming"    => array(
1710           "CLASS"     => "",
1711           "TABNAME"   => "",
1712           "TABCLASS"  => "",
1713           "ACLC"      => "incoming",
1714           "ACL"       => "incoming/systems"),
1716         "ArpNewDevice"=> array(
1717           "CLASS"     => "TERMTABS",
1718           "TABNAME"   => "termgeneric" ,
1719           "TABCLASS"  => "termtabs",
1720           "ACLC"      => "incoming",
1721           "ACL"       => "incoming/systems"),
1723         "NewDevice"   => array(
1724           "CLASS"     => "TERMTABS",
1725           "TABNAME"   => "termgeneric",
1726           "TABCLASS"  => "termtabs",
1727           "ACLC"      => "incoming",
1728           "ACL"       => "incoming/systems"),
1730         "terminal"    => array(
1731             "CLASS"     => "TERMTABS",
1732             "TABNAME"   => "termgeneric",
1733             "TABCLASS"  => "termtabs",
1734             "ACLC"      => "terminal",
1735             "ACL"       => "terminal/termgeneric"),
1737         "workstation" =>  array(
1738             "CLASS"   => "WORKTABS",
1739             "TABNAME" => "workgeneric",
1740             "TABCLASS"=> "worktabs",
1741             "ACLC"    => "workstation",
1742             "ACL"     => "workstation/workgeneric" ),
1744         "server"      => array(
1745             "CLASS"   => "SERVTABS",
1746             "TABNAME" => "servgeneric",
1747             "TABCLASS"=> "servtabs",
1748             "ACLC"    => "server",
1749             "ACL"     => "server/servgeneric"),
1751         "printer"     => array(
1752             "CLASS"   => "PRINTTABS",
1753             "TABNAME" => "printgeneric",
1754             "TABCLASS"=> "printtabs",
1755             "ACLC"    => "printer",
1756             "ACL"     => "printer/printgeneric"),
1758         "phone"       => array(
1759             "CLASS"   => "PHONETABS",
1760             "TABNAME" => "phoneGeneric",
1761             "TABCLASS"=> "phonetabs",
1762             "ACLC"    => "phone",
1763             "ACL"     => "phone/phoneGeneric"),
1765         "winstation"  => array(
1766             "CLASS"   => "WINTABS",
1767             "TABNAME" => "wingeneric",
1768             "TABCLASS"=> "wintabs",
1769             "ACLC"    => "winworkstation",
1770             "ACL"     => "winworkstation/wingeneric"),
1772         "component"   => array(
1773             "CLASS"   => "COMPONENTTABS",
1774             "TABNAME" => "componentGeneric",
1775             "TABCLASS"=> "componenttabs",
1776             "ACLC"    => "component",
1777             "ACL"     => "component/componentGeneric"));
1779     if($this->opsi != NULL){
1780       $tabs["opsi_client"] = array(
1781           "CLASS"   => "OPSITABS",
1782           "TABNAME" => "opsiGeneric" ,
1783           "TABCLASS"=> "opsi_tabs",
1784           "ACLC"    => "opsi" ,
1785           "ACL"     => "opsi/opsiGeneric");
1786     }
1788     return($tabs);
1789   }
1792   /*! \brief  Sets FAIstate to "install" for "New Devices".
1793               This function is some kind of "Post handler" for activated systems,
1794                it is called directly after the object (workstabs,servtabs) gets saved.  
1795       @param  String  $dn   The dn of the newly activated object.
1796       @return Boolean TRUE if activated else FALSE
1797    */
1798   function activate_new_device($dn)
1799   {
1800     $ldap = $this->config->get_ldap_link();
1801     $ldap->cd($this->config->current['BASE']);
1802     $ldap->cat($dn);
1803     if($ldap->count()){
1804       $attrs = $ldap->fetch();
1805       $type  = $this->get_system_type($attrs);
1806       if(!in_array($type,array("workstation","server"))) {
1807         $ocs = $attrs['objectClass'];
1808         unset($ocs['count']);
1809         $new_attrs = array();
1810         if(!in_array("FAIobject",$ocs)){
1811           $ocs[] = "FAIobject";
1812           $new_attrs['objectClass'] = $ocs;
1813         }
1814         $new_attrs['FAIstate'] = "install";
1815         $ldap->cd($dn);
1816         $ldap->modify($new_attrs);
1817         if (!$ldap->success()){
1818           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 
1819                 LDAP_MOD, "activate_new_device($dn)"));
1820         }else{
1821           return(TRUE);
1822         }
1823       }
1824     }
1825     return(FALSE);
1826   }
1829   /* !! Incoming dummy acls, required to defined acls for incoming objects
1830    */
1831   static function plInfo()
1832   {
1833     return (array(
1834           "plShortName"   => _("Incoming objects"),
1835           "plDescription" => _("Incoming objects"),
1836           "plSelfModify"  => FALSE,
1837           "plDepends"     => array(),
1838           "plPriority"    => 99,
1839           "plSection"     => array("administration"),
1840           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1841                                                           "objectClass"  => "")),
1842           "plProvidedAcls"=> array()
1843             
1844           ));
1845   }
1848 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1849 ?>