d20bc1766c96cfcdb3eb188a3ceaaddd270c0576
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 }
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"];
169 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
170 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
171 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
172 $this->systab->base = $this->DivListSystem->selectedBase;
173 }
174 }
176 /********************
177 Edit system ...
178 ********************/
180 /* User wants to edit data? */
181 if (($s_action == "edit") && (!isset($this->systab->config))){
183 $this->dn= $this->terminals[$s_entry]['dn'];
185 /* Check locking, save current plugin in 'back_plugin', so
186 the dialog knows where to return. */
187 if (($user= get_lock($this->dn)) != ""){
188 return(gen_locked_message ($user, $this->dn));
189 }
191 /* Find out more about the object type */
192 $ldap= $this->config->get_ldap_link();
193 $ldap->cat($this->dn, array('objectClass'));
194 $attrs= $ldap->fetch();
195 $type= $this->get_system_type($attrs['objectClass']);
197 /* Lock the current entry, so everyone will get the
198 above dialog */
199 $tabs = array(
200 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
201 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
202 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
203 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
204 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
205 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
206 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
209 if($type == "NewDevice"){
210 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
211 }elseif(isset($tabs[$type])){
213 $class = $tabs[$type]["CLASS"];
214 $acl_cat = $tabs[$type]["ACL"];
215 $tabclass = $tabs[$type]["TABCLASS"];
217 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
218 $this->systab->set_acl_base($this->dn);
219 $_SESSION['objectinfo']= $this->dn;
220 add_lock ($this->dn, $this->ui->dn);
221 }else{
222 print_red (_("You can't edit this object type yet!"));
223 del_lock($this->dn);
224 }
225 }
228 /********************
229 Change password ...
230 ********************/
232 /* Set terminals root password */
233 if ($s_action=="change_pw"){
234 $this->dn= $this->terminals[$s_entry]['dn'];
235 $_SESSION['objectinfo']= $this->dn;
236 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
237 }
240 /********************
241 Password cahnge finish, but check if entered data is ok
242 ********************/
244 /* Correctly specified? */
245 if (isset($_POST['password_finish'])){
246 if ($_POST['new_password'] != $_POST['repeated_password']){
247 print_red (_("Passwords entered as new and repeated do not match!"));
248 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
249 }
250 }
252 /********************
253 Password change finish
254 ********************/
256 /* Change terminal password */
257 if (isset($_POST['password_finish']) &&
258 $_POST['new_password'] == $_POST['repeated_password']){
260 /* Check if user is allowed to set password */
261 $ui = get_userinfo();
262 $acl = $ui -> get_category_permissions($this->dn,"terminal");
263 if(preg_match("/w/",$acl)){
264 print_red (_("You are not allowed to set this systems password!"));
265 } else {
266 $ldap= $this->config->get_ldap_link();
267 $ldap->cd($this->dn);
269 $attrs= array();
270 if ($_POST['new_password'] == ""){
271 $attrs['gotoRootPasswd']= array();
272 } else {
273 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
274 substr(session_id(),0,2));
275 }
276 $ldap->modify($attrs);
277 gosa_log ("Password for '".$this->dn."' has been changed");
278 }
279 unset($_SESSION['objectinfo']);
280 }
283 /********************
284 Delete system cancel
285 ********************/
287 /* Delete terminal canceled? */
288 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
289 del_lock ($this->dn);
290 unset($_SESSION['objectinfo']);
291 }
294 /********************
295 Delete system, confirm dialog
296 ********************/
298 /* Remove terminal was requested */
299 if ($s_action=="del"){
301 /* Get 'dn' from posted termlinst */
302 $this->dn = $this->terminals[$s_entry]['dn'];
303 $attrs = $this->terminals[$s_entry];
305 $type= $this->get_system_type($attrs['objectClass']);
306 $ui = get_userinfo();
307 $tabs = array(
308 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
309 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
310 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
311 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgenric"),
312 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
313 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
314 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
317 /* get object type */
318 $tabtype = "termtabs";
319 $tabobj = "TERMTABS";
320 $tabacl = "";
321 if(isset($tabs[$type])){
322 $tabtype = $tabs[$type]['TABCLASS'];
323 $tabobj = $tabs[$type]['CLASS'];
324 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
325 }
327 /* Load permissions for selected 'dn' and check if
328 we're allowed to remove this 'dn' */
329 if(preg_match("/d/",$tabacl)){
331 /* Check locking, save current plugin in 'back_plugin', so
332 the dialog knows where to return. */
333 if (($user= get_lock($this->dn)) != ""){
334 return(gen_locked_message ($user, $this->dn));
335 }
337 /* Lock the current entry, so nobody will edit it during deletion */
338 add_lock ($this->dn, $this->ui->dn);
339 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
340 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
341 } else {
343 /* Obviously the user isn't allowed to delete. Show message and
344 clean session. */
345 print_red (_("You are not allowed to delete this component!"));
346 }
347 }
350 /********************
351 Delete system, confirmed
352 ********************/
353 /* Confirmation for deletion has been passed. Terminal should be deleted. */
354 if (isset($_POST['delete_terminal_confirm'])){
356 /* Find out more about the object type */
357 $ldap= $this->config->get_ldap_link();
358 $ldap->cat($this->dn, array('objectClass'));
359 $attrs= $ldap->fetch();
360 $type= $this->get_system_type($attrs['objectClass']);
362 $ui = get_userinfo();
364 $tabs = array(
365 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
366 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
367 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
368 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgenric"),
369 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
370 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
371 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
373 /* get object type */
374 $tabtype = "termtabs";
375 $tabobj = "TERMTABS";
376 $tabacl = "";
377 if(isset($tabs[$type])){
378 $tabtype = $tabs[$type]['TABCLASS'];
379 $tabobj = $tabs[$type]['CLASS'];
380 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
381 }
383 /* Check if we are allowed to remove this object */
384 if(preg_match("/d/",$tabacl)){
386 /* Delete request is permitted, perform LDAP action */
387 if($tabtype=="phonetabs"){
388 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
389 $this->systab->set_acl_base($this->dn);
390 $this->systab->by_object['phonegeneric']->remove_from_parent ();
391 }else{
392 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
393 $this->systab->set_acl_base($this->dn);
394 $this->systab->delete();
395 }
396 unset ($this->systab);
397 gosa_log ("System object'".$this->dn."' has been removed");
398 $this->systab= NULL;
400 /* Terminal list has changed, reload it. */
401 } else {
403 /* Normally this shouldn't be reached, send some extra
404 logs to notify the administrator */
405 print_red (_("You are not allowed to delete this component!"));
406 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
407 "deletion.");
408 }
410 /* Remove lock file after successfull deletion */
411 del_lock ($this->dn);
412 }
415 /********************
416 Edit system type finished, check if everything went ok
417 ********************/
418 /* Finish user edit is triggered by the tabulator dialog, so
419 the user wants to save edited data. Check and save at this
420 point. */
421 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
423 /* Check tabs, will feed message array */
424 $message= $this->systab->check();
426 /* Save, or display error message? */
427 if (count($message) == 0){
429 /* Save terminal data to ldap */
430 if(isset($_SESSION['SelectedSystemType']['ogroup'])){
431 foreach (array("workservice", "termservice") as $cls){
432 if (isset($this->systab->by_object[$cls])){
433 $this->systab->by_object[$cls]->gotoXMouseport= "";
434 $this->systab->by_object[$cls]->gotoXMouseType= "";
435 $this->systab->by_object[$cls]->gotoXResolution= "";
436 $this->systab->by_object[$cls]->gotoXColordepth= "";
437 }
438 }
439 }
440 $this->systab->save();
441 gosa_log ("System object'".$this->dn."' has been saved");
443 /* Incoming behavior; you can select a system type and an ogroup membership.
444 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
445 * Check if we must add the new object to an object group.
446 *
447 * If this is done, delete the old incoming entry... it is still there, because this is a new
448 * entry and not an edited one, so we will delete it.
449 */
451 if(isset($_SESSION['SelectedSystemType'])){
452 $SelectedSystemType= $_SESSION['SelectedSystemType'];
453 unset($_SESSION['SelectedSystemType']);
454 if($SelectedSystemType['ogroup'] != "none"){
455 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
456 if($og){
457 $og->AddDelMembership($this->systab->dn);
458 $og->save();
459 }
460 }
461 if(!isset($ldap)){
462 $ldap = $this->config->get_ldap_link();
463 }
464 $ldap->cd ($this->dn);
465 $ldap->cat($this->dn, array('dn'));
466 if(count($ldap->fetch())){
467 $ldap->cd($this->dn);
468 $ldap->rmDir($this->dn);
469 }
470 $ldap->cd($this->config->current['BASE']);
471 }
473 if (!isset($_POST['edit_apply'])){
474 /* Terminal has been saved successfully, remove lock from
475 LDAP. */
476 if ($this->dn != "new"){
477 del_lock ($this->dn);
478 }
480 unset ($this->systab);
481 $this->systab= NULL;
482 unset($_SESSION['objectinfo']);
483 }
484 } else {
485 /* Ok. There seem to be errors regarding to the tab data,
486 show message and continue as usual. */
487 show_errors($message);
488 }
489 }
491 /********************
492 Edit system was canceled
493 ********************/
494 /* Cancel dialogs */
495 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
496 if (isset($this->systab)){
497 del_lock ($this->systab->dn);
498 unset ($this->systab);
499 }
500 $this->systab= NULL;
501 unset($_SESSION['objectinfo']);
503 /* Remove ogroup selection, which was set while editing a new incoming entry */
504 if(isset($_SESSION['SelectedSystemType'])){
505 unset($_SESSION['SelectedSystemType']);
506 }
507 }
509 /********************
510 Display edit dialog, or some other
511 ********************/
513 /* Show tab dialog if object is present */
514 if (isset($this->systab->config)){
515 $display= $this->systab->execute();
517 /* Don't show buttons if tab dialog requests this */
518 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
519 $display.= "<p style=\"text-align:right\">\n";
520 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
521 $display.= " \n";
522 if ($this->dn != "new"){
523 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
524 $display.= " \n";
525 }
526 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
527 $display.= "</p>";
528 }
529 return ($display);
530 }
532 /* Check if there is a snapshot dialog open */
533 $base = $this->DivListSystem->selectedBase;
534 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
535 return($str);
536 }
538 /* Display dialog with system list */
539 $this->DivListSystem->parent = $this;
540 $this->DivListSystem->execute();
542 /* Add departments if subsearch is disabled */
543 if(!$this->DivListSystem->SubSearch){
544 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
545 }
546 $this->reload();
547 $this->DivListSystem->setEntries($this->terminals);
548 return($this->DivListSystem->Draw());
549 }
552 /* Return departments, that will be included within snapshot detection */
553 function get_used_snapshot_bases()
554 {
555 $tmp = array();
556 foreach(array("phones","servers","printers","terminals","netdevices","workstations") as $ent){
557 $tmp[] = "ou=".$ent.",ou=systems,".$this->DivListSystem->selectedBase;
558 }
559 return($tmp);
560 }
563 function remove_from_parent()
564 {
565 /* Optionally execute a command after we're done */
566 $this->postremove();
567 }
570 /* Save data to object */
571 function save_object()
572 {
573 $this->DivListSystem->save_object();
574 }
577 /* Check values */
578 function check()
579 {
580 }
583 /* Save to LDAP */
584 function save()
585 {
586 }
588 function adapt_from_template($dn)
589 {
590 }
592 function password_change_needed()
593 {
594 }
596 function reload()
597 {
598 /* some var init */
599 $ui = get_userinfo();
600 $res = array();
601 $this->terminals = array();
602 $userregex = "";
604 /* Set base for all searches */
605 $base= $this->DivListSystem->selectedBase;
607 /* Prepare samba class name */
608 $samba ="";
609 if ($this->DivListSystem->ShowWinWorkstations){
610 if ($this->config->current['SAMBAVERSION'] == "3"){
611 $samba= "sambaSamAccount";
612 } else {
613 $samba= "sambaAccount";
614 }
615 }
617 /* This array represents the combination between checkboxes and search filters */
618 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
619 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
620 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
621 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
622 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
623 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
624 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
626 /* Include the 'Display Systems of user' attribute */
627 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
628 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
629 }
631 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
632 foreach($objs as $checkBox => $oc){
633 if($this->DivListSystem->$checkBox){
634 if($this->DivListSystem->SubSearch){
635 if($oc['CLASS'] != ""){
636 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
637 $res = array_merge($res,get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
638 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
639 }
640 }else{
641 /* User filter? */
642 if($oc['CLASS'] != ""){
643 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
644 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
645 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
646 }
647 }
648 }
649 }
651 /* Search for incoming objects */
652 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
653 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
654 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
656 /* Get all gotoTerminal's */
657 foreach ($res as $value){
659 $tmp= $value['dn'];
660 $add= "";
662 /* Extract base */
663 foreach($objs as $obj){
664 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
665 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
666 }
667 }
669 /* Create a string containing the last part of the department. */
670 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
671 if(empty($dn_name)){
672 $dn_name = "/";
673 }
675 /* check if current object is a new one */
676 if (preg_match ("/,ou=incoming,/i", $tmp)){
677 if (in_array_ics('gotoTerminal', $value['objectClass'])){
678 $add= "- "._("New terminal");
679 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
680 $add= "- "._("New workstation");
681 }elseif (in_array_ics('GOhard', $value['objectClass'])){
682 $add= "- "._("New Device");
683 }
684 }
686 /* Detect type of object and create an entry for $this->terminals */
687 $terminal = array();
689 if (in_array_ics('gotoTerminal', $value["objectClass"])){
691 /* check acl */
692 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
693 if($add != "" || preg_match("/r/",$acl)) {
694 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
695 $terminal = $value;
696 $terminal['type'] = "T";
697 $terminal['is_new'] = $add;
698 } else {
699 $terminal = $value;
700 $terminal['type'] = "D";
701 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
702 $terminal['location'] = array_search($tmp, $this->config->departments);
703 }
704 }
705 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
707 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
708 if($add != "" || preg_match("/r/",$acl)) {
709 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
710 $terminal = $value;
711 $terminal['type'] = "L";
712 $terminal['is_new'] = $add;
713 } else {
714 $terminal = $value;
715 $terminal['type'] = "D";
716 $terminal['location'] = array_search($tmp, $this->config->departments);
717 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
718 }
719 if (isset($value["FAIstate"][0])){
720 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
721 }
722 }
723 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
726 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
727 if($add != "" || preg_match("/r/",$acl)) {
729 $terminal = $value;
730 $terminal['type'] = "P";
731 }
732 } elseif (in_array_ics('goServer', $value["objectClass"])){
734 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
735 if($add != "" || preg_match("/r/",$acl)) {
737 $terminal = $value;
738 $terminal['type'] = "S";
739 if (isset($value["FAIstate"][0])){
740 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
741 }
742 }
743 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
745 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
746 if($add != "" || preg_match("/r/",$acl)) {
748 $terminal = $value;
749 $terminal['type'] = "F";
750 }
751 }elseif (in_array_ics("GOhard",$value['objectClass'])){
753 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
754 $ui->get_permissions($value['dn'],"terminal/termgeneric").
755 $ui->get_permissions($value['dn'],"workstation/workgeneric");
756 if($add != "" || preg_match("/r/",$acl)) {
758 $terminal = $value;
759 $terminal['type'] = "Q";
760 $terminal['is_new'] = $add;
761 }
762 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
764 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
765 if($add != "" || preg_match("/r/",$acl)) {
767 $terminal = $value;
768 $terminal['type'] = "C";
769 }
770 } else{
772 $name= preg_replace('/\$$/', '', $value['cn'][0]);
773 if (isset($value['sambaDomainName'])){
774 $domain= " [".$value['sambaDomainName'][0]."]";
775 } else {
776 $domain= "";
777 }
778 $terminal=$value;
779 $terminal['type'] ="W";
780 $terminal['domain'] = $name.$domain;
781 }
783 if(count($terminal)){
784 $this->terminals[]=$terminal;
785 }
786 }
788 $tmp=array();
789 foreach($this->terminals as $tkey => $val ){
790 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
791 }
792 ksort($tmp);
793 $this->terminals=array();
794 foreach($tmp as $val){
795 $this->terminals[]=$val;
796 }
797 reset ($this->terminals);
798 }
800 function remove_lock()
801 {
802 if (isset($this->systab->dn)){
803 del_lock ($this->systab->dn);
804 }
805 }
808 function get_system_type($classes)
809 {
810 $type= "";
811 if (in_array_ics('ieee802Device', $classes)){
812 $type= "component";
813 }elseif (in_array_ics('gotoTerminal', $classes)){
814 $type= "terminal";
815 }elseif (in_array_ics('gotoWorkstation', $classes)){
816 $type= "workstation";
817 }elseif (in_array_ics('gotoPrinter', $classes)){
818 $type= "printer";
819 }elseif (in_array_ics('goFonHardware', $classes)){
820 $type= "phone";
821 }elseif (in_array_ics('goServer', $classes)){
822 $type= "server";
823 }elseif (in_array_ics('GOhard', $classes)){
824 $type= "NewDevice";
825 }elseif (in_array_ics('sambaAccount', $classes) ||
826 in_array_ics('sambaSamAccount', $classes)){
827 $type= "winstation";
828 }
829 return ($type);
830 }
833 function convert_list($input)
834 {
835 $temp= "";
836 $conv= array(
837 "NQ" => array("select_newsystem.png",_("New System from incoming")),
838 "D" => array("select_default.png",_("Template")),
839 "T" => array("select_terminal.png",_("Terminal")),
840 "L" => array("select_workstation.png",_("Workstation")),
841 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
842 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
843 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
844 "F" => array("select_phone.png",_("Phone")),
845 "S" => array("select_server.png",_("Server")),
846 "GS" => array("select_server_green.png",_("Server is installing")),
847 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
848 "RS" => array("select_server_red.png",_("Server installation failed")),
849 "W" => array("select_winstation.png",_("Winstation")),
850 "C" => array("select_component.png",_("Network Device")),
851 "NT"=> array("select_new_terminal.png",_("New Terminal")),
852 "NL"=> array("select_new_workstation.png",_("New Workstation")),
853 "P" => array("select_printer.png",_("Printer")));
855 if((isset($input['is_new']))&&(!empty($input['is_new']))){
856 $input['type']="N".$input['type'];
857 }
858 foreach ($conv as $key => $value){
859 if($input['type']==$key){
860 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
861 $tmp['class']=$key;
862 return $tmp;
863 }
864 }
865 }
868 function getState($type, $state)
869 {
870 switch (preg_replace('/:.*$/', '', $state)) {
871 case 'installing':
872 $type= 'G'.$type;
873 break;
874 case 'error':
875 $type= 'R'.$type;
876 break;
877 case 'install':
878 $type= 'Y'.$type;
879 break;
880 case 'sysinfo':
881 $type= 'Y'.$type;
882 break;
883 case 'softupdate':
884 $type= 'Y'.$type;
885 break;
886 }
889 return ($type);
890 }
892 }
894 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
895 ?>