Code

Updated server services
[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 $departments    = array();
30   /* Dialog attributes */
31   var $systab   = NULL;
32   var $terminals= array();
33   var $ui       = NULL;
34   var $DivListSystem;
35   var $start_pasting_copied_objects = FALSE;
36   var $CopyPasteHandler   = NULL;
38   /* Arp hanlding activated */
39   var $arp_handling_active = FALSE;
40   var $last_action = "";
42   var $dns = array();
44   var $system_activation_object = ""; // The object to activate (NewDevice)
45   var $fai_activated  = FALSE;
46   var $si_active      = FALSE;
48   var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
50   function systems (&$config, $ui)
51   {
52     /* Save configuration for internal use */
53     $this->config= $config;
54     $this->ui= $ui;
56     /* Add FAIstate to attributes if FAI is activated */
57     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
58     if(!empty($tmp)){
59       $this->fai_activated = TRUE;
60     }
62     /* Creat dialog object */
63     $this->DivListSystem = new divListSystem($this->config,$this);
65     /* Copy & Paste enabled ?*/
66     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
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     }
81   }
84   function execute()
85   {
86     /* Call parent execute */
87     plugin::execute();
89     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
91     /********************
92       Check for functional posts, edit|delete|add|... system devices 
93      ********************/
94     $s_action     = "";                       // Contains the action to proceed
95     $s_entry      = "";                       // The value for s_action
96     $base_back    = "";                       // The Link for Backbutton
97     $smarty       = get_smarty();
99     /* Test Posts */
100     foreach($_POST as $key => $val){
101       // Post for delete
102       if(preg_match("/system_del.*/",$key)){
103         $s_action = "del";
104         $s_entry  = preg_replace("/system_del_/i","",$key);
105         // Post for edit
106       }elseif(preg_match("/system_edit_.*/",$key)){
107         $s_action="edit";
108         $s_entry  = preg_replace("/system_edit_/i","",$key);
109         // Post for new
110       }elseif(preg_match("/system_new.*/",$key)){
111         $s_action="new";
112       }elseif(preg_match("/system_tplnew.*/i",$key)){
113         $s_action="new_tpl";
114       }elseif(preg_match("/system_setpwd_.*/i",$key)){
115         $s_action="change_pw";
116         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
117       }elseif(preg_match("/gen_cd_.*/i",$key)){
118         $s_action="gen_cd";
119         $s_entry  = preg_replace("/gen_cd_/i","",$key);
120       }elseif(preg_match("/^copy_.*/",$key)){
121         $s_action="copy";
122         $s_entry  = preg_replace("/^copy_/i","",$key);
123       }elseif(preg_match("/^cut_.*/",$key)){
124         $s_action="cut";
125         $s_entry  = preg_replace("/^cut_/i","",$key);
126       }
127     }
128    
129     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
130     $s_entry  = preg_replace("/_.$/","",$s_entry);
132     /* Edit was requested by pressing the name(link) of an item */
133     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
134       $s_action ="edit";
135       $s_entry  = $_GET['id'];
136     }
137     /* Create options */
138     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
139       $s_action = "newsystem";
140       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
141     }
143     /* handle C&P from layers menu */
144     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
145       $s_action = "copy_multiple";
146     }
147     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
148       $s_action = "cut_multiple";
149     }
150     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
151       $s_action = "editPaste";
152     }
154     /* Handle daemon events */
155     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
156       $s_action = $_POST['menu_action'];
157     }
158     
159     /* Handle daemon events */
160     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
161       $s_action = $_POST['menu_action'];
162     }
164     /* handle remove from layers menu */
165     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
166       $s_action = "del_multiple";
167     }
168     
169     /* Handle instant actions from layers menu */
170     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
171             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
172               $s_action = "${act}_multiple";
173             }
174     }
176     /* Activate multiple machines */
177     if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
178       $s_action = "activate_multiple";
179     }
181     /* Check for exeeded sizelimit */
182     if (($message= check_sizelimit()) != ""){
183       return($message);
184     }
186     /* Try to get informations about what kind of system to create */
187     if ($s_action=="new") {
188       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
189     }
191     /* Incoming handling  
192      * If someone made a systemtype and ogroup selection 
193      * Display the new requested entry type ... servtab  in case of server and so on.
194      */
195     if(isset($_POST['SystemTypeChoosen'])){
196       $s_action = "SelectedSystemType";
197     }
199     /********************
200       Copy & Paste Handling  ...
201      ********************/
203     /* Display the copy & paste dialog, if it is currently open */
204     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
205     if($ret){
206       return($ret);
207     }
208   
210     /********************
211       Create FAI CD ...   
212      ********************/
213     if ($s_action=="gen_cd"){
214       $this->dn= $this->terminals[$s_entry]['dn'];
215       session::set('objectinfo',$this->dn);
216       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
217     }
220     /* Start CD-Creation */
221     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
222       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
223       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
224     }
227     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
229       $return_button   = "<form method='get' action='main.php' target='_parent'>
230         <input type='submit' value='"._("Back")."'>
231         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
232         </form>";
234       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
236       /* Get and check command */
237       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
238       
239       if (check_command($command)){
240         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
242         /* Print out html introduction */
243         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
244           <html>
245           <head>
246           <title></title>
247           <style type="text/css">@import url("themes/default/style.css");</style>
248           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
249           </head>
250           <body style="background: none; margin:4px;" id="body" >
251           <pre>';
253         /* Open process handle and check if it is a valid process */
254         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
255         if (is_resource($process)) {
256           fclose($pipes[0]);
258           /* Print out returned lines && write JS to scroll down each line */
259           while (!feof($pipes[1])){
260             $cur_dat = fgets($pipes[1], 1024);
261             echo $cur_dat;
262             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
263             flush();
264           }
265         }
267         /* Get error string && close streams */
268         $buffer= stream_get_contents($pipes[2]);
270         fclose($pipes[1]);
271         fclose($pipes[2]);
272         echo "</pre>";
274         /* Check return code */
275         $ret= proc_close($process);
276         if ($ret != 0){
277           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
278           echo "<pre style='color:red'>$buffer</pre>";
279         }
283         echo $return_button."<br>";
285       } else {
286         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
287         echo $tmp;
288       }
290       /* Scroll down completly */
291       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
292       echo '</body></html>';
293       flush();
294       exit;
295     }
298     /********************
299       New Device hanlding  (Ogroup/System select dialog.)
300      ********************/
302     if($s_action == "SelectedSystemType"){
304       /* Possible destination system types 
305        */
306       $tabs = array(
307           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     
308             "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
309           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     
310             "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
311           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     
312             "TABCLASS" =>"servtabs",      "ACL"=> "server"));
314       /* Remember dialog selection.
315        */
316       $selected_group = $_POST['ObjectGroup'];
317       $selected_system = $_POST['SystemType'];
319       $this->systab = NULL;
321       /* Check if system type exists. It should! */
322       if(isset($tabs[$selected_system])){
324         /* Get tab informations */
325         $class    = $tabs[$selected_system]["CLASS"];
326         $tabname  = $tabs[$selected_system]["TABNAME"];
327         $tabclass = $tabs[$selected_system]["TABCLASS"];
328         $acl_cat  = $tabs[$selected_system]["ACL"];
331         if(!class_available($tabclass)){
332           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
333         }else{
335           /* Go through all objects that should be activated */
336           foreach($this->system_activation_object as $key => $dn){
338             /* Remove entry from list, to avoid page-reload problems */
339             unset($this->system_activation_object[$key]);
341             /* Load permissions for selected 'dn' and check if
342                we're allowed to create this 'dn' */
343             $this->dn = $dn;
344             $ui       = get_userinfo();
345             $tabacl   = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
347             /* We are allowed to create the requested system type */
348             if(preg_match("/c/",$tabacl)){
349               $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
350               $this->systab->set_acl_base($this->DivListSystem->selectedBase);
351               $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
352               $this->systab->base = $this->DivListSystem->selectedBase;
355               if($selected_group != "none"){
357                 /*******
358                  * Set gotoMode to active if we there was an ogroup selected. 
359                  */
360                 $found = false;
361                 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
362                   if(isset($this->systab->by_object[$tab]->gotoMode)) {
363                     $found = true;
364                     $this->systab->by_object[$tab]->gotoMode = $value;
365                   }
366                 }
367                 if(!$found){
368                   msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
369                 }
371                 /*******
372                  * Update object group membership
373                  */
374                 $og = new ogroup($this->config,$selected_group);
375                 if($og){
376                   $og->AddDelMembership($this->systab->dn);
377                   $og->save();
378                 }
380                 /*******
381                  * Set default system specific attributes 
382                  */
383                 foreach (array("workservice", "termservice") as $cls){
384                   if (isset($this->systab->by_object[$cls])){
385                     $this->systab->by_object[$cls]->gotoXMouseport= "";
386                     $this->systab->by_object[$cls]->gotoXMouseType= "";
387                     $this->systab->by_object[$cls]->gotoXResolution= "";
388                     $this->systab->by_object[$cls]->gotoXColordepth= "";
389                   }
390                 }
392                 // Enable activation
393                 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
394                   if (isset($this->systab->by_object[$cls])){
395                     $this->systab->by_object[$cls]->auto_activate= TRUE;
396                   }
397                 }
399                 // Enable sending of LDAP events
400                 if (isset($this->systab->by_object["workstartup"])){
401                   $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
402                 }
403               }
405               /* Don't save directly if there is no objectGroup selected.
406                  The user will then be able to configure the missing attributes 
407                  on his own.
408                */
409               if($selected_group != "none"){
410                 $this->systab->save();
411                 $this->systab = NULL;
413                 if(!isset($ldap)){
414                   $ldap = $this->config->get_ldap_link();
415                 }
416                 $ldap->cd ($this->dn);
417                 $ldap->cat($this->dn, array('dn'));
418                 if(count($ldap->fetch())){
419                   $ldap->cd($this->dn);
420                   $ldap->rmDir($this->dn);
421                 }
422               }
423             }else{
424               msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
425             }
426           }
427         }
428       }
429     }
432     if (isset($_POST['create_system'])||$s_action=="newsystem") {
433     
434       $this->last_action = "";
435   
436       /* If the current entry is an incoming object 
437        * $sw = System type as posted in new incoming handling dialog 
438        */ 
439       if(isset($_POST['system'])){
440         $sw = $_POST['system'];
441       }else{
442         $sw = $s_entry;
443       }
444       $this->dn= "new";
446       $tabs = array(
447           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
448           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
449           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
450           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
451           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
452           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
454       if(isset($tabs[$sw])){
455         $class    = $tabs[$sw]["CLASS"];
456         $tabname  = $tabs[$sw]["TABNAME"];
457         $tabclass = $tabs[$sw]["TABCLASS"];
458         $acl_cat  = $tabs[$sw]["ACL"];
460         /* Load permissions for selected 'dn' and check if
461            we're allowed to remove this 'dn' */
462         $ui       = get_userinfo();
463         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
464         if(preg_match("/c/",$tabacl)){
466           if(!class_available($tabclass)){
467             msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
468           }else{
469             $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
470             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
471             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
472             $this->systab->base = $this->DivListSystem->selectedBase;
473           }
474         }else{
475           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
476         }
477       }
478     }
481     /********************
482       System activation
483      ********************/
485     /* User wants to edit data? */
486     if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
487       $this->system_activation_object = array();
488       foreach($this->list_get_selected_items() as $id) {
489         $obj = $this->terminals[$id];
490         $type= $this->get_system_type($obj);
491         if($type == "NewDevice"){
492           $this->system_activation_object[] = $obj['dn'];
493         }
494       }
495       if(count($this->system_activation_object)){
496         $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
497       }
498     }
501     /********************
502       Edit system ...   
503      ********************/
505     /* User wants to edit data? */
506     if (($s_action == "edit") && (!isset($this->systab->config))){
507       $this->last_action = "";
508       $this->dn= $this->terminals[$s_entry]['dn'];
510       /* Check locking, save current plugin in 'back_plugin', so
511          the dialog knows where to return. */
512       if (($user= get_lock($this->dn)) != ""){
513         return(gen_locked_message ($user, $this->dn));
514       }
516       /* Find out more about the object type */
517       $ldap= $this->config->get_ldap_link();
518       $ldap->cat($this->dn, array('objectClass','gotoMode'));
519       $attrs= $ldap->fetch();
520       $type= $this->get_system_type($attrs);
522       /* Lock the current entry, so everyone will get the
523          above dialog */
524       $tabs = array(
525           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
526           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
527           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
528           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
529           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
530           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
531           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
534       if($type == "ArpNewDevice"){
535         if(!class_available("ArpNewDeviceTabs")){
536           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
537         }else{
538           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
539         }
540       }elseif($type == "NewDevice"){
541         if(!class_available("SelectDeviceType")){
542           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
543         }else{
544           $this->system_activation_object= array($this->dn);
545           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
546         }
547       }elseif(isset($tabs[$type])){
549         $class    = $tabs[$type]["CLASS"];
550         $acl_cat  = $tabs[$type]["ACL"];
551         $tabclass = $tabs[$type]["TABCLASS"];
553         if(!class_available($tabclass)){
554           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
555         }else{
556           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
557           $this->systab->set_acl_base($this->dn);
558           session::set('objectinfo',$this->dn);
559           add_lock ($this->dn, $this->ui->dn);
560         }
561       }else{ 
562         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
563         $this->remove_lock();
564       }
565     }
568     /********************
569       Change password ...   
570      ********************/
572     /* Set terminals root password */
573     if ($s_action=="change_pw"){
574       $tabs = array(
575           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
576           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
577           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
578           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
579           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
580           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
581           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
582           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
583           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
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         session::set('objectinfo',$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 = array(
625           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"    ,"PLUG"=>"termgeneric"),
626           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
627           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"      ,"PLUG"=>"servgeneric"),
628           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
630       /* Detect object type */
631       $type = "";
632       foreach($this->terminals as $terminal){
633         if($terminal['dn'] == $this->dn){
634           $type  = $this->get_system_type($terminal);
635           break;
636         } 
637       }
639       /* Type detected */
640       $allow_for = array("terminal","workstation","server","component");
641       if(!empty($type) && in_array($type,$allow_for)){
643         /* Get infos */
644         $plug     = $tabs[$type]["PLUG"];
645         $class    = $tabs[$type]["CLASS"];
646         $acl      = $tabs[$type]["ACL"];
647         $tabclass = $tabs[$type]["TABCLASS"];
648     
649         /* Get acls */
650         $ui       = get_userinfo();
651         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
653         /* Check acls */
654         if(preg_match("/w/",$tabacl)){
655           $ldap = $this->config->get_ldap_link();
656           $ldap->cd($this->dn);
657           $ldap->cat($this->dn);
658           $old_attrs = $ldap->fetch();
660           $attrs= array();
661           if ($_POST['new_password'] == ""){
663             /* Remove password attribute 
664              */
665             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
666               $attrs['objectClass'] = array();
667               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
668                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
669                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
670                 }
671               }
672             }
673             $attrs['userPassword']= array();
674           } else {
676             /* Add/modify password attribute 
677              */
678             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
679               $attrs['objectClass'] = array();
680               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
681                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
682               }
683               $attrs['objectClass'][] = "simpleSecurityObject";
684             }
686             if(class_available("passwordMethodCrypt")){
687               $pwd_m = new passwordMethodCrypt($this->config);
688               $pwd_m->set_hash("crypt/md5");
689               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
690             }else{
691               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
692               $attrs = array();
693             }
694           }
695           $ldap->modify($attrs);
696           if (!$ldap->success()){
697             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
698           }else{
699             if(class_available($plug)){
700               $p = new $plug($this->config,$this->dn);
701               $p->handle_post_events("modify");
702             }
703           }
704   
705           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
706         }else{
707           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
708         }
709       }else{
710         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
711       }
712       session::un_set('objectinfo');
713     }
716     /********************
717       Delete system cancel
718      ********************/
720     /* Delete terminal canceled? */
721     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
722       $this->remove_lock();
723       session::un_set('objectinfo');
724     }
727     /********************
728       Action(s) for MULTIPLE
729      ********************/
731     /********************
732       SCHEDULE action in GOsa Daemon
733      ********************/
735     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
736       $this->dns = array();
737       $ids = $this->list_get_selected_items();
739       if(count($ids) && class_available("DaemonEvent")){
740         $mac= array();
742         $ldap = $this->config->get_ldap_link();
743         foreach($ids as $id){
744           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
745           $attrs= $ldap->fetch();
746           if (isset($attrs['macAddress'][0])){
747             $mac[]= $attrs['macAddress'][0];
748           }
749         }
750         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
751         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
752         $o_queue = new gosaSupportDaemon();
754         /* Skip installation or update trigerred events, 
755          *  if this entry is currently processing.
756          */
757         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
758           foreach($mac as $key => $mac_address){
759             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
761               $entry['STATUS'] = strtoupper($entry['STATUS']);
762               if($entry['STATUS'] == "PROCESSING" && 
763                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
764                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
765                 unset($mac[$key]);
767                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
768                 break;
769               }
770             }
771           }
772         }        
774         /* Prepare event to be added 
775          */
776         if(count($mac) && isset($events['BY_CLASS'][$type])){
777           $event = $events['BY_CLASS'][$type];
778           $this->systab = new $event['CLASS_NAME']($this->config);
779           $this->systab->add_targets($mac);
780           if(preg_match("/trigger_event/",$s_action)){
781             $this->systab->set_type(TRIGGERED_EVENT);
782           }else{
783             $this->systab->set_type(SCHEDULED_EVENT);
784           }
785         }
786       }
787     }
789     /* Insert scheduled events into queue */
790     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
791       $this->systab->save_object();
793       /* Save event 
794        */
795       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
796         $o_queue = new gosaSupportDaemon();
797         $o_queue->append($this->systab);
798         if($o_queue->is_error()){
799           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
800         }else{
801           $this->systab = FALSE;
802         }
803       }
804       if(isset($_POST['abort_event_dialog'])){
805         $this->systab = FALSE;
806       }
807     }
810     /********************
811       Delete MULTIPLE entries requested, display confirm dialog
812      ********************/
814     if ($s_action=="del_multiple" || $s_action == "del"){
815       $this->dns = array();
817       if($s_action == "del_multiple"){
818         $ids = $this->list_get_selected_items();
819       }else{
820         $ids = array($s_entry);
821       }
823       $ui = get_userinfo();
824       $tabs = array(
825           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
826           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
827           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
828           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
829           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
830           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
831           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
832           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
833           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
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 = array(
887           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
888           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
889           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
890           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
891           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
892           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
893           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
894           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
895           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
898       /* Remove user by user and check acls before removeing them */
899       foreach($this->dns as $key => $dn){
901         /* Get 'dn' from posted termlinst */
902         $attrs    = $this->terminals[$key];
903         $type= $this->get_system_type($attrs);
905         /* get object type */
906         $tabtype  = "termtabs";
907         $tabobj   = "TERMTABS";
908         $tabacl   = "";
909         if(isset($tabs[$type])){
910           $tabtype = $tabs[$type]['TABCLASS'];
911           $tabobj  = $tabs[$type]['CLASS'];
912           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
914           /* Load permissions for selected 'dn' and check if
915              we're allowed to remove this 'dn' */
916           if(preg_match("/d/",$tabacl)){ 
918             /* Delete request is permitted, perform LDAP action */
919             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
920               $this->systab= new termgeneric($this->config, $dn);
921               $this->systab->set_acl_base($dn);
922               $this->systab->remove_from_parent();
923             }elseif($tabtype=="phonetabs"){
924               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
925               $this->systab->set_acl_base($dn);
926               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
927             }else{
928               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
929               $this->systab->set_acl_base($dn);
930               $this->systab->delete();
931             }
932             unset ($this->systab);
933             $this->systab= NULL;
935           } else {
936             /* Normally this shouldn't be reached, send some extra
937                logs to notify the administrator */
938             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
939             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
940           }
941         }
943         /* Remove lock file after successfull deletion */
944         $this->remove_lock();
945         $this->dns = array();
946       }
947     }
949     /********************
950       Delete MULTIPLE entries Canceled
951      ********************/
953     /* Remove lock */
954    if(isset($_POST['delete_multiple_system_cancel'])){
956      /* Remove lock file after successfull deletion */
957      $this->remove_lock();
958      $this->dns = array();
959    }
962     /********************
963       Edit system type finished, check if everything went ok
964      ********************/
965     /* Finish user edit is triggered by the tabulator dialog, so
966        the user wants to save edited data. Check and save at this
967        point. */
969     /* Dirty workaround - MSG_DIALOG - OK
970       If a message dialog is shown and we press 'OK'
971        then try to save again.
972      */
973     foreach($_POST as $name => $value){
974       if(preg_match("/^MSG_OK/",$name)){
975         $_POST[$this->last_action] = TRUE;
976       }
977     }
979     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
981       /* If the save routine gets interrupted by a confirm dialog, 
982           store last action so we can trigger it again after 'Ok' was pressed.
983          (This is the case if a system gets modified while it is installing - GOsa si)
984        */
985       $this->last_action = ""; 
986       if(isset($_POST['edit_finish'])){
987         $this->last_action = "edit_finish"; 
988       }elseif(isset($_POST['edit_apply'])){
989         $this->last_action = "edit_apply";
990       }
992       /* Check tabs, will feed message array */
993       $message = $this->systab->check();
995       /* Save, or display error message? */
996       if (count($message) == 0){
999         $this->systab->save();
1001         /* Terminal has been saved successfully, remove lock from LDAP. */
1002         if (!isset($_POST['edit_apply'])){
1003           if ($this->dn != "new"){
1004             $this->remove_lock();
1005           }
1007           unset ($this->systab);
1008           $this->systab= NULL;
1009           session::un_set('objectinfo');
1010         }else{
1011       
1012           /* Reinitialize tab */
1013           if($this->systab instanceof tabs){
1014             $this->systab->re_init();
1015           }
1016         }
1017       } else {
1018         /* Ok. There seem to be errors regarding to the tab data,
1019            show message and continue as usual. */
1020         msg_dialog::displayChecks($message);
1021       }
1022     }
1025     /********************
1026       Edit system was canceled 
1027      ********************/
1028     /* Cancel dialogs */
1029     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1030       if (isset($this->systab)){
1031         $this->remove_lock();
1032         unset ($this->systab);
1033       }
1034       $this->systab= NULL;
1035       session::un_set('objectinfo');
1036     }
1038     /********************
1039       Display edit dialog, or some other
1040      ********************/
1042     /* Show tab dialog if object is present */
1043     if (isset($this->systab->config)){
1044       $display= $this->systab->execute();
1046       /* Don't show buttons if tab dialog requests this */
1048       $dialog     = FALSE;
1049       $hide_apply = $this->dn == "new";
1050       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1051       if(is_object($this->systab) && !isset($this->systab->by_object)){
1052         $dialog = TRUE;
1053         $hide_apply = TRUE;
1054       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1055         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1056         if($dia === TRUE || is_object($dia)){
1057           $dialog = TRUE;
1058         }  
1059       }
1060       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1061         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1062         $dialog = TRUE;
1063       }
1065       if (!$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('terminalou'),
1114         "workstation"     => get_ou('workstationou'),
1115         "incoming"        => get_ou('incomingou'),
1116         "server"          => get_ou('serverou'),
1117         "printer"         => get_ou('printerou'),
1118         "phone"           => get_ou('phoneou'),
1119         "winworkstation"  => get_winstations_ou(),
1120         "component"       => get_ou('componentou')
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        = "";
1178     /* Set base for all searches */
1179     $base=  $this->DivListSystem->selectedBase;
1181     /* Prepare samba class name */
1182     $samba  ="";
1183     if ($this->DivListSystem->ShowWinWorkstations){
1184       if ($this->config->current['SAMBAVERSION'] == "3"){
1185         $samba= "sambaSamAccount";
1186       } else {
1187         $samba= "sambaAccount";
1188       }
1189     }
1191     /* This array represents the combination between checkboxes and search filters */
1192     $objs = array( 
1193         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1194         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1195         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1196         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1197         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1198         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1199         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1201     /* Include the 'Display Systems of user' attribute */ 
1202     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1203       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1204     }
1206     /* Attributes to fetch */
1207     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1208     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1210     /* Add FAIstate to attributes if FAI is activated */
1211     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1212     if(!empty($tmp)){
1213       $sys_attrs[] = "FAIstate";
1214     }    
1216     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1217     foreach($objs as $checkBox => $oc){
1219       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1220         if($this->DivListSystem->SubSearch){
1221           if($oc['CLASS'] != ""){
1222             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1223             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1224             $res = array_merge($res,$new_res);
1225           }
1226         }else{
1227           /* User filter? */
1228           if($oc['CLASS'] != ""){
1229             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1230             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1231           }
1232         }
1233       } 
1234     }
1236     /* Search for incoming objects */ 
1237     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1238     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1240     /* Get all gotoTerminal's */
1241     foreach ($res as $value){
1243       $tmp= $value['dn'];
1244       $add= "";
1246       /* Extract base */
1247       foreach($objs as $obj){
1248         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1249           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1250         }
1251       }
1253       /* Create a string containing the last part of the department. */
1254       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1255       if(empty($dn_name)){
1256         $dn_name = "/";
1257       }
1259       /* check if current object is a new one */
1260       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1261         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1262           $add= "- "._("New terminal");
1263         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1264           $add= "- "._("New workstation");
1265         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1266           $add= "- "._("Unknown device");
1267         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1268           $add= "- "._("New Device");
1269         }
1270       } 
1272       /* Detect type of object and create an entry for $this->terminals */
1273       $terminal = array();
1274       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1276         /* check acl */
1277         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1278         if($add != "" || preg_match("/r/",$acl)) {
1279           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1280             $terminal             = $value;
1281             $terminal['type']     = "T";
1282             $terminal['is_new']   = $add;
1283           } else {
1284             $terminal             = $value;
1285             $terminal['type']     = "D";
1286             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1287             $terminal['location'] = array_search($tmp, $this->config->departments); 
1288           }
1289         }
1290       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1292         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1293         if($add != "" || preg_match("/r/",$acl)) {
1294           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1295             $terminal             = $value;
1296             $terminal['type']     = "L";
1297             $terminal['is_new']   = $add;
1298           } else {
1299             $terminal             = $value;
1300             $terminal['type']     = "D";
1301             $terminal['location'] = array_search($tmp, $this->config->departments);
1302             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1303           }
1304 #          if (isset($value["FAIstate"][0])){
1305 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1306 #          }
1307         }
1308       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1309        
1310    
1311         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1312         if($add != "" || preg_match("/r/",$acl)) {
1314           $terminal             = $value;
1315           $terminal['type']     = "P";
1316         }
1317       } elseif (in_array_ics('goServer', $value["objectClass"])){
1319         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1320         if($add != "" || preg_match("/r/",$acl)) {
1322           $terminal             = $value;
1323           $terminal['type']     = "S";
1324 #          if (isset($value["FAIstate"][0])){
1325 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1326 #          }
1327         }
1328       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1330         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1331         if($add != "" || preg_match("/r/",$acl)) {
1333           $terminal             = $value;
1334           $terminal['type']     = "F";
1335         }
1336       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1338         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1339                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1340                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1341         if($add != "" || preg_match("/r/",$acl)) {
1343           $terminal = $value;
1344           $terminal['type']   = "Q";
1345           $terminal['is_new'] = $add;
1346         }
1347       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1349         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1350         if($add != "" || preg_match("/r/",$acl)) {
1352           $terminal             = $value;
1353           $terminal['type']     = "C";
1354         }
1355       } else{
1357         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1358         if (isset($value['sambaDomainName'])){
1359           $domain= " [".$value['sambaDomainName'][0]."]";
1360         } else {
1361           $domain= "";
1362         }
1363         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1364         if($add != "" || preg_match("/r/",$acl)) {
1365           $terminal=$value;
1366           $terminal['type']     ="W";
1367           $terminal['domain']   = $name.$domain;
1368         }
1369       }
1371       if(count($terminal)){
1372         $this->terminals[]=$terminal;
1373       }
1374     }
1376     $tmp  =array();
1377     $tmp2 =array();
1378     foreach($this->terminals as $tkey => $val ){
1379       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1380       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1381     }
1382     natcasesort($tmp2);
1383     $this->terminals=array();
1384     foreach($tmp2 as $val){
1385       $this->terminals[]=$tmp[$val];
1386     }
1387     reset ($this->terminals);
1388   }
1390   function remove_lock()
1391   {
1392     if (isset($this->systab->dn)){
1393       del_lock ($this->systab->dn);
1394     }
1395     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1396       del_lock($this->dn);
1397     }
1398     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1399       del_lock($this->dns);
1400     }
1401   }
1404   function copyPasteHandling_from_queue($s_action,$s_entry)
1405   {
1406     /* Check if Copy & Paste is disabled */
1407     if(!is_object($this->CopyPasteHandler)){
1408       return("");
1409     }
1411     $ui = get_userinfo();
1413     $tabs = array(
1414         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1415           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1416         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1417           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1418         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1419           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1420         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1421           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1422         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1423           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1424         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1425           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1427     /* Add a single entry to queue */
1428     if($s_action == "cut" || $s_action == "copy"){
1430       /* Cleanup object queue */
1431       $this->CopyPasteHandler->cleanup_queue();
1432       $dn     = $this->terminals[$s_entry]['dn'];
1433       $oc     = $this->terminals[$s_entry]['objectClass'];
1434       $type   = $this->get_system_type($this->terminals[$s_entry]);
1436       $tab_o  = $tabs[$type]['CLASS'];
1437       $tab_c  = $tabs[$type]['TABCLASS'];
1438       $acl_c  = $tabs[$type]['TABNAME'];
1439       $acl    = $tabs[$type]['ACL'];
1441       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1442         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1443       }
1444       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1445         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1446       }
1447     }
1449     /* Add entries to queue */
1450     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1452       /* Cleanup object queue */
1453       $this->CopyPasteHandler->cleanup_queue();
1455       /* Add new entries to CP queue */
1456       foreach($this->list_get_selected_items() as $id){
1457         $dn = $this->terminals[$id]['dn'];
1458         $oc = $this->terminals[$id]['objectClass']; 
1459         $type = $this->get_system_type($this->terminals[$id]);
1461         if(isset($tabs[$type])){
1462           $tab_o  = $tabs[$type]['CLASS'];
1463           $tab_c  = $tabs[$type]['TABCLASS'];
1464           $acl_c  = $tabs[$type]['TABNAME'];
1465           $acl    = $tabs[$type]['ACL'];
1467           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1468             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1469           }
1470           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1471             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1472           }
1473         }
1474       }
1475     }
1477     /* Start pasting entries */
1478     if($s_action == "editPaste"){
1479       $this->start_pasting_copied_objects = TRUE;
1480     }
1481   
1482     /* Return C&P dialog */
1483     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1485       /* Get dialog */
1486       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1487       $data = $this->CopyPasteHandler->execute();
1489       /* Return dialog data */
1490       if(!empty($data)){
1491         return($data);
1492       }
1493     }
1495     /* Automatically disable status for pasting */
1496     if(!$this->CopyPasteHandler->entries_queued()){
1497       $this->start_pasting_copied_objects = FALSE;
1498     }
1499     return("");
1500   }
1503   function get_system_type($attrs)
1504   {
1505     $classes = $attrs['objectClass'];
1507     $type= "";
1508     if (in_array_ics('ieee802Device', $classes)){
1509       $type= "component";
1510     }elseif (in_array_ics('gotoTerminal', $classes)){
1511       $type= "terminal";
1512     }elseif (in_array_ics('gotoWorkstation', $classes)){
1513       $type= "workstation";
1514     }elseif (in_array_ics('gotoPrinter', $classes)){
1515       $type= "printer";
1516     }elseif (in_array_ics('goFonHardware', $classes)){
1517       $type= "phone";
1518     }elseif (in_array_ics('goServer', $classes)){
1519       $type= "server";
1520     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1521       $type= "ArpNewDevice";
1522     }elseif (in_array_ics('GOhard', $classes)){
1523       $type= "NewDevice";
1524     }elseif (in_array_ics('sambaAccount', $classes) ||
1525         in_array_ics('sambaSamAccount', $classes)){
1526       $type= "winstation";
1527     }
1528     return ($type);
1529   }
1532   function convert_list($input)
1533   {
1534     $temp= "";
1536     $conv= array(
1537         "D" => array("select_default.png",_("Template")),
1538         "F" => array("select_phone.png",_("Phone")),
1539         "C" => array("select_component.png",_("Network device")),
1540         "P" => array("select_printer.png",_("Printer")),
1542         "W" => array("select_winstation.png",_("Win workstation")),
1544         "L" => array("select_workstation.png",_("Workstation")),
1545         "S" => array("select_server.png",_("Server")),
1546         "T" => array("select_terminal.png",_("Terminal")),
1548         "LX" => array("workstation_locked.png",_("Locked workstation")),
1549         "SX" => array("server_locked.png",_("Locked server")),
1550         "TX" => array("terminal_locked.png",_("Locked terminal")),
1552         "LE" => array("workstation_error.png",_("Workstation error")),
1553         "SE" => array("server_error.png",_("Server error")),
1554         "TE" => array("terminal_error.png",_("Terminal error")),
1556         "LB" => array("workstation_busy.png",_("Workstation busy")),
1557         "SB" => array("server_busy.png",_("Server busy")),
1559         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1560         "NT"=> array("select_new_terminal.png",_("New terminal")),
1561         "NL"=> array("select_new_workstation.png",_("New workstation")));
1563     /* Use locked icons 
1564      */
1565     if( in_array($input['type'],array("S","T","L")) && 
1566         isset($input['gotoMode'][0]) && 
1567         preg_match("/locked/",$input['gotoMode'][0])){
1568       $input['type'].="X";
1569     } elseif(in_array($input['type'],array("S","L")) &&
1570         isset($input['FAIstate'][0])){
1572     /* Add FAI state icons 
1573      */
1574       $type= "";
1575       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1576         case 'error':
1577           $type= 'E';
1578           break;
1579         case 'installing':
1580         case 'install':
1581         case 'sysinfo':
1582         case 'softupdate':
1583         case 'scheduledupdate':
1584           $type= 'B';
1585           break;
1586       }
1588       $input['type'].= $type;
1589     }   
1591     /* Use new images if object is from incoming 
1592      */
1593     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1594       $input['type']="N".$input['type'];
1595     }
1597     /* Check which flags this objects uses 
1598      */
1599     foreach ($conv  as $key => $value){
1600       $found = TRUE;
1601       if(strlen($key) != strlen($input['type'])) {
1602         $found = FALSE;
1603       }
1604       for($i = 0 ; $i < strlen($key) ; $i++){
1605         if(!preg_match("/".$key[$i]."/",$input['type'])){
1606           $found = FALSE;
1607         }
1608       }
1610       if($found){
1611         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1612         $tmp['class']=$key;
1613         return $tmp;
1614       }
1615     }
1616   }
1619   function list_get_selected_items()
1620   {
1621     $ids = array();
1622     foreach($_POST as $name => $value){
1623       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1624         $id   = preg_replace("/^item_selected_/","",$name);
1625         $ids[$id] = $id;
1626       }
1627     }
1628     return($ids);
1629   }
1632   /* !! Incoming dummy acls, required to defined acls for incoming objects
1633    */
1634   static function plInfo()
1635   {
1636     return (array(
1637           "plShortName"   => _("Incoming objects"),
1638           "plDescription" => _("Incoming objects"),
1639           "plSelfModify"  => FALSE,
1640           "plDepends"     => array(),
1641           "plPriority"    => 99,
1642           "plSection"     => array("administration"),
1643           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1644                                                           "objectClass"  => "")),
1645           "plProvidedAcls"=> array()
1646             
1647           ));
1648   }
1651 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1652 ?>