Code

Fix regression in #4271
[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     if (isset($_POST['edit_continue'])) {
153       $s_action = "select_ogroup_finished";
154     }
156     /* handle C&P from layers menu */
157     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
158       $s_action = "copy_multiple";
159     }
160     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
161       $s_action = "cut_multiple";
162     }
163     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
164       $s_action = "editPaste";
165     }
167     /* Handle daemon events */
168     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
169       $s_action = $_POST['menu_action'];
170     }
171     
172     /* Handle daemon events */
173     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
174       $s_action = $_POST['menu_action'];
175     }
177     /* handle remove from layers menu */
178     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
179       $s_action = "del_multiple";
180     }
181     
182     /* Handle instant actions from layers menu */
183     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
184             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
185               $s_action = "${act}_multiple";
186             }
187     }
189     /* Activate multiple machines */
190     if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
191       $s_action = "activate_multiple";
192     }
194     /* Check for exeeded sizelimit */
195     if (($message= check_sizelimit()) != ""){
196       return($message);
197     }
199     /* Try to get informations about what kind of system to create */
200     if ($s_action=="new") {
201       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
202     }
204     /* Incoming handling  
205      * If someone made a systemtype and ogroup selection 
206      * Display the new requested entry type ... servtab  in case of server and so on.
207      */
208     if(isset($_POST['SystemTypeChoosen'])){
209       $s_action = "SelectedSystemType";
210     }
212     /********************
213       Copy & Paste Handling  ...
214      ********************/
216     /* Display the copy & paste dialog, if it is currently open */
217     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
218     if($ret){
219       return($ret);
220     }
221   
223     /********************
224       Create FAI CD ...   
225      ********************/
226     if ($s_action=="gen_cd"){
227       $this->dn= $this->terminals[$s_entry]['dn'];
228       set_object_info($this->dn);
229       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
230     }
233     /* Start CD-Creation */
234     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
235       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
236       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
237     }
240     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
242       $return_button   = "<form method='get' action='main.php' target='_parent'>
243         <input type='submit' value='"._("Back")."'>
244         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
245         </form>";
247       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
249       /* Get and check command */
250       $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
251       
252       if (check_command($command)){
253         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
255         /* Print out html introduction */
256         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
257           <html>
258           <head>
259           <title></title>
260           <style type="text/css">@import url("themes/default/style.css");</style>
261           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
262           </head>
263           <body style="background: none; margin:4px;" id="body" >
264           <pre>';
266         /* Open process handle and check if it is a valid process */
267         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
268         if (is_resource($process)) {
269           fclose($pipes[0]);
271           /* Print out returned lines && write JS to scroll down each line */
272           while (!feof($pipes[1])){
273             $cur_dat = fgets($pipes[1], 1024);
274             echo $cur_dat;
275             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
276             flush();
277           }
278         }
280         /* Get error string && close streams */
281         $buffer= stream_get_contents($pipes[2]);
283         fclose($pipes[1]);
284         fclose($pipes[2]);
285         echo "</pre>";
287         /* Check return code */
288         $ret= proc_close($process);
289         if ($ret != 0){
290           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
291           echo "<pre style='color:red'>$buffer</pre>";
292         }
296         echo $return_button."<br>";
298       } else {
299         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
300         echo $tmp;
301       }
303       /* Scroll down completly */
304       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
305       echo '</body></html>';
306       flush();
307       exit;
308     }
311     /********************
312       New Device handling  (Ogroup/System select dialog.)
313      ********************/
315     /*  All objects that have to be activated are listed in 
316           $this->system_activation_object[] = "dn";
317       
318         If there is an object group selected we simply adopt all
319          settings from these group and then directly save the entry again.
320         If no object group was selected, then we keep the "edit" dialog of 
321          the target system opened to allow to edit the objects attributes.
322      */
323   
324     if($s_action == "SelectedSystemType"){
326       /* Possible destination system types 
327        */
328       $tabs = $this->get_tab_defs();
330       /* Remember dialog selection.
331        */
332       $selected_group = $_POST['ObjectGroup'];
333       $selected_system = $_POST['SystemType'];
335       $this->systab = NULL;
337       /* Check if system type exists. It should! */
338       if(isset($tabs[$selected_system])){
340         /* Get tab informations */
341         $class    = $tabs[$selected_system]["CLASS"];
342         $tabname  = $tabs[$selected_system]["TABNAME"];
343         $tabclass = $tabs[$selected_system]["TABCLASS"];
344         $acl_cat  = $tabs[$selected_system]["ACLC"];
347         if(!class_available($tabclass)){
348           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
349         }else{
351           /* Go through all objects that should be activated 
352               Contains alls object dns that have to be activated ("New Devices" not unknown)
353             */
354           foreach($this->system_activation_object as $key => $dn){
356             /* Remove entry from list, to avoid page-reload problems */
357             unset($this->system_activation_object[$key]);
359             /* Load permissions for selected 'dn' and check if
360                we're allowed to create this 'dn' */
361             $this->dn = $dn;
362             $ui       = get_userinfo();
363             $tabacl   = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
365             /* We are allowed to create the requested system type */
366             if(preg_match("/c/",$tabacl)){
367               $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
368               $this->systab->set_acl_base($this->DivListSystem->selectedBase);
369               $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
370               $this->systab->base = $this->DivListSystem->selectedBase;
372               /* This will be used when the object is saved, to set FAIstate to 'install'
373                   and to preset maybe other attributes.
374                */
375               $this->systab->was_activated = TRUE;
377               /* Assign some default values for opsi hosts 
378                */
379               if($this->systab instanceOf opsi_tabs){
380                 $ldap = $this->config->get_ldap_link();
381                 $ldap->cat($dn);
382                 $source_attrs = $ldap->fetch();
383                 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
384                   if(isset($source_attrs[$src][0])){
385                     $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
386                   }
387                 }
388               }
390               if($selected_group != "none"){
392                 /*******
393                  * Set gotoMode to active if there was an ogroup selected. 
394                  */
395                 $found = false;
396                 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
397                   if(isset($this->systab->by_object[$tab]->gotoMode)) {
398                     $found = true;
399                     $this->systab->by_object[$tab]->gotoMode = $value;
400                   }
401                 }
402                 if(!$found){
403                   msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
404                 }
406                 /*******
407                  * Update object group membership
408                  */
409                 $og = new ogroup($this->config,$selected_group);
410                 if($og){
411                   $og->AddDelMembership($this->systab->dn);
412                   $og->save();
413                 }
415                 /*******
416                  * Enable inheritance
417                  */
418                 foreach (array("workgeneric", "termgeneric") as $cls){
419                   if (isset($this->systab->by_object[$cls])){
420                     $this->systab->by_object[$cls]->member_of_ogroup = true;
421                     $this->systab->by_object[$cls]->set_everything_to_inherited();
422                     $this->systab->by_object[$cls]->save();
423                   }
424                 }
426                 // Enable activation
427                 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
428                   if (isset($this->systab->by_object[$cls])){
429                     $this->systab->by_object[$cls]->auto_activate= TRUE;
430                   }
431                 }
432               }
434               /* Don't save directly if there is no objectGroup selected.
435                  The user will then be able to configure the missing attributes 
436                  on his own.
437                */
438               if($selected_group != "none"){
439                 $this->systab->save();
440     
441                 /* Post handling for activated new devices 
442                  */
443                 $this->activate_new_device($this->systab->dn);
444                 $this->systab = NULL;
446                 if(!isset($ldap)){
447                   $ldap = $this->config->get_ldap_link();
448                 }
449                 $ldap->cd ($this->dn);
450                 $ldap->cat($this->dn, array('dn'));
451                 if(count($ldap->fetch())){
452                   $ldap->cd($this->dn);
453                   $ldap->rmDir($this->dn);
454                 }
455               }
456             }else{
457               msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
458             }
459           }
460         }
461       }
462     }
465     if ($s_action=="select_ogroup_finished") {
466       $this->systab->save_object();
468       if (count($this->systab->check())!=0) {
469         foreach($this->systab->check() as $msg){
470           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
471         }
472       }elseif(isset($this->systab->objectClass) && isset($this->systab->sw)) {
473         $this->dn = "new";
474         $sw = $this->systab->sw;
475         $tabs = $this->get_tab_defs();
476         $class    = $tabs[$sw]["CLASS"];
477         $tabname  = $tabs[$sw]["TABNAME"];
478         $tabclass = $tabs[$sw]["TABCLASS"];
479         $acl_cat  = $tabs[$sw]["ACLC"];
480         $ogroup = $this->systab->save();
481         if (class_exists($tabclass)) {
482             $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
483             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
484             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
485             $this->systab->by_object[$tabname]->ogroup = $ogroup;
486             $this->systab->base = $this->DivListSystem->selectedBase;
487         }
488       }
489     }
491     if (isset($_POST['create_system'])||$s_action=="newsystem") {
493       $this->last_action = "";
494   
495       /* If the current entry is an incoming object 
496        * $sw = System type as posted in new incoming handling dialog 
497        */ 
498       if(isset($_POST['system'])){
499         $sw = $_POST['system'];
500       }else{
501         $sw = $s_entry;
502       }
504       $this->dn= "new";
506       $tabs = $this->get_tab_defs();
507   
508       if(isset($tabs[$sw])){
509         $class    = $tabs[$sw]["CLASS"];
510         $tabname  = $tabs[$sw]["TABNAME"];
511         $tabclass = $tabs[$sw]["TABCLASS"];
512         $acl_cat  = $tabs[$sw]["ACLC"];
514         /* Load permissions for selected 'dn' and check if
515            we're allowed to remove this 'dn' */
516         $ui       = get_userinfo();
517         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
518         if(preg_match("/c/",$tabacl)){
519           if ($tabclass == 'worktabs') {
520             $this->systab = new askObjectGroup($this->config, $this->dn, $ui, $tabclass, $sw);
521           }
522           else {
523             if(!class_available($tabclass)){
524               msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
525             }else{
526               $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
527             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
528             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
529             $this->systab->base = $this->DivListSystem->selectedBase;
530             }
531           }
532         }else{
533           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
534         }
535       }
536     }
538     /********************
539       System activation
540      ********************/
542     /* User wants to edit data? */
543     if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
544       $this->system_activation_object = array();
545       foreach($this->list_get_selected_items() as $id) {
546         $obj = $this->terminals[$id];
547         $type= $this->get_system_type($obj);
548         if($type == "NewDevice"){
549           $this->system_activation_object[] = $obj['dn'];
550         }
551       }
552       if(count($this->system_activation_object)){
553         $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
554       }
555     }
558     /********************
559       Edit system ...   
560      ********************/
562     /* User wants to edit data? */
563     if (($s_action == "edit") && (!isset($this->systab->config))){
564       $this->last_action = "";
565       $this->dn= $this->terminals[$s_entry]['dn'];
567       /* Check locking, save current plugin in 'back_plugin', so
568          the dialog knows where to return. */
569       if (($user= get_lock($this->dn)) != ""){
570         return(gen_locked_message ($user, $this->dn,TRUE));
571       }
573       /* Find out more about the object type */
574       $attrs = $this->terminals[$s_entry];
575       $type= $this->get_system_type($attrs);
576      
577       /* Lock the current entry, so everyone will get the
578          above dialog */
579       $tabs = $this->get_tab_defs();
581       if($type == "ArpNewDevice"){
582         if(!class_available("ArpNewDeviceTabs")){
583           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
584         }else{
585           add_lock ($this->dn, $this->ui->dn);
586           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
587         }
588       }elseif($type == "NewDevice"){
589         if(!class_available("SelectDeviceType")){
590           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
591         }else{
592           add_lock ($this->dn, $this->ui->dn);
593           $this->system_activation_object= array($this->dn);
594           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
596           // see condition  -$s_action == "SelectedSystemType"-  for further handling
597         }
598       }elseif(isset($tabs[$type])){
600         $class    = $tabs[$type]["CLASS"];
601         $acl_cat  = $tabs[$type]["ACLC"];
602         $tabclass = $tabs[$type]["TABCLASS"];
604         if(!class_available($tabclass)){
605           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
606         }else{
607           add_lock ($this->dn, $this->ui->dn);
608           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
609           $this->systab->set_acl_base($this->dn);
610           set_object_info($this->dn);
611         }
612       }else{ 
613         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
614         $this->remove_lock();
615       }
616     }
619     /********************
620       Change password ...   
621      ********************/
623     /* Set terminals root password */
624     if ($s_action=="change_pw"){
625       $tabs = $this->get_tab_defs();
627       $dn   = $this->terminals[$s_entry]['dn'];
628       $type = $this->get_system_type($this->terminals[$s_entry]);
630       $class    = $tabs[$type]["CLASS"];
631       $acl      = $tabs[$type]["ACL"];
632       $tabclass = $tabs[$type]["TABCLASS"];
633       $ui       = get_userinfo();
634       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
635       if(preg_match("/w/",$tabacl)){
636         $this->dn= $this->terminals[$s_entry]['dn'];
637         set_object_info($this->dn);
638         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
639       }else{
640         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
641       }
642     }
645     /********************
646       Password change finish, but check if entered data is ok 
647      ********************/
649     /* Correctly specified? */
650     if (isset($_POST['password_finish'])){
651       if ($_POST['new_password'] != $_POST['repeated_password']){
652         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
653         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
654       }
655     }
657     /********************
658       Password change finish
659      ********************/
661     /* Change terminal password */
662     if (isset($_POST['password_finish']) && 
663         $_POST['new_password'] == $_POST['repeated_password']){
665       /* Check if user is allowed to set password */
666       $tabs = $this->get_tab_defs();
668       $type = "";
669       foreach($this->terminals as $terminal){
670         if($terminal['dn'] == $this->dn){
671           $type  = $this->get_system_type($terminal);
672           break;
673         } 
674       }
676       /* Type detected */
677       $allow_for = array("terminal","workstation","server","component");
678       if(!empty($type) && in_array($type,$allow_for)){
680         /* Get infos */
681         $plug     = $tabs[$type]["TABNAME"];
682         $acl      = $tabs[$type]["ACL"];
683         $tabclass = $tabs[$type]["TABCLASS"];
684    
685         /* Get acls */
686         $ui       = get_userinfo();
687         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
689         /* Check acls */
690         if(preg_match("/w/",$tabacl)){
691           $ldap = $this->config->get_ldap_link();
692           $ldap->cd($this->dn);
693           $ldap->cat($this->dn);
694           $old_attrs = $ldap->fetch();
696           $attrs= array();
697           if ($_POST['new_password'] == ""){
699             /* Remove password attribute 
700              */
701             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
702               $attrs['objectClass'] = array();
703               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
704                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
705                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
706                 }
707               }
708             }
709             $attrs['userPassword']= array();
710           } else {
712             /* Add/modify password attribute 
713              */
714             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
715               $attrs['objectClass'] = array();
716               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
717                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
718               }
719               $attrs['objectClass'][] = "simpleSecurityObject";
720             }
722             if(class_available("passwordMethodCrypt")){
723               $pwd_m = new passwordMethodCrypt($this->config);
724               $pwd_m->set_hash("crypt/md5");
725               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
726             }else{
727               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
728               $attrs = array();
729             }
730           }
731           $ldap->modify($attrs);
732           if (!$ldap->success()){
733             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
734           }else{
735             if(class_available($plug)){ 
736               $p = new $plug($this->config,$this->dn);
737               $p->handle_post_events("modify");
738             }
739           }
740   
741           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
742         }else{
743           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
744         }
745       }else{
746         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
747       }
748       set_object_info();
749     }
752     /********************
753       Delete system cancel
754      ********************/
756     /* Delete terminal canceled? */
757     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
758       $this->remove_lock();
759       set_object_info();
760     }
763     /********************
764       Action(s) for MULTIPLE
765      ********************/
767     /********************
768       SCHEDULE action in GOsa Daemon
769      ********************/
771     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
772       $this->dns = array();
773       $ids = $this->list_get_selected_items();
775       /* Handle opsi actions */
776       if($s_action == "trigger_event_DaemonEvent_reinstall"){
777         foreach($ids as $key => $id){
778           if($this->terminals[$id]['type'] == "O"){
779             $obj = $this->terminals[$id];
780             $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
781             unset($ids[$key]);
782           }
783         }
784       }
786       if(count($ids) && class_available("DaemonEvent")){
787         $targets = array();
789         /* Collect target mac addresses */
790         $ldap = $this->config->get_ldap_link();
791         foreach($ids as $id){
792           $type = $this->get_system_type($this->terminals[$id]);
793           if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
794           if(isset($this->terminals[$id]['macAddress'][0])){
795             $targets[] = array( "mac" => $this->terminals[$id]['macAddress'][0], "cn" => $this->terminals[$id]['cn'][0] );
796           }else{
797             $ldap->cat ($this->terminals[$id]['dn'], array("macAddress", "cn"));
798             $attrs= $ldap->fetch();
799             if (isset($attrs['macAddress'][0])){
800               $targets[]= array( "mac" => $attrs['macAddress'][0], "cn" => $attrs['cn'][0] );
801             }
802           }
803         }
804         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
805         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
806         $o_queue = new gosaSupportDaemon();
808         /* Skip installation or update trigerred events, 
809          *  if this entry is currently processing.
810          */
811         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
812           foreach($targets as $key => $mac_address){
813             $mac_address = $mac_address['mac'];
814             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
816               $entry['STATUS'] = strtoupper($entry['STATUS']);
817               if($entry['STATUS'] == "PROCESSING" && 
818                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
819                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
820                 unset($targets[$key]);
822                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
823                 break;
824               }
825             }
826           }
827         }        
829         /* Prepare event to be added 
830          */
831         if(count($targets) && isset($events['BY_CLASS'][$type])){
832           $event = $events['BY_CLASS'][$type];
833           $this->systab = new $event['CLASS_NAME']($this->config);
834           $this->systab->add_targets($targets);
835           if(preg_match("/trigger_event/",$s_action)){
836             $this->systab->set_type(TRIGGERED_EVENT);
837           }else{
838             $this->systab->set_type(SCHEDULED_EVENT);
839           }
840         }
841       }
842     }
844     /* Insert scheduled events into queue */
845     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
846       $this->systab->save_object();
848       /* Save event 
849        */
850       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
851         $o_queue = new gosaSupportDaemon();
852         $this->systab = DaemonEvent::save_event_dialog($this->systab, NULL, $o_queue, $this->config);
854       }
855       if(isset($_POST['abort_event_dialog'])){
856         $this->systab = FALSE;
857       }
858     }
861     /********************
862       Delete MULTIPLE entries requested, display confirm dialog
863      ********************/
865     if ($s_action=="del_multiple" || $s_action == "del"){
866       $this->dns = array();
868       if($s_action == "del_multiple"){
869         $ids = $this->list_get_selected_items();
870       }else{
871         $ids = array($s_entry);
872       }
874       $ui = get_userinfo();
875       $tabs = $this->get_tab_defs();
877       if(count($ids)){
879         $disallowed = array();
880         foreach($ids as $id){
882           /* Get 'dn' from posted termlinst */
883           $attrs  = $this->terminals[$id];
884           $type   = $this->get_system_type($attrs);
885           $dn     = $attrs['dn'];
886           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
887           if(preg_match("/d/",$acl)){
888             $this->dns[$id] = $dn;
889           }else{
890             $disallowed[] = $dn;
891           }
892         }
894         if(count($disallowed)){
895           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
896         }
898         if(count($this->dns)){
900           if ($user= get_multiple_locks($this->dns)){
901             return(gen_locked_message($user,$this->dns));
902           }
904           $dns_names = array();
905           foreach($this->dns as $dn){
906             add_lock ($dn, $this->ui->dn);
907             $dns_names[] = LDAP::fix($dn);
908           }
910           /* Lock the current entry, so nobody will edit it during deletion */
911           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
912           $smarty->assign("multiple", true);
913           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
914         }
915       }
916     }
919     /********************
920       Delete MULTIPLE entries confirmed
921      ********************/
923     /* Confirmation for deletion has been passed. Users should be deleted. */
924     if (isset($_POST['delete_multiple_system_confirm'])){
926       $ui = get_userinfo();
927       $tabs = $this->get_tab_defs();
929       /* Remove user by user and check acls before removeing them */
930       foreach($this->dns as $key => $dn){
932         /* Get 'dn' from posted termlinst */
933         $attrs    = $this->terminals[$key];
934         $type= $this->get_system_type($attrs);
936         /* get object type */
937         $tabtype  = "termtabs";
938         $tabobj   = "TERMTABS";
939         $tabacl   = "";
940         if(isset($tabs[$type])){
941           $tabtype = $tabs[$type]['TABCLASS'];
942           $tabobj  = $tabs[$type]['CLASS'];
943           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
945           /* Load permissions for selected 'dn' and check if
946              we're allowed to remove this 'dn' */
947           if(preg_match("/d/",$tabacl)){ 
949             /* Delete request is permitted, perform LDAP action */
950             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
951               $this->systab= new termgeneric($this->config, $dn);
952               $this->systab->set_acl_base($dn);
953               $this->systab->set_acl_category("terminal");
954               $this->systab->remove_from_parent();
955             }elseif($tabtype=="phonetabs"){
956               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
957               $this->systab->set_acl_base($dn);
958               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
959             }else{
960               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
961               $this->systab->set_acl_base($dn);
962               $this->systab->delete();
963             }
964             unset ($this->systab);
965             $this->systab= NULL;
967           } else {
968             /* Normally this shouldn't be reached, send some extra
969                logs to notify the administrator */
970             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
971             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
972           }
973         }
975         /* Remove lock file after successfull deletion */
976         $this->remove_lock();
977         $this->dns = array();
978       }
979     }
981     /********************
982       Delete MULTIPLE entries Canceled
983      ********************/
985     /* Remove lock */
986    if(isset($_POST['delete_multiple_system_cancel'])){
988      /* Remove lock file after successfull deletion */
989      $this->remove_lock();
990      $this->dns = array();
991    }
994     /********************
995       Edit system type finished, check if everything went ok
996      ********************/
997     /* Finish user edit is triggered by the tabulator dialog, so
998        the user wants to save edited data. Check and save at this
999        point. */
1001     /* Dirty workaround - MSG_DIALOG - OK
1002       If a message dialog is shown and we press 'OK'
1003        then try to save again.
1004      */
1005     foreach($_POST as $name => $value){
1006       if(preg_match("/^MSG_OK/",$name)){
1007         $_POST[$this->last_action] = TRUE;
1008       }
1009     }
1011     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1013       /* If the save routine gets interrupted by a confirm dialog, 
1014           store last action so we can trigger it again after 'Ok' was pressed.
1015          (This is the case if a system gets modified while it is installing - GOsa si)
1016        */
1017       $this->last_action = ""; 
1018       if(isset($_POST['edit_finish'])){
1019         $this->last_action = "edit_finish"; 
1020       }elseif(isset($_POST['edit_apply'])){
1021         $this->last_action = "edit_apply";
1022       }
1024       /* Check tabs, will feed message array */
1025       $message = $this->systab->check();
1027       /* Save, or display error message? */
1028       if (count($message) == 0){
1029         $this->systab->save();
1031         /* Post handling for activated systems 
1032             target opsi -> Remove source.
1033             target gosa -> Activate system.
1034          */
1035         if($this->systab instanceOf opsi_tabs && $this->systab->was_activated){
1036           $ldap = $this->config->get_ldap_link();
1037           $ldap->cd($this->config->current['BASE']);
1038           $ldap->rmdir ($this->systab->dn);
1039           @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1041           $hostId =  $this->systab->by_object['opsiGeneric']->hostId;
1042           $mac    =  $this->systab->by_object['opsiGeneric']->mac;
1043           $this->opsi->job_opsi_activate_client($hostId,$mac);
1045         }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1046           $this->activate_new_device($this->systab->dn);
1047         }
1049         /* Terminal has been saved successfully, remove lock from LDAP. */
1050         if (!isset($_POST['edit_apply'])){
1051           if ($this->dn != "new"){
1052             $this->remove_lock();
1053           }
1055           unset ($this->systab);
1056           $this->systab= NULL;
1057           set_object_info();
1058         }else{
1059       
1060           /* Reinitialize tab */
1061           if($this->systab instanceof tabs){
1062             $this->systab->re_init();
1063           }
1064         }
1065       } else {
1066         /* Ok. There seem to be errors regarding to the tab data,
1067            show message and continue as usual. */
1068         msg_dialog::displayChecks($message);
1069       }
1070     }
1073     /********************
1074       Edit system was canceled 
1075      ********************/
1076     /* Cancel dialogs */
1077     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1078       if (isset($this->systab)){
1079         $this->remove_lock();
1080         unset ($this->systab);
1081       }
1082       $this->systab= NULL;
1083       set_object_info();
1084     }
1086     /********************
1087       Display edit dialog, or some other
1088      ********************/
1090     /* Show tab dialog if object is present */
1091     if (isset($this->systab->config)){
1093       if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1094         $this->systab->save_object();
1095       }
1097       $display= $this->systab->execute();
1099       /* Don't show buttons if tab dialog requests this */
1101       $dialog     = FALSE;
1102       $hide_apply = $this->dn == "new";
1103       $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1104       if(is_object($this->systab) && !isset($this->systab->by_object)){
1105         $dialog = TRUE;
1106         $hide_apply = TRUE;
1107       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1108         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1109         if($dia === TRUE || is_object($dia)){
1110           $dialog = TRUE;
1111         }  
1112       }
1113       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1114         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1115         $dialog = TRUE;
1116       }
1118       if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1119         $display.= "<p style=\"text-align:right\">
1120           <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1121           </p>";
1122       }elseif (!$dialog){
1123         $display.= "<p style=\"text-align:right\">\n";
1124         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1125         $display.= "&nbsp;\n";
1126         if (!$hide_apply){
1127           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1128           $display.= "&nbsp;\n";
1129         }
1130         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1131         $display.= "</p>";
1132       }
1134       return ($display);
1135     }
1137     /* Check if there is a snapshot dialog open */
1138     $base = $this->DivListSystem->selectedBase;
1139     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1140       return($str);
1141     }
1143     /* Display dialog with system list */
1144     $this->DivListSystem->parent = $this;
1145     $this->DivListSystem->execute();
1147     /* Add departments if subsearch is disabled */
1148     if(!$this->DivListSystem->SubSearch){
1150       /* Add FAIstate to attributes if FAI is activated */
1151       if($this->fai_activated){
1152         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1153       }else{
1154         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1155       }
1156     }
1157     $this->reload();
1158     $this->DivListSystem->setEntries($this->terminals);
1159     return($this->DivListSystem->Draw());
1160   }
1163   /* Return departments, that will be included within snapshot detection */
1164   function get_used_snapshot_bases()
1165   {
1166     $tmp = array();
1168     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1170     $tabs = array(
1171         "terminal"        => get_ou('terminalRDN'),
1172         "workstation"     => get_ou('workstationRDN'),
1173         "incoming"        => get_ou('systemIncomingRDN'),
1174         "server"          => get_ou('serverRDN'),
1175         "printer"         => get_ou('printerRDN'),
1176         "phone"           => get_ou('phoneRDN'),
1177         "winworkstation"  => get_winstations_ou(),
1178         "component"       => get_ou('componentRDN')
1179         ); 
1181     foreach($tabs as $acl_cat => $dn){
1183       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1184       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1185         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1186       }
1187     }
1188     return($tmp); 
1189   }
1192   function remove_from_parent()
1193   {
1194     /* Optionally execute a command after we're done */
1195     $this->postremove();
1196   }
1199   /* Save data to object */
1200   function save_object()
1201   {
1202     $this->DivListSystem->save_object();
1203     if(is_object($this->CopyPasteHandler)){
1204       $this->CopyPasteHandler->save_object();
1205     }
1206   }
1209   /* Check values */
1210   function check()
1211   {
1212   }
1215   /* Save to LDAP */
1216   function save()
1217   {
1218   }
1220   function adapt_from_template($dn, $skip= array())
1221   {
1222   }
1224   function password_change_needed()
1225   {
1226   }
1228   function reload()
1229   {
1230     /* some var init */
1231     $ui = get_userinfo();
1232     $res              = array();
1233     $this->terminals  = array();
1234     $userregex        = "";
1235     $opsi_clients     = array();
1237     /* Set base for all searches */
1238     $base=  $this->DivListSystem->selectedBase;
1240     /* Prepare samba class name */
1241     $samba  ="";
1242     if ($this->DivListSystem->ShowWinWorkstations){
1243       if ($this->config->get_cfg_value("sambaversion") == "3"){
1244         $samba= "sambaSamAccount";
1245       } else {
1246         $samba= "sambaAccount";
1247       }
1248     }
1250     /* This array represents the combination between checkboxes and search filters */
1251     $objs = array( 
1252         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverRDN')),
1253         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalRDN')),
1254         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerRDN')),
1255         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentRDN')),
1256         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneRDN')),
1257         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1258         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1260     /* Include the 'Display Systems of user' attribute */ 
1261     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1262       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1263     }
1265     /* Attributes to fetch */
1266     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1267     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1269     /* Add FAIstate to attributes if FAI is activated */
1270     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1271     if(!empty($tmp)){
1272       $sys_attrs[] = "FAIstate";
1273     }    
1275     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1276     foreach($objs as $checkBox => $oc){
1278       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1279         if($this->DivListSystem->SubSearch){
1280           if($oc['CLASS'] != ""){
1281             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1282             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1283             $res = array_merge($res,$new_res);
1284           }
1285         }else{
1286           /* User filter? */
1287           if($oc['CLASS'] != ""){
1288             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")";
1289             /* Decide weither to search in description and CN or only in the CN */
1290             if ($this->DivListSystem->DescSearch) {
1291               $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1292             }
1293             else {
1294               $filter = $filter . "(cn=".$this->DivListSystem->Regex."))";
1295             }
1296             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1297           }
1298         }
1299       } 
1300     }
1302     /* Search for incoming objects */ 
1303     $filter = "(|(&".$userregex."(objectClass=goHard)";
1304     if ($this->DivListSystem->DescSearch) {
1305       $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1306     }
1307     else {
1308       $filter = $filter . "(cn=".$this->DivListSystem->Regex.")))";
1309     }
1310     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$this->config->get_cfg_value('base'),$sys_attrs, GL_SIZELIMIT));
1312     /* Append opsi systems, the opsi extension have to installed.
1313         (Only, if we are allowed to view opsi hosts)
1314      */
1315     if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1316       $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1317       if(preg_match("/r/",$o_acl)){
1318         $opsi_clients = $this->opsi->get_hosts_for_system_management();
1319         if($this->opsi->is_error()){
1320           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1321         }
1322       }
1323     }
1324     
1325     /* Get all gotoTerminal's */
1326     $t_id = 0;
1327     $opsi_map  = array();
1328     foreach ($res as $value){
1330       $tmp= $value['dn'];
1331       $add= "";
1333       /* Extract base */
1334       foreach($objs as $obj){
1335         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1336           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1337         }
1338       }
1340       /* Create a string containing the last part of the department. */
1341       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1342       if(empty($dn_name)){
1343         $dn_name = "/";
1344       }
1346       /* check if current object is a new one */
1347       if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1348         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1349           $add= "- "._("New terminal");
1350         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1351           $add= "- "._("New workstation");
1352         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1353           $add= "- "._("Unknown device");
1354         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1355           $add= "- "._("New Device");
1356         }
1357       } 
1359       /* Detect type of object and create an entry for $this->terminals */
1360       $terminal = array();
1362        if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1364          /* check acl */
1365          $terminal             = $value;
1366          $terminal['type']     = "O";
1368        } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1370         /* check acl */
1371         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1372         if($add != "" || preg_match("/r/",$acl)) {
1373           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1374             $terminal             = $value;
1375             $terminal['type']     = "T";
1376             $terminal['is_new']   = $add;
1377           } else {
1378             $terminal             = $value;
1379             $terminal['type']     = "D";
1380             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1381             $terminal['location'] = array_search($tmp, $this->config->departments); 
1382           }
1383         }
1384       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1386         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1387         if($add != "" || preg_match("/r/",$acl)) {
1388           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1389             $terminal             = $value;
1390             $terminal['type']     = "L";
1391             $terminal['is_new']   = $add;
1392           } else {
1393             $terminal             = $value;
1394             $terminal['type']     = "D";
1395             $terminal['location'] = array_search($tmp, $this->config->departments);
1396             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1397           }
1398 #          if (isset($value["FAIstate"][0])){
1399 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1400 #          }
1401         }
1402       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1403        
1404    
1405         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1406         if($add != "" || preg_match("/r/",$acl)) {
1408           $terminal             = $value;
1409           $terminal['type']     = "P";
1410         }
1411       } elseif (in_array_ics('goServer', $value["objectClass"])){
1413         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1414         if($add != "" || preg_match("/r/",$acl)) {
1416           $terminal             = $value;
1417           $terminal['type']     = "S";
1418 #          if (isset($value["FAIstate"][0])){
1419 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1420 #          }
1421         }
1422       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1424         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1425         if($add != "" || preg_match("/r/",$acl)) {
1427           $terminal             = $value;
1428           $terminal['type']     = "F";
1429         }
1430       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1432         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1433                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1434                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1435         if($add != "" || preg_match("/r/",$acl)) {
1437           $terminal = $value;
1438           $terminal['type']   = "Q";
1439           $terminal['is_new'] = $add;
1440         }
1441       } elseif (in_array_ics('ieee802Device', $value["objectClass"]) && 
1442         !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1443         $type= "winstation";
1444         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1445         if($add != "" || preg_match("/r/",$acl)) {
1447           $terminal             = $value;
1448           $terminal['type']     = "C";
1449         }
1450       } else{
1452         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1453         if (isset($value['sambaDomainName'])){
1454           $domain= " [".$value['sambaDomainName'][0]."]";
1455         } else {
1456           $domain= "";
1457         }
1458         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1459         if($add != "" || preg_match("/r/",$acl)) {
1460           $terminal=$value;
1461           $terminal['type']     ="W";
1462           $terminal['domain']   = $name.$domain;
1463         }
1464       }
1466       /* Append collected data to the host list.
1467        */
1468       if(count($terminal)){
1469         $t_id ++ ;
1470         $this->terminals[$t_id]=$terminal;
1471         $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1472       }
1473     }
1476     /* Merge real hosts with opsi hosts.
1477        If there is a samba host, then merge it with the opsi host,
1478         to avoid duplicate entries.
1479      */
1480     foreach($opsi_clients as $entry){
1481       if(isset($opsi_map[$entry['cn'][0]])){
1482         continue;
1483       }
1484       $terminal             = $entry;
1485       $terminal['type']     = "O";
1486       $this->terminals[] = $terminal;
1487     }
1489     $tmp  =array();
1490     $tmp2 =array();
1491     foreach($this->terminals as $tkey => $val ){
1492       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1493       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1494     }
1495     natcasesort($tmp2);
1496     $this->terminals=array();
1497     foreach($tmp2 as $val){
1498       $this->terminals[]=$tmp[$val];
1499     }
1500     reset ($this->terminals);
1501   }
1503   function remove_lock()
1504   {
1505     if (isset($this->systab->dn)){
1506       del_lock ($this->systab->dn);
1507     }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1508       del_lock($this->dn);
1509     }
1510     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1511       del_lock($this->dns);
1512     }
1513   }
1516   function copyPasteHandling_from_queue($s_action,$s_entry)
1517   {
1518     /* Check if Copy & Paste is disabled */
1519     if(!is_object($this->CopyPasteHandler)){
1520       return("");
1521     }
1523     $ui = get_userinfo();
1524     
1525     $tabs = $this->get_tab_defs();
1527     /* Add a single entry to queue */
1528     if($s_action == "cut" || $s_action == "copy"){
1530       /* Cleanup object queue */
1531       $this->CopyPasteHandler->cleanup_queue();
1532       $dn     = $this->terminals[$s_entry]['dn'];
1533       $oc     = $this->terminals[$s_entry]['objectClass'];
1534       $type   = $this->get_system_type($this->terminals[$s_entry]);
1536       $tab_o  = $tabs[$type]['CLASS'];
1537       $tab_c  = $tabs[$type]['TABCLASS'];
1538       $acl_c  = $tabs[$type]['TABNAME'];
1539       $acl    = $tabs[$type]['ACLC'];
1541       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1542         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1543       }
1544       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1545         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1546       }
1547     }
1549     /* Add entries to queue */
1550     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1552       /* Cleanup object queue */
1553       $this->CopyPasteHandler->cleanup_queue();
1555       /* Add new entries to CP queue */
1556       foreach($this->list_get_selected_items() as $id){
1557         $dn = $this->terminals[$id]['dn'];
1558         $oc = $this->terminals[$id]['objectClass']; 
1559         $type = $this->get_system_type($this->terminals[$id]);
1561         if(isset($tabs[$type])){
1562           $tab_o  = $tabs[$type]['CLASS'];
1563           $tab_c  = $tabs[$type]['TABCLASS'];
1564           $acl_c  = $tabs[$type]['TABNAME'];
1565           $acl    = $tabs[$type]['ACLC'];
1567           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1568             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1569           }
1570           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1571             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1572           }
1573         }
1574       }
1575     }
1577     /* Start pasting entries */
1578     if($s_action == "editPaste"){
1579       $this->start_pasting_copied_objects = TRUE;
1580     }
1581   
1582     /* Return C&P dialog */
1583     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1585       /* Get dialog */
1586       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1587       $data = $this->CopyPasteHandler->execute();
1589       /* Return dialog data */
1590       if(!empty($data)){
1591         return($data);
1592       }
1593     }
1595     /* Automatically disable status for pasting */
1596     if(!$this->CopyPasteHandler->entries_queued()){
1597       $this->start_pasting_copied_objects = FALSE;
1598     }
1599     return("");
1600   }
1603   function get_system_type($attrs)
1604   {
1605     $classes = $attrs['objectClass'];
1607     $type= "";
1608     if (in_array_ics('gosa_opsi_client', $classes)){
1609       $type= "opsi_client";
1610     }elseif (in_array_ics('sambaAccount', $classes) ||
1611         in_array_ics('sambaSamAccount', $classes)){
1612       $type= "winstation";
1613     }elseif (in_array_ics('ieee802Device', $classes)){
1614       $type= "component";
1615     }elseif (in_array_ics('gotoTerminal', $classes)){
1616       $type= "terminal";
1617     }elseif (in_array_ics('gotoWorkstation', $classes)){
1618       $type= "workstation";
1619     }elseif (in_array_ics('gotoPrinter', $classes)){
1620       $type= "printer";
1621     }elseif (in_array_ics('goFonHardware', $classes)){
1622       $type= "phone";
1623     }elseif (in_array_ics('goServer', $classes)){
1624       $type= "server";
1625     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1626       $type= "ArpNewDevice";
1627     }elseif (in_array_ics('GOhard', $classes)){
1628       $type= "NewDevice";
1629     }
1630     return ($type);
1631   }
1634   function convert_list($input)
1635   {
1636     $temp= "";
1638     $conv= array(
1639         "D" => array("plugins/systems/images/select_default.png",_("Template")),
1640         "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1641         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1642         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1644         "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1646         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1647         "S" => array("plugins/systems/images/select_server.png",_("Server")),
1648         "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1650         "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1651         "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1652         "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1654         "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1655         "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1656         "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1658         "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1659         "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1661         "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1662         "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1663         "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1665     /* Add opsi client to system types */
1666     if($this->opsi != NULL){
1667         $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1668     }
1670     /* Use locked icons 
1671      */
1672     if( in_array($input['type'],array("S","T","L")) && 
1673         isset($input['gotoMode'][0]) && 
1674         preg_match("/locked/",$input['gotoMode'][0])){
1675       $input['type'].="X";
1676     } elseif(in_array($input['type'],array("S","L")) &&
1677         isset($input['FAIstate'][0])){
1679     /* Add FAI state icons 
1680      */
1681       $type= "";
1682       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1683         case 'error':
1684           $type= 'E';
1685           break;
1686         case 'installing':
1687         case 'install':
1688         case 'sysinfo':
1689         case 'softupdate':
1690         case 'scheduledupdate':
1691           $type= 'B';
1692           break;
1693       }
1695       $input['type'].= $type;
1696     }   
1698     /* Use new images if object is from incoming 
1699      */
1700     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1701       $input['type']="N".$input['type'];
1702     }
1704     /* Check which flags this objects uses 
1705      */
1706     foreach ($conv  as $key => $value){
1707       $found = TRUE;
1708       if(strlen($key) != strlen($input['type'])) {
1709         $found = FALSE;
1710       }
1711       for($i = 0 ; $i < strlen($key) ; $i++){
1712         if(!preg_match("/".$key[$i]."/",$input['type'])){
1713           $found = FALSE;
1714         }
1715      }
1717       if($found){
1718         $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1719         $tmp['class']=$key;
1720         return $tmp;
1721       }
1722     }
1723   }
1726   function list_get_selected_items()
1727   {
1728     $ids = array();
1729     foreach($_POST as $name => $value){
1730       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1731         $id   = preg_replace("/^item_selected_/","",$name);
1732         $ids[$id] = $id;
1733       }
1734     }
1735     return($ids);
1736   }
1739   public function get_tab_defs()
1740   {
1741     $tabs = array(
1742         "incoming"    => array(
1743           "CLASS"     => "",
1744           "TABNAME"   => "",
1745           "TABCLASS"  => "",
1746           "ACLC"      => "incoming",
1747           "ACL"       => "incoming/systems"),
1749         "ArpNewDevice"=> array(
1750           "CLASS"     => "TERMTABS",
1751           "TABNAME"   => "termgeneric" ,
1752           "TABCLASS"  => "termtabs",
1753           "ACLC"      => "incoming",
1754           "ACL"       => "incoming/systems"),
1756         "NewDevice"   => array(
1757           "CLASS"     => "TERMTABS",
1758           "TABNAME"   => "termgeneric",
1759           "TABCLASS"  => "termtabs",
1760           "ACLC"      => "incoming",
1761           "ACL"       => "incoming/systems"),
1763         "terminal"    => array(
1764             "CLASS"     => "TERMTABS",
1765             "TABNAME"   => "termgeneric",
1766             "TABCLASS"  => "termtabs",
1767             "ACLC"      => "terminal",
1768             "ACL"       => "terminal/termgeneric"),
1770         "workstation" =>  array(
1771             "CLASS"   => "WORKTABS",
1772             "TABNAME" => "workgeneric",
1773             "TABCLASS"=> "worktabs",
1774             "ACLC"    => "workstation",
1775             "ACL"     => "workstation/workgeneric" ),
1777         "server"      => array(
1778             "CLASS"   => "SERVTABS",
1779             "TABNAME" => "servgeneric",
1780             "TABCLASS"=> "servtabs",
1781             "ACLC"    => "server",
1782             "ACL"     => "server/servgeneric"),
1784         "printer"     => array(
1785             "CLASS"   => "PRINTTABS",
1786             "TABNAME" => "printgeneric",
1787             "TABCLASS"=> "printtabs",
1788             "ACLC"    => "printer",
1789             "ACL"     => "printer/printgeneric"),
1791         "phone"       => array(
1792             "CLASS"   => "PHONETABS",
1793             "TABNAME" => "phoneGeneric",
1794             "TABCLASS"=> "phonetabs",
1795             "ACLC"    => "phone",
1796             "ACL"     => "phone/phoneGeneric"),
1798         "winstation"  => array(
1799             "CLASS"   => "WINTABS",
1800             "TABNAME" => "wingeneric",
1801             "TABCLASS"=> "wintabs",
1802             "ACLC"    => "winworkstation",
1803             "ACL"     => "winworkstation/wingeneric"),
1805         "component"   => array(
1806             "CLASS"   => "COMPONENTTABS",
1807             "TABNAME" => "componentGeneric",
1808             "TABCLASS"=> "componenttabs",
1809             "ACLC"    => "component",
1810             "ACL"     => "component/componentGeneric"));
1812     if($this->opsi != NULL){
1813       $tabs["opsi_client"] = array(
1814           "CLASS"   => "OPSITABS",
1815           "TABNAME" => "opsiGeneric" ,
1816           "TABCLASS"=> "opsi_tabs",
1817           "ACLC"    => "opsi" ,
1818           "ACL"     => "opsi/opsiGeneric");
1819     }
1821     return($tabs);
1822   }
1825   /*! \brief  Sets FAIstate to "install" for "New Devices".
1826               This function is some kind of "Post handler" for activated systems,
1827                it is called directly after the object (workstabs,servtabs) gets saved.  
1828       @param  String  $dn   The dn of the newly activated object.
1829       @return Boolean TRUE if activated else FALSE
1830    */
1831   function activate_new_device($dn)
1832   {
1833     $ldap = $this->config->get_ldap_link();
1834     $ldap->cd($this->config->current['BASE']);
1835     $ldap->cat($dn);
1836     if($ldap->count()){
1837       $attrs = $ldap->fetch();
1838       $type  = $this->get_system_type($attrs);
1839       if(!in_array($type,array("workstation","server"))) {
1840         $ocs = $attrs['objectClass'];
1841         unset($ocs['count']);
1842         $new_attrs = array();
1843         if(!in_array("FAIobject",$ocs)){
1844           $ocs[] = "FAIobject";
1845           $new_attrs['objectClass'] = $ocs;
1846         }
1847         $new_attrs['FAIstate'] = "install";
1848         $ldap->cd($dn);
1849         $ldap->modify($new_attrs);
1850         if (!$ldap->success()){
1851           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 
1852                 LDAP_MOD, "activate_new_device($dn)"));
1853         }else{
1854           return(TRUE);
1855         }
1856       }
1857     }
1858     return(FALSE);
1859   }
1862   /* !! Incoming dummy acls, required to defined acls for incoming objects
1863    */
1864   static function plInfo()
1865   {
1866     return (array(
1867           "plShortName"   => _("Incoming objects"),
1868           "plDescription" => _("Incoming objects"),
1869           "plSelfModify"  => FALSE,
1870           "plDepends"     => array(),
1871           "plPriority"    => 99,
1872           "plSection"     => array("administration"),
1873           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1874                                                           "objectClass"  => "")),
1875           "plProvidedAcls"=> array()
1876             
1877           ));
1878   }
1881 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1882 ?>