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";
27 require "tabs_arpnewdevice.inc";
30 class systems extends plugin
31 {
32 /* Definitions */
33 var $plHeadline= "Systems";
34 var $plDescription= "This does something";
35 var $departments=array();
37 /* Dialog attributes */
38 var $systab= NULL;
39 var $terminals= array();
40 var $ui= NULL;
41 var $acl= "";
42 var $DivListSystem;
44 function systems ($config, $ui)
45 {
46 /* Save configuration for internal use */
47 $this->config= $config;
48 $this->ui= $ui;
50 /* Creat dialog object */
51 $this->DivListSystem = new divListSystem($this->config,$this);
52 }
54 function execute()
55 {
56 /* Call parent execute */
57 plugin::execute();
59 $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
61 /********************
62 Check for functional posts, edit|delete|add|... system devices
63 ********************/
64 $s_action = ""; // Contains the action to proceed
65 $s_entry = ""; // The value for s_action
66 $base_back = ""; // The Link for Backbutton
67 $smarty = get_smarty();
69 /* Test Posts */
70 foreach($_POST as $key => $val){
71 // Post for delete
72 if(preg_match("/user_del.*/",$key)){
73 $s_action = "del";
74 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
75 // Post for edit
76 }elseif(preg_match("/user_edit_.*/",$key)){
77 $s_action="edit";
78 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
79 // Post for new
80 }elseif(preg_match("/user_new.*/",$key)){
81 $s_action="new";
82 }elseif(preg_match("/user_tplnew.*/i",$key)){
83 $s_action="new_tpl";
84 }elseif(preg_match("/user_setpwd_.*/i",$key)){
85 $s_action="change_pw";
86 $s_entry = preg_replace("/user_setpwd_/i","",$key);
87 }elseif(preg_match("/gen_cd_.*/i",$key)){
88 $s_action="gen_cd";
89 $s_entry = preg_replace("/gen_cd_/i","",$key);
90 }elseif(preg_match("/newsystem_.*/i",$key)){
91 $s_action="newsystem";
92 $s_entry = preg_replace("/newsystem_/i","",$key);
93 }
94 }
96 /* Incoming handling
97 * If someone made a systemtype and ogroup selection
98 * Display the new requested entry type ... servtab in case of server and so on.
99 */
100 if(isset($_POST['SystemTypeChoosen'])){
101 $s_action = "SelectedSystemType";
102 $s_entry = $_POST['SystemType'];
103 $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
104 $this->systab = NULL;
105 }
107 /* remove image tags from posted entry (posts looks like this 'name_x')*/
108 $s_entry = preg_replace("/_.$/","",$s_entry);
110 /* Edit was requested by pressing the name(link) of an item */
111 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
112 $s_action ="edit";
113 $s_entry = $_GET['id'];
114 }
116 /* Check for exeeded sizelimit */
117 if (($message= check_sizelimit()) != ""){
118 return($message);
119 }
121 /* Try to get informations about what kind of system to create */
122 if ($s_action=="new") {
123 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
124 }
126 /********************
127 Create new system ...
128 ********************/
129 /* Create new default terminal
130 * Or create specified object of selected system type, from given incoming object
131 */
133 $save_object_directly = false;
134 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
135 $save_object_directly = true;
136 }
138 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
140 /* If the current entry is an incoming object
141 * $sw = System type as posted in new incoming handling dialog
142 */
143 if($s_action == "SelectedSystemType") {
144 $sw = $s_entry;
145 }else{
146 if(isset($_POST['system'])){
147 $sw = $_POST['system'];
148 }else{
149 $sw = $s_entry;
150 }
151 $this->dn= "new";
152 }
153 $this->acl= array(":all");
154 $tabs = array(
155 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs"),
156 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs"),
157 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs"),
158 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs"),
159 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phonegeneric", "TABCLASS" =>"phonetabs"),
160 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
162 if(isset($tabs[$sw])){
163 $class = $tabs[$sw]["CLASS"];
164 $tabname = $tabs[$sw]["TABNAME"];
165 $tabclass = $tabs[$sw]["TABCLASS"];
166 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
167 $this->systab->set_acl ($this->acl);
168 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
169 $this->systab->base = $this->DivListSystem->selectedBase;
170 }
171 }
173 /********************
174 Edit system ...
175 ********************/
177 /* User wants to edit data? */
178 if (($s_action == "edit") && (!isset($this->systab->config))){
180 $this->dn= $this->terminals[$s_entry]['dn'];
182 /* Check locking, save current plugin in 'back_plugin', so
183 the dialog knows where to return. */
184 if (($user= get_lock($this->dn)) != ""){
185 return(gen_locked_message ($user, $this->dn));
186 }
188 /* Set up the users ACL's for this 'dn' */
189 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
191 /* Find out more about the object type */
192 $ldap= $this->config->get_ldap_link();
193 $ldap->cat($this->dn, array('objectClass','gotoMode'));
194 $attrs= $ldap->fetch();
195 $type= $this->get_system_type($attrs);
197 /* Lock the current entry, so everyone will get the
198 above dialog */
199 $tabs = array(
200 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
201 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
202 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
203 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
204 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
205 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
206 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
209 if($type == "ArpNewDevice"){
210 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
211 }elseif($type == "NewDevice"){
212 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
213 }elseif(isset($tabs[$type])){
215 $class = $tabs[$type]["CLASS"];
216 $tabclass = $tabs[$type]["TABCLASS"];
218 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
219 $this->systab->set_acl($acl);
220 $_SESSION['objectinfo']= $this->dn;
221 add_lock ($this->dn, $this->ui->dn);
222 }else{
223 print_red (_("You can't edit this object type yet!"));
224 del_lock($this->dn);
225 }
226 }
228 /********************
229 Create FAI CD ...
230 ********************/
231 if ($s_action=="gen_cd"){
232 $this->dn= $this->terminals[$s_entry]['dn'];
233 $_SESSION['objectinfo']= $this->dn;
234 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
235 }
237 /* Start CD-Creation */
238 if (isset($_POST["cd_create"])){
239 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
240 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
241 }
243 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
245 $return_button = "<form method='get' action='main.php' target='_parent'>
246 <input type='submit' value='"._("Back")."'>
247 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
248 </form>";
250 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
252 /* Get and check command */
253 $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
254 if (check_command($command)){
255 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
257 /* Print out html introduction */
258 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
259 <html>
260 <head>
261 <title></title>
262 <style type="text/css">@import url("themes/default/style.css");</style>
263 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
264 </head>
265 <body style="background: none; margin:4px;" id="body" >
266 <pre>';
268 /* Open process handle and check if it is a valid process */
269 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
270 if (is_resource($process)) {
271 fclose($pipes[0]);
273 /* Print out returned lines && write JS to scroll down each line */
274 while (!feof($pipes[1])){
275 $cur_dat = fgets($pipes[1], 1024);
276 echo $cur_dat;
277 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
278 flush();
279 }
280 }
282 /* Get error string && close streams */
283 $buffer = "";
284 while (!feof($pipes[2])){
285 $buffer .= fgets($pipes[2],256);
286 }
288 fclose($pipes[1]);
289 fclose($pipes[2]);
290 echo "</pre>";
292 /* Check return code */
293 $ret= proc_close($process);
294 if ($ret != 0){
295 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
296 echo "<pre style='color:red'>$buffer</pre>";
297 }
299 echo $return_button."<br>";
301 } else {
302 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
303 echo $tmp;
304 }
306 /* Scroll down completly */
307 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
308 echo '</body></html>';
309 flush();
310 exit;
311 }
314 /********************
315 Change password ...
316 ********************/
318 /* Set terminals root password */
319 if ($s_action=="change_pw"){
320 $this->dn= $this->terminals[$s_entry]['dn'];
321 $_SESSION['objectinfo']= $this->dn;
322 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
323 }
326 /********************
327 Password cahnge finish, but check if entered data is ok
328 ********************/
330 /* Correctly specified? */
331 if (isset($_POST['password_finish'])){
332 if ($_POST['new_password'] != $_POST['repeated_password']){
333 print_red (_("Passwords entered as new and repeated do not match!"));
334 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
335 }
336 }
338 /********************
339 Password change finish
340 ********************/
342 /* Change terminal password */
343 if (isset($_POST['password_finish']) &&
344 $_POST['new_password'] == $_POST['repeated_password']){
346 /* Check if user is allowed to set password */
347 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
348 $acl= get_module_permission($acl, "terminal", $this->dn);
349 if (chkacl($acl, "password") != ""){
350 print_red (_("You are not allowed to set this systems password!"));
351 } else {
352 $ldap= $this->config->get_ldap_link();
353 $ldap->cd($this->dn);
355 $attrs= array();
356 if ($_POST['new_password'] == ""){
357 $attrs['gotoRootPasswd']= array();
358 } else {
359 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
360 substr(session_id(),0,2));
361 }
362 $ldap->modify($attrs);
363 gosa_log ("Password for '".$this->dn."' has been changed");
364 }
365 unset($_SESSION['objectinfo']);
366 }
369 /********************
370 Delete system cancel
371 ********************/
373 /* Delete terminal canceled? */
374 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
375 del_lock ($this->dn);
376 unset($_SESSION['objectinfo']);
377 }
380 /********************
381 Delete system, confirm dialog
382 ********************/
384 /* Remove terminal was requested */
385 if ($s_action=="del"){
387 /* Get 'dn' from posted termlinst */
388 $this->dn= $this->terminals[$s_entry]['dn'];
390 /* Load permissions for selected 'dn' and check if
391 we're allowed to remove this 'dn' */
392 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
393 $this->acl= get_module_permission($acl, "terminal", $this->dn);
394 if (chkacl($this->acl, "delete") == ""){
396 /* Check locking, save current plugin in 'back_plugin', so
397 the dialog knows where to return. */
398 if (($user= get_lock($this->dn)) != ""){
399 return(gen_locked_message ($user, $this->dn));
400 }
402 /* Lock the current entry, so nobody will edit it during deletion */
403 add_lock ($this->dn, $this->ui->dn);
404 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
405 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
406 } else {
408 /* Obviously the user isn't allowed to delete. Show message and
409 clean session. */
410 print_red (_("You are not allowed to delete this component!"));
411 }
412 }
415 /********************
416 Delete system, confirmed
417 ********************/
418 /* Confirmation for deletion has been passed. Terminal should be deleted. */
419 if (isset($_POST['delete_terminal_confirm'])){
421 /* Some nice guy may send this as POST, so we've to check
422 for the permissions again. */
423 if (chkacl($this->acl, "delete") == ""){
425 /* Find out more about the object type */
426 $ldap= $this->config->get_ldap_link();
427 $ldap->cat($this->dn, array('objectClass','gotoMode'));
428 $attrs= $ldap->fetch();
429 $type= $this->get_system_type($attrs);
431 $tabs = array(
432 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
433 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
434 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
435 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
436 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
437 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
438 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
440 /* get object type */
441 $tabtype = "termtabs";
442 $tabobj = "TERMTABS";
443 if(isset($tabs[$type])){
444 $tabtype = $tabs[$type]['TABCLASS'];
445 $tabobj = $tabs[$type]['CLASS'];
446 }
448 /* Delete request is permitted, perform LDAP action */
449 if($tabtype=="phonetabs"){
450 $this->systab= new $tabtype($this->config,
451 $this->config->data['TABS'][$tabobj], $this->dn);
452 $this->systab->set_acl(array($this->acl));
453 $this->systab->by_object['phonegeneric']->remove_from_parent ();
454 }else{
455 $this->systab= new $tabtype($this->config,
456 $this->config->data['TABS'][$tabobj], $this->dn);
457 $this->systab->set_acl(array($this->acl));
458 $this->systab->delete();
459 #$this->systab->by_object['termgeneric']->remove_from_parent ();
460 }
461 unset ($this->systab);
462 gosa_log ("System object'".$this->dn."' has been removed");
463 $this->systab= NULL;
465 /* Terminal list has changed, reload it. */
466 } else {
468 /* Normally this shouldn't be reached, send some extra
469 logs to notify the administrator */
470 print_red (_("You are not allowed to delete this component!"));
471 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
472 "deletion.");
473 }
475 /* Remove lock file after successfull deletion */
476 del_lock ($this->dn);
477 }
480 /********************
481 Edit system type finished, check if everything went ok
482 ********************/
483 /* Finish user edit is triggered by the tabulator dialog, so
484 the user wants to save edited data. Check and save at this
485 point. */
486 if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
488 /* Check tabs, will feed message array */
489 $message = array();
490 if(!$save_object_directly){
491 $message = $this->systab->check();
492 }else{
493 $found = false;
495 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
496 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
497 if(isset($this->systab->by_object[$tab]->gotoMode)) {
498 $found = true;
499 $this->systab->by_object[$tab]->gotoMode = $value;
500 }
501 }
502 if(!$found){
503 print_red(sprintf(_("Can't set gotoMode to status 'active', the current object couldn't be identified.")));
504 }
506 }
507 /* Save, or display error message? */
508 if (count($message) == 0){
510 /* Incoming behavior; you can select a system type and an ogroup membership.
511 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
512 * Check if we must add the new object to an object group.
513 *
514 * If this is done, delete the old incoming entry... it is still there, because this is a new
515 * entry and not an edited one, so we will delete it.
516 */
518 if(isset($_SESSION['SelectedSystemType'])){
519 $SelectedSystemType= $_SESSION['SelectedSystemType'];
520 if($SelectedSystemType['ogroup'] != "none"){
521 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
522 if($og){
523 $og->AddDelMembership($this->systab->dn);
524 $og->save();
525 }
526 }
527 }
529 /* Save terminal data to ldap */
530 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
531 foreach (array("workservice", "termservice") as $cls){
532 if (isset($this->systab->by_object[$cls])){
533 $this->systab->by_object[$cls]->gotoXMouseport= "";
534 $this->systab->by_object[$cls]->gotoXMouseType= "";
535 $this->systab->by_object[$cls]->gotoXResolution= "";
536 $this->systab->by_object[$cls]->gotoXColordepth= "";
537 }
538 }
539 }
541 $this->systab->save();
542 gosa_log ("System object'".$this->dn."' has been saved");
544 if(isset($_SESSION['SelectedSystemType'])){
545 unset($_SESSION['SelectedSystemType']);
546 if(!isset($ldap)){
547 $ldap = $this->config->get_ldap_link();
548 }
549 $ldap->cd ($this->dn);
550 $ldap->cat($this->dn, array('dn'));
551 if(count($ldap->fetch())){
552 $ldap->cd($this->dn);
553 $ldap->rmDir($this->dn);
554 }
555 $ldap->cd($this->config->current['BASE']);
556 }
559 /* Terminal has been saved successfully, remove lock from
560 LDAP. */
561 if ($this->dn != "new"){
562 del_lock ($this->dn);
563 }
565 unset ($this->systab);
566 $this->systab= NULL;
567 unset($_SESSION['objectinfo']);
568 } else {
569 /* Ok. There seem to be errors regarding to the tab data,
570 show message and continue as usual. */
571 show_errors($message);
572 }
573 }
575 /********************
576 Edit system was canceled
577 ********************/
578 /* Cancel dialogs */
579 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
580 if (isset($this->systab)){
581 del_lock ($this->systab->dn);
582 unset ($this->systab);
583 }
584 $this->systab= NULL;
585 unset($_SESSION['objectinfo']);
587 /* Remove ogroup selection, which was set while editing a new incoming entry */
588 if(isset($_SESSION['SelectedSystemType'])){
589 unset($_SESSION['SelectedSystemType']);
590 }
591 }
593 /********************
594 Display edit dialog, or some other
595 ********************/
597 /* Show tab dialog if object is present */
598 if (isset($this->systab->config)){
599 $display= $this->systab->execute();
601 /* Don't show buttons if tab dialog requests this */
602 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
603 $display.= "<p style=\"text-align:right\">\n";
604 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
605 $display.= " \n";
606 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
607 $display.= "</p>";
608 }
609 return ($display);
610 }
612 /* Display dialog with system list */
613 $this->DivListSystem->parent = $this;
614 $this->DivListSystem->execute();
616 /* Add departments if subsearch is disabled */
617 if(!$this->DivListSystem->SubSearch){
618 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
619 }
620 $this->reload();
621 $this->DivListSystem->setEntries($this->terminals);
622 return($this->DivListSystem->Draw());
623 }
627 function remove_from_parent()
628 {
629 /* Optionally execute a command after we're done */
630 $this->postremove();
631 }
634 /* Save data to object */
635 function save_object()
636 {
637 $this->DivListSystem->save_object();
638 }
641 /* Check values */
642 function check()
643 {
644 }
647 /* Save to LDAP */
648 function save()
649 {
650 }
652 function adapt_from_template($dn)
653 {
654 }
656 function password_change_needed()
657 {
658 }
660 function reload()
661 {
662 /* Load terminal shortcuts */
663 $responsible= array();
664 foreach ($this->config->departments as $key => $value){
665 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
666 "systems", $value) != ""){
667 $responsible[$key]= $value;
668 }
669 }
671 /* some var init */
672 $res = array();
673 $this->terminals = array();
674 $userregex = "";
676 /* Set base for all searches */
677 $base= $this->DivListSystem->selectedBase;
679 /* Prepare samba class name */
680 $samba ="";
681 if ($this->DivListSystem->ShowWinWorkstations){
682 if ($this->config->current['SAMBAVERSION'] == "3"){
683 $samba= "sambaSamAccount";
684 } else {
685 $samba= "sambaAccount";
686 }
687 }
689 /* This array represents the combination between checkboxes and search filters */
690 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
691 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
692 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
693 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
694 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
695 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
696 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
698 /* Include the 'Display Systems of user' attribute */
699 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
700 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
701 }
703 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
704 foreach($objs as $checkBox => $oc){
705 if($this->DivListSystem->$checkBox){
706 if($this->DivListSystem->SubSearch){
707 if($oc['CLASS'] != ""){
708 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
709 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
710 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate","gotoMode"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
711 }
712 }else{
713 /* User filter? */
714 if($oc['CLASS'] != ""){
715 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
716 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
717 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate", "gotoMode"), GL_NONE | GL_SIZELIMIT));
718 }
719 }
720 }
721 }
723 /* Search for incoming objects */
724 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
725 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
726 array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode"), GL_NONE | GL_SIZELIMIT));
728 /* Get all gotoTerminal's */
729 foreach ($res as $value){
731 $tmp= $value['dn'];
732 $add= "";
734 /* Extract base */
735 foreach($objs as $obj){
736 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
737 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
738 }
739 }
741 /* check if current object is a new one */
742 if (preg_match ("/,ou=incoming,/i", $tmp)){
743 if (in_array_ics('gotoTerminal', $value['objectClass'])){
744 $add= "- "._("New terminal");
745 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
746 $add= "- "._("New workstation");
747 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
748 $add= "- "._("Unknown device");
749 }elseif (in_array_ics('GOhard', $value['objectClass'])){
750 $add= "- "._("New Device");
751 }
752 }
754 /* Create a string containing the last part of the department. */
755 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
756 if(empty($dn_name)){
757 $dn_name = "/";
758 }
760 /* Detect type of object and create an entry for $this->terminals */
761 $terminal = array();
762 if ((in_array ($tmp, $responsible)) || ($add != "")){
763 if (in_array_ics('gotoTerminal', $value["objectClass"])){
764 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
765 $terminal = $value;
766 $terminal['type'] = "T";
767 $terminal['is_new'] = $add;
768 } else {
769 $terminal = $value;
770 $terminal['type'] = "D";
771 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
772 $terminal['location'] = array_search($tmp, $this->config->departments);
773 }
774 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
775 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
776 $terminal = $value;
777 $terminal['type'] = "L";
778 $terminal['is_new'] = $add;
779 } else {
780 $terminal = $value;
781 $terminal['type'] = "D";
782 $terminal['location'] = array_search($tmp, $this->config->departments);
783 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
784 }
785 if (isset($value["FAIstate"][0])){
786 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
787 }
788 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
789 $terminal = $value;
790 $terminal['type'] = "P";
791 } elseif (in_array_ics('goServer', $value["objectClass"])){
792 $terminal = $value;
793 $terminal['type'] = "S";
794 if (isset($value["FAIstate"][0])){
795 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
796 }
797 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
798 $terminal = $value;
799 $terminal['type'] = "F";
800 }elseif (in_array_ics("GOhard",$value['objectClass'])){
801 $terminal = $value;
802 $terminal['type'] = "Q";
803 $terminal['is_new'] = $add;
804 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
805 $terminal = $value;
806 $terminal['type'] = "C";
807 } else{
808 $name= preg_replace('/\$$/', '', $value['cn'][0]);
809 if (isset($value['sambaDomainName'])){
810 $domain= " [".$value['sambaDomainName'][0]."]";
811 } else {
812 $domain= "";
813 }
814 $terminal=$value;
815 $terminal['type'] ="W";
816 $terminal['domain'] = $name.$domain;
817 }
818 $this->terminals[]=$terminal;
819 }
820 }
822 $tmp=array();
823 foreach($this->terminals as $tkey => $val ){
824 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
825 }
826 ksort($tmp);
827 $this->terminals=array();
828 foreach($tmp as $val){
829 $this->terminals[]=$val;
830 }
831 reset ($this->terminals);
832 }
834 function remove_lock()
835 {
836 if (isset($this->systab->dn)){
837 del_lock ($this->systab->dn);
838 }
839 }
842 function get_system_type($attrs)
843 {
844 $enable_arp_device_handling = preg_match("/ArpNewDevice/i",search_config($this->config->data['TABS'], "ArpNewDevice", "CLASS"));
845 $classes = $attrs['objectClass'];
847 $type= "";
848 if (in_array_ics('ieee802Device', $classes)){
849 $type= "component";
850 }elseif (in_array_ics('gotoTerminal', $classes)){
851 $type= "terminal";
852 }elseif (in_array_ics('gotoWorkstation', $classes)){
853 $type= "workstation";
854 }elseif (in_array_ics('gotoPrinter', $classes)){
855 $type= "printer";
856 }elseif (in_array_ics('goFonHardware', $classes)){
857 $type= "phone";
858 }elseif (in_array_ics('goServer', $classes)){
859 $type= "server";
860 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $enable_arp_device_handling){
861 $type= "ArpNewDevice";
862 }elseif (in_array_ics('GOhard', $classes)){
863 $type= "NewDevice";
864 }elseif (in_array_ics('sambaAccount', $classes) ||
865 in_array_ics('sambaSamAccount', $classes)){
866 $type= "winstation";
867 }
868 return ($type);
869 }
872 function convert_list($input)
873 {
874 $temp= "";
875 $conv= array(
876 "NQ" => array("select_newsystem.png",_("New System from incoming")),
877 "D" => array("select_default.png",_("Template")),
878 "T" => array("select_terminal.png",_("Terminal")),
879 "L" => array("select_workstation.png",_("Workstation")),
880 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
881 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
882 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
883 "F" => array("select_phone.png",_("Phone")),
884 "S" => array("select_server.png",_("Server")),
885 "GS" => array("select_server_green.png",_("Server is installing")),
886 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
887 "RS" => array("select_server_red.png",_("Server installation failed")),
888 "W" => array("select_winstation.png",_("Winstation")),
889 "C" => array("select_component.png",_("Network Device")),
890 "NT"=> array("select_new_terminal.png",_("New Terminal")),
891 "NL"=> array("select_new_workstation.png",_("New Workstation")),
892 "P" => array("select_printer.png",_("Printer")));
894 if((isset($input['is_new']))&&(!empty($input['is_new']))){
895 $input['type']="N".$input['type'];
896 }
897 foreach ($conv as $key => $value){
898 if($input['type']==$key){
899 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
900 $tmp['class']=$key;
901 return $tmp;
902 }
903 }
904 }
907 function getState($type, $state)
908 {
909 switch (preg_replace('/:.*$/', '', $state)) {
910 case 'installing':
911 $type= 'G'.$type;
912 break;
913 case 'error':
914 $type= 'R'.$type;
915 break;
916 case 'install':
917 case 'sysinfo':
918 case 'softupdate':
919 case 'scheduledupdate':
920 $type= 'Y'.$type;
921 break;
922 }
925 return ($type);
926 }
928 }
930 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
931 ?>