Code

ac36a2034057729f02f3d917f9962884c62053dd
[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 $DivListSystem;
42   function systems ($config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= $config;
46     $this->ui= $ui;
48     /* Creat dialog object */
49     $this->DivListSystem = new divListSystem($this->config,$this);
50   }
52   function execute()
53   {
54     /* Call parent execute */
55     plugin::execute();
57     $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/");
59     /********************
60       Check for functional posts, edit|delete|add|... system devices 
61      ********************/
62     $s_action     = "";                       // Contains the action to proceed
63     $s_entry      = "";                       // The value for s_action
64     $base_back    = "";                       // The Link for Backbutton
65     $smarty       = get_smarty();
67     /* Test Posts */
68     foreach($_POST as $key => $val){
69       // Post for delete
70       if(preg_match("/system_del.*/",$key)){
71         $s_action = "del";
72         $s_entry  = preg_replace("/system_del_/i","",$key);
73         // Post for edit
74       }elseif(preg_match("/system_edit_.*/",$key)){
75         $s_action="edit";
76         $s_entry  = preg_replace("/system_edit_/i","",$key);
77         // Post for new
78       }elseif(preg_match("/system_new.*/",$key)){
79         $s_action="new";
80       }elseif(preg_match("/system_tplnew.*/i",$key)){
81         $s_action="new_tpl";
82       }elseif(preg_match("/system_setpwd_.*/i",$key)){
83         $s_action="change_pw";
84         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
85       }elseif(preg_match("/gen_cd_.*/i",$key)){
86         $s_action="gen_cd";
87         $s_entry  = preg_replace("/gen_cd_/i","",$key);
88       }elseif(preg_match("/newsystem_.*/i",$key)){
89         $s_action="newsystem";
90         $s_entry  = preg_replace("/newsystem_/i","",$key);
91       }
92     }
94     /* Incoming handling  
95      * If someone made a systemtype and ogroup selection 
96      * Display the new requested entry type ... servtab  in case of server and so on.
97      */
98     if(isset($_POST['SystemTypeChoosen'])){
99       $s_action = "SelectedSystemType";
100       $s_entry  = $_POST['SystemType'];
101       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
102       $this->systab = NULL;
103     }
105     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
106     $s_entry  = preg_replace("/_.$/","",$s_entry);
108     /* Edit was requested by pressing the name(link) of an item */
109     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
110       $s_action ="edit";
111       $s_entry  = $_GET['id'];
112     }
114     /* Check for exeeded sizelimit */
115     if (($message= check_sizelimit()) != ""){
116       return($message);
117     }
119     /* Try to get informations about what kind of system to create */
120     if ($s_action=="new") {
121       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
122     }
125     /********************
126       Create FAI CD ...   
127      ********************/
128     if ($s_action=="gen_cd"){
129       $this->dn= $this->terminals[$s_entry]['dn'];
130       $_SESSION['objectinfo']= $this->dn;
131       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
132     }
135     /* Start CD-Creation */
136     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
137       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
138       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
139     }
142     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
144       $return_button   = "<form method='get' action='main.php' target='_parent'>
145         <input type='submit' value='"._("Back")."'>
146         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
147         </form>";
149       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
151       /* Get and check command */
152       $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
153       if (check_command($command)){
154         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
156         /* Print out html introduction */
157         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
158           <html>
159           <head>
160           <title></title>
161           <style type="text/css">@import url("themes/default/style.css");</style>
162           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
163           </head>
164           <body style="background: none; margin:4px;" id="body" >
165           <pre>';
167         /* Open process handle and check if it is a valid process */
168         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
169         if (is_resource($process)) {
170           fclose($pipes[0]);
172           /* Print out returned lines && write JS to scroll down each line */
173           while (!feof($pipes[1])){
174             $cur_dat = fgets($pipes[1], 1024);
175             echo $cur_dat;
176             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
177             flush();
178           }
179         }
181         /* Get error string && close streams */
182         $buffer= stream_get_contents($pipes[2]);
184         fclose($pipes[1]);
185         fclose($pipes[2]);
186         echo "</pre>";
188         /* Check return code */
189         $ret= proc_close($process);
190         if ($ret != 0){
191           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
192           echo "<pre style='color:red'>$buffer</pre>";
193         }
197         echo $return_button."<br>";
199       } else {
200         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
201         echo $tmp;
202       }
204       /* Scroll down completly */
205       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
206       echo '</body></html>';
207       flush();
208       exit;
209     }
212     /********************
213       Create new system ...   
214      ********************/
215     /* Create new default terminal 
216      * Or create specified object of selected system type, from given incoming object  
217      */
218     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
220       /* If the current entry is an incoming object 
221        * $sw = System type as posted in new incoming handling dialog 
222        */ 
223       if($s_action == "SelectedSystemType") {
224         $sw         = $s_entry;
225       }else{
226         if(isset($_POST['system'])){
227           $sw = $_POST['system'];
228         }else{
229           $sw = $s_entry;
230         }
231         $this->dn= "new";
232       }
233       $tabs = array(
234           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
235           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
236           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
237           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
238           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
239           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
241       if(isset($tabs[$sw])){
242         $class    = $tabs[$sw]["CLASS"];
243         $tabname  = $tabs[$sw]["TABNAME"];
244         $tabclass = $tabs[$sw]["TABCLASS"];
245         $acl_cat  = $tabs[$sw]["ACL"];
247         /* Load permissions for selected 'dn' and check if
248            we're allowed to remove this 'dn' */
249         $ui       = get_userinfo();
250         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
251         if(preg_match("/c/",$tabacl)){
252           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
253           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
254           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
255           $this->systab->base = $this->DivListSystem->selectedBase;
256         }else{
257           print_red(_("You are not allowed to create a new object of this type."));
258         }
259       }
260     }
262     /********************
263       Edit system ...   
264      ********************/
266     /* User wants to edit data? */
267     if (($s_action == "edit") && (!isset($this->systab->config))){
269       $this->dn= $this->terminals[$s_entry]['dn'];
271       /* Check locking, save current plugin in 'back_plugin', so
272          the dialog knows where to return. */
273       if (($user= get_lock($this->dn)) != ""){
274         return(gen_locked_message ($user, $this->dn));
275       }
277       /* Find out more about the object type */
278       $ldap= $this->config->get_ldap_link();
279       $ldap->cat($this->dn, array('objectClass'));
280       $attrs= $ldap->fetch();
281       $type= $this->get_system_type($attrs['objectClass']);
283       /* Lock the current entry, so everyone will get the
284          above dialog */
285       $tabs = array(
286           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
287           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
288           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
289           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
290           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
291           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
292           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
295       if($type == "NewDevice"){
296         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
297       }elseif(isset($tabs[$type])){
299         $class    = $tabs[$type]["CLASS"];
300         $acl_cat  = $tabs[$type]["ACL"];
301         $tabclass = $tabs[$type]["TABCLASS"];
303         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
304         $this->systab->set_acl_base($this->dn);
305         $_SESSION['objectinfo']= $this->dn;
306         add_lock ($this->dn, $this->ui->dn);
307       }else{ 
308         print_red (_("You can't edit this object type yet!"));
309         del_lock($this->dn);
310       }
311     }
314     /********************
315       Change password ...   
316      ********************/
318     /* Set terminals root password */
319     if ($s_action=="change_pw"){
320       $tabs = array(
321           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
322           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
324       $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
325       $class    = $tabs[$type]["CLASS"];
326       $tabname  = $tabs[$type]["TABNAME"];
327       $acl_cat  = $tabs[$type]["ACL"];
328       $tabclass = $tabs[$type]["TABCLASS"];
329       $ui       = get_userinfo();
330       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
331       if(preg_match("/w/",$tabacl)){
332         $this->dn= $this->terminals[$s_entry]['dn'];
333         $_SESSION['objectinfo']= $this->dn;
334         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
335       }else{
336         print_red(_("You are not allowed to change the password for this object."));
337       }
338     }
341     /********************
342       Password change finish, but check if entered data is ok 
343      ********************/
345     /* Correctly specified? */
346     if (isset($_POST['password_finish'])){
347       if ($_POST['new_password'] != $_POST['repeated_password']){
348         print_red (_("Passwords entered as new and repeated do not match!"));
349         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
350       }
351     }
353     /********************
354       Password change finish
355      ********************/
357     /* Change terminal password */
358     if (isset($_POST['password_finish']) && 
359         $_POST['new_password'] == $_POST['repeated_password']){
361       /* Check if user is allowed to set password */
362       $tabs = array(
363           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
364           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
366       /* Detect object type */
367       $type = "";
368       foreach($this->terminals as $terminal){
369         if($terminal['dn'] == $this->dn){
370           $type = $this->get_system_type($terminal['objectClass']);
371           break;
372         } 
373       }
375       /* Type detected */
376       if(!empty($type)){
378         /* Get infos */
379         $class    = $tabs[$type]["CLASS"];
380         $tabname  = $tabs[$type]["TABNAME"];
381         $acl_cat  = $tabs[$type]["ACL"];
382         $tabclass = $tabs[$type]["TABCLASS"];
383     
384         /* Get acls */
385         $ui       = get_userinfo();
386         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
388         /* Check acls */
389         if(preg_match("/w/",$tabacl)){
390           $ldap = $this->config->get_ldap_link();
391           $ldap->cd($this->dn);
393           $attrs= array();
394           if ($_POST['new_password'] == ""){
395             $attrs['gotoRootPasswd']= array();
396           } else {
397             $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
398           }
399           $ldap->modify($attrs);
400           gosa_log ("Password for '".$this->dn."' has been changed");
401         }else{
402           print_red(_("You are not allowed to change the password for this object."));
403         }
404       }else{
405         print_red(_("Can't detect object to change password."));
406       }
407       unset($_SESSION['objectinfo']);
408     }
411     /********************
412       Delete system cancel
413      ********************/
415     /* Delete terminal canceled? */
416     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
417       del_lock ($this->dn);
418       unset($_SESSION['objectinfo']);
419     }
422     /********************
423       Delete system, confirm dialog
424      ********************/
426     /* Remove terminal was requested */
427     if ($s_action=="del"){
429       /* Get 'dn' from posted termlinst */
430       $this->dn = $this->terminals[$s_entry]['dn'];
431       $attrs    = $this->terminals[$s_entry];
433       $type= $this->get_system_type($attrs['objectClass']);
434       $ui = get_userinfo();
435       $tabs = array(
436           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
437           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
438           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
439           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
440           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
441           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
442           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
445       /* get object type */
446       $tabtype  = "termtabs";
447       $tabobj   = "TERMTABS";
448       $tabacl   = "";
449       if(isset($tabs[$type])){
450         $tabtype = $tabs[$type]['TABCLASS'];
451         $tabobj  = $tabs[$type]['CLASS'];
452         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
453       }
455       /* Load permissions for selected 'dn' and check if
456          we're allowed to remove this 'dn' */
457       if(preg_match("/d/",$tabacl)){ 
459         /* Check locking, save current plugin in 'back_plugin', so
460            the dialog knows where to return. */
461         if (($user= get_lock($this->dn)) != ""){
462           return(gen_locked_message ($user, $this->dn));
463         }
465         /* Lock the current entry, so nobody will edit it during deletion */
466         add_lock ($this->dn, $this->ui->dn);
467         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
468         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
469       } else {
471         /* Obviously the user isn't allowed to delete. Show message and
472            clean session. */
473         print_red (_("You are not allowed to delete this component!"));
474       }
475     }
478     /********************
479       Delete system, confirmed
480      ********************/
481     /* Confirmation for deletion has been passed. Terminal should be deleted. */
482     if (isset($_POST['delete_terminal_confirm'])){
484       /* Find out more about the object type */
485       $ldap= $this->config->get_ldap_link();
486       $ldap->cat($this->dn, array('objectClass'));
487       $attrs= $ldap->fetch();
488       $type= $this->get_system_type($attrs['objectClass']);
490       $ui = get_userinfo();
492       $tabs = array(
493           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
494           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
495           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
496           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
497           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
498           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
499           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
501       /* get object type */
502       $tabtype  = "termtabs";
503       $tabobj   = "TERMTABS";
504       $tabacl   = "";
505       if(isset($tabs[$type])){
506         $tabtype = $tabs[$type]['TABCLASS'];
507         $tabobj  = $tabs[$type]['CLASS'];
508         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
509       }
511       /* Check if we are allowed to remove this object */
512       if(preg_match("/d/",$tabacl)){
514         /* Delete request is permitted, perform LDAP action */
515         if($tabtype=="phonetabs"){
516           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
517           $this->systab->set_acl_base($this->dn);
518           $this->systab->by_object['phonegeneric']->remove_from_parent ();
519         }else{  
520           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
521           $this->systab->set_acl_base($this->dn);
522           $this->systab->delete();
523         }
524         unset ($this->systab);
525         gosa_log ("System object'".$this->dn."' has been removed");
526         $this->systab= NULL;
528         /* Terminal list has changed, reload it. */
529       } else {
531         /* Normally this shouldn't be reached, send some extra
532            logs to notify the administrator */
533         print_red (_("You are not allowed to delete this component!"));
534         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
535             "deletion.");
536       }
538       /* Remove lock file after successfull deletion */
539       del_lock ($this->dn);
540     }
543     /********************
544       Edit system type finished, check if everything went ok 
545      ********************/
546     /* Finish user edit is triggered by the tabulator dialog, so
547        the user wants to save edited data. Check and save at this
548        point. */
549     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
551       /* Check tabs, will feed message array */
552       $message= $this->systab->check();
554       /* Save, or display error message? */
555       if (count($message) == 0){
557         /* Save terminal data to ldap */
558         if(isset($_SESSION['SelectedSystemType']['ogroup'])){
559           foreach (array("workservice", "termservice") as $cls){
560             if (isset($this->systab->by_object[$cls])){
561               $this->systab->by_object[$cls]->gotoXMouseport= "";
562               $this->systab->by_object[$cls]->gotoXMouseType= "";
563               $this->systab->by_object[$cls]->gotoXResolution= "";
564               $this->systab->by_object[$cls]->gotoXColordepth= "";
565             }
566           }
567         }
568         $this->systab->save();
569         gosa_log ("System object'".$this->dn."' has been saved");
571         /* Incoming behavior; you can select a system type and an ogroup membership. 
572          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
573          * Check if we must add the new object to an object group.
574          * 
575          * If this is done, delete the old incoming entry... it is still there, because this is a new 
576          * entry and not an edited one, so we will delete it.
577          */
579         if(isset($_SESSION['SelectedSystemType'])){
580           $SelectedSystemType= $_SESSION['SelectedSystemType'];
581           unset($_SESSION['SelectedSystemType']);
582           if($SelectedSystemType['ogroup'] != "none"){
583             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
584             if($og){
585               $og->AddDelMembership($this->systab->dn);
586               $og->save();
587             }
588           }
589           if(!isset($ldap)){
590             $ldap = $this->config->get_ldap_link();
591           }
592           $ldap->cd ($this->dn);
593           $ldap->cat($this->dn, array('dn'));  
594           if(count($ldap->fetch())){
595             $ldap->cd($this->dn);
596             $ldap->rmDir($this->dn);
597           }
598           $ldap->cd($this->config->current['BASE']);
599         }
601         if (!isset($_POST['edit_apply'])){
602           /* Terminal has been saved successfully, remove lock from
603              LDAP. */
604           if ($this->dn != "new"){
605             del_lock ($this->dn);
606           }
608           unset ($this->systab);
609           $this->systab= NULL;
610           unset($_SESSION['objectinfo']);
611         }
612       } else {
613         /* Ok. There seem to be errors regarding to the tab data,
614            show message and continue as usual. */
615         show_errors($message);
616       }
617     }
619     /********************
620       Edit system was canceled 
621      ********************/
622     /* Cancel dialogs */
623     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
624       if (isset($this->systab)){
625         del_lock ($this->systab->dn);
626         unset ($this->systab);
627       }
628       $this->systab= NULL;
629       unset($_SESSION['objectinfo']);
631       /* Remove ogroup selection, which was set while editing a new incoming entry */
632       if(isset($_SESSION['SelectedSystemType'])){
633         unset($_SESSION['SelectedSystemType']);
634       }
635     }
637     /********************
638       Display edit dialog, or some other
639      ********************/
641     /* Show tab dialog if object is present */
642     if (isset($this->systab->config)){
643       $display= $this->systab->execute();
645       /* Don't show buttons if tab dialog requests this */
646       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
647         $display.= "<p style=\"text-align:right\">\n";
648         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
649         $display.= "&nbsp;\n";
650         if ($this->dn != "new"){
651           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
652           $display.= "&nbsp;\n";
653         }
654         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
655         $display.= "</p>";
656       }
657       return ($display);
658     }
660     /* Check if there is a snapshot dialog open */
661     $base = $this->DivListSystem->selectedBase;
662     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
663       return($str);
664     }
666     /* Display dialog with system list */
667     $this->DivListSystem->parent = $this;
668     $this->DivListSystem->execute();
670     /* Add departments if subsearch is disabled */
671     if(!$this->DivListSystem->SubSearch){
672       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
673     }
674     $this->reload();
675     $this->DivListSystem->setEntries($this->terminals);
676     return($this->DivListSystem->Draw());
677   }
680   /* Return departments, that will be included within snapshot detection */
681   function get_used_snapshot_bases()
682   {
683     $tmp = array();
685     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
687     $tabs = array(
688         "terminal"        => "ou=terminals,ou=systems,",
689         "workstation"     => "ou=workstations,ou=systems,",
690         "server"          => "ou=servers,ou=systems,",
691         "printer"         => "ou=printers,ou=systems,",
692         "phone"           => "ou=phones,ou=systems,",
693         "winworkstation"  => get_winstations_ou(),
694         "component"       => "ou=netdevices,ou=systems,"
695         ); 
697     foreach($tabs as $acl_cat => $dn){
699       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
700       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
701         $tmp[] = $dn.$this->DivListSystem->selectedBase;
702       }
703     }
704     return($tmp); 
705   }
708   function remove_from_parent()
709   {
710     /* Optionally execute a command after we're done */
711     $this->postremove();
712   }
715   /* Save data to object */
716   function save_object()
717   {
718     $this->DivListSystem->save_object();
719   }
722   /* Check values */
723   function check()
724   {
725   }
728   /* Save to LDAP */
729   function save()
730   {
731   }
733   function adapt_from_template($dn)
734   {
735   }
737   function password_change_needed()
738   {
739   }
741   function reload()
742   {
743     /* some var init */
744     $ui = get_userinfo();
745     $res              = array();
746     $this->terminals  = array();
747     $userregex        = "";
749     /* Set base for all searches */
750     $base=  $this->DivListSystem->selectedBase;
752     /* Prepare samba class name */
753     $samba  ="";
754     if ($this->DivListSystem->ShowWinWorkstations){
755       if ($this->config->current['SAMBAVERSION'] == "3"){
756         $samba= "sambaSamAccount";
757       } else {
758         $samba= "sambaAccount";
759       }
760     }
762     /* This array represents the combination between checkboxes and search filters */
763     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
764         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
765         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
766         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
767         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
768         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
769         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
771     /* Include the 'Display Systems of user' attribute */ 
772     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
773       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
774     }
776     /* Attributes to fetch */
777     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName");
778     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer");
780     /* Add FAIstate to attributes if FAI is activated */
781     $tmp = search_config($this->config->data,"faiManagement","CLASS");
782     if(!empty($tmp)){
783       $sys_attrs[] = "FAIstate";
784     }    
786     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
787     foreach($objs as $checkBox => $oc){
788       if($this->DivListSystem->$checkBox){
789         if($this->DivListSystem->SubSearch){
790           if($oc['CLASS'] != ""){
791             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
792             $new_res = get_list($filter, $sys_categories , $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
793       
794             /* Remove all objects that are not in the expected sub department */
795             foreach($new_res as $key => $obj){
796               if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
797                 $res[$obj['dn']] = $obj;
798               }
799             }
800           }
801         }else{
802           /* User filter? */
803           if($oc['CLASS'] != ""){
804             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
805             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
806           }
807         }
808       } 
809     }
811     /* Search for incoming objects */ 
812     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
813     $res = array_merge($res,get_list($filter,$sys_categories,"ou=incoming,".$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
815     /* Get all gotoTerminal's */
816     foreach ($res as $value){
818       $tmp= $value['dn'];
819       $add= "";
821       /* Extract base */
822       foreach($objs as $obj){
823         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
824           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
825         }
826       }
828       /* Create a string containing the last part of the department. */
829       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
830       if(empty($dn_name)){
831         $dn_name = "/";
832       }
834       /* check if current object is a new one */
835       if (preg_match ("/,ou=incoming,/i", $tmp)){
836         if (in_array_ics('gotoTerminal', $value['objectClass'])){
837           $add= "- "._("New terminal");
838         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
839           $add= "- "._("New workstation");
840         }elseif (in_array_ics('GOhard', $value['objectClass'])){
841           $add= "- "._("New Device");
842         }
843       } 
845       /* Detect type of object and create an entry for $this->terminals */
846       $terminal = array();
848       if (in_array_ics('gotoTerminal', $value["objectClass"])){
850         /* check acl */
851         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
852         if($add != "" || preg_match("/r/",$acl)) {
853           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
854             $terminal             = $value;
855             $terminal['type']     = "T";
856             $terminal['is_new']   = $add;
857           } else {
858             $terminal             = $value;
859             $terminal['type']     = "D";
860             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
861             $terminal['location'] = array_search($tmp, $this->config->departments); 
862           }
863         }
864       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
866         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
867         if($add != "" || preg_match("/r/",$acl)) {
868           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
869             $terminal             = $value;
870             $terminal['type']     = "L";
871             $terminal['is_new']   = $add;
872           } else {
873             $terminal             = $value;
874             $terminal['type']     = "D";
875             $terminal['location'] = array_search($tmp, $this->config->departments);
876             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
877           }
878           if (isset($value["FAIstate"][0])){
879             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
880           }
881         }
882       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
883        
884    
885         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
886         if($add != "" || preg_match("/r/",$acl)) {
888           $terminal             = $value;
889           $terminal['type']     = "P";
890         }
891       } elseif (in_array_ics('goServer', $value["objectClass"])){
893         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
894         if($add != "" || preg_match("/r/",$acl)) {
896           $terminal             = $value;
897           $terminal['type']     = "S";
898           if (isset($value["FAIstate"][0])){
899             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
900           }
901         }
902       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
904         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
905         if($add != "" || preg_match("/r/",$acl)) {
907           $terminal             = $value;
908           $terminal['type']     = "F";
909         }
910       }elseif (in_array_ics("GOhard",$value['objectClass'])){
912         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
913                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
914                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
915         if($add != "" || preg_match("/r/",$acl)) {
917           $terminal = $value;
918           $terminal['type']   = "Q";
919           $terminal['is_new'] = $add;
920         }
921       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
923         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
924         if($add != "" || preg_match("/r/",$acl)) {
926           $terminal             = $value;
927           $terminal['type']     = "C";
928         }
929       } else{
931         $name= preg_replace('/\$$/', '', $value['cn'][0]);
932         if (isset($value['sambaDomainName'])){
933           $domain= " [".$value['sambaDomainName'][0]."]";
934         } else {
935           $domain= "";
936         }
937         $terminal=$value;
938         $terminal['type']     ="W";
939         $terminal['domain']   = $name.$domain;
940       }
942       if(count($terminal)){
943         $this->terminals[]=$terminal;
944       }
945     }
947     $tmp=array();
948     foreach($this->terminals as $tkey => $val ){
949       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
950     }
951     ksort($tmp);
952     $this->terminals=array();
953     foreach($tmp as $val){
954       $this->terminals[]=$val;
955     }
956     reset ($this->terminals);
957   }
959   function remove_lock()
960   {
961     if (isset($this->systab->dn)){
962       del_lock ($this->systab->dn);
963     }
964   }
967   function get_system_type($classes)
968   {
969     $type= "";
970     if (in_array_ics('ieee802Device', $classes)){
971       $type= "component";
972     }elseif (in_array_ics('gotoTerminal', $classes)){
973       $type= "terminal";
974     }elseif (in_array_ics('gotoWorkstation', $classes)){
975       $type= "workstation";
976     }elseif (in_array_ics('gotoPrinter', $classes)){
977       $type= "printer";
978     }elseif (in_array_ics('goFonHardware', $classes)){
979       $type= "phone";
980     }elseif (in_array_ics('goServer', $classes)){
981       $type= "server";
982     }elseif (in_array_ics('GOhard', $classes)){
983       $type= "NewDevice";
984     }elseif (in_array_ics('sambaAccount', $classes) ||
985         in_array_ics('sambaSamAccount', $classes)){
986       $type= "winstation";
987     }
988     return ($type);
989   }
992   function convert_list($input)
993   {
994     $temp= "";
995     $conv= array(       
996         "NQ" => array("select_newsystem.png",_("New System from incoming")),
997         "D" => array("select_default.png",_("Template")),
998         "T" => array("select_terminal.png",_("Terminal")),
999         "L" => array("select_workstation.png",_("Workstation")),
1000         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1001         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1002         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1003         "F" => array("select_phone.png",_("Phone")),
1004         "S" => array("select_server.png",_("Server")),
1005         "GS" => array("select_server_green.png",_("Server is installing")),
1006         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1007         "RS" => array("select_server_red.png",_("Server installation failed")),
1008         "W" => array("select_winstation.png",_("Winstation")),
1009         "C" => array("select_component.png",_("Network Device")),
1010         "NT"=> array("select_new_terminal.png",_("New Terminal")),
1011         "NL"=> array("select_new_workstation.png",_("New Workstation")),
1012         "P" => array("select_printer.png",_("Printer")));
1014     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1015       $input['type']="N".$input['type'];
1016     }
1017     foreach ($conv  as $key => $value){
1018       if($input['type']==$key){
1019         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1020         $tmp['class']=$key;
1021         return $tmp;
1022       }
1023     }
1024   }
1026   
1027   function getState($type, $state)
1028   {
1029     switch (preg_replace('/:.*$/', '', $state)) {
1030       case 'installing':
1031                 $type= 'G'.$type;
1032                 break;
1033       case 'error':
1034                 $type= 'R'.$type;
1035                 break;
1036       case 'install':
1037                 $type= 'Y'.$type;
1038                 break;
1039       case 'sysinfo':
1040                 $type= 'Y'.$type;
1041                 break;
1042       case 'softupdate':
1043                 $type= 'Y'.$type;
1044                 break;
1045     }
1048     return ($type);
1049   }
1053 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1054 ?>