Code

Added delimiter to preg_quote
[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       session::set('objectinfo',$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));
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           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
544         }
545       }elseif($type == "NewDevice"){
546         if(!class_available("SelectDeviceType")){
547           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
548         }else{
549           $this->system_activation_object= array($this->dn);
550           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
552           // see condition  -$s_action == "SelectedSystemType"-  for further handling
553         }
554       }elseif(isset($tabs[$type])){
556         $class    = $tabs[$type]["CLASS"];
557         $acl_cat  = $tabs[$type]["ACLC"];
558         $tabclass = $tabs[$type]["TABCLASS"];
560         if(!class_available($tabclass)){
561           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
562         }else{
563           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
564           $this->systab->set_acl_base($this->dn);
565           session::set('objectinfo',$this->dn);
566           add_lock ($this->dn, $this->ui->dn);
567         }
568       }else{ 
569         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
570         $this->remove_lock();
571       }
572     }
575     /********************
576       Change password ...   
577      ********************/
579     /* Set terminals root password */
580     if ($s_action=="change_pw"){
581       $tabs = $this->get_tab_defs();
583       $dn   = $this->terminals[$s_entry]['dn'];
584       $type = $this->get_system_type($this->terminals[$s_entry]);
586       $class    = $tabs[$type]["CLASS"];
587       $acl      = $tabs[$type]["ACL"];
588       $tabclass = $tabs[$type]["TABCLASS"];
589       $ui       = get_userinfo();
590       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
591       if(preg_match("/w/",$tabacl)){
592         $this->dn= $this->terminals[$s_entry]['dn'];
593         session::set('objectinfo',$this->dn);
594         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
595       }else{
596         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
597       }
598     }
601     /********************
602       Password change finish, but check if entered data is ok 
603      ********************/
605     /* Correctly specified? */
606     if (isset($_POST['password_finish'])){
607       if ($_POST['new_password'] != $_POST['repeated_password']){
608         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
609         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
610       }
611     }
613     /********************
614       Password change finish
615      ********************/
617     /* Change terminal password */
618     if (isset($_POST['password_finish']) && 
619         $_POST['new_password'] == $_POST['repeated_password']){
621       /* Check if user is allowed to set password */
622       $tabs = $this->get_tab_defs();
624       $type = "";
625       foreach($this->terminals as $terminal){
626         if($terminal['dn'] == $this->dn){
627           $type  = $this->get_system_type($terminal);
628           break;
629         } 
630       }
632       /* Type detected */
633       $allow_for = array("terminal","workstation","server","component");
634       if(!empty($type) && in_array($type,$allow_for)){
636         /* Get infos */
637         $plug     = $tabs[$type]["TABNAME"];
638         $acl      = $tabs[$type]["ACL"];
639         $tabclass = $tabs[$type]["TABCLASS"];
640    
641         /* Get acls */
642         $ui       = get_userinfo();
643         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
645         /* Check acls */
646         if(preg_match("/w/",$tabacl)){
647           $ldap = $this->config->get_ldap_link();
648           $ldap->cd($this->dn);
649           $ldap->cat($this->dn);
650           $old_attrs = $ldap->fetch();
652           $attrs= array();
653           if ($_POST['new_password'] == ""){
655             /* Remove password attribute 
656              */
657             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
658               $attrs['objectClass'] = array();
659               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
660                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
661                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
662                 }
663               }
664             }
665             $attrs['userPassword']= array();
666           } else {
668             /* Add/modify password attribute 
669              */
670             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
671               $attrs['objectClass'] = array();
672               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
673                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
674               }
675               $attrs['objectClass'][] = "simpleSecurityObject";
676             }
678             if(class_available("passwordMethodCrypt")){
679               $pwd_m = new passwordMethodCrypt($this->config);
680               $pwd_m->set_hash("crypt/md5");
681               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
682             }else{
683               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
684               $attrs = array();
685             }
686           }
687           $ldap->modify($attrs);
688           if (!$ldap->success()){
689             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
690           }else{
691             if(class_available($plug)){ 
692               $p = new $plug($this->config,$this->dn);
693               $p->handle_post_events("modify");
694             }
695           }
696   
697           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
698         }else{
699           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
700         }
701       }else{
702         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
703       }
704       session::un_set('objectinfo');
705     }
708     /********************
709       Delete system cancel
710      ********************/
712     /* Delete terminal canceled? */
713     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
714       $this->remove_lock();
715       session::un_set('objectinfo');
716     }
719     /********************
720       Action(s) for MULTIPLE
721      ********************/
723     /********************
724       SCHEDULE action in GOsa Daemon
725      ********************/
727     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
728       $this->dns = array();
729       $ids = $this->list_get_selected_items();
731       /* Handle opsi actions */
732       if($s_action == "trigger_event_DaemonEvent_reinstall"){
733         foreach($ids as $key => $id){
734           if($this->terminals[$id]['type'] == "O"){
735             $obj = $this->terminals[$id];
736             $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
737             unset($ids[$key]);
738           }
739         }
740       }
742       if(count($ids) && class_available("DaemonEvent")){
743         $mac= array();
745         /* Collect target mac addresses */
746         $ldap = $this->config->get_ldap_link();
747         foreach($ids as $id){
748           $type = $this->get_system_type($this->terminals[$id]);
749           if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
750           if(isset($this->terminals[$id]['macAddress'][0])){
751             $mac[] = $this->terminals[$id]['macAddress'][0];
752           }else{
753             $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
754             $attrs= $ldap->fetch();
755             if (isset($attrs['macAddress'][0])){
756               $mac[]= $attrs['macAddress'][0];
757             }
758           }
759         }
760         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
761         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
762         $o_queue = new gosaSupportDaemon();
764         /* Skip installation or update trigerred events, 
765          *  if this entry is currently processing.
766          */
767         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
768           foreach($mac as $key => $mac_address){
769             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
771               $entry['STATUS'] = strtoupper($entry['STATUS']);
772               if($entry['STATUS'] == "PROCESSING" && 
773                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
774                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
775                 unset($mac[$key]);
777                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
778                 break;
779               }
780             }
781           }
782         }        
784         /* Prepare event to be added 
785          */
786         if(count($mac) && isset($events['BY_CLASS'][$type])){
787           $event = $events['BY_CLASS'][$type];
788           $this->systab = new $event['CLASS_NAME']($this->config);
789           $this->systab->add_targets($mac);
790           if(preg_match("/trigger_event/",$s_action)){
791             $this->systab->set_type(TRIGGERED_EVENT);
792           }else{
793             $this->systab->set_type(SCHEDULED_EVENT);
794           }
795         }
796       }
797     }
799     /* Insert scheduled events into queue */
800     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
801       $this->systab->save_object();
803       /* Save event 
804        */
805       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
806         $o_queue = new gosaSupportDaemon();
807         $o_queue->append($this->systab);
808         if($o_queue->is_error()){
809           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
810         }else{
811           $this->systab = FALSE;
812         }
813       }
814       if(isset($_POST['abort_event_dialog'])){
815         $this->systab = FALSE;
816       }
817     }
820     /********************
821       Delete MULTIPLE entries requested, display confirm dialog
822      ********************/
824     if ($s_action=="del_multiple" || $s_action == "del"){
825       $this->dns = array();
827       if($s_action == "del_multiple"){
828         $ids = $this->list_get_selected_items();
829       }else{
830         $ids = array($s_entry);
831       }
833       $ui = get_userinfo();
834       $tabs = $this->get_tab_defs();
836       if(count($ids)){
838         $disallowed = array();
839         foreach($ids as $id){
841           /* Get 'dn' from posted termlinst */
842           $attrs  = $this->terminals[$id];
843           $type   = $this->get_system_type($attrs);
844           $dn     = $attrs['dn'];
845           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
846           if(preg_match("/d/",$acl)){
847             $this->dns[$id] = $dn;
848           }else{
849             $disallowed[] = $dn;
850           }
851         }
853         if(count($disallowed)){
854           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
855         }
857         if(count($this->dns)){
859           if ($user= get_multiple_locks($this->dns)){
860             return(gen_locked_message($user,$this->dns));
861           }
863           $dns_names = array();
864           foreach($this->dns as $dn){
865             add_lock ($dn, $this->ui->dn);
866             $dns_names[] = LDAP::fix($dn);
867           }
869           /* Lock the current entry, so nobody will edit it during deletion */
870           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
871           $smarty->assign("multiple", true);
872           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
873         }
874       }
875     }
878     /********************
879       Delete MULTIPLE entries confirmed
880      ********************/
882     /* Confirmation for deletion has been passed. Users should be deleted. */
883     if (isset($_POST['delete_multiple_system_confirm'])){
885       $ui = get_userinfo();
886       $tabs = $this->get_tab_defs();
888       /* Remove user by user and check acls before removeing them */
889       foreach($this->dns as $key => $dn){
891         /* Get 'dn' from posted termlinst */
892         $attrs    = $this->terminals[$key];
893         $type= $this->get_system_type($attrs);
895         /* get object type */
896         $tabtype  = "termtabs";
897         $tabobj   = "TERMTABS";
898         $tabacl   = "";
899         if(isset($tabs[$type])){
900           $tabtype = $tabs[$type]['TABCLASS'];
901           $tabobj  = $tabs[$type]['CLASS'];
902           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
904           /* Load permissions for selected 'dn' and check if
905              we're allowed to remove this 'dn' */
906           if(preg_match("/d/",$tabacl)){ 
908             /* Delete request is permitted, perform LDAP action */
909             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
910               $this->systab= new termgeneric($this->config, $dn);
911               $this->systab->set_acl_base($dn);
912               $this->systab->remove_from_parent();
913             }elseif($tabtype=="phonetabs"){
914               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
915               $this->systab->set_acl_base($dn);
916               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
917             }else{
918               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
919               $this->systab->set_acl_base($dn);
920               $this->systab->delete();
921             }
922             unset ($this->systab);
923             $this->systab= NULL;
925           } else {
926             /* Normally this shouldn't be reached, send some extra
927                logs to notify the administrator */
928             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
929             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
930           }
931         }
933         /* Remove lock file after successfull deletion */
934         $this->remove_lock();
935         $this->dns = array();
936       }
937     }
939     /********************
940       Delete MULTIPLE entries Canceled
941      ********************/
943     /* Remove lock */
944    if(isset($_POST['delete_multiple_system_cancel'])){
946      /* Remove lock file after successfull deletion */
947      $this->remove_lock();
948      $this->dns = array();
949    }
952     /********************
953       Edit system type finished, check if everything went ok
954      ********************/
955     /* Finish user edit is triggered by the tabulator dialog, so
956        the user wants to save edited data. Check and save at this
957        point. */
959     /* Dirty workaround - MSG_DIALOG - OK
960       If a message dialog is shown and we press 'OK'
961        then try to save again.
962      */
963     foreach($_POST as $name => $value){
964       if(preg_match("/^MSG_OK/",$name)){
965         $_POST[$this->last_action] = TRUE;
966       }
967     }
969     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
971       /* If the save routine gets interrupted by a confirm dialog, 
972           store last action so we can trigger it again after 'Ok' was pressed.
973          (This is the case if a system gets modified while it is installing - GOsa si)
974        */
975       $this->last_action = ""; 
976       if(isset($_POST['edit_finish'])){
977         $this->last_action = "edit_finish"; 
978       }elseif(isset($_POST['edit_apply'])){
979         $this->last_action = "edit_apply";
980       }
982       /* Check tabs, will feed message array */
983       $message = $this->systab->check();
985       /* Save, or display error message? */
986       if (count($message) == 0){
987         $this->systab->save();
989         /* Post handling for activated systems 
990          */
991         if(isset($this->systab->was_activated) && $this->systab->was_activated){
992           $this->activate_new_device($this->systab->dn);
993         }
995         /* Terminal has been saved successfully, remove lock from LDAP. */
996         if (!isset($_POST['edit_apply'])){
997           if ($this->dn != "new"){
998             $this->remove_lock();
999           }
1001           unset ($this->systab);
1002           $this->systab= NULL;
1003           session::un_set('objectinfo');
1004         }else{
1005       
1006           /* Reinitialize tab */
1007           if($this->systab instanceof tabs){
1008             $this->systab->re_init();
1009           }
1010         }
1011       } else {
1012         /* Ok. There seem to be errors regarding to the tab data,
1013            show message and continue as usual. */
1014         msg_dialog::displayChecks($message);
1015       }
1016     }
1019     /********************
1020       Edit system was canceled 
1021      ********************/
1022     /* Cancel dialogs */
1023     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1024       if (isset($this->systab)){
1025         $this->remove_lock();
1026         unset ($this->systab);
1027       }
1028       $this->systab= NULL;
1029       session::un_set('objectinfo');
1030     }
1032     /********************
1033       Display edit dialog, or some other
1034      ********************/
1036     /* Show tab dialog if object is present */
1037     if (isset($this->systab->config)){
1038       $display= $this->systab->execute();
1040       /* Don't show buttons if tab dialog requests this */
1042       $dialog     = FALSE;
1043       $hide_apply = $this->dn == "new";
1044       $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1045       if(is_object($this->systab) && !isset($this->systab->by_object)){
1046         $dialog = TRUE;
1047         $hide_apply = TRUE;
1048       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1049         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1050         if($dia === TRUE || is_object($dia)){
1051           $dialog = TRUE;
1052         }  
1053       }
1054       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1055         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1056         $dialog = TRUE;
1057       }
1059       if (!$dialog){
1060         $display.= "<p style=\"text-align:right\">\n";
1061         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1062         $display.= "&nbsp;\n";
1063         if (!$hide_apply){
1064           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1065           $display.= "&nbsp;\n";
1066         }
1067         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1068         $display.= "</p>";
1069       }
1070       return ($display);
1071     }
1073     /* Check if there is a snapshot dialog open */
1074     $base = $this->DivListSystem->selectedBase;
1075     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1076       return($str);
1077     }
1079     /* Display dialog with system list */
1080     $this->DivListSystem->parent = $this;
1081     $this->DivListSystem->execute();
1083     /* Add departments if subsearch is disabled */
1084     if(!$this->DivListSystem->SubSearch){
1086       /* Add FAIstate to attributes if FAI is activated */
1087       if($this->fai_activated){
1088         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1089       }else{
1090         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1091       }
1092     }
1093     $this->reload();
1094     $this->DivListSystem->setEntries($this->terminals);
1095     return($this->DivListSystem->Draw());
1096   }
1099   /* Return departments, that will be included within snapshot detection */
1100   function get_used_snapshot_bases()
1101   {
1102     $tmp = array();
1104     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1106     $tabs = array(
1107         "terminal"        => get_ou('terminalRDN'),
1108         "workstation"     => get_ou('workstationRDN'),
1109         "incoming"        => get_ou('systemIncomingRDN'),
1110         "server"          => get_ou('serverRDN'),
1111         "printer"         => get_ou('printerRDN'),
1112         "phone"           => get_ou('phoneRDN'),
1113         "winworkstation"  => get_winstations_ou(),
1114         "component"       => get_ou('componentRDN')
1115         ); 
1117     foreach($tabs as $acl_cat => $dn){
1119       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1120       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1121         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1122       }
1123     }
1124     return($tmp); 
1125   }
1128   function remove_from_parent()
1129   {
1130     /* Optionally execute a command after we're done */
1131     $this->postremove();
1132   }
1135   /* Save data to object */
1136   function save_object()
1137   {
1138     $this->DivListSystem->save_object();
1139     if(is_object($this->CopyPasteHandler)){
1140       $this->CopyPasteHandler->save_object();
1141     }
1142   }
1145   /* Check values */
1146   function check()
1147   {
1148   }
1151   /* Save to LDAP */
1152   function save()
1153   {
1154   }
1156   function adapt_from_template($dn, $skip= array())
1157   {
1158   }
1160   function password_change_needed()
1161   {
1162   }
1164   function reload()
1165   {
1166     /* some var init */
1167     $ui = get_userinfo();
1168     $res              = array();
1169     $this->terminals  = array();
1170     $userregex        = "";
1171     $opsi_clients     = array();
1173     /* Set base for all searches */
1174     $base=  $this->DivListSystem->selectedBase;
1176     /* Prepare samba class name */
1177     $samba  ="";
1178     if ($this->DivListSystem->ShowWinWorkstations){
1179       if ($this->config->get_cfg_value("sambaversion") == "3"){
1180         $samba= "sambaSamAccount";
1181       } else {
1182         $samba= "sambaAccount";
1183       }
1184     }
1186     /* This array represents the combination between checkboxes and search filters */
1187     $objs = array( 
1188         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverRDN')),
1189         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalRDN')),
1190         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerRDN')),
1191         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentRDN')),
1192         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneRDN')),
1193         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1194         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1196     /* Include the 'Display Systems of user' attribute */ 
1197     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1198       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1199     }
1201     /* Attributes to fetch */
1202     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1203     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1205     /* Add FAIstate to attributes if FAI is activated */
1206     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1207     if(!empty($tmp)){
1208       $sys_attrs[] = "FAIstate";
1209     }    
1211     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1212     foreach($objs as $checkBox => $oc){
1214       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1215         if($this->DivListSystem->SubSearch){
1216           if($oc['CLASS'] != ""){
1217             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1218             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1219             $res = array_merge($res,$new_res);
1220           }
1221         }else{
1222           /* User filter? */
1223           if($oc['CLASS'] != ""){
1224             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1225             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1226           }
1227         }
1228       } 
1229     }
1231     /* Search for incoming objects */ 
1232     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1233     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1235     /* Append opsi systems, the opsi extension have to installed.
1236         (Only, if we are allowed to view opsi hosts)
1237      */
1238     if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1239       $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1240       if(preg_match("/r/",$o_acl)){
1241         $opsi_clients = $this->opsi->get_hosts_for_system_management();
1242         if($this->opsi->is_error()){
1243           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1244         }
1245       }
1246     }
1247     
1248     /* Get all gotoTerminal's */
1249     $t_id = 0;
1250     $opsi_map  = array();
1251     foreach ($res as $value){
1253       $tmp= $value['dn'];
1254       $add= "";
1256       /* Extract base */
1257       foreach($objs as $obj){
1258         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1259           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1260         }
1261       }
1263       /* Create a string containing the last part of the department. */
1264       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1265       if(empty($dn_name)){
1266         $dn_name = "/";
1267       }
1269       /* check if current object is a new one */
1270       if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1271         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1272           $add= "- "._("New terminal");
1273         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1274           $add= "- "._("New workstation");
1275         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1276           $add= "- "._("Unknown device");
1277         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1278           $add= "- "._("New Device");
1279         }
1280       } 
1282       /* Detect type of object and create an entry for $this->terminals */
1283       $terminal = array();
1285        if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1287          /* check acl */
1288          $terminal             = $value;
1289          $terminal['type']     = "O";
1291        } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1293         /* check acl */
1294         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1295         if($add != "" || preg_match("/r/",$acl)) {
1296           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1297             $terminal             = $value;
1298             $terminal['type']     = "T";
1299             $terminal['is_new']   = $add;
1300           } else {
1301             $terminal             = $value;
1302             $terminal['type']     = "D";
1303             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1304             $terminal['location'] = array_search($tmp, $this->config->departments); 
1305           }
1306         }
1307       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1309         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1310         if($add != "" || preg_match("/r/",$acl)) {
1311           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1312             $terminal             = $value;
1313             $terminal['type']     = "L";
1314             $terminal['is_new']   = $add;
1315           } else {
1316             $terminal             = $value;
1317             $terminal['type']     = "D";
1318             $terminal['location'] = array_search($tmp, $this->config->departments);
1319             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1320           }
1321 #          if (isset($value["FAIstate"][0])){
1322 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1323 #          }
1324         }
1325       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1326        
1327    
1328         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1329         if($add != "" || preg_match("/r/",$acl)) {
1331           $terminal             = $value;
1332           $terminal['type']     = "P";
1333         }
1334       } elseif (in_array_ics('goServer', $value["objectClass"])){
1336         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1337         if($add != "" || preg_match("/r/",$acl)) {
1339           $terminal             = $value;
1340           $terminal['type']     = "S";
1341 #          if (isset($value["FAIstate"][0])){
1342 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1343 #          }
1344         }
1345       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1347         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1348         if($add != "" || preg_match("/r/",$acl)) {
1350           $terminal             = $value;
1351           $terminal['type']     = "F";
1352         }
1353       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1355         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1356                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1357                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1358         if($add != "" || preg_match("/r/",$acl)) {
1360           $terminal = $value;
1361           $terminal['type']   = "Q";
1362           $terminal['is_new'] = $add;
1363         }
1364       } elseif (in_array_ics('ieee802Device', $value["objectClass"]) && 
1365         !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1366         $type= "winstation";
1367         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1368         if($add != "" || preg_match("/r/",$acl)) {
1370           $terminal             = $value;
1371           $terminal['type']     = "C";
1372         }
1373       } else{
1375         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1376         if (isset($value['sambaDomainName'])){
1377           $domain= " [".$value['sambaDomainName'][0]."]";
1378         } else {
1379           $domain= "";
1380         }
1381         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1382         if($add != "" || preg_match("/r/",$acl)) {
1383           $terminal=$value;
1384           $terminal['type']     ="W";
1385           $terminal['domain']   = $name.$domain;
1386         }
1387       }
1389       /* Append collected data to the host list.
1390        */
1391       if(count($terminal)){
1392         $t_id ++ ;
1393         $this->terminals[$t_id]=$terminal;
1394         $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1395       }
1396     }
1399     /* Merge real hosts with opsi hosts.
1400        If there is a samba host, then merge it with the opsi host,
1401         to avoid duplicate entries.
1402      */
1403     foreach($opsi_clients as $entry){
1404       if(isset($opsi_map[$entry['cn'][0]])){
1405         continue;
1406       }
1407       $terminal             = $entry;
1408       $terminal['type']     = "O";
1409       $this->terminals[] = $terminal;
1410     }
1412     $tmp  =array();
1413     $tmp2 =array();
1414     foreach($this->terminals as $tkey => $val ){
1415       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1416       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1417     }
1418     natcasesort($tmp2);
1419     $this->terminals=array();
1420     foreach($tmp2 as $val){
1421       $this->terminals[]=$tmp[$val];
1422     }
1423     reset ($this->terminals);
1424   }
1426   function remove_lock()
1427   {
1428     if (isset($this->systab->dn)){
1429       del_lock ($this->systab->dn);
1430     }
1431     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1432       del_lock($this->dn);
1433     }
1434     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1435       del_lock($this->dns);
1436     }
1437   }
1440   function copyPasteHandling_from_queue($s_action,$s_entry)
1441   {
1442     /* Check if Copy & Paste is disabled */
1443     if(!is_object($this->CopyPasteHandler)){
1444       return("");
1445     }
1447     $ui = get_userinfo();
1448     
1449     $tabs = $this->get_tab_defs();
1451     /* Add a single entry to queue */
1452     if($s_action == "cut" || $s_action == "copy"){
1454       /* Cleanup object queue */
1455       $this->CopyPasteHandler->cleanup_queue();
1456       $dn     = $this->terminals[$s_entry]['dn'];
1457       $oc     = $this->terminals[$s_entry]['objectClass'];
1458       $type   = $this->get_system_type($this->terminals[$s_entry]);
1460       $tab_o  = $tabs[$type]['CLASS'];
1461       $tab_c  = $tabs[$type]['TABCLASS'];
1462       $acl_c  = $tabs[$type]['TABNAME'];
1463       $acl    = $tabs[$type]['ACLC'];
1465       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1466         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1467       }
1468       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1469         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1470       }
1471     }
1473     /* Add entries to queue */
1474     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1476       /* Cleanup object queue */
1477       $this->CopyPasteHandler->cleanup_queue();
1479       /* Add new entries to CP queue */
1480       foreach($this->list_get_selected_items() as $id){
1481         $dn = $this->terminals[$id]['dn'];
1482         $oc = $this->terminals[$id]['objectClass']; 
1483         $type = $this->get_system_type($this->terminals[$id]);
1485         if(isset($tabs[$type])){
1486           $tab_o  = $tabs[$type]['CLASS'];
1487           $tab_c  = $tabs[$type]['TABCLASS'];
1488           $acl_c  = $tabs[$type]['TABNAME'];
1489           $acl    = $tabs[$type]['ACLC'];
1491           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1492             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1493           }
1494           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1495             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1496           }
1497         }
1498       }
1499     }
1501     /* Start pasting entries */
1502     if($s_action == "editPaste"){
1503       $this->start_pasting_copied_objects = TRUE;
1504     }
1505   
1506     /* Return C&P dialog */
1507     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1509       /* Get dialog */
1510       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1511       $data = $this->CopyPasteHandler->execute();
1513       /* Return dialog data */
1514       if(!empty($data)){
1515         return($data);
1516       }
1517     }
1519     /* Automatically disable status for pasting */
1520     if(!$this->CopyPasteHandler->entries_queued()){
1521       $this->start_pasting_copied_objects = FALSE;
1522     }
1523     return("");
1524   }
1527   function get_system_type($attrs)
1528   {
1529     $classes = $attrs['objectClass'];
1531     $type= "";
1532     if (in_array_ics('gosa_opsi_client', $classes)){
1533       $type= "opsi_client";
1534     }elseif (in_array_ics('sambaAccount', $classes) ||
1535         in_array_ics('sambaSamAccount', $classes)){
1536       $type= "winstation";
1537     }elseif (in_array_ics('ieee802Device', $classes)){
1538       $type= "component";
1539     }elseif (in_array_ics('gotoTerminal', $classes)){
1540       $type= "terminal";
1541     }elseif (in_array_ics('gotoWorkstation', $classes)){
1542       $type= "workstation";
1543     }elseif (in_array_ics('gotoPrinter', $classes)){
1544       $type= "printer";
1545     }elseif (in_array_ics('goFonHardware', $classes)){
1546       $type= "phone";
1547     }elseif (in_array_ics('goServer', $classes)){
1548       $type= "server";
1549     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1550       $type= "ArpNewDevice";
1551     }elseif (in_array_ics('GOhard', $classes)){
1552       $type= "NewDevice";
1553     }
1554     return ($type);
1555   }
1558   function convert_list($input)
1559   {
1560     $temp= "";
1562     $conv= array(
1563         "D" => array("plugins/systems/images/select_default.png",_("Template")),
1564         "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1565         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1566         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1568         "W" => array("plugins/systems/images/select_winstation.png",_("Win workstation")),
1570         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1571         "S" => array("plugins/systems/images/select_server.png",_("Server")),
1572         "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1574         "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1575         "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1576         "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1578         "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1579         "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1580         "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1582         "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1583         "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1585         "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1586         "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1587         "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1589     /* Add opsi client to system types */
1590     if($this->opsi != NULL){
1591         $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1592     }
1594     /* Use locked icons 
1595      */
1596     if( in_array($input['type'],array("S","T","L")) && 
1597         isset($input['gotoMode'][0]) && 
1598         preg_match("/locked/",$input['gotoMode'][0])){
1599       $input['type'].="X";
1600     } elseif(in_array($input['type'],array("S","L")) &&
1601         isset($input['FAIstate'][0])){
1603     /* Add FAI state icons 
1604      */
1605       $type= "";
1606       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1607         case 'error':
1608           $type= 'E';
1609           break;
1610         case 'installing':
1611         case 'install':
1612         case 'sysinfo':
1613         case 'softupdate':
1614         case 'scheduledupdate':
1615           $type= 'B';
1616           break;
1617       }
1619       $input['type'].= $type;
1620     }   
1622     /* Use new images if object is from incoming 
1623      */
1624     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1625       $input['type']="N".$input['type'];
1626     }
1628     /* Check which flags this objects uses 
1629      */
1630     foreach ($conv  as $key => $value){
1631       $found = TRUE;
1632       if(strlen($key) != strlen($input['type'])) {
1633         $found = FALSE;
1634       }
1635       for($i = 0 ; $i < strlen($key) ; $i++){
1636         if(!preg_match("/".$key[$i]."/",$input['type'])){
1637           $found = FALSE;
1638         }
1639      }
1641       if($found){
1642         $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1643         $tmp['class']=$key;
1644         return $tmp;
1645       }
1646     }
1647   }
1650   function list_get_selected_items()
1651   {
1652     $ids = array();
1653     foreach($_POST as $name => $value){
1654       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1655         $id   = preg_replace("/^item_selected_/","",$name);
1656         $ids[$id] = $id;
1657       }
1658     }
1659     return($ids);
1660   }
1663   public function get_tab_defs()
1664   {
1665     $tabs = array(
1666         "incoming"    => array(
1667           "CLASS"     => "",
1668           "TABNAME"   => "",
1669           "TABCLASS"  => "",
1670           "ACLC"      => "incoming",
1671           "ACL"       => "incoming/systems"),
1673         "ArpNewDevice"=> array(
1674           "CLASS"     => "TERMTABS",
1675           "TABNAME"   => "termgeneric" ,
1676           "TABCLASS"  => "termtabs",
1677           "ACLC"      => "incoming",
1678           "ACL"       => "incoming/systems"),
1680         "NewDevice"   => array(
1681           "CLASS"     => "TERMTABS",
1682           "TABNAME"   => "termgeneric",
1683           "TABCLASS"  => "termtabs",
1684           "ACLC"      => "incoming",
1685           "ACL"       => "incoming/systems"),
1687         "terminal"    => array(
1688             "CLASS"     => "TERMTABS",
1689             "TABNAME"   => "termgeneric",
1690             "TABCLASS"  => "termtabs",
1691             "ACLC"      => "terminal",
1692             "ACL"       => "terminal/termgeneric"),
1694         "workstation" =>  array(
1695             "CLASS"   => "WORKTABS",
1696             "TABNAME" => "workgeneric",
1697             "TABCLASS"=> "worktabs",
1698             "ACLC"    => "workstation",
1699             "ACL"     => "workstation/workgeneric" ),
1701         "server"      => array(
1702             "CLASS"   => "SERVTABS",
1703             "TABNAME" => "servgeneric",
1704             "TABCLASS"=> "servtabs",
1705             "ACLC"    => "server",
1706             "ACL"     => "server/servgeneric"),
1708         "printer"     => array(
1709             "CLASS"   => "PRINTTABS",
1710             "TABNAME" => "printgeneric",
1711             "TABCLASS"=> "printtabs",
1712             "ACLC"    => "printer",
1713             "ACL"     => "printer/printgeneric"),
1715         "phone"       => array(
1716             "CLASS"   => "PHONETABS",
1717             "TABNAME" => "phoneGeneric",
1718             "TABCLASS"=> "phonetabs",
1719             "ACLC"    => "phone",
1720             "ACL"     => "phone/phoneGeneric"),
1722         "winstation"  => array(
1723             "CLASS"   => "WINTABS",
1724             "TABNAME" => "wingeneric",
1725             "TABCLASS"=> "wintabs",
1726             "ACLC"    => "winworkstation",
1727             "ACL"     => "winworkstation/wingeneric"),
1729         "component"   => array(
1730             "CLASS"   => "COMPONENTTABS",
1731             "TABNAME" => "componentGeneric",
1732             "TABCLASS"=> "componenttabs",
1733             "ACLC"    => "component",
1734             "ACL"     => "component/componentGeneric"));
1736     if($this->opsi != NULL){
1737       $tabs["opsi_client"] = array(
1738           "CLASS"   => "OPSITABS",
1739           "TABNAME" => "opsiGeneric" ,
1740           "TABCLASS"=> "opsi_tabs",
1741           "ACLC"    => "opsi" ,
1742           "ACL"     => "opsi/opsiGeneric");
1743     }
1745     return($tabs);
1746   }
1749   /*! \brief  Sets FAIstate to "install" for "New Devices".
1750               This function is some kind of "Post handler" for activated systems,
1751                it is called directly after the object (workstabs,servtabs) gets saved.  
1752       @param  String  $dn   The dn of the newly activated object.
1753       @return Boolean TRUE if activated else FALSE
1754    */
1755   function activate_new_device($dn)
1756   {
1757     $ldap = $this->config->get_ldap_link();
1758     $ldap->cd($this->config->current['BASE']);
1759     $ldap->cat($dn);
1760     if($ldap->count()){
1761       $attrs = $ldap->fetch();
1762       $type  = $this->get_system_type($attrs);
1763       if(!in_array($type,array("workstation","server"))) {
1764         $ocs = $attrs['objectClass'];
1765         unset($ocs['count']);
1766         $new_attrs = array();
1767         if(!in_array("FAIobject",$ocs)){
1768           $ocs[] = "FAIobject";
1769           $new_attrs['objectClass'] = $ocs;
1770         }
1771         $new_attrs['FAIstate'] = "install";
1772         $ldap->cd($dn);
1773         $ldap->modify($new_attrs);
1774         if (!$ldap->success()){
1775           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 
1776                 LDAP_MOD, "activate_new_device($dn)"));
1777         }else{
1778           return(TRUE);
1779         }
1780       }
1781     }
1782     return(FALSE);
1783   }
1786   /* !! Incoming dummy acls, required to defined acls for incoming objects
1787    */
1788   static function plInfo()
1789   {
1790     return (array(
1791           "plShortName"   => _("Incoming objects"),
1792           "plDescription" => _("Incoming objects"),
1793           "plSelfModify"  => FALSE,
1794           "plDepends"     => array(),
1795           "plPriority"    => 99,
1796           "plSection"     => array("administration"),
1797           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1798                                                           "objectClass"  => "")),
1799           "plProvidedAcls"=> array()
1800             
1801           ));
1802   }
1805 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1806 ?>