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 }
234 /* Start CD-Creation */
235 if (isset($_POST["cd_create"])){
236 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
237 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
238 }
240 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
242 $return_button = "<form method='get' action='main.php' target='_parent'>
243 <input type='submit' value='"._("Back")."'>
244 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
245 </form>";
247 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
249 /* Get and check command */
250 $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
251 if (check_command($command)){
252 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
254 /* Print out html introduction */
255 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
256 <html>
257 <head>
258 <title></title>
259 <style type="text/css">@import url("themes/default/style.css");</style>
260 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
261 </head>
262 <body style="background: none; margin:4px;" id="body" >
263 <pre>';
265 /* Open process handle and check if it is a valid process */
266 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
267 if (is_resource($process)) {
268 fclose($pipes[0]);
270 /* Print out returned lines && write JS to scroll down each line */
271 while (!feof($pipes[1])){
272 $cur_dat = fgets($pipes[1], 1024);
273 echo $cur_dat;
274 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
275 flush();
276 }
277 }
279 /* Get error string && close streams */
280 $buffer = "";
281 while (!feof($pipes[2])){
282 $buffer .= fgets($pipes[2],256);
283 }
285 fclose($pipes[1]);
286 fclose($pipes[2]);
287 echo "</pre>";
289 /* Check return code */
290 $ret= proc_close($process);
291 if ($ret != 0){
292 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
293 echo "<pre style='color:red'>$buffer</pre>";
294 }
296 echo $return_button."<br>";
298 } else {
299 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
300 echo $tmp;
301 }
303 /* Scroll down completly */
304 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
305 echo '</body></html>';
306 flush();
307 exit;
308 }
311 /********************
312 Change password ...
313 ********************/
315 /* Set terminals root password */
316 if ($s_action=="change_pw"){
317 $this->dn= $this->terminals[$s_entry]['dn'];
318 $_SESSION['objectinfo']= $this->dn;
319 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
320 }
323 /********************
324 Password cahnge finish, but check if entered data is ok
325 ********************/
327 /* Correctly specified? */
328 if (isset($_POST['password_finish'])){
329 if ($_POST['new_password'] != $_POST['repeated_password']){
330 print_red (_("Passwords entered as new and repeated do not match!"));
331 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
332 }
333 }
335 /********************
336 Password change finish
337 ********************/
339 /* Change terminal password */
340 if (isset($_POST['password_finish']) &&
341 $_POST['new_password'] == $_POST['repeated_password']){
343 /* Check if user is allowed to set password */
344 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
345 $acl= get_module_permission($acl, "terminal", $this->dn);
346 if (chkacl($acl, "password") != ""){
347 print_red (_("You are not allowed to set this systems password!"));
348 } else {
349 $ldap= $this->config->get_ldap_link();
350 $ldap->cd($this->dn);
352 $attrs= array();
353 if ($_POST['new_password'] == ""){
354 $attrs['gotoRootPasswd']= array();
355 } else {
356 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
357 substr(session_id(),0,2));
358 }
359 $ldap->modify($attrs);
360 gosa_log ("Password for '".$this->dn."' has been changed");
361 }
362 unset($_SESSION['objectinfo']);
363 }
366 /********************
367 Delete system cancel
368 ********************/
370 /* Delete terminal canceled? */
371 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
372 del_lock ($this->dn);
373 unset($_SESSION['objectinfo']);
374 }
377 /********************
378 Delete system, confirm dialog
379 ********************/
381 /* Remove terminal was requested */
382 if ($s_action=="del"){
384 /* Get 'dn' from posted termlinst */
385 $this->dn= $this->terminals[$s_entry]['dn'];
387 /* Load permissions for selected 'dn' and check if
388 we're allowed to remove this 'dn' */
389 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
390 $this->acl= get_module_permission($acl, "terminal", $this->dn);
391 if (chkacl($this->acl, "delete") == ""){
393 /* Check locking, save current plugin in 'back_plugin', so
394 the dialog knows where to return. */
395 if (($user= get_lock($this->dn)) != ""){
396 return(gen_locked_message ($user, $this->dn));
397 }
399 /* Lock the current entry, so nobody will edit it during deletion */
400 add_lock ($this->dn, $this->ui->dn);
401 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
402 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
403 } else {
405 /* Obviously the user isn't allowed to delete. Show message and
406 clean session. */
407 print_red (_("You are not allowed to delete this component!"));
408 }
409 }
412 /********************
413 Delete system, confirmed
414 ********************/
415 /* Confirmation for deletion has been passed. Terminal should be deleted. */
416 if (isset($_POST['delete_terminal_confirm'])){
418 /* Some nice guy may send this as POST, so we've to check
419 for the permissions again. */
420 if (chkacl($this->acl, "delete") == ""){
422 /* Find out more about the object type */
423 $ldap= $this->config->get_ldap_link();
424 $ldap->cat($this->dn, array('objectClass'));
425 $attrs= $ldap->fetch();
426 $type= $this->get_system_type($attrs['objectClass']);
428 $tabs = array(
429 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
430 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
431 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
432 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
433 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
434 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
435 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
437 /* get object type */
438 $tabtype = "termtabs";
439 $tabobj = "TERMTABS";
440 if(isset($tabs[$type])){
441 $tabtype = $tabs[$type]['TABCLASS'];
442 $tabobj = $tabs[$type]['CLASS'];
443 }
445 /* Delete request is permitted, perform LDAP action */
446 if($tabtype=="phonetabs"){
447 $this->systab= new $tabtype($this->config,
448 $this->config->data['TABS'][$tabobj], $this->dn);
449 $this->systab->set_acl(array($this->acl));
450 $this->systab->by_object['phonegeneric']->remove_from_parent ();
451 }else{
452 $this->systab= new $tabtype($this->config,
453 $this->config->data['TABS'][$tabobj], $this->dn);
454 $this->systab->set_acl(array($this->acl));
455 $this->systab->delete();
456 #$this->systab->by_object['termgeneric']->remove_from_parent ();
457 }
458 unset ($this->systab);
459 gosa_log ("System object'".$this->dn."' has been removed");
460 $this->systab= NULL;
462 /* Terminal list has changed, reload it. */
463 } else {
465 /* Normally this shouldn't be reached, send some extra
466 logs to notify the administrator */
467 print_red (_("You are not allowed to delete this component!"));
468 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
469 "deletion.");
470 }
472 /* Remove lock file after successfull deletion */
473 del_lock ($this->dn);
474 }
477 /********************
478 Edit system type finished, check if everything went ok
479 ********************/
480 /* Finish user edit is triggered by the tabulator dialog, so
481 the user wants to save edited data. Check and save at this
482 point. */
483 if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
485 /* Check tabs, will feed message array */
486 $message = array();
487 if(!$save_object_directly){
488 $message = $this->systab->check();
489 }else{
490 $found = false;
492 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
493 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
494 if(isset($this->systab->by_object[$tab]->gotoMode)) {
495 $found = true;
496 $this->systab->by_object[$tab]->gotoMode = $value;
497 }
498 }
499 if(!$found){
500 print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
501 }
503 }
504 /* Save, or display error message? */
505 if (count($message) == 0){
507 /* Save terminal data to ldap */
508 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
509 foreach (array("workservice", "termservice") as $cls){
510 if (isset($this->systab->by_object[$cls])){
511 $this->systab->by_object[$cls]->gotoXMouseport= "";
512 $this->systab->by_object[$cls]->gotoXMouseType= "";
513 $this->systab->by_object[$cls]->gotoXResolution= "";
514 $this->systab->by_object[$cls]->gotoXColordepth= "";
515 }
516 }
517 }
519 $this->systab->save();
520 gosa_log ("System object'".$this->dn."' has been saved");
522 /* Incoming behavior; you can select a system type and an ogroup membership.
523 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
524 * Check if we must add the new object to an object group.
525 *
526 * If this is done, delete the old incoming entry... it is still there, because this is a new
527 * entry and not an edited one, so we will delete it.
528 */
530 if(isset($_SESSION['SelectedSystemType'])){
531 $SelectedSystemType= $_SESSION['SelectedSystemType'];
532 unset($_SESSION['SelectedSystemType']);
533 if($SelectedSystemType['ogroup'] != "none"){
534 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
535 if($og){
536 $og->AddDelMembership($this->systab->dn);
537 $og->save();
538 }
539 }
540 if(!isset($ldap)){
541 $ldap = $this->config->get_ldap_link();
542 }
543 $ldap->cd ($this->dn);
544 $ldap->cat($this->dn, array('dn'));
545 if(count($ldap->fetch())){
546 $ldap->cd($this->dn);
547 $ldap->rmDir($this->dn);
548 }
549 $ldap->cd($this->config->current['BASE']);
550 }
552 /* Terminal has been saved successfully, remove lock from
553 LDAP. */
554 if ($this->dn != "new"){
555 del_lock ($this->dn);
556 }
558 unset ($this->systab);
559 $this->systab= NULL;
560 unset($_SESSION['objectinfo']);
561 } else {
562 /* Ok. There seem to be errors regarding to the tab data,
563 show message and continue as usual. */
564 show_errors($message);
565 }
566 }
568 /********************
569 Edit system was canceled
570 ********************/
571 /* Cancel dialogs */
572 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
573 if (isset($this->systab)){
574 del_lock ($this->systab->dn);
575 unset ($this->systab);
576 }
577 $this->systab= NULL;
578 unset($_SESSION['objectinfo']);
580 /* Remove ogroup selection, which was set while editing a new incoming entry */
581 if(isset($_SESSION['SelectedSystemType'])){
582 unset($_SESSION['SelectedSystemType']);
583 }
584 }
586 /********************
587 Display edit dialog, or some other
588 ********************/
590 /* Show tab dialog if object is present */
591 if (isset($this->systab->config)){
592 $display= $this->systab->execute();
594 /* Don't show buttons if tab dialog requests this */
595 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
596 $display.= "<p style=\"text-align:right\">\n";
597 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
598 $display.= " \n";
599 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
600 $display.= "</p>";
601 }
602 return ($display);
603 }
605 /* Display dialog with system list */
606 $this->DivListSystem->parent = $this;
607 $this->DivListSystem->execute();
609 /* Add departments if subsearch is disabled */
610 if(!$this->DivListSystem->SubSearch){
611 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
612 }
613 $this->reload();
614 $this->DivListSystem->setEntries($this->terminals);
615 return($this->DivListSystem->Draw());
616 }
620 function remove_from_parent()
621 {
622 /* Optionally execute a command after we're done */
623 $this->postremove();
624 }
627 /* Save data to object */
628 function save_object()
629 {
630 $this->DivListSystem->save_object();
631 }
634 /* Check values */
635 function check()
636 {
637 }
640 /* Save to LDAP */
641 function save()
642 {
643 }
645 function adapt_from_template($dn)
646 {
647 }
649 function password_change_needed()
650 {
651 }
653 function reload()
654 {
655 /* Load terminal shortcuts */
656 $responsible= array();
657 foreach ($this->config->departments as $key => $value){
658 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
659 "systems", $value) != ""){
660 $responsible[$key]= $value;
661 }
662 }
664 /* some var init */
665 $res = array();
666 $this->terminals = array();
667 $userregex = "";
669 /* Set base for all searches */
670 $base= $this->DivListSystem->selectedBase;
672 /* Prepare samba class name */
673 $samba ="";
674 if ($this->DivListSystem->ShowWinWorkstations){
675 if ($this->config->current['SAMBAVERSION'] == "3"){
676 $samba= "sambaSamAccount";
677 } else {
678 $samba= "sambaAccount";
679 }
680 }
682 /* This array represents the combination between checkboxes and search filters */
683 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
684 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
685 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
686 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
687 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
688 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
689 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
691 /* Include the 'Display Systems of user' attribute */
692 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
693 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
694 }
696 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
697 foreach($objs as $checkBox => $oc){
698 if($this->DivListSystem->$checkBox){
699 if($this->DivListSystem->SubSearch){
700 if($oc['CLASS'] != ""){
701 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
702 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
703 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
704 }
705 }else{
706 /* User filter? */
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, $oc['TREE'].$base,
710 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
711 }
712 }
713 }
714 }
716 /* Search for incoming objects */
717 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
718 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
719 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
721 /* Get all gotoTerminal's */
722 foreach ($res as $value){
724 $tmp= $value['dn'];
725 $add= "";
727 /* Extract base */
728 foreach($objs as $obj){
729 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
730 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
731 }
732 }
734 /* check if current object is a new one */
735 if (preg_match ("/,ou=incoming,/i", $tmp)){
736 if (in_array_ics('gotoTerminal', $value['objectClass'])){
737 $add= "- "._("New terminal");
738 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
739 $add= "- "._("New workstation");
740 }elseif (in_array_ics('GOhard', $value['objectClass'])){
741 $add= "- "._("New Device");
742 }
743 }
745 /* Create a string containing the last part of the department. */
746 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
747 if(empty($dn_name)){
748 $dn_name = "/";
749 }
751 /* Detect type of object and create an entry for $this->terminals */
752 $terminal = array();
753 if ((in_array ($tmp, $responsible)) || ($add != "")){
754 if (in_array_ics('gotoTerminal', $value["objectClass"])){
755 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
756 $terminal = $value;
757 $terminal['type'] = "T";
758 $terminal['is_new'] = $add;
759 } else {
760 $terminal = $value;
761 $terminal['type'] = "D";
762 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
763 $terminal['location'] = array_search($tmp, $this->config->departments);
764 }
765 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
766 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
767 $terminal = $value;
768 $terminal['type'] = "L";
769 $terminal['is_new'] = $add;
770 } else {
771 $terminal = $value;
772 $terminal['type'] = "D";
773 $terminal['location'] = array_search($tmp, $this->config->departments);
774 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
775 }
776 if (isset($value["FAIstate"][0])){
777 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
778 }
779 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
780 $terminal = $value;
781 $terminal['type'] = "P";
782 } elseif (in_array_ics('goServer', $value["objectClass"])){
783 $terminal = $value;
784 $terminal['type'] = "S";
785 if (isset($value["FAIstate"][0])){
786 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
787 }
788 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
789 $terminal = $value;
790 $terminal['type'] = "F";
791 }elseif (in_array_ics("GOhard",$value['objectClass'])){
792 $terminal = $value;
793 $terminal['type'] = "Q";
794 $terminal['is_new'] = $add;
795 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
796 $terminal = $value;
797 $terminal['type'] = "C";
798 } else{
799 $name= preg_replace('/\$$/', '', $value['cn'][0]);
800 if (isset($value['sambaDomainName'])){
801 $domain= " [".$value['sambaDomainName'][0]."]";
802 } else {
803 $domain= "";
804 }
805 $terminal=$value;
806 $terminal['type'] ="W";
807 $terminal['domain'] = $name.$domain;
808 }
809 $this->terminals[]=$terminal;
810 }
811 }
813 $tmp=array();
814 foreach($this->terminals as $tkey => $val ){
815 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
816 }
817 ksort($tmp);
818 $this->terminals=array();
819 foreach($tmp as $val){
820 $this->terminals[]=$val;
821 }
822 reset ($this->terminals);
823 }
825 function remove_lock()
826 {
827 if (isset($this->systab->dn)){
828 del_lock ($this->systab->dn);
829 }
830 }
833 function get_system_type($classes)
834 {
835 $type= "";
836 if (in_array_ics('ieee802Device', $classes)){
837 $type= "component";
838 }elseif (in_array_ics('gotoTerminal', $classes)){
839 $type= "terminal";
840 }elseif (in_array_ics('gotoWorkstation', $classes)){
841 $type= "workstation";
842 }elseif (in_array_ics('gotoPrinter', $classes)){
843 $type= "printer";
844 }elseif (in_array_ics('goFonHardware', $classes)){
845 $type= "phone";
846 }elseif (in_array_ics('goServer', $classes)){
847 $type= "server";
848 }elseif (in_array_ics('GOhard', $classes)){
849 $type= "NewDevice";
850 }elseif (in_array_ics('sambaAccount', $classes) ||
851 in_array_ics('sambaSamAccount', $classes)){
852 $type= "winstation";
853 }
854 return ($type);
855 }
858 function convert_list($input)
859 {
860 $temp= "";
861 $conv= array(
862 "NQ" => array("select_newsystem.png",_("New System from incoming")),
863 "D" => array("select_default.png",_("Template")),
864 "T" => array("select_terminal.png",_("Terminal")),
865 "L" => array("select_workstation.png",_("Workstation")),
866 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
867 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
868 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
869 "F" => array("select_phone.png",_("Phone")),
870 "S" => array("select_server.png",_("Server")),
871 "GS" => array("select_server_green.png",_("Server is installing")),
872 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
873 "RS" => array("select_server_red.png",_("Server installation failed")),
874 "W" => array("select_winstation.png",_("Winstation")),
875 "C" => array("select_component.png",_("Network Device")),
876 "NT"=> array("select_new_terminal.png",_("New Terminal")),
877 "NL"=> array("select_new_workstation.png",_("New Workstation")),
878 "P" => array("select_printer.png",_("Printer")));
880 if((isset($input['is_new']))&&(!empty($input['is_new']))){
881 $input['type']="N".$input['type'];
882 }
883 foreach ($conv as $key => $value){
884 if($input['type']==$key){
885 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
886 $tmp['class']=$key;
887 return $tmp;
888 }
889 }
890 }
893 function getState($type, $state)
894 {
895 switch (preg_replace('/:.*$/', '', $state)) {
896 case 'installing':
897 $type= 'G'.$type;
898 break;
899 case 'error':
900 $type= 'R'.$type;
901 break;
902 case 'install':
903 case 'sysinfo':
904 case 'softupdate':
905 case 'scheduledupdate':
906 $type= 'Y'.$type;
907 break;
908 }
911 return ($type);
912 }
914 }
916 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
917 ?>