Code

de5f19e02be081ef24ca03962ae2bd1317e1ed4d
[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("/^user_edit_/i","/^user_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("/user_del.*/",$key)){
71         $s_action = "del";
72         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
73         // Post for edit
74       }elseif(preg_match("/user_edit_.*/",$key)){
75         $s_action="edit";
76         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
77         // Post for new
78       }elseif(preg_match("/user_new.*/",$key)){
79         $s_action="new";
80       }elseif(preg_match("/user_tplnew.*/i",$key)){
81         $s_action="new_tpl";
82       }elseif(preg_match("/user_setpwd_.*/i",$key)){
83         $s_action="change_pw";
84         $s_entry  = preg_replace("/user_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     }
124      
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     /********************
136       Create new system ...   
137      ********************/
138     /* Create new default terminal 
139      * Or create specified object of selected system type, from given incoming object  
140      */
141     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
143       /* If the current entry is an incoming object 
144        * $sw = System type as posted in new incoming handling dialog 
145        */ 
146       if($s_action == "SelectedSystemType") {
147         $sw         = $s_entry;
148       }else{
149         if(isset($_POST['system'])){
150           $sw = $_POST['system'];
151         }else{
152           $sw = $s_entry;
153         }
154         $this->dn= "new";
155       }
156       $tabs = array(
157           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
158           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
159           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
160           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
161           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
162           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
164       if(isset($tabs[$sw])){
165         $class    = $tabs[$sw]["CLASS"];
166         $tabname  = $tabs[$sw]["TABNAME"];
167         $tabclass = $tabs[$sw]["TABCLASS"];
168         $acl_cat  = $tabs[$sw]["ACL"];
170         /* Load permissions for selected 'dn' and check if
171            we're allowed to remove this 'dn' */
172         $ui       = get_userinfo();
173         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
174         if(preg_match("/c/",$tabacl)){
175           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
176           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
177           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
178           $this->systab->base = $this->DivListSystem->selectedBase;
179         }else{
180           print_red(_("You are not allowed to create a new object of this type."));
181         }
182       }
183     }
185     /********************
186       Edit system ...   
187      ********************/
189     /* User wants to edit data? */
190     if (($s_action == "edit") && (!isset($this->systab->config))){
192       $this->dn= $this->terminals[$s_entry]['dn'];
194       /* Check locking, save current plugin in 'back_plugin', so
195          the dialog knows where to return. */
196       if (($user= get_lock($this->dn)) != ""){
197         return(gen_locked_message ($user, $this->dn));
198       }
200       /* Find out more about the object type */
201       $ldap= $this->config->get_ldap_link();
202       $ldap->cat($this->dn, array('objectClass'));
203       $attrs= $ldap->fetch();
204       $type= $this->get_system_type($attrs['objectClass']);
206       /* Lock the current entry, so everyone will get the
207          above dialog */
208       $tabs = array(
209           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
210           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
211           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
212           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
213           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
214           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
215           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
218       if($type == "NewDevice"){
219         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
220       }elseif(isset($tabs[$type])){
222         $class    = $tabs[$type]["CLASS"];
223         $acl_cat  = $tabs[$type]["ACL"];
224         $tabclass = $tabs[$type]["TABCLASS"];
226         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
227         $this->systab->set_acl_base($this->dn);
228         $_SESSION['objectinfo']= $this->dn;
229         add_lock ($this->dn, $this->ui->dn);
230       }else{ 
231         print_red (_("You can't edit this object type yet!"));
232         del_lock($this->dn);
233       }
234     }
237     /********************
238       Change password ...   
239      ********************/
241     /* Set terminals root password */
242     if ($s_action=="change_pw"){
243       $tabs = array(
244           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
245           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
247       $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
248       $class    = $tabs[$type]["CLASS"];
249       $tabname  = $tabs[$type]["TABNAME"];
250       $acl_cat  = $tabs[$type]["ACL"];
251       $tabclass = $tabs[$type]["TABCLASS"];
252       $ui       = get_userinfo();
253       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
254       if(preg_match("/w/",$tabacl)){
255         $this->dn= $this->terminals[$s_entry]['dn'];
256         $_SESSION['objectinfo']= $this->dn;
257         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
258       }else{
259         print_red(_("You are not allowed to change the password for this object."));
260       }
261     }
264     /********************
265       Password change finish, but check if entered data is ok 
266      ********************/
268     /* Correctly specified? */
269     if (isset($_POST['password_finish'])){
270       if ($_POST['new_password'] != $_POST['repeated_password']){
271         print_red (_("Passwords entered as new and repeated do not match!"));
272         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
273       }
274     }
276     /********************
277       Password change finish
278      ********************/
280     /* Change terminal password */
281     if (isset($_POST['password_finish']) && 
282         $_POST['new_password'] == $_POST['repeated_password']){
284       /* Check if user is allowed to set password */
285       $tabs = array(
286           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
287           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
289       /* Detect object type */
290       $type = "";
291       foreach($this->terminals as $terminal){
292         if($terminal['dn'] == $this->dn){
293           $type = $this->get_system_type($terminal['objectClass']);
294           break;
295         } 
296       }
298       /* Type detected */
299       if(!empty($type)){
301         /* Get infos */
302         $class    = $tabs[$type]["CLASS"];
303         $tabname  = $tabs[$type]["TABNAME"];
304         $acl_cat  = $tabs[$type]["ACL"];
305         $tabclass = $tabs[$type]["TABCLASS"];
306     
307         /* Get acls */
308         $ui       = get_userinfo();
309         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
311         /* Check acls */
312         if(preg_match("/w/",$tabacl)){
313           $ldap = $this->config->get_ldap_link();
314           $ldap->cd($this->dn);
316           $attrs= array();
317           if ($_POST['new_password'] == ""){
318             $attrs['gotoRootPasswd']= array();
319           } else {
320             $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
321           }
322           $ldap->modify($attrs);
323           gosa_log ("Password for '".$this->dn."' has been changed");
324         }else{
325           print_red(_("You are not allowed to change the password for this object."));
326         }
327       }else{
328         print_red(_("Can't detect object to change password."));
329       }
330       unset($_SESSION['objectinfo']);
331     }
334     /********************
335       Delete system cancel
336      ********************/
338     /* Delete terminal canceled? */
339     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
340       del_lock ($this->dn);
341       unset($_SESSION['objectinfo']);
342     }
345     /********************
346       Delete system, confirm dialog
347      ********************/
349     /* Remove terminal was requested */
350     if ($s_action=="del"){
352       /* Get 'dn' from posted termlinst */
353       $this->dn = $this->terminals[$s_entry]['dn'];
354       $attrs    = $this->terminals[$s_entry];
356       $type= $this->get_system_type($attrs['objectClass']);
357       $ui = get_userinfo();
358       $tabs = array(
359           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
360           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
361           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
362           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgenric"),
363           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
364           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
365           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
368       /* get object type */
369       $tabtype  = "termtabs";
370       $tabobj   = "TERMTABS";
371       $tabacl   = "";
372       if(isset($tabs[$type])){
373         $tabtype = $tabs[$type]['TABCLASS'];
374         $tabobj  = $tabs[$type]['CLASS'];
375         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
376       }
378       /* Load permissions for selected 'dn' and check if
379          we're allowed to remove this 'dn' */
380       if(preg_match("/d/",$tabacl)){ 
382         /* Check locking, save current plugin in 'back_plugin', so
383            the dialog knows where to return. */
384         if (($user= get_lock($this->dn)) != ""){
385           return(gen_locked_message ($user, $this->dn));
386         }
388         /* Lock the current entry, so nobody will edit it during deletion */
389         add_lock ($this->dn, $this->ui->dn);
390         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
391         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
392       } else {
394         /* Obviously the user isn't allowed to delete. Show message and
395            clean session. */
396         print_red (_("You are not allowed to delete this component!"));
397       }
398     }
401     /********************
402       Delete system, confirmed
403      ********************/
404     /* Confirmation for deletion has been passed. Terminal should be deleted. */
405     if (isset($_POST['delete_terminal_confirm'])){
407       /* Find out more about the object type */
408       $ldap= $this->config->get_ldap_link();
409       $ldap->cat($this->dn, array('objectClass'));
410       $attrs= $ldap->fetch();
411       $type= $this->get_system_type($attrs['objectClass']);
413       $ui = get_userinfo();
415       $tabs = array(
416           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
417           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
418           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
419           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgenric"),
420           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
421           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
422           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
424       /* get object type */
425       $tabtype  = "termtabs";
426       $tabobj   = "TERMTABS";
427       $tabacl   = "";
428       if(isset($tabs[$type])){
429         $tabtype = $tabs[$type]['TABCLASS'];
430         $tabobj  = $tabs[$type]['CLASS'];
431         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
432       }
434       /* Check if we are allowed to remove this object */
435       if(preg_match("/d/",$tabacl)){
437         /* Delete request is permitted, perform LDAP action */
438         if($tabtype=="phonetabs"){
439           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
440           $this->systab->set_acl_base($this->dn);
441           $this->systab->by_object['phonegeneric']->remove_from_parent ();
442         }else{  
443           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
444           $this->systab->set_acl_base($this->dn);
445           $this->systab->delete();
446         }
447         unset ($this->systab);
448         gosa_log ("System object'".$this->dn."' has been removed");
449         $this->systab= NULL;
451         /* Terminal list has changed, reload it. */
452       } else {
454         /* Normally this shouldn't be reached, send some extra
455            logs to notify the administrator */
456         print_red (_("You are not allowed to delete this component!"));
457         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
458             "deletion.");
459       }
461       /* Remove lock file after successfull deletion */
462       del_lock ($this->dn);
463     }
466     /********************
467       Edit system type finished, check if everything went ok 
468      ********************/
469     /* Finish user edit is triggered by the tabulator dialog, so
470        the user wants to save edited data. Check and save at this
471        point. */
472     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
474       /* Check tabs, will feed message array */
475       $message= $this->systab->check();
477       /* Save, or display error message? */
478       if (count($message) == 0){
480         /* Save terminal data to ldap */
481         if(isset($_SESSION['SelectedSystemType']['ogroup'])){
482           foreach (array("workservice", "termservice") as $cls){
483             if (isset($this->systab->by_object[$cls])){
484               $this->systab->by_object[$cls]->gotoXMouseport= "";
485               $this->systab->by_object[$cls]->gotoXMouseType= "";
486               $this->systab->by_object[$cls]->gotoXResolution= "";
487               $this->systab->by_object[$cls]->gotoXColordepth= "";
488             }
489           }
490         }
491         $this->systab->save();
492         gosa_log ("System object'".$this->dn."' has been saved");
494         /* Incoming behavior; you can select a system type and an ogroup membership. 
495          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
496          * Check if we must add the new object to an object group.
497          * 
498          * If this is done, delete the old incoming entry... it is still there, because this is a new 
499          * entry and not an edited one, so we will delete it.
500          */
502         if(isset($_SESSION['SelectedSystemType'])){
503           $SelectedSystemType= $_SESSION['SelectedSystemType'];
504           unset($_SESSION['SelectedSystemType']);
505           if($SelectedSystemType['ogroup'] != "none"){
506             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
507             if($og){
508               $og->AddDelMembership($this->systab->dn);
509               $og->save();
510             }
511           }
512           if(!isset($ldap)){
513             $ldap = $this->config->get_ldap_link();
514           }
515           $ldap->cd ($this->dn);
516           $ldap->cat($this->dn, array('dn'));  
517           if(count($ldap->fetch())){
518             $ldap->cd($this->dn);
519             $ldap->rmDir($this->dn);
520           }
521           $ldap->cd($this->config->current['BASE']);
522         }
524         if (!isset($_POST['edit_apply'])){
525           /* Terminal has been saved successfully, remove lock from
526              LDAP. */
527           if ($this->dn != "new"){
528             del_lock ($this->dn);
529           }
531           unset ($this->systab);
532           $this->systab= NULL;
533           unset($_SESSION['objectinfo']);
534         }
535       } else {
536         /* Ok. There seem to be errors regarding to the tab data,
537            show message and continue as usual. */
538         show_errors($message);
539       }
540     }
542     /********************
543       Edit system was canceled 
544      ********************/
545     /* Cancel dialogs */
546     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
547       if (isset($this->systab)){
548         del_lock ($this->systab->dn);
549         unset ($this->systab);
550       }
551       $this->systab= NULL;
552       unset($_SESSION['objectinfo']);
554       /* Remove ogroup selection, which was set while editing a new incoming entry */
555       if(isset($_SESSION['SelectedSystemType'])){
556         unset($_SESSION['SelectedSystemType']);
557       }
558     }
560     /********************
561       Display edit dialog, or some other
562      ********************/
564     /* Show tab dialog if object is present */
565     if (isset($this->systab->config)){
566       $display= $this->systab->execute();
568       /* Don't show buttons if tab dialog requests this */
569       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
570         $display.= "<p style=\"text-align:right\">\n";
571         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
572         $display.= "&nbsp;\n";
573         if ($this->dn != "new"){
574           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
575           $display.= "&nbsp;\n";
576         }
577         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
578         $display.= "</p>";
579       }
580       return ($display);
581     }
583     /* Check if there is a snapshot dialog open */
584     $base = $this->DivListSystem->selectedBase;
585     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
586       return($str);
587     }
589     /* Display dialog with system list */
590     $this->DivListSystem->parent = $this;
591     $this->DivListSystem->execute();
593     /* Add departments if subsearch is disabled */
594     if(!$this->DivListSystem->SubSearch){
595       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
596     }
597     $this->reload();
598     $this->DivListSystem->setEntries($this->terminals);
599     return($this->DivListSystem->Draw());
600   }
603   /* Return departments, that will be included within snapshot detection */
604   function get_used_snapshot_bases()
605   {
606     $tmp = array();
607     foreach(array("phones","servers","printers","terminals","netdevices","workstations") as $ent){
608       $tmp[] = "ou=".$ent.",ou=systems,".$this->DivListSystem->selectedBase;
609     }
610     return($tmp); 
611   }
614   function remove_from_parent()
615   {
616     /* Optionally execute a command after we're done */
617     $this->postremove();
618   }
621   /* Save data to object */
622   function save_object()
623   {
624     $this->DivListSystem->save_object();
625   }
628   /* Check values */
629   function check()
630   {
631   }
634   /* Save to LDAP */
635   function save()
636   {
637   }
639   function adapt_from_template($dn)
640   {
641   }
643   function password_change_needed()
644   {
645   }
647   function reload()
648   {
649     /* some var init */
650     $ui = get_userinfo();
651     $res              = array();
652     $this->terminals  = array();
653     $userregex        = "";
655     /* Set base for all searches */
656     $base=  $this->DivListSystem->selectedBase;
658     /* Prepare samba class name */
659     $samba  ="";
660     if ($this->DivListSystem->ShowWinWorkstations){
661       if ($this->config->current['SAMBAVERSION'] == "3"){
662         $samba= "sambaSamAccount";
663       } else {
664         $samba= "sambaAccount";
665       }
666     }
668     /* This array represents the combination between checkboxes and search filters */
669     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
670         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
671         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
672         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
673         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
674         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
675         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
677     /* Include the 'Display Systems of user' attribute */ 
678     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
679       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
680     }
682     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
683     foreach($objs as $checkBox => $oc){
684       if($this->DivListSystem->$checkBox){
685         if($this->DivListSystem->SubSearch){
686           if($oc['CLASS'] != ""){
687             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
688             $res = array_merge($res,get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
689                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
690           }
691         }else{
692           /* User filter? */
693           if($oc['CLASS'] != ""){
694             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
695             $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
696                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
697           }
698         }
699       } 
700     }
702     /* Search for incoming objects */ 
703     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
704     $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
705           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
707     /* Get all gotoTerminal's */
708     foreach ($res as $value){
710       $tmp= $value['dn'];
711       $add= "";
713       /* Extract base */
714       foreach($objs as $obj){
715         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
716           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
717         }
718       }
720       /* Create a string containing the last part of the department. */
721       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
722       if(empty($dn_name)){
723         $dn_name = "/";
724       }
726       /* check if current object is a new one */
727       if (preg_match ("/,ou=incoming,/i", $tmp)){
728         if (in_array_ics('gotoTerminal', $value['objectClass'])){
729           $add= "- "._("New terminal");
730         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
731           $add= "- "._("New workstation");
732         }elseif (in_array_ics('GOhard', $value['objectClass'])){
733           $add= "- "._("New Device");
734         }
735       } 
737       /* Detect type of object and create an entry for $this->terminals */
738       $terminal = array();
740       if (in_array_ics('gotoTerminal', $value["objectClass"])){
742         /* check acl */
743         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
744         if($add != "" || preg_match("/r/",$acl)) {
745           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
746             $terminal             = $value;
747             $terminal['type']     = "T";
748             $terminal['is_new']   = $add;
749           } else {
750             $terminal             = $value;
751             $terminal['type']     = "D";
752             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
753             $terminal['location'] = array_search($tmp, $this->config->departments); 
754           }
755         }
756       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
758         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
759         if($add != "" || preg_match("/r/",$acl)) {
760           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
761             $terminal             = $value;
762             $terminal['type']     = "L";
763             $terminal['is_new']   = $add;
764           } else {
765             $terminal             = $value;
766             $terminal['type']     = "D";
767             $terminal['location'] = array_search($tmp, $this->config->departments);
768             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
769           }
770           if (isset($value["FAIstate"][0])){
771             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
772           }
773         }
774       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
775        
776    
777         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
778         if($add != "" || preg_match("/r/",$acl)) {
780           $terminal             = $value;
781           $terminal['type']     = "P";
782         }
783       } elseif (in_array_ics('goServer', $value["objectClass"])){
785         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
786         if($add != "" || preg_match("/r/",$acl)) {
788           $terminal             = $value;
789           $terminal['type']     = "S";
790           if (isset($value["FAIstate"][0])){
791             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
792           }
793         }
794       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
796         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
797         if($add != "" || preg_match("/r/",$acl)) {
799           $terminal             = $value;
800           $terminal['type']     = "F";
801         }
802       }elseif (in_array_ics("GOhard",$value['objectClass'])){
804         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
805                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
806                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
807         if($add != "" || preg_match("/r/",$acl)) {
809           $terminal = $value;
810           $terminal['type']   = "Q";
811           $terminal['is_new'] = $add;
812         }
813       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
815         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
816         if($add != "" || preg_match("/r/",$acl)) {
818           $terminal             = $value;
819           $terminal['type']     = "C";
820         }
821       } else{
823         $name= preg_replace('/\$$/', '', $value['cn'][0]);
824         if (isset($value['sambaDomainName'])){
825           $domain= " [".$value['sambaDomainName'][0]."]";
826         } else {
827           $domain= "";
828         }
829         $terminal=$value;
830         $terminal['type']     ="W";
831         $terminal['domain']   = $name.$domain;
832       }
834       if(count($terminal)){
835         $this->terminals[]=$terminal;
836       }
837     }
839     $tmp=array();
840     foreach($this->terminals as $tkey => $val ){
841       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
842     }
843     ksort($tmp);
844     $this->terminals=array();
845     foreach($tmp as $val){
846       $this->terminals[]=$val;
847     }
848     reset ($this->terminals);
849   }
851   function remove_lock()
852   {
853     if (isset($this->systab->dn)){
854       del_lock ($this->systab->dn);
855     }
856   }
859   function get_system_type($classes)
860   {
861     $type= "";
862     if (in_array_ics('ieee802Device', $classes)){
863       $type= "component";
864     }elseif (in_array_ics('gotoTerminal', $classes)){
865       $type= "terminal";
866     }elseif (in_array_ics('gotoWorkstation', $classes)){
867       $type= "workstation";
868     }elseif (in_array_ics('gotoPrinter', $classes)){
869       $type= "printer";
870     }elseif (in_array_ics('goFonHardware', $classes)){
871       $type= "phone";
872     }elseif (in_array_ics('goServer', $classes)){
873       $type= "server";
874     }elseif (in_array_ics('GOhard', $classes)){
875       $type= "NewDevice";
876     }elseif (in_array_ics('sambaAccount', $classes) ||
877         in_array_ics('sambaSamAccount', $classes)){
878       $type= "winstation";
879     }
880     return ($type);
881   }
884   function convert_list($input)
885   {
886     $temp= "";
887     $conv= array(       
888         "NQ" => array("select_newsystem.png",_("New System from incoming")),
889         "D" => array("select_default.png",_("Template")),
890         "T" => array("select_terminal.png",_("Terminal")),
891         "L" => array("select_workstation.png",_("Workstation")),
892         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
893         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
894         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
895         "F" => array("select_phone.png",_("Phone")),
896         "S" => array("select_server.png",_("Server")),
897         "GS" => array("select_server_green.png",_("Server is installing")),
898         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
899         "RS" => array("select_server_red.png",_("Server installation failed")),
900         "W" => array("select_winstation.png",_("Winstation")),
901         "C" => array("select_component.png",_("Network Device")),
902         "NT"=> array("select_new_terminal.png",_("New Terminal")),
903         "NL"=> array("select_new_workstation.png",_("New Workstation")),
904         "P" => array("select_printer.png",_("Printer")));
906     if((isset($input['is_new']))&&(!empty($input['is_new']))){
907       $input['type']="N".$input['type'];
908     }
909     foreach ($conv  as $key => $value){
910       if($input['type']==$key){
911         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
912         $tmp['class']=$key;
913         return $tmp;
914       }
915     }
916   }
918   
919   function getState($type, $state)
920   {
921     switch (preg_replace('/:.*$/', '', $state)) {
922       case 'installing':
923                 $type= 'G'.$type;
924                 break;
925       case 'error':
926                 $type= 'R'.$type;
927                 break;
928       case 'install':
929                 $type= 'Y'.$type;
930                 break;
931       case 'sysinfo':
932                 $type= 'Y'.$type;
933                 break;
934       case 'softupdate':
935                 $type= 'Y'.$type;
936                 break;
937     }
940     return ($type);
941   }
945 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
946 ?>