Code

Several systems acl fixes
[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']);
249       $class    = $tabs[$type]["CLASS"];
250       $tabname  = $tabs[$type]["TABNAME"];
251       $acl_cat  = $tabs[$type]["ACL"];
252       $tabclass = $tabs[$type]["TABCLASS"];
254       $ui       = get_userinfo();
255       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
256       if(preg_match("/w/",$tabacl)){
259       $this->dn= $this->terminals[$s_entry]['dn'];
260       $_SESSION['objectinfo']= $this->dn;
261       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
262       }else{
263         print_red(_("You are not allowed to change the password for this object."));
264       }
265     }
268     /********************
269       Password cahnge finish, but check if entered data is ok 
270      ********************/
272     /* Correctly specified? */
273     if (isset($_POST['password_finish'])){
274       if ($_POST['new_password'] != $_POST['repeated_password']){
275         print_red (_("Passwords entered as new and repeated do not match!"));
276         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
277       }
278     }
280     /********************
281       Password change finish
282      ********************/
284     /* Change terminal password */
285     if (isset($_POST['password_finish']) && 
286         $_POST['new_password'] == $_POST['repeated_password']){
288       /* Check if user is allowed to set password */
289       $ui  = get_userinfo();
290       $acl = $ui -> get_category_permissions($this->dn,"terminal");
291       if(preg_match("/w/",$acl)){ 
292         print_red (_("You are not allowed to set this systems password!"));
293       } else {
294         $ldap= $this->config->get_ldap_link();
295         $ldap->cd($this->dn);
297         $attrs= array();
298         if ($_POST['new_password'] == ""){
299           $attrs['gotoRootPasswd']= array();
300         } else {
301           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
302               substr(session_id(),0,2));
303         }
304         $ldap->modify($attrs);
305         gosa_log ("Password for '".$this->dn."' has been changed");
306       }
307       unset($_SESSION['objectinfo']);
308     }
311     /********************
312       Delete system cancel
313      ********************/
315     /* Delete terminal canceled? */
316     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
317       del_lock ($this->dn);
318       unset($_SESSION['objectinfo']);
319     }
322     /********************
323       Delete system, confirm dialog
324      ********************/
326     /* Remove terminal was requested */
327     if ($s_action=="del"){
329       /* Get 'dn' from posted termlinst */
330       $this->dn = $this->terminals[$s_entry]['dn'];
331       $attrs    = $this->terminals[$s_entry];
333       $type= $this->get_system_type($attrs['objectClass']);
334       $ui = get_userinfo();
335       $tabs = array(
336           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
337           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
338           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
339           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgenric"),
340           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
341           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
342           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
345       /* get object type */
346       $tabtype  = "termtabs";
347       $tabobj   = "TERMTABS";
348       $tabacl   = "";
349       if(isset($tabs[$type])){
350         $tabtype = $tabs[$type]['TABCLASS'];
351         $tabobj  = $tabs[$type]['CLASS'];
352         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
353       }
355       /* Load permissions for selected 'dn' and check if
356          we're allowed to remove this 'dn' */
357       if(preg_match("/d/",$tabacl)){ 
359         /* Check locking, save current plugin in 'back_plugin', so
360            the dialog knows where to return. */
361         if (($user= get_lock($this->dn)) != ""){
362           return(gen_locked_message ($user, $this->dn));
363         }
365         /* Lock the current entry, so nobody will edit it during deletion */
366         add_lock ($this->dn, $this->ui->dn);
367         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
368         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
369       } else {
371         /* Obviously the user isn't allowed to delete. Show message and
372            clean session. */
373         print_red (_("You are not allowed to delete this component!"));
374       }
375     }
378     /********************
379       Delete system, confirmed
380      ********************/
381     /* Confirmation for deletion has been passed. Terminal should be deleted. */
382     if (isset($_POST['delete_terminal_confirm'])){
384       /* Find out more about the object type */
385       $ldap= $this->config->get_ldap_link();
386       $ldap->cat($this->dn, array('objectClass'));
387       $attrs= $ldap->fetch();
388       $type= $this->get_system_type($attrs['objectClass']);
390       $ui = get_userinfo();
392       $tabs = array(
393           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
394           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
395           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
396           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgenric"),
397           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
398           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
399           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
401       /* get object type */
402       $tabtype  = "termtabs";
403       $tabobj   = "TERMTABS";
404       $tabacl   = "";
405       if(isset($tabs[$type])){
406         $tabtype = $tabs[$type]['TABCLASS'];
407         $tabobj  = $tabs[$type]['CLASS'];
408         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
409       }
411       /* Check if we are allowed to remove this object */
412       if(preg_match("/d/",$tabacl)){
414         /* Delete request is permitted, perform LDAP action */
415         if($tabtype=="phonetabs"){
416           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
417           $this->systab->set_acl_base($this->dn);
418           $this->systab->by_object['phonegeneric']->remove_from_parent ();
419         }else{  
420           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
421           $this->systab->set_acl_base($this->dn);
422           $this->systab->delete();
423         }
424         unset ($this->systab);
425         gosa_log ("System object'".$this->dn."' has been removed");
426         $this->systab= NULL;
428         /* Terminal list has changed, reload it. */
429       } else {
431         /* Normally this shouldn't be reached, send some extra
432            logs to notify the administrator */
433         print_red (_("You are not allowed to delete this component!"));
434         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
435             "deletion.");
436       }
438       /* Remove lock file after successfull deletion */
439       del_lock ($this->dn);
440     }
443     /********************
444       Edit system type finished, check if everything went ok 
445      ********************/
446     /* Finish user edit is triggered by the tabulator dialog, so
447        the user wants to save edited data. Check and save at this
448        point. */
449     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
451       /* Check tabs, will feed message array */
452       $message= $this->systab->check();
454       /* Save, or display error message? */
455       if (count($message) == 0){
457         /* Save terminal data to ldap */
458         if(isset($_SESSION['SelectedSystemType']['ogroup'])){
459           foreach (array("workservice", "termservice") as $cls){
460             if (isset($this->systab->by_object[$cls])){
461               $this->systab->by_object[$cls]->gotoXMouseport= "";
462               $this->systab->by_object[$cls]->gotoXMouseType= "";
463               $this->systab->by_object[$cls]->gotoXResolution= "";
464               $this->systab->by_object[$cls]->gotoXColordepth= "";
465             }
466           }
467         }
468         $this->systab->save();
469         gosa_log ("System object'".$this->dn."' has been saved");
471         /* Incoming behavior; you can select a system type and an ogroup membership. 
472          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
473          * Check if we must add the new object to an object group.
474          * 
475          * If this is done, delete the old incoming entry... it is still there, because this is a new 
476          * entry and not an edited one, so we will delete it.
477          */
479         if(isset($_SESSION['SelectedSystemType'])){
480           $SelectedSystemType= $_SESSION['SelectedSystemType'];
481           unset($_SESSION['SelectedSystemType']);
482           if($SelectedSystemType['ogroup'] != "none"){
483             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
484             if($og){
485               $og->AddDelMembership($this->systab->dn);
486               $og->save();
487             }
488           }
489           if(!isset($ldap)){
490             $ldap = $this->config->get_ldap_link();
491           }
492           $ldap->cd ($this->dn);
493           $ldap->cat($this->dn, array('dn'));  
494           if(count($ldap->fetch())){
495             $ldap->cd($this->dn);
496             $ldap->rmDir($this->dn);
497           }
498           $ldap->cd($this->config->current['BASE']);
499         }
501         if (!isset($_POST['edit_apply'])){
502           /* Terminal has been saved successfully, remove lock from
503              LDAP. */
504           if ($this->dn != "new"){
505             del_lock ($this->dn);
506           }
508           unset ($this->systab);
509           $this->systab= NULL;
510           unset($_SESSION['objectinfo']);
511         }
512       } else {
513         /* Ok. There seem to be errors regarding to the tab data,
514            show message and continue as usual. */
515         show_errors($message);
516       }
517     }
519     /********************
520       Edit system was canceled 
521      ********************/
522     /* Cancel dialogs */
523     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
524       if (isset($this->systab)){
525         del_lock ($this->systab->dn);
526         unset ($this->systab);
527       }
528       $this->systab= NULL;
529       unset($_SESSION['objectinfo']);
531       /* Remove ogroup selection, which was set while editing a new incoming entry */
532       if(isset($_SESSION['SelectedSystemType'])){
533         unset($_SESSION['SelectedSystemType']);
534       }
535     }
537     /********************
538       Display edit dialog, or some other
539      ********************/
541     /* Show tab dialog if object is present */
542     if (isset($this->systab->config)){
543       $display= $this->systab->execute();
545       /* Don't show buttons if tab dialog requests this */
546       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
547         $display.= "<p style=\"text-align:right\">\n";
548         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
549         $display.= "&nbsp;\n";
550         if ($this->dn != "new"){
551           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
552           $display.= "&nbsp;\n";
553         }
554         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
555         $display.= "</p>";
556       }
557       return ($display);
558     }
560     /* Check if there is a snapshot dialog open */
561     $base = $this->DivListSystem->selectedBase;
562     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
563       return($str);
564     }
566     /* Display dialog with system list */
567     $this->DivListSystem->parent = $this;
568     $this->DivListSystem->execute();
570     /* Add departments if subsearch is disabled */
571     if(!$this->DivListSystem->SubSearch){
572       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
573     }
574     $this->reload();
575     $this->DivListSystem->setEntries($this->terminals);
576     return($this->DivListSystem->Draw());
577   }
580   /* Return departments, that will be included within snapshot detection */
581   function get_used_snapshot_bases()
582   {
583     $tmp = array();
584     foreach(array("phones","servers","printers","terminals","netdevices","workstations") as $ent){
585       $tmp[] = "ou=".$ent.",ou=systems,".$this->DivListSystem->selectedBase;
586     }
587     return($tmp); 
588   }
591   function remove_from_parent()
592   {
593     /* Optionally execute a command after we're done */
594     $this->postremove();
595   }
598   /* Save data to object */
599   function save_object()
600   {
601     $this->DivListSystem->save_object();
602   }
605   /* Check values */
606   function check()
607   {
608   }
611   /* Save to LDAP */
612   function save()
613   {
614   }
616   function adapt_from_template($dn)
617   {
618   }
620   function password_change_needed()
621   {
622   }
624   function reload()
625   {
626     /* some var init */
627     $ui = get_userinfo();
628     $res              = array();
629     $this->terminals  = array();
630     $userregex        = "";
632     /* Set base for all searches */
633     $base=  $this->DivListSystem->selectedBase;
635     /* Prepare samba class name */
636     $samba  ="";
637     if ($this->DivListSystem->ShowWinWorkstations){
638       if ($this->config->current['SAMBAVERSION'] == "3"){
639         $samba= "sambaSamAccount";
640       } else {
641         $samba= "sambaAccount";
642       }
643     }
645     /* This array represents the combination between checkboxes and search filters */
646     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
647         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
648         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
649         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
650         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
651         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
652         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
654     /* Include the 'Display Systems of user' attribute */ 
655     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
656       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
657     }
659     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
660     foreach($objs as $checkBox => $oc){
661       if($this->DivListSystem->$checkBox){
662         if($this->DivListSystem->SubSearch){
663           if($oc['CLASS'] != ""){
664             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
665             $res = array_merge($res,get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
666                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
667           }
668         }else{
669           /* User filter? */
670           if($oc['CLASS'] != ""){
671             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
672             $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
673                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
674           }
675         }
676       } 
677     }
679     /* Search for incoming objects */ 
680     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
681     $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
682           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
684     /* Get all gotoTerminal's */
685     foreach ($res as $value){
687       $tmp= $value['dn'];
688       $add= "";
690       /* Extract base */
691       foreach($objs as $obj){
692         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
693           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
694         }
695       }
697       /* Create a string containing the last part of the department. */
698       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
699       if(empty($dn_name)){
700         $dn_name = "/";
701       }
703       /* check if current object is a new one */
704       if (preg_match ("/,ou=incoming,/i", $tmp)){
705         if (in_array_ics('gotoTerminal', $value['objectClass'])){
706           $add= "- "._("New terminal");
707         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
708           $add= "- "._("New workstation");
709         }elseif (in_array_ics('GOhard', $value['objectClass'])){
710           $add= "- "._("New Device");
711         }
712       } 
714       /* Detect type of object and create an entry for $this->terminals */
715       $terminal = array();
717       if (in_array_ics('gotoTerminal', $value["objectClass"])){
719         /* check acl */
720         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
721         if($add != "" || preg_match("/r/",$acl)) {
722           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
723             $terminal             = $value;
724             $terminal['type']     = "T";
725             $terminal['is_new']   = $add;
726           } else {
727             $terminal             = $value;
728             $terminal['type']     = "D";
729             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
730             $terminal['location'] = array_search($tmp, $this->config->departments); 
731           }
732         }
733       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
735         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
736         if($add != "" || preg_match("/r/",$acl)) {
737           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
738             $terminal             = $value;
739             $terminal['type']     = "L";
740             $terminal['is_new']   = $add;
741           } else {
742             $terminal             = $value;
743             $terminal['type']     = "D";
744             $terminal['location'] = array_search($tmp, $this->config->departments);
745             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
746           }
747           if (isset($value["FAIstate"][0])){
748             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
749           }
750         }
751       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
752        
753    
754         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
755         if($add != "" || preg_match("/r/",$acl)) {
757           $terminal             = $value;
758           $terminal['type']     = "P";
759         }
760       } elseif (in_array_ics('goServer', $value["objectClass"])){
762         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
763         if($add != "" || preg_match("/r/",$acl)) {
765           $terminal             = $value;
766           $terminal['type']     = "S";
767           if (isset($value["FAIstate"][0])){
768             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
769           }
770         }
771       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
773         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
774         if($add != "" || preg_match("/r/",$acl)) {
776           $terminal             = $value;
777           $terminal['type']     = "F";
778         }
779       }elseif (in_array_ics("GOhard",$value['objectClass'])){
781         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
782                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
783                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
784         if($add != "" || preg_match("/r/",$acl)) {
786           $terminal = $value;
787           $terminal['type']   = "Q";
788           $terminal['is_new'] = $add;
789         }
790       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
792         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
793         if($add != "" || preg_match("/r/",$acl)) {
795           $terminal             = $value;
796           $terminal['type']     = "C";
797         }
798       } else{
800         $name= preg_replace('/\$$/', '', $value['cn'][0]);
801         if (isset($value['sambaDomainName'])){
802           $domain= " [".$value['sambaDomainName'][0]."]";
803         } else {
804           $domain= "";
805         }
806         $terminal=$value;
807         $terminal['type']     ="W";
808         $terminal['domain']   = $name.$domain;
809       }
811       if(count($terminal)){
812         $this->terminals[]=$terminal;
813       }
814     }
816     $tmp=array();
817     foreach($this->terminals as $tkey => $val ){
818       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
819     }
820     ksort($tmp);
821     $this->terminals=array();
822     foreach($tmp as $val){
823       $this->terminals[]=$val;
824     }
825     reset ($this->terminals);
826   }
828   function remove_lock()
829   {
830     if (isset($this->systab->dn)){
831       del_lock ($this->systab->dn);
832     }
833   }
836   function get_system_type($classes)
837   {
838     $type= "";
839     if (in_array_ics('ieee802Device', $classes)){
840       $type= "component";
841     }elseif (in_array_ics('gotoTerminal', $classes)){
842       $type= "terminal";
843     }elseif (in_array_ics('gotoWorkstation', $classes)){
844       $type= "workstation";
845     }elseif (in_array_ics('gotoPrinter', $classes)){
846       $type= "printer";
847     }elseif (in_array_ics('goFonHardware', $classes)){
848       $type= "phone";
849     }elseif (in_array_ics('goServer', $classes)){
850       $type= "server";
851     }elseif (in_array_ics('GOhard', $classes)){
852       $type= "NewDevice";
853     }elseif (in_array_ics('sambaAccount', $classes) ||
854         in_array_ics('sambaSamAccount', $classes)){
855       $type= "winstation";
856     }
857     return ($type);
858   }
861   function convert_list($input)
862   {
863     $temp= "";
864     $conv= array(       
865         "NQ" => array("select_newsystem.png",_("New System from incoming")),
866         "D" => array("select_default.png",_("Template")),
867         "T" => array("select_terminal.png",_("Terminal")),
868         "L" => array("select_workstation.png",_("Workstation")),
869         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
870         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
871         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
872         "F" => array("select_phone.png",_("Phone")),
873         "S" => array("select_server.png",_("Server")),
874         "GS" => array("select_server_green.png",_("Server is installing")),
875         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
876         "RS" => array("select_server_red.png",_("Server installation failed")),
877         "W" => array("select_winstation.png",_("Winstation")),
878         "C" => array("select_component.png",_("Network Device")),
879         "NT"=> array("select_new_terminal.png",_("New Terminal")),
880         "NL"=> array("select_new_workstation.png",_("New Workstation")),
881         "P" => array("select_printer.png",_("Printer")));
883     if((isset($input['is_new']))&&(!empty($input['is_new']))){
884       $input['type']="N".$input['type'];
885     }
886     foreach ($conv  as $key => $value){
887       if($input['type']==$key){
888         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
889         $tmp['class']=$key;
890         return $tmp;
891       }
892     }
893   }
895   
896   function getState($type, $state)
897   {
898     switch (preg_replace('/:.*$/', '', $state)) {
899       case 'installing':
900                 $type= 'G'.$type;
901                 break;
902       case 'error':
903                 $type= 'R'.$type;
904                 break;
905       case 'install':
906                 $type= 'Y'.$type;
907                 break;
908       case 'sysinfo':
909                 $type= 'Y'.$type;
910                 break;
911       case 'softupdate':
912                 $type= 'Y'.$type;
913                 break;
914     }
917     return ($type);
918   }
922 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
923 ?>