1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31 /* Definitions */
32 var $plHeadline= "Systems";
33 var $plDescription= "This does something";
34 var $departments=array();
36 /* Dialog attributes */
37 var $systab= NULL;
38 var $terminals= array();
39 var $ui= NULL;
40 var $acl= "";
41 var $DivListSystem;
43 function systems ($config, $ui)
44 {
45 /* Save configuration for internal use */
46 $this->config= $config;
47 $this->ui= $ui;
49 /* Creat dialog object */
50 $this->DivListSystem = new divListSystem($this->config,$this);
51 }
53 function execute()
54 {
55 /* Call parent execute */
56 plugin::execute();
58 $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
60 /********************
61 Check for functional posts, edit|delete|add|... system devices
62 ********************/
63 $s_action = ""; // Contains the action to proceed
64 $s_entry = ""; // The value for s_action
65 $base_back = ""; // The Link for Backbutton
66 $smarty = get_smarty();
68 /* Test Posts */
69 foreach($_POST as $key => $val){
70 // Post for delete
71 if(preg_match("/user_del.*/",$key)){
72 $s_action = "del";
73 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
74 // Post for edit
75 }elseif(preg_match("/user_edit_.*/",$key)){
76 $s_action="edit";
77 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
78 // Post for new
79 }elseif(preg_match("/user_new.*/",$key)){
80 $s_action="new";
81 }elseif(preg_match("/user_tplnew.*/i",$key)){
82 $s_action="new_tpl";
83 }elseif(preg_match("/user_setpwd_.*/i",$key)){
84 $s_action="change_pw";
85 $s_entry = preg_replace("/user_setpwd_/i","",$key);
86 }elseif(preg_match("/gen_cd_.*/i",$key)){
87 $s_action="gen_cd";
88 $s_entry = preg_replace("/gen_cd_/i","",$key);
89 }elseif(preg_match("/newsystem_.*/i",$key)){
90 $s_action="newsystem";
91 $s_entry = preg_replace("/newsystem_/i","",$key);
92 }
93 }
95 /* Incoming handling
96 * If someone made a systemtype and ogroup selection
97 * Display the new requested entry type ... servtab in case of server and so on.
98 */
99 if(isset($_POST['SystemTypeChoosen'])){
100 $s_action = "SelectedSystemType";
101 $s_entry = $_POST['SystemType'];
102 $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
103 $this->systab = NULL;
104 }
106 /* remove image tags from posted entry (posts looks like this 'name_x')*/
107 $s_entry = preg_replace("/_.$/","",$s_entry);
109 /* Edit was requested by pressing the name(link) of an item */
110 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
111 $s_action ="edit";
112 $s_entry = $_GET['id'];
113 }
115 /* Check for exeeded sizelimit */
116 if (($message= check_sizelimit()) != ""){
117 return($message);
118 }
120 /* Try to get informations about what kind of system to create */
121 if ($s_action=="new") {
122 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
123 }
125 /********************
126 Create new system ...
127 ********************/
128 /* Create new default terminal
129 * Or create specified object of selected system type, from given incoming object
130 */
132 $save_object_directly = false;
133 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
134 $save_object_directly = true;
135 }
137 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
139 /* If the current entry is an incoming object
140 * $sw = System type as posted in new incoming handling dialog
141 */
142 if($s_action == "SelectedSystemType") {
143 $sw = $s_entry;
144 }else{
145 if(isset($_POST['system'])){
146 $sw = $_POST['system'];
147 }else{
148 $sw = $s_entry;
149 }
150 $this->dn= "new";
151 }
152 $this->acl= array(":all");
153 $tabs = array(
154 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs"),
155 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs"),
156 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs"),
157 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs"),
158 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phonegeneric", "TABCLASS" =>"phonetabs"),
159 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
161 if(isset($tabs[$sw])){
162 $class = $tabs[$sw]["CLASS"];
163 $tabname = $tabs[$sw]["TABNAME"];
164 $tabclass = $tabs[$sw]["TABCLASS"];
165 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
166 $this->systab->set_acl ($this->acl);
167 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
168 $this->systab->base = $this->DivListSystem->selectedBase;
169 }
170 }
172 /********************
173 Edit system ...
174 ********************/
176 /* User wants to edit data? */
177 if (($s_action == "edit") && (!isset($this->systab->config))){
179 $this->dn= $this->terminals[$s_entry]['dn'];
181 /* Check locking, save current plugin in 'back_plugin', so
182 the dialog knows where to return. */
183 if (($user= get_lock($this->dn)) != ""){
184 return(gen_locked_message ($user, $this->dn));
185 }
187 /* Set up the users ACL's for this 'dn' */
188 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
190 /* Find out more about the object type */
191 $ldap= $this->config->get_ldap_link();
192 $ldap->cat($this->dn, array('objectClass'));
193 $attrs= $ldap->fetch();
194 $type= $this->get_system_type($attrs['objectClass']);
196 /* Lock the current entry, so everyone will get the
197 above dialog */
198 $tabs = array(
199 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
200 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
201 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
202 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
203 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
204 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
205 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
208 if($type == "NewDevice"){
209 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
210 }elseif(isset($tabs[$type])){
212 $class = $tabs[$type]["CLASS"];
213 $tabclass = $tabs[$type]["TABCLASS"];
215 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
216 $this->systab->set_acl($acl);
217 $_SESSION['objectinfo']= $this->dn;
218 add_lock ($this->dn, $this->ui->dn);
219 }else{
220 print_red (_("You can't edit this object type yet!"));
221 del_lock($this->dn);
222 }
223 }
225 /********************
226 Create FAI CD ...
227 ********************/
228 if ($s_action=="gen_cd"){
229 $this->dn= $this->terminals[$s_entry]['dn'];
230 $_SESSION['objectinfo']= $this->dn;
231 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
232 }
236 /********************
237 Change password ...
238 ********************/
240 /* Set terminals root password */
241 if ($s_action=="change_pw"){
242 $this->dn= $this->terminals[$s_entry]['dn'];
243 $_SESSION['objectinfo']= $this->dn;
244 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
245 }
248 /********************
249 Password cahnge finish, but check if entered data is ok
250 ********************/
252 /* Correctly specified? */
253 if (isset($_POST['password_finish'])){
254 if ($_POST['new_password'] != $_POST['repeated_password']){
255 print_red (_("Passwords entered as new and repeated do not match!"));
256 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
257 }
258 }
260 /********************
261 Password change finish
262 ********************/
264 /* Change terminal password */
265 if (isset($_POST['password_finish']) &&
266 $_POST['new_password'] == $_POST['repeated_password']){
268 /* Check if user is allowed to set password */
269 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
270 $acl= get_module_permission($acl, "terminal", $this->dn);
271 if (chkacl($acl, "password") != ""){
272 print_red (_("You are not allowed to set this systems password!"));
273 } else {
274 $ldap= $this->config->get_ldap_link();
275 $ldap->cd($this->dn);
277 $attrs= array();
278 if ($_POST['new_password'] == ""){
279 $attrs['gotoRootPasswd']= array();
280 } else {
281 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
282 substr(session_id(),0,2));
283 }
284 $ldap->modify($attrs);
285 gosa_log ("Password for '".$this->dn."' has been changed");
286 }
287 unset($_SESSION['objectinfo']);
288 }
291 /********************
292 Delete system cancel
293 ********************/
295 /* Delete terminal canceled? */
296 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
297 del_lock ($this->dn);
298 unset($_SESSION['objectinfo']);
299 }
302 /********************
303 Delete system, confirm dialog
304 ********************/
306 /* Remove terminal was requested */
307 if ($s_action=="del"){
309 /* Get 'dn' from posted termlinst */
310 $this->dn= $this->terminals[$s_entry]['dn'];
312 /* Load permissions for selected 'dn' and check if
313 we're allowed to remove this 'dn' */
314 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
315 $this->acl= get_module_permission($acl, "terminal", $this->dn);
316 if (chkacl($this->acl, "delete") == ""){
318 /* Check locking, save current plugin in 'back_plugin', so
319 the dialog knows where to return. */
320 if (($user= get_lock($this->dn)) != ""){
321 return(gen_locked_message ($user, $this->dn));
322 }
324 /* Lock the current entry, so nobody will edit it during deletion */
325 add_lock ($this->dn, $this->ui->dn);
326 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
327 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
328 } else {
330 /* Obviously the user isn't allowed to delete. Show message and
331 clean session. */
332 print_red (_("You are not allowed to delete this component!"));
333 }
334 }
337 /********************
338 Delete system, confirmed
339 ********************/
340 /* Confirmation for deletion has been passed. Terminal should be deleted. */
341 if (isset($_POST['delete_terminal_confirm'])){
343 /* Some nice guy may send this as POST, so we've to check
344 for the permissions again. */
345 if (chkacl($this->acl, "delete") == ""){
347 /* Find out more about the object type */
348 $ldap= $this->config->get_ldap_link();
349 $ldap->cat($this->dn, array('objectClass'));
350 $attrs= $ldap->fetch();
351 $type= $this->get_system_type($attrs['objectClass']);
353 $tabs = array(
354 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
355 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
356 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
357 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
358 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
359 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
360 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
362 /* get object type */
363 $tabtype = "termtabs";
364 $tabobj = "TERMTABS";
365 if(isset($tabs[$type])){
366 $tabtype = $tabs[$type]['TABCLASS'];
367 $tabobj = $tabs[$type]['CLASS'];
368 }
370 /* Delete request is permitted, perform LDAP action */
371 if($tabtype=="phonetabs"){
372 $this->systab= new $tabtype($this->config,
373 $this->config->data['TABS'][$tabobj], $this->dn);
374 $this->systab->set_acl(array($this->acl));
375 $this->systab->by_object['phonegeneric']->remove_from_parent ();
376 }else{
377 $this->systab= new $tabtype($this->config,
378 $this->config->data['TABS'][$tabobj], $this->dn);
379 $this->systab->set_acl(array($this->acl));
380 $this->systab->delete();
381 #$this->systab->by_object['termgeneric']->remove_from_parent ();
382 }
383 unset ($this->systab);
384 gosa_log ("System object'".$this->dn."' has been removed");
385 $this->systab= NULL;
387 /* Terminal list has changed, reload it. */
388 } else {
390 /* Normally this shouldn't be reached, send some extra
391 logs to notify the administrator */
392 print_red (_("You are not allowed to delete this component!"));
393 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
394 "deletion.");
395 }
397 /* Remove lock file after successfull deletion */
398 del_lock ($this->dn);
399 }
402 /********************
403 Edit system type finished, check if everything went ok
404 ********************/
405 /* Finish user edit is triggered by the tabulator dialog, so
406 the user wants to save edited data. Check and save at this
407 point. */
408 if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
410 /* Check tabs, will feed message array */
411 $message = array();
412 if(!$save_object_directly){
413 $message = $this->systab->check();
414 }else{
415 $found = false;
417 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
418 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
419 if(isset($this->systab->by_object[$tab]->gotoMode)) {
420 $found = true;
421 $this->systab->by_object[$tab]->gotoMode = $value;
422 }
423 }
424 if(!$found){
425 print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
426 }
428 }
429 /* Save, or display error message? */
430 if (count($message) == 0){
432 /* Save terminal data to ldap */
433 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
434 foreach (array("workservice", "termservice") as $cls){
435 if (isset($this->systab->by_object[$cls])){
436 $this->systab->by_object[$cls]->gotoXMouseport= "";
437 $this->systab->by_object[$cls]->gotoXMouseType= "";
438 $this->systab->by_object[$cls]->gotoXResolution= "";
439 $this->systab->by_object[$cls]->gotoXColordepth= "";
440 }
441 }
442 }
444 $this->systab->save();
445 gosa_log ("System object'".$this->dn."' has been saved");
447 /* Incoming behavior; you can select a system type and an ogroup membership.
448 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
449 * Check if we must add the new object to an object group.
450 *
451 * If this is done, delete the old incoming entry... it is still there, because this is a new
452 * entry and not an edited one, so we will delete it.
453 */
455 if(isset($_SESSION['SelectedSystemType'])){
456 $SelectedSystemType= $_SESSION['SelectedSystemType'];
457 unset($_SESSION['SelectedSystemType']);
458 if($SelectedSystemType['ogroup'] != "none"){
459 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
460 if($og){
461 $og->AddDelMembership($this->systab->dn);
462 $og->save();
463 }
464 }
465 if(!isset($ldap)){
466 $ldap = $this->config->get_ldap_link();
467 }
468 $ldap->cd ($this->dn);
469 $ldap->cat($this->dn, array('dn'));
470 if(count($ldap->fetch())){
471 $ldap->cd($this->dn);
472 $ldap->rmDir($this->dn);
473 }
474 $ldap->cd($this->config->current['BASE']);
475 }
477 /* Terminal has been saved successfully, remove lock from
478 LDAP. */
479 if ($this->dn != "new"){
480 del_lock ($this->dn);
481 }
483 unset ($this->systab);
484 $this->systab= NULL;
485 unset($_SESSION['objectinfo']);
486 } else {
487 /* Ok. There seem to be errors regarding to the tab data,
488 show message and continue as usual. */
489 show_errors($message);
490 }
491 }
493 /********************
494 Edit system was canceled
495 ********************/
496 /* Cancel dialogs */
497 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
498 if (isset($this->systab)){
499 del_lock ($this->systab->dn);
500 unset ($this->systab);
501 }
502 $this->systab= NULL;
503 unset($_SESSION['objectinfo']);
505 /* Remove ogroup selection, which was set while editing a new incoming entry */
506 if(isset($_SESSION['SelectedSystemType'])){
507 unset($_SESSION['SelectedSystemType']);
508 }
509 }
511 /********************
512 Display edit dialog, or some other
513 ********************/
515 /* Show tab dialog if object is present */
516 if (isset($this->systab->config)){
517 $display= $this->systab->execute();
519 /* Don't show buttons if tab dialog requests this */
520 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
521 $display.= "<p style=\"text-align:right\">\n";
522 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
523 $display.= " \n";
524 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
525 $display.= "</p>";
526 }
527 return ($display);
528 }
530 /* Display dialog with system list */
531 $this->DivListSystem->parent = $this;
532 $this->DivListSystem->execute();
534 /* Add departments if subsearch is disabled */
535 if(!$this->DivListSystem->SubSearch){
536 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
537 }
538 $this->reload();
539 $this->DivListSystem->setEntries($this->terminals);
540 return($this->DivListSystem->Draw());
541 }
545 function remove_from_parent()
546 {
547 /* Optionally execute a command after we're done */
548 $this->postremove();
549 }
552 /* Save data to object */
553 function save_object()
554 {
555 $this->DivListSystem->save_object();
556 }
559 /* Check values */
560 function check()
561 {
562 }
565 /* Save to LDAP */
566 function save()
567 {
568 }
570 function adapt_from_template($dn)
571 {
572 }
574 function password_change_needed()
575 {
576 }
578 function reload()
579 {
580 /* Load terminal shortcuts */
581 $responsible= array();
582 foreach ($this->config->departments as $key => $value){
583 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
584 "terminal", $value) == "#all#"){
585 $responsible[$key]= $value;
586 }
587 }
589 /* some var init */
590 $res = array();
591 $this->terminals = array();
592 $userregex = "";
594 /* Set base for all searches */
595 $base= $this->DivListSystem->selectedBase;
597 /* Prepare samba class name */
598 $samba ="";
599 if ($this->DivListSystem->ShowWinWorkstations){
600 if ($this->config->current['SAMBAVERSION'] == "3"){
601 $samba= "sambaSamAccount";
602 } else {
603 $samba= "sambaAccount";
604 }
605 }
607 /* This array represents the combination between checkboxes and search filters */
608 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
609 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
610 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
611 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
612 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
613 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
614 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
616 /* Include the 'Display Systems of user' attribute */
617 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
618 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
619 }
621 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
622 foreach($objs as $checkBox => $oc){
623 if($this->DivListSystem->$checkBox){
624 if($this->DivListSystem->SubSearch){
625 if($oc['CLASS'] != ""){
626 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
627 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
628 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
629 }
630 }else{
631 /* User filter? */
632 if($oc['CLASS'] != ""){
633 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
634 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
635 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
636 }
637 }
638 }
639 }
641 /* Search for incoming objects */
642 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
643 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
644 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
646 /* Get all gotoTerminal's */
647 foreach ($res as $value){
649 $tmp= $value['dn'];
650 $add= "";
652 /* Extract base */
653 foreach($objs as $obj){
654 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
655 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
656 }
657 }
659 /* check if current object is a new one */
660 if (preg_match ("/,ou=incoming,/i", $tmp)){
661 if (in_array_ics('gotoTerminal', $value['objectClass'])){
662 $add= "- "._("New terminal");
663 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
664 $add= "- "._("New workstation");
665 }elseif (in_array_ics('GOhard', $value['objectClass'])){
666 $add= "- "._("New Device");
667 }
668 }
670 /* Detect type of object and create an entry for $this->terminals */
671 $terminal = array();
672 if ((in_array ($tmp, $responsible)) || ($add != "")){
673 if (in_array_ics('gotoTerminal', $value["objectClass"])){
674 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
675 $terminal = $value;
676 $terminal['type'] = "T";
677 $terminal['is_new'] = $add;
678 } else {
679 $terminal = $value;
680 $terminal['type'] = "D";
681 $terminal['message'] = _("Terminal template for");
682 $terminal['location'] = array_search($tmp, $this->config->departments);
683 }
684 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
685 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
686 $terminal = $value;
687 $terminal['type'] = "L";
688 $terminal['is_new'] = $add;
689 } else {
690 $terminal = $value;
691 $terminal['type'] = "D";
692 $terminal['location'] = array_search($tmp, $this->config->departments);
693 $terminal['message'] = _("Workstation template for");
694 }
695 if (isset($value["FAIstate"][0])){
696 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
697 }
698 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
699 $terminal = $value;
700 $terminal['type'] = "P";
701 } elseif (in_array_ics('goServer', $value["objectClass"])){
702 $terminal = $value;
703 $terminal['type'] = "S";
704 if (isset($value["FAIstate"][0])){
705 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
706 }
707 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
708 $terminal = $value;
709 $terminal['type'] = "F";
710 }elseif (in_array_ics("GOhard",$value['objectClass'])){
711 $terminal = $value;
712 $terminal['type'] = "Q";
713 $terminal['is_new'] = $add;
714 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
715 $terminal = $value;
716 $terminal['type'] = "C";
717 } else{
718 $name= preg_replace('/\$$/', '', $value['cn'][0]);
719 if (isset($value['sambaDomainName'])){
720 $domain= " [".$value['sambaDomainName'][0]."]";
721 } else {
722 $domain= "";
723 }
724 $terminal=$value;
725 $terminal['type'] ="W";
726 $terminal['domain'] = $name.$domain;
727 }
728 $this->terminals[]=$terminal;
729 }
730 }
732 $tmp=array();
733 foreach($this->terminals as $tkey => $val ){
734 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
735 }
736 ksort($tmp);
737 $this->terminals=array();
738 foreach($tmp as $val){
739 $this->terminals[]=$val;
740 }
741 reset ($this->terminals);
742 }
744 function remove_lock()
745 {
746 if (isset($this->systab->dn)){
747 del_lock ($this->systab->dn);
748 }
749 }
752 function get_system_type($classes)
753 {
754 $type= "";
755 if (in_array_ics('ieee802Device', $classes)){
756 $type= "component";
757 }elseif (in_array_ics('gotoTerminal', $classes)){
758 $type= "terminal";
759 }elseif (in_array_ics('gotoWorkstation', $classes)){
760 $type= "workstation";
761 }elseif (in_array_ics('gotoPrinter', $classes)){
762 $type= "printer";
763 }elseif (in_array_ics('goFonHardware', $classes)){
764 $type= "phone";
765 }elseif (in_array_ics('goServer', $classes)){
766 $type= "server";
767 }elseif (in_array_ics('GOhard', $classes)){
768 $type= "NewDevice";
769 }elseif (in_array_ics('sambaAccount', $classes) ||
770 in_array_ics('sambaSamAccount', $classes)){
771 $type= "winstation";
772 }
773 return ($type);
774 }
777 function convert_list($input)
778 {
779 $temp= "";
780 $conv= array(
781 "NQ" => array("select_newsystem.png",_("New System from incoming")),
782 "D" => array("select_default.png",_("Template")),
783 "T" => array("select_terminal.png",_("Terminal")),
784 "L" => array("select_workstation.png",_("Workstation")),
785 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
786 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
787 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
788 "F" => array("select_phone.png",_("Phone")),
789 "S" => array("select_server.png",_("Server")),
790 "GS" => array("select_server_green.png",_("Server is installing")),
791 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
792 "RS" => array("select_server_red.png",_("Server installation failed")),
793 "W" => array("select_winstation.png",_("Winstation")),
794 "C" => array("select_component.png",_("Network Device")),
795 "NT"=> array("select_new_terminal.png",_("New Terminal")),
796 "NL"=> array("select_new_workstation.png",_("New Workstation")),
797 "P" => array("select_printer.png",_("Printer")));
799 if((isset($input['is_new']))&&(!empty($input['is_new']))){
800 $input['type']="N".$input['type'];
801 }
802 foreach ($conv as $key => $value){
803 if($input['type']==$key){
804 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
805 $tmp['class']=$key;
806 return $tmp;
807 }
808 }
809 }
812 function getState($type, $state)
813 {
814 switch (preg_replace('/:.*$/', '', $state)) {
815 case 'installing':
816 $type= 'G'.$type;
817 break;
818 case 'error':
819 $type= 'R'.$type;
820 break;
821 case 'install':
822 $type= 'Y'.$type;
823 break;
824 case 'sysinfo':
825 $type= 'Y'.$type;
826 break;
827 case 'softupdate':
828 $type= 'Y'.$type;
829 break;
830 }
833 return ($type);
834 }
836 }
838 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
839 ?>