Code

Added release col to system management. Sorting does now work currently.
[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       if(count($ids)){
785         foreach($ids as $id){
786           $dn = $this->terminals[$id]['dn'];
787           $this->dns[$id] = $dn;
788         }
789         if ($user= get_multiple_locks($this->dns)){
790           return(gen_locked_message($user,$this->dns));
791         }
793         $dns_names = array();
794         foreach($this->dns as $dn){
795           add_lock ($dn, $this->ui->dn);
796           $dns_names[] = @LDAP::fix($dn);
797         }
799         /* Lock the current entry, so nobody will edit it during deletion */
800         $smarty->assign("warning", msgPool::deleteInfo($dns_names));
801         $smarty->assign("multiple", true);
802         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
803       }
804     }
807     /********************
808       Delete MULTIPLE entries confirmed
809      ********************/
811     /* Confirmation for deletion has been passed. Users should be deleted. */
812     if (isset($_POST['delete_multiple_system_confirm'])){
814       $ui = get_userinfo();
815       $tabs = array(
816           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
817           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
818           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
819           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
820           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
821           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
822           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
823           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
824           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
827       /* Remove user by user and check acls before removeing them */
828       foreach($this->dns as $key => $dn){
830         /* Get 'dn' from posted termlinst */
831         $attrs    = $this->terminals[$key];
832         $type= $this->get_system_type($attrs);
834         /* get object type */
835         $tabtype  = "termtabs";
836         $tabobj   = "TERMTABS";
837         $tabacl   = "";
838         if(isset($tabs[$type])){
839           $tabtype = $tabs[$type]['TABCLASS'];
840           $tabobj  = $tabs[$type]['CLASS'];
841           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
843           /* Load permissions for selected 'dn' and check if
844              we're allowed to remove this 'dn' */
845           if(preg_match("/d/",$tabacl)){ 
847             /* Delete request is permitted, perform LDAP action */
848             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
849               $this->systab= new termgeneric($this->config, $dn);
850               $this->systab->set_acl_base($dn);
851               $this->systab->remove_from_parent();
852             }elseif($tabtype=="phonetabs"){
853               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
854               $this->systab->set_acl_base($dn);
855               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
856             }else{
857               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
858               $this->systab->set_acl_base($dn);
859               $this->systab->delete();
860             }
861             unset ($this->systab);
862             $this->systab= NULL;
864           } else {
865             /* Normally this shouldn't be reached, send some extra
866                logs to notify the administrator */
867             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
868             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
869           }
870         }
872         /* Remove lock file after successfull deletion */
873         $this->remove_lock();
874         $this->dns = array();
875       }
876     }
878     /********************
879       Delete MULTIPLE entries Canceled
880      ********************/
882     /* Remove lock */
883    if(isset($_POST['delete_multiple_system_cancel'])){
885      /* Remove lock file after successfull deletion */
886      $this->remove_lock();
887      $this->dns = array();
888    }
891     /********************
892       Delete system, confirm dialog
893      ********************/
895     /* Remove terminal was requested */
896     if ($s_action=="del"){
898       /* Get 'dn' from posted termlinst */
899       $this->dn = $this->terminals[$s_entry]['dn'];
900       $attrs    = $this->terminals[$s_entry];
902   
904       $type= $this->get_system_type($attrs);
905       $ui = get_userinfo();
906       $tabs = array(
907           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
908           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
909           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
910           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
911           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
912           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
913           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
914           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
915           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
917       /* get object type */
918       $tabtype  = "termtabs";
919       $tabobj   = "TERMTABS";
920       $tabacl   = "";
921       if(isset($tabs[$type])){
922         $tabtype = $tabs[$type]['TABCLASS'];
923         $tabobj  = $tabs[$type]['CLASS'];
924         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
925       }
927       /* Load permissions for selected 'dn' and check if
928          we're allowed to remove this 'dn' */
929       if(preg_match("/d/",$tabacl)){ 
931         /* Check locking, save current plugin in 'back_plugin', so
932            the dialog knows where to return. */
933         if (($user= get_lock($this->dn)) != ""){
934           return(gen_locked_message ($user, $this->dn));
935         }
937         /* Lock the current entry, so nobody will edit it during deletion */
938         add_lock ($this->dn, $this->ui->dn);
939         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
940         $smarty->assign("multiple", false);
941         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
942       } else {
944         /* Obviously the user isn't allowed to delete. Show message and
945            clean session. */
946         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
947       }
948     }
951     /********************
952       Delete system, confirmed
953      ********************/
954     /* Confirmation for deletion has been passed. Terminal should be deleted. */
955     if (isset($_POST['delete_terminal_confirm'])){
957       /* Find out more about the object type */
958       $ldap= $this->config->get_ldap_link();
959       $ldap->cat($this->dn, array('objectClass'));
960       $attrs= $ldap->fetch();
961       $type= $this->get_system_type($attrs);
963       $ui = get_userinfo();
965       $tabs = array(
966           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
967           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
968           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
969           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
970           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
971           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
972           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
973           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
974           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
976       /* get object type */
977       $tabtype  = "termtabs";
978       $tabobj   = "TERMTABS";
979       $tabacl   = "";
980       if(isset($tabs[$type])){
981         $tabtype = $tabs[$type]['TABCLASS'];
982         $tabobj  = $tabs[$type]['CLASS'];
983         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
984       }
986       /* Check if we are allowed to remove this object */
987       if(preg_match("/d/",$tabacl)){
989         /* Delete request is permitted, perform LDAP action */
990         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
991           $this->systab= new termgeneric($this->config, $this->dn);
992           $this->systab->set_acl_base($this->dn);
993           $this->systab->remove_from_parent();
994         }elseif($tabtype=="phonetabs"){
995           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
996           $this->systab->set_acl_base($this->dn);
997           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
998         }else{  
999           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
1000           $this->systab->set_acl_base($this->dn);
1001           $this->systab->delete();
1002         }
1003         unset ($this->systab);
1004         $this->systab= NULL;
1006         /* Terminal list has changed, reload it. */
1007       } else {
1009         /* Normally this shouldn't be reached, send some extra
1010            logs to notify the administrator */
1011         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1012         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1013       }
1015       /* Remove lock file after successfull deletion */
1016       $this->remove_lock();
1017     }
1020     /********************
1021       Edit system type finished, check if everything went ok
1022      ********************/
1023     /* Finish user edit is triggered by the tabulator dialog, so
1024        the user wants to save edited data. Check and save at this
1025        point. */
1027     /* Dirty workaround - MSG_DIALOG - OK
1028       If a message dialog is shown and we press 'OK'
1029        then try to save again.
1030      */
1031     foreach($_POST as $name => $value){
1032       if(preg_match("/^MSG_OK/",$name)){
1033         $_POST[$this->last_action] = TRUE;
1034       }
1035     }
1037     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1039       /* If the save routine gets interrupted by a confirm dialog, 
1040           store last action so we can trigger it again after 'Ok' was pressed.
1041          (This is the case if a system gets modified while it is installing - GOsa si)
1042        */
1043       $this->last_action = ""; 
1044       if(isset($_POST['edit_finish'])){
1045         $this->last_action = "edit_finish"; 
1046       }elseif(isset($_POST['edit_apply'])){
1047         $this->last_action = "edit_apply";
1048       }
1050       /* Check tabs, will feed message array */
1051       $message = $this->systab->check();
1053       /* Save, or display error message? */
1054       if (count($message) == 0){
1057         $this->systab->save();
1059         /* Terminal has been saved successfully, remove lock from LDAP. */
1060         if (!isset($_POST['edit_apply'])){
1061           if ($this->dn != "new"){
1062             $this->remove_lock();
1063           }
1065           unset ($this->systab);
1066           $this->systab= NULL;
1067           session::un_set('objectinfo');
1068         }else{
1069       
1070           /* Reinitialize tab */
1071           if($this->systab instanceof tabs){
1072             $this->systab->re_init();
1073           }
1074         }
1075       } else {
1076         /* Ok. There seem to be errors regarding to the tab data,
1077            show message and continue as usual. */
1078         msg_dialog::displayChecks($message);
1079       }
1080     }
1083     /********************
1084       Edit system was canceled 
1085      ********************/
1086     /* Cancel dialogs */
1087     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1088       if (isset($this->systab)){
1089         $this->remove_lock();
1090         unset ($this->systab);
1091       }
1092       $this->systab= NULL;
1093       session::un_set('objectinfo');
1094     }
1096     /********************
1097       Display edit dialog, or some other
1098      ********************/
1100     /* Show tab dialog if object is present */
1101     if (isset($this->systab->config)){
1102       $display= $this->systab->execute();
1104       /* Don't show buttons if tab dialog requests this */
1106       $dialog     = FALSE;
1107       $hide_apply = $this->dn == "new";
1108       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1109       if(is_object($this->systab) && !isset($this->systab->by_object)){
1110         $dialog = TRUE;
1111         $hide_apply = TRUE;
1112       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1113         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1114         if($dia === TRUE || is_object($dia)){
1115           $dialog = TRUE;
1116         }  
1117       }
1118       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1119         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1120         $dialog = TRUE;
1121       }
1123       if (!$dialog){
1124         $display.= "<p style=\"text-align:right\">\n";
1125         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1126         $display.= "&nbsp;\n";
1127         if (!$hide_apply){
1128           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1129           $display.= "&nbsp;\n";
1130         }
1131         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1132         $display.= "</p>";
1133       }
1134       return ($display);
1135     }
1137     /* Check if there is a snapshot dialog open */
1138     $base = $this->DivListSystem->selectedBase;
1139     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1140       return($str);
1141     }
1143     /* Display dialog with system list */
1144     $this->DivListSystem->parent = $this;
1145     $this->DivListSystem->execute();
1147     /* Add departments if subsearch is disabled */
1148     if(!$this->DivListSystem->SubSearch){
1150       /* Add FAIstate to attributes if FAI is activated */
1151       if($this->fai_activated){
1152         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1153       }else{
1154         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1155       }
1156     }
1157     $this->reload();
1158     $this->DivListSystem->setEntries($this->terminals);
1159     return($this->DivListSystem->Draw());
1160   }
1163   /* Return departments, that will be included within snapshot detection */
1164   function get_used_snapshot_bases()
1165   {
1166     $tmp = array();
1168     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1170     $tabs = array(
1171         "terminal"        => get_ou('terminalou'),
1172         "workstation"     => get_ou('workstationou'),
1173         "incoming"        => get_ou('incomingou'),
1174         "server"          => get_ou('serverou'),
1175         "printer"         => get_ou('printerou'),
1176         "phone"           => get_ou('phoneou'),
1177         "winworkstation"  => get_winstations_ou(),
1178         "component"       => get_ou('componentou')
1179         ); 
1181     foreach($tabs as $acl_cat => $dn){
1183       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1184       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1185         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1186       }
1187     }
1188     return($tmp); 
1189   }
1192   function remove_from_parent()
1193   {
1194     /* Optionally execute a command after we're done */
1195     $this->postremove();
1196   }
1199   /* Save data to object */
1200   function save_object()
1201   {
1202     $this->DivListSystem->save_object();
1203     if(is_object($this->CopyPasteHandler)){
1204       $this->CopyPasteHandler->save_object();
1205     }
1206   }
1209   /* Check values */
1210   function check()
1211   {
1212   }
1215   /* Save to LDAP */
1216   function save()
1217   {
1218   }
1220   function adapt_from_template($dn, $skip= array())
1221   {
1222   }
1224   function password_change_needed()
1225   {
1226   }
1228   function reload()
1229   {
1230     /* some var init */
1231     $ui = get_userinfo();
1232     $res              = array();
1233     $this->terminals  = array();
1234     $userregex        = "";
1236     /* Set base for all searches */
1237     $base=  $this->DivListSystem->selectedBase;
1239     /* Prepare samba class name */
1240     $samba  ="";
1241     if ($this->DivListSystem->ShowWinWorkstations){
1242       if ($this->config->current['SAMBAVERSION'] == "3"){
1243         $samba= "sambaSamAccount";
1244       } else {
1245         $samba= "sambaAccount";
1246       }
1247     }
1249     /* This array represents the combination between checkboxes and search filters */
1250     $objs = array( 
1251         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1252         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1253         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1254         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1255         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1256         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1257         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1259     /* Include the 'Display Systems of user' attribute */ 
1260     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1261       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1262     }
1264     /* Attributes to fetch */
1265     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1266     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1268     /* Add FAIstate to attributes if FAI is activated */
1269     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1270     if(!empty($tmp)){
1271       $sys_attrs[] = "FAIstate";
1272     }    
1274     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1275     foreach($objs as $checkBox => $oc){
1276       if($this->DivListSystem->$checkBox){
1277         if($this->DivListSystem->SubSearch){
1278           if($oc['CLASS'] != ""){
1279             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1280             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1281             $res = array_merge($res,$new_res);
1282           }
1283         }else{
1284           /* User filter? */
1285           if($oc['CLASS'] != ""){
1286             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1287             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1288           }
1289         }
1290       } 
1291     }
1293     /* Search for incoming objects */ 
1294     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1295     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1297     /* Get all gotoTerminal's */
1298     foreach ($res as $value){
1300       $tmp= $value['dn'];
1301       $add= "";
1303       /* Extract base */
1304       foreach($objs as $obj){
1305         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1306           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1307         }
1308       }
1310       /* Create a string containing the last part of the department. */
1311       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1312       if(empty($dn_name)){
1313         $dn_name = "/";
1314       }
1316       /* check if current object is a new one */
1317       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1318         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1319           $add= "- "._("New terminal");
1320         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1321           $add= "- "._("New workstation");
1322         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1323           $add= "- "._("Unknown device");
1324         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1325           $add= "- "._("New Device");
1326         }
1327       } 
1329       /* Detect type of object and create an entry for $this->terminals */
1330       $terminal = array();
1331       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1333         /* check acl */
1334         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1335         if($add != "" || preg_match("/r/",$acl)) {
1336           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1337             $terminal             = $value;
1338             $terminal['type']     = "T";
1339             $terminal['is_new']   = $add;
1340           } else {
1341             $terminal             = $value;
1342             $terminal['type']     = "D";
1343             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1344             $terminal['location'] = array_search($tmp, $this->config->departments); 
1345           }
1346         }
1347       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1349         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1350         if($add != "" || preg_match("/r/",$acl)) {
1351           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1352             $terminal             = $value;
1353             $terminal['type']     = "L";
1354             $terminal['is_new']   = $add;
1355           } else {
1356             $terminal             = $value;
1357             $terminal['type']     = "D";
1358             $terminal['location'] = array_search($tmp, $this->config->departments);
1359             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1360           }
1361 #          if (isset($value["FAIstate"][0])){
1362 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1363 #          }
1364         }
1365       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1366        
1367    
1368         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1369         if($add != "" || preg_match("/r/",$acl)) {
1371           $terminal             = $value;
1372           $terminal['type']     = "P";
1373         }
1374       } elseif (in_array_ics('goServer', $value["objectClass"])){
1376         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1377         if($add != "" || preg_match("/r/",$acl)) {
1379           $terminal             = $value;
1380           $terminal['type']     = "S";
1381 #          if (isset($value["FAIstate"][0])){
1382 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1383 #          }
1384         }
1385       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1387         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1388         if($add != "" || preg_match("/r/",$acl)) {
1390           $terminal             = $value;
1391           $terminal['type']     = "F";
1392         }
1393       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1395         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1396                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1397                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1398         if($add != "" || preg_match("/r/",$acl)) {
1400           $terminal = $value;
1401           $terminal['type']   = "Q";
1402           $terminal['is_new'] = $add;
1403         }
1404       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1406         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1407         if($add != "" || preg_match("/r/",$acl)) {
1409           $terminal             = $value;
1410           $terminal['type']     = "C";
1411         }
1412       } else{
1414         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1415         if (isset($value['sambaDomainName'])){
1416           $domain= " [".$value['sambaDomainName'][0]."]";
1417         } else {
1418           $domain= "";
1419         }
1420         $terminal=$value;
1421         $terminal['type']     ="W";
1422         $terminal['domain']   = $name.$domain;
1423       }
1425       if(count($terminal)){
1426         $this->terminals[]=$terminal;
1427       }
1428     }
1430     $tmp  =array();
1431     $tmp2 =array();
1432     foreach($this->terminals as $tkey => $val ){
1433       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1434       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1435     }
1436     natcasesort($tmp2);
1437     $this->terminals=array();
1438     foreach($tmp2 as $val){
1439       $this->terminals[]=$tmp[$val];
1440     }
1441     reset ($this->terminals);
1442   }
1444   function remove_lock()
1445   {
1446     if (isset($this->systab->dn)){
1447       del_lock ($this->systab->dn);
1448     }
1449     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1450       del_lock($this->dn);
1451     }
1452     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1453       del_lock($this->dns);
1454     }
1455   }
1458   function copyPasteHandling_from_queue($s_action,$s_entry)
1459   {
1460     /* Check if Copy & Paste is disabled */
1461     if(!is_object($this->CopyPasteHandler)){
1462       return("");
1463     }
1466     $tabs = array(
1467         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1468           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1469         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1470           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1471         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1472           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1473         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1474           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1475         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1476           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1477         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1478           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1480     /* Add a single entry to queue */
1481     if($s_action == "cut" || $s_action == "copy"){
1483       /* Cleanup object queue */
1484       $this->CopyPasteHandler->cleanup_queue();
1485       $dn     = $this->terminals[$s_entry]['dn'];
1486       $oc     = $this->terminals[$s_entry]['objectClass'];
1487       $type   = $this->get_system_type($this->terminals[$s_entry]);
1489       $tab_o  = $tabs[$type]['CLASS'];
1490       $tab_c  = $tabs[$type]['TABCLASS'];
1491       $acl    = $tabs[$type]['ACL'];
1493       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1494     }
1496     /* Add entries to queue */
1497     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1499       /* Cleanup object queue */
1500       $this->CopyPasteHandler->cleanup_queue();
1502       /* Add new entries to CP queue */
1503       foreach($this->list_get_selected_items() as $id){
1504         $dn = $this->terminals[$id]['dn'];
1505         $oc = $this->terminals[$id]['objectClass']; 
1506         $type = $this->get_system_type($this->terminals[$id]);
1508         if(isset($tabs[$type])){
1509           $tab_o  = $tabs[$type]['CLASS'];
1510           $tab_c  = $tabs[$type]['TABCLASS'];
1511           $acl    = $tabs[$type]['ACL'];
1513           if($s_action == "copy_multiple"){
1514             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1515           }
1516           if($s_action == "cut_multiple"){
1517             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1518           }
1519         }
1520       }
1521     }
1523     /* Start pasting entries */
1524     if($s_action == "editPaste"){
1525       $this->start_pasting_copied_objects = TRUE;
1526     }
1527   
1528     /* Return C&P dialog */
1529     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1531       /* Get dialog */
1532       $data = $this->CopyPasteHandler->execute();
1533       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1535       /* Return dialog data */
1536       if(!empty($data)){
1537         return($data);
1538       }
1539     }
1541     /* Automatically disable status for pasting */
1542     if(!$this->CopyPasteHandler->entries_queued()){
1543       $this->start_pasting_copied_objects = FALSE;
1544     }
1545     return("");
1546   }
1549   function get_system_type($attrs)
1550   {
1551     $classes = $attrs['objectClass'];
1553     $type= "";
1554     if (in_array_ics('ieee802Device', $classes)){
1555       $type= "component";
1556     }elseif (in_array_ics('gotoTerminal', $classes)){
1557       $type= "terminal";
1558     }elseif (in_array_ics('gotoWorkstation', $classes)){
1559       $type= "workstation";
1560     }elseif (in_array_ics('gotoPrinter', $classes)){
1561       $type= "printer";
1562     }elseif (in_array_ics('goFonHardware', $classes)){
1563       $type= "phone";
1564     }elseif (in_array_ics('goServer', $classes)){
1565       $type= "server";
1566     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1567       $type= "ArpNewDevice";
1568     }elseif (in_array_ics('GOhard', $classes)){
1569       $type= "NewDevice";
1570     }elseif (in_array_ics('sambaAccount', $classes) ||
1571         in_array_ics('sambaSamAccount', $classes)){
1572       $type= "winstation";
1573     }
1574     return ($type);
1575   }
1578   function convert_list($input)
1579   {
1580     $temp= "";
1582     $conv= array(
1583         "D" => array("select_default.png",_("Template")),
1584         "F" => array("select_phone.png",_("Phone")),
1585         "C" => array("select_component.png",_("Network device")),
1586         "P" => array("select_printer.png",_("Printer")),
1588         "W" => array("select_winstation.png",_("Win workstation")),
1590         "L" => array("select_workstation.png",_("Workstation")),
1591         "S" => array("select_server.png",_("Server")),
1592         "T" => array("select_terminal.png",_("Terminal")),
1594         "LX" => array("workstation_locked.png",_("Locked workstation")),
1595         "SX" => array("server_locked.png",_("Locked server")),
1596         "TX" => array("terminal_locked.png",_("Locked terminal")),
1598         "LE" => array("workstation_error.png",_("Workstation error")),
1599         "SE" => array("server_error.png",_("Server error")),
1600         "TE" => array("terminal_error.png",_("Terminal error")),
1602         "LB" => array("workstation_busy.png",_("Workstation busy")),
1603         "SB" => array("server_busy.png",_("Server busy")),
1605         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1606         "NT"=> array("select_new_terminal.png",_("New terminal")),
1607         "NL"=> array("select_new_workstation.png",_("New workstation")));
1609     /* Use locked icons 
1610      */
1611     if( in_array($input['type'],array("S","T","L")) && 
1612         isset($input['gotoMode'][0]) && 
1613         preg_match("/locked/",$input['gotoMode'][0])){
1614       $input['type'].="X";
1615     } elseif(in_array($input['type'],array("S","L")) &&
1616         isset($input['FAIstate'][0])){
1618     /* Add FAI state icons 
1619      */
1620       $type= "";
1621       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1622         case 'error':
1623           $type= 'E';
1624           break;
1625         case 'installing':
1626         case 'install':
1627         case 'sysinfo':
1628         case 'softupdate':
1629         case 'scheduledupdate':
1630           $type= 'B';
1631           break;
1632       }
1634       $input['type'].= $type;
1635     }   
1637     /* Use new images if object is from incoming 
1638      */
1639     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1640       $input['type']="N".$input['type'];
1641     }
1643     /* Check which flags this objects uses 
1644      */
1645     foreach ($conv  as $key => $value){
1646       $found = TRUE;
1647       if(strlen($key) != strlen($input['type'])) {
1648         $found = FALSE;
1649       }
1650       for($i = 0 ; $i < strlen($key) ; $i++){
1651         if(!preg_match("/".$key[$i]."/",$input['type'])){
1652           $found = FALSE;
1653         }
1654       }
1656       if($found){
1657         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1658         $tmp['class']=$key;
1659         return $tmp;
1660       }
1661     }
1662   }
1665   function list_get_selected_items()
1666   {
1667     $ids = array();
1668     foreach($_POST as $name => $value){
1669       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1670         $id   = preg_replace("/^item_selected_/","",$name);
1671         $ids[$id] = $id;
1672       }
1673     }
1674     return($ids);
1675   }
1678   /* !! Incoming dummy acls, required to defined acls for incoming objects
1679    */
1680   static function plInfo()
1681   {
1682     return (array(
1683           "plShortName"   => _("Incoming objects"),
1684           "plDescription" => _("Incoming objects"),
1685           "plSelfModify"  => FALSE,
1686           "plDepends"     => array(),
1687           "plPriority"    => 99,
1688           "plSection"     => array("administration"),
1689           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1690                                                           "objectClass"  => "")),
1691           "plProvidedAcls"=> array()
1692             
1693           ));
1694   }
1697   
1701 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1702 ?>