c9974d227dcae1b44877d38665252ac5e692d55b
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'));
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"),
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'));
428 $attrs= $ldap->fetch();
429 $type= $this->get_system_type($attrs['objectClass']);
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 /* Save terminal data to ldap */
511 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
512 foreach (array("workservice", "termservice") as $cls){
513 if (isset($this->systab->by_object[$cls])){
514 $this->systab->by_object[$cls]->gotoXMouseport= "";
515 $this->systab->by_object[$cls]->gotoXMouseType= "";
516 $this->systab->by_object[$cls]->gotoXResolution= "";
517 $this->systab->by_object[$cls]->gotoXColordepth= "";
518 }
519 }
520 }
522 $this->systab->save();
523 gosa_log ("System object'".$this->dn."' has been saved");
525 /* Incoming behavior; you can select a system type and an ogroup membership.
526 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
527 * Check if we must add the new object to an object group.
528 *
529 * If this is done, delete the old incoming entry... it is still there, because this is a new
530 * entry and not an edited one, so we will delete it.
531 */
533 if(isset($_SESSION['SelectedSystemType'])){
534 $SelectedSystemType= $_SESSION['SelectedSystemType'];
535 unset($_SESSION['SelectedSystemType']);
536 if($SelectedSystemType['ogroup'] != "none"){
537 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
538 if($og){
539 $og->AddDelMembership($this->systab->dn);
540 $og->save();
541 }
542 }
543 if(!isset($ldap)){
544 $ldap = $this->config->get_ldap_link();
545 }
546 $ldap->cd ($this->dn);
547 $ldap->cat($this->dn, array('dn'));
548 if(count($ldap->fetch())){
549 $ldap->cd($this->dn);
550 $ldap->rmDir($this->dn);
551 }
552 $ldap->cd($this->config->current['BASE']);
553 }
555 /* Terminal has been saved successfully, remove lock from
556 LDAP. */
557 if ($this->dn != "new"){
558 del_lock ($this->dn);
559 }
561 unset ($this->systab);
562 $this->systab= NULL;
563 unset($_SESSION['objectinfo']);
564 } else {
565 /* Ok. There seem to be errors regarding to the tab data,
566 show message and continue as usual. */
567 show_errors($message);
568 }
569 }
571 /********************
572 Edit system was canceled
573 ********************/
574 /* Cancel dialogs */
575 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
576 if (isset($this->systab)){
577 del_lock ($this->systab->dn);
578 unset ($this->systab);
579 }
580 $this->systab= NULL;
581 unset($_SESSION['objectinfo']);
583 /* Remove ogroup selection, which was set while editing a new incoming entry */
584 if(isset($_SESSION['SelectedSystemType'])){
585 unset($_SESSION['SelectedSystemType']);
586 }
587 }
589 /********************
590 Display edit dialog, or some other
591 ********************/
593 /* Show tab dialog if object is present */
594 if (isset($this->systab->config)){
595 $display= $this->systab->execute();
597 /* Don't show buttons if tab dialog requests this */
598 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
599 $display.= "<p style=\"text-align:right\">\n";
600 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
601 $display.= " \n";
602 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
603 $display.= "</p>";
604 }
605 return ($display);
606 }
608 /* Display dialog with system list */
609 $this->DivListSystem->parent = $this;
610 $this->DivListSystem->execute();
612 /* Add departments if subsearch is disabled */
613 if(!$this->DivListSystem->SubSearch){
614 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
615 }
616 $this->reload();
617 $this->DivListSystem->setEntries($this->terminals);
618 return($this->DivListSystem->Draw());
619 }
623 function remove_from_parent()
624 {
625 /* Optionally execute a command after we're done */
626 $this->postremove();
627 }
630 /* Save data to object */
631 function save_object()
632 {
633 $this->DivListSystem->save_object();
634 }
637 /* Check values */
638 function check()
639 {
640 }
643 /* Save to LDAP */
644 function save()
645 {
646 }
648 function adapt_from_template($dn)
649 {
650 }
652 function password_change_needed()
653 {
654 }
656 function reload()
657 {
658 /* Load terminal shortcuts */
659 $responsible= array();
660 foreach ($this->config->departments as $key => $value){
661 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
662 "systems", $value) != ""){
663 $responsible[$key]= $value;
664 }
665 }
667 /* some var init */
668 $res = array();
669 $this->terminals = array();
670 $userregex = "";
672 /* Set base for all searches */
673 $base= $this->DivListSystem->selectedBase;
675 /* Prepare samba class name */
676 $samba ="";
677 if ($this->DivListSystem->ShowWinWorkstations){
678 if ($this->config->current['SAMBAVERSION'] == "3"){
679 $samba= "sambaSamAccount";
680 } else {
681 $samba= "sambaAccount";
682 }
683 }
685 /* This array represents the combination between checkboxes and search filters */
686 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
687 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
688 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
689 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
690 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
691 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
692 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
694 /* Include the 'Display Systems of user' attribute */
695 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
696 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
697 }
699 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
700 foreach($objs as $checkBox => $oc){
701 if($this->DivListSystem->$checkBox){
702 if($this->DivListSystem->SubSearch){
703 if($oc['CLASS'] != ""){
704 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
705 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
706 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
707 }
708 }else{
709 /* User filter? */
710 if($oc['CLASS'] != ""){
711 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
712 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
713 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
714 }
715 }
716 }
717 }
719 /* Search for incoming objects */
720 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
721 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
722 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
724 /* Get all gotoTerminal's */
725 foreach ($res as $value){
727 $tmp= $value['dn'];
728 $add= "";
730 /* Extract base */
731 foreach($objs as $obj){
732 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
733 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
734 }
735 }
737 /* check if current object is a new one */
738 if (preg_match ("/,ou=incoming,/i", $tmp)){
739 if (in_array_ics('gotoTerminal', $value['objectClass'])){
740 $add= "- "._("New terminal");
741 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
742 $add= "- "._("New workstation");
743 }elseif (in_array_ics('GOhard', $value['objectClass']) && !in_array_ics("gotoMode",$value['objectClass'])){
744 $add= "- "._("Unknown device");
745 }elseif (in_array_ics('GOhard', $value['objectClass'])){
746 $add= "- "._("New Device");
747 }
748 }
750 /* Create a string containing the last part of the department. */
751 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
752 if(empty($dn_name)){
753 $dn_name = "/";
754 }
756 /* Detect type of object and create an entry for $this->terminals */
757 $terminal = array();
758 if ((in_array ($tmp, $responsible)) || ($add != "")){
759 if (in_array_ics('gotoTerminal', $value["objectClass"])){
760 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
761 $terminal = $value;
762 $terminal['type'] = "T";
763 $terminal['is_new'] = $add;
764 } else {
765 $terminal = $value;
766 $terminal['type'] = "D";
767 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
768 $terminal['location'] = array_search($tmp, $this->config->departments);
769 }
770 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
771 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
772 $terminal = $value;
773 $terminal['type'] = "L";
774 $terminal['is_new'] = $add;
775 } else {
776 $terminal = $value;
777 $terminal['type'] = "D";
778 $terminal['location'] = array_search($tmp, $this->config->departments);
779 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
780 }
781 if (isset($value["FAIstate"][0])){
782 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
783 }
784 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
785 $terminal = $value;
786 $terminal['type'] = "P";
787 } elseif (in_array_ics('goServer', $value["objectClass"])){
788 $terminal = $value;
789 $terminal['type'] = "S";
790 if (isset($value["FAIstate"][0])){
791 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
792 }
793 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
794 $terminal = $value;
795 $terminal['type'] = "F";
796 }elseif (in_array_ics("GOhard",$value['objectClass'])){
797 $terminal = $value;
798 $terminal['type'] = "Q";
799 $terminal['is_new'] = $add;
800 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
801 $terminal = $value;
802 $terminal['type'] = "C";
803 } else{
804 $name= preg_replace('/\$$/', '', $value['cn'][0]);
805 if (isset($value['sambaDomainName'])){
806 $domain= " [".$value['sambaDomainName'][0]."]";
807 } else {
808 $domain= "";
809 }
810 $terminal=$value;
811 $terminal['type'] ="W";
812 $terminal['domain'] = $name.$domain;
813 }
814 $this->terminals[]=$terminal;
815 }
816 }
818 $tmp=array();
819 foreach($this->terminals as $tkey => $val ){
820 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
821 }
822 ksort($tmp);
823 $this->terminals=array();
824 foreach($tmp as $val){
825 $this->terminals[]=$val;
826 }
827 reset ($this->terminals);
828 }
830 function remove_lock()
831 {
832 if (isset($this->systab->dn)){
833 del_lock ($this->systab->dn);
834 }
835 }
838 function get_system_type($classes)
839 {
840 $enable_arp_device_handling = preg_match("/ArpNewDevice/i",search_config($this->config->data['TABS'], "ArpNewDevice", "CLASS"));
842 $type= "";
843 if (in_array_ics('ieee802Device', $classes)){
844 $type= "component";
845 }elseif (in_array_ics('gotoTerminal', $classes)){
846 $type= "terminal";
847 }elseif (in_array_ics('gotoWorkstation', $classes)){
848 $type= "workstation";
849 }elseif (in_array_ics('gotoPrinter', $classes)){
850 $type= "printer";
851 }elseif (in_array_ics('goFonHardware', $classes)){
852 $type= "phone";
853 }elseif (in_array_ics('goServer', $classes)){
854 $type= "server";
855 }elseif (in_array_ics('GOhard', $classes)&& !in_array('gotoMode', $classes) && $enable_arp_device_handling){
856 $type= "ArpNewDevice";
857 }elseif (in_array_ics('GOhard', $classes)){
858 $type= "NewDevice";
859 }elseif (in_array_ics('sambaAccount', $classes) ||
860 in_array_ics('sambaSamAccount', $classes)){
861 $type= "winstation";
862 }
863 return ($type);
864 }
867 function convert_list($input)
868 {
869 $temp= "";
870 $conv= array(
871 "NQ" => array("select_newsystem.png",_("New System from incoming")),
872 "D" => array("select_default.png",_("Template")),
873 "T" => array("select_terminal.png",_("Terminal")),
874 "L" => array("select_workstation.png",_("Workstation")),
875 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
876 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
877 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
878 "F" => array("select_phone.png",_("Phone")),
879 "S" => array("select_server.png",_("Server")),
880 "GS" => array("select_server_green.png",_("Server is installing")),
881 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
882 "RS" => array("select_server_red.png",_("Server installation failed")),
883 "W" => array("select_winstation.png",_("Winstation")),
884 "C" => array("select_component.png",_("Network Device")),
885 "NT"=> array("select_new_terminal.png",_("New Terminal")),
886 "NL"=> array("select_new_workstation.png",_("New Workstation")),
887 "P" => array("select_printer.png",_("Printer")));
889 if((isset($input['is_new']))&&(!empty($input['is_new']))){
890 $input['type']="N".$input['type'];
891 }
892 foreach ($conv as $key => $value){
893 if($input['type']==$key){
894 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
895 $tmp['class']=$key;
896 return $tmp;
897 }
898 }
899 }
902 function getState($type, $state)
903 {
904 switch (preg_replace('/:.*$/', '', $state)) {
905 case 'installing':
906 $type= 'G'.$type;
907 break;
908 case 'error':
909 $type= 'R'.$type;
910 break;
911 case 'install':
912 case 'sysinfo':
913 case 'softupdate':
914 case 'scheduledupdate':
915 $type= 'Y'.$type;
916 break;
917 }
920 return ($type);
921 }
923 }
925 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
926 ?>