Code

Updated systems to support opsi.
[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 $plIcon         = "plugins/systems/images/plugin.png";
29   var $departments    = array();
31   /* Dialog attributes */
32   var $systab   = NULL;
33   var $terminals= array();
34   var $ui       = NULL;
35   var $DivListSystem;
36   var $start_pasting_copied_objects = FALSE;
37   var $CopyPasteHandler   = NULL;
39   /* Arp hanlding activated */
40   var $arp_handling_active = FALSE;
41   var $last_action = "";
43   var $dns = array();
45   var $system_activation_object = ""; // The object to activate (NewDevice)
46   var $fai_activated  = FALSE;
47   var $si_active      = FALSE;
49   var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
51   var $opsi = NULL;
53   function systems (&$config, $ui)
54   {
55     /* Save configuration for internal use */
56     $this->config= $config;
57     $this->ui= $ui;
59     /* Add FAIstate to attributes if FAI is activated */
60     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
61     if(!empty($tmp)){
62       $this->fai_activated = TRUE;
63     }
65     /* Creat dialog object */
66     $this->DivListSystem = new divListSystem($this->config,$this);
68     /* Copy & Paste enabled ?*/
69     if ($this->config->get_cfg_value("enablecopypaste") == "true"){
70       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
71     }
73     /* Check whether the arp handling active or not */
74     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
75       $this->arp_handling_active = TRUE;
76     }
78     /* Check if we are able to communicate with the GOsa supprot daemon 
79      */
80     if(class_available("gosaSupportDaemon")){
81       $o = new gosaSupportDaemon();
82       $this->si_active = $o->connect() && class_available("DaemonEvent");
83     }
85     /* Check if we are able to communicate with the GOsa supprot daemon 
86      */
87     if(class_available("opsi")){
88       $this->opsi = new opsi($this->config);
89     }
90   }
93   function execute()
94   {
95     /* Call parent execute */
96     plugin::execute();
98     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
100     /********************
101       Check for functional posts, edit|delete|add|... system devices 
102      ********************/
103     $s_action     = "";                       // Contains the action to proceed
104     $s_entry      = "";                       // The value for s_action
105     $base_back    = "";                       // The Link for Backbutton
106     $smarty       = get_smarty();
108     /* Test Posts */
109     foreach($_POST as $key => $val){
110       // Post for delete
111       if(preg_match("/system_del.*/",$key)){
112         $s_action = "del";
113         $s_entry  = preg_replace("/system_del_/i","",$key);
114         // Post for edit
115       }elseif(preg_match("/system_edit_.*/",$key)){
116         $s_action="edit";
117         $s_entry  = preg_replace("/system_edit_/i","",$key);
118         // Post for new
119       }elseif(preg_match("/system_new.*/",$key)){
120         $s_action="new";
121       }elseif(preg_match("/system_tplnew.*/i",$key)){
122         $s_action="new_tpl";
123       }elseif(preg_match("/system_setpwd_.*/i",$key)){
124         $s_action="change_pw";
125         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
126       }elseif(preg_match("/gen_cd_.*/i",$key)){
127         $s_action="gen_cd";
128         $s_entry  = preg_replace("/gen_cd_/i","",$key);
129       }elseif(preg_match("/^copy_.*/",$key)){
130         $s_action="copy";
131         $s_entry  = preg_replace("/^copy_/i","",$key);
132       }elseif(preg_match("/^cut_.*/",$key)){
133         $s_action="cut";
134         $s_entry  = preg_replace("/^cut_/i","",$key);
135       }
136     }
137    
138     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
139     $s_entry  = preg_replace("/_.$/","",$s_entry);
141     /* Edit was requested by pressing the name(link) of an item */
142     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
143       $s_action ="edit";
144       $s_entry  = $_GET['id'];
145     }
146     /* Create options */
147     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
148       $s_action = "newsystem";
149       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
150     }
152     /* handle C&P from layers menu */
153     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
154       $s_action = "copy_multiple";
155     }
156     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
157       $s_action = "cut_multiple";
158     }
159     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
160       $s_action = "editPaste";
161     }
163     /* Handle daemon events */
164     if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
165       $s_action = $_POST['menu_action'];
166     }
167     
168     /* Handle daemon events */
169     if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
170       $s_action = $_POST['menu_action'];
171     }
173     /* handle remove from layers menu */
174     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
175       $s_action = "del_multiple";
176     }
177     
178     /* Handle instant actions from layers menu */
179     foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
180             if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
181               $s_action = "${act}_multiple";
182             }
183     }
185     /* Activate multiple machines */
186     if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
187       $s_action = "activate_multiple";
188     }
190     /* Check for exeeded sizelimit */
191     if (($message= check_sizelimit()) != ""){
192       return($message);
193     }
195     /* Try to get informations about what kind of system to create */
196     if ($s_action=="new") {
197       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
198     }
200     /* Incoming handling  
201      * If someone made a systemtype and ogroup selection 
202      * Display the new requested entry type ... servtab  in case of server and so on.
203      */
204     if(isset($_POST['SystemTypeChoosen'])){
205       $s_action = "SelectedSystemType";
206     }
208     /********************
209       Copy & Paste Handling  ...
210      ********************/
212     /* Display the copy & paste dialog, if it is currently open */
213     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
214     if($ret){
215       return($ret);
216     }
217   
219     /********************
220       Create FAI CD ...   
221      ********************/
222     if ($s_action=="gen_cd"){
223       $this->dn= $this->terminals[$s_entry]['dn'];
224       session::set('objectinfo',$this->dn);
225       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
226     }
229     /* Start CD-Creation */
230     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
231       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
232       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
233     }
236     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
238       $return_button   = "<form method='get' action='main.php' target='_parent'>
239         <input type='submit' value='"._("Back")."'>
240         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
241         </form>";
243       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
245       /* Get and check command */
246       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
247       
248       if (check_command($command)){
249         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
251         /* Print out html introduction */
252         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
253           <html>
254           <head>
255           <title></title>
256           <style type="text/css">@import url("themes/default/style.css");</style>
257           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
258           </head>
259           <body style="background: none; margin:4px;" id="body" >
260           <pre>';
262         /* Open process handle and check if it is a valid process */
263         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
264         if (is_resource($process)) {
265           fclose($pipes[0]);
267           /* Print out returned lines && write JS to scroll down each line */
268           while (!feof($pipes[1])){
269             $cur_dat = fgets($pipes[1], 1024);
270             echo $cur_dat;
271             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
272             flush();
273           }
274         }
276         /* Get error string && close streams */
277         $buffer= stream_get_contents($pipes[2]);
279         fclose($pipes[1]);
280         fclose($pipes[2]);
281         echo "</pre>";
283         /* Check return code */
284         $ret= proc_close($process);
285         if ($ret != 0){
286           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
287           echo "<pre style='color:red'>$buffer</pre>";
288         }
292         echo $return_button."<br>";
294       } else {
295         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
296         echo $tmp;
297       }
299       /* Scroll down completly */
300       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
301       echo '</body></html>';
302       flush();
303       exit;
304     }
307     /********************
308       New Device hanlding  (Ogroup/System select dialog.)
309      ********************/
311     if($s_action == "SelectedSystemType"){
313       /* Possible destination system types 
314        */
315       $tabs = $this->get_tab_defs();
317       /* Remember dialog selection.
318        */
319       $selected_group = $_POST['ObjectGroup'];
320       $selected_system = $_POST['SystemType'];
322       $this->systab = NULL;
324       /* Check if system type exists. It should! */
325       if(isset($tabs[$selected_system])){
327         /* Get tab informations */
328         $class    = $tabs[$selected_system]["CLASS"];
329         $tabname  = $tabs[$selected_system]["TABNAME"];
330         $tabclass = $tabs[$selected_system]["TABCLASS"];
331         $acl_cat  = $tabs[$selected_system]["ACLC"];
334         if(!class_available($tabclass)){
335           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
336         }else{
338           /* Go through all objects that should be activated */
339           foreach($this->system_activation_object as $key => $dn){
341             /* Remove entry from list, to avoid page-reload problems */
342             unset($this->system_activation_object[$key]);
344             /* Load permissions for selected 'dn' and check if
345                we're allowed to create this 'dn' */
346             $this->dn = $dn;
347             $ui       = get_userinfo();
348             $tabacl   = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
350             /* We are allowed to create the requested system type */
351             if(preg_match("/c/",$tabacl)){
352               $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
353               $this->systab->set_acl_base($this->DivListSystem->selectedBase);
354               $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
355               $this->systab->base = $this->DivListSystem->selectedBase;
358               if($selected_group != "none"){
360                 /*******
361                  * Set gotoMode to active if we there was an ogroup selected. 
362                  */
363                 $found = false;
364                 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
365                   if(isset($this->systab->by_object[$tab]->gotoMode)) {
366                     $found = true;
367                     $this->systab->by_object[$tab]->gotoMode = $value;
368                   }
369                 }
370                 if(!$found){
371                   msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
372                 }
374                 /*******
375                  * Update object group membership
376                  */
377                 $og = new ogroup($this->config,$selected_group);
378                 if($og){
379                   $og->AddDelMembership($this->systab->dn);
380                   $og->save();
381                 }
383                 /*******
384                  * Set default system specific attributes 
385                  */
386                 foreach (array("workservice", "termservice") as $cls){
387                   if (isset($this->systab->by_object[$cls])){
388                     $this->systab->by_object[$cls]->gotoXMouseport= "";
389                     $this->systab->by_object[$cls]->gotoXMouseType= "";
390                     $this->systab->by_object[$cls]->gotoXResolution= "";
391                     $this->systab->by_object[$cls]->gotoXColordepth= "";
392                   }
393                 }
395                 // Enable activation
396                 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
397                   if (isset($this->systab->by_object[$cls])){
398                     $this->systab->by_object[$cls]->auto_activate= TRUE;
399                   }
400                 }
402                 // Enable sending of LDAP events
403                 if (isset($this->systab->by_object["workstartup"])){
404                   $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
405                 }
406               }
408               /* Don't save directly if there is no objectGroup selected.
409                  The user will then be able to configure the missing attributes 
410                  on his own.
411                */
412               if($selected_group != "none"){
413                 $this->systab->save();
414                 $this->systab = NULL;
416                 if(!isset($ldap)){
417                   $ldap = $this->config->get_ldap_link();
418                 }
419                 $ldap->cd ($this->dn);
420                 $ldap->cat($this->dn, array('dn'));
421                 if(count($ldap->fetch())){
422                   $ldap->cd($this->dn);
423                   $ldap->rmDir($this->dn);
424                 }
425               }
426             }else{
427               msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
428             }
429           }
430         }
431       }
432     }
435     if (isset($_POST['create_system'])||$s_action=="newsystem") {
436     
437       $this->last_action = "";
438   
439       /* If the current entry is an incoming object 
440        * $sw = System type as posted in new incoming handling dialog 
441        */ 
442       if(isset($_POST['system'])){
443         $sw = $_POST['system'];
444       }else{
445         $sw = $s_entry;
446       }
447       $this->dn= "new";
449       $tabs = $this->get_tab_defs();
451       if(isset($tabs[$sw])){
452         $class    = $tabs[$sw]["CLASS"];
453         $tabname  = $tabs[$sw]["TABNAME"];
454         $tabclass = $tabs[$sw]["TABCLASS"];
455         $acl_cat  = $tabs[$sw]["ACLC"];
457         /* Load permissions for selected 'dn' and check if
458            we're allowed to remove this 'dn' */
459         $ui       = get_userinfo();
460         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
461         if(preg_match("/c/",$tabacl)){
463           if(!class_available($tabclass)){
464             msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
465           }else{
466             $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
467             $this->systab->set_acl_base($this->DivListSystem->selectedBase);
468             $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
469             $this->systab->base = $this->DivListSystem->selectedBase;
470           }
471         }else{
472           msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
473         }
474       }
475     }
478     /********************
479       System activation
480      ********************/
482     /* User wants to edit data? */
483     if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
484       $this->system_activation_object = array();
485       foreach($this->list_get_selected_items() as $id) {
486         $obj = $this->terminals[$id];
487         $type= $this->get_system_type($obj);
488         if($type == "NewDevice"){
489           $this->system_activation_object[] = $obj['dn'];
490         }
491       }
492       if(count($this->system_activation_object)){
493         $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
494       }
495     }
498     /********************
499       Edit system ...   
500      ********************/
502     /* User wants to edit data? */
503     if (($s_action == "edit") && (!isset($this->systab->config))){
504       $this->last_action = "";
505       $this->dn= $this->terminals[$s_entry]['dn'];
507       /* Check locking, save current plugin in 'back_plugin', so
508          the dialog knows where to return. */
509       if (($user= get_lock($this->dn)) != ""){
510         return(gen_locked_message ($user, $this->dn));
511       }
513       /* Find out more about the object type */
514       $attrs = $this->terminals[$s_entry];
515       $type= $this->get_system_type($attrs);
516      
517       /* Lock the current entry, so everyone will get the
518          above dialog */
519       $tabs = $this->get_tab_defs();
521       if($type == "ArpNewDevice"){
522         if(!class_available("ArpNewDeviceTabs")){
523           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
524         }else{
525           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
526         }
527       }elseif($type == "NewDevice"){
528         if(!class_available("SelectDeviceType")){
529           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
530         }else{
531           $this->system_activation_object= array($this->dn);
532           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
533         }
534       }elseif(isset($tabs[$type])){
536         $class    = $tabs[$type]["CLASS"];
537         $acl_cat  = $tabs[$type]["ACLC"];
538         $tabclass = $tabs[$type]["TABCLASS"];
540         if(!class_available($tabclass)){
541           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
542         }else{
543           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
544           $this->systab->set_acl_base($this->dn);
545           session::set('objectinfo',$this->dn);
546           add_lock ($this->dn, $this->ui->dn);
547         }
548       }else{ 
549         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
550         $this->remove_lock();
551       }
552     }
555     /********************
556       Change password ...   
557      ********************/
559     /* Set terminals root password */
560     if ($s_action=="change_pw"){
561       $tabs = $this->get_tab_defs();
563       $dn   = $this->terminals[$s_entry]['dn'];
564       $type = $this->get_system_type($this->terminals[$s_entry]);
566       $class    = $tabs[$type]["CLASS"];
567       $acl      = $tabs[$type]["ACL"];
568       $tabclass = $tabs[$type]["TABCLASS"];
569       $ui       = get_userinfo();
570       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
571       if(preg_match("/w/",$tabacl)){
572         $this->dn= $this->terminals[$s_entry]['dn'];
573         session::set('objectinfo',$this->dn);
574         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
575       }else{
576         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
577       }
578     }
581     /********************
582       Password change finish, but check if entered data is ok 
583      ********************/
585     /* Correctly specified? */
586     if (isset($_POST['password_finish'])){
587       if ($_POST['new_password'] != $_POST['repeated_password']){
588         msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
589         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
590       }
591     }
593     /********************
594       Password change finish
595      ********************/
597     /* Change terminal password */
598     if (isset($_POST['password_finish']) && 
599         $_POST['new_password'] == $_POST['repeated_password']){
601       /* Check if user is allowed to set password */
602       $tabs = $this->get_tab_defs();
604       $type = "";
605       foreach($this->terminals as $terminal){
606         if($terminal['dn'] == $this->dn){
607           $type  = $this->get_system_type($terminal);
608           break;
609         } 
610       }
612       /* Type detected */
613       $allow_for = array("terminal","workstation","server","component");
614       if(!empty($type) && in_array($type,$allow_for)){
616         /* Get infos */
617         $plug     = $tabs[$type]["PLUG"];
618         $class    = $tabs[$type]["CLASS"];
619         $acl      = $tabs[$type]["ACL"];
620         $tabclass = $tabs[$type]["TABCLASS"];
621     
622         /* Get acls */
623         $ui       = get_userinfo();
624         $tabacl   = $ui->get_permissions($this->dn,$acl,"userPassword");
626         /* Check acls */
627         if(preg_match("/w/",$tabacl)){
628           $ldap = $this->config->get_ldap_link();
629           $ldap->cd($this->dn);
630           $ldap->cat($this->dn);
631           $old_attrs = $ldap->fetch();
633           $attrs= array();
634           if ($_POST['new_password'] == ""){
636             /* Remove password attribute 
637              */
638             if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
639               $attrs['objectClass'] = array();
640               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
641                 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
642                   $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
643                 }
644               }
645             }
646             $attrs['userPassword']= array();
647           } else {
649             /* Add/modify password attribute 
650              */
651             if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
652               $attrs['objectClass'] = array();
653               for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
654                 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
655               }
656               $attrs['objectClass'][] = "simpleSecurityObject";
657             }
659             if(class_available("passwordMethodCrypt")){
660               $pwd_m = new passwordMethodCrypt($this->config);
661               $pwd_m->set_hash("crypt/md5");
662               $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
663             }else{
664               msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
665               $attrs = array();
666             }
667           }
668           $ldap->modify($attrs);
669           if (!$ldap->success()){
670             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
671           }else{
672             if(class_available($plug)){
673               $p = new $plug($this->config,$this->dn);
674               $p->handle_post_events("modify");
675             }
676           }
677   
678           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
679         }else{
680           msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
681         }
682       }else{
683         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
684       }
685       session::un_set('objectinfo');
686     }
689     /********************
690       Delete system cancel
691      ********************/
693     /* Delete terminal canceled? */
694     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
695       $this->remove_lock();
696       session::un_set('objectinfo');
697     }
700     /********************
701       Action(s) for MULTIPLE
702      ********************/
704     /********************
705       SCHEDULE action in GOsa Daemon
706      ********************/
708     if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
709       $this->dns = array();
710       $ids = $this->list_get_selected_items();
712       if(count($ids) && class_available("DaemonEvent")){
713         $mac= array();
715         $ldap = $this->config->get_ldap_link();
716         foreach($ids as $id){
717           $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
718           $attrs= $ldap->fetch();
719           if (isset($attrs['macAddress'][0])){
720             $mac[]= $attrs['macAddress'][0];
721           }
722         }
723         $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
724         $type = preg_replace("/^[a-z]*_event_/","",$s_action);
725         $o_queue = new gosaSupportDaemon();
727         /* Skip installation or update trigerred events, 
728          *  if this entry is currently processing.
729          */
730         if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
731           foreach($mac as $key => $mac_address){
732             foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
734               $entry['STATUS'] = strtoupper($entry['STATUS']);
735               if($entry['STATUS'] == "PROCESSING" && 
736                   isset($events['QUEUED'][$entry['HEADERTAG']]) && 
737                   in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
738                 unset($mac[$key]);
740                 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
741                 break;
742               }
743             }
744           }
745         }        
747         /* Prepare event to be added 
748          */
749         if(count($mac) && isset($events['BY_CLASS'][$type])){
750           $event = $events['BY_CLASS'][$type];
751           $this->systab = new $event['CLASS_NAME']($this->config);
752           $this->systab->add_targets($mac);
753           if(preg_match("/trigger_event/",$s_action)){
754             $this->systab->set_type(TRIGGERED_EVENT);
755           }else{
756             $this->systab->set_type(SCHEDULED_EVENT);
757           }
758         }
759       }
760     }
762     /* Insert scheduled events into queue */
763     if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
764       $this->systab->save_object();
766       /* Save event 
767        */
768       if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
769         $o_queue = new gosaSupportDaemon();
770         $o_queue->append($this->systab);
771         if($o_queue->is_error()){
772           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
773         }else{
774           $this->systab = FALSE;
775         }
776       }
777       if(isset($_POST['abort_event_dialog'])){
778         $this->systab = FALSE;
779       }
780     }
783     /********************
784       Delete MULTIPLE entries requested, display confirm dialog
785      ********************/
787     if ($s_action=="del_multiple" || $s_action == "del"){
788       $this->dns = array();
790       if($s_action == "del_multiple"){
791         $ids = $this->list_get_selected_items();
792       }else{
793         $ids = array($s_entry);
794       }
796       $ui = get_userinfo();
797       $tabs = $this->get_tab_defs();
799       if(count($ids)){
801         $disallowed = array();
802         foreach($ids as $id){
804           /* Get 'dn' from posted termlinst */
805           $attrs  = $this->terminals[$id];
806           $type   = $this->get_system_type($attrs);
807           $dn     = $attrs['dn'];
808           $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
809           if(preg_match("/d/",$acl)){
810             $this->dns[$id] = $dn;
811           }else{
812             $disallowed[] = $dn;
813           }
814         }
816         if(count($disallowed)){
817           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
818         }
820         if(count($this->dns)){
822           if ($user= get_multiple_locks($this->dns)){
823             return(gen_locked_message($user,$this->dns));
824           }
826           $dns_names = array();
827           foreach($this->dns as $dn){
828             add_lock ($dn, $this->ui->dn);
829             $dns_names[] = @LDAP::fix($dn);
830           }
832           /* Lock the current entry, so nobody will edit it during deletion */
833           $smarty->assign("warning", msgPool::deleteInfo($dns_names));
834           $smarty->assign("multiple", true);
835           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
836         }
837       }
838     }
841     /********************
842       Delete MULTIPLE entries confirmed
843      ********************/
845     /* Confirmation for deletion has been passed. Users should be deleted. */
846     if (isset($_POST['delete_multiple_system_confirm'])){
848       $ui = get_userinfo();
849       $tabs = $this->get_tab_defs();
851       /* Remove user by user and check acls before removeing them */
852       foreach($this->dns as $key => $dn){
854         /* Get 'dn' from posted termlinst */
855         $attrs    = $this->terminals[$key];
856         $type= $this->get_system_type($attrs);
858         /* get object type */
859         $tabtype  = "termtabs";
860         $tabobj   = "TERMTABS";
861         $tabacl   = "";
862         if(isset($tabs[$type])){
863           $tabtype = $tabs[$type]['TABCLASS'];
864           $tabobj  = $tabs[$type]['CLASS'];
865           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
867           /* Load permissions for selected 'dn' and check if
868              we're allowed to remove this 'dn' */
869           if(preg_match("/d/",$tabacl)){ 
871             /* Delete request is permitted, perform LDAP action */
872             if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
873               $this->systab= new termgeneric($this->config, $dn);
874               $this->systab->set_acl_base($dn);
875               $this->systab->remove_from_parent();
876             }elseif($tabtype=="phonetabs"){
877               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
878               $this->systab->set_acl_base($dn);
879               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
880             }else{
881               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
882               $this->systab->set_acl_base($dn);
883               $this->systab->delete();
884             }
885             unset ($this->systab);
886             $this->systab= NULL;
888           } else {
889             /* Normally this shouldn't be reached, send some extra
890                logs to notify the administrator */
891             msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
892             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
893           }
894         }
896         /* Remove lock file after successfull deletion */
897         $this->remove_lock();
898         $this->dns = array();
899       }
900     }
902     /********************
903       Delete MULTIPLE entries Canceled
904      ********************/
906     /* Remove lock */
907    if(isset($_POST['delete_multiple_system_cancel'])){
909      /* Remove lock file after successfull deletion */
910      $this->remove_lock();
911      $this->dns = array();
912    }
915     /********************
916       Edit system type finished, check if everything went ok
917      ********************/
918     /* Finish user edit is triggered by the tabulator dialog, so
919        the user wants to save edited data. Check and save at this
920        point. */
922     /* Dirty workaround - MSG_DIALOG - OK
923       If a message dialog is shown and we press 'OK'
924        then try to save again.
925      */
926     foreach($_POST as $name => $value){
927       if(preg_match("/^MSG_OK/",$name)){
928         $_POST[$this->last_action] = TRUE;
929       }
930     }
932     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
934       /* If the save routine gets interrupted by a confirm dialog, 
935           store last action so we can trigger it again after 'Ok' was pressed.
936          (This is the case if a system gets modified while it is installing - GOsa si)
937        */
938       $this->last_action = ""; 
939       if(isset($_POST['edit_finish'])){
940         $this->last_action = "edit_finish"; 
941       }elseif(isset($_POST['edit_apply'])){
942         $this->last_action = "edit_apply";
943       }
945       /* Check tabs, will feed message array */
946       $message = $this->systab->check();
948       /* Save, or display error message? */
949       if (count($message) == 0){
952         $this->systab->save();
954         /* Terminal has been saved successfully, remove lock from LDAP. */
955         if (!isset($_POST['edit_apply'])){
956           if ($this->dn != "new"){
957             $this->remove_lock();
958           }
960           unset ($this->systab);
961           $this->systab= NULL;
962           session::un_set('objectinfo');
963         }else{
964       
965           /* Reinitialize tab */
966           if($this->systab instanceof tabs){
967             $this->systab->re_init();
968           }
969         }
970       } else {
971         /* Ok. There seem to be errors regarding to the tab data,
972            show message and continue as usual. */
973         msg_dialog::displayChecks($message);
974       }
975     }
978     /********************
979       Edit system was canceled 
980      ********************/
981     /* Cancel dialogs */
982     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
983       if (isset($this->systab)){
984         $this->remove_lock();
985         unset ($this->systab);
986       }
987       $this->systab= NULL;
988       session::un_set('objectinfo');
989     }
991     /********************
992       Display edit dialog, or some other
993      ********************/
995     /* Show tab dialog if object is present */
996     if (isset($this->systab->config)){
997       $display= $this->systab->execute();
999       /* Don't show buttons if tab dialog requests this */
1001       $dialog     = FALSE;
1002       $hide_apply = $this->dn == "new";
1003       $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1004       if(is_object($this->systab) && !isset($this->systab->by_object)){
1005         $dialog = TRUE;
1006         $hide_apply = TRUE;
1007       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1008         $dia = $this->systab->by_object[$this->systab->current]->dialog;
1009         if($dia === TRUE || is_object($dia)){
1010           $dialog = TRUE;
1011         }  
1012       }
1013       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
1014         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1015         $dialog = TRUE;
1016       }
1018       if (!$dialog){
1019         $display.= "<p style=\"text-align:right\">\n";
1020         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1021         $display.= "&nbsp;\n";
1022         if (!$hide_apply){
1023           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1024           $display.= "&nbsp;\n";
1025         }
1026         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1027         $display.= "</p>";
1028       }
1029       return ($display);
1030     }
1032     /* Check if there is a snapshot dialog open */
1033     $base = $this->DivListSystem->selectedBase;
1034     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1035       return($str);
1036     }
1038     /* Display dialog with system list */
1039     $this->DivListSystem->parent = $this;
1040     $this->DivListSystem->execute();
1042     /* Add departments if subsearch is disabled */
1043     if(!$this->DivListSystem->SubSearch){
1045       /* Add FAIstate to attributes if FAI is activated */
1046       if($this->fai_activated){
1047         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1048       }else{
1049         $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1050       }
1051     }
1052     $this->reload();
1053     $this->DivListSystem->setEntries($this->terminals);
1054     return($this->DivListSystem->Draw());
1055   }
1058   /* Return departments, that will be included within snapshot detection */
1059   function get_used_snapshot_bases()
1060   {
1061     $tmp = array();
1063     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1065     $tabs = array(
1066         "terminal"        => get_ou('terminalou'),
1067         "workstation"     => get_ou('workstationou'),
1068         "incoming"        => get_ou('incomingou'),
1069         "server"          => get_ou('serverou'),
1070         "printer"         => get_ou('printerou'),
1071         "phone"           => get_ou('phoneou'),
1072         "winworkstation"  => get_winstations_ou(),
1073         "component"       => get_ou('componentou')
1074         ); 
1076     foreach($tabs as $acl_cat => $dn){
1078       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1079       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1080         $tmp[] = $dn.$this->DivListSystem->selectedBase;
1081       }
1082     }
1083     return($tmp); 
1084   }
1087   function remove_from_parent()
1088   {
1089     /* Optionally execute a command after we're done */
1090     $this->postremove();
1091   }
1094   /* Save data to object */
1095   function save_object()
1096   {
1097     $this->DivListSystem->save_object();
1098     if(is_object($this->CopyPasteHandler)){
1099       $this->CopyPasteHandler->save_object();
1100     }
1101   }
1104   /* Check values */
1105   function check()
1106   {
1107   }
1110   /* Save to LDAP */
1111   function save()
1112   {
1113   }
1115   function adapt_from_template($dn, $skip= array())
1116   {
1117   }
1119   function password_change_needed()
1120   {
1121   }
1123   function reload()
1124   {
1125     /* some var init */
1126     $ui = get_userinfo();
1127     $res              = array();
1128     $this->terminals  = array();
1129     $userregex        = "";
1131     /* Set base for all searches */
1132     $base=  $this->DivListSystem->selectedBase;
1134     /* Prepare samba class name */
1135     $samba  ="";
1136     if ($this->DivListSystem->ShowWinWorkstations){
1137       if ($this->config->get_cfg_value("sambaversion") == "3"){
1138         $samba= "sambaSamAccount";
1139       } else {
1140         $samba= "sambaAccount";
1141       }
1142     }
1144     /* This array represents the combination between checkboxes and search filters */
1145     $objs = array( 
1146         "ShowServers"        => array("TAB" => "servtabs",      "CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
1147         "ShowTerminals"      => array("TAB" => "termtabs",      "CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
1148         "ShowPrinters"       => array("TAB" => "printtabs",     "CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
1149         "ShowDevices"        => array("TAB" => "componenttabs", "CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
1150         "ShowPhones"         => array("TAB" => "phonetabs",     "CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
1151         "ShowWorkstations"   => array("TAB" => "worktabs",      "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1152         "ShowWinWorkstations"=> array("TAB" => "wintabs",       "CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
1154     /* Include the 'Display Systems of user' attribute */ 
1155     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1156       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1157     }
1159     /* Attributes to fetch */
1160     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1161     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1163     /* Add FAIstate to attributes if FAI is activated */
1164     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1165     if(!empty($tmp)){
1166       $sys_attrs[] = "FAIstate";
1167     }    
1169     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1170     foreach($objs as $checkBox => $oc){
1172       if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1173         if($this->DivListSystem->SubSearch){
1174           if($oc['CLASS'] != ""){
1175             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1176             $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1177             $res = array_merge($res,$new_res);
1178           }
1179         }else{
1180           /* User filter? */
1181           if($oc['CLASS'] != ""){
1182             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1183             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs,  GL_SIZELIMIT));
1184           }
1185         }
1186       } 
1187     }
1189     /* Search for incoming objects */ 
1190     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1191     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1193     /* Append opsi systems, the opsi extension have to installed.
1194      */
1195     if($this->opsi != NULL){
1196       $res = array_merge($res,$this->opsi->get_hosts_for_system_management());
1197       if($this->opsi->is_error()){
1198         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1199       }
1200     }
1201     
1202     /* Get all gotoTerminal's */
1203     foreach ($res as $value){
1205       $tmp= $value['dn'];
1206       $add= "";
1208       /* Extract base */
1209       foreach($objs as $obj){
1210         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1211           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1212         }
1213       }
1215       /* Create a string containing the last part of the department. */
1216       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1217       if(empty($dn_name)){
1218         $dn_name = "/";
1219       }
1221       /* check if current object is a new one */
1222       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1223         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1224           $add= "- "._("New terminal");
1225         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1226           $add= "- "._("New workstation");
1227         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1228           $add= "- "._("Unknown device");
1229         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1230           $add= "- "._("New Device");
1231         }
1232       } 
1234       /* Detect type of object and create an entry for $this->terminals */
1235       $terminal = array();
1237        if (in_array_ics('opsi_client', $value["objectClass"])){
1239          /* check acl */
1240          $terminal             = $value;
1241          $terminal['type']     = "O";
1243        } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1245         /* check acl */
1246         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1247         if($add != "" || preg_match("/r/",$acl)) {
1248           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1249             $terminal             = $value;
1250             $terminal['type']     = "T";
1251             $terminal['is_new']   = $add;
1252           } else {
1253             $terminal             = $value;
1254             $terminal['type']     = "D";
1255             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1256             $terminal['location'] = array_search($tmp, $this->config->departments); 
1257           }
1258         }
1259       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1261         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1262         if($add != "" || preg_match("/r/",$acl)) {
1263           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1264             $terminal             = $value;
1265             $terminal['type']     = "L";
1266             $terminal['is_new']   = $add;
1267           } else {
1268             $terminal             = $value;
1269             $terminal['type']     = "D";
1270             $terminal['location'] = array_search($tmp, $this->config->departments);
1271             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1272           }
1273 #          if (isset($value["FAIstate"][0])){
1274 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1275 #          }
1276         }
1277       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1278        
1279    
1280         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1281         if($add != "" || preg_match("/r/",$acl)) {
1283           $terminal             = $value;
1284           $terminal['type']     = "P";
1285         }
1286       } elseif (in_array_ics('goServer', $value["objectClass"])){
1288         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1289         if($add != "" || preg_match("/r/",$acl)) {
1291           $terminal             = $value;
1292           $terminal['type']     = "S";
1293 #          if (isset($value["FAIstate"][0])){
1294 #            $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1295 #          }
1296         }
1297       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1299         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1300         if($add != "" || preg_match("/r/",$acl)) {
1302           $terminal             = $value;
1303           $terminal['type']     = "F";
1304         }
1305       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1307         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1308                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1309                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1310         if($add != "" || preg_match("/r/",$acl)) {
1312           $terminal = $value;
1313           $terminal['type']   = "Q";
1314           $terminal['is_new'] = $add;
1315         }
1316       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1318         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1319         if($add != "" || preg_match("/r/",$acl)) {
1321           $terminal             = $value;
1322           $terminal['type']     = "C";
1323         }
1324       } else{
1326         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1327         if (isset($value['sambaDomainName'])){
1328           $domain= " [".$value['sambaDomainName'][0]."]";
1329         } else {
1330           $domain= "";
1331         }
1332         $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1333         if($add != "" || preg_match("/r/",$acl)) {
1334           $terminal=$value;
1335           $terminal['type']     ="W";
1336           $terminal['domain']   = $name.$domain;
1337         }
1338       }
1340       if(count($terminal)){
1341         $this->terminals[]=$terminal;
1342       }
1343     }
1345     $tmp  =array();
1346     $tmp2 =array();
1347     foreach($this->terminals as $tkey => $val ){
1348       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1349       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1350     }
1351     natcasesort($tmp2);
1352     $this->terminals=array();
1353     foreach($tmp2 as $val){
1354       $this->terminals[]=$tmp[$val];
1355     }
1356     reset ($this->terminals);
1357   }
1359   function remove_lock()
1360   {
1361     if (isset($this->systab->dn)){
1362       del_lock ($this->systab->dn);
1363     }
1364     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1365       del_lock($this->dn);
1366     }
1367     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1368       del_lock($this->dns);
1369     }
1370   }
1373   function copyPasteHandling_from_queue($s_action,$s_entry)
1374   {
1375     /* Check if Copy & Paste is disabled */
1376     if(!is_object($this->CopyPasteHandler)){
1377       return("");
1378     }
1380     $ui = get_userinfo();
1381     
1382     $tabs = $this->get_tab_defs();
1384     /* Add a single entry to queue */
1385     if($s_action == "cut" || $s_action == "copy"){
1387       /* Cleanup object queue */
1388       $this->CopyPasteHandler->cleanup_queue();
1389       $dn     = $this->terminals[$s_entry]['dn'];
1390       $oc     = $this->terminals[$s_entry]['objectClass'];
1391       $type   = $this->get_system_type($this->terminals[$s_entry]);
1393       $tab_o  = $tabs[$type]['CLASS'];
1394       $tab_c  = $tabs[$type]['TABCLASS'];
1395       $acl_c  = $tabs[$type]['TABNAME'];
1396       $acl    = $tabs[$type]['ACLC'];
1398       if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1399         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1400       }
1401       if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1402         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1403       }
1404     }
1406     /* Add entries to queue */
1407     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1409       /* Cleanup object queue */
1410       $this->CopyPasteHandler->cleanup_queue();
1412       /* Add new entries to CP queue */
1413       foreach($this->list_get_selected_items() as $id){
1414         $dn = $this->terminals[$id]['dn'];
1415         $oc = $this->terminals[$id]['objectClass']; 
1416         $type = $this->get_system_type($this->terminals[$id]);
1418         if(isset($tabs[$type])){
1419           $tab_o  = $tabs[$type]['CLASS'];
1420           $tab_c  = $tabs[$type]['TABCLASS'];
1421           $acl_c  = $tabs[$type]['TABNAME'];
1422           $acl    = $tabs[$type]['ACLC'];
1424           if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){ 
1425             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1426           }
1427           if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1428             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1429           }
1430         }
1431       }
1432     }
1434     /* Start pasting entries */
1435     if($s_action == "editPaste"){
1436       $this->start_pasting_copied_objects = TRUE;
1437     }
1438   
1439     /* Return C&P dialog */
1440     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1442       /* Get dialog */
1443       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1444       $data = $this->CopyPasteHandler->execute();
1446       /* Return dialog data */
1447       if(!empty($data)){
1448         return($data);
1449       }
1450     }
1452     /* Automatically disable status for pasting */
1453     if(!$this->CopyPasteHandler->entries_queued()){
1454       $this->start_pasting_copied_objects = FALSE;
1455     }
1456     return("");
1457   }
1460   function get_system_type($attrs)
1461   {
1462     $classes = $attrs['objectClass'];
1464     $type= "";
1465     if (in_array_ics('gosa_opsi_client', $classes)){
1466       $type= "opsi_client";
1467     }elseif (in_array_ics('ieee802Device', $classes)){
1468       $type= "component";
1469     }elseif (in_array_ics('gotoTerminal', $classes)){
1470       $type= "terminal";
1471     }elseif (in_array_ics('gotoWorkstation', $classes)){
1472       $type= "workstation";
1473     }elseif (in_array_ics('gotoPrinter', $classes)){
1474       $type= "printer";
1475     }elseif (in_array_ics('goFonHardware', $classes)){
1476       $type= "phone";
1477     }elseif (in_array_ics('goServer', $classes)){
1478       $type= "server";
1479     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1480       $type= "ArpNewDevice";
1481     }elseif (in_array_ics('GOhard', $classes)){
1482       $type= "NewDevice";
1483     }elseif (in_array_ics('sambaAccount', $classes) ||
1484         in_array_ics('sambaSamAccount', $classes)){
1485       $type= "winstation";
1486     }
1487     return ($type);
1488   }
1491   function convert_list($input)
1492   {
1493     $temp= "";
1495     $conv= array(
1496         "D" => array("plugins/systems/images/select_default.png",_("Template")),
1497         "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1498         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1499         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1501         "W" => array("plugins/systems/images/select_winstation.png",_("Win workstation")),
1503         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1504         "S" => array("plugins/systems/images/select_server.png",_("Server")),
1505         "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1507         "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1508         "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1509         "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1511         "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1512         "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1513         "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1515         "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1516         "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1518         "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1519         "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1520         "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1522     /* Add opsi client to system types */
1523     if($this->opsi != NULL){
1524         $conv["O"] = array("plugins/systems/images/select_default.png",_("Opsi client"));
1525     }
1527     /* Use locked icons 
1528      */
1529     if( in_array($input['type'],array("S","T","L")) && 
1530         isset($input['gotoMode'][0]) && 
1531         preg_match("/locked/",$input['gotoMode'][0])){
1532       $input['type'].="X";
1533     } elseif(in_array($input['type'],array("S","L")) &&
1534         isset($input['FAIstate'][0])){
1536     /* Add FAI state icons 
1537      */
1538       $type= "";
1539       switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1540         case 'error':
1541           $type= 'E';
1542           break;
1543         case 'installing':
1544         case 'install':
1545         case 'sysinfo':
1546         case 'softupdate':
1547         case 'scheduledupdate':
1548           $type= 'B';
1549           break;
1550       }
1552       $input['type'].= $type;
1553     }   
1555     /* Use new images if object is from incoming 
1556      */
1557     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1558       $input['type']="N".$input['type'];
1559     }
1561     /* Check which flags this objects uses 
1562      */
1563     foreach ($conv  as $key => $value){
1564       $found = TRUE;
1565       if(strlen($key) != strlen($input['type'])) {
1566         $found = FALSE;
1567       }
1568       for($i = 0 ; $i < strlen($key) ; $i++){
1569         if(!preg_match("/".$key[$i]."/",$input['type'])){
1570           $found = FALSE;
1571         }
1572      }
1574       if($found){
1575         $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1576         $tmp['class']=$key;
1577         return $tmp;
1578       }
1579     }
1580   }
1583   function list_get_selected_items()
1584   {
1585     $ids = array();
1586     foreach($_POST as $name => $value){
1587       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1588         $id   = preg_replace("/^item_selected_/","",$name);
1589         $ids[$id] = $id;
1590       }
1591     }
1592     return($ids);
1593   }
1596   public function get_tab_defs()
1597   {
1598     $tabs = array(
1599         "incoming"    => array(
1600           "CLASS"     => "",
1601           "TABNAME"   => "",
1602           "TABCLASS"  => "",
1603           "ACLC"      => "incoming",
1604           "ACL"       => "incoming/systems"),
1606         "ArpNewDevice"=> array(
1607           "CLASS"     => "TERMTABS",
1608           "TABNAME"   => "termgeneric" ,
1609           "TABCLASS"  => "termtabs",
1610           "ACLC"      => "incoming",
1611           "ACL"       => "incoming/systems"),
1613         "NewDevice"   => array(
1614           "CLASS"     => "TERMTABS",
1615           "TABNAME"   => "termgeneric",
1616           "TABCLASS"  => "termtabs",
1617           "ACLC"      => "incoming",
1618           "ACL"       => "incoming/systems"),
1620         "terminal"    => array(
1621             "CLASS"     => "TERMTABS",
1622             "TABNAME"   => "termgeneric",
1623             "TABCLASS"  => "termtabs",
1624             "ACLC"      => "terminal",
1625             "ACL"       => "terminal/termgeneric"),
1627         "workstation" =>  array(
1628             "CLASS"   => "WORKTABS",
1629             "TABNAME" => "workgeneric",
1630             "TABCLASS"=> "worktabs",
1631             "ACLC"    => "workstation",
1632             "ACL"     => "workstation/workgeneric" ),
1634         "server"      => array(
1635             "CLASS"   => "SERVTABS",
1636             "TABNAME" => "servgeneric",
1637             "TABCLASS"=> "servtabs",
1638             "ACLC"    => "server",
1639             "ACL"     => "server/servgeneric"),
1641         "printer"     => array(
1642             "CLASS"   => "PRINTTABS",
1643             "TABNAME" => "printgeneric",
1644             "TABCLASS"=> "printtabs",
1645             "ACLC"    => "printer",
1646             "ACL"     => "printer/printgeneric"),
1648         "phone"       => array(
1649             "CLASS"   => "PHONETABS",
1650             "TABNAME" => "phoneGeneric",
1651             "TABCLASS"=> "phonetabs",
1652             "ACLC"    => "phone",
1653             "ACL"     => "phone/phoneGeneric"),
1655         "winstation"  => array(
1656             "CLASS"   => "WINTABS",
1657             "TABNAME" => "wingeneric",
1658             "TABCLASS"=> "wintabs",
1659             "ACLC"    => "winworkstation",
1660             "ACL"     => "winworkstation/wingeneric"),
1662         "component"   => array(
1663             "CLASS"   => "COMPONENTTABS",
1664             "TABNAME" => "componentGeneric",
1665             "TABCLASS"=> "componenttabs",
1666             "ACLC"    => "component",
1667             "ACL"     => "component/componentGeneric"));
1669     if($this->opsi != NULL){
1670       $tabs["opsi_client"] = array(
1671           "CLASS"   => "OPSITABS",
1672           "TABNAME" => "opsi_generic" ,
1673           "TABCLASS"=> "opsi_tabs",
1674           "ACLC"    => "opsi" ,
1675           "ACL"     => "opsi/opsi_generic");
1676     }
1678     return($tabs);
1679   }
1683   /* !! Incoming dummy acls, required to defined acls for incoming objects
1684    */
1685   static function plInfo()
1686   {
1687     return (array(
1688           "plShortName"   => _("Incoming objects"),
1689           "plDescription" => _("Incoming objects"),
1690           "plSelfModify"  => FALSE,
1691           "plDepends"     => array(),
1692           "plPriority"    => 99,
1693           "plSection"     => array("administration"),
1694           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1695                                                           "objectClass"  => "")),
1696           "plProvidedAcls"=> array()
1697             
1698           ));
1699   }
1702 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1703 ?>