Code

Added missing variable
[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;
47   function systems (&$config, $ui)
48   {
49     /* Save configuration for internal use */
50     $this->config= $config;
51     $this->ui= $ui;
53     /* Add FAIstate to attributes if FAI is activated */
54     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
55     if(!empty($tmp)){
56       $this->fai_activated = TRUE;
57     }
59     /* Creat dialog object */
60     $this->DivListSystem = new divListSystem($this->config,$this);
62     /* Copy & Paste enabled ?*/
63     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
64       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
65     }
67     /* Check whether the arp handling active or not */
68     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
69       $this->arp_handling_active = TRUE;
70     }
71   }
74   function execute()
75   {
76     /* Call parent execute */
77     plugin::execute();
79     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
81     /********************
82       Check for functional posts, edit|delete|add|... system devices 
83      ********************/
84     $s_action     = "";                       // Contains the action to proceed
85     $s_entry      = "";                       // The value for s_action
86     $base_back    = "";                       // The Link for Backbutton
87     $smarty       = get_smarty();
89     /* Test Posts */
90     foreach($_POST as $key => $val){
91       // Post for delete
92       if(preg_match("/system_del.*/",$key)){
93         $s_action = "del";
94         $s_entry  = preg_replace("/system_del_/i","",$key);
95         // Post for edit
96       }elseif(preg_match("/system_edit_.*/",$key)){
97         $s_action="edit";
98         $s_entry  = preg_replace("/system_edit_/i","",$key);
99         // Post for new
100       }elseif(preg_match("/system_new.*/",$key)){
101         $s_action="new";
102       }elseif(preg_match("/system_tplnew.*/i",$key)){
103         $s_action="new_tpl";
104       }elseif(preg_match("/system_setpwd_.*/i",$key)){
105         $s_action="change_pw";
106         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
107       }elseif(preg_match("/gen_cd_.*/i",$key)){
108         $s_action="gen_cd";
109         $s_entry  = preg_replace("/gen_cd_/i","",$key);
110       }elseif(preg_match("/^copy_.*/",$key)){
111         $s_action="copy";
112         $s_entry  = preg_replace("/^copy_/i","",$key);
113       }elseif(preg_match("/^cut_.*/",$key)){
114         $s_action="cut";
115         $s_entry  = preg_replace("/^cut_/i","",$key);
116       }
117     }
118    
119     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
120     $s_entry  = preg_replace("/_.$/","",$s_entry);
122     /* Edit was requested by pressing the name(link) of an item */
123     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
124       $s_action ="edit";
125       $s_entry  = $_GET['id'];
126     }
127     /* Create options */
128     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
129       $s_action = "newsystem";
130       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
131     }
133     /* handle C&P from layers menu */
134     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
135       $s_action = "copy_multiple";
136     }
137     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
138       $s_action = "cut_multiple";
139     }
140     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
141       $s_action = "editPaste";
142     }
144     /* Handle daemon events */
145     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
146       $s_action = $_POST['menu_action'];
147     }
148     
149     /* Handle daemon events */
150     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
151       $s_action = $_POST['menu_action'];
152     }
154     /* handle remove from layers menu */
155     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
156       $s_action = "del_multiple";
157     }
158     
159     /* Handle instant actions from layers menu */
160     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
161             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
162               $s_action = "${act}_multiple";
163             }
164     }
166     /* Activate multiple machines */
167     if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
168       $s_action = "activate_multiple";
169     }
171     /* Check for exeeded sizelimit */
172     if (($message= check_sizelimit()) != ""){
173       return($message);
174     }
176     /* Try to get informations about what kind of system to create */
177     if ($s_action=="new") {
178       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
179     }
181     /* Incoming handling  
182      * If someone made a systemtype and ogroup selection 
183      * Display the new requested entry type ... servtab  in case of server and so on.
184      */
185     if(isset($_POST['SystemTypeChoosen'])){
186       $s_action = "SelectedSystemType";
187     }
189     /********************
190       Copy & Paste Handling  ...
191      ********************/
193     /* Display the copy & paste dialog, if it is currently open */
194     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
195     if($ret){
196       return($ret);
197     }
198   
200     /********************
201       Create FAI CD ...   
202      ********************/
203     if ($s_action=="gen_cd"){
204       $this->dn= $this->terminals[$s_entry]['dn'];
205       session::set('objectinfo',$this->dn);
206       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
207     }
210     /* Start CD-Creation */
211     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
212       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
213       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
214     }
217     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
219       $return_button   = "<form method='get' action='main.php' target='_parent'>
220         <input type='submit' value='"._("Back")."'>
221         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
222         </form>";
224       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
226       /* Get and check command */
227       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
228       
229       if (check_command($command)){
230         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
232         /* Print out html introduction */
233         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
234           <html>
235           <head>
236           <title></title>
237           <style type="text/css">@import url("themes/default/style.css");</style>
238           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
239           </head>
240           <body style="background: none; margin:4px;" id="body" >
241           <pre>';
243         /* Open process handle and check if it is a valid process */
244         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
245         if (is_resource($process)) {
246           fclose($pipes[0]);
248           /* Print out returned lines && write JS to scroll down each line */
249           while (!feof($pipes[1])){
250             $cur_dat = fgets($pipes[1], 1024);
251             echo $cur_dat;
252             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
253             flush();
254           }
255         }
257         /* Get error string && close streams */
258         $buffer= stream_get_contents($pipes[2]);
260         fclose($pipes[1]);
261         fclose($pipes[2]);
262         echo "</pre>";
264         /* Check return code */
265         $ret= proc_close($process);
266         if ($ret != 0){
267           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
268           echo "<pre style='color:red'>$buffer</pre>";
269         }
273         echo $return_button."<br>";
275       } else {
276         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
277         echo $tmp;
278       }
280       /* Scroll down completly */
281       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
282       echo '</body></html>';
283       flush();
284       exit;
285     }
288     /********************
289       New Device hanlding  (Ogroup/System select dialog.)
290      ********************/
292     if($s_action == "SelectedSystemType"){
294       /* Possible destination system types 
295        */
296       $tabs = array(
297           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     
298             "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
299           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     
300             "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
301           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     
302             "TABCLASS" =>"servtabs",      "ACL"=> "server"));
304       /* Remember dialog selection.
305        */
306       $selected_group = $_POST['ObjectGroup'];
307       $selected_system = $_POST['SystemType'];
309       $this->systab = NULL;
311       /* Check if system type exists. It should! */
312       if(isset($tabs[$selected_system])){
314         /* Get tab informations */
315         $class    = $tabs[$selected_system]["CLASS"];
316         $tabname  = $tabs[$selected_system]["TABNAME"];
317         $tabclass = $tabs[$selected_system]["TABCLASS"];
318         $acl_cat  = $tabs[$selected_system]["ACL"];
320         /* Go through all objects that should be activated */
321         foreach($this->system_activation_object as $key => $dn){
323           /* Remove entry from list, to avoid page-reload problems */
324           unset($this->system_activation_object[$key]);
325   
326           /* Load permissions for selected 'dn' and check if
327              we're allowed to create this 'dn' */
328           $this->dn = $dn;
329           $ui       = get_userinfo();
330           $tabacl   = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
332           /* We are allowed to create the requested system type */
333           if(preg_match("/c/",$tabacl)){
334             $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
335             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
336             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
337             $this->systab->base = $this->DivListSystem->selectedBase;
340             if($selected_group != "none"){
342               /*******
343                * Set gotoMode to active if we there was an ogroup selected. 
344                */
345               $found = false;
346               foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
347                 if(isset($this->systab->by_object[$tab]->gotoMode)) {
348                   $found = true;
349                   $this->systab->by_object[$tab]->gotoMode = $value;
350                 }
351               }
352               if(!$found){
353                 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
354               }
356               /*******
357                * Update object group membership
358                */
359               $og = new ogroup($this->config,$selected_group);
360               if($og){
361                 $og->AddDelMembership($this->systab->dn);
362                 $og->save();
363               }
365               /*******
366                * Set default system specific attributes 
367                */
368               foreach (array("workservice", "termservice") as $cls){
369                 if (isset($this->systab->by_object[$cls])){
370                   $this->systab->by_object[$cls]->gotoXMouseport= "";
371                   $this->systab->by_object[$cls]->gotoXMouseType= "";
372                   $this->systab->by_object[$cls]->gotoXResolution= "";
373                   $this->systab->by_object[$cls]->gotoXColordepth= "";
374                 }
375               }
377               // Enable activation
378               foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
379                 if (isset($this->systab->by_object[$cls])){
380                   $this->systab->by_object[$cls]->auto_activate= TRUE;
381                 }
382               }
384               // Enable sending of LDAP events
385               if (isset($this->systab->by_object["workstartup"])){
386                 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
387               }
388             }
390             /* Don't save directly if there is no objectGroup selected.
391                The user will then be able to configure the missing attributes 
392                 on his own.
393              */
394             if($selected_group != "none"){
395               $this->systab->save();
396               $this->systab = NULL;
398               if(!isset($ldap)){
399                 $ldap = $this->config->get_ldap_link();
400               }
401               $ldap->cd ($this->dn);
402               $ldap->cat($this->dn, array('dn'));
403               if(count($ldap->fetch())){
404                 $ldap->cd($this->dn);
405                 $ldap->rmDir($this->dn);
406               }
407             }
408           }else{
409             msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
410           }
411         }
412       }
413     }
416     if (isset($_POST['create_system'])||$s_action=="newsystem") {
418       /* If the current entry is an incoming object 
419        * $sw = System type as posted in new incoming handling dialog 
420        */ 
421       if(isset($_POST['system'])){
422         $sw = $_POST['system'];
423       }else{
424         $sw = $s_entry;
425       }
426       $this->dn= "new";
428       $tabs = array(
429           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
430           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
431           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
432           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
433           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
434           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
436       if(isset($tabs[$sw])){
437         $class    = $tabs[$sw]["CLASS"];
438         $tabname  = $tabs[$sw]["TABNAME"];
439         $tabclass = $tabs[$sw]["TABCLASS"];
440         $acl_cat  = $tabs[$sw]["ACL"];
442         /* Load permissions for selected 'dn' and check if
443            we're allowed to remove this 'dn' */
444         $ui       = get_userinfo();
445         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
446         if(preg_match("/c/",$tabacl)){
447           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
448           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
449           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
450           $this->systab->base = $this->DivListSystem->selectedBase;
451         }else{
452           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
453         }
454       }
455     }
458     /********************
459       System activation
460      ********************/
462     /* User wants to edit data? */
463     if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
464       $this->system_activation_object = array();
465       foreach($this->list_get_selected_items() as $id) {
466         $obj = $this->terminals[$id];
467         $type= $this->get_system_type($obj);
468         if($type == "NewDevice"){
469           $this->system_activation_object[] = $obj['dn'];
470         }
471       }
472       if(count($this->system_activation_object)){
473         $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
474       }
475     }
478     /********************
479       Edit system ...   
480      ********************/
482     /* User wants to edit data? */
483     if (($s_action == "edit") && (!isset($this->systab->config))){
485       $this->dn= $this->terminals[$s_entry]['dn'];
487       /* Check locking, save current plugin in 'back_plugin', so
488          the dialog knows where to return. */
489       if (($user= get_lock($this->dn)) != ""){
490         return(gen_locked_message ($user, $this->dn));
491       }
493       /* Find out more about the object type */
494       $ldap= $this->config->get_ldap_link();
495       $ldap->cat($this->dn, array('objectClass','gotoMode'));
496       $attrs= $ldap->fetch();
497       $type= $this->get_system_type($attrs);
499       /* Lock the current entry, so everyone will get the
500          above dialog */
501       $tabs = array(
502           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
503           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
504           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
505           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
506           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
507           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
508           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
511       if($type == "ArpNewDevice"){
512         $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
513       }elseif($type == "NewDevice"){
514         $this->system_activation_object= array($this->dn);
515         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
516       }elseif(isset($tabs[$type])){
518         $class    = $tabs[$type]["CLASS"];
519         $acl_cat  = $tabs[$type]["ACL"];
520         $tabclass = $tabs[$type]["TABCLASS"];
522         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
523         $this->systab->set_acl_base($this->dn);
524         session::set('objectinfo',$this->dn);
525         add_lock ($this->dn, $this->ui->dn);
526       }else{ 
527         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
528         $this->remove_lock();
529       }
530     }
533     /********************
534       Change password ...   
535      ********************/
537     /* Set terminals root password */
538     if ($s_action=="change_pw"){
539       $tabs = array(
540           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
541           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
542           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
543           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
544           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
545           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
546           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
547           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
548           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
550       $dn   = $this->terminals[$s_entry]['dn'];
551       $type = $this->get_system_type($this->terminals[$s_entry]);
553       $class    = $tabs[$type]["CLASS"];
554       $acl      = $tabs[$type]["ACL"];
555       $tabclass = $tabs[$type]["TABCLASS"];
556       $ui       = get_userinfo();
557       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
558       if(preg_match("/w/",$tabacl)){
559         $this->dn= $this->terminals[$s_entry]['dn'];
560         session::set('objectinfo',$this->dn);
561         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
562       }else{
563         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
564       }
565     }
568     /********************
569       Password change finish, but check if entered data is ok 
570      ********************/
572     /* Correctly specified? */
573     if (isset($_POST['password_finish'])){
574       if ($_POST['new_password'] != $_POST['repeated_password']){
575         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
576         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
577       }
578     }
580     /********************
581       Password change finish
582      ********************/
584     /* Change terminal password */
585     if (isset($_POST['password_finish']) && 
586         $_POST['new_password'] == $_POST['repeated_password']){
588       /* Check if user is allowed to set password */
589       $tabs = array(
590           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"    ,"PLUG"=>"termgeneric"),
591           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
592           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"      ,"PLUG"=>"servgeneric"),
593           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
595       /* Detect object type */
596       $type = "";
597       foreach($this->terminals as $terminal){
598         if($terminal['dn'] == $this->dn){
599           $type  = $this->get_system_type($terminal);
600           break;
601         } 
602       }
604       /* Type detected */
605       $allow_for = array("terminal","workstation","server","component");
606       if(!empty($type) && in_array($type,$allow_for)){
608         /* Get infos */
609         $plug     = $tabs[$type]["PLUG"];
610         $class    = $tabs[$type]["CLASS"];
611         $acl      = $tabs[$type]["ACL"];
612         $tabclass = $tabs[$type]["TABCLASS"];
613     
614         /* Get acls */
615         $ui       = get_userinfo();
616         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
618         /* Check acls */
619         if(preg_match("/w/",$tabacl)){
620           $ldap = $this->config->get_ldap_link();
621           $ldap->cd($this->dn);
622           $ldap->cat($this->dn);
623           $old_attrs = $ldap->fetch();
625           $attrs= array();
626           if ($_POST['new_password'] == ""){
628             /* Remove password attribute 
629              */
630             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
631               $attrs['objectClass'] = array();
632               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
633                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
634                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
635                 }
636               }
637             }
638             $attrs['userPassword']= array();
639           } else {
641             /* Add/modify password attribute 
642              */
643             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
644               $attrs['objectClass'] = array();
645               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
646                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
647               }
648               $attrs['objectClass'][] = "simpleSecurityObject";
649             }
651             if(class_available("passwordMethodCrypt")){
652               $pwd_m = new passwordMethodCrypt($this->config);
653               $pwd_m->set_hash("crypt/md5");
654               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
655             }else{
656               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
657               $attrs = array();
658             }
659           }
660           $ldap->modify($attrs);
661           if (!$ldap->success()){
662             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
663           }else{
664             if(class_available($plug)){
665               $p = new $plug($this->config,$this->dn);
666               $p->handle_post_events("modify");
667             }
668           }
669   
670           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
671         }else{
672           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
673         }
674       }else{
675         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
676       }
677       session::un_set('objectinfo');
678     }
681     /********************
682       Delete system cancel
683      ********************/
685     /* Delete terminal canceled? */
686     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
687       $this->remove_lock();
688       session::un_set('objectinfo');
689     }
692     /********************
693       Action(s) for MULTIPLE
694      ********************/
696     /********************
697       SCHEDULE action in GOsa Daemon
698      ********************/
700     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
701       $this->dns = array();
702       $ids = $this->list_get_selected_items();
704       if(count($ids)){
705         $mac= array();
707         $ldap = $this->config->get_ldap_link();
708         foreach($ids as $id){
709           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
710           $attrs= $ldap->fetch();
711           if (isset($attrs['macAddress'][0])){
712             $mac[]= $attrs['macAddress'][0];
713           }
714         }
715         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
716         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
717         $o_queue = new gosaSupportDaemon();
719         /* Skip installation or update trigerred events, 
720          *  if this entry is currently processing.
721          */
722         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
723           foreach($mac as $key => $mac_address){
724             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
726               $entry['STATUS'] = strtoupper($entry['STATUS']);
727               if($entry['STATUS'] == "PROCESSING" && 
728                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
729                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
730                 unset($mac[$key]);
732                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
733                 break;
734               }
735             }
736           }
737         }        
739         /* Prepare event to be added 
740          */
741         if(count($mac) && isset($events['BY_CLASS'][$type])){
742           $event = $events['BY_CLASS'][$type];
743           $this->systab = new $event['CLASS_NAME']($this->config);
744           $this->systab->add_targets($mac);
745           if(preg_match("/trigger_event/",$s_action)){
746             $this->systab->set_type(TRIGGERED_EVENT);
747           }else{
748             $this->systab->set_type(SCHEDULED_EVENT);
749           }
750         }
751       }
752     }
754     /* Insert scheduled events into queue */
755     if($this->systab instanceof DaemonEvent){
756       $this->systab->save_object();
758       /* Save event 
759        */
760       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
761         $o_queue = new gosaSupportDaemon();
762         $o_queue->append($this->systab);
763         if($o_queue->is_error()){
764           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
765         }else{
766           $this->systab = FALSE;
767         }
768       }
769       if(isset($_POST['abort_event_dialog'])){
770         $this->systab = FALSE;
771       }
772     }
775     /********************
776       Delete MULTIPLE entries requested, display confirm dialog
777      ********************/
779     if ($s_action=="del_multiple"){
780       $this->dns = array();
781       $ids = $this->list_get_selected_items();
783       $ui = get_userinfo();
784       $tabs = array(
785           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
786           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
787           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
788           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
789           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
790           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
791           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
792           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
793           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
796       if(count($ids)){
798         $disallowed = array();
799         foreach($ids as $id){
801           /* Get 'dn' from posted termlinst */
802           $attrs  = $this->terminals[$id];
803           $type   = $this->get_system_type($attrs);
804           $dn     = $attrs['dn'];
805           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
806           if(preg_match("/d/",$acl)){
807             $this->dns[$id] = $dn;
808           }else{
809             $disallowed[] = $dn;
810           }
811         }
813         if(count($disallowed)){
814           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
815         }
817         if(count($this->dns)){
819           if ($user= get_multiple_locks($this->dns)){
820             return(gen_locked_message($user,$this->dns));
821           }
823           $dns_names = array();
824           foreach($this->dns as $dn){
825             add_lock ($dn, $this->ui->dn);
826             $dns_names[] = @LDAP::fix($dn);
827           }
829           /* Lock the current entry, so nobody will edit it during deletion */
830           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
831           $smarty->assign("multiple", true);
832           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
833         }
834       }
835     }
838     /********************
839       Delete MULTIPLE entries confirmed
840      ********************/
842     /* Confirmation for deletion has been passed. Users should be deleted. */
843     if (isset($_POST['delete_multiple_system_confirm'])){
845       $ui = get_userinfo();
846       $tabs = array(
847           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
848           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
849           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
850           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
851           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
852           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
853           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
854           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
855           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
858       /* Remove user by user and check acls before removeing them */
859       foreach($this->dns as $key => $dn){
861         /* Get 'dn' from posted termlinst */
862         $attrs    = $this->terminals[$key];
863         $type= $this->get_system_type($attrs);
865         /* get object type */
866         $tabtype  = "termtabs";
867         $tabobj   = "TERMTABS";
868         $tabacl   = "";
869         if(isset($tabs[$type])){
870           $tabtype = $tabs[$type]['TABCLASS'];
871           $tabobj  = $tabs[$type]['CLASS'];
872           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
874           /* Load permissions for selected 'dn' and check if
875              we're allowed to remove this 'dn' */
876           if(preg_match("/d/",$tabacl)){ 
878             /* Delete request is permitted, perform LDAP action */
879             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
880               $this->systab= new termgeneric($this->config, $dn);
881               $this->systab->set_acl_base($dn);
882               $this->systab->remove_from_parent();
883             }elseif($tabtype=="phonetabs"){
884               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
885               $this->systab->set_acl_base($dn);
886               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
887             }else{
888               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
889               $this->systab->set_acl_base($dn);
890               $this->systab->delete();
891             }
892             unset ($this->systab);
893             $this->systab= NULL;
895           } else {
896             /* Normally this shouldn't be reached, send some extra
897                logs to notify the administrator */
898             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
899             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
900           }
901         }
903         /* Remove lock file after successfull deletion */
904         $this->remove_lock();
905         $this->dns = array();
906       }
907     }
909     /********************
910       Delete MULTIPLE entries Canceled
911      ********************/
913     /* Remove lock */
914    if(isset($_POST['delete_multiple_system_cancel'])){
916      /* Remove lock file after successfull deletion */
917      $this->remove_lock();
918      $this->dns = array();
919    }
922     /********************
923       Delete system, confirm dialog
924      ********************/
926     /* Remove terminal was requested */
927     if ($s_action=="del"){
929       /* Get 'dn' from posted termlinst */
930       $this->dn = $this->terminals[$s_entry]['dn'];
931       $attrs    = $this->terminals[$s_entry];
933   
935       $type= $this->get_system_type($attrs);
936       $ui = get_userinfo();
937       $tabs = array(
938           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
939           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
940           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
941           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
942           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
943           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
944           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
945           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
946           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
948       /* get object type */
949       $tabtype  = "termtabs";
950       $tabobj   = "TERMTABS";
951       $tabacl   = "";
952       if(isset($tabs[$type])){
953         $tabtype = $tabs[$type]['TABCLASS'];
954         $tabobj  = $tabs[$type]['CLASS'];
955         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
956       }
958       /* Load permissions for selected 'dn' and check if
959          we're allowed to remove this 'dn' */
960       if(preg_match("/d/",$tabacl)){ 
962         /* Check locking, save current plugin in 'back_plugin', so
963            the dialog knows where to return. */
964         if (($user= get_lock($this->dn)) != ""){
965           return(gen_locked_message ($user, $this->dn));
966         }
968         /* Lock the current entry, so nobody will edit it during deletion */
969         add_lock ($this->dn, $this->ui->dn);
970         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
971         $smarty->assign("multiple", false);
972         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
973       } else {
975         /* Obviously the user isn't allowed to delete. Show message and
976            clean session. */
977         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
978       }
979     }
982     /********************
983       Delete system, confirmed
984      ********************/
985     /* Confirmation for deletion has been passed. Terminal should be deleted. */
986     if (isset($_POST['delete_terminal_confirm'])){
988       /* Find out more about the object type */
989       $ldap= $this->config->get_ldap_link();
990       $ldap->cat($this->dn, array('objectClass'));
991       $attrs= $ldap->fetch();
992       $type= $this->get_system_type($attrs);
994       $ui = get_userinfo();
996       $tabs = array(
997           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
998           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
999           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
1000           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
1001           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
1002           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
1003           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
1004           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
1005           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
1007       /* get object type */
1008       $tabtype  = "termtabs";
1009       $tabobj   = "TERMTABS";
1010       $tabacl   = "";
1011       if(isset($tabs[$type])){
1012         $tabtype = $tabs[$type]['TABCLASS'];
1013         $tabobj  = $tabs[$type]['CLASS'];
1014         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
1015       }
1017       /* Check if we are allowed to remove this object */
1018       if(preg_match("/d/",$tabacl)){
1020         /* Delete request is permitted, perform LDAP action */
1021         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
1022           $this->systab= new termgeneric($this->config, $this->dn);
1023           $this->systab->set_acl_base($this->dn);
1024           $this->systab->remove_from_parent();
1025         }elseif($tabtype=="phonetabs"){
1026           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
1027           $this->systab->set_acl_base($this->dn);
1028           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
1029         }else{  
1030           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
1031           $this->systab->set_acl_base($this->dn);
1032           $this->systab->delete();
1033         }
1034         unset ($this->systab);
1035         $this->systab= NULL;
1037         /* Terminal list has changed, reload it. */
1038       } else {
1040         /* Normally this shouldn't be reached, send some extra
1041            logs to notify the administrator */
1042         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1043         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1044       }
1046       /* Remove lock file after successfull deletion */
1047       $this->remove_lock();
1048     }
1051     /********************
1052       Edit system type finished, check if everything went ok
1053      ********************/
1054     /* Finish user edit is triggered by the tabulator dialog, so
1055        the user wants to save edited data. Check and save at this
1056        point. */
1058     /* Dirty workaround - MSG_DIALOG - OK
1059       If a message dialog is shown and we press 'OK'
1060        then try to save again.
1061      */
1062     foreach($_POST as $name => $value){
1063       if(preg_match("/^MSG_OK/",$name)){
1064         $_POST[$this->last_action] = TRUE;
1065       }
1066     }
1068     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1070       /* If the save routine gets interrupted by a confirm dialog, 
1071           store last action so we can trigger it again after 'Ok' was pressed.
1072          (This is the case if a system gets modified while it is installing - GOsa si)
1073        */
1074       $this->last_action = ""; 
1075       if(isset($_POST['edit_finish'])){
1076         $this->last_action = "edit_finish"; 
1077       }elseif(isset($_POST['edit_apply'])){
1078         $this->last_action = "edit_apply";
1079       }
1081       /* Check tabs, will feed message array */
1082       $message = $this->systab->check();
1084       /* Save, or display error message? */
1085       if (count($message) == 0){
1088         $this->systab->save();
1090         /* Terminal has been saved successfully, remove lock from LDAP. */
1091         if (!isset($_POST['edit_apply'])){
1092           if ($this->dn != "new"){
1093             $this->remove_lock();
1094           }
1096           unset ($this->systab);
1097           $this->systab= NULL;
1098           session::un_set('objectinfo');
1099         }else{
1100       
1101           /* Reinitialize tab */
1102           if($this->systab instanceof tabs){
1103             $this->systab->re_init();
1104           }
1105         }
1106       } else {
1107         /* Ok. There seem to be errors regarding to the tab data,
1108            show message and continue as usual. */
1109         msg_dialog::displayChecks($message);
1110       }
1111     }
1114     /********************
1115       Edit system was canceled 
1116      ********************/
1117     /* Cancel dialogs */
1118     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1119       if (isset($this->systab)){
1120         $this->remove_lock();
1121         unset ($this->systab);
1122       }
1123       $this->systab= NULL;
1124       session::un_set('objectinfo');
1125     }
1127     /********************
1128       Display edit dialog, or some other
1129      ********************/
1131     /* Show tab dialog if object is present */
1132     if (isset($this->systab->config)){
1133       $display= $this->systab->execute();
1135       /* Don't show buttons if tab dialog requests this */
1137       $dialog     = FALSE;
1138       $hide_apply = $this->dn == "new";
1139       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1140       if(is_object($this->systab) && !isset($this->systab->by_object)){
1141         $dialog = TRUE;
1142         $hide_apply = TRUE;
1143       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1144         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1145         if($dia === TRUE || is_object($dia)){
1146           $dialog = TRUE;
1147         }  
1148       }
1149       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1150         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1151         $dialog = TRUE;
1152       }
1154       if (!$dialog){
1155         $display.= "<p style=\"text-align:right\">\n";
1156         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1157         $display.= "&nbsp;\n";
1158         if (!$hide_apply){
1159           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1160           $display.= "&nbsp;\n";
1161         }
1162         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1163         $display.= "</p>";
1164       }
1165       return ($display);
1166     }
1168     /* Check if there is a snapshot dialog open */
1169     $base = $this->DivListSystem->selectedBase;
1170     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1171       return($str);
1172     }
1174     /* Display dialog with system list */
1175     $this->DivListSystem->parent = $this;
1176     $this->DivListSystem->execute();
1178     /* Add departments if subsearch is disabled */
1179     if(!$this->DivListSystem->SubSearch){
1181       /* Add FAIstate to attributes if FAI is activated */
1182       if($this->fai_activated){
1183         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1184       }else{
1185         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1186       }
1187     }
1188     $this->reload();
1189     $this->DivListSystem->setEntries($this->terminals);
1190     return($this->DivListSystem->Draw());
1191   }
1194   /* Return departments, that will be included within snapshot detection */
1195   function get_used_snapshot_bases()
1196   {
1197     $tmp = array();
1199     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1201     $tabs = array(
1202         "terminal"        => get_ou('terminalou'),
1203         "workstation"     => get_ou('workstationou'),
1204         "incoming"        => get_ou('incomingou'),
1205         "server"          => get_ou('serverou'),
1206         "printer"         => get_ou('printerou'),
1207         "phone"           => get_ou('phoneou'),
1208         "winworkstation"  => get_winstations_ou(),
1209         "component"       => get_ou('componentou')
1210         ); 
1212     foreach($tabs as $acl_cat => $dn){
1214       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1215       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1216         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1217       }
1218     }
1219     return($tmp); 
1220   }
1223   function remove_from_parent()
1224   {
1225     /* Optionally execute a command after we're done */
1226     $this->postremove();
1227   }
1230   /* Save data to object */
1231   function save_object()
1232   {
1233     $this->DivListSystem->save_object();
1234     if(is_object($this->CopyPasteHandler)){
1235       $this->CopyPasteHandler->save_object();
1236     }
1237   }
1240   /* Check values */
1241   function check()
1242   {
1243   }
1246   /* Save to LDAP */
1247   function save()
1248   {
1249   }
1251   function adapt_from_template($dn, $skip= array())
1252   {
1253   }
1255   function password_change_needed()
1256   {
1257   }
1259   function reload()
1260   {
1261     /* some var init */
1262     $ui = get_userinfo();
1263     $res              = array();
1264     $this->terminals  = array();
1265     $userregex        = "";
1267     /* Set base for all searches */
1268     $base=  $this->DivListSystem->selectedBase;
1270     /* Prepare samba class name */
1271     $samba  ="";
1272     if ($this->DivListSystem->ShowWinWorkstations){
1273       if ($this->config->current['SAMBAVERSION'] == "3"){
1274         $samba= "sambaSamAccount";
1275       } else {
1276         $samba= "sambaAccount";
1277       }
1278     }
1280     /* This array represents the combination between checkboxes and search filters */
1281     $objs = array( 
1282         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1283         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1284         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1285         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1286         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1287         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1288         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1290     /* Include the 'Display Systems of user' attribute */ 
1291     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1292       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1293     }
1295     /* Attributes to fetch */
1296     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1297     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1299     /* Add FAIstate to attributes if FAI is activated */
1300     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1301     if(!empty($tmp)){
1302       $sys_attrs[] = "FAIstate";
1303     }    
1305     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1306     foreach($objs as $checkBox => $oc){
1307       if($this->DivListSystem->$checkBox){
1308         if($this->DivListSystem->SubSearch){
1309           if($oc['CLASS'] != ""){
1310             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1311             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1312             $res = array_merge($res,$new_res);
1313           }
1314         }else{
1315           /* User filter? */
1316           if($oc['CLASS'] != ""){
1317             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1318             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1319           }
1320         }
1321       } 
1322     }
1324     /* Search for incoming objects */ 
1325     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1326     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1328     /* Get all gotoTerminal's */
1329     foreach ($res as $value){
1331       $tmp= $value['dn'];
1332       $add= "";
1334       /* Extract base */
1335       foreach($objs as $obj){
1336         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1337           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1338         }
1339       }
1341       /* Create a string containing the last part of the department. */
1342       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1343       if(empty($dn_name)){
1344         $dn_name = "/";
1345       }
1347       /* check if current object is a new one */
1348       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1349         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1350           $add= "- "._("New terminal");
1351         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1352           $add= "- "._("New workstation");
1353         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1354           $add= "- "._("Unknown device");
1355         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1356           $add= "- "._("New Device");
1357         }
1358       } 
1360       /* Detect type of object and create an entry for $this->terminals */
1361       $terminal = array();
1362       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1364         /* check acl */
1365         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1366         if($add != "" || preg_match("/r/",$acl)) {
1367           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1368             $terminal             = $value;
1369             $terminal['type']     = "T";
1370             $terminal['is_new']   = $add;
1371           } else {
1372             $terminal             = $value;
1373             $terminal['type']     = "D";
1374             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1375             $terminal['location'] = array_search($tmp, $this->config->departments); 
1376           }
1377         }
1378       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1380         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1381         if($add != "" || preg_match("/r/",$acl)) {
1382           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1383             $terminal             = $value;
1384             $terminal['type']     = "L";
1385             $terminal['is_new']   = $add;
1386           } else {
1387             $terminal             = $value;
1388             $terminal['type']     = "D";
1389             $terminal['location'] = array_search($tmp, $this->config->departments);
1390             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1391           }
1392 #          if (isset($value["FAIstate"][0])){
1393 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1394 #          }
1395         }
1396       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1397        
1398    
1399         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1400         if($add != "" || preg_match("/r/",$acl)) {
1402           $terminal             = $value;
1403           $terminal['type']     = "P";
1404         }
1405       } elseif (in_array_ics('goServer', $value["objectClass"])){
1407         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1408         if($add != "" || preg_match("/r/",$acl)) {
1410           $terminal             = $value;
1411           $terminal['type']     = "S";
1412 #          if (isset($value["FAIstate"][0])){
1413 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1414 #          }
1415         }
1416       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1418         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1419         if($add != "" || preg_match("/r/",$acl)) {
1421           $terminal             = $value;
1422           $terminal['type']     = "F";
1423         }
1424       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1426         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1427                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1428                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1429         if($add != "" || preg_match("/r/",$acl)) {
1431           $terminal = $value;
1432           $terminal['type']   = "Q";
1433           $terminal['is_new'] = $add;
1434         }
1435       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1437         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1438         if($add != "" || preg_match("/r/",$acl)) {
1440           $terminal             = $value;
1441           $terminal['type']     = "C";
1442         }
1443       } else{
1445         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1446         if (isset($value['sambaDomainName'])){
1447           $domain= " [".$value['sambaDomainName'][0]."]";
1448         } else {
1449           $domain= "";
1450         }
1451         $terminal=$value;
1452         $terminal['type']     ="W";
1453         $terminal['domain']   = $name.$domain;
1454       }
1456       if(count($terminal)){
1457         $this->terminals[]=$terminal;
1458       }
1459     }
1461     $tmp  =array();
1462     $tmp2 =array();
1463     foreach($this->terminals as $tkey => $val ){
1464       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1465       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1466     }
1467     natcasesort($tmp2);
1468     $this->terminals=array();
1469     foreach($tmp2 as $val){
1470       $this->terminals[]=$tmp[$val];
1471     }
1472     reset ($this->terminals);
1473   }
1475   function remove_lock()
1476   {
1477     if (isset($this->systab->dn)){
1478       del_lock ($this->systab->dn);
1479     }
1480     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1481       del_lock($this->dn);
1482     }
1483     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1484       del_lock($this->dns);
1485     }
1486   }
1489   function copyPasteHandling_from_queue($s_action,$s_entry)
1490   {
1491     /* Check if Copy & Paste is disabled */
1492     if(!is_object($this->CopyPasteHandler)){
1493       return("");
1494     }
1496     $ui = get_userinfo();
1498     $tabs = array(
1499         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1500           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1501         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1502           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1503         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1504           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1505         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1506           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1507         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1508           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1509         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1510           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1512     /* Add a single entry to queue */
1513     if($s_action == "cut" || $s_action == "copy"){
1515       /* Cleanup object queue */
1516       $this->CopyPasteHandler->cleanup_queue();
1517       $dn     = $this->terminals[$s_entry]['dn'];
1518       $oc     = $this->terminals[$s_entry]['objectClass'];
1519       $type   = $this->get_system_type($this->terminals[$s_entry]);
1521       $tab_o  = $tabs[$type]['CLASS'];
1522       $tab_c  = $tabs[$type]['TABCLASS'];
1523       $acl    = $tabs[$type]['ACL'];
1525       if($s_action == "copy" && preg_match("/r/",$ui->has_complete_category_acls($dn,$acl))){
1526         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1527       }
1528       if($s_action == "cut" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,$acl))){
1529         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1530       }
1531     }
1533     /* Add entries to queue */
1534     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1536       /* Cleanup object queue */
1537       $this->CopyPasteHandler->cleanup_queue();
1539       /* Add new entries to CP queue */
1540       foreach($this->list_get_selected_items() as $id){
1541         $dn = $this->terminals[$id]['dn'];
1542         $oc = $this->terminals[$id]['objectClass']; 
1543         $type = $this->get_system_type($this->terminals[$id]);
1545         if(isset($tabs[$type])){
1546           $tab_o  = $tabs[$type]['CLASS'];
1547           $tab_c  = $tabs[$type]['TABCLASS'];
1548           $acl    = $tabs[$type]['ACL'];
1550           if($s_action == "copy_multiple" && preg_match("/r/",$ui->has_complete_category_acls($dn,$acl))){
1551             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1552           }
1553           if($s_action == "cut_multiple" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,$acl))){
1554             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1555           }
1556         }
1557       }
1558     }
1560     /* Start pasting entries */
1561     if($s_action == "editPaste"){
1562       $this->start_pasting_copied_objects = TRUE;
1563     }
1564   
1565     /* Return C&P dialog */
1566     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1568       /* Get dialog */
1569       $data = $this->CopyPasteHandler->execute();
1570       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1572       /* Return dialog data */
1573       if(!empty($data)){
1574         return($data);
1575       }
1576     }
1578     /* Automatically disable status for pasting */
1579     if(!$this->CopyPasteHandler->entries_queued()){
1580       $this->start_pasting_copied_objects = FALSE;
1581     }
1582     return("");
1583   }
1586   function get_system_type($attrs)
1587   {
1588     $classes = $attrs['objectClass'];
1590     $type= "";
1591     if (in_array_ics('ieee802Device', $classes)){
1592       $type= "component";
1593     }elseif (in_array_ics('gotoTerminal', $classes)){
1594       $type= "terminal";
1595     }elseif (in_array_ics('gotoWorkstation', $classes)){
1596       $type= "workstation";
1597     }elseif (in_array_ics('gotoPrinter', $classes)){
1598       $type= "printer";
1599     }elseif (in_array_ics('goFonHardware', $classes)){
1600       $type= "phone";
1601     }elseif (in_array_ics('goServer', $classes)){
1602       $type= "server";
1603     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1604       $type= "ArpNewDevice";
1605     }elseif (in_array_ics('GOhard', $classes)){
1606       $type= "NewDevice";
1607     }elseif (in_array_ics('sambaAccount', $classes) ||
1608         in_array_ics('sambaSamAccount', $classes)){
1609       $type= "winstation";
1610     }
1611     return ($type);
1612   }
1615   function convert_list($input)
1616   {
1617     $temp= "";
1619     $conv= array(
1620         "D" => array("select_default.png",_("Template")),
1621         "F" => array("select_phone.png",_("Phone")),
1622         "C" => array("select_component.png",_("Network device")),
1623         "P" => array("select_printer.png",_("Printer")),
1625         "W" => array("select_winstation.png",_("Win workstation")),
1627         "L" => array("select_workstation.png",_("Workstation")),
1628         "S" => array("select_server.png",_("Server")),
1629         "T" => array("select_terminal.png",_("Terminal")),
1631         "LX" => array("workstation_locked.png",_("Locked workstation")),
1632         "SX" => array("server_locked.png",_("Locked server")),
1633         "TX" => array("terminal_locked.png",_("Locked terminal")),
1635         "LE" => array("workstation_error.png",_("Workstation error")),
1636         "SE" => array("server_error.png",_("Server error")),
1637         "TE" => array("terminal_error.png",_("Terminal error")),
1639         "LB" => array("workstation_busy.png",_("Workstation busy")),
1640         "SB" => array("server_busy.png",_("Server busy")),
1642         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1643         "NT"=> array("select_new_terminal.png",_("New terminal")),
1644         "NL"=> array("select_new_workstation.png",_("New workstation")));
1646     /* Use locked icons 
1647      */
1648     if( in_array($input['type'],array("S","T","L")) && 
1649         isset($input['gotoMode'][0]) && 
1650         preg_match("/locked/",$input['gotoMode'][0])){
1651       $input['type'].="X";
1652     } elseif(in_array($input['type'],array("S","L")) &&
1653         isset($input['FAIstate'][0])){
1655     /* Add FAI state icons 
1656      */
1657       $type= "";
1658       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1659         case 'error':
1660           $type= 'E';
1661           break;
1662         case 'installing':
1663         case 'install':
1664         case 'sysinfo':
1665         case 'softupdate':
1666         case 'scheduledupdate':
1667           $type= 'B';
1668           break;
1669       }
1671       $input['type'].= $type;
1672     }   
1674     /* Use new images if object is from incoming 
1675      */
1676     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1677       $input['type']="N".$input['type'];
1678     }
1680     /* Check which flags this objects uses 
1681      */
1682     foreach ($conv  as $key => $value){
1683       $found = TRUE;
1684       if(strlen($key) != strlen($input['type'])) {
1685         $found = FALSE;
1686       }
1687       for($i = 0 ; $i < strlen($key) ; $i++){
1688         if(!preg_match("/".$key[$i]."/",$input['type'])){
1689           $found = FALSE;
1690         }
1691       }
1693       if($found){
1694         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1695         $tmp['class']=$key;
1696         return $tmp;
1697       }
1698     }
1699   }
1702   function list_get_selected_items()
1703   {
1704     $ids = array();
1705     foreach($_POST as $name => $value){
1706       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1707         $id   = preg_replace("/^item_selected_/","",$name);
1708         $ids[$id] = $id;
1709       }
1710     }
1711     return($ids);
1712   }
1715   /* !! Incoming dummy acls, required to defined acls for incoming objects
1716    */
1717   static function plInfo()
1718   {
1719     return (array(
1720           "plShortName"   => _("Incoming objects"),
1721           "plDescription" => _("Incoming objects"),
1722           "plSelfModify"  => FALSE,
1723           "plDepends"     => array(),
1724           "plPriority"    => 99,
1725           "plSection"     => array("administration"),
1726           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1727                                                           "objectClass"  => "")),
1728           "plProvidedAcls"=> array()
1729             
1730           ));
1731   }
1734   
1738 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1739 ?>