Code

Apply fix for #4368
[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         $mac= 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             $mac[] = $this->terminals[$id]['macAddress'][0];
796           }else{
797             $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
798             $attrs= $ldap->fetch();
799             if (isset($attrs['macAddress'][0])){
800               $mac[]= $attrs['macAddress'][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($mac as $key => $mac_address){
813             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
815               $entry['STATUS'] = strtoupper($entry['STATUS']);
816               if($entry['STATUS'] == "PROCESSING" && 
817                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
818                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
819                 unset($mac[$key]);
821                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
822                 break;
823               }
824             }
825           }
826         }        
828         /* Prepare event to be added 
829          */
830         if(count($mac) && isset($events['BY_CLASS'][$type])){
831           $event = $events['BY_CLASS'][$type];
832           $this->systab = new $event['CLASS_NAME']($this->config);
833           $this->systab->add_targets($mac);
834           if(preg_match("/trigger_event/",$s_action)){
835             $this->systab->set_type(TRIGGERED_EVENT);
836           }else{
837             $this->systab->set_type(SCHEDULED_EVENT);
838           }
839         }
840       }
841     }
843     /* Insert scheduled events into queue */
844     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
845       $this->systab->save_object();
847       /* Save event 
848        */
849       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
850         $o_queue = new gosaSupportDaemon();
851         $o_queue->append($this->systab);
852         if($o_queue->is_error()){
853           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
854         }else{
855           $this->systab = FALSE;
856         }
857       }
858       if(isset($_POST['abort_event_dialog'])){
859         $this->systab = FALSE;
860       }
861     }
864     /********************
865       Delete MULTIPLE entries requested, display confirm dialog
866      ********************/
868     if ($s_action=="del_multiple" || $s_action == "del"){
869       $this->dns = array();
871       if($s_action == "del_multiple"){
872         $ids = $this->list_get_selected_items();
873       }else{
874         $ids = array($s_entry);
875       }
877       $ui = get_userinfo();
878       $tabs = $this->get_tab_defs();
880       if(count($ids)){
882         $disallowed = array();
883         foreach($ids as $id){
885           /* Get 'dn' from posted termlinst */
886           $attrs  = $this->terminals[$id];
887           $type   = $this->get_system_type($attrs);
888           $dn     = $attrs['dn'];
889           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
890           if(preg_match("/d/",$acl)){
891             $this->dns[$id] = $dn;
892           }else{
893             $disallowed[] = $dn;
894           }
895         }
897         if(count($disallowed)){
898           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
899         }
901         if(count($this->dns)){
903           if ($user= get_multiple_locks($this->dns)){
904             return(gen_locked_message($user,$this->dns));
905           }
907           $dns_names = array();
908           foreach($this->dns as $dn){
909             add_lock ($dn, $this->ui->dn);
910             $dns_names[] = LDAP::fix($dn);
911           }
913           /* Lock the current entry, so nobody will edit it during deletion */
914           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
915           $smarty->assign("multiple", true);
916           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
917         }
918       }
919     }
922     /********************
923       Delete MULTIPLE entries confirmed
924      ********************/
926     /* Confirmation for deletion has been passed. Users should be deleted. */
927     if (isset($_POST['delete_multiple_system_confirm'])){
929       $ui = get_userinfo();
930       $tabs = $this->get_tab_defs();
932       /* Remove user by user and check acls before removeing them */
933       foreach($this->dns as $key => $dn){
935         /* Get 'dn' from posted termlinst */
936         $attrs    = $this->terminals[$key];
937         $type= $this->get_system_type($attrs);
939         /* get object type */
940         $tabtype  = "termtabs";
941         $tabobj   = "TERMTABS";
942         $tabacl   = "";
943         if(isset($tabs[$type])){
944           $tabtype = $tabs[$type]['TABCLASS'];
945           $tabobj  = $tabs[$type]['CLASS'];
946           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
948           /* Load permissions for selected 'dn' and check if
949              we're allowed to remove this 'dn' */
950           if(preg_match("/d/",$tabacl)){ 
952             /* Delete request is permitted, perform LDAP action */
953             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
954               $this->systab= new termgeneric($this->config, $dn);
955               $this->systab->set_acl_base($dn);
956               $this->systab->set_acl_category("terminal");
957               $this->systab->remove_from_parent();
958             }elseif($tabtype=="phonetabs"){
959               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
960               $this->systab->set_acl_base($dn);
961               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
962             }else{
963               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
964               $this->systab->set_acl_base($dn);
965               $this->systab->delete();
966             }
967             unset ($this->systab);
968             $this->systab= NULL;
970           } else {
971             /* Normally this shouldn't be reached, send some extra
972                logs to notify the administrator */
973             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
974             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
975           }
976         }
978         /* Remove lock file after successfull deletion */
979         $this->remove_lock();
980         $this->dns = array();
981       }
982     }
984     /********************
985       Delete MULTIPLE entries Canceled
986      ********************/
988     /* Remove lock */
989    if(isset($_POST['delete_multiple_system_cancel'])){
991      /* Remove lock file after successfull deletion */
992      $this->remove_lock();
993      $this->dns = array();
994    }
997     /********************
998       Edit system type finished, check if everything went ok
999      ********************/
1000     /* Finish user edit is triggered by the tabulator dialog, so
1001        the user wants to save edited data. Check and save at this
1002        point. */
1004     /* Dirty workaround - MSG_DIALOG - OK
1005       If a message dialog is shown and we press 'OK'
1006        then try to save again.
1007      */
1008     foreach($_POST as $name => $value){
1009       if(preg_match("/^MSG_OK/",$name)){
1010         $_POST[$this->last_action] = TRUE;
1011       }
1012     }
1014     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1016       /* If the save routine gets interrupted by a confirm dialog, 
1017           store last action so we can trigger it again after 'Ok' was pressed.
1018          (This is the case if a system gets modified while it is installing - GOsa si)
1019        */
1020       $this->last_action = ""; 
1021       if(isset($_POST['edit_finish'])){
1022         $this->last_action = "edit_finish"; 
1023       }elseif(isset($_POST['edit_apply'])){
1024         $this->last_action = "edit_apply";
1025       }
1027       /* Check tabs, will feed message array */
1028       $message = $this->systab->check();
1030       /* Save, or display error message? */
1031       if (count($message) == 0){
1032         $this->systab->save();
1034         /* Post handling for activated systems 
1035             target opsi -> Remove source.
1036             target gosa -> Activate system.
1037          */
1038         if($this->systab instanceOf opsi_tabs && $this->systab->was_activated){
1039           $ldap = $this->config->get_ldap_link();
1040           $ldap->cd($this->config->current['BASE']);
1041           $ldap->rmdir ($this->systab->dn);
1042           @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1044           $hostId =  $this->systab->by_object['opsiGeneric']->hostId;
1045           $mac    =  $this->systab->by_object['opsiGeneric']->mac;
1046           $this->opsi->job_opsi_activate_client($hostId,$mac);
1048         }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1049           $this->activate_new_device($this->systab->dn);
1050         }
1052         /* Terminal has been saved successfully, remove lock from LDAP. */
1053         if (!isset($_POST['edit_apply'])){
1054           if ($this->dn != "new"){
1055             $this->remove_lock();
1056           }
1058           unset ($this->systab);
1059           $this->systab= NULL;
1060           set_object_info();
1061         }else{
1062       
1063           /* Reinitialize tab */
1064           if($this->systab instanceof tabs){
1065             $this->systab->re_init();
1066           }
1067         }
1068       } else {
1069         /* Ok. There seem to be errors regarding to the tab data,
1070            show message and continue as usual. */
1071         msg_dialog::displayChecks($message);
1072       }
1073     }
1076     /********************
1077       Edit system was canceled 
1078      ********************/
1079     /* Cancel dialogs */
1080     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1081       if (isset($this->systab)){
1082         $this->remove_lock();
1083         unset ($this->systab);
1084       }
1085       $this->systab= NULL;
1086       set_object_info();
1087     }
1089     /********************
1090       Display edit dialog, or some other
1091      ********************/
1093     /* Show tab dialog if object is present */
1094     if (isset($this->systab->config)){
1096       if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1097         $this->systab->save_object();
1098       }
1100       $display= $this->systab->execute();
1102       /* Don't show buttons if tab dialog requests this */
1104       $dialog     = FALSE;
1105       $hide_apply = $this->dn == "new";
1106       $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1107       if(is_object($this->systab) && !isset($this->systab->by_object)){
1108         $dialog = TRUE;
1109         $hide_apply = TRUE;
1110       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1111         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1112         if($dia === TRUE || is_object($dia)){
1113           $dialog = TRUE;
1114         }  
1115       }
1116       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1117         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1118         $dialog = TRUE;
1119       }
1121       if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1122         $display.= "<p style=\"text-align:right\">
1123           <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1124           </p>";
1125       }elseif (!$dialog){
1126         $display.= "<p style=\"text-align:right\">\n";
1127         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1128         $display.= "&nbsp;\n";
1129         if (!$hide_apply){
1130           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1131           $display.= "&nbsp;\n";
1132         }
1133         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1134         $display.= "</p>";
1135       }
1137       return ($display);
1138     }
1140     /* Check if there is a snapshot dialog open */
1141     $base = $this->DivListSystem->selectedBase;
1142     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1143       return($str);
1144     }
1146     /* Display dialog with system list */
1147     $this->DivListSystem->parent = $this;
1148     $this->DivListSystem->execute();
1150     /* Add departments if subsearch is disabled */
1151     if(!$this->DivListSystem->SubSearch){
1153       /* Add FAIstate to attributes if FAI is activated */
1154       if($this->fai_activated){
1155         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1156       }else{
1157         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1158       }
1159     }
1160     $this->reload();
1161     $this->DivListSystem->setEntries($this->terminals);
1162     return($this->DivListSystem->Draw());
1163   }
1166   /* Return departments, that will be included within snapshot detection */
1167   function get_used_snapshot_bases()
1168   {
1169     $tmp = array();
1171     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1173     $tabs = array(
1174         "terminal"        => get_ou('terminalRDN'),
1175         "workstation"     => get_ou('workstationRDN'),
1176         "incoming"        => get_ou('systemIncomingRDN'),
1177         "server"          => get_ou('serverRDN'),
1178         "printer"         => get_ou('printerRDN'),
1179         "phone"           => get_ou('phoneRDN'),
1180         "winworkstation"  => get_winstations_ou(),
1181         "component"       => get_ou('componentRDN')
1182         ); 
1184     foreach($tabs as $acl_cat => $dn){
1186       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1187       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1188         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1189       }
1190     }
1191     return($tmp); 
1192   }
1195   function remove_from_parent()
1196   {
1197     /* Optionally execute a command after we're done */
1198     $this->postremove();
1199   }
1202   /* Save data to object */
1203   function save_object()
1204   {
1205     $this->DivListSystem->save_object();
1206     if(is_object($this->CopyPasteHandler)){
1207       $this->CopyPasteHandler->save_object();
1208     }
1209   }
1212   /* Check values */
1213   function check()
1214   {
1215   }
1218   /* Save to LDAP */
1219   function save()
1220   {
1221   }
1223   function adapt_from_template($dn, $skip= array())
1224   {
1225   }
1227   function password_change_needed()
1228   {
1229   }
1231   function reload()
1232   {
1233     /* some var init */
1234     $ui = get_userinfo();
1235     $res              = array();
1236     $this->terminals  = array();
1237     $userregex        = "";
1238     $opsi_clients     = array();
1240     /* Set base for all searches */
1241     $base=  $this->DivListSystem->selectedBase;
1243     /* Prepare samba class name */
1244     $samba  ="";
1245     if ($this->DivListSystem->ShowWinWorkstations){
1246       if ($this->config->get_cfg_value("sambaversion") == "3"){
1247         $samba= "sambaSamAccount";
1248       } else {
1249         $samba= "sambaAccount";
1250       }
1251     }
1253     /* This array represents the combination between checkboxes and search filters */
1254     $objs = array( 
1255         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverRDN')),
1256         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalRDN')),
1257         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerRDN')),
1258         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentRDN')),
1259         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneRDN')),
1260         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1261         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1263     /* Include the 'Display Systems of user' attribute */ 
1264     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1265       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1266     }
1268     /* Attributes to fetch */
1269     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1270     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1272     /* Add FAIstate to attributes if FAI is activated */
1273     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1274     if(!empty($tmp)){
1275       $sys_attrs[] = "FAIstate";
1276     }    
1278     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1279     foreach($objs as $checkBox => $oc){
1281       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1282         if($this->DivListSystem->SubSearch){
1283           if($oc['CLASS'] != ""){
1284             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1285             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1286             $res = array_merge($res,$new_res);
1287           }
1288         }else{
1289           /* User filter? */
1290           if($oc['CLASS'] != ""){
1291             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")";
1292             /* Decide weither to search in description and CN or only in the CN */
1293             if ($this->DivListSystem->DescSearch) {
1294               $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1295             }
1296             else {
1297               $filter = $filter . "(cn=".$this->DivListSystem->Regex."))";
1298             }
1299             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1300           }
1301         }
1302       } 
1303     }
1305     /* Search for incoming objects */ 
1306     $filter = "(|(&".$userregex."(objectClass=goHard)";
1307     if ($this->DivListSystem->DescSearch) {
1308       $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1309     }
1310     else {
1311       $filter = $filter . "(cn=".$this->DivListSystem->Regex.")))";
1312     }
1313     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$this->config->get_cfg_value('base'),$sys_attrs, GL_SIZELIMIT));
1315     /* Append opsi systems, the opsi extension have to installed.
1316         (Only, if we are allowed to view opsi hosts)
1317      */
1318     if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1319       $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1320       if(preg_match("/r/",$o_acl)){
1321         $opsi_clients = $this->opsi->get_hosts_for_system_management();
1322         if($this->opsi->is_error()){
1323           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1324         }
1325       }
1326     }
1327     
1328     /* Get all gotoTerminal's */
1329     $t_id = 0;
1330     $opsi_map  = array();
1331     foreach ($res as $value){
1333       $tmp= $value['dn'];
1334       $add= "";
1336       /* Extract base */
1337       foreach($objs as $obj){
1338         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1339           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1340         }
1341       }
1343       /* Create a string containing the last part of the department. */
1344       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1345       if(empty($dn_name)){
1346         $dn_name = "/";
1347       }
1349       /* check if current object is a new one */
1350       if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1351         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1352           $add= "- "._("New terminal");
1353         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1354           $add= "- "._("New workstation");
1355         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1356           $add= "- "._("Unknown device");
1357         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1358           $add= "- "._("New Device");
1359         }
1360       } 
1362       /* Detect type of object and create an entry for $this->terminals */
1363       $terminal = array();
1365        if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1367          /* check acl */
1368          $terminal             = $value;
1369          $terminal['type']     = "O";
1371        } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1373         /* check acl */
1374         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1375         if($add != "" || preg_match("/r/",$acl)) {
1376           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1377             $terminal             = $value;
1378             $terminal['type']     = "T";
1379             $terminal['is_new']   = $add;
1380           } else {
1381             $terminal             = $value;
1382             $terminal['type']     = "D";
1383             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1384             $terminal['location'] = array_search($tmp, $this->config->departments); 
1385           }
1386         }
1387       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1389         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1390         if($add != "" || preg_match("/r/",$acl)) {
1391           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1392             $terminal             = $value;
1393             $terminal['type']     = "L";
1394             $terminal['is_new']   = $add;
1395           } else {
1396             $terminal             = $value;
1397             $terminal['type']     = "D";
1398             $terminal['location'] = array_search($tmp, $this->config->departments);
1399             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1400           }
1401 #          if (isset($value["FAIstate"][0])){
1402 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1403 #          }
1404         }
1405       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1406        
1407    
1408         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1409         if($add != "" || preg_match("/r/",$acl)) {
1411           $terminal             = $value;
1412           $terminal['type']     = "P";
1413         }
1414       } elseif (in_array_ics('goServer', $value["objectClass"])){
1416         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1417         if($add != "" || preg_match("/r/",$acl)) {
1419           $terminal             = $value;
1420           $terminal['type']     = "S";
1421 #          if (isset($value["FAIstate"][0])){
1422 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1423 #          }
1424         }
1425       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1427         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1428         if($add != "" || preg_match("/r/",$acl)) {
1430           $terminal             = $value;
1431           $terminal['type']     = "F";
1432         }
1433       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1435         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1436                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1437                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1438         if($add != "" || preg_match("/r/",$acl)) {
1440           $terminal = $value;
1441           $terminal['type']   = "Q";
1442           $terminal['is_new'] = $add;
1443         }
1444       } elseif (in_array_ics('ieee802Device', $value["objectClass"]) && 
1445         !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1446         $type= "winstation";
1447         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1448         if($add != "" || preg_match("/r/",$acl)) {
1450           $terminal             = $value;
1451           $terminal['type']     = "C";
1452         }
1453       } else{
1455         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1456         if (isset($value['sambaDomainName'])){
1457           $domain= " [".$value['sambaDomainName'][0]."]";
1458         } else {
1459           $domain= "";
1460         }
1461         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1462         if($add != "" || preg_match("/r/",$acl)) {
1463           $terminal=$value;
1464           $terminal['type']     ="W";
1465           $terminal['domain']   = $name.$domain;
1466         }
1467       }
1469       /* Append collected data to the host list.
1470        */
1471       if(count($terminal)){
1472         $t_id ++ ;
1473         $this->terminals[$t_id]=$terminal;
1474         $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1475       }
1476     }
1479     /* Merge real hosts with opsi hosts.
1480        If there is a samba host, then merge it with the opsi host,
1481         to avoid duplicate entries.
1482      */
1483     foreach($opsi_clients as $entry){
1484       if(isset($opsi_map[$entry['cn'][0]])){
1485         continue;
1486       }
1487       $terminal             = $entry;
1488       $terminal['type']     = "O";
1489       $this->terminals[] = $terminal;
1490     }
1492     $tmp  =array();
1493     $tmp2 =array();
1494     foreach($this->terminals as $tkey => $val ){
1495       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1496       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1497     }
1498     natcasesort($tmp2);
1499     $this->terminals=array();
1500     foreach($tmp2 as $val){
1501       $this->terminals[]=$tmp[$val];
1502     }
1503     reset ($this->terminals);
1504   }
1506   function remove_lock()
1507   {
1508     if (isset($this->systab->dn)){
1509       del_lock ($this->systab->dn);
1510     }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1511       del_lock($this->dn);
1512     }
1513     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1514       del_lock($this->dns);
1515     }
1516   }
1519   function copyPasteHandling_from_queue($s_action,$s_entry)
1520   {
1521     /* Check if Copy & Paste is disabled */
1522     if(!is_object($this->CopyPasteHandler)){
1523       return("");
1524     }
1526     $ui = get_userinfo();
1527     
1528     $tabs = $this->get_tab_defs();
1530     /* Add a single entry to queue */
1531     if($s_action == "cut" || $s_action == "copy"){
1533       /* Cleanup object queue */
1534       $this->CopyPasteHandler->cleanup_queue();
1535       $dn     = $this->terminals[$s_entry]['dn'];
1536       $oc     = $this->terminals[$s_entry]['objectClass'];
1537       $type   = $this->get_system_type($this->terminals[$s_entry]);
1539       $tab_o  = $tabs[$type]['CLASS'];
1540       $tab_c  = $tabs[$type]['TABCLASS'];
1541       $acl_c  = $tabs[$type]['TABNAME'];
1542       $acl    = $tabs[$type]['ACLC'];
1544       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1545         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1546       }
1547       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1548         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1549       }
1550     }
1552     /* Add entries to queue */
1553     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1555       /* Cleanup object queue */
1556       $this->CopyPasteHandler->cleanup_queue();
1558       /* Add new entries to CP queue */
1559       foreach($this->list_get_selected_items() as $id){
1560         $dn = $this->terminals[$id]['dn'];
1561         $oc = $this->terminals[$id]['objectClass']; 
1562         $type = $this->get_system_type($this->terminals[$id]);
1564         if(isset($tabs[$type])){
1565           $tab_o  = $tabs[$type]['CLASS'];
1566           $tab_c  = $tabs[$type]['TABCLASS'];
1567           $acl_c  = $tabs[$type]['TABNAME'];
1568           $acl    = $tabs[$type]['ACLC'];
1570           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1571             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1572           }
1573           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1574             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1575           }
1576         }
1577       }
1578     }
1580     /* Start pasting entries */
1581     if($s_action == "editPaste"){
1582       $this->start_pasting_copied_objects = TRUE;
1583     }
1584   
1585     /* Return C&P dialog */
1586     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1588       /* Get dialog */
1589       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1590       $data = $this->CopyPasteHandler->execute();
1592       /* Return dialog data */
1593       if(!empty($data)){
1594         return($data);
1595       }
1596     }
1598     /* Automatically disable status for pasting */
1599     if(!$this->CopyPasteHandler->entries_queued()){
1600       $this->start_pasting_copied_objects = FALSE;
1601     }
1602     return("");
1603   }
1606   function get_system_type($attrs)
1607   {
1608     $classes = $attrs['objectClass'];
1610     $type= "";
1611     if (in_array_ics('gosa_opsi_client', $classes)){
1612       $type= "opsi_client";
1613     }elseif (in_array_ics('sambaAccount', $classes) ||
1614         in_array_ics('sambaSamAccount', $classes)){
1615       $type= "winstation";
1616     }elseif (in_array_ics('ieee802Device', $classes)){
1617       $type= "component";
1618     }elseif (in_array_ics('gotoTerminal', $classes)){
1619       $type= "terminal";
1620     }elseif (in_array_ics('gotoWorkstation', $classes)){
1621       $type= "workstation";
1622     }elseif (in_array_ics('gotoPrinter', $classes)){
1623       $type= "printer";
1624     }elseif (in_array_ics('goFonHardware', $classes)){
1625       $type= "phone";
1626     }elseif (in_array_ics('goServer', $classes)){
1627       $type= "server";
1628     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1629       $type= "ArpNewDevice";
1630     }elseif (in_array_ics('GOhard', $classes)){
1631       $type= "NewDevice";
1632     }
1633     return ($type);
1634   }
1637   function convert_list($input)
1638   {
1639     $temp= "";
1641     $conv= array(
1642         "D" => array("plugins/systems/images/select_default.png",_("Template")),
1643         "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1644         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1645         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1647         "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1649         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1650         "S" => array("plugins/systems/images/select_server.png",_("Server")),
1651         "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1653         "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1654         "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1655         "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1657         "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1658         "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1659         "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1661         "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1662         "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1664         "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1665         "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1666         "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1668     /* Add opsi client to system types */
1669     if($this->opsi != NULL){
1670         $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1671     }
1673     /* Use locked icons 
1674      */
1675     if( in_array($input['type'],array("S","T","L")) && 
1676         isset($input['gotoMode'][0]) && 
1677         preg_match("/locked/",$input['gotoMode'][0])){
1678       $input['type'].="X";
1679     } elseif(in_array($input['type'],array("S","L")) &&
1680         isset($input['FAIstate'][0])){
1682     /* Add FAI state icons 
1683      */
1684       $type= "";
1685       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1686         case 'error':
1687           $type= 'E';
1688           break;
1689         case 'installing':
1690         case 'install':
1691         case 'sysinfo':
1692         case 'softupdate':
1693         case 'scheduledupdate':
1694           $type= 'B';
1695           break;
1696       }
1698       $input['type'].= $type;
1699     }   
1701     /* Use new images if object is from incoming 
1702      */
1703     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1704       $input['type']="N".$input['type'];
1705     }
1707     /* Check which flags this objects uses 
1708      */
1709     foreach ($conv  as $key => $value){
1710       $found = TRUE;
1711       if(strlen($key) != strlen($input['type'])) {
1712         $found = FALSE;
1713       }
1714       for($i = 0 ; $i < strlen($key) ; $i++){
1715         if(!preg_match("/".$key[$i]."/",$input['type'])){
1716           $found = FALSE;
1717         }
1718      }
1720       if($found){
1721         $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1722         $tmp['class']=$key;
1723         return $tmp;
1724       }
1725     }
1726   }
1729   function list_get_selected_items()
1730   {
1731     $ids = array();
1732     foreach($_POST as $name => $value){
1733       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1734         $id   = preg_replace("/^item_selected_/","",$name);
1735         $ids[$id] = $id;
1736       }
1737     }
1738     return($ids);
1739   }
1742   public function get_tab_defs()
1743   {
1744     $tabs = array(
1745         "incoming"    => array(
1746           "CLASS"     => "",
1747           "TABNAME"   => "",
1748           "TABCLASS"  => "",
1749           "ACLC"      => "incoming",
1750           "ACL"       => "incoming/systems"),
1752         "ArpNewDevice"=> array(
1753           "CLASS"     => "TERMTABS",
1754           "TABNAME"   => "termgeneric" ,
1755           "TABCLASS"  => "termtabs",
1756           "ACLC"      => "incoming",
1757           "ACL"       => "incoming/systems"),
1759         "NewDevice"   => array(
1760           "CLASS"     => "TERMTABS",
1761           "TABNAME"   => "termgeneric",
1762           "TABCLASS"  => "termtabs",
1763           "ACLC"      => "incoming",
1764           "ACL"       => "incoming/systems"),
1766         "terminal"    => array(
1767             "CLASS"     => "TERMTABS",
1768             "TABNAME"   => "termgeneric",
1769             "TABCLASS"  => "termtabs",
1770             "ACLC"      => "terminal",
1771             "ACL"       => "terminal/termgeneric"),
1773         "workstation" =>  array(
1774             "CLASS"   => "WORKTABS",
1775             "TABNAME" => "workgeneric",
1776             "TABCLASS"=> "worktabs",
1777             "ACLC"    => "workstation",
1778             "ACL"     => "workstation/workgeneric" ),
1780         "server"      => array(
1781             "CLASS"   => "SERVTABS",
1782             "TABNAME" => "servgeneric",
1783             "TABCLASS"=> "servtabs",
1784             "ACLC"    => "server",
1785             "ACL"     => "server/servgeneric"),
1787         "printer"     => array(
1788             "CLASS"   => "PRINTTABS",
1789             "TABNAME" => "printgeneric",
1790             "TABCLASS"=> "printtabs",
1791             "ACLC"    => "printer",
1792             "ACL"     => "printer/printgeneric"),
1794         "phone"       => array(
1795             "CLASS"   => "PHONETABS",
1796             "TABNAME" => "phoneGeneric",
1797             "TABCLASS"=> "phonetabs",
1798             "ACLC"    => "phone",
1799             "ACL"     => "phone/phoneGeneric"),
1801         "winstation"  => array(
1802             "CLASS"   => "WINTABS",
1803             "TABNAME" => "wingeneric",
1804             "TABCLASS"=> "wintabs",
1805             "ACLC"    => "winworkstation",
1806             "ACL"     => "winworkstation/wingeneric"),
1808         "component"   => array(
1809             "CLASS"   => "COMPONENTTABS",
1810             "TABNAME" => "componentGeneric",
1811             "TABCLASS"=> "componenttabs",
1812             "ACLC"    => "component",
1813             "ACL"     => "component/componentGeneric"));
1815     if($this->opsi != NULL){
1816       $tabs["opsi_client"] = array(
1817           "CLASS"   => "OPSITABS",
1818           "TABNAME" => "opsiGeneric" ,
1819           "TABCLASS"=> "opsi_tabs",
1820           "ACLC"    => "opsi" ,
1821           "ACL"     => "opsi/opsiGeneric");
1822     }
1824     return($tabs);
1825   }
1828   /*! \brief  Sets FAIstate to "install" for "New Devices".
1829               This function is some kind of "Post handler" for activated systems,
1830                it is called directly after the object (workstabs,servtabs) gets saved.  
1831       @param  String  $dn   The dn of the newly activated object.
1832       @return Boolean TRUE if activated else FALSE
1833    */
1834   function activate_new_device($dn)
1835   {
1836     $ldap = $this->config->get_ldap_link();
1837     $ldap->cd($this->config->current['BASE']);
1838     $ldap->cat($dn);
1839     if($ldap->count()){
1840       $attrs = $ldap->fetch();
1841       $type  = $this->get_system_type($attrs);
1842       if(!in_array($type,array("workstation","server"))) {
1843         $ocs = $attrs['objectClass'];
1844         unset($ocs['count']);
1845         $new_attrs = array();
1846         if(!in_array("FAIobject",$ocs)){
1847           $ocs[] = "FAIobject";
1848           $new_attrs['objectClass'] = $ocs;
1849         }
1850         $new_attrs['FAIstate'] = "install";
1851         $ldap->cd($dn);
1852         $ldap->modify($new_attrs);
1853         if (!$ldap->success()){
1854           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 
1855                 LDAP_MOD, "activate_new_device($dn)"));
1856         }else{
1857           return(TRUE);
1858         }
1859       }
1860     }
1861     return(FALSE);
1862   }
1865   /* !! Incoming dummy acls, required to defined acls for incoming objects
1866    */
1867   static function plInfo()
1868   {
1869     return (array(
1870           "plShortName"   => _("Incoming objects"),
1871           "plDescription" => _("Incoming objects"),
1872           "plSelfModify"  => FALSE,
1873           "plDepends"     => array(),
1874           "plPriority"    => 99,
1875           "plSection"     => array("administration"),
1876           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1877                                                           "objectClass"  => "")),
1878           "plProvidedAcls"=> array()
1879             
1880           ));
1881   }
1884 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1885 ?>