Code

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