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'];
304 /* Load permissions for selected 'dn' and check if
305 we're allowed to remove this 'dn' */
306 $ui = get_userinfo();
307 $acl = $ui -> get_category_permissions($this->dn,"terminal");
308 if(preg_match("/w/",$acl)){
310 /* Check locking, save current plugin in 'back_plugin', so
311 the dialog knows where to return. */
312 if (($user= get_lock($this->dn)) != ""){
313 return(gen_locked_message ($user, $this->dn));
314 }
316 /* Lock the current entry, so nobody will edit it during deletion */
317 add_lock ($this->dn, $this->ui->dn);
318 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
319 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
320 } else {
322 /* Obviously the user isn't allowed to delete. Show message and
323 clean session. */
324 print_red (_("You are not allowed to delete this component!"));
325 }
326 }
329 /********************
330 Delete system, confirmed
331 ********************/
332 /* Confirmation for deletion has been passed. Terminal should be deleted. */
333 if (isset($_POST['delete_terminal_confirm'])){
335 /* Find out more about the object type */
336 $ldap= $this->config->get_ldap_link();
337 $ldap->cat($this->dn, array('objectClass'));
338 $attrs= $ldap->fetch();
339 $type= $this->get_system_type($attrs['objectClass']);
341 $ui = get_userinfo();
343 $tabs = array(
344 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
345 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
346 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
347 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
348 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
349 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
350 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
353 /* get object type */
354 $tabtype = "termtabs";
355 $tabobj = "TERMTABS";
356 $tabacl = "";
357 if(isset($tabs[$type])){
358 $tabtype = $tabs[$type]['TABCLASS'];
359 $tabobj = $tabs[$type]['CLASS'];
360 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
361 }
363 /* Check if we are allowed to remove this object */
364 if(preg_match("/d/",$tabacl)){
366 /* Delete request is permitted, perform LDAP action */
367 if($tabtype=="phonetabs"){
368 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$tabs[$type]['ACL']);
369 $this->systab->set_acl_base($this->dn);
370 $this->systab->by_object['phonegeneric']->remove_from_parent ();
371 }else{
372 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$tabs[$type]['ACL']);
373 $this->systab->set_acl_base($this->dn);
374 $this->systab->delete();
375 }
376 unset ($this->systab);
377 gosa_log ("System object'".$this->dn."' has been removed");
378 $this->systab= NULL;
380 /* Terminal list has changed, reload it. */
381 } else {
383 /* Normally this shouldn't be reached, send some extra
384 logs to notify the administrator */
385 print_red (_("You are not allowed to delete this component!"));
386 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
387 "deletion.");
388 }
390 /* Remove lock file after successfull deletion */
391 del_lock ($this->dn);
392 }
395 /********************
396 Edit system type finished, check if everything went ok
397 ********************/
398 /* Finish user edit is triggered by the tabulator dialog, so
399 the user wants to save edited data. Check and save at this
400 point. */
401 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
403 /* Check tabs, will feed message array */
404 $message= $this->systab->check();
406 /* Save, or display error message? */
407 if (count($message) == 0){
409 /* Save terminal data to ldap */
410 if(isset($_SESSION['SelectedSystemType']['ogroup'])){
411 foreach (array("workservice", "termservice") as $cls){
412 if (isset($this->systab->by_object[$cls])){
413 $this->systab->by_object[$cls]->gotoXMouseport= "";
414 $this->systab->by_object[$cls]->gotoXMouseType= "";
415 $this->systab->by_object[$cls]->gotoXResolution= "";
416 $this->systab->by_object[$cls]->gotoXColordepth= "";
417 }
418 }
419 }
420 $this->systab->save();
421 gosa_log ("System object'".$this->dn."' has been saved");
423 /* Incoming behavior; you can select a system type and an ogroup membership.
424 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
425 * Check if we must add the new object to an object group.
426 *
427 * If this is done, delete the old incoming entry... it is still there, because this is a new
428 * entry and not an edited one, so we will delete it.
429 */
431 if(isset($_SESSION['SelectedSystemType'])){
432 $SelectedSystemType= $_SESSION['SelectedSystemType'];
433 unset($_SESSION['SelectedSystemType']);
434 if($SelectedSystemType['ogroup'] != "none"){
435 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
436 if($og){
437 $og->AddDelMembership($this->systab->dn);
438 $og->save();
439 }
440 }
441 if(!isset($ldap)){
442 $ldap = $this->config->get_ldap_link();
443 }
444 $ldap->cd ($this->dn);
445 $ldap->cat($this->dn, array('dn'));
446 if(count($ldap->fetch())){
447 $ldap->cd($this->dn);
448 $ldap->rmDir($this->dn);
449 }
450 $ldap->cd($this->config->current['BASE']);
451 }
453 if (!isset($_POST['edit_apply'])){
454 /* Terminal has been saved successfully, remove lock from
455 LDAP. */
456 if ($this->dn != "new"){
457 del_lock ($this->dn);
458 }
460 unset ($this->systab);
461 $this->systab= NULL;
462 unset($_SESSION['objectinfo']);
463 }
464 } else {
465 /* Ok. There seem to be errors regarding to the tab data,
466 show message and continue as usual. */
467 show_errors($message);
468 }
469 }
471 /********************
472 Edit system was canceled
473 ********************/
474 /* Cancel dialogs */
475 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
476 if (isset($this->systab)){
477 del_lock ($this->systab->dn);
478 unset ($this->systab);
479 }
480 $this->systab= NULL;
481 unset($_SESSION['objectinfo']);
483 /* Remove ogroup selection, which was set while editing a new incoming entry */
484 if(isset($_SESSION['SelectedSystemType'])){
485 unset($_SESSION['SelectedSystemType']);
486 }
487 }
489 /********************
490 Display edit dialog, or some other
491 ********************/
493 /* Show tab dialog if object is present */
494 if (isset($this->systab->config)){
495 $display= $this->systab->execute();
497 /* Don't show buttons if tab dialog requests this */
498 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
499 $display.= "<p style=\"text-align:right\">\n";
500 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
501 $display.= " \n";
502 if ($this->dn != "new"){
503 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
504 $display.= " \n";
505 }
506 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
507 $display.= "</p>";
508 }
509 return ($display);
510 }
512 /* Check if there is a snapshot dialog open */
513 $base = $this->DivListSystem->selectedBase;
514 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
515 return($str);
516 }
518 /* Display dialog with system list */
519 $this->DivListSystem->parent = $this;
520 $this->DivListSystem->execute();
522 /* Add departments if subsearch is disabled */
523 if(!$this->DivListSystem->SubSearch){
524 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
525 }
526 $this->reload();
527 $this->DivListSystem->setEntries($this->terminals);
528 return($this->DivListSystem->Draw());
529 }
532 /* Return departments, that will be included within snapshot detection */
533 function get_used_snapshot_bases()
534 {
535 $tmp = array();
536 foreach(array("phones","servers","printers","terminals","netdevices","workstations") as $ent){
537 $tmp[] = "ou=".$ent.",ou=systems,".$this->DivListSystem->selectedBase;
538 }
539 return($tmp);
540 }
543 function remove_from_parent()
544 {
545 /* Optionally execute a command after we're done */
546 $this->postremove();
547 }
550 /* Save data to object */
551 function save_object()
552 {
553 $this->DivListSystem->save_object();
554 }
557 /* Check values */
558 function check()
559 {
560 }
563 /* Save to LDAP */
564 function save()
565 {
566 }
568 function adapt_from_template($dn)
569 {
570 }
572 function password_change_needed()
573 {
574 }
576 function reload()
577 {
578 /* some var init */
579 $ui = get_userinfo();
580 $res = array();
581 $this->terminals = array();
582 $userregex = "";
584 /* Set base for all searches */
585 $base= $this->DivListSystem->selectedBase;
587 /* Prepare samba class name */
588 $samba ="";
589 if ($this->DivListSystem->ShowWinWorkstations){
590 if ($this->config->current['SAMBAVERSION'] == "3"){
591 $samba= "sambaSamAccount";
592 } else {
593 $samba= "sambaAccount";
594 }
595 }
597 /* This array represents the combination between checkboxes and search filters */
598 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
599 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
600 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
601 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
602 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
603 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
604 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
606 /* Include the 'Display Systems of user' attribute */
607 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
608 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
609 }
611 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
612 foreach($objs as $checkBox => $oc){
613 if($this->DivListSystem->$checkBox){
614 if($this->DivListSystem->SubSearch){
615 if($oc['CLASS'] != ""){
616 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
617 $res = array_merge($res,get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
618 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
619 }
620 }else{
621 /* User filter? */
622 if($oc['CLASS'] != ""){
623 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
624 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
625 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
626 }
627 }
628 }
629 }
631 /* Search for incoming objects */
632 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
633 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
634 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
636 /* Get all gotoTerminal's */
637 foreach ($res as $value){
639 $tmp= $value['dn'];
640 $add= "";
642 /* Extract base */
643 foreach($objs as $obj){
644 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
645 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
646 }
647 }
649 /* check if current object is a new one */
650 if (preg_match ("/,ou=incoming,/i", $tmp)){
651 if (in_array_ics('gotoTerminal', $value['objectClass'])){
652 $add= "- "._("New terminal");
653 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
654 $add= "- "._("New workstation");
655 }elseif (in_array_ics('GOhard', $value['objectClass'])){
656 $add= "- "._("New Device");
657 }
658 }
660 /* Detect type of object and create an entry for $this->terminals */
661 $terminal = array();
663 if (in_array_ics('gotoTerminal', $value["objectClass"])){
665 /* check acl */
666 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
667 if($add != "" || preg_match("/r/",$acl)) {
668 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
669 $terminal = $value;
670 $terminal['type'] = "T";
671 $terminal['is_new'] = $add;
672 } else {
673 $terminal = $value;
674 $terminal['type'] = "D";
675 $terminal['message'] = _("Terminal template for");
676 $terminal['location'] = array_search($tmp, $this->config->departments);
677 }
678 }
679 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
681 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
682 if($add != "" || preg_match("/r/",$acl)) {
683 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
684 $terminal = $value;
685 $terminal['type'] = "L";
686 $terminal['is_new'] = $add;
687 } else {
688 $terminal = $value;
689 $terminal['type'] = "D";
690 $terminal['location'] = array_search($tmp, $this->config->departments);
691 $terminal['message'] = _("Workstation template for");
692 }
693 if (isset($value["FAIstate"][0])){
694 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
695 }
696 }
697 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
700 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
701 if($add != "" || preg_match("/r/",$acl)) {
703 $terminal = $value;
704 $terminal['type'] = "P";
705 }
706 } elseif (in_array_ics('goServer', $value["objectClass"])){
708 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
709 if($add != "" || preg_match("/r/",$acl)) {
711 $terminal = $value;
712 $terminal['type'] = "S";
713 if (isset($value["FAIstate"][0])){
714 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
715 }
716 }
717 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
719 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
720 if($add != "" || preg_match("/r/",$acl)) {
722 $terminal = $value;
723 $terminal['type'] = "F";
724 }
725 }elseif (in_array_ics("GOhard",$value['objectClass'])){
727 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
728 $ui->get_permissions($value['dn'],"terminal/termgeneric").
729 $ui->get_permissions($value['dn'],"workstation/workgeneric");
730 if($add != "" || preg_match("/r/",$acl)) {
732 $terminal = $value;
733 $terminal['type'] = "Q";
734 $terminal['is_new'] = $add;
735 }
736 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
738 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
739 if($add != "" || preg_match("/r/",$acl)) {
741 $terminal = $value;
742 $terminal['type'] = "C";
743 }
744 } else{
746 $name= preg_replace('/\$$/', '', $value['cn'][0]);
747 if (isset($value['sambaDomainName'])){
748 $domain= " [".$value['sambaDomainName'][0]."]";
749 } else {
750 $domain= "";
751 }
752 $terminal=$value;
753 $terminal['type'] ="W";
754 $terminal['domain'] = $name.$domain;
755 }
757 if(count($terminal)){
758 $this->terminals[]=$terminal;
759 }
760 }
762 $tmp=array();
763 foreach($this->terminals as $tkey => $val ){
764 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
765 }
766 ksort($tmp);
767 $this->terminals=array();
768 foreach($tmp as $val){
769 $this->terminals[]=$val;
770 }
771 reset ($this->terminals);
772 }
774 function remove_lock()
775 {
776 if (isset($this->systab->dn)){
777 del_lock ($this->systab->dn);
778 }
779 }
782 function get_system_type($classes)
783 {
784 $type= "";
785 if (in_array_ics('ieee802Device', $classes)){
786 $type= "component";
787 }elseif (in_array_ics('gotoTerminal', $classes)){
788 $type= "terminal";
789 }elseif (in_array_ics('gotoWorkstation', $classes)){
790 $type= "workstation";
791 }elseif (in_array_ics('gotoPrinter', $classes)){
792 $type= "printer";
793 }elseif (in_array_ics('goFonHardware', $classes)){
794 $type= "phone";
795 }elseif (in_array_ics('goServer', $classes)){
796 $type= "server";
797 }elseif (in_array_ics('GOhard', $classes)){
798 $type= "NewDevice";
799 }elseif (in_array_ics('sambaAccount', $classes) ||
800 in_array_ics('sambaSamAccount', $classes)){
801 $type= "winstation";
802 }
803 return ($type);
804 }
807 function convert_list($input)
808 {
809 $temp= "";
810 $conv= array(
811 "NQ" => array("select_newsystem.png",_("New System from incoming")),
812 "D" => array("select_default.png",_("Template")),
813 "T" => array("select_terminal.png",_("Terminal")),
814 "L" => array("select_workstation.png",_("Workstation")),
815 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
816 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
817 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
818 "F" => array("select_phone.png",_("Phone")),
819 "S" => array("select_server.png",_("Server")),
820 "GS" => array("select_server_green.png",_("Server is installing")),
821 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
822 "RS" => array("select_server_red.png",_("Server installation failed")),
823 "W" => array("select_winstation.png",_("Winstation")),
824 "C" => array("select_component.png",_("Network Device")),
825 "NT"=> array("select_new_terminal.png",_("New Terminal")),
826 "NL"=> array("select_new_workstation.png",_("New Workstation")),
827 "P" => array("select_printer.png",_("Printer")));
829 if((isset($input['is_new']))&&(!empty($input['is_new']))){
830 $input['type']="N".$input['type'];
831 }
832 foreach ($conv as $key => $value){
833 if($input['type']==$key){
834 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
835 $tmp['class']=$key;
836 return $tmp;
837 }
838 }
839 }
842 function getState($type, $state)
843 {
844 switch (preg_replace('/:.*$/', '', $state)) {
845 case 'installing':
846 $type= 'G'.$type;
847 break;
848 case 'error':
849 $type= 'R'.$type;
850 break;
851 case 'install':
852 $type= 'Y'.$type;
853 break;
854 case 'sysinfo':
855 $type= 'Y'.$type;
856 break;
857 case 'softupdate':
858 $type= 'Y'.$type;
859 break;
860 }
863 return ($type);
864 }
866 }
868 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
869 ?>