Code

Fixed service plugin initializations. Parent wasn't correct initialized
[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   function systems (&$config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= $config;
46     $this->ui= $ui;
48     /* Creat dialog object */
49     $this->DivListSystem = new divListSystem($this->config,$this);
51     /* Copy & Paste enabled ?*/
52     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
53       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
54     }
56     /* Check whether the arp handling active or not */
57     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
58       $this->arp_handling_active = TRUE;
59     }
61   }
64   function execute()
65   {
66     /* Call parent execute */
67     plugin::execute();
69     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
71     /********************
72       Check for functional posts, edit|delete|add|... system devices 
73      ********************/
74     $s_action     = "";                       // Contains the action to proceed
75     $s_entry      = "";                       // The value for s_action
76     $base_back    = "";                       // The Link for Backbutton
77     $smarty       = get_smarty();
79     /* Test Posts */
80     foreach($_POST as $key => $val){
81       // Post for delete
82       if(preg_match("/system_del.*/",$key)){
83         $s_action = "del";
84         $s_entry  = preg_replace("/system_del_/i","",$key);
85         // Post for edit
86       }elseif(preg_match("/system_edit_.*/",$key)){
87         $s_action="edit";
88         $s_entry  = preg_replace("/system_edit_/i","",$key);
89         // Post for new
90       }elseif(preg_match("/system_new.*/",$key)){
91         $s_action="new";
92       }elseif(preg_match("/system_tplnew.*/i",$key)){
93         $s_action="new_tpl";
94       }elseif(preg_match("/system_setpwd_.*/i",$key)){
95         $s_action="change_pw";
96         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
97       }elseif(preg_match("/gen_cd_.*/i",$key)){
98         $s_action="gen_cd";
99         $s_entry  = preg_replace("/gen_cd_/i","",$key);
100       }elseif(preg_match("/^copy_.*/",$key)){
101         $s_action="copy";
102         $s_entry  = preg_replace("/^copy_/i","",$key);
103       }elseif(preg_match("/^cut_.*/",$key)){
104         $s_action="cut";
105         $s_entry  = preg_replace("/^cut_/i","",$key);
106       }
107     }
108    
109     /* Incoming handling  
110      * If someone made a systemtype and ogroup selection 
111      * Display the new requested entry type ... servtab  in case of server and so on.
112      */
113     if(isset($_POST['SystemTypeChoosen'])){
114       $SelectedSystemType = session::get('SelectedSystemType');
115       $s_action = "SelectedSystemType";
116       $s_entry  = $_POST['SystemType'];
117       $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
118       $this->systab = NULL;
119       session::set('SelectedSystemType',$SelectedSystemType);
120     }
122     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
123     $s_entry  = preg_replace("/_.$/","",$s_entry);
125     /* Edit was requested by pressing the name(link) of an item */
126     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
127       $s_action ="edit";
128       $s_entry  = $_GET['id'];
129     }
130     /* Create options */
131     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
132       $s_action = "newsystem";
133       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
134     }
136     /* handle C&P from layers menu */
137     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
138       $s_action = "copy_multiple";
139     }
140     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
141       $s_action = "cut_multiple";
142     }
143     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
144       $s_action = "editPaste";
145     }
147     /* Handle daemon events */
148     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
149       $s_action = $_POST['menu_action'];
150     }
151     
152     /* Handle daemon events */
153     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
154       $s_action = $_POST['menu_action'];
155     }
157     /* handle remove from layers menu */
158     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
159       $s_action = "del_multiple";
160     }
161     
162     /* Handle instant actions from layers menu */
163     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
164             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
165               $s_action = "${act}_multiple";
166             }
167     }
169     /* Check for exeeded sizelimit */
170     if (($message= check_sizelimit()) != ""){
171       return($message);
172     }
174     /* Try to get informations about what kind of system to create */
175     if ($s_action=="new") {
176       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
177     }
180     /********************
181       Copy & Paste Handling  ...
182      ********************/
184     /* Display the copy & paste dialog, if it is currently open */
185     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
186     if($ret){
187       return($ret);
188     }
189   
191     /********************
192       Create FAI CD ...   
193      ********************/
194     if ($s_action=="gen_cd"){
195       $this->dn= $this->terminals[$s_entry]['dn'];
196       session::set('objectinfo',$this->dn);
197       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
198     }
201     /* Start CD-Creation */
202     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
203       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
204       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
205     }
208     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
210       $return_button   = "<form method='get' action='main.php' target='_parent'>
211         <input type='submit' value='"._("Back")."'>
212         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
213         </form>";
215       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
217       /* Get and check command */
218       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
219       
220       if (check_command($command)){
221         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
223         /* Print out html introduction */
224         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
225           <html>
226           <head>
227           <title></title>
228           <style type="text/css">@import url("themes/default/style.css");</style>
229           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
230           </head>
231           <body style="background: none; margin:4px;" id="body" >
232           <pre>';
234         /* Open process handle and check if it is a valid process */
235         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
236         if (is_resource($process)) {
237           fclose($pipes[0]);
239           /* Print out returned lines && write JS to scroll down each line */
240           while (!feof($pipes[1])){
241             $cur_dat = fgets($pipes[1], 1024);
242             echo $cur_dat;
243             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
244             flush();
245           }
246         }
248         /* Get error string && close streams */
249         $buffer= stream_get_contents($pipes[2]);
251         fclose($pipes[1]);
252         fclose($pipes[2]);
253         echo "</pre>";
255         /* Check return code */
256         $ret= proc_close($process);
257         if ($ret != 0){
258           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
259           echo "<pre style='color:red'>$buffer</pre>";
260         }
264         echo $return_button."<br>";
266       } else {
267         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
268         echo $tmp;
269       }
271       /* Scroll down completly */
272       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
273       echo '</body></html>';
274       flush();
275       exit;
276     }
279     /********************
280       Create new system ...   
281      ********************/
282     /* Create new default terminal 
283      * Or create specified object of selected system type, from given incoming object  
284      */
286     $save_object_directly = false;
287     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
288       $save_object_directly = true;
289     }
291     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
293       /* If the current entry is an incoming object 
294        * $sw = System type as posted in new incoming handling dialog 
295        */ 
296       if($s_action == "SelectedSystemType") {
297         $sw         = $s_entry;
298       }else{
299         if(isset($_POST['system'])){
300           $sw = $_POST['system'];
301         }else{
302           $sw = $s_entry;
303         }
304         $this->dn= "new";
305       }
307       $tabs = array(
308           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
309           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
310           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
311           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
312           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
313           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
315       if(isset($tabs[$sw])){
316         $class    = $tabs[$sw]["CLASS"];
317         $tabname  = $tabs[$sw]["TABNAME"];
318         $tabclass = $tabs[$sw]["TABCLASS"];
319         $acl_cat  = $tabs[$sw]["ACL"];
321         /* Load permissions for selected 'dn' and check if
322            we're allowed to remove this 'dn' */
323         $ui       = get_userinfo();
324         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
325         if(preg_match("/c/",$tabacl)){
326           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
327           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
328           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
329           $this->systab->base = $this->DivListSystem->selectedBase;
330         }else{
331           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
332         }
333       }
334     }
336     /********************
337       Edit system ...   
338      ********************/
340     /* User wants to edit data? */
341     if (($s_action == "edit") && (!isset($this->systab->config))){
343       $this->dn= $this->terminals[$s_entry]['dn'];
345       /* Check locking, save current plugin in 'back_plugin', so
346          the dialog knows where to return. */
347       if (($user= get_lock($this->dn)) != ""){
348         return(gen_locked_message ($user, $this->dn));
349       }
351       /* Find out more about the object type */
352       $ldap= $this->config->get_ldap_link();
353       $ldap->cat($this->dn, array('objectClass','gotoMode'));
354       $attrs= $ldap->fetch();
355       $type= $this->get_system_type($attrs);
357       /* Lock the current entry, so everyone will get the
358          above dialog */
359       $tabs = array(
360           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
361           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
362           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
363           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
364           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
365           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
366           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
369       if($type == "ArpNewDevice"){
370         $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
371       }elseif($type == "NewDevice"){
372         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
373       }elseif(isset($tabs[$type])){
375         $class    = $tabs[$type]["CLASS"];
376         $acl_cat  = $tabs[$type]["ACL"];
377         $tabclass = $tabs[$type]["TABCLASS"];
379         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
380         $this->systab->set_acl_base($this->dn);
381         session::set('objectinfo',$this->dn);
382         add_lock ($this->dn, $this->ui->dn);
383       }else{ 
384         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
385         del_lock($this->dn);
386       }
387     }
390     /********************
391       Change password ...   
392      ********************/
394     /* Set terminals root password */
395     if ($s_action=="change_pw"){
396       $tabs = array(
397           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
398           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
399           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
400           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
401           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
402           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
403           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
404           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
405           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
407       $dn   = $this->terminals[$s_entry]['dn'];
408       $type = $this->get_system_type($this->terminals[$s_entry]);
410       $class    = $tabs[$type]["CLASS"];
411       $acl      = $tabs[$type]["ACL"];
412       $tabclass = $tabs[$type]["TABCLASS"];
413       $ui       = get_userinfo();
414       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
415       if(preg_match("/w/",$tabacl)){
416         $this->dn= $this->terminals[$s_entry]['dn'];
417         session::set('objectinfo',$this->dn);
418         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
419       }else{
420         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
421       }
422     }
425     /********************
426       Password change finish, but check if entered data is ok 
427      ********************/
429     /* Correctly specified? */
430     if (isset($_POST['password_finish'])){
431       if ($_POST['new_password'] != $_POST['repeated_password']){
432         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
433         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
434       }
435     }
437     /********************
438       Password change finish
439      ********************/
441     /* Change terminal password */
442     if (isset($_POST['password_finish']) && 
443         $_POST['new_password'] == $_POST['repeated_password']){
445       /* Check if user is allowed to set password */
446       $tabs = array(
447           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"    ,"PLUG"=>"termgeneric"),
448           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
449           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"      ,"PLUG"=>"servgeneric"),
450           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
452       /* Detect object type */
453       $type = "";
454       foreach($this->terminals as $terminal){
455         if($terminal['dn'] == $this->dn){
456           $type  = $this->get_system_type($terminal);
457           break;
458         } 
459       }
461       /* Type detected */
462       $allow_for = array("terminal","workstation","server","component");
463       if(!empty($type) && in_array($type,$allow_for)){
465         /* Get infos */
466         $plug     = $tabs[$type]["PLUG"];
467         $class    = $tabs[$type]["CLASS"];
468         $acl      = $tabs[$type]["ACL"];
469         $tabclass = $tabs[$type]["TABCLASS"];
470     
471         /* Get acls */
472         $ui       = get_userinfo();
473         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
475         /* Check acls */
476         if(preg_match("/w/",$tabacl)){
477           $ldap = $this->config->get_ldap_link();
478           $ldap->cd($this->dn);
479           $ldap->cat($this->dn);
480           $old_attrs = $ldap->fetch();
482           $attrs= array();
483           if ($_POST['new_password'] == ""){
485             /* Remove password attribute 
486              */
487             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
488               $attrs['objectClass'] = array();
489               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
490                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
491                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
492                 }
493               }
494             }
495             $attrs['userPassword']= array();
496           } else {
498             /* Add/modify password attribute 
499              */
500             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
501               $attrs['objectClass'] = array();
502               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
503                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
504               }
505               $attrs['objectClass'][] = "simpleSecurityObject";
506             }
508             if(class_available("passwordMethodCrypt")){
509               $pwd_m = new passwordMethodCrypt($this->config);
510               $pwd_m->set_hash("crypt/md5");
511               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
512             }else{
513               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
514               $attrs = array();
515             }
516           }
517           $ldap->modify($attrs);
518           if (!$ldap->success()){
519             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
520           }else{
521             if(class_available($plug)){
522               $p = new $plug($this->config,$this->dn);
523               $p->handle_post_events("modify");
524             }
525           }
526   
527           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
528         }else{
529           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
530         }
531       }else{
532         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
533       }
534       session::un_set('objectinfo');
535     }
538     /********************
539       Delete system cancel
540      ********************/
542     /* Delete terminal canceled? */
543     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
544       del_lock ($this->dn);
545       session::un_set('objectinfo');
546     }
549     /********************
550       Action(s) for MULTIPLE
551      ********************/
553     /********************
554       SCHEDULE action in GOsa Daemon
555      ********************/
557     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
558       $this->dns = array();
559       $ids = $this->list_get_selected_items();
561       if(count($ids)){
562         $mac= array();
564         $ldap = $this->config->get_ldap_link();
565         foreach($ids as $id){
566           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
567           $attrs= $ldap->fetch();
568           if (isset($attrs['macAddress'][0])){
569             $mac[]= $attrs['macAddress'][0];
570           }
571         }
572         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
573         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
574         $o_queue = new gosaSupportDaemon();
576         /* Skip installation or update trigerred events, 
577          *  if this entry is currently processing.
578          */
579         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
580           foreach($mac as $key => $mac_address){
581             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
583               $entry['STATUS'] = strtoupper($entry['STATUS']);
584               if($entry['STATUS'] == "PROCESSING" && 
585                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
586                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
587                 unset($mac[$key]);
589                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
590                 break;
591               }
592             }
593           }
594         }        
596         /* Prepare event to be added 
597          */
598         if(count($mac) && isset($events['BY_CLASS'][$type])){
599           $event = $events['BY_CLASS'][$type];
600           $this->systab = new $event['CLASS_NAME']($this->config);
601           $this->systab->add_targets($mac);
602           if(preg_match("/trigger_event/",$s_action)){
603             $this->systab->set_type(TRIGGERED_EVENT);
604           }else{
605             $this->systab->set_type(SCHEDULED_EVENT);
606           }
607         }
608       }
609     }
611     /* Insert scheduled events into queue */
612     if($this->systab instanceof DaemonEvent){
613       $this->systab->save_object();
615       /* Save event 
616        */
617       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
618         $o_queue = new gosaSupportDaemon();
619         $o_queue->append($this->systab);
620         if($o_queue->is_error()){
621           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
622         }else{
623           $this->systab = FALSE;
624         }
625       }
626       if(isset($_POST['abort_event_dialog'])){
627         $this->systab = FALSE;
628       }
629     }
632     /********************
633       Delete MULTIPLE entries requested, display confirm dialog
634      ********************/
636     if ($s_action=="del_multiple"){
637       $this->dns = array();
638       $ids = $this->list_get_selected_items();
640       if(count($ids)){
642         foreach($ids as $id){
643           $dn = $this->terminals[$id]['dn'];
644           $this->dns[$id] = $dn;
645         }
646         if ($user= get_multiple_locks($this->dns)){
647           return(gen_locked_message($user,$this->dns));
648         }
650         $dns_names = array();
651         foreach($this->dns as $dn){
652           add_lock ($dn, $this->ui->dn);
653           $dns_names[] = @LDAP::fix($dn);
654         }
656         /* Lock the current entry, so nobody will edit it during deletion */
657         $smarty->assign("warning", msgPool::deleteInfo($dns_names));
658         $smarty->assign("multiple", true);
659         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
660       }
661     }
664     /********************
665       Delete MULTIPLE entries confirmed
666      ********************/
668     /* Confirmation for deletion has been passed. Users should be deleted. */
669     if (isset($_POST['delete_multiple_system_confirm'])){
671       $ui = get_userinfo();
672       $tabs = array(
673           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
674           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
675           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
676           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
677           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
678           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
679           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
680           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
681           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
684       /* Remove user by user and check acls before removeing them */
685       foreach($this->dns as $key => $dn){
687         /* Get 'dn' from posted termlinst */
688         $attrs    = $this->terminals[$key];
689         $type= $this->get_system_type($attrs);
691         /* get object type */
692         $tabtype  = "termtabs";
693         $tabobj   = "TERMTABS";
694         $tabacl   = "";
695         if(isset($tabs[$type])){
696           $tabtype = $tabs[$type]['TABCLASS'];
697           $tabobj  = $tabs[$type]['CLASS'];
698           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
700           /* Load permissions for selected 'dn' and check if
701              we're allowed to remove this 'dn' */
702           if(preg_match("/d/",$tabacl)){ 
704             /* Delete request is permitted, perform LDAP action */
705             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
706               $this->systab= new termgeneric($this->config, $dn);
707               $this->systab->set_acl_base($dn);
708               $this->systab->remove_from_parent();
709             }elseif($tabtype=="phonetabs"){
710               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
711               $this->systab->set_acl_base($dn);
712               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
713             }else{
714               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
715               $this->systab->set_acl_base($dn);
716               $this->systab->delete();
717             }
718             unset ($this->systab);
719             $this->systab= NULL;
721           } else {
722             /* Normally this shouldn't be reached, send some extra
723                logs to notify the administrator */
724             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
725             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
726           }
727           /* Remove lock file after successfull deletion */
728           del_lock ($dn);
729           unset($this->dns[$key]);
730         }
731       }
732     }
734     /********************
735       Delete MULTIPLE entries Canceled
736      ********************/
738     /* Remove lock */
739    if(isset($_POST['delete_multiple_system_cancel'])){
740       foreach($this->dns as $key => $dn){
741         del_lock ($dn);
742         unset($this->dns[$key]);
743       }
744     }
747     /********************
748       Delete system, confirm dialog
749      ********************/
751     /* Remove terminal was requested */
752     if ($s_action=="del"){
754       /* Get 'dn' from posted termlinst */
755       $this->dn = $this->terminals[$s_entry]['dn'];
756       $attrs    = $this->terminals[$s_entry];
758   
760       $type= $this->get_system_type($attrs);
761       $ui = get_userinfo();
762       $tabs = array(
763           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
764           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
765           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
766           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
767           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
768           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
769           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
770           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
771           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
773       /* get object type */
774       $tabtype  = "termtabs";
775       $tabobj   = "TERMTABS";
776       $tabacl   = "";
777       if(isset($tabs[$type])){
778         $tabtype = $tabs[$type]['TABCLASS'];
779         $tabobj  = $tabs[$type]['CLASS'];
780         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
781       }
783       /* Load permissions for selected 'dn' and check if
784          we're allowed to remove this 'dn' */
785       if(preg_match("/d/",$tabacl)){ 
787         /* Check locking, save current plugin in 'back_plugin', so
788            the dialog knows where to return. */
789         if (($user= get_lock($this->dn)) != ""){
790           return(gen_locked_message ($user, $this->dn));
791         }
793         /* Lock the current entry, so nobody will edit it during deletion */
794         add_lock ($this->dn, $this->ui->dn);
795         $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
796         $smarty->assign("multiple", false);
797         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
798       } else {
800         /* Obviously the user isn't allowed to delete. Show message and
801            clean session. */
802         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
803       }
804     }
807     /********************
808       Delete system, confirmed
809      ********************/
810     /* Confirmation for deletion has been passed. Terminal should be deleted. */
811     if (isset($_POST['delete_terminal_confirm'])){
813       /* Find out more about the object type */
814       $ldap= $this->config->get_ldap_link();
815       $ldap->cat($this->dn, array('objectClass'));
816       $attrs= $ldap->fetch();
817       $type= $this->get_system_type($attrs);
819       $ui = get_userinfo();
821       $tabs = array(
822           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
823           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
824           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
825           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
826           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
827           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
828           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
829           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
830           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
832       /* get object type */
833       $tabtype  = "termtabs";
834       $tabobj   = "TERMTABS";
835       $tabacl   = "";
836       if(isset($tabs[$type])){
837         $tabtype = $tabs[$type]['TABCLASS'];
838         $tabobj  = $tabs[$type]['CLASS'];
839         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
840       }
842       /* Check if we are allowed to remove this object */
843       if(preg_match("/d/",$tabacl)){
845         /* Delete request is permitted, perform LDAP action */
846         if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
847           $this->systab= new termgeneric($this->config, $this->dn);
848           $this->systab->set_acl_base($this->dn);
849           $this->systab->remove_from_parent();
850         }elseif($tabtype=="phonetabs"){
851           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
852           $this->systab->set_acl_base($this->dn);
853           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
854         }else{  
855           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
856           $this->systab->set_acl_base($this->dn);
857           $this->systab->delete();
858         }
859         unset ($this->systab);
860         $this->systab= NULL;
862         /* Terminal list has changed, reload it. */
863       } else {
865         /* Normally this shouldn't be reached, send some extra
866            logs to notify the administrator */
867         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
868         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
869       }
871       /* Remove lock file after successfull deletion */
872       del_lock ($this->dn);
873     }
876     /********************
877       Edit system type finished, check if everything went ok
878      ********************/
879     /* Finish user edit is triggered by the tabulator dialog, so
880        the user wants to save edited data. Check and save at this
881        point. */
883     /* Dirty workaround - MSG_DIALOG - OK
884       If a message dialog is shown and we press 'OK'
885        then try to save again.
886      */
887     foreach($_POST as $name => $value){
888       if(preg_match("/^MSG_OK/",$name)){
889         $_POST[$this->last_action] = TRUE;
890       }
891     }
893     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
895       /* If the save routine gets interrupted by a confirm dialog, 
896           store last action so we can trigger it again after 'Ok' was pressed.
897          (This is the case if a system gets modified while it is installing - GOsa si)
898        */
899       $this->last_action = ""; 
900       if(isset($_POST['edit_finish'])){
901         $this->last_action = "edit_finish"; 
902       }elseif(isset($_POST['edit_apply'])){
903         $this->last_action = "edit_apply";
904       }
906       /* Check tabs, will feed message array */
907       $message = array();
908       if(!$save_object_directly){
909         $message = $this->systab->check();
910       }else{
911         $found = false;
913         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
914         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
915           if(isset($this->systab->by_object[$tab]->gotoMode)) {
916             $found = true;
917             $this->systab->by_object[$tab]->gotoMode = $value;
918           }
919         }
920         if(!$found){
921           msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
922         }
924       }
925       /* Save, or display error message? */
926       if (count($message) == 0){
928         /* Incoming behavior; you can select a system type and an ogroup membership.
929          * If this object is an Incoming object, session::get('SelectedSystemType') isset.
930          * Check if we must add the new object to an object group.
931          *
932          * If this is done, delete the old incoming entry... it is still there, because this is a new
933          * entry and not an edited one, so we will delete it.
934          *
935          */
936         if(session::is_set('SelectedSystemType')){
937           $SelectedSystemType = session::get('SelectedSystemType');
938           if($SelectedSystemType['ogroup'] != "none"){
939             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
940             if($og){
941               $og->AddDelMembership($this->systab->dn);
942               $og->save();
943             }
944           }
945         }
947         /* Save terminal data to ldap */
948         $SelectedSystemType = session::get('SelectedSystemType');
949         if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
950           foreach (array("workservice", "termservice") as $cls){
951             if (isset($this->systab->by_object[$cls])){
952               $this->systab->by_object[$cls]->gotoXMouseport= "";
953               $this->systab->by_object[$cls]->gotoXMouseType= "";
954               $this->systab->by_object[$cls]->gotoXResolution= "";
955               $this->systab->by_object[$cls]->gotoXColordepth= "";
956             }
957           }
959           # Enable activation
960           foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
961             if (isset($this->systab->by_object[$cls])){
962               $this->systab->by_object["workstartup"]->auto_activate= TRUE;
963             }
964           }
966           # Enable sending of LDAP events
967           if (isset($this->systab->by_object["workstartup"])){
968             $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
969           }
970         }
972         $this->systab->save();
974         if(session::is_set('SelectedSystemType')){
975           session::un_set('SelectedSystemType');
976           if(!isset($ldap)){
977             $ldap = $this->config->get_ldap_link();
978           }
979           $ldap->cd ($this->dn);
980           $ldap->cat($this->dn, array('dn'));
981           if(count($ldap->fetch())){
982             $ldap->cd($this->dn);
983             $ldap->rmDir($this->dn);
984           }
985           $ldap->cd($this->config->current['BASE']);
986         }
988         /* Terminal has been saved successfully, remove lock from LDAP. */
989         if (!isset($_POST['edit_apply'])){
990           if ($this->dn != "new"){
991             del_lock ($this->dn);
992           }
994           unset ($this->systab);
995           $this->systab= NULL;
996           session::un_set('objectinfo');
997         }
998       } else {
999         /* Ok. There seem to be errors regarding to the tab data,
1000            show message and continue as usual. */
1001         msg_dialog::displayChecks($message);
1002       }
1003     }
1006     /********************
1007       Edit system was canceled 
1008      ********************/
1009     /* Cancel dialogs */
1010     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1011       if (isset($this->systab)){
1012         del_lock ($this->systab->dn);
1013         unset ($this->systab);
1014       }
1015       $this->systab= NULL;
1016       session::un_set('objectinfo');
1018       /* Remove ogroup selection, which was set while editing a new incoming entry */
1019       if(session::is_set('SelectedSystemType')){
1020         session::un_set('SelectedSystemType');
1021       }
1022     }
1024     /********************
1025       Display edit dialog, or some other
1026      ********************/
1028     /* Show tab dialog if object is present */
1029     if (isset($this->systab->config)){
1030       $display= $this->systab->execute();
1032       /* Don't show buttons if tab dialog requests this */
1034       $dialog     = FALSE;
1035       $hide_apply = $this->dn == "new";
1036       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1037       if(is_object($this->systab) && !isset($this->systab->by_object)){
1038         $dialog = TRUE;
1039         $hide_apply = TRUE;
1040       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1041         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1042         if($dia === TRUE || is_object($dia)){
1043           $dialog = TRUE;
1044         }  
1045       }
1046       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1047         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1048         $dialog = TRUE;
1049       }
1051       if (!$dialog){
1052         $display.= "<p style=\"text-align:right\">\n";
1053         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1054         $display.= "&nbsp;\n";
1055         if (!$hide_apply){
1056           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1057           $display.= "&nbsp;\n";
1058         }
1059         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1060         $display.= "</p>";
1061       }
1062       return ($display);
1063     }
1065     /* Check if there is a snapshot dialog open */
1066     $base = $this->DivListSystem->selectedBase;
1067     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1068       return($str);
1069     }
1071     /* Display dialog with system list */
1072     $this->DivListSystem->parent = $this;
1073     $this->DivListSystem->execute();
1075     /* Add departments if subsearch is disabled */
1076     if(!$this->DivListSystem->SubSearch){
1077       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1078     }
1079     $this->reload();
1080     $this->DivListSystem->setEntries($this->terminals);
1081     return($this->DivListSystem->Draw());
1082   }
1085   /* Return departments, that will be included within snapshot detection */
1086   function get_used_snapshot_bases()
1087   {
1088     $tmp = array();
1090     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1092     $tabs = array(
1093         "terminal"        => get_ou('terminalou'),
1094         "workstation"     => get_ou('workstationou'),
1095         "incoming"        => get_ou('incomingou'),
1096         "server"          => get_ou('serverou'),
1097         "printer"         => get_ou('printerou'),
1098         "phone"           => get_ou('phoneou'),
1099         "winworkstation"  => get_winstations_ou(),
1100         "component"       => get_ou('componentou')
1101         ); 
1103     foreach($tabs as $acl_cat => $dn){
1105       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1106       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1107         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1108       }
1109     }
1110     return($tmp); 
1111   }
1114   function remove_from_parent()
1115   {
1116     /* Optionally execute a command after we're done */
1117     $this->postremove();
1118   }
1121   /* Save data to object */
1122   function save_object()
1123   {
1124     $this->DivListSystem->save_object();
1125     if(is_object($this->CopyPasteHandler)){
1126       $this->CopyPasteHandler->save_object();
1127     }
1128   }
1131   /* Check values */
1132   function check()
1133   {
1134   }
1137   /* Save to LDAP */
1138   function save()
1139   {
1140   }
1142   function adapt_from_template($dn, $skip= array())
1143   {
1144   }
1146   function password_change_needed()
1147   {
1148   }
1150   function reload()
1151   {
1152     /* some var init */
1153     $ui = get_userinfo();
1154     $res              = array();
1155     $this->terminals  = array();
1156     $userregex        = "";
1158     /* Set base for all searches */
1159     $base=  $this->DivListSystem->selectedBase;
1161     /* Prepare samba class name */
1162     $samba  ="";
1163     if ($this->DivListSystem->ShowWinWorkstations){
1164       if ($this->config->current['SAMBAVERSION'] == "3"){
1165         $samba= "sambaSamAccount";
1166       } else {
1167         $samba= "sambaAccount";
1168       }
1169     }
1171     /* This array represents the combination between checkboxes and search filters */
1172     $objs = array( 
1173         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1174         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1175         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1176         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1177         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1178         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1179         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1181     /* Include the 'Display Systems of user' attribute */ 
1182     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1183       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1184     }
1186     /* Attributes to fetch */
1187     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1188     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1190     /* Add FAIstate to attributes if FAI is activated */
1191     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1192     if(!empty($tmp)){
1193       $sys_attrs[] = "FAIstate";
1194     }    
1196     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1197     foreach($objs as $checkBox => $oc){
1198       if($this->DivListSystem->$checkBox){
1199         if($this->DivListSystem->SubSearch){
1200           if($oc['CLASS'] != ""){
1201             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1202             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1203             $res = array_merge($res,$new_res);
1204           }
1205         }else{
1206           /* User filter? */
1207           if($oc['CLASS'] != ""){
1208             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1209             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1210           }
1211         }
1212       } 
1213     }
1215     /* Search for incoming objects */ 
1216     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1217     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1219     /* Get all gotoTerminal's */
1220     foreach ($res as $value){
1222       $tmp= $value['dn'];
1223       $add= "";
1225       /* Extract base */
1226       foreach($objs as $obj){
1227         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1228           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1229         }
1230       }
1232       /* Create a string containing the last part of the department. */
1233       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1234       if(empty($dn_name)){
1235         $dn_name = "/";
1236       }
1238       /* check if current object is a new one */
1239       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1240         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1241           $add= "- "._("New terminal");
1242         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1243           $add= "- "._("New workstation");
1244         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1245           $add= "- "._("Unknown device");
1246         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1247           $add= "- "._("New Device");
1248         }
1249       } 
1251       /* Detect type of object and create an entry for $this->terminals */
1252       $terminal = array();
1253       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1255         /* check acl */
1256         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1257         if($add != "" || preg_match("/r/",$acl)) {
1258           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1259             $terminal             = $value;
1260             $terminal['type']     = "T";
1261             $terminal['is_new']   = $add;
1262           } else {
1263             $terminal             = $value;
1264             $terminal['type']     = "D";
1265             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1266             $terminal['location'] = array_search($tmp, $this->config->departments); 
1267           }
1268         }
1269       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1271         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1272         if($add != "" || preg_match("/r/",$acl)) {
1273           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1274             $terminal             = $value;
1275             $terminal['type']     = "L";
1276             $terminal['is_new']   = $add;
1277           } else {
1278             $terminal             = $value;
1279             $terminal['type']     = "D";
1280             $terminal['location'] = array_search($tmp, $this->config->departments);
1281             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1282           }
1283           if (isset($value["FAIstate"][0])){
1284             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1285           }
1286         }
1287       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1288        
1289    
1290         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1291         if($add != "" || preg_match("/r/",$acl)) {
1293           $terminal             = $value;
1294           $terminal['type']     = "P";
1295         }
1296       } elseif (in_array_ics('goServer', $value["objectClass"])){
1298         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1299         if($add != "" || preg_match("/r/",$acl)) {
1301           $terminal             = $value;
1302           $terminal['type']     = "S";
1303           if (isset($value["FAIstate"][0])){
1304             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1305           }
1306         }
1307       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1309         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1310         if($add != "" || preg_match("/r/",$acl)) {
1312           $terminal             = $value;
1313           $terminal['type']     = "F";
1314         }
1315       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1317         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1318                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1319                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1320         if($add != "" || preg_match("/r/",$acl)) {
1322           $terminal = $value;
1323           $terminal['type']   = "Q";
1324           $terminal['is_new'] = $add;
1325         }
1326       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1328         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1329         if($add != "" || preg_match("/r/",$acl)) {
1331           $terminal             = $value;
1332           $terminal['type']     = "C";
1333         }
1334       } else{
1336         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1337         if (isset($value['sambaDomainName'])){
1338           $domain= " [".$value['sambaDomainName'][0]."]";
1339         } else {
1340           $domain= "";
1341         }
1342         $terminal=$value;
1343         $terminal['type']     ="W";
1344         $terminal['domain']   = $name.$domain;
1345       }
1347       if(count($terminal)){
1348         $this->terminals[]=$terminal;
1349       }
1350     }
1352     $tmp  =array();
1353     $tmp2 =array();
1354     foreach($this->terminals as $tkey => $val ){
1355       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1356       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1357     }
1358     natcasesort($tmp2);
1359     $this->terminals=array();
1360     foreach($tmp2 as $val){
1361       $this->terminals[]=$tmp[$val];
1362     }
1363     reset ($this->terminals);
1364   }
1366   function remove_lock()
1367   {
1368     if (isset($this->systab->dn)){
1369       del_lock ($this->systab->dn);
1370     }
1371   }
1374   function copyPasteHandling_from_queue($s_action,$s_entry)
1375   {
1376     /* Check if Copy & Paste is disabled */
1377     if(!is_object($this->CopyPasteHandler)){
1378       return("");
1379     }
1382     $tabs = array(
1383         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1384           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1385         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1386           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1387         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1388           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1389         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1390           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1391         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1392           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1393         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1394           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1396     /* Add a single entry to queue */
1397     if($s_action == "cut" || $s_action == "copy"){
1399       /* Cleanup object queue */
1400       $this->CopyPasteHandler->cleanup_queue();
1401       $dn     = $this->terminals[$s_entry]['dn'];
1402       $oc     = $this->terminals[$s_entry]['objectClass'];
1403       $type   = $this->get_system_type($this->terminals[$s_entry]);
1405       $tab_o  = $tabs[$type]['CLASS'];
1406       $tab_c  = $tabs[$type]['TABCLASS'];
1407       $acl    = $tabs[$type]['ACL'];
1409       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1410     }
1412     /* Add entries to queue */
1413     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1415       /* Cleanup object queue */
1416       $this->CopyPasteHandler->cleanup_queue();
1418       /* Add new entries to CP queue */
1419       foreach($this->list_get_selected_items() as $id){
1420         $dn = $this->terminals[$id]['dn'];
1421         $oc = $this->terminals[$id]['objectClass']; 
1422         $type = $this->get_system_type($this->terminals[$id]);
1424         if(isset($tabs[$type])){
1425           $tab_o  = $tabs[$type]['CLASS'];
1426           $tab_c  = $tabs[$type]['TABCLASS'];
1427           $acl    = $tabs[$type]['ACL'];
1429           if($s_action == "copy_multiple"){
1430             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1431           }
1432           if($s_action == "cut_multiple"){
1433             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1434           }
1435         }
1436       }
1437     }
1439     /* Start pasting entries */
1440     if($s_action == "editPaste"){
1441       $this->start_pasting_copied_objects = TRUE;
1442     }
1443   
1444     /* Return C&P dialog */
1445     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1447       /* Get dialog */
1448       $data = $this->CopyPasteHandler->execute();
1449       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1451       /* Return dialog data */
1452       if(!empty($data)){
1453         return($data);
1454       }
1455     }
1457     /* Automatically disable status for pasting */
1458     if(!$this->CopyPasteHandler->entries_queued()){
1459       $this->start_pasting_copied_objects = FALSE;
1460     }
1461     return("");
1462   }
1465   function get_system_type($attrs)
1466   {
1467     $classes = $attrs['objectClass'];
1469     $type= "";
1470     if (in_array_ics('ieee802Device', $classes)){
1471       $type= "component";
1472     }elseif (in_array_ics('gotoTerminal', $classes)){
1473       $type= "terminal";
1474     }elseif (in_array_ics('gotoWorkstation', $classes)){
1475       $type= "workstation";
1476     }elseif (in_array_ics('gotoPrinter', $classes)){
1477       $type= "printer";
1478     }elseif (in_array_ics('goFonHardware', $classes)){
1479       $type= "phone";
1480     }elseif (in_array_ics('goServer', $classes)){
1481       $type= "server";
1482     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1483       $type= "ArpNewDevice";
1484     }elseif (in_array_ics('GOhard', $classes)){
1485       $type= "NewDevice";
1486     }elseif (in_array_ics('sambaAccount', $classes) ||
1487         in_array_ics('sambaSamAccount', $classes)){
1488       $type= "winstation";
1489     }
1490     return ($type);
1491   }
1494   function convert_list($input)
1495   {
1496     $temp= "";
1497     $conv= array(       
1498         "NQ" => array("select_newsystem.png",_("New system from incoming")),
1499         "D" => array("select_default.png",_("Template")),
1500         "T" => array("select_terminal.png",_("Terminal")),
1501         "L" => array("select_workstation.png",_("Workstation")),
1502         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1503         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1504         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1505         "F" => array("select_phone.png",_("Phone")),
1506         "S" => array("select_server.png",_("Server")),
1507         "GS" => array("select_server_green.png",_("Server is installing")),
1508         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1509         "RS" => array("select_server_red.png",_("Server installation failed")),
1510         "W" => array("select_winstation.png",_("Win workstation")),
1511         "C" => array("select_component.png",_("Network device")),
1512         "NT"=> array("select_new_terminal.png",_("New terminal")),
1513         "NL"=> array("select_new_workstation.png",_("New workstation")),
1514         "P" => array("select_printer.png",_("Printer")));
1516     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1517       $input['type']="N".$input['type'];
1518     }
1519     foreach ($conv  as $key => $value){
1520       if($input['type']==$key){
1521         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1522         $tmp['class']=$key;
1523         return $tmp;
1524       }
1525     }
1526   }
1528   
1529   function getState($type, $state)
1530   {
1531     switch (preg_replace('/:.*$/', '', $state)) {
1532       case 'installing':
1533                 $type= 'G'.$type;
1534                 break;
1535       case 'error':
1536                 $type= 'R'.$type;
1537                 break;
1538       case 'install':
1539       case 'sysinfo':
1540       case 'softupdate':
1541       case 'scheduledupdate':
1542                 $type= 'Y'.$type;
1543                 break;
1544     }
1547     return ($type);
1548   }
1551   function list_get_selected_items()
1552   {
1553     $ids = array();
1554     foreach($_POST as $name => $value){
1555       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1556         $id   = preg_replace("/^item_selected_/","",$name);
1557         $ids[$id] = $id;
1558       }
1559     }
1560     return($ids);
1561   }
1564   /* !! Incoming dummy acls, required to defined acls for incoming objects
1565    */
1566   static function plInfo()
1567   {
1568     return (array(
1569           "plShortName"   => _("Incoming objects"),
1570           "plDescription" => _("Incoming objects"),
1571           "plSelfModify"  => FALSE,
1572           "plDepends"     => array(),
1573           "plPriority"    => 99,
1574           "plSection"     => array("administration"),
1575           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1576                                                           "objectClass"  => "")),
1577           "plProvidedAcls"=> array()
1578             
1579           ));
1580   }
1583   
1587 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1588 ?>