Code

Added missing class var.
[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   function systems (&$config, $ui)
45   {
46     /* Save configuration for internal use */
47     $this->config= $config;
48     $this->ui= $ui;
50     /* Creat dialog object */
51     $this->DivListSystem = new divListSystem($this->config,$this);
53     /* Copy & Paste enabled ?*/
54     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
55       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
56     }
58     /* Check whether the arp handling active or not */
59     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
60       $this->arp_handling_active = TRUE;
61     }
63   }
66   function execute()
67   {
68     /* Call parent execute */
69     plugin::execute();
71     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
73     /********************
74       Check for functional posts, edit|delete|add|... system devices 
75      ********************/
76     $s_action     = "";                       // Contains the action to proceed
77     $s_entry      = "";                       // The value for s_action
78     $base_back    = "";                       // The Link for Backbutton
79     $smarty       = get_smarty();
81     /* Test Posts */
82     foreach($_POST as $key => $val){
83       // Post for delete
84       if(preg_match("/system_del.*/",$key)){
85         $s_action = "del";
86         $s_entry  = preg_replace("/system_del_/i","",$key);
87         // Post for edit
88       }elseif(preg_match("/system_edit_.*/",$key)){
89         $s_action="edit";
90         $s_entry  = preg_replace("/system_edit_/i","",$key);
91         // Post for new
92       }elseif(preg_match("/system_new.*/",$key)){
93         $s_action="new";
94       }elseif(preg_match("/system_tplnew.*/i",$key)){
95         $s_action="new_tpl";
96       }elseif(preg_match("/system_setpwd_.*/i",$key)){
97         $s_action="change_pw";
98         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
99       }elseif(preg_match("/gen_cd_.*/i",$key)){
100         $s_action="gen_cd";
101         $s_entry  = preg_replace("/gen_cd_/i","",$key);
102       }elseif(preg_match("/^copy_.*/",$key)){
103         $s_action="copy";
104         $s_entry  = preg_replace("/^copy_/i","",$key);
105       }elseif(preg_match("/^cut_.*/",$key)){
106         $s_action="cut";
107         $s_entry  = preg_replace("/^cut_/i","",$key);
108       }
109     }
110    
111     /* Incoming handling  
112      * If someone made a systemtype and ogroup selection 
113      * Display the new requested entry type ... servtab  in case of server and so on.
114      */
115     if(isset($_POST['SystemTypeChoosen'])){
116       $SelectedSystemType = session::get('SelectedSystemType');
117       $s_action = "SelectedSystemType";
118       $s_entry  = $_POST['SystemType'];
119       $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
120       $this->systab = NULL;
121       session::set('SelectedSystemType',$SelectedSystemType);
122     }
124     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
125     $s_entry  = preg_replace("/_.$/","",$s_entry);
127     /* Edit was requested by pressing the name(link) of an item */
128     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
129       $s_action ="edit";
130       $s_entry  = $_GET['id'];
131     }
132     /* Create options */
133     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
134       $s_action = "newsystem";
135       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
136     }
138     /* handle C&P from layers menu */
139     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
140       $s_action = "copy_multiple";
141     }
142     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
143       $s_action = "cut_multiple";
144     }
145     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
146       $s_action = "editPaste";
147     }
149     /* Handle daemon events */
150     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
151       $s_action = $_POST['menu_action'];
152     }
153     
154     /* Handle daemon events */
155     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
156       $s_action = $_POST['menu_action'];
157     }
159     /* handle remove from layers menu */
160     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
161       $s_action = "del_multiple";
162     }
163     
164     /* Handle instant actions from layers menu */
165     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
166             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
167               $s_action = "${act}_multiple";
168             }
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     }
182     /********************
183       Copy & Paste Handling  ...
184      ********************/
186     /* Display the copy & paste dialog, if it is currently open */
187     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
188     if($ret){
189       return($ret);
190     }
191   
193     /********************
194       Create FAI CD ...   
195      ********************/
196     if ($s_action=="gen_cd"){
197       $this->dn= $this->terminals[$s_entry]['dn'];
198       session::set('objectinfo',$this->dn);
199       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
200     }
203     /* Start CD-Creation */
204     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
205       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
206       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
207     }
210     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
212       $return_button   = "<form method='get' action='main.php' target='_parent'>
213         <input type='submit' value='"._("Back")."'>
214         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
215         </form>";
217       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
219       /* Get and check command */
220       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
221       
222       if (check_command($command)){
223         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
225         /* Print out html introduction */
226         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
227           <html>
228           <head>
229           <title></title>
230           <style type="text/css">@import url("themes/default/style.css");</style>
231           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
232           </head>
233           <body style="background: none; margin:4px;" id="body" >
234           <pre>';
236         /* Open process handle and check if it is a valid process */
237         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
238         if (is_resource($process)) {
239           fclose($pipes[0]);
241           /* Print out returned lines && write JS to scroll down each line */
242           while (!feof($pipes[1])){
243             $cur_dat = fgets($pipes[1], 1024);
244             echo $cur_dat;
245             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
246             flush();
247           }
248         }
250         /* Get error string && close streams */
251         $buffer= stream_get_contents($pipes[2]);
253         fclose($pipes[1]);
254         fclose($pipes[2]);
255         echo "</pre>";
257         /* Check return code */
258         $ret= proc_close($process);
259         if ($ret != 0){
260           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
261           echo "<pre style='color:red'>$buffer</pre>";
262         }
266         echo $return_button."<br>";
268       } else {
269         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
270         echo $tmp;
271       }
273       /* Scroll down completly */
274       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
275       echo '</body></html>';
276       flush();
277       exit;
278     }
281     /********************
282       Create new system ...   
283      ********************/
284     /* Create new default terminal 
285      * Or create specified object of selected system type, from given incoming object  
286      */
288     $save_object_directly = false;
289     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
290       $save_object_directly = true;
291     }
293     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
295       /* If the current entry is an incoming object 
296        * $sw = System type as posted in new incoming handling dialog 
297        */ 
298       if($s_action == "SelectedSystemType") {
299         $sw         = $s_entry;
300       }else{
301         if(isset($_POST['system'])){
302           $sw = $_POST['system'];
303         }else{
304           $sw = $s_entry;
305         }
306         $this->dn= "new";
307       }
309       $tabs = array(
310           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
311           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
312           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
313           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
314           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
315           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
317       if(isset($tabs[$sw])){
318         $class    = $tabs[$sw]["CLASS"];
319         $tabname  = $tabs[$sw]["TABNAME"];
320         $tabclass = $tabs[$sw]["TABCLASS"];
321         $acl_cat  = $tabs[$sw]["ACL"];
323         /* Load permissions for selected 'dn' and check if
324            we're allowed to remove this 'dn' */
325         $ui       = get_userinfo();
326         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
327         if(preg_match("/c/",$tabacl)){
328           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
329           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
330           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
331           $this->systab->base = $this->DivListSystem->selectedBase;
332         }else{
333           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
334         }
335       }
336     }
338     /********************
339       Edit system ...   
340      ********************/
342     /* User wants to edit data? */
343     if (($s_action == "edit") && (!isset($this->systab->config))){
345       $this->dn= $this->terminals[$s_entry]['dn'];
347       /* Check locking, save current plugin in 'back_plugin', so
348          the dialog knows where to return. */
349       if (($user= get_lock($this->dn)) != ""){
350         return(gen_locked_message ($user, $this->dn));
351       }
353       /* Find out more about the object type */
354       $ldap= $this->config->get_ldap_link();
355       $ldap->cat($this->dn, array('objectClass','gotoMode'));
356       $attrs= $ldap->fetch();
357       $type= $this->get_system_type($attrs);
359       /* Lock the current entry, so everyone will get the
360          above dialog */
361       $tabs = array(
362           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
363           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
364           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
365           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
366           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
367           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
368           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
371       if($type == "ArpNewDevice"){
372         $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
373       }elseif($type == "NewDevice"){
374         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
375       }elseif(isset($tabs[$type])){
377         $class    = $tabs[$type]["CLASS"];
378         $acl_cat  = $tabs[$type]["ACL"];
379         $tabclass = $tabs[$type]["TABCLASS"];
381         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
382         $this->systab->set_acl_base($this->dn);
383         session::set('objectinfo',$this->dn);
384         add_lock ($this->dn, $this->ui->dn);
385       }else{ 
386         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
387         $this->remove_lock();
388       }
389     }
392     /********************
393       Change password ...   
394      ********************/
396     /* Set terminals root password */
397     if ($s_action=="change_pw"){
398       $tabs = array(
399           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
400           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
401           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
402           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
403           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
404           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
405           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
406           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
407           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
409       $dn   = $this->terminals[$s_entry]['dn'];
410       $type = $this->get_system_type($this->terminals[$s_entry]);
412       $class    = $tabs[$type]["CLASS"];
413       $acl      = $tabs[$type]["ACL"];
414       $tabclass = $tabs[$type]["TABCLASS"];
415       $ui       = get_userinfo();
416       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
417       if(preg_match("/w/",$tabacl)){
418         $this->dn= $this->terminals[$s_entry]['dn'];
419         session::set('objectinfo',$this->dn);
420         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
421       }else{
422         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
423       }
424     }
427     /********************
428       Password change finish, but check if entered data is ok 
429      ********************/
431     /* Correctly specified? */
432     if (isset($_POST['password_finish'])){
433       if ($_POST['new_password'] != $_POST['repeated_password']){
434         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
435         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
436       }
437     }
439     /********************
440       Password change finish
441      ********************/
443     /* Change terminal password */
444     if (isset($_POST['password_finish']) && 
445         $_POST['new_password'] == $_POST['repeated_password']){
447       /* Check if user is allowed to set password */
448       $tabs = array(
449           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"    ,"PLUG"=>"termgeneric"),
450           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
451           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"      ,"PLUG"=>"servgeneric"),
452           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
454       /* Detect object type */
455       $type = "";
456       foreach($this->terminals as $terminal){
457         if($terminal['dn'] == $this->dn){
458           $type  = $this->get_system_type($terminal);
459           break;
460         } 
461       }
463       /* Type detected */
464       $allow_for = array("terminal","workstation","server","component");
465       if(!empty($type) && in_array($type,$allow_for)){
467         /* Get infos */
468         $plug     = $tabs[$type]["PLUG"];
469         $class    = $tabs[$type]["CLASS"];
470         $acl      = $tabs[$type]["ACL"];
471         $tabclass = $tabs[$type]["TABCLASS"];
472     
473         /* Get acls */
474         $ui       = get_userinfo();
475         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
477         /* Check acls */
478         if(preg_match("/w/",$tabacl)){
479           $ldap = $this->config->get_ldap_link();
480           $ldap->cd($this->dn);
481           $ldap->cat($this->dn);
482           $old_attrs = $ldap->fetch();
484           $attrs= array();
485           if ($_POST['new_password'] == ""){
487             /* Remove password attribute 
488              */
489             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
490               $attrs['objectClass'] = array();
491               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
492                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
493                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
494                 }
495               }
496             }
497             $attrs['userPassword']= array();
498           } else {
500             /* Add/modify password attribute 
501              */
502             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
503               $attrs['objectClass'] = array();
504               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
505                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
506               }
507               $attrs['objectClass'][] = "simpleSecurityObject";
508             }
510             if(class_available("passwordMethodCrypt")){
511               $pwd_m = new passwordMethodCrypt($this->config);
512               $pwd_m->set_hash("crypt/md5");
513               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
514             }else{
515               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
516               $attrs = array();
517             }
518           }
519           $ldap->modify($attrs);
520           if (!$ldap->success()){
521             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
522           }else{
523             if(class_available($plug)){
524               $p = new $plug($this->config,$this->dn);
525               $p->handle_post_events("modify");
526             }
527           }
528   
529           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
530         }else{
531           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
532         }
533       }else{
534         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
535       }
536       session::un_set('objectinfo');
537     }
540     /********************
541       Delete system cancel
542      ********************/
544     /* Delete terminal canceled? */
545     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
546       $this->remove_lock();
547       session::un_set('objectinfo');
548     }
551     /********************
552       Action(s) for MULTIPLE
553      ********************/
555     /********************
556       SCHEDULE action in GOsa Daemon
557      ********************/
559     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
560       $this->dns = array();
561       $ids = $this->list_get_selected_items();
563       if(count($ids)){
564         $mac= array();
566         $ldap = $this->config->get_ldap_link();
567         foreach($ids as $id){
568           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
569           $attrs= $ldap->fetch();
570           if (isset($attrs['macAddress'][0])){
571             $mac[]= $attrs['macAddress'][0];
572           }
573         }
574         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
575         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
576         $o_queue = new gosaSupportDaemon();
578         /* Skip installation or update trigerred events, 
579          *  if this entry is currently processing.
580          */
581         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
582           foreach($mac as $key => $mac_address){
583             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
585               $entry['STATUS'] = strtoupper($entry['STATUS']);
586               if($entry['STATUS'] == "PROCESSING" && 
587                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
588                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
589                 unset($mac[$key]);
591                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
592                 break;
593               }
594             }
595           }
596         }        
598         /* Prepare event to be added 
599          */
600         if(count($mac) && isset($events['BY_CLASS'][$type])){
601           $event = $events['BY_CLASS'][$type];
602           $this->systab = new $event['CLASS_NAME']($this->config);
603           $this->systab->add_targets($mac);
604           if(preg_match("/trigger_event/",$s_action)){
605             $this->systab->set_type(TRIGGERED_EVENT);
606           }else{
607             $this->systab->set_type(SCHEDULED_EVENT);
608           }
609         }
610       }
611     }
613     /* Insert scheduled events into queue */
614     if($this->systab instanceof DaemonEvent){
615       $this->systab->save_object();
617       /* Save event 
618        */
619       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
620         $o_queue = new gosaSupportDaemon();
621         $o_queue->append($this->systab);
622         if($o_queue->is_error()){
623           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
624         }else{
625           $this->systab = FALSE;
626         }
627       }
628       if(isset($_POST['abort_event_dialog'])){
629         $this->systab = FALSE;
630       }
631     }
634     /********************
635       Delete MULTIPLE entries requested, display confirm dialog
636      ********************/
638     if ($s_action=="del_multiple"){
639       $this->dns = array();
640       $ids = $this->list_get_selected_items();
642       if(count($ids)){
644         foreach($ids as $id){
645           $dn = $this->terminals[$id]['dn'];
646           $this->dns[$id] = $dn;
647         }
648         if ($user= get_multiple_locks($this->dns)){
649           return(gen_locked_message($user,$this->dns));
650         }
652         $dns_names = array();
653         foreach($this->dns as $dn){
654           add_lock ($dn, $this->ui->dn);
655           $dns_names[] = @LDAP::fix($dn);
656         }
658         /* Lock the current entry, so nobody will edit it during deletion */
659         $smarty->assign("warning", msgPool::deleteInfo($dns_names));
660         $smarty->assign("multiple", true);
661         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
662       }
663     }
666     /********************
667       Delete MULTIPLE entries confirmed
668      ********************/
670     /* Confirmation for deletion has been passed. Users should be deleted. */
671     if (isset($_POST['delete_multiple_system_confirm'])){
673       $ui = get_userinfo();
674       $tabs = array(
675           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
676           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
677           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
678           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
679           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
680           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
681           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
682           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
683           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
686       /* Remove user by user and check acls before removeing them */
687       foreach($this->dns as $key => $dn){
689         /* Get 'dn' from posted termlinst */
690         $attrs    = $this->terminals[$key];
691         $type= $this->get_system_type($attrs);
693         /* get object type */
694         $tabtype  = "termtabs";
695         $tabobj   = "TERMTABS";
696         $tabacl   = "";
697         if(isset($tabs[$type])){
698           $tabtype = $tabs[$type]['TABCLASS'];
699           $tabobj  = $tabs[$type]['CLASS'];
700           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
702           /* Load permissions for selected 'dn' and check if
703              we're allowed to remove this 'dn' */
704           if(preg_match("/d/",$tabacl)){ 
706             /* Delete request is permitted, perform LDAP action */
707             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
708               $this->systab= new termgeneric($this->config, $dn);
709               $this->systab->set_acl_base($dn);
710               $this->systab->remove_from_parent();
711             }elseif($tabtype=="phonetabs"){
712               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
713               $this->systab->set_acl_base($dn);
714               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
715             }else{
716               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
717               $this->systab->set_acl_base($dn);
718               $this->systab->delete();
719             }
720             unset ($this->systab);
721             $this->systab= NULL;
723           } else {
724             /* Normally this shouldn't be reached, send some extra
725                logs to notify the administrator */
726             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
727             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
728           }
729         }
731         /* Remove lock file after successfull deletion */
732         $this->remove_lock();
733         $this->dns = array();
734       }
735     }
737     /********************
738       Delete MULTIPLE entries Canceled
739      ********************/
741     /* Remove lock */
742    if(isset($_POST['delete_multiple_system_cancel'])){
744      /* Remove lock file after successfull deletion */
745      $this->remove_lock();
746      $this->dns = array();
747    }
750     /********************
751       Delete system, confirm dialog
752      ********************/
754     /* Remove terminal was requested */
755     if ($s_action=="del"){
757       /* Get 'dn' from posted termlinst */
758       $this->dn = $this->terminals[$s_entry]['dn'];
759       $attrs    = $this->terminals[$s_entry];
761   
763       $type= $this->get_system_type($attrs);
764       $ui = get_userinfo();
765       $tabs = array(
766           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
767           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
768           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
769           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
770           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
771           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
772           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
773           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
774           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
776       /* get object type */
777       $tabtype  = "termtabs";
778       $tabobj   = "TERMTABS";
779       $tabacl   = "";
780       if(isset($tabs[$type])){
781         $tabtype = $tabs[$type]['TABCLASS'];
782         $tabobj  = $tabs[$type]['CLASS'];
783         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
784       }
786       /* Load permissions for selected 'dn' and check if
787          we're allowed to remove this 'dn' */
788       if(preg_match("/d/",$tabacl)){ 
790         /* Check locking, save current plugin in 'back_plugin', so
791            the dialog knows where to return. */
792         if (($user= get_lock($this->dn)) != ""){
793           return(gen_locked_message ($user, $this->dn));
794         }
796         /* Lock the current entry, so nobody will edit it during deletion */
797         add_lock ($this->dn, $this->ui->dn);
798         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
799         $smarty->assign("multiple", false);
800         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
801       } else {
803         /* Obviously the user isn't allowed to delete. Show message and
804            clean session. */
805         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
806       }
807     }
810     /********************
811       Delete system, confirmed
812      ********************/
813     /* Confirmation for deletion has been passed. Terminal should be deleted. */
814     if (isset($_POST['delete_terminal_confirm'])){
816       /* Find out more about the object type */
817       $ldap= $this->config->get_ldap_link();
818       $ldap->cat($this->dn, array('objectClass'));
819       $attrs= $ldap->fetch();
820       $type= $this->get_system_type($attrs);
822       $ui = get_userinfo();
824       $tabs = array(
825           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
826           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
827           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
828           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
829           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
830           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
831           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
832           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
833           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
835       /* get object type */
836       $tabtype  = "termtabs";
837       $tabobj   = "TERMTABS";
838       $tabacl   = "";
839       if(isset($tabs[$type])){
840         $tabtype = $tabs[$type]['TABCLASS'];
841         $tabobj  = $tabs[$type]['CLASS'];
842         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
843       }
845       /* Check if we are allowed to remove this object */
846       if(preg_match("/d/",$tabacl)){
848         /* Delete request is permitted, perform LDAP action */
849         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
850           $this->systab= new termgeneric($this->config, $this->dn);
851           $this->systab->set_acl_base($this->dn);
852           $this->systab->remove_from_parent();
853         }elseif($tabtype=="phonetabs"){
854           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
855           $this->systab->set_acl_base($this->dn);
856           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
857         }else{  
858           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
859           $this->systab->set_acl_base($this->dn);
860           $this->systab->delete();
861         }
862         unset ($this->systab);
863         $this->systab= NULL;
865         /* Terminal list has changed, reload it. */
866       } else {
868         /* Normally this shouldn't be reached, send some extra
869            logs to notify the administrator */
870         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
871         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
872       }
874       /* Remove lock file after successfull deletion */
875       $this->remove_lock();
876     }
879     /********************
880       Edit system type finished, check if everything went ok
881      ********************/
882     /* Finish user edit is triggered by the tabulator dialog, so
883        the user wants to save edited data. Check and save at this
884        point. */
886     /* Dirty workaround - MSG_DIALOG - OK
887       If a message dialog is shown and we press 'OK'
888        then try to save again.
889      */
890     foreach($_POST as $name => $value){
891       if(preg_match("/^MSG_OK/",$name)){
892         $_POST[$this->last_action] = TRUE;
893       }
894     }
896     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
898       /* If the save routine gets interrupted by a confirm dialog, 
899           store last action so we can trigger it again after 'Ok' was pressed.
900          (This is the case if a system gets modified while it is installing - GOsa si)
901        */
902       $this->last_action = ""; 
903       if(isset($_POST['edit_finish'])){
904         $this->last_action = "edit_finish"; 
905       }elseif(isset($_POST['edit_apply'])){
906         $this->last_action = "edit_apply";
907       }
909       /* Check tabs, will feed message array */
910       $message = array();
911       if(!$save_object_directly){
912         $message = $this->systab->check();
913       }else{
914         $found = false;
916         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
917         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
918           if(isset($this->systab->by_object[$tab]->gotoMode)) {
919             $found = true;
920             $this->systab->by_object[$tab]->gotoMode = $value;
921           }
922         }
923         if(!$found){
924           msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
925         }
927       }
928       /* Save, or display error message? */
929       if (count($message) == 0){
931         /* Incoming behavior; you can select a system type and an ogroup membership.
932          * If this object is an Incoming object, session::get('SelectedSystemType') isset.
933          * Check if we must add the new object to an object group.
934          *
935          * If this is done, delete the old incoming entry... it is still there, because this is a new
936          * entry and not an edited one, so we will delete it.
937          *
938          */
939         if(session::is_set('SelectedSystemType')){
940           $SelectedSystemType = session::get('SelectedSystemType');
941           if($SelectedSystemType['ogroup'] != "none"){
942             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
943             if($og){
944               $og->AddDelMembership($this->systab->dn);
945               $og->save();
946             }
947           }
948         }
950         /* Save terminal data to ldap */
951         $SelectedSystemType = session::get('SelectedSystemType');
952         if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
953           foreach (array("workservice", "termservice") as $cls){
954             if (isset($this->systab->by_object[$cls])){
955               $this->systab->by_object[$cls]->gotoXMouseport= "";
956               $this->systab->by_object[$cls]->gotoXMouseType= "";
957               $this->systab->by_object[$cls]->gotoXResolution= "";
958               $this->systab->by_object[$cls]->gotoXColordepth= "";
959             }
960           }
962           # Enable activation
963           foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
964             if (isset($this->systab->by_object[$cls])){
965               $this->systab->by_object["workstartup"]->auto_activate= TRUE;
966             }
967           }
969           # Enable sending of LDAP events
970           if (isset($this->systab->by_object["workstartup"])){
971             $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
972           }
973         }
975         $this->systab->save();
977         if(session::is_set('SelectedSystemType')){
978           session::un_set('SelectedSystemType');
979           if(!isset($ldap)){
980             $ldap = $this->config->get_ldap_link();
981           }
982           $ldap->cd ($this->dn);
983           $ldap->cat($this->dn, array('dn'));
984           if(count($ldap->fetch())){
985             $ldap->cd($this->dn);
986             $ldap->rmDir($this->dn);
987           }
988           $ldap->cd($this->config->current['BASE']);
989         }
991         /* Terminal has been saved successfully, remove lock from LDAP. */
992         if (!isset($_POST['edit_apply'])){
993           if ($this->dn != "new"){
994             $this->remove_lock();
995           }
997           unset ($this->systab);
998           $this->systab= NULL;
999           session::un_set('objectinfo');
1000         }else{
1001       
1002           /* Reinitialize tab */
1003           if($this->systab instanceof tabs){
1004             $this->systab->re_init();
1005           }
1006         }
1007       } else {
1008         /* Ok. There seem to be errors regarding to the tab data,
1009            show message and continue as usual. */
1010         msg_dialog::displayChecks($message);
1011       }
1012     }
1015     /********************
1016       Edit system was canceled 
1017      ********************/
1018     /* Cancel dialogs */
1019     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1020       if (isset($this->systab)){
1021         $this->remove_lock();
1022         unset ($this->systab);
1023       }
1024       $this->systab= NULL;
1025       session::un_set('objectinfo');
1027       /* Remove ogroup selection, which was set while editing a new incoming entry */
1028       if(session::is_set('SelectedSystemType')){
1029         session::un_set('SelectedSystemType');
1030       }
1031     }
1033     /********************
1034       Display edit dialog, or some other
1035      ********************/
1037     /* Show tab dialog if object is present */
1038     if (isset($this->systab->config)){
1039       $display= $this->systab->execute();
1041       /* Don't show buttons if tab dialog requests this */
1043       $dialog     = FALSE;
1044       $hide_apply = $this->dn == "new";
1045       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1046       if(is_object($this->systab) && !isset($this->systab->by_object)){
1047         $dialog = TRUE;
1048         $hide_apply = TRUE;
1049       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1050         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1051         if($dia === TRUE || is_object($dia)){
1052           $dialog = TRUE;
1053         }  
1054       }
1055       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1056         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1057         $dialog = TRUE;
1058       }
1060       if (!$dialog){
1061         $display.= "<p style=\"text-align:right\">\n";
1062         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1063         $display.= "&nbsp;\n";
1064         if (!$hide_apply){
1065           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1066           $display.= "&nbsp;\n";
1067         }
1068         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1069         $display.= "</p>";
1070       }
1071       return ($display);
1072     }
1074     /* Check if there is a snapshot dialog open */
1075     $base = $this->DivListSystem->selectedBase;
1076     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1077       return($str);
1078     }
1080     /* Display dialog with system list */
1081     $this->DivListSystem->parent = $this;
1082     $this->DivListSystem->execute();
1084     /* Add departments if subsearch is disabled */
1085     if(!$this->DivListSystem->SubSearch){
1086       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1087     }
1088     $this->reload();
1089     $this->DivListSystem->setEntries($this->terminals);
1090     return($this->DivListSystem->Draw());
1091   }
1094   /* Return departments, that will be included within snapshot detection */
1095   function get_used_snapshot_bases()
1096   {
1097     $tmp = array();
1099     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1101     $tabs = array(
1102         "terminal"        => get_ou('terminalou'),
1103         "workstation"     => get_ou('workstationou'),
1104         "incoming"        => get_ou('incomingou'),
1105         "server"          => get_ou('serverou'),
1106         "printer"         => get_ou('printerou'),
1107         "phone"           => get_ou('phoneou'),
1108         "winworkstation"  => get_winstations_ou(),
1109         "component"       => get_ou('componentou')
1110         ); 
1112     foreach($tabs as $acl_cat => $dn){
1114       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1115       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1116         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1117       }
1118     }
1119     return($tmp); 
1120   }
1123   function remove_from_parent()
1124   {
1125     /* Optionally execute a command after we're done */
1126     $this->postremove();
1127   }
1130   /* Save data to object */
1131   function save_object()
1132   {
1133     $this->DivListSystem->save_object();
1134     if(is_object($this->CopyPasteHandler)){
1135       $this->CopyPasteHandler->save_object();
1136     }
1137   }
1140   /* Check values */
1141   function check()
1142   {
1143   }
1146   /* Save to LDAP */
1147   function save()
1148   {
1149   }
1151   function adapt_from_template($dn, $skip= array())
1152   {
1153   }
1155   function password_change_needed()
1156   {
1157   }
1159   function reload()
1160   {
1161     /* some var init */
1162     $ui = get_userinfo();
1163     $res              = array();
1164     $this->terminals  = array();
1165     $userregex        = "";
1167     /* Set base for all searches */
1168     $base=  $this->DivListSystem->selectedBase;
1170     /* Prepare samba class name */
1171     $samba  ="";
1172     if ($this->DivListSystem->ShowWinWorkstations){
1173       if ($this->config->current['SAMBAVERSION'] == "3"){
1174         $samba= "sambaSamAccount";
1175       } else {
1176         $samba= "sambaAccount";
1177       }
1178     }
1180     /* This array represents the combination between checkboxes and search filters */
1181     $objs = array( 
1182         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1183         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1184         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1185         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1186         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1187         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1188         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1190     /* Include the 'Display Systems of user' attribute */ 
1191     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1192       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1193     }
1195     /* Attributes to fetch */
1196     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1197     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1199     /* Add FAIstate to attributes if FAI is activated */
1200     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1201     if(!empty($tmp)){
1202       $sys_attrs[] = "FAIstate";
1203     }    
1205     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1206     foreach($objs as $checkBox => $oc){
1207       if($this->DivListSystem->$checkBox){
1208         if($this->DivListSystem->SubSearch){
1209           if($oc['CLASS'] != ""){
1210             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1211             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1212             $res = array_merge($res,$new_res);
1213           }
1214         }else{
1215           /* User filter? */
1216           if($oc['CLASS'] != ""){
1217             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1218             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1219           }
1220         }
1221       } 
1222     }
1224     /* Search for incoming objects */ 
1225     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1226     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1228     /* Get all gotoTerminal's */
1229     foreach ($res as $value){
1231       $tmp= $value['dn'];
1232       $add= "";
1234       /* Extract base */
1235       foreach($objs as $obj){
1236         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1237           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1238         }
1239       }
1241       /* Create a string containing the last part of the department. */
1242       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1243       if(empty($dn_name)){
1244         $dn_name = "/";
1245       }
1247       /* check if current object is a new one */
1248       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1249         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1250           $add= "- "._("New terminal");
1251         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1252           $add= "- "._("New workstation");
1253         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1254           $add= "- "._("Unknown device");
1255         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1256           $add= "- "._("New Device");
1257         }
1258       } 
1260       /* Detect type of object and create an entry for $this->terminals */
1261       $terminal = array();
1262       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1264         /* check acl */
1265         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1266         if($add != "" || preg_match("/r/",$acl)) {
1267           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1268             $terminal             = $value;
1269             $terminal['type']     = "T";
1270             $terminal['is_new']   = $add;
1271           } else {
1272             $terminal             = $value;
1273             $terminal['type']     = "D";
1274             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1275             $terminal['location'] = array_search($tmp, $this->config->departments); 
1276           }
1277         }
1278       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1280         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1281         if($add != "" || preg_match("/r/",$acl)) {
1282           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1283             $terminal             = $value;
1284             $terminal['type']     = "L";
1285             $terminal['is_new']   = $add;
1286           } else {
1287             $terminal             = $value;
1288             $terminal['type']     = "D";
1289             $terminal['location'] = array_search($tmp, $this->config->departments);
1290             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1291           }
1292 #          if (isset($value["FAIstate"][0])){
1293 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1294 #          }
1295         }
1296       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1297        
1298    
1299         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1300         if($add != "" || preg_match("/r/",$acl)) {
1302           $terminal             = $value;
1303           $terminal['type']     = "P";
1304         }
1305       } elseif (in_array_ics('goServer', $value["objectClass"])){
1307         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1308         if($add != "" || preg_match("/r/",$acl)) {
1310           $terminal             = $value;
1311           $terminal['type']     = "S";
1312 #          if (isset($value["FAIstate"][0])){
1313 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1314 #          }
1315         }
1316       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1318         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1319         if($add != "" || preg_match("/r/",$acl)) {
1321           $terminal             = $value;
1322           $terminal['type']     = "F";
1323         }
1324       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1326         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1327                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1328                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1329         if($add != "" || preg_match("/r/",$acl)) {
1331           $terminal = $value;
1332           $terminal['type']   = "Q";
1333           $terminal['is_new'] = $add;
1334         }
1335       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1337         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1338         if($add != "" || preg_match("/r/",$acl)) {
1340           $terminal             = $value;
1341           $terminal['type']     = "C";
1342         }
1343       } else{
1345         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1346         if (isset($value['sambaDomainName'])){
1347           $domain= " [".$value['sambaDomainName'][0]."]";
1348         } else {
1349           $domain= "";
1350         }
1351         $terminal=$value;
1352         $terminal['type']     ="W";
1353         $terminal['domain']   = $name.$domain;
1354       }
1356       if(count($terminal)){
1357         $this->terminals[]=$terminal;
1358       }
1359     }
1361     $tmp  =array();
1362     $tmp2 =array();
1363     foreach($this->terminals as $tkey => $val ){
1364       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1365       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1366     }
1367     natcasesort($tmp2);
1368     $this->terminals=array();
1369     foreach($tmp2 as $val){
1370       $this->terminals[]=$tmp[$val];
1371     }
1372     reset ($this->terminals);
1373   }
1375   function remove_lock()
1376   {
1377     if (isset($this->systab->dn)){
1378       del_lock ($this->systab->dn);
1379     }
1380     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1381       del_lock($this->dn);
1382     }
1383     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1384       del_lock($this->dns);
1385     }
1386   }
1389   function copyPasteHandling_from_queue($s_action,$s_entry)
1390   {
1391     /* Check if Copy & Paste is disabled */
1392     if(!is_object($this->CopyPasteHandler)){
1393       return("");
1394     }
1397     $tabs = array(
1398         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1399           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1400         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1401           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1402         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1403           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1404         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1405           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1406         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1407           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1408         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1409           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1411     /* Add a single entry to queue */
1412     if($s_action == "cut" || $s_action == "copy"){
1414       /* Cleanup object queue */
1415       $this->CopyPasteHandler->cleanup_queue();
1416       $dn     = $this->terminals[$s_entry]['dn'];
1417       $oc     = $this->terminals[$s_entry]['objectClass'];
1418       $type   = $this->get_system_type($this->terminals[$s_entry]);
1420       $tab_o  = $tabs[$type]['CLASS'];
1421       $tab_c  = $tabs[$type]['TABCLASS'];
1422       $acl    = $tabs[$type]['ACL'];
1424       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1425     }
1427     /* Add entries to queue */
1428     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1430       /* Cleanup object queue */
1431       $this->CopyPasteHandler->cleanup_queue();
1433       /* Add new entries to CP queue */
1434       foreach($this->list_get_selected_items() as $id){
1435         $dn = $this->terminals[$id]['dn'];
1436         $oc = $this->terminals[$id]['objectClass']; 
1437         $type = $this->get_system_type($this->terminals[$id]);
1439         if(isset($tabs[$type])){
1440           $tab_o  = $tabs[$type]['CLASS'];
1441           $tab_c  = $tabs[$type]['TABCLASS'];
1442           $acl    = $tabs[$type]['ACL'];
1444           if($s_action == "copy_multiple"){
1445             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1446           }
1447           if($s_action == "cut_multiple"){
1448             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1449           }
1450         }
1451       }
1452     }
1454     /* Start pasting entries */
1455     if($s_action == "editPaste"){
1456       $this->start_pasting_copied_objects = TRUE;
1457     }
1458   
1459     /* Return C&P dialog */
1460     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1462       /* Get dialog */
1463       $data = $this->CopyPasteHandler->execute();
1464       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1466       /* Return dialog data */
1467       if(!empty($data)){
1468         return($data);
1469       }
1470     }
1472     /* Automatically disable status for pasting */
1473     if(!$this->CopyPasteHandler->entries_queued()){
1474       $this->start_pasting_copied_objects = FALSE;
1475     }
1476     return("");
1477   }
1480   function get_system_type($attrs)
1481   {
1482     $classes = $attrs['objectClass'];
1484     $type= "";
1485     if (in_array_ics('ieee802Device', $classes)){
1486       $type= "component";
1487     }elseif (in_array_ics('gotoTerminal', $classes)){
1488       $type= "terminal";
1489     }elseif (in_array_ics('gotoWorkstation', $classes)){
1490       $type= "workstation";
1491     }elseif (in_array_ics('gotoPrinter', $classes)){
1492       $type= "printer";
1493     }elseif (in_array_ics('goFonHardware', $classes)){
1494       $type= "phone";
1495     }elseif (in_array_ics('goServer', $classes)){
1496       $type= "server";
1497     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1498       $type= "ArpNewDevice";
1499     }elseif (in_array_ics('GOhard', $classes)){
1500       $type= "NewDevice";
1501     }elseif (in_array_ics('sambaAccount', $classes) ||
1502         in_array_ics('sambaSamAccount', $classes)){
1503       $type= "winstation";
1504     }
1505     return ($type);
1506   }
1509   function convert_list($input)
1510   {
1511     $temp= "";
1513     $conv= array(
1514         "D" => array("select_default.png",_("Template")),
1515         "F" => array("select_phone.png",_("Phone")),
1516         "C" => array("select_component.png",_("Network device")),
1517         "P" => array("select_printer.png",_("Printer")),
1519         "W" => array("select_winstation.png",_("Win workstation")),
1521         "L" => array("select_workstation.png",_("Workstation")),
1522         "S" => array("select_server.png",_("Server")),
1523         "T" => array("select_terminal.png",_("Terminal")),
1525         "LX" => array("workstation_locked.png",_("Locked workstation")),
1526         "SX" => array("server_locked.png",_("Locked server")),
1527         "TX" => array("terminal_locked.png",_("Locked terminal")),
1529         "LE" => array("workstation_error.png",_("Workstation error")),
1530         "SE" => array("server_error.png",_("Server error")),
1531         "TE" => array("terminal_error.png",_("Terminal error")),
1533         "LB" => array("workstation_busy.png",_("Workstation busy")),
1534         "SB" => array("server_busy.png",_("Server busy")),
1536         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1537         "NT"=> array("select_new_terminal.png",_("New terminal")),
1538         "NL"=> array("select_new_workstation.png",_("New workstation")));
1540     /* Use locked icons 
1541      */
1542     if( in_array($input['type'],array("S","T","L")) && 
1543         isset($input['gotoMode'][0]) && 
1544         preg_match("/locked/",$input['gotoMode'][0])){
1545       $input['type'].="X";
1546     } elseif(in_array($input['type'],array("S","L")) &&
1547         isset($input['FAIstate'][0])){
1549     /* Add FAI state icons 
1550      */
1551       $type= "";
1552       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1553         case 'error':
1554           $type= 'E';
1555           break;
1556         case 'installing':
1557         case 'install':
1558         case 'sysinfo':
1559         case 'softupdate':
1560         case 'scheduledupdate':
1561           $type= 'B';
1562           break;
1563       }
1565       $input['type'].= $type;
1566     }   
1568     /* Use new images if object is from incoming 
1569      */
1570     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1571       $input['type']="N".$input['type'];
1572     }
1574     /* Check which flags this objects uses 
1575      */
1576     foreach ($conv  as $key => $value){
1577       $found = TRUE;
1578       if(strlen($key) != strlen($input['type'])) {
1579         $found = FALSE;
1580       }
1581       for($i = 0 ; $i < strlen($key) ; $i++){
1582         if(!preg_match("/".$key[$i]."/",$input['type'])){
1583           $found = FALSE;
1584         }
1585       }
1587       if($found){
1588         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1589         $tmp['class']=$key;
1590         return $tmp;
1591       }
1592     }
1593   }
1596   function list_get_selected_items()
1597   {
1598     $ids = array();
1599     foreach($_POST as $name => $value){
1600       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1601         $id   = preg_replace("/^item_selected_/","",$name);
1602         $ids[$id] = $id;
1603       }
1604     }
1605     return($ids);
1606   }
1609   /* !! Incoming dummy acls, required to defined acls for incoming objects
1610    */
1611   static function plInfo()
1612   {
1613     return (array(
1614           "plShortName"   => _("Incoming objects"),
1615           "plDescription" => _("Incoming objects"),
1616           "plSelfModify"  => FALSE,
1617           "plDepends"     => array(),
1618           "plPriority"    => 99,
1619           "plSection"     => array("administration"),
1620           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1621                                                           "objectClass"  => "")),
1622           "plProvidedAcls"=> array()
1623             
1624           ));
1625   }
1628   
1632 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1633 ?>