Code

Updated system mangement.
[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;
41   function systems (&$config, $ui)
42   {
43     /* Save configuration for internal use */
44     $this->config= $config;
45     $this->ui= $ui;
47     /* Creat dialog object */
48     $this->DivListSystem = new divListSystem($this->config,$this);
50     /* Copy & Paste enabled ?*/
51     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
52       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
53     }
55     /* Check whether the arp handling active or not */
56     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
57       $this->arp_handling_active = TRUE;
58     }
60   }
63   function execute()
64   {
65     /* Call parent execute */
66     plugin::execute();
68     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
70     /********************
71       Check for functional posts, edit|delete|add|... system devices 
72      ********************/
73     $s_action     = "";                       // Contains the action to proceed
74     $s_entry      = "";                       // The value for s_action
75     $base_back    = "";                       // The Link for Backbutton
76     $smarty       = get_smarty();
78     /* Test Posts */
79     foreach($_POST as $key => $val){
80       // Post for delete
81       if(preg_match("/system_del.*/",$key)){
82         $s_action = "del";
83         $s_entry  = preg_replace("/system_del_/i","",$key);
84         // Post for edit
85       }elseif(preg_match("/system_edit_.*/",$key)){
86         $s_action="edit";
87         $s_entry  = preg_replace("/system_edit_/i","",$key);
88         // Post for new
89       }elseif(preg_match("/system_new.*/",$key)){
90         $s_action="new";
91       }elseif(preg_match("/system_tplnew.*/i",$key)){
92         $s_action="new_tpl";
93       }elseif(preg_match("/system_setpwd_.*/i",$key)){
94         $s_action="change_pw";
95         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
96       }elseif(preg_match("/gen_cd_.*/i",$key)){
97         $s_action="gen_cd";
98         $s_entry  = preg_replace("/gen_cd_/i","",$key);
99       }elseif(preg_match("/^copy_.*/",$key)){
100         $s_action="copy";
101         $s_entry  = preg_replace("/^copy_/i","",$key);
102       }elseif(preg_match("/^cut_.*/",$key)){
103         $s_action="cut";
104         $s_entry  = preg_replace("/^cut_/i","",$key);
105       }
106     }
107    
108     /* Incoming handling  
109      * If someone made a systemtype and ogroup selection 
110      * Display the new requested entry type ... servtab  in case of server and so on.
111      */
112     if(isset($_POST['SystemTypeChoosen'])){
113       $SelectedSystemType = session::get('SelectedSystemType');
114       $s_action = "SelectedSystemType";
115       $s_entry  = $_POST['SystemType'];
116       $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
117       $this->systab = NULL;
118       session::set('SelectedSystemType',$SelectedSystemType);
119     }
121     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
122     $s_entry  = preg_replace("/_.$/","",$s_entry);
124     /* Edit was requested by pressing the name(link) of an item */
125     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
126       $s_action ="edit";
127       $s_entry  = $_GET['id'];
128     }
129     /* Create options */
130     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
131       $s_action = "newsystem";
132       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
133     }
135     /* handle C&P from layers menu */
136     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
137       $s_action = "copy_multiple";
138     }
139     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
140       $s_action = "cut_multiple";
141     }
142     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
143       $s_action = "editPaste";
144     }
146     /* Handle daemon events */
147     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
148       $s_action = $_POST['menu_action'];
149     }
150     
151     /* Handle daemon events */
152     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
153       $s_action = $_POST['menu_action'];
154     }
156     /* handle remove from layers menu */
157     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
158       $s_action = "del_multiple";
159     }
160     
161     /* Handle instant actions from layers menu */
162     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
163             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
164               $s_action = "${act}_multiple";
165             }
166     }
168     /* Check for exeeded sizelimit */
169     if (($message= check_sizelimit()) != ""){
170       return($message);
171     }
173     /* Try to get informations about what kind of system to create */
174     if ($s_action=="new") {
175       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
176     }
179     /********************
180       Copy & Paste Handling  ...
181      ********************/
183     /* Display the copy & paste dialog, if it is currently open */
184     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
185     if($ret){
186       return($ret);
187     }
188   
190     /********************
191       Create FAI CD ...   
192      ********************/
193     if ($s_action=="gen_cd"){
194       $this->dn= $this->terminals[$s_entry]['dn'];
195       session::set('objectinfo',$this->dn);
196       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
197     }
200     /* Start CD-Creation */
201     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
202       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
203       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
204     }
207     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
209       $return_button   = "<form method='get' action='main.php' target='_parent'>
210         <input type='submit' value='"._("Back")."'>
211         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
212         </form>";
214       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
216       /* Get and check command */
217       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
218       
219       if (check_command($command)){
220         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
222         /* Print out html introduction */
223         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
224           <html>
225           <head>
226           <title></title>
227           <style type="text/css">@import url("themes/default/style.css");</style>
228           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
229           </head>
230           <body style="background: none; margin:4px;" id="body" >
231           <pre>';
233         /* Open process handle and check if it is a valid process */
234         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
235         if (is_resource($process)) {
236           fclose($pipes[0]);
238           /* Print out returned lines && write JS to scroll down each line */
239           while (!feof($pipes[1])){
240             $cur_dat = fgets($pipes[1], 1024);
241             echo $cur_dat;
242             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
243             flush();
244           }
245         }
247         /* Get error string && close streams */
248         $buffer= stream_get_contents($pipes[2]);
250         fclose($pipes[1]);
251         fclose($pipes[2]);
252         echo "</pre>";
254         /* Check return code */
255         $ret= proc_close($process);
256         if ($ret != 0){
257           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
258           echo "<pre style='color:red'>$buffer</pre>";
259         }
263         echo $return_button."<br>";
265       } else {
266         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
267         echo $tmp;
268       }
270       /* Scroll down completly */
271       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
272       echo '</body></html>';
273       flush();
274       exit;
275     }
278     /********************
279       Create new system ...   
280      ********************/
281     /* Create new default terminal 
282      * Or create specified object of selected system type, from given incoming object  
283      */
285     $save_object_directly = false;
286     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
287       $save_object_directly = true;
288     }
290     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
292       /* If the current entry is an incoming object 
293        * $sw = System type as posted in new incoming handling dialog 
294        */ 
295       if($s_action == "SelectedSystemType") {
296         $sw         = $s_entry;
297       }else{
298         if(isset($_POST['system'])){
299           $sw = $_POST['system'];
300         }else{
301           $sw = $s_entry;
302         }
303         $this->dn= "new";
304       }
306       $tabs = array(
307           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
308           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
309           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
310           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
311           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
312           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
314       if(isset($tabs[$sw])){
315         $class    = $tabs[$sw]["CLASS"];
316         $tabname  = $tabs[$sw]["TABNAME"];
317         $tabclass = $tabs[$sw]["TABCLASS"];
318         $acl_cat  = $tabs[$sw]["ACL"];
320         /* Load permissions for selected 'dn' and check if
321            we're allowed to remove this 'dn' */
322         $ui       = get_userinfo();
323         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
324         if(preg_match("/c/",$tabacl)){
325           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
326           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
327           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
328           $this->systab->base = $this->DivListSystem->selectedBase;
329         }else{
330           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
331         }
332       }
333     }
335     /********************
336       Edit system ...   
337      ********************/
339     /* User wants to edit data? */
340     if (($s_action == "edit") && (!isset($this->systab->config))){
342       $this->dn= $this->terminals[$s_entry]['dn'];
344       /* Check locking, save current plugin in 'back_plugin', so
345          the dialog knows where to return. */
346       if (($user= get_lock($this->dn)) != ""){
347         return(gen_locked_message ($user, $this->dn));
348       }
350       /* Find out more about the object type */
351       $ldap= $this->config->get_ldap_link();
352       $ldap->cat($this->dn, array('objectClass','gotoMode'));
353       $attrs= $ldap->fetch();
354       $type= $this->get_system_type($attrs);
356       /* Lock the current entry, so everyone will get the
357          above dialog */
358       $tabs = array(
359           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
360           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
361           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
362           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
363           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
364           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
365           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
368       if($type == "ArpNewDevice"){
369         $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
370       }elseif($type == "NewDevice"){
371         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
372       }elseif(isset($tabs[$type])){
374         $class    = $tabs[$type]["CLASS"];
375         $acl_cat  = $tabs[$type]["ACL"];
376         $tabclass = $tabs[$type]["TABCLASS"];
378         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
379         $this->systab->set_acl_base($this->dn);
380         session::set('objectinfo',$this->dn);
381         add_lock ($this->dn, $this->ui->dn);
382       }else{ 
383         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
384         del_lock($this->dn);
385       }
386     }
389     /********************
390       Change password ...   
391      ********************/
393     /* Set terminals root password */
394     if ($s_action=="change_pw"){
395       $tabs = array(
396           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
397           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
399       $type = $this->get_system_type($this->terminals[$s_entry]);
400       $class    = $tabs[$type]["CLASS"];
401       $tabname  = $tabs[$type]["TABNAME"];
402       $acl_cat  = $tabs[$type]["ACL"];
403       $tabclass = $tabs[$type]["TABCLASS"];
404       $ui       = get_userinfo();
405       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
406       if(preg_match("/w/",$tabacl)){
407         $this->dn= $this->terminals[$s_entry]['dn'];
408         session::set('objectinfo',$this->dn);
409         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
410       }else{
411         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
412       }
413     }
416     /********************
417       Password change finish, but check if entered data is ok 
418      ********************/
420     /* Correctly specified? */
421     if (isset($_POST['password_finish'])){
422       if ($_POST['new_password'] != $_POST['repeated_password']){
423         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
424         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
425       }
426     }
428     /********************
429       Password change finish
430      ********************/
432     /* Change terminal password */
433     if (isset($_POST['password_finish']) && 
434         $_POST['new_password'] == $_POST['repeated_password']){
436       /* Check if user is allowed to set password */
437       $tabs = array(
438           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
439           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
441       /* Detect object type */
442       $type = "";
443       foreach($this->terminals as $terminal){
444         if($terminal['dn'] == $this->dn){
445           $type = $this->get_system_type($terminal);
446           break;
447         } 
448       }
450       /* Type detected */
451       if(!empty($type)){
453         /* Get infos */
454         $class    = $tabs[$type]["CLASS"];
455         $tabname  = $tabs[$type]["TABNAME"];
456         $acl_cat  = $tabs[$type]["ACL"];
457         $tabclass = $tabs[$type]["TABCLASS"];
458     
459         /* Get acls */
460         $ui       = get_userinfo();
461         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
463         /* Check acls */
464         if(preg_match("/w/",$tabacl)){
465           $ldap = $this->config->get_ldap_link();
466           $ldap->cd($this->dn);
468           $attrs= array();
469           if ($_POST['new_password'] == ""){
470             $attrs['gotoRootPasswd']= array();
471           } else {
472             $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
473           }
474           $ldap->modify($attrs);
475           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
476         }else{
477           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
478         }
479       }else{
480         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
481       }
482       session::un_set('objectinfo');
483     }
486     /********************
487       Delete system cancel
488      ********************/
490     /* Delete terminal canceled? */
491     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
492       del_lock ($this->dn);
493       session::un_set('objectinfo');
494     }
497     /********************
498       Action(s) for MULTIPLE
499      ********************/
501     /********************
502       SCHEDULE action in GOsa Daemon
503      ********************/
505     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
506       $this->dns = array();
507       $ids = $this->list_get_selected_items();
509       if(count($ids)){
510         $mac= array();
512         $ldap = $this->config->get_ldap_link();
513         foreach($ids as $id){
514           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
515           $attrs= $ldap->fetch();
516           if (isset($attrs['macAddress'][0])){
517             $mac[]= $attrs['macAddress'][0];
518           }
519         }
520         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
521         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
522         $o_queue = new gosaSupportDaemon();
524         /* Skip installation or update trigerred events, 
525          *  if this entry is currently processing.
526          */
527         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
528           foreach($mac as $key => $mac_address){
529             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
531               $entry['STATUS'] = strtoupper($entry['STATUS']);
532               if($entry['STATUS'] == "PROCESSING" && 
533                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
534                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
535                 unset($mac[$key]);
537                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
538                 break;
539               }
540             }
541           }
542         }        
544         /* Prepare event to be added 
545          */
546         if(count($mac) && isset($events['BY_CLASS'][$type])){
547           $event = $events['BY_CLASS'][$type];
548           $this->systab = new $event['CLASS_NAME']($this->config);
549           $this->systab->add_targets($mac);
550           if(preg_match("/trigger_event/",$s_action)){
551             $this->systab->set_type(TRIGGERED_EVENT);
552           }else{
553             $this->systab->set_type(SCHEDULED_EVENT);
554           }
555         }
556       }
557     }
559     /* Insert scheduled events into queue */
560     if($this->systab instanceof DaemonEvent){
561       $this->systab->save_object();
563       /* Save event 
564        */
565       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
566         $o_queue = new gosaSupportDaemon();
567         $o_queue->append($this->systab);
568         if($o_queue->is_error()){
569           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
570         }else{
571           $this->systab = FALSE;
572         }
573       }
574       if(isset($_POST['abort_event_dialog'])){
575         $this->systab = FALSE;
576       }
577     }
580     /********************
581       Delete MULTIPLE entries requested, display confirm dialog
582      ********************/
584     if ($s_action=="del_multiple"){
585       $this->dns = array();
586       $ids = $this->list_get_selected_items();
588       if(count($ids)){
590         foreach($ids as $id){
591           $dn = $this->terminals[$id]['dn'];
592           $this->dns[$id] = $dn;
593         }
594         if ($user= get_multiple_locks($this->dns)){
595           return(gen_locked_message($user,$this->dns));
596         }
598         $dns_names = array();
599         foreach($this->dns as $dn){
600           add_lock ($dn, $this->ui->dn);
601           $dns_names[] = @LDAP::fix($dn);
602         }
604         /* Lock the current entry, so nobody will edit it during deletion */
605         $smarty->assign("warning", msgPool::deleteInfo($dns_names));
606         $smarty->assign("multiple", true);
607         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
608       }
609     }
612     /********************
613       Delete MULTIPLE entries confirmed
614      ********************/
616     /* Confirmation for deletion has been passed. Users should be deleted. */
617     if (isset($_POST['delete_multiple_system_confirm'])){
619       $ui = get_userinfo();
620       $tabs = array(
621           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
622           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
623           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
624           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
625           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
626           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
627           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
628           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
629           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
632       /* Remove user by user and check acls before removeing them */
633       foreach($this->dns as $key => $dn){
635         /* Get 'dn' from posted termlinst */
636         $attrs    = $this->terminals[$key];
637         $type= $this->get_system_type($attrs);
639         /* get object type */
640         $tabtype  = "termtabs";
641         $tabobj   = "TERMTABS";
642         $tabacl   = "";
643         if(isset($tabs[$type])){
644           $tabtype = $tabs[$type]['TABCLASS'];
645           $tabobj  = $tabs[$type]['CLASS'];
646           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
648           /* Load permissions for selected 'dn' and check if
649              we're allowed to remove this 'dn' */
650           if(preg_match("/d/",$tabacl)){ 
652             /* Delete request is permitted, perform LDAP action */
653             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
654               $this->systab= new termgeneric($this->config, $dn);
655               $this->systab->set_acl_base($dn);
656               $this->systab->remove_from_parent();
657             }elseif($tabtype=="phonetabs"){
658               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
659               $this->systab->set_acl_base($dn);
660               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
661             }else{
662               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
663               $this->systab->set_acl_base($dn);
664               $this->systab->delete();
665             }
666             unset ($this->systab);
667             $this->systab= NULL;
669           } else {
670             /* Normally this shouldn't be reached, send some extra
671                logs to notify the administrator */
672             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
673             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
674           }
675           /* Remove lock file after successfull deletion */
676           del_lock ($dn);
677           unset($this->dns[$key]);
678         }
679       }
680     }
682     /********************
683       Delete MULTIPLE entries Canceled
684      ********************/
686     /* Remove lock */
687    if(isset($_POST['delete_multiple_system_cancel'])){
688       foreach($this->dns as $key => $dn){
689         del_lock ($dn);
690         unset($this->dns[$key]);
691       }
692     }
695     /********************
696       Delete system, confirm dialog
697      ********************/
699     /* Remove terminal was requested */
700     if ($s_action=="del"){
702       /* Get 'dn' from posted termlinst */
703       $this->dn = $this->terminals[$s_entry]['dn'];
704       $attrs    = $this->terminals[$s_entry];
706   
708       $type= $this->get_system_type($attrs);
709       $ui = get_userinfo();
710       $tabs = array(
711           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
712           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
713           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
714           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
715           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
716           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
717           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
718           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
719           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
721       /* get object type */
722       $tabtype  = "termtabs";
723       $tabobj   = "TERMTABS";
724       $tabacl   = "";
725       if(isset($tabs[$type])){
726         $tabtype = $tabs[$type]['TABCLASS'];
727         $tabobj  = $tabs[$type]['CLASS'];
728         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
729       }
731       /* Load permissions for selected 'dn' and check if
732          we're allowed to remove this 'dn' */
733       if(preg_match("/d/",$tabacl)){ 
735         /* Check locking, save current plugin in 'back_plugin', so
736            the dialog knows where to return. */
737         if (($user= get_lock($this->dn)) != ""){
738           return(gen_locked_message ($user, $this->dn));
739         }
741         /* Lock the current entry, so nobody will edit it during deletion */
742         add_lock ($this->dn, $this->ui->dn);
743         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
744         $smarty->assign("multiple", false);
745         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
746       } else {
748         /* Obviously the user isn't allowed to delete. Show message and
749            clean session. */
750         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
751       }
752     }
755     /********************
756       Delete system, confirmed
757      ********************/
758     /* Confirmation for deletion has been passed. Terminal should be deleted. */
759     if (isset($_POST['delete_terminal_confirm'])){
761       /* Find out more about the object type */
762       $ldap= $this->config->get_ldap_link();
763       $ldap->cat($this->dn, array('objectClass'));
764       $attrs= $ldap->fetch();
765       $type= $this->get_system_type($attrs);
767       $ui = get_userinfo();
769       $tabs = array(
770           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
771           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
772           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
773           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
774           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
775           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
776           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
777           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
778           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
780       /* get object type */
781       $tabtype  = "termtabs";
782       $tabobj   = "TERMTABS";
783       $tabacl   = "";
784       if(isset($tabs[$type])){
785         $tabtype = $tabs[$type]['TABCLASS'];
786         $tabobj  = $tabs[$type]['CLASS'];
787         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
788       }
790       /* Check if we are allowed to remove this object */
791       if(preg_match("/d/",$tabacl)){
793         /* Delete request is permitted, perform LDAP action */
794         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
795           $this->systab= new termgeneric($this->config, $this->dn);
796           $this->systab->set_acl_base($this->dn);
797           $this->systab->remove_from_parent();
798         }elseif($tabtype=="phonetabs"){
799           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
800           $this->systab->set_acl_base($this->dn);
801           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
802         }else{  
803           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
804           $this->systab->set_acl_base($this->dn);
805           $this->systab->delete();
806         }
807         unset ($this->systab);
808         $this->systab= NULL;
810         /* Terminal list has changed, reload it. */
811       } else {
813         /* Normally this shouldn't be reached, send some extra
814            logs to notify the administrator */
815         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
816         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
817       }
819       /* Remove lock file after successfull deletion */
820       del_lock ($this->dn);
821     }
824     /********************
825       Edit system type finished, check if everything went ok
826      ********************/
827     /* Finish user edit is triggered by the tabulator dialog, so
828        the user wants to save edited data. Check and save at this
829        point. */
830     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
832       /* Check tabs, will feed message array */
833       $message = array();
834       if(!$save_object_directly){
835         $message = $this->systab->check();
836       }else{
837         $found = false;
839         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
840         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
841           if(isset($this->systab->by_object[$tab]->gotoMode)) {
842             $found = true;
843             $this->systab->by_object[$tab]->gotoMode = $value;
844           }
845         }
846         if(!$found){
847           msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
848         }
850       }
851       /* Save, or display error message? */
852       if (count($message) == 0){
854         /* Incoming behavior; you can select a system type and an ogroup membership.
855          * If this object is an Incoming object, session::get('SelectedSystemType') isset.
856          * Check if we must add the new object to an object group.
857          *
858          * If this is done, delete the old incoming entry... it is still there, because this is a new
859          * entry and not an edited one, so we will delete it.
860          *
861          */
862         if(session::is_set('SelectedSystemType')){
863           $SelectedSystemType = session::get('SelectedSystemType');
864           if($SelectedSystemType['ogroup'] != "none"){
865             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
866             if($og){
867               $og->AddDelMembership($this->systab->dn);
868               $og->save();
869             }
870           }
871         }
873         /* Save terminal data to ldap */
874         $SelectedSystemType = session::get('SelectedSystemType');
875         if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
876           foreach (array("workservice", "termservice") as $cls){
877             if (isset($this->systab->by_object[$cls])){
878               $this->systab->by_object[$cls]->gotoXMouseport= "";
879               $this->systab->by_object[$cls]->gotoXMouseType= "";
880               $this->systab->by_object[$cls]->gotoXResolution= "";
881               $this->systab->by_object[$cls]->gotoXColordepth= "";
882             }
883           }
884         }
886         $this->systab->save();
888         if(session::is_set('SelectedSystemType')){
889           session::un_set('SelectedSystemType');
890           if(!isset($ldap)){
891             $ldap = $this->config->get_ldap_link();
892           }
893           $ldap->cd ($this->dn);
894           $ldap->cat($this->dn, array('dn'));
895           if(count($ldap->fetch())){
896             $ldap->cd($this->dn);
897             $ldap->rmDir($this->dn);
898           }
899           $ldap->cd($this->config->current['BASE']);
900         }
902         /* Terminal has been saved successfully, remove lock from LDAP. */
903         if (!isset($_POST['edit_apply'])){
904           if ($this->dn != "new"){
905             del_lock ($this->dn);
906           }
908           unset ($this->systab);
909           $this->systab= NULL;
910           session::un_set('objectinfo');
911         }
912       } else {
913         /* Ok. There seem to be errors regarding to the tab data,
914            show message and continue as usual. */
915         msg_dialog::displayChecks($message);
916       }
917     }
920     /********************
921       Edit system was canceled 
922      ********************/
923     /* Cancel dialogs */
924     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
925       if (isset($this->systab)){
926         del_lock ($this->systab->dn);
927         unset ($this->systab);
928       }
929       $this->systab= NULL;
930       session::un_set('objectinfo');
932       /* Remove ogroup selection, which was set while editing a new incoming entry */
933       if(session::is_set('SelectedSystemType')){
934         session::un_set('SelectedSystemType');
935       }
936     }
938     /********************
939       Display edit dialog, or some other
940      ********************/
942     /* Show tab dialog if object is present */
943     if (isset($this->systab->config)){
944       $display= $this->systab->execute();
946       /* Don't show buttons if tab dialog requests this */
948       $dialog     = FALSE;
949       $hide_apply = $this->dn == "new";
950       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
951       if(is_object($this->systab) && !isset($this->systab->by_object)){
952         $dialog = TRUE;
953         $hide_apply = TRUE;
954       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
955         $dia = $this->systab->by_object[$this->systab->current]->dialog;
956         if($dia === TRUE || is_object($dia)){
957           $dialog = TRUE;
958         }  
959       }
960       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
961         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
962         $dialog = TRUE;
963       }
965       if (!$dialog){
966         $display.= "<p style=\"text-align:right\">\n";
967         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
968         $display.= "&nbsp;\n";
969         if (!$hide_apply){
970           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
971           $display.= "&nbsp;\n";
972         }
973         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
974         $display.= "</p>";
975       }
976       return ($display);
977     }
979     /* Check if there is a snapshot dialog open */
980     $base = $this->DivListSystem->selectedBase;
981     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
982       return($str);
983     }
985     /* Display dialog with system list */
986     $this->DivListSystem->parent = $this;
987     $this->DivListSystem->execute();
989     /* Add departments if subsearch is disabled */
990     if(!$this->DivListSystem->SubSearch){
991       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
992     }
993     $this->reload();
994     $this->DivListSystem->setEntries($this->terminals);
995     return($this->DivListSystem->Draw());
996   }
999   /* Return departments, that will be included within snapshot detection */
1000   function get_used_snapshot_bases()
1001   {
1002     $tmp = array();
1004     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1006     $tabs = array(
1007         "terminal"        => get_ou('terminalou'),
1008         "workstation"     => get_ou('workstationou'),
1009         "incoming"        => get_ou('incomingou'),
1010         "server"          => get_ou('serverou'),
1011         "printer"         => get_ou('printerou'),
1012         "phone"           => get_ou('phoneou'),
1013         "winworkstation"  => get_winstations_ou(),
1014         "component"       => get_ou('componentou')
1015         ); 
1017     foreach($tabs as $acl_cat => $dn){
1019       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1020       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1021         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1022       }
1023     }
1024     return($tmp); 
1025   }
1028   function remove_from_parent()
1029   {
1030     /* Optionally execute a command after we're done */
1031     $this->postremove();
1032   }
1035   /* Save data to object */
1036   function save_object()
1037   {
1038     $this->DivListSystem->save_object();
1039   }
1042   /* Check values */
1043   function check()
1044   {
1045   }
1048   /* Save to LDAP */
1049   function save()
1050   {
1051   }
1053   function adapt_from_template($dn)
1054   {
1055   }
1057   function password_change_needed()
1058   {
1059   }
1061   function reload()
1062   {
1063     /* some var init */
1064     $ui = get_userinfo();
1065     $res              = array();
1066     $this->terminals  = array();
1067     $userregex        = "";
1069     /* Set base for all searches */
1070     $base=  $this->DivListSystem->selectedBase;
1072     /* Prepare samba class name */
1073     $samba  ="";
1074     if ($this->DivListSystem->ShowWinWorkstations){
1075       if ($this->config->current['SAMBAVERSION'] == "3"){
1076         $samba= "sambaSamAccount";
1077       } else {
1078         $samba= "sambaAccount";
1079       }
1080     }
1082     /* This array represents the combination between checkboxes and search filters */
1083     $objs = array( 
1084         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1085         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1086         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1087         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1088         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1089         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1090         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1092     /* Include the 'Display Systems of user' attribute */ 
1093     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1094       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1095     }
1097     /* Attributes to fetch */
1098     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1099     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1101     /* Add FAIstate to attributes if FAI is activated */
1102     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1103     if(!empty($tmp)){
1104       $sys_attrs[] = "FAIstate";
1105     }    
1107     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1108     foreach($objs as $checkBox => $oc){
1109       if($this->DivListSystem->$checkBox){
1110         if($this->DivListSystem->SubSearch){
1111           if($oc['CLASS'] != ""){
1112             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1113             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1114             $res = array_merge($res,$new_res);
1115           }
1116         }else{
1117           /* User filter? */
1118           if($oc['CLASS'] != ""){
1119             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1120             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1121           }
1122         }
1123       } 
1124     }
1126     /* Search for incoming objects */ 
1127     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1128     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1130     /* Get all gotoTerminal's */
1131     foreach ($res as $value){
1133       $tmp= $value['dn'];
1134       $add= "";
1136       /* Extract base */
1137       foreach($objs as $obj){
1138         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1139           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1140         }
1141       }
1143       /* Create a string containing the last part of the department. */
1144       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1145       if(empty($dn_name)){
1146         $dn_name = "/";
1147       }
1149       /* check if current object is a new one */
1150       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1151         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1152           $add= "- "._("New terminal");
1153         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1154           $add= "- "._("New workstation");
1155         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1156           $add= "- "._("Unknown device");
1157         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1158           $add= "- "._("New Device");
1159         }
1160       } 
1162       /* Detect type of object and create an entry for $this->terminals */
1163       $terminal = array();
1164       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1166         /* check acl */
1167         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1168         if($add != "" || preg_match("/r/",$acl)) {
1169           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1170             $terminal             = $value;
1171             $terminal['type']     = "T";
1172             $terminal['is_new']   = $add;
1173           } else {
1174             $terminal             = $value;
1175             $terminal['type']     = "D";
1176             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1177             $terminal['location'] = array_search($tmp, $this->config->departments); 
1178           }
1179         }
1180       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1182         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1183         if($add != "" || preg_match("/r/",$acl)) {
1184           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1185             $terminal             = $value;
1186             $terminal['type']     = "L";
1187             $terminal['is_new']   = $add;
1188           } else {
1189             $terminal             = $value;
1190             $terminal['type']     = "D";
1191             $terminal['location'] = array_search($tmp, $this->config->departments);
1192             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1193           }
1194           if (isset($value["FAIstate"][0])){
1195             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1196           }
1197         }
1198       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1199        
1200    
1201         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1202         if($add != "" || preg_match("/r/",$acl)) {
1204           $terminal             = $value;
1205           $terminal['type']     = "P";
1206         }
1207       } elseif (in_array_ics('goServer', $value["objectClass"])){
1209         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1210         if($add != "" || preg_match("/r/",$acl)) {
1212           $terminal             = $value;
1213           $terminal['type']     = "S";
1214           if (isset($value["FAIstate"][0])){
1215             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1216           }
1217         }
1218       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1220         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1221         if($add != "" || preg_match("/r/",$acl)) {
1223           $terminal             = $value;
1224           $terminal['type']     = "F";
1225         }
1226       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1228         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1229                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1230                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1231         if($add != "" || preg_match("/r/",$acl)) {
1233           $terminal = $value;
1234           $terminal['type']   = "Q";
1235           $terminal['is_new'] = $add;
1236         }
1237       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1239         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1240         if($add != "" || preg_match("/r/",$acl)) {
1242           $terminal             = $value;
1243           $terminal['type']     = "C";
1244         }
1245       } else{
1247         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1248         if (isset($value['sambaDomainName'])){
1249           $domain= " [".$value['sambaDomainName'][0]."]";
1250         } else {
1251           $domain= "";
1252         }
1253         $terminal=$value;
1254         $terminal['type']     ="W";
1255         $terminal['domain']   = $name.$domain;
1256       }
1258       if(count($terminal)){
1259         $this->terminals[]=$terminal;
1260       }
1261     }
1263     $tmp  =array();
1264     $tmp2 =array();
1265     foreach($this->terminals as $tkey => $val ){
1266       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1267       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1268     }
1269     natcasesort($tmp2);
1270     $this->terminals=array();
1271     foreach($tmp2 as $val){
1272       $this->terminals[]=$tmp[$val];
1273     }
1274     reset ($this->terminals);
1275   }
1277   function remove_lock()
1278   {
1279     if (isset($this->systab->dn)){
1280       del_lock ($this->systab->dn);
1281     }
1282   }
1285   function copyPasteHandling_from_queue($s_action,$s_entry)
1286   {
1287     /* Check if Copy & Paste is disabled */
1288     if(!is_object($this->CopyPasteHandler)){
1289       return("");
1290     }
1293     $tabs = array(
1294         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1295           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1296         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1297           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1298         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1299           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1300         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1301           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1302         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1303           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1304         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1305           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1307     /* Add a single entry to queue */
1308     if($s_action == "cut" || $s_action == "copy"){
1310       /* Cleanup object queue */
1311       $this->CopyPasteHandler->cleanup_queue();
1312       $dn     = $this->terminals[$s_entry]['dn'];
1313       $oc     = $this->terminals[$s_entry]['objectClass'];
1314       $type   = $this->get_system_type($this->terminals[$s_entry]);
1316       $tab_o  = $tabs[$type]['CLASS'];
1317       $tab_c  = $tabs[$type]['TABCLASS'];
1318       $acl    = $tabs[$type]['ACL'];
1320       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1321     }
1323     /* Add entries to queue */
1324     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1326       /* Cleanup object queue */
1327       $this->CopyPasteHandler->cleanup_queue();
1329       /* Add new entries to CP queue */
1330       foreach($this->list_get_selected_items() as $id){
1331         $dn = $this->terminals[$id]['dn'];
1332         $oc = $this->terminals[$id]['objectClass']; 
1333         $type = $this->get_system_type($this->terminals[$id]);
1335         if(isset($tabs[$type])){
1336           $tab_o  = $tabs[$type]['CLASS'];
1337           $tab_c  = $tabs[$type]['TABCLASS'];
1338           $acl    = $tabs[$type]['ACL'];
1340           if($s_action == "copy_multiple"){
1341             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1342           }
1343           if($s_action == "cut_multiple"){
1344             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1345           }
1346         }
1347       }
1348     }
1350     /* Start pasting entries */
1351     if($s_action == "editPaste"){
1352       $this->start_pasting_copied_objects = TRUE;
1353     }
1354   
1355     /* Return C&P dialog */
1356     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1358       /* Get dialog */
1359       $data = $this->CopyPasteHandler->execute();
1360       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1362       /* Return dialog data */
1363       if(!empty($data)){
1364         return($data);
1365       }
1366     }
1368     /* Automatically disable status for pasting */
1369     if(!$this->CopyPasteHandler->entries_queued()){
1370       $this->start_pasting_copied_objects = FALSE;
1371     }
1372     return("");
1373   }
1376   function get_system_type($attrs)
1377   {
1378     $classes = $attrs['objectClass'];
1380     $type= "";
1381     if (in_array_ics('ieee802Device', $classes)){
1382       $type= "component";
1383     }elseif (in_array_ics('gotoTerminal', $classes)){
1384       $type= "terminal";
1385     }elseif (in_array_ics('gotoWorkstation', $classes)){
1386       $type= "workstation";
1387     }elseif (in_array_ics('gotoPrinter', $classes)){
1388       $type= "printer";
1389     }elseif (in_array_ics('goFonHardware', $classes)){
1390       $type= "phone";
1391     }elseif (in_array_ics('goServer', $classes)){
1392       $type= "server";
1393     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1394       $type= "ArpNewDevice";
1395     }elseif (in_array_ics('GOhard', $classes)){
1396       $type= "NewDevice";
1397     }elseif (in_array_ics('sambaAccount', $classes) ||
1398         in_array_ics('sambaSamAccount', $classes)){
1399       $type= "winstation";
1400     }
1401     return ($type);
1402   }
1405   function convert_list($input)
1406   {
1407     $temp= "";
1408     $conv= array(       
1409         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1410         "D" => array("select_default.png",_("Template")),
1411         "T" => array("select_terminal.png",_("Terminal")),
1412         "L" => array("select_workstation.png",_("Workstation")),
1413         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1414         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1415         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1416         "F" => array("select_phone.png",_("Phone")),
1417         "S" => array("select_server.png",_("Server")),
1418         "GS" => array("select_server_green.png",_("Server is installing")),
1419         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1420         "RS" => array("select_server_red.png",_("Server installation failed")),
1421         "W" => array("select_winstation.png",_("Win workstation")),
1422         "C" => array("select_component.png",_("Network device")),
1423         "NT"=> array("select_new_terminal.png",_("New terminal")),
1424         "NL"=> array("select_new_workstation.png",_("New workstation")),
1425         "P" => array("select_printer.png",_("Printer")));
1427     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1428       $input['type']="N".$input['type'];
1429     }
1430     foreach ($conv  as $key => $value){
1431       if($input['type']==$key){
1432         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1433         $tmp['class']=$key;
1434         return $tmp;
1435       }
1436     }
1437   }
1439   
1440   function getState($type, $state)
1441   {
1442     switch (preg_replace('/:.*$/', '', $state)) {
1443       case 'installing':
1444                 $type= 'G'.$type;
1445                 break;
1446       case 'error':
1447                 $type= 'R'.$type;
1448                 break;
1449       case 'install':
1450       case 'sysinfo':
1451       case 'softupdate':
1452       case 'scheduledupdate':
1453                 $type= 'Y'.$type;
1454                 break;
1455     }
1458     return ($type);
1459   }
1462   function list_get_selected_items()
1463   {
1464     $ids = array();
1465     foreach($_POST as $name => $value){
1466       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1467         $id   = preg_replace("/^item_selected_/","",$name);
1468         $ids[$id] = $id;
1469       }
1470     }
1471     return($ids);
1472   }
1475   /* !! Incoming dummy acls, required to defined acls for incoming objects
1476    */
1477   static function plInfo()
1478   {
1479     return (array(
1480           "plShortName"   => _("Incoming objects"),
1481           "plDescription" => _("Incoming objects"),
1482           "plSelfModify"  => FALSE,
1483           "plDepends"     => array(),
1484           "plPriority"    => 99,
1485           "plSection"     => array("administration"),
1486           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1487                                                           "objectClass"  => "")),
1488           "plProvidedAcls"=> array()
1489             
1490           ));
1491   }
1494   
1498 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1499 ?>