56899502e07d78d914a16306fd3931568fe1ce61
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;
42 var $image_creation_log ="";
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 == "NewDevice"){
210 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
211 }elseif(isset($tabs[$type])){
213 $class = $tabs[$type]["CLASS"];
214 $tabclass = $tabs[$type]["TABCLASS"];
216 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
217 $this->systab->set_acl($acl);
218 $_SESSION['objectinfo']= $this->dn;
219 add_lock ($this->dn, $this->ui->dn);
220 }else{
221 print_red (_("You can't edit this object type yet!"));
222 del_lock($this->dn);
223 }
224 }
226 /********************
227 Create FAI CD ...
228 ********************/
229 if ($s_action=="gen_cd"){
230 $this->dn= $this->terminals[$s_entry]['dn'];
231 $_SESSION['objectinfo']= $this->dn;
232 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
233 }
235 /* Start CD-Creation */
236 if (isset($_POST["cd_create"])){
237 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
238 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
239 }
241 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
243 /* Initialize some attributes */
244 $this->image_creation_log = "";
245 $download_button = "<a href='?plug=".$_GET['plug']."&download_image_log'><image='images/zip.png'>"._("Download")."</a>";
246 $return_button = "<a href='?plug=".$_GET['plug']."' target='parent'><image='images/list_reload.png'>"._("Back to work")."</a>";
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 // $command = "/bin/sh /home/hickert/gen_stuff.sh";
252 if (check_command($command)){
253 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
255 /* Print out html introduction */
256 echo "<html><head>";
257 echo "<script language=\"javascript\" src=\"include/focus.js\" type=\"text/javascript\"></script>";
258 echo "</head>";
259 echo "<body>
260 <script language=\"javascript\" type=\"text/javascript\">
261 document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
262 </script>
263 <pre>";
265 /* Open process handle and check if it is a valid process */
266 $process= proc_open($command, $dsc, $pipes, '/tmp');
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 $this->image_creation_log .= $cur_dat;
274 echo $cur_dat;
275 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
276 flush();
277 }
278 }
280 /* Get error string && close streams */
281 $buffer= stream_get_contents($pipes[2]);
282 fclose($pipes[1]);
283 fclose($pipes[2]);
284 echo "</pre>";
286 /* Check return code */
287 $ret= proc_close($process);
288 if ($ret == 0){
290 /* No error */
291 $this->image_creation_log.="\n\nSuccessfull finished image creation.\n\n";
292 } else {
294 /* Error */
295 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
296 echo "<pre style='color:red'>$buffer</pre>";
298 $this->image_creation_log.="\n\nImage creation failed. Please see report below : \n\n";
299 $this->image_creation_log.=$buffer."\n\n";
300 }
302 echo $return_button.$download_button;
304 } else {
305 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
306 echo $tmp;
307 }
309 /* Scroll down completly */
310 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
311 echo "</body></html>";
312 flush();
313 exit;
314 }
317 /******************
318 FAI Image creation logfile requested
319 ******************/
320 if(isset($_GET['download_image_log'])){
322 /* force download dialog */
323 header("Content-type: application/tiff\n");
324 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
325 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
326 header('Content-Disposition: filename="image.log"');
327 } else {
328 header('Content-Disposition: attachment; filename="image.log"');
329 }
330 header("Content-transfer-encoding: binary\n");
331 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
332 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
333 header("Cache-Control: no-cache");
334 header("Pragma: no-cache");
335 header("Cache-Control: post-check=0, pre-check=0");
337 echo $this->image_creation_log;
339 exit();
340 }
344 /********************
345 Change password ...
346 ********************/
348 /* Set terminals root password */
349 if ($s_action=="change_pw"){
350 $this->dn= $this->terminals[$s_entry]['dn'];
351 $_SESSION['objectinfo']= $this->dn;
352 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
353 }
356 /********************
357 Password cahnge finish, but check if entered data is ok
358 ********************/
360 /* Correctly specified? */
361 if (isset($_POST['password_finish'])){
362 if ($_POST['new_password'] != $_POST['repeated_password']){
363 print_red (_("Passwords entered as new and repeated do not match!"));
364 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
365 }
366 }
368 /********************
369 Password change finish
370 ********************/
372 /* Change terminal password */
373 if (isset($_POST['password_finish']) &&
374 $_POST['new_password'] == $_POST['repeated_password']){
376 /* Check if user is allowed to set password */
377 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
378 $acl= get_module_permission($acl, "terminal", $this->dn);
379 if (chkacl($acl, "password") != ""){
380 print_red (_("You are not allowed to set this systems password!"));
381 } else {
382 $ldap= $this->config->get_ldap_link();
383 $ldap->cd($this->dn);
385 $attrs= array();
386 if ($_POST['new_password'] == ""){
387 $attrs['gotoRootPasswd']= array();
388 } else {
389 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
390 substr(session_id(),0,2));
391 }
392 $ldap->modify($attrs);
393 gosa_log ("Password for '".$this->dn."' has been changed");
394 }
395 unset($_SESSION['objectinfo']);
396 }
399 /********************
400 Delete system cancel
401 ********************/
403 /* Delete terminal canceled? */
404 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
405 del_lock ($this->dn);
406 unset($_SESSION['objectinfo']);
407 }
410 /********************
411 Delete system, confirm dialog
412 ********************/
414 /* Remove terminal was requested */
415 if ($s_action=="del"){
417 /* Get 'dn' from posted termlinst */
418 $this->dn= $this->terminals[$s_entry]['dn'];
420 /* Load permissions for selected 'dn' and check if
421 we're allowed to remove this 'dn' */
422 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
423 $this->acl= get_module_permission($acl, "terminal", $this->dn);
424 if (chkacl($this->acl, "delete") == ""){
426 /* Check locking, save current plugin in 'back_plugin', so
427 the dialog knows where to return. */
428 if (($user= get_lock($this->dn)) != ""){
429 return(gen_locked_message ($user, $this->dn));
430 }
432 /* Lock the current entry, so nobody will edit it during deletion */
433 add_lock ($this->dn, $this->ui->dn);
434 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
435 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
436 } else {
438 /* Obviously the user isn't allowed to delete. Show message and
439 clean session. */
440 print_red (_("You are not allowed to delete this component!"));
441 }
442 }
445 /********************
446 Delete system, confirmed
447 ********************/
448 /* Confirmation for deletion has been passed. Terminal should be deleted. */
449 if (isset($_POST['delete_terminal_confirm'])){
451 /* Some nice guy may send this as POST, so we've to check
452 for the permissions again. */
453 if (chkacl($this->acl, "delete") == ""){
455 /* Find out more about the object type */
456 $ldap= $this->config->get_ldap_link();
457 $ldap->cat($this->dn, array('objectClass'));
458 $attrs= $ldap->fetch();
459 $type= $this->get_system_type($attrs['objectClass']);
461 $tabs = array(
462 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs"),
463 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs"),
464 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs"),
465 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs"),
466 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs"),
467 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs"),
468 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
470 /* get object type */
471 $tabtype = "termtabs";
472 $tabobj = "TERMTABS";
473 if(isset($tabs[$type])){
474 $tabtype = $tabs[$type]['TABCLASS'];
475 $tabobj = $tabs[$type]['CLASS'];
476 }
478 /* Delete request is permitted, perform LDAP action */
479 if($tabtype=="phonetabs"){
480 $this->systab= new $tabtype($this->config,
481 $this->config->data['TABS'][$tabobj], $this->dn);
482 $this->systab->set_acl(array($this->acl));
483 $this->systab->by_object['phonegeneric']->remove_from_parent ();
484 }else{
485 $this->systab= new $tabtype($this->config,
486 $this->config->data['TABS'][$tabobj], $this->dn);
487 $this->systab->set_acl(array($this->acl));
488 $this->systab->delete();
489 #$this->systab->by_object['termgeneric']->remove_from_parent ();
490 }
491 unset ($this->systab);
492 gosa_log ("System object'".$this->dn."' has been removed");
493 $this->systab= NULL;
495 /* Terminal list has changed, reload it. */
496 } else {
498 /* Normally this shouldn't be reached, send some extra
499 logs to notify the administrator */
500 print_red (_("You are not allowed to delete this component!"));
501 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
502 "deletion.");
503 }
505 /* Remove lock file after successfull deletion */
506 del_lock ($this->dn);
507 }
510 /********************
511 Edit system type finished, check if everything went ok
512 ********************/
513 /* Finish user edit is triggered by the tabulator dialog, so
514 the user wants to save edited data. Check and save at this
515 point. */
516 if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
518 /* Check tabs, will feed message array */
519 $message = array();
520 if(!$save_object_directly){
521 $message = $this->systab->check();
522 }else{
523 $found = false;
525 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
526 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
527 if(isset($this->systab->by_object[$tab]->gotoMode)) {
528 $found = true;
529 $this->systab->by_object[$tab]->gotoMode = $value;
530 }
531 }
532 if(!$found){
533 print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
534 }
536 }
537 /* Save, or display error message? */
538 if (count($message) == 0){
540 /* Save terminal data to ldap */
541 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
542 foreach (array("workservice", "termservice") as $cls){
543 if (isset($this->systab->by_object[$cls])){
544 $this->systab->by_object[$cls]->gotoXMouseport= "";
545 $this->systab->by_object[$cls]->gotoXMouseType= "";
546 $this->systab->by_object[$cls]->gotoXResolution= "";
547 $this->systab->by_object[$cls]->gotoXColordepth= "";
548 }
549 }
550 }
552 $this->systab->save();
553 gosa_log ("System object'".$this->dn."' has been saved");
555 /* Incoming behavior; you can select a system type and an ogroup membership.
556 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
557 * Check if we must add the new object to an object group.
558 *
559 * If this is done, delete the old incoming entry... it is still there, because this is a new
560 * entry and not an edited one, so we will delete it.
561 */
563 if(isset($_SESSION['SelectedSystemType'])){
564 $SelectedSystemType= $_SESSION['SelectedSystemType'];
565 unset($_SESSION['SelectedSystemType']);
566 if($SelectedSystemType['ogroup'] != "none"){
567 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
568 if($og){
569 $og->AddDelMembership($this->systab->dn);
570 $og->save();
571 }
572 }
573 if(!isset($ldap)){
574 $ldap = $this->config->get_ldap_link();
575 }
576 $ldap->cd ($this->dn);
577 $ldap->cat($this->dn, array('dn'));
578 if(count($ldap->fetch())){
579 $ldap->cd($this->dn);
580 $ldap->rmDir($this->dn);
581 }
582 $ldap->cd($this->config->current['BASE']);
583 }
585 /* Terminal has been saved successfully, remove lock from
586 LDAP. */
587 if ($this->dn != "new"){
588 del_lock ($this->dn);
589 }
591 unset ($this->systab);
592 $this->systab= NULL;
593 unset($_SESSION['objectinfo']);
594 } else {
595 /* Ok. There seem to be errors regarding to the tab data,
596 show message and continue as usual. */
597 show_errors($message);
598 }
599 }
601 /********************
602 Edit system was canceled
603 ********************/
604 /* Cancel dialogs */
605 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
606 if (isset($this->systab)){
607 del_lock ($this->systab->dn);
608 unset ($this->systab);
609 }
610 $this->systab= NULL;
611 unset($_SESSION['objectinfo']);
613 /* Remove ogroup selection, which was set while editing a new incoming entry */
614 if(isset($_SESSION['SelectedSystemType'])){
615 unset($_SESSION['SelectedSystemType']);
616 }
617 }
619 /********************
620 Display edit dialog, or some other
621 ********************/
623 /* Show tab dialog if object is present */
624 if (isset($this->systab->config)){
625 $display= $this->systab->execute();
627 /* Don't show buttons if tab dialog requests this */
628 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
629 $display.= "<p style=\"text-align:right\">\n";
630 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
631 $display.= " \n";
632 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
633 $display.= "</p>";
634 }
635 return ($display);
636 }
638 /* Display dialog with system list */
639 $this->DivListSystem->parent = $this;
640 $this->DivListSystem->execute();
642 /* Add departments if subsearch is disabled */
643 if(!$this->DivListSystem->SubSearch){
644 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
645 }
646 $this->reload();
647 $this->DivListSystem->setEntries($this->terminals);
648 return($this->DivListSystem->Draw());
649 }
653 function remove_from_parent()
654 {
655 /* Optionally execute a command after we're done */
656 $this->postremove();
657 }
660 /* Save data to object */
661 function save_object()
662 {
663 $this->DivListSystem->save_object();
664 }
667 /* Check values */
668 function check()
669 {
670 }
673 /* Save to LDAP */
674 function save()
675 {
676 }
678 function adapt_from_template($dn)
679 {
680 }
682 function password_change_needed()
683 {
684 }
686 function reload()
687 {
688 /* Load terminal shortcuts */
689 $responsible= array();
690 foreach ($this->config->departments as $key => $value){
691 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
692 "terminal", $value) == "#all#"){
693 $responsible[$key]= $value;
694 }
695 }
697 /* some var init */
698 $res = array();
699 $this->terminals = array();
700 $userregex = "";
702 /* Set base for all searches */
703 $base= $this->DivListSystem->selectedBase;
705 /* Prepare samba class name */
706 $samba ="";
707 if ($this->DivListSystem->ShowWinWorkstations){
708 if ($this->config->current['SAMBAVERSION'] == "3"){
709 $samba= "sambaSamAccount";
710 } else {
711 $samba= "sambaAccount";
712 }
713 }
715 /* This array represents the combination between checkboxes and search filters */
716 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
717 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
718 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
719 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
720 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
721 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
722 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
724 /* Include the 'Display Systems of user' attribute */
725 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
726 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
727 }
729 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
730 foreach($objs as $checkBox => $oc){
731 if($this->DivListSystem->$checkBox){
732 if($this->DivListSystem->SubSearch){
733 if($oc['CLASS'] != ""){
734 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
735 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
736 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
737 }
738 }else{
739 /* User filter? */
740 if($oc['CLASS'] != ""){
741 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
742 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
743 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
744 }
745 }
746 }
747 }
749 /* Search for incoming objects */
750 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
751 $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
752 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
754 /* Get all gotoTerminal's */
755 foreach ($res as $value){
757 $tmp= $value['dn'];
758 $add= "";
760 /* Extract base */
761 foreach($objs as $obj){
762 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
763 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
764 }
765 }
767 /* check if current object is a new one */
768 if (preg_match ("/,ou=incoming,/i", $tmp)){
769 if (in_array_ics('gotoTerminal', $value['objectClass'])){
770 $add= "- "._("New terminal");
771 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
772 $add= "- "._("New workstation");
773 }elseif (in_array_ics('GOhard', $value['objectClass'])){
774 $add= "- "._("New Device");
775 }
776 }
778 /* Create a string containing the last part of the department. */
779 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
780 if(empty($dn_name)){
781 $dn_name = "/";
782 }
784 /* Detect type of object and create an entry for $this->terminals */
785 $terminal = array();
786 if ((in_array ($tmp, $responsible)) || ($add != "")){
787 if (in_array_ics('gotoTerminal', $value["objectClass"])){
788 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
789 $terminal = $value;
790 $terminal['type'] = "T";
791 $terminal['is_new'] = $add;
792 } else {
793 $terminal = $value;
794 $terminal['type'] = "D";
795 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
796 $terminal['location'] = array_search($tmp, $this->config->departments);
797 }
798 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
799 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
800 $terminal = $value;
801 $terminal['type'] = "L";
802 $terminal['is_new'] = $add;
803 } else {
804 $terminal = $value;
805 $terminal['type'] = "D";
806 $terminal['location'] = array_search($tmp, $this->config->departments);
807 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
808 }
809 if (isset($value["FAIstate"][0])){
810 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
811 }
812 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
813 $terminal = $value;
814 $terminal['type'] = "P";
815 } elseif (in_array_ics('goServer', $value["objectClass"])){
816 $terminal = $value;
817 $terminal['type'] = "S";
818 if (isset($value["FAIstate"][0])){
819 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
820 }
821 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
822 $terminal = $value;
823 $terminal['type'] = "F";
824 }elseif (in_array_ics("GOhard",$value['objectClass'])){
825 $terminal = $value;
826 $terminal['type'] = "Q";
827 $terminal['is_new'] = $add;
828 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
829 $terminal = $value;
830 $terminal['type'] = "C";
831 } else{
832 $name= preg_replace('/\$$/', '', $value['cn'][0]);
833 if (isset($value['sambaDomainName'])){
834 $domain= " [".$value['sambaDomainName'][0]."]";
835 } else {
836 $domain= "";
837 }
838 $terminal=$value;
839 $terminal['type'] ="W";
840 $terminal['domain'] = $name.$domain;
841 }
842 $this->terminals[]=$terminal;
843 }
844 }
846 $tmp=array();
847 foreach($this->terminals as $tkey => $val ){
848 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
849 }
850 ksort($tmp);
851 $this->terminals=array();
852 foreach($tmp as $val){
853 $this->terminals[]=$val;
854 }
855 reset ($this->terminals);
856 }
858 function remove_lock()
859 {
860 if (isset($this->systab->dn)){
861 del_lock ($this->systab->dn);
862 }
863 }
866 function get_system_type($classes)
867 {
868 $type= "";
869 if (in_array_ics('ieee802Device', $classes)){
870 $type= "component";
871 }elseif (in_array_ics('gotoTerminal', $classes)){
872 $type= "terminal";
873 }elseif (in_array_ics('gotoWorkstation', $classes)){
874 $type= "workstation";
875 }elseif (in_array_ics('gotoPrinter', $classes)){
876 $type= "printer";
877 }elseif (in_array_ics('goFonHardware', $classes)){
878 $type= "phone";
879 }elseif (in_array_ics('goServer', $classes)){
880 $type= "server";
881 }elseif (in_array_ics('GOhard', $classes)){
882 $type= "NewDevice";
883 }elseif (in_array_ics('sambaAccount', $classes) ||
884 in_array_ics('sambaSamAccount', $classes)){
885 $type= "winstation";
886 }
887 return ($type);
888 }
891 function convert_list($input)
892 {
893 $temp= "";
894 $conv= array(
895 "NQ" => array("select_newsystem.png",_("New System from incoming")),
896 "D" => array("select_default.png",_("Template")),
897 "T" => array("select_terminal.png",_("Terminal")),
898 "L" => array("select_workstation.png",_("Workstation")),
899 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
900 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
901 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
902 "F" => array("select_phone.png",_("Phone")),
903 "S" => array("select_server.png",_("Server")),
904 "GS" => array("select_server_green.png",_("Server is installing")),
905 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
906 "RS" => array("select_server_red.png",_("Server installation failed")),
907 "W" => array("select_winstation.png",_("Winstation")),
908 "C" => array("select_component.png",_("Network Device")),
909 "NT"=> array("select_new_terminal.png",_("New Terminal")),
910 "NL"=> array("select_new_workstation.png",_("New Workstation")),
911 "P" => array("select_printer.png",_("Printer")));
913 if((isset($input['is_new']))&&(!empty($input['is_new']))){
914 $input['type']="N".$input['type'];
915 }
916 foreach ($conv as $key => $value){
917 if($input['type']==$key){
918 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
919 $tmp['class']=$key;
920 return $tmp;
921 }
922 }
923 }
926 function getState($type, $state)
927 {
928 switch (preg_replace('/:.*$/', '', $state)) {
929 case 'installing':
930 $type= 'G'.$type;
931 break;
932 case 'error':
933 $type= 'R'.$type;
934 break;
935 case 'install':
936 $type= 'Y'.$type;
937 break;
938 case 'sysinfo':
939 $type= 'Y'.$type;
940 break;
941 case 'softupdate':
942 $type= 'Y'.$type;
943 break;
944 }
947 return ($type);
948 }
950 }
952 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
953 ?>