Code

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