Code

Fixed network configuration class
[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"){
815       $this->dns = array();
816       $ids = $this->list_get_selected_items();
818       $ui = get_userinfo();
819       $tabs = array(
820           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
821           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
822           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
823           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
824           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
825           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
826           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
827           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
828           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
831       if(count($ids)){
833         $disallowed = array();
834         foreach($ids as $id){
836           /* Get 'dn' from posted termlinst */
837           $attrs  = $this->terminals[$id];
838           $type   = $this->get_system_type($attrs);
839           $dn     = $attrs['dn'];
840           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
841           if(preg_match("/d/",$acl)){
842             $this->dns[$id] = $dn;
843           }else{
844             $disallowed[] = $dn;
845           }
846         }
848         if(count($disallowed)){
849           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
850         }
852         if(count($this->dns)){
854           if ($user= get_multiple_locks($this->dns)){
855             return(gen_locked_message($user,$this->dns));
856           }
858           $dns_names = array();
859           foreach($this->dns as $dn){
860             add_lock ($dn, $this->ui->dn);
861             $dns_names[] = @LDAP::fix($dn);
862           }
864           /* Lock the current entry, so nobody will edit it during deletion */
865           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
866           $smarty->assign("multiple", true);
867           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
868         }
869       }
870     }
873     /********************
874       Delete MULTIPLE entries confirmed
875      ********************/
877     /* Confirmation for deletion has been passed. Users should be deleted. */
878     if (isset($_POST['delete_multiple_system_confirm'])){
880       $ui = get_userinfo();
881       $tabs = array(
882           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
883           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
884           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
885           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
886           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
887           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
888           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
889           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
890           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
893       /* Remove user by user and check acls before removeing them */
894       foreach($this->dns as $key => $dn){
896         /* Get 'dn' from posted termlinst */
897         $attrs    = $this->terminals[$key];
898         $type= $this->get_system_type($attrs);
900         /* get object type */
901         $tabtype  = "termtabs";
902         $tabobj   = "TERMTABS";
903         $tabacl   = "";
904         if(isset($tabs[$type])){
905           $tabtype = $tabs[$type]['TABCLASS'];
906           $tabobj  = $tabs[$type]['CLASS'];
907           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
909           /* Load permissions for selected 'dn' and check if
910              we're allowed to remove this 'dn' */
911           if(preg_match("/d/",$tabacl)){ 
913             /* Delete request is permitted, perform LDAP action */
914             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
915               $this->systab= new termgeneric($this->config, $dn);
916               $this->systab->set_acl_base($dn);
917               $this->systab->remove_from_parent();
918             }elseif($tabtype=="phonetabs"){
919               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
920               $this->systab->set_acl_base($dn);
921               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
922             }else{
923               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
924               $this->systab->set_acl_base($dn);
925               $this->systab->delete();
926             }
927             unset ($this->systab);
928             $this->systab= NULL;
930           } else {
931             /* Normally this shouldn't be reached, send some extra
932                logs to notify the administrator */
933             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
934             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
935           }
936         }
938         /* Remove lock file after successfull deletion */
939         $this->remove_lock();
940         $this->dns = array();
941       }
942     }
944     /********************
945       Delete MULTIPLE entries Canceled
946      ********************/
948     /* Remove lock */
949    if(isset($_POST['delete_multiple_system_cancel'])){
951      /* Remove lock file after successfull deletion */
952      $this->remove_lock();
953      $this->dns = array();
954    }
957     /********************
958       Delete system, confirm dialog
959      ********************/
961     /* Remove terminal was requested */
962     if ($s_action=="del"){
964       /* Get 'dn' from posted termlinst */
965       $this->dn = $this->terminals[$s_entry]['dn'];
966       $attrs    = $this->terminals[$s_entry];
968   
970       $type= $this->get_system_type($attrs);
971       $ui = get_userinfo();
972       $tabs = array(
973           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
974           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
975           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
976           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
977           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
978           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
979           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
980           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
981           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
983       /* get object type */
984       $tabtype  = "termtabs";
985       $tabobj   = "TERMTABS";
986       $tabacl   = "";
987       if(isset($tabs[$type])){
988         $tabtype = $tabs[$type]['TABCLASS'];
989         $tabobj  = $tabs[$type]['CLASS'];
990         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
991       }
993       /* Load permissions for selected 'dn' and check if
994          we're allowed to remove this 'dn' */
995       if(preg_match("/d/",$tabacl)){ 
997         /* Check locking, save current plugin in 'back_plugin', so
998            the dialog knows where to return. */
999         if (($user= get_lock($this->dn)) != ""){
1000           return(gen_locked_message ($user, $this->dn));
1001         }
1003         /* Lock the current entry, so nobody will edit it during deletion */
1004         add_lock ($this->dn, $this->ui->dn);
1005         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
1006         $smarty->assign("multiple", false);
1007         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
1008       } else {
1010         /* Obviously the user isn't allowed to delete. Show message and
1011            clean session. */
1012         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1013       }
1014     }
1017     /********************
1018       Delete system, confirmed
1019      ********************/
1020     /* Confirmation for deletion has been passed. Terminal should be deleted. */
1021     if (isset($_POST['delete_terminal_confirm'])){
1023       /* Find out more about the object type */
1024       $ldap= $this->config->get_ldap_link();
1025       $ldap->cat($this->dn, array('objectClass'));
1026       $attrs= $ldap->fetch();
1027       $type= $this->get_system_type($attrs);
1029       $ui = get_userinfo();
1031       $tabs = array(
1032           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
1033           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
1034           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
1035           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
1036           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
1037           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
1038           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
1039           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
1040           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
1042       /* get object type */
1043       $tabtype  = "termtabs";
1044       $tabobj   = "TERMTABS";
1045       $tabacl   = "";
1046       if(isset($tabs[$type])){
1047         $tabtype = $tabs[$type]['TABCLASS'];
1048         $tabobj  = $tabs[$type]['CLASS'];
1049         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
1050       }
1052       /* Check if we are allowed to remove this object */
1053       if(preg_match("/d/",$tabacl)){
1055         /* Delete request is permitted, perform LDAP action */
1056         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
1057           $this->systab= new termgeneric($this->config, $this->dn);
1058           $this->systab->set_acl_base($this->dn);
1059           $this->systab->remove_from_parent();
1060         }elseif($tabtype=="phonetabs"){
1061           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
1062           $this->systab->set_acl_base($this->dn);
1063           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
1064         }else{  
1065           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
1066           $this->systab->set_acl_base($this->dn);
1067           $this->systab->delete();
1068         }
1069         unset ($this->systab);
1070         $this->systab= NULL;
1072         /* Terminal list has changed, reload it. */
1073       } else {
1075         /* Normally this shouldn't be reached, send some extra
1076            logs to notify the administrator */
1077         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1078         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1079       }
1081       /* Remove lock file after successfull deletion */
1082       $this->remove_lock();
1083     }
1086     /********************
1087       Edit system type finished, check if everything went ok
1088      ********************/
1089     /* Finish user edit is triggered by the tabulator dialog, so
1090        the user wants to save edited data. Check and save at this
1091        point. */
1093     /* Dirty workaround - MSG_DIALOG - OK
1094       If a message dialog is shown and we press 'OK'
1095        then try to save again.
1096      */
1097     foreach($_POST as $name => $value){
1098       if(preg_match("/^MSG_OK/",$name)){
1099         $_POST[$this->last_action] = TRUE;
1100       }
1101     }
1103     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1105       /* If the save routine gets interrupted by a confirm dialog, 
1106           store last action so we can trigger it again after 'Ok' was pressed.
1107          (This is the case if a system gets modified while it is installing - GOsa si)
1108        */
1109       $this->last_action = ""; 
1110       if(isset($_POST['edit_finish'])){
1111         $this->last_action = "edit_finish"; 
1112       }elseif(isset($_POST['edit_apply'])){
1113         $this->last_action = "edit_apply";
1114       }
1116       /* Check tabs, will feed message array */
1117       $message = $this->systab->check();
1119       /* Save, or display error message? */
1120       if (count($message) == 0){
1123         $this->systab->save();
1125         /* Terminal has been saved successfully, remove lock from LDAP. */
1126         if (!isset($_POST['edit_apply'])){
1127           if ($this->dn != "new"){
1128             $this->remove_lock();
1129           }
1131           unset ($this->systab);
1132           $this->systab= NULL;
1133           session::un_set('objectinfo');
1134         }else{
1135       
1136           /* Reinitialize tab */
1137           if($this->systab instanceof tabs){
1138             $this->systab->re_init();
1139           }
1140         }
1141       } else {
1142         /* Ok. There seem to be errors regarding to the tab data,
1143            show message and continue as usual. */
1144         msg_dialog::displayChecks($message);
1145       }
1146     }
1149     /********************
1150       Edit system was canceled 
1151      ********************/
1152     /* Cancel dialogs */
1153     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1154       if (isset($this->systab)){
1155         $this->remove_lock();
1156         unset ($this->systab);
1157       }
1158       $this->systab= NULL;
1159       session::un_set('objectinfo');
1160     }
1162     /********************
1163       Display edit dialog, or some other
1164      ********************/
1166     /* Show tab dialog if object is present */
1167     if (isset($this->systab->config)){
1168       $display= $this->systab->execute();
1170       /* Don't show buttons if tab dialog requests this */
1172       $dialog     = FALSE;
1173       $hide_apply = $this->dn == "new";
1174       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1175       if(is_object($this->systab) && !isset($this->systab->by_object)){
1176         $dialog = TRUE;
1177         $hide_apply = TRUE;
1178       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1179         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1180         if($dia === TRUE || is_object($dia)){
1181           $dialog = TRUE;
1182         }  
1183       }
1184       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1185         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1186         $dialog = TRUE;
1187       }
1189       if (!$dialog){
1190         $display.= "<p style=\"text-align:right\">\n";
1191         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1192         $display.= "&nbsp;\n";
1193         if (!$hide_apply){
1194           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1195           $display.= "&nbsp;\n";
1196         }
1197         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1198         $display.= "</p>";
1199       }
1200       return ($display);
1201     }
1203     /* Check if there is a snapshot dialog open */
1204     $base = $this->DivListSystem->selectedBase;
1205     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1206       return($str);
1207     }
1209     /* Display dialog with system list */
1210     $this->DivListSystem->parent = $this;
1211     $this->DivListSystem->execute();
1213     /* Add departments if subsearch is disabled */
1214     if(!$this->DivListSystem->SubSearch){
1216       /* Add FAIstate to attributes if FAI is activated */
1217       if($this->fai_activated){
1218         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1219       }else{
1220         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1221       }
1222     }
1223     $this->reload();
1224     $this->DivListSystem->setEntries($this->terminals);
1225     return($this->DivListSystem->Draw());
1226   }
1229   /* Return departments, that will be included within snapshot detection */
1230   function get_used_snapshot_bases()
1231   {
1232     $tmp = array();
1234     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1236     $tabs = array(
1237         "terminal"        => get_ou('terminalou'),
1238         "workstation"     => get_ou('workstationou'),
1239         "incoming"        => get_ou('incomingou'),
1240         "server"          => get_ou('serverou'),
1241         "printer"         => get_ou('printerou'),
1242         "phone"           => get_ou('phoneou'),
1243         "winworkstation"  => get_winstations_ou(),
1244         "component"       => get_ou('componentou')
1245         ); 
1247     foreach($tabs as $acl_cat => $dn){
1249       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1250       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1251         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1252       }
1253     }
1254     return($tmp); 
1255   }
1258   function remove_from_parent()
1259   {
1260     /* Optionally execute a command after we're done */
1261     $this->postremove();
1262   }
1265   /* Save data to object */
1266   function save_object()
1267   {
1268     $this->DivListSystem->save_object();
1269     if(is_object($this->CopyPasteHandler)){
1270       $this->CopyPasteHandler->save_object();
1271     }
1272   }
1275   /* Check values */
1276   function check()
1277   {
1278   }
1281   /* Save to LDAP */
1282   function save()
1283   {
1284   }
1286   function adapt_from_template($dn, $skip= array())
1287   {
1288   }
1290   function password_change_needed()
1291   {
1292   }
1294   function reload()
1295   {
1296     /* some var init */
1297     $ui = get_userinfo();
1298     $res              = array();
1299     $this->terminals  = array();
1300     $userregex        = "";
1302     /* Set base for all searches */
1303     $base=  $this->DivListSystem->selectedBase;
1305     /* Prepare samba class name */
1306     $samba  ="";
1307     if ($this->DivListSystem->ShowWinWorkstations){
1308       if ($this->config->current['SAMBAVERSION'] == "3"){
1309         $samba= "sambaSamAccount";
1310       } else {
1311         $samba= "sambaAccount";
1312       }
1313     }
1315     /* This array represents the combination between checkboxes and search filters */
1316     $objs = array( 
1317         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1318         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1319         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1320         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1321         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1322         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1323         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1325     /* Include the 'Display Systems of user' attribute */ 
1326     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1327       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1328     }
1330     /* Attributes to fetch */
1331     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1332     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1334     /* Add FAIstate to attributes if FAI is activated */
1335     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1336     if(!empty($tmp)){
1337       $sys_attrs[] = "FAIstate";
1338     }    
1340     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1341     foreach($objs as $checkBox => $oc){
1343       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1344         if($this->DivListSystem->SubSearch){
1345           if($oc['CLASS'] != ""){
1346             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1347             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1348             $res = array_merge($res,$new_res);
1349           }
1350         }else{
1351           /* User filter? */
1352           if($oc['CLASS'] != ""){
1353             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1354             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1355           }
1356         }
1357       } 
1358     }
1360     /* Search for incoming objects */ 
1361     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1362     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1364     /* Get all gotoTerminal's */
1365     foreach ($res as $value){
1367       $tmp= $value['dn'];
1368       $add= "";
1370       /* Extract base */
1371       foreach($objs as $obj){
1372         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1373           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1374         }
1375       }
1377       /* Create a string containing the last part of the department. */
1378       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1379       if(empty($dn_name)){
1380         $dn_name = "/";
1381       }
1383       /* check if current object is a new one */
1384       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1385         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1386           $add= "- "._("New terminal");
1387         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1388           $add= "- "._("New workstation");
1389         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1390           $add= "- "._("Unknown device");
1391         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1392           $add= "- "._("New Device");
1393         }
1394       } 
1396       /* Detect type of object and create an entry for $this->terminals */
1397       $terminal = array();
1398       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1400         /* check acl */
1401         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1402         if($add != "" || preg_match("/r/",$acl)) {
1403           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1404             $terminal             = $value;
1405             $terminal['type']     = "T";
1406             $terminal['is_new']   = $add;
1407           } else {
1408             $terminal             = $value;
1409             $terminal['type']     = "D";
1410             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1411             $terminal['location'] = array_search($tmp, $this->config->departments); 
1412           }
1413         }
1414       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1416         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1417         if($add != "" || preg_match("/r/",$acl)) {
1418           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1419             $terminal             = $value;
1420             $terminal['type']     = "L";
1421             $terminal['is_new']   = $add;
1422           } else {
1423             $terminal             = $value;
1424             $terminal['type']     = "D";
1425             $terminal['location'] = array_search($tmp, $this->config->departments);
1426             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1427           }
1428 #          if (isset($value["FAIstate"][0])){
1429 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1430 #          }
1431         }
1432       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1433        
1434    
1435         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1436         if($add != "" || preg_match("/r/",$acl)) {
1438           $terminal             = $value;
1439           $terminal['type']     = "P";
1440         }
1441       } elseif (in_array_ics('goServer', $value["objectClass"])){
1443         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1444         if($add != "" || preg_match("/r/",$acl)) {
1446           $terminal             = $value;
1447           $terminal['type']     = "S";
1448 #          if (isset($value["FAIstate"][0])){
1449 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1450 #          }
1451         }
1452       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1454         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1455         if($add != "" || preg_match("/r/",$acl)) {
1457           $terminal             = $value;
1458           $terminal['type']     = "F";
1459         }
1460       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1462         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1463                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1464                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1465         if($add != "" || preg_match("/r/",$acl)) {
1467           $terminal = $value;
1468           $terminal['type']   = "Q";
1469           $terminal['is_new'] = $add;
1470         }
1471       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1473         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1474         if($add != "" || preg_match("/r/",$acl)) {
1476           $terminal             = $value;
1477           $terminal['type']     = "C";
1478         }
1479       } else{
1481         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1482         if (isset($value['sambaDomainName'])){
1483           $domain= " [".$value['sambaDomainName'][0]."]";
1484         } else {
1485           $domain= "";
1486         }
1487         $terminal=$value;
1488         $terminal['type']     ="W";
1489         $terminal['domain']   = $name.$domain;
1490       }
1492       if(count($terminal)){
1493         $this->terminals[]=$terminal;
1494       }
1495     }
1497     $tmp  =array();
1498     $tmp2 =array();
1499     foreach($this->terminals as $tkey => $val ){
1500       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1501       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1502     }
1503     natcasesort($tmp2);
1504     $this->terminals=array();
1505     foreach($tmp2 as $val){
1506       $this->terminals[]=$tmp[$val];
1507     }
1508     reset ($this->terminals);
1509   }
1511   function remove_lock()
1512   {
1513     if (isset($this->systab->dn)){
1514       del_lock ($this->systab->dn);
1515     }
1516     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1517       del_lock($this->dn);
1518     }
1519     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1520       del_lock($this->dns);
1521     }
1522   }
1525   function copyPasteHandling_from_queue($s_action,$s_entry)
1526   {
1527     /* Check if Copy & Paste is disabled */
1528     if(!is_object($this->CopyPasteHandler)){
1529       return("");
1530     }
1532     $ui = get_userinfo();
1534     $tabs = array(
1535         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1536           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1537         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1538           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1539         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1540           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1541         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1542           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1543         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1544           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1545         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1546           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1548     /* Add a single entry to queue */
1549     if($s_action == "cut" || $s_action == "copy"){
1551       /* Cleanup object queue */
1552       $this->CopyPasteHandler->cleanup_queue();
1553       $dn     = $this->terminals[$s_entry]['dn'];
1554       $oc     = $this->terminals[$s_entry]['objectClass'];
1555       $type   = $this->get_system_type($this->terminals[$s_entry]);
1557       $tab_o  = $tabs[$type]['CLASS'];
1558       $tab_c  = $tabs[$type]['TABCLASS'];
1559       $acl_c  = $tabs[$type]['TABNAME'];
1560       $acl    = $tabs[$type]['ACL'];
1562       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1563         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1564       }
1565       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1566         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1567       }
1568     }
1570     /* Add entries to queue */
1571     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1573       /* Cleanup object queue */
1574       $this->CopyPasteHandler->cleanup_queue();
1576       /* Add new entries to CP queue */
1577       foreach($this->list_get_selected_items() as $id){
1578         $dn = $this->terminals[$id]['dn'];
1579         $oc = $this->terminals[$id]['objectClass']; 
1580         $type = $this->get_system_type($this->terminals[$id]);
1582         if(isset($tabs[$type])){
1583           $tab_o  = $tabs[$type]['CLASS'];
1584           $tab_c  = $tabs[$type]['TABCLASS'];
1585           $acl_c  = $tabs[$type]['TABNAME'];
1586           $acl    = $tabs[$type]['ACL'];
1588           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1589             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1590           }
1591           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1592             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1593           }
1594         }
1595       }
1596     }
1598     /* Start pasting entries */
1599     if($s_action == "editPaste"){
1600       $this->start_pasting_copied_objects = TRUE;
1601     }
1602   
1603     /* Return C&P dialog */
1604     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1606       /* Get dialog */
1607       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1608       $data = $this->CopyPasteHandler->execute();
1610       /* Return dialog data */
1611       if(!empty($data)){
1612         return($data);
1613       }
1614     }
1616     /* Automatically disable status for pasting */
1617     if(!$this->CopyPasteHandler->entries_queued()){
1618       $this->start_pasting_copied_objects = FALSE;
1619     }
1620     return("");
1621   }
1624   function get_system_type($attrs)
1625   {
1626     $classes = $attrs['objectClass'];
1628     $type= "";
1629     if (in_array_ics('ieee802Device', $classes)){
1630       $type= "component";
1631     }elseif (in_array_ics('gotoTerminal', $classes)){
1632       $type= "terminal";
1633     }elseif (in_array_ics('gotoWorkstation', $classes)){
1634       $type= "workstation";
1635     }elseif (in_array_ics('gotoPrinter', $classes)){
1636       $type= "printer";
1637     }elseif (in_array_ics('goFonHardware', $classes)){
1638       $type= "phone";
1639     }elseif (in_array_ics('goServer', $classes)){
1640       $type= "server";
1641     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1642       $type= "ArpNewDevice";
1643     }elseif (in_array_ics('GOhard', $classes)){
1644       $type= "NewDevice";
1645     }elseif (in_array_ics('sambaAccount', $classes) ||
1646         in_array_ics('sambaSamAccount', $classes)){
1647       $type= "winstation";
1648     }
1649     return ($type);
1650   }
1653   function convert_list($input)
1654   {
1655     $temp= "";
1657     $conv= array(
1658         "D" => array("select_default.png",_("Template")),
1659         "F" => array("select_phone.png",_("Phone")),
1660         "C" => array("select_component.png",_("Network device")),
1661         "P" => array("select_printer.png",_("Printer")),
1663         "W" => array("select_winstation.png",_("Win workstation")),
1665         "L" => array("select_workstation.png",_("Workstation")),
1666         "S" => array("select_server.png",_("Server")),
1667         "T" => array("select_terminal.png",_("Terminal")),
1669         "LX" => array("workstation_locked.png",_("Locked workstation")),
1670         "SX" => array("server_locked.png",_("Locked server")),
1671         "TX" => array("terminal_locked.png",_("Locked terminal")),
1673         "LE" => array("workstation_error.png",_("Workstation error")),
1674         "SE" => array("server_error.png",_("Server error")),
1675         "TE" => array("terminal_error.png",_("Terminal error")),
1677         "LB" => array("workstation_busy.png",_("Workstation busy")),
1678         "SB" => array("server_busy.png",_("Server busy")),
1680         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1681         "NT"=> array("select_new_terminal.png",_("New terminal")),
1682         "NL"=> array("select_new_workstation.png",_("New workstation")));
1684     /* Use locked icons 
1685      */
1686     if( in_array($input['type'],array("S","T","L")) && 
1687         isset($input['gotoMode'][0]) && 
1688         preg_match("/locked/",$input['gotoMode'][0])){
1689       $input['type'].="X";
1690     } elseif(in_array($input['type'],array("S","L")) &&
1691         isset($input['FAIstate'][0])){
1693     /* Add FAI state icons 
1694      */
1695       $type= "";
1696       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1697         case 'error':
1698           $type= 'E';
1699           break;
1700         case 'installing':
1701         case 'install':
1702         case 'sysinfo':
1703         case 'softupdate':
1704         case 'scheduledupdate':
1705           $type= 'B';
1706           break;
1707       }
1709       $input['type'].= $type;
1710     }   
1712     /* Use new images if object is from incoming 
1713      */
1714     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1715       $input['type']="N".$input['type'];
1716     }
1718     /* Check which flags this objects uses 
1719      */
1720     foreach ($conv  as $key => $value){
1721       $found = TRUE;
1722       if(strlen($key) != strlen($input['type'])) {
1723         $found = FALSE;
1724       }
1725       for($i = 0 ; $i < strlen($key) ; $i++){
1726         if(!preg_match("/".$key[$i]."/",$input['type'])){
1727           $found = FALSE;
1728         }
1729       }
1731       if($found){
1732         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1733         $tmp['class']=$key;
1734         return $tmp;
1735       }
1736     }
1737   }
1740   function list_get_selected_items()
1741   {
1742     $ids = array();
1743     foreach($_POST as $name => $value){
1744       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1745         $id   = preg_replace("/^item_selected_/","",$name);
1746         $ids[$id] = $id;
1747       }
1748     }
1749     return($ids);
1750   }
1753   /* !! Incoming dummy acls, required to defined acls for incoming objects
1754    */
1755   static function plInfo()
1756   {
1757     return (array(
1758           "plShortName"   => _("Incoming objects"),
1759           "plDescription" => _("Incoming objects"),
1760           "plSelfModify"  => FALSE,
1761           "plDepends"     => array(),
1762           "plPriority"    => 99,
1763           "plSection"     => array("administration"),
1764           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1765                                                           "objectClass"  => "")),
1766           "plProvidedAcls"=> array()
1767             
1768           ));
1769   }
1772 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1773 ?>