Code

b93f4c5d89a049915e019ffdbab293c7f2ca201f
[gosa.git] / plugins / admin / systems / class_systemManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31   /* Definitions */
32   var $plHeadline= "Systems";
33   var $plDescription= "This does something";
34   var $departments=array();
36   /* Dialog attributes */
37   var $systab= NULL;
38   var $terminals= array();
39   var $ui= NULL;
40   var $acl= "";
41   var $DivListSystem;
42   var $image_creation_log ="";
44   function systems ($config, $ui)
45   {
46     /* Save configuration for internal use */
47     $this->config= $config;
48     $this->ui= $ui;
50     /* Creat dialog object */
51     $this->DivListSystem = new divListSystem($this->config,$this);
52   }
54   function execute()
55   {
56     /* Call parent execute */
57     plugin::execute();
59     $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
61     /********************
62       Check for functional posts, edit|delete|add|... system devices 
63      ********************/
64     $s_action     = "";                       // Contains the action to proceed
65     $s_entry      = "";                       // The value for s_action
66     $base_back    = "";                       // The Link for Backbutton
67     $smarty       = get_smarty();
69     /* Test Posts */
70     foreach($_POST as $key => $val){
71       // Post for delete
72       if(preg_match("/user_del.*/",$key)){
73         $s_action = "del";
74         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
75         // Post for edit
76       }elseif(preg_match("/user_edit_.*/",$key)){
77         $s_action="edit";
78         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
79         // Post for new
80       }elseif(preg_match("/user_new.*/",$key)){
81         $s_action="new";
82       }elseif(preg_match("/user_tplnew.*/i",$key)){
83         $s_action="new_tpl";
84       }elseif(preg_match("/user_setpwd_.*/i",$key)){
85         $s_action="change_pw";
86         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
87       }elseif(preg_match("/gen_cd_.*/i",$key)){
88         $s_action="gen_cd";
89         $s_entry  = preg_replace("/gen_cd_/i","",$key);
90       }elseif(preg_match("/newsystem_.*/i",$key)){
91         $s_action="newsystem";
92         $s_entry  = preg_replace("/newsystem_/i","",$key);
93       }
94     }
96     /* Incoming handling  
97      * If someone made a systemtype and ogroup selection 
98      * Display the new requested entry type ... servtab  in case of server and so on.
99      */
100     if(isset($_POST['SystemTypeChoosen'])){
101       $s_action = "SelectedSystemType";
102       $s_entry  = $_POST['SystemType'];
103       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
104       $this->systab = NULL;
105     }
107     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
108     $s_entry  = preg_replace("/_.$/","",$s_entry);
110     /* Edit was requested by pressing the name(link) of an item */
111     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
112       $s_action ="edit";
113       $s_entry  = $_GET['id'];
114     }
116     /* Check for exeeded sizelimit */
117     if (($message= check_sizelimit()) != ""){
118       return($message);
119     }
121     /* Try to get informations about what kind of system to create */
122     if ($s_action=="new") {
123       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
124     }
126     /********************
127       Create new system ...   
128      ********************/
129     /* Create new default terminal 
130      * Or create specified object of selected system type, from given incoming object  
131      */
133     $save_object_directly = false;
134     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
135       $save_object_directly = true;
136     }
137     
138     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
140       /* If the current entry is an incoming object 
141        * $sw = System type as posted in new incoming handling dialog 
142        */ 
143       if($s_action == "SelectedSystemType") {
144         $sw         = $s_entry;
145       }else{
146         if(isset($_POST['system'])){
147           $sw = $_POST['system'];
148         }else{
149           $sw = $s_entry;
150         }
151         $this->dn= "new";
152       }
153       $this->acl= array(":all");
154       $tabs = array(
155           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs"),
156           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs"),
157           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs"),
158           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs"),
159           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs"),
160           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
162       if(isset($tabs[$sw])){
163         $class    = $tabs[$sw]["CLASS"];
164         $tabname  = $tabs[$sw]["TABNAME"];
165         $tabclass = $tabs[$sw]["TABCLASS"];
166         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
167         $this->systab->set_acl ($this->acl);
168         $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
169         $this->systab->base = $this->DivListSystem->selectedBase;
170       }
171     }
173     /********************
174       Edit system ...   
175      ********************/
177     /* User wants to edit data? */
178     if (($s_action == "edit") && (!isset($this->systab->config))){
180       $this->dn= $this->terminals[$s_entry]['dn'];
182       /* Check locking, save current plugin in 'back_plugin', so
183          the dialog knows where to return. */
184       if (($user= get_lock($this->dn)) != ""){
185         return(gen_locked_message ($user, $this->dn));
186       }
188       /* Set up the users ACL's for this 'dn' */
189       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
191       /* Find out more about the object type */
192       $ldap= $this->config->get_ldap_link();
193       $ldap->cat($this->dn, array('objectClass'));
194       $attrs= $ldap->fetch();
195       $type= $this->get_system_type($attrs['objectClass']);
197       /* Lock the current entry, so everyone will get the
198          above dialog */
199       $tabs = array(
200           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
201           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
202           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
203           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
204           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
205           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
206           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
209       if($type == "NewDevice"){
210         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
211       }elseif(isset($tabs[$type])){
213         $class    = $tabs[$type]["CLASS"];
214         $tabclass = $tabs[$type]["TABCLASS"];
216         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
217         $this->systab->set_acl($acl);
218         $_SESSION['objectinfo']= $this->dn;
219         add_lock ($this->dn, $this->ui->dn);
220       }else{ 
221         print_red (_("You can't edit this object type yet!"));
222         del_lock($this->dn);
223       }
224     }
226     /********************
227       Create FAI CD ...   
228      ********************/
229     if ($s_action=="gen_cd"){
230       $this->dn= $this->terminals[$s_entry]['dn'];
231       $_SESSION['objectinfo']= $this->dn;
232       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
233     }
235     /* Start CD-Creation */
236     if (isset($_POST["cd_create"])){
237       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
238       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
239     }
240   
241     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
243       /* Initialize some attributes  */
244       $this->image_creation_log = 
246 GOsa - FAI image 
247 Date        : ".date("d.m.Y - H:i:s")."
248 User-cn     : ".$this->ui->cn."
249 User-dn     : ".$this->ui->dn."
251 Object-dn   : ".$this->dn."
253 /* Script returned : */
254 ";
256       $download_button = "<a href='?plug=".$_GET['plug']."&amp;download_image_log' class='center' >".
257                            "<img src='images/save.png' border=0 class='center'>".
258                         _("Use this link to download the logfile")."</a>";
260       $return_button   = "<a href='?plug=".$_GET['plug']."' target='parent' class='center'> ".
261                          "  <img src='images/list_reload.png' border=0 class='center'>".
262                          _("Back to work")."</a>";
264       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
266       /* Get and check command */
267       $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
268 //      $command = "/bin/sh /home/hickert/gen_stuff.sh";
269       if (check_command($command)){
270         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
272         /* Print out html introduction */
273         echo '<!-- headers.tpl--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
274                 "http://www.w3.org/TR/html4/transitional.dtd">
275                 <html><head><title></title><style type="text/css">@import url("themes/default/style.css");</style>';
276         echo "<script language=\"javascript\" src=\"include/focus.js\" type=\"text/javascript\"></script>";
277         echo "</head>";
278         echo "<body style='background: none;'>
279                 <script language=\"javascript\" type=\"text/javascript\">
280                   document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
281                 </script>
282               <pre>";
284         /* Open process handle and check if it is a valid process */
285         $process= proc_open($command, $dsc, $pipes, '/tmp');
286         if (is_resource($process)) {
287           fclose($pipes[0]);
289           /* Print out returned lines && write JS to scroll down each line */
290           while (!feof($pipes[1])){
291             $cur_dat = fgets($pipes[1], 1024);
292             $this->image_creation_log .= $cur_dat;
293             echo $cur_dat;
294             echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
295             flush();
296           }
297         }
298     
299         /* Get error string && close streams */
300         $buffer= stream_get_contents($pipes[2]);
301         fclose($pipes[1]);
302         fclose($pipes[2]);
303         echo "</pre>";
304       
305         /* Check return code */ 
306         $ret= proc_close($process);
307         if ($ret == 0){
308   
309           /* No error */
310           $this->image_creation_log.="\n\nSuccessfull finished image creation.\n\n";
311         } else {
312   
313           /* Error */
314           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
315           echo "<pre style='color:red'>$buffer</pre>";
317           $this->image_creation_log.="\n\nImage creation failed. Please see report below : \n\n";
318           $this->image_creation_log.=$buffer."\n\n";
319         }
321         echo $download_button."<br><br>";
322         echo $return_button."<br>";
324       } else {
325         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
326         echo $tmp;
327       }
329       /* Scroll down completly */
330       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
331       echo "</body></html>";
332       flush();
333       exit;
334     }
337     /******************
338       FAI Image creation logfile requested 
339      ******************/
340     if(isset($_GET['download_image_log'])){
342       /* force download dialog */
343       header("Content-type: application/tiff\n");
344       if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
345           preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
346         header('Content-Disposition: filename="image.log"');
347       } else {
348         header('Content-Disposition: attachment; filename="image.log"');
349       }
350       header("Content-transfer-encoding: binary\n");
351       header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
352       header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
353       header("Cache-Control: no-cache");
354       header("Pragma: no-cache");
355       header("Cache-Control: post-check=0, pre-check=0");
357       echo $this->image_creation_log;
358  
359       exit();
360     }
361     
364     /********************
365       Change password ...   
366      ********************/
368     /* Set terminals root password */
369     if ($s_action=="change_pw"){
370       $this->dn= $this->terminals[$s_entry]['dn'];
371       $_SESSION['objectinfo']= $this->dn;
372       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
373     }
376     /********************
377       Password cahnge finish, but check if entered data is ok 
378      ********************/
380     /* Correctly specified? */
381     if (isset($_POST['password_finish'])){
382       if ($_POST['new_password'] != $_POST['repeated_password']){
383         print_red (_("Passwords entered as new and repeated do not match!"));
384         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
385       }
386     }
388     /********************
389       Password change finish
390      ********************/
392     /* Change terminal password */
393     if (isset($_POST['password_finish']) && 
394         $_POST['new_password'] == $_POST['repeated_password']){
396       /* Check if user is allowed to set password */
397       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
398       $acl= get_module_permission($acl, "terminal", $this->dn);
399       if (chkacl($acl, "password") != ""){
400         print_red (_("You are not allowed to set this systems password!"));
401       } else {
402         $ldap= $this->config->get_ldap_link();
403         $ldap->cd($this->dn);
405         $attrs= array();
406         if ($_POST['new_password'] == ""){
407           $attrs['gotoRootPasswd']= array();
408         } else {
409           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
410               substr(session_id(),0,2));
411         }
412         $ldap->modify($attrs);
413         gosa_log ("Password for '".$this->dn."' has been changed");
414       }
415       unset($_SESSION['objectinfo']);
416     }
419     /********************
420       Delete system cancel
421      ********************/
423     /* Delete terminal canceled? */
424     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
425       del_lock ($this->dn);
426       unset($_SESSION['objectinfo']);
427     }
430     /********************
431       Delete system, confirm dialog
432      ********************/
434     /* Remove terminal was requested */
435     if ($s_action=="del"){
437       /* Get 'dn' from posted termlinst */
438       $this->dn= $this->terminals[$s_entry]['dn'];
440       /* Load permissions for selected 'dn' and check if
441          we're allowed to remove this 'dn' */
442       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
443       $this->acl= get_module_permission($acl, "terminal", $this->dn);
444       if (chkacl($this->acl, "delete") == ""){
446         /* Check locking, save current plugin in 'back_plugin', so
447            the dialog knows where to return. */
448         if (($user= get_lock($this->dn)) != ""){
449           return(gen_locked_message ($user, $this->dn));
450         }
452         /* Lock the current entry, so nobody will edit it during deletion */
453         add_lock ($this->dn, $this->ui->dn);
454         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
455         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
456       } else {
458         /* Obviously the user isn't allowed to delete. Show message and
459            clean session. */
460         print_red (_("You are not allowed to delete this component!"));
461       }
462     }
465     /********************
466       Delete system, confirmed
467      ********************/
468     /* Confirmation for deletion has been passed. Terminal should be deleted. */
469     if (isset($_POST['delete_terminal_confirm'])){
471       /* Some nice guy may send this as POST, so we've to check
472          for the permissions again. */
473       if (chkacl($this->acl, "delete") == ""){
475         /* Find out more about the object type */
476         $ldap= $this->config->get_ldap_link();
477         $ldap->cat($this->dn, array('objectClass'));
478         $attrs= $ldap->fetch();
479         $type= $this->get_system_type($attrs['objectClass']);
481         $tabs = array(
482             "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
483             "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
484             "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
485             "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
486             "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
487             "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
488             "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
490         /* get object type */
491         $tabtype  = "termtabs";
492         $tabobj   = "TERMTABS";
493         if(isset($tabs[$type])){
494           $tabtype = $tabs[$type]['TABCLASS'];
495           $tabobj  = $tabs[$type]['CLASS'];
496         }
498         /* Delete request is permitted, perform LDAP action */
499         if($tabtype=="phonetabs"){
500           $this->systab= new $tabtype($this->config,
501               $this->config->data['TABS'][$tabobj], $this->dn);
502           $this->systab->set_acl(array($this->acl));
503           $this->systab->by_object['phonegeneric']->remove_from_parent ();
504         }else{  
505           $this->systab= new $tabtype($this->config,
506               $this->config->data['TABS'][$tabobj], $this->dn);
507           $this->systab->set_acl(array($this->acl));
508           $this->systab->delete();
509 #$this->systab->by_object['termgeneric']->remove_from_parent ();
510         }
511         unset ($this->systab);
512         gosa_log ("System object'".$this->dn."' has been removed");
513         $this->systab= NULL;
515         /* Terminal list has changed, reload it. */
516       } else {
518         /* Normally this shouldn't be reached, send some extra
519            logs to notify the administrator */
520         print_red (_("You are not allowed to delete this component!"));
521         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
522             "deletion.");
523       }
525       /* Remove lock file after successfull deletion */
526       del_lock ($this->dn);
527     }
530     /********************
531       Edit system type finished, check if everything went ok 
532      ********************/
533     /* Finish user edit is triggered by the tabulator dialog, so
534        the user wants to save edited data. Check and save at this
535        point. */
536     if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
538       /* Check tabs, will feed message array */
539       $message = array();
540       if(!$save_object_directly){
541         $message = $this->systab->check();
542       }else{
543         $found = false;
544   
545         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
546         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
547           if(isset($this->systab->by_object[$tab]->gotoMode)) {
548             $found = true;
549             $this->systab->by_object[$tab]->gotoMode = $value;
550           }
551         }   
552         if(!$found){
553           print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
554         }
556       }
557       /* Save, or display error message? */
558       if (count($message) == 0){
560         /* Save terminal data to ldap */
561         if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
562           foreach (array("workservice", "termservice") as $cls){
563             if (isset($this->systab->by_object[$cls])){
564               $this->systab->by_object[$cls]->gotoXMouseport= "";
565               $this->systab->by_object[$cls]->gotoXMouseType= "";
566               $this->systab->by_object[$cls]->gotoXResolution= "";
567               $this->systab->by_object[$cls]->gotoXColordepth= "";
568             }
569           }
570         }
572         $this->systab->save();
573         gosa_log ("System object'".$this->dn."' has been saved");
575         /* Incoming behavior; you can select a system type and an ogroup membership. 
576          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
577          * Check if we must add the new object to an object group.
578          * 
579          * If this is done, delete the old incoming entry... it is still there, because this is a new 
580          * entry and not an edited one, so we will delete it.
581          */
583         if(isset($_SESSION['SelectedSystemType'])){
584           $SelectedSystemType= $_SESSION['SelectedSystemType'];
585           unset($_SESSION['SelectedSystemType']);
586           if($SelectedSystemType['ogroup'] != "none"){
587             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
588             if($og){
589               $og->AddDelMembership($this->systab->dn);
590               $og->save();
591             }
592           }
593           if(!isset($ldap)){
594             $ldap = $this->config->get_ldap_link();
595           }
596           $ldap->cd ($this->dn);
597           $ldap->cat($this->dn, array('dn'));  
598           if(count($ldap->fetch())){
599             $ldap->cd($this->dn);
600             $ldap->rmDir($this->dn);
601           }
602           $ldap->cd($this->config->current['BASE']);
603         }
605         /* Terminal has been saved successfully, remove lock from
606            LDAP. */
607         if ($this->dn != "new"){
608           del_lock ($this->dn);
609         }
611         unset ($this->systab);
612         $this->systab= NULL;
613         unset($_SESSION['objectinfo']);
614       } else {
615         /* Ok. There seem to be errors regarding to the tab data,
616            show message and continue as usual. */
617         show_errors($message);
618       }
619     }
621     /********************
622       Edit system was canceled 
623      ********************/
624     /* Cancel dialogs */
625     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
626       if (isset($this->systab)){
627         del_lock ($this->systab->dn);
628         unset ($this->systab);
629       }
630       $this->systab= NULL;
631       unset($_SESSION['objectinfo']);
633       /* Remove ogroup selection, which was set while editing a new incoming entry */
634       if(isset($_SESSION['SelectedSystemType'])){
635         unset($_SESSION['SelectedSystemType']);
636       }
637     }
639     /********************
640       Display edit dialog, or some other
641      ********************/
643     /* Show tab dialog if object is present */
644     if (isset($this->systab->config)){
645       $display= $this->systab->execute();
647       /* Don't show buttons if tab dialog requests this */
648       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
649         $display.= "<p style=\"text-align:right\">\n";
650         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
651         $display.= "&nbsp;\n";
652         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
653         $display.= "</p>";
654       }
655       return ($display);
656     }
658     /* Display dialog with system list */
659     $this->DivListSystem->parent = $this;
660     $this->DivListSystem->execute();
662     /* Add departments if subsearch is disabled */
663     if(!$this->DivListSystem->SubSearch){
664       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
665     }
666     $this->reload();
667     $this->DivListSystem->setEntries($this->terminals);
668     return($this->DivListSystem->Draw());
669   }
673   function remove_from_parent()
674   {
675     /* Optionally execute a command after we're done */
676     $this->postremove();
677   }
680   /* Save data to object */
681   function save_object()
682   {
683     $this->DivListSystem->save_object();
684   }
687   /* Check values */
688   function check()
689   {
690   }
693   /* Save to LDAP */
694   function save()
695   {
696   }
698   function adapt_from_template($dn)
699   {
700   }
702   function password_change_needed()
703   {
704   }
706   function reload()
707   {
708     /* Load terminal shortcuts */
709     $responsible= array();
710     foreach ($this->config->departments as $key => $value){
711       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
712             "terminal", $value) == "#all#"){
713         $responsible[$key]= $value;
714       }
715     }
717     /* some var init */
718     $res              = array();
719     $this->terminals  = array();
720     $userregex        = "";
722     /* Set base for all searches */
723     $base=  $this->DivListSystem->selectedBase;
725     /* Prepare samba class name */
726     $samba  ="";
727     if ($this->DivListSystem->ShowWinWorkstations){
728       if ($this->config->current['SAMBAVERSION'] == "3"){
729         $samba= "sambaSamAccount";
730       } else {
731         $samba= "sambaAccount";
732       }
733     }
735     /* This array represents the combination between checkboxes and search filters */
736     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
737         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
738         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
739         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
740         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
741         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
742         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
744     /* Include the 'Display Systems of user' attribute */ 
745     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
746       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
747     }
749     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
750     foreach($objs as $checkBox => $oc){
751       if($this->DivListSystem->$checkBox){
752         if($this->DivListSystem->SubSearch){
753           if($oc['CLASS'] != ""){
754             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
755             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
756                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
757           }
758         }else{
759           /* User filter? */
760           if($oc['CLASS'] != ""){
761             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
762             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
763                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
764           }
765         }
766       } 
767     }
769     /* Search for incoming objects */ 
770     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
771     $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
772           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
774     /* Get all gotoTerminal's */
775     foreach ($res as $value){
777       $tmp= $value['dn'];
778       $add= "";
780       /* Extract base */
781       foreach($objs as $obj){
782         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
783           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
784         }
785       }
787       /* check if current object is a new one */
788       if (preg_match ("/,ou=incoming,/i", $tmp)){
789         if (in_array_ics('gotoTerminal', $value['objectClass'])){
790           $add= "- "._("New terminal");
791         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
792           $add= "- "._("New workstation");
793         }elseif (in_array_ics('GOhard', $value['objectClass'])){
794           $add= "- "._("New Device");
795         }
796       } 
798       /* Create a string containing the last part of the department. */
799       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
800       if(empty($dn_name)){
801         $dn_name = "/";
802       }
803       
804       /* Detect type of object and create an entry for $this->terminals */
805       $terminal = array();
806       if ((in_array ($tmp, $responsible)) || ($add != "")){
807         if (in_array_ics('gotoTerminal', $value["objectClass"])){
808           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
809             $terminal             = $value;
810             $terminal['type']     = "T";
811             $terminal['is_new']   = $add;
812           } else {
813             $terminal             = $value;
814             $terminal['type']     = "D";
815             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
816             $terminal['location'] = array_search($tmp, $this->config->departments); 
817           }
818         } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
819           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
820             $terminal             = $value;
821             $terminal['type']     = "L";
822             $terminal['is_new']   = $add;
823           } else {
824             $terminal             = $value;
825             $terminal['type']     = "D";
826             $terminal['location'] = array_search($tmp, $this->config->departments);
827             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
828           }
829           if (isset($value["FAIstate"][0])){
830             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
831           }
832         } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
833           $terminal             = $value;
834           $terminal['type']     = "P";
835         } elseif (in_array_ics('goServer', $value["objectClass"])){
836           $terminal             = $value;
837           $terminal['type']     = "S";
838           if (isset($value["FAIstate"][0])){
839             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
840           }
841         } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
842           $terminal             = $value;
843           $terminal['type']     = "F";
844         }elseif (in_array_ics("GOhard",$value['objectClass'])){
845           $terminal = $value;
846           $terminal['type']   = "Q";
847           $terminal['is_new'] = $add;
848         } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
849           $terminal             = $value;
850           $terminal['type']     = "C";
851         } else{
852           $name= preg_replace('/\$$/', '', $value['cn'][0]);
853           if (isset($value['sambaDomainName'])){
854             $domain= " [".$value['sambaDomainName'][0]."]";
855           } else {
856             $domain= "";
857           }
858           $terminal=$value;
859           $terminal['type']     ="W";
860           $terminal['domain']   = $name.$domain;
861         }
862         $this->terminals[]=$terminal;
863       }
864     }
866     $tmp=array();
867     foreach($this->terminals as $tkey => $val ){
868       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
869     }
870     ksort($tmp);
871     $this->terminals=array();
872     foreach($tmp as $val){
873       $this->terminals[]=$val;
874     }
875     reset ($this->terminals);
876   }
878   function remove_lock()
879   {
880     if (isset($this->systab->dn)){
881       del_lock ($this->systab->dn);
882     }
883   }
886   function get_system_type($classes)
887   {
888     $type= "";
889     if (in_array_ics('ieee802Device', $classes)){
890       $type= "component";
891     }elseif (in_array_ics('gotoTerminal', $classes)){
892       $type= "terminal";
893     }elseif (in_array_ics('gotoWorkstation', $classes)){
894       $type= "workstation";
895     }elseif (in_array_ics('gotoPrinter', $classes)){
896       $type= "printer";
897     }elseif (in_array_ics('goFonHardware', $classes)){
898       $type= "phone";
899     }elseif (in_array_ics('goServer', $classes)){
900       $type= "server";
901     }elseif (in_array_ics('GOhard', $classes)){
902       $type= "NewDevice";
903     }elseif (in_array_ics('sambaAccount', $classes) ||
904         in_array_ics('sambaSamAccount', $classes)){
905       $type= "winstation";
906     }
907     return ($type);
908   }
911   function convert_list($input)
912   {
913     $temp= "";
914     $conv= array(       
915         "NQ" => array("select_newsystem.png",_("New System from incoming")),
916         "D" => array("select_default.png",_("Template")),
917         "T" => array("select_terminal.png",_("Terminal")),
918         "L" => array("select_workstation.png",_("Workstation")),
919         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
920         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
921         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
922         "F" => array("select_phone.png",_("Phone")),
923         "S" => array("select_server.png",_("Server")),
924         "GS" => array("select_server_green.png",_("Server is installing")),
925         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
926         "RS" => array("select_server_red.png",_("Server installation failed")),
927         "W" => array("select_winstation.png",_("Winstation")),
928         "C" => array("select_component.png",_("Network Device")),
929         "NT"=> array("select_new_terminal.png",_("New Terminal")),
930         "NL"=> array("select_new_workstation.png",_("New Workstation")),
931         "P" => array("select_printer.png",_("Printer")));
933     if((isset($input['is_new']))&&(!empty($input['is_new']))){
934       $input['type']="N".$input['type'];
935     }
936     foreach ($conv  as $key => $value){
937       if($input['type']==$key){
938         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
939         $tmp['class']=$key;
940         return $tmp;
941       }
942     }
943   }
945   
946   function getState($type, $state)
947   {
948     switch (preg_replace('/:.*$/', '', $state)) {
949       case 'installing':
950                 $type= 'G'.$type;
951                 break;
952       case 'error':
953                 $type= 'R'.$type;
954                 break;
955       case 'install':
956                 $type= 'Y'.$type;
957                 break;
958       case 'sysinfo':
959                 $type= 'Y'.$type;
960                 break;
961       case 'softupdate':
962                 $type= 'Y'.$type;
963                 break;
964     }
967     return ($type);
968   }
972 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
973 ?>