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