66ff41e5c5a1ed98a61c6c71655169110a6df1ad
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= "";
42 function systems ($config, $ui)
43 {
44 /* Save configuration for internal use */
45 $this->config= $config;
46 $this->ui= $ui;
48 /* Get global filter config */
49 if (!is_global("terminalfilter")){
50 $ui = get_userinfo();
51 $base = get_base_from_people($ui->dn);
52 $terminalfilter= array("workstations" => "checked",
53 "thins" => "checked",
54 "winstations" => "checked",
55 "servers" => "checked",
56 "printers" => "checked",
57 "phones" => "checked",
58 "netdev" => "checked",
59 "user" => "*",
60 "depselect" => $base,
61 "regex" => "*");
62 register_global("terminalfilter", $terminalfilter);
63 }
64 }
66 function execute()
67 {
68 /* Call parent execute */
69 plugin::execute();
71 $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
73 /********************
74 Filter handling, check posted filter options and store them in our Session obejct
75 ********************/
77 /* Save posted filter data */
78 $terminalfilter= get_global("terminalfilter");
79 foreach( array("depselect", "user", "regex") as $type){
80 if (isset($_POST[$type])){
81 $terminalfilter[$type]= $_POST[$type];
82 }
83 }
85 /* Check if filter checkboxes are selected */
86 if (isset($_POST['depselect'])){
87 foreach( array("workstations", "thins", "winstations", "printers", "phones", "servers", "netdev") as $type){
88 if (isset($_POST[$type])) {
89 $terminalfilter[$type]= "checked";
90 } else {
91 $terminalfilter[$type]= "";
92 }
93 }
94 }
96 /* Check for search post */
97 if (isset($_GET['search'])){
98 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
99 if ($s == "**"){
100 $s= "*";
101 }
102 $terminalfilter['regex']= $s;
103 }
106 /********************
107 Check for functional posts, edit|delete|add|... system devices
108 ********************/
109 $s_action = ""; // Contains the action to proceed
110 $s_entry = ""; // The value for s_action
111 $base_back = ""; // The Link for Backbutton
112 $smarty = get_smarty();
114 /* check if base was changed */
115 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
116 $s_action="open";
117 $s_entry = base64_decode($_GET['dep_id']);
118 $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
119 $this->reload();
120 }
122 /* Test Posts */
123 foreach($_POST as $key => $val){
124 // Post for delete
125 if(preg_match("/user_del.*/",$key)){
126 $s_action = "del";
127 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
128 // Post for edit
129 }elseif(preg_match("/user_edit_.*/",$key)){
130 $s_action="edit";
131 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
132 // Post for new
133 }elseif(preg_match("/dep_back.*/i",$key)){
134 $s_action="back";
135 }elseif(preg_match("/user_new.*/",$key)){
136 $s_action="new";
137 }elseif(preg_match("/dep_home.*/i",$key)){
138 $s_action="home";
139 }elseif(preg_match("/user_tplnew.*/i",$key)){
140 $s_action="new_tpl";
141 }elseif(preg_match("/user_setpwd_.*/i",$key)){
142 $s_action="change_pw";
143 $s_entry = preg_replace("/user_setpwd_/i","",$key);
144 }elseif(preg_match("/dep_root.*/i",$key)){
145 $s_action="root";
146 }elseif(preg_match("/newsystem_.*/i",$key)){
147 $s_action="newsystem";
148 $s_entry = preg_replace("/newsystem_/i","",$key);
149 }
150 }
152 /* 09.02.2006 : New incoming handling ; hickert
153 * If someone made a systemtype and ogroup selection
154 * Display the new requested entry type ... servtab in case of server and so on.
155 */
156 if(isset($_POST['SystemTypeChoosen'])){
157 $s_action = "SelectedSystemType";
158 $s_entry = $_POST['SystemType'];
159 $this->systab = NULL;
160 }
162 /* remove image tags from posted entry (posts looks like this 'name_x')*/
163 $s_entry = preg_replace("/_.$/","",$s_entry);
165 /* Edit was requested by pressing the name(link) of an item */
166 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
167 $s_action ="edit";
168 $s_entry = $_GET['id'];
169 }
171 /* Department changed? */
172 if(isset($_POST['depselect']) && $_POST['depselect']){
173 $terminalfilter['depselect']= $_POST['depselect'];
174 }
176 /* Homebutton is posted */
177 if($s_action=="home"){
178 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
179 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
180 }
182 /* back to the roots ^^ */
183 if($s_action=="root"){
184 $terminalfilter['depselect']=($this->config->current['BASE']);
185 }
187 /* If Backbutton is Posted */
188 if($s_action=="back"){
189 $base_back = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
190 $base_back = convert_department_dn($base_back);
192 if(isset($this->config->departments[trim($base_back)])){
193 $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
194 }else{
195 $terminalfilter['depselect']= $this->config->departments["/"];
196 }
197 }
199 /* Save Termfilter .... */
200 register_global("terminalfilter", $terminalfilter);
201 $this->reload();
203 /* Check for exeeded sizelimit */
204 if (($message= check_sizelimit()) != ""){
205 return($message);
206 }
208 /* Try to get informations about what kind of system to create */
209 if ($s_action=="new") {
210 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
211 }
213 /********************
214 Create new system ...
215 ********************/
216 /* Create new default terminal
217 *
218 * 09.02.2006 ; New incoming handling ; hickert
219 * Or create specified object of selected system type, from given incoming object
220 */
221 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
223 /* If the current entry is an incoming object
224 * $sw = System type as posted in new incoming handling dialog
225 */
226 if($s_action == "SelectedSystemType") {
227 $sw = $s_entry;
228 $dn_backup = $this->dn;
229 }else{
230 if(isset($_POST['system'])){
231 $sw = $_POST['system'];
232 }else{
233 $sw = $s_entry;
234 }
235 }
237 $this->dn= "new";
238 $this->acl= array(":all");
240 switch ($sw){
241 case 'terminal':
242 $this->systab= new termtabs($this->config,
243 $this->config->data['TABS']['TERMTABS'], $this->dn);
244 $this->systab->set_acl ($this->acl);
245 $this->systab->by_object['termgeneric']->cn= "default";
246 $this->systab->by_object['termservice']->cn= "default";
247 $this->systab->by_object['termgeneric']->base = $_SESSION['terminalfilter']['depselect'];
248 break;
250 case 'workstation':
251 $this->systab= new worktabs($this->config,
252 $this->config->data['TABS']['WORKTABS'], $this->dn);
253 $this->systab->set_acl ($this->acl);
254 $this->systab->by_object['workgeneric']->cn= "wdefault";
255 $this->systab->by_object['workservice']->cn= "default";
256 $this->systab->by_object['workgeneric']->base = $_SESSION['terminalfilter']['depselect'];
257 break;
259 case 'server':
260 $this->systab= new servtabs($this->config,
261 $this->config->data['TABS']['SERVTABS'], $this->dn);
262 $this->systab->set_acl ($this->acl);
263 $this->systab->by_object['servgeneric']->base = $_SESSION['terminalfilter']['depselect'];
264 break;
266 case 'printer':
267 $this->systab= new printtabs($this->config,
268 $this->config->data['TABS']['PRINTTABS'], $this->dn);
269 $this->systab->set_acl ($this->acl);
270 $this->systab->by_object['printgeneric']->base = $_SESSION['terminalfilter']['depselect'];
271 break;
273 case 'phone':
274 $this->systab= new phonetabs($this->config,
275 $this->config->data['TABS']['PHONETABS'], $this->dn);
276 $this->systab->set_acl ($this->acl);
277 $this->systab->by_object['phonegeneric']->base = $_SESSION['terminalfilter']['depselect'];
278 break;
280 case 'component':
281 $this->systab= new componenttabs($this->config,
282 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
283 $this->systab->set_acl ($this->acl);
284 $this->systab->by_object['componentgeneric']->base = $_SESSION['terminalfilter']['depselect'];
285 break;
286 }
288 /* 09.02.2006 ; New incoming handling ; hickert.
289 * We must create a NEW object of given system type (Posted from SelectDeviceType).
290 * But we have to use the same attributes as used in incoming object, thats
291 * what we do here.
292 */
293 if($s_action == "SelectedSystemType"){
295 /* Store some informations, to be able to add this object to
296 * To specified objectgroup and delete incoming object
297 */
298 $_SESSION['SelectedSystemType']['dn'] = $this->dn;
299 $_SESSION['SelectedSystemType']['server'] = $s_entry;
300 $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
302 /* restore dn */
303 $this->dn = $dn_backup;
305 /* Get properties from incoming object */
306 $ldap = $this->config->get_ldap_link();
307 $ldap->cd($this->dn);
308 $ldap->cat($this->dn);
309 $res = $ldap->fetch();
311 /* Unset not needed attributes */
312 unset($res['dn']);
313 unset($res['objectClass']);
315 /* Walk through all tabs and set attributes if available */
316 foreach($this->systab->by_object as $name => $value){
317 foreach($this->systab->by_object[$name]->attributes as $atr){
318 if((isset($value))&&(isset($res[$atr]))){
319 $this->systab->by_object[$name]->$atr = $res[$atr][0];
320 }
321 }
322 }
323 }
325 /* set base ... of current divlist position */
326 $this->systab->base = $_SESSION['terminalfilter']['depselect'];
327 }
330 /********************
331 Edit system ...
332 ********************/
334 /* User wants to edit data? */
335 if ($s_action == "edit"){
337 $this->dn= $this->terminals[$s_entry]['dn'];
339 /* Check locking, save current plugin in 'back_plugin', so
340 the dialog knows where to return. */
341 if (($user= get_lock($this->dn)) != ""){
342 return(gen_locked_message ($user, $this->dn));
343 }
345 /* Set up the users ACL's for this 'dn' */
346 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
348 /* Find out more about the object type */
349 $ldap= $this->config->get_ldap_link();
350 $ldap->cat($this->dn);
351 $attrs= $ldap->fetch();
352 $type= $this->get_system_type($attrs['objectClass']);
354 /* Lock the current entry, so everyone will get the
355 above dialog */
357 switch ($type){
358 case "NewDevice" :
359 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
360 break;
361 case "terminal":
362 /* Register systab to trigger edit dialog */
363 $this->systab= new termtabs($this->config,
364 $this->config->data['TABS']['TERMTABS'], $this->dn);
365 $this->systab->set_acl($acl);
366 $_SESSION['objectinfo']= $this->dn;
367 add_lock ($this->dn, $this->ui->dn);
368 break;
370 case "server":
372 /* Register systab to trigger edit dialog */
373 $this->systab= new servtabs($this->config,$this->config->data['TABS']['SERVTABS'], $this->dn);
374 $this->systab->set_acl($acl);
375 $_SESSION['objectinfo']= $this->dn;
376 add_lock ($this->dn, $this->ui->dn);
377 break;
379 case "workstation":
380 /* Register systab to trigger edit dialog */
381 $this->systab= new worktabs($this->config,
382 $this->config->data['TABS']['WORKTABS'], $this->dn);
383 $this->systab->set_acl($acl);
384 $_SESSION['objectinfo']= $this->dn;
385 add_lock ($this->dn, $this->ui->dn);
386 break;
388 case "printer":
389 /* Register systab to trigger edit dialog */
390 $this->systab= new printtabs($this->config,
391 $this->config->data['TABS']['PRINTTABS'], $this->dn);
392 $this->systab->set_acl($acl);
393 $_SESSION['objectinfo']= $this->dn;
394 add_lock ($this->dn, $this->ui->dn);
395 break;
397 case "phone":
398 /* Register systab to trigger edit dialog */
399 $this->systab= new phonetabs($this->config,
400 $this->config->data['TABS']['PHONETABS'], $this->dn);
401 $this->systab->set_acl($acl);
402 $_SESSION['objectinfo']= $this->dn;
403 add_lock ($this->dn, $this->ui->dn);
404 break;
406 case "component":
407 /* Register systab to trigger edit dialog */
408 $this->systab= new componenttabs($this->config,
409 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
410 $this->systab->set_acl($acl);
411 $_SESSION['objectinfo']= $this->dn;
412 add_lock ($this->dn, $this->ui->dn);
413 break;
415 case "winstation":
416 /* Register systab to trigger edit dialog */
417 $this->systab= new wintabs($this->config,
418 $this->config->data['TABS']['WINTABS'], $this->dn);
419 $this->systab->set_acl($acl);
420 $_SESSION['objectinfo']= $this->dn;
421 add_lock ($this->dn, $this->ui->dn);
422 break;
425 default:
426 print_red (_("You can't edit this object type yet!"));
427 del_lock($this->dn);
428 break;
429 }
430 }
433 /********************
434 Change password ...
435 ********************/
437 /* Set terminals root password */
438 if ($s_action=="change_pw"){
439 $this->dn= $this->terminals[$s_entry]['dn'];
440 $_SESSION['objectinfo']= $this->dn;
441 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
442 }
445 /********************
446 Password cahnge finish, but check if entered data is ok
447 ********************/
449 /* Correctly specified? */
450 if (isset($_POST['password_finish'])){
451 if ($_POST['new_password'] != $_POST['repeated_password']){
452 print_red (_("Passwords entered as new and repeated do not match!"));
453 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
454 }
455 }
457 /********************
458 Password change finish
459 ********************/
461 /* Change terminal password */
462 if (isset($_POST['password_finish']) &&
463 $_POST['new_password'] == $_POST['repeated_password']){
465 /* Check if user is allowed to set password */
466 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
467 $acl= get_module_permission($acl, "terminal", $this->dn);
468 if (chkacl($acl, "password") != ""){
469 print_red (_("You are not allowed to set this systems password!"));
470 } else {
471 $ldap= $this->config->get_ldap_link();
472 $ldap->cd($this->dn);
474 $attrs= array();
475 if ($_POST['new_password'] == ""){
476 $attrs['gotoRootPasswd']= array();
477 } else {
478 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
479 substr(session_id(),0,2));
480 }
481 $ldap->modify($attrs);
482 gosa_log ("Password for '".$this->dn."' has been changed");
483 }
484 unset($_SESSION['objectinfo']);
485 }
488 /********************
489 Delete system cancel
490 ********************/
492 /* Delete terminal canceled? */
493 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
494 del_lock ($this->dn);
495 unset($_SESSION['objectinfo']);
496 }
499 /********************
500 Delete system, confirm dialog
501 ********************/
503 /* Remove terminal was requested */
504 if ($s_action=="del"){
506 /* Get 'dn' from posted termlinst */
507 $this->dn= $this->terminals[$s_entry]['dn'];
509 /* Load permissions for selected 'dn' and check if
510 we're allowed to remove this 'dn' */
511 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
512 $this->acl= get_module_permission($acl, "terminal", $this->dn);
513 if (chkacl($this->acl, "delete") == ""){
515 /* Check locking, save current plugin in 'back_plugin', so
516 the dialog knows where to return. */
517 if (($user= get_lock($this->dn)) != ""){
518 return(gen_locked_message ($user, $this->dn));
519 }
521 /* Lock the current entry, so nobody will edit it during deletion */
522 add_lock ($this->dn, $this->ui->dn);
523 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), LDAP::fix($this->dn)));
524 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
525 } else {
527 /* Obviously the user isn't allowed to delete. Show message and
528 clean session. */
529 print_red (_("You are not allowed to delete this component!"));
530 }
531 }
534 /********************
535 Delete system, confirmed
536 ********************/
537 /* Confirmation for deletion has been passed. Terminal should be deleted. */
538 if (isset($_POST['delete_terminal_confirm'])){
540 /* Some nice guy may send this as POST, so we've to check
541 for the permissions again. */
542 if (chkacl($this->acl, "delete") == ""){
544 /* Find out more about the object type */
545 $ldap= $this->config->get_ldap_link();
546 $ldap->cat($this->dn);
547 $attrs= $ldap->fetch();
548 $type= $this->get_system_type($attrs['objectClass']);
550 switch ($type){
551 case "terminal":
552 $tabtype = "termtabs";
553 $tabobj = "TERMTABS";
554 break;
556 case "workstation":
557 $tabtype = "worktabs";
558 $tabobj = "WORKTABS";
559 break;
561 case "phone":
562 $tabtype = "phonetabs";
563 $tabobj = "PHONETABS";
564 break;
566 case "server":
567 $tabtype = "servtabs";
568 $tabobj = "SERVTABS";
569 break;
571 default:
572 $tabtype = "termtabs";
573 $tabobj = "TERMTABS";
574 break;
575 }
577 /* Delete request is permitted, perform LDAP action */
578 if($tabtype=="phonetabs"){
579 $this->systab= new $tabtype($this->config,
580 $this->config->data['TABS'][$tabobj], $this->dn);
581 $this->systab->set_acl(array($this->acl));
582 $this->systab->by_object['phonegeneric']->remove_from_parent ();
583 }else{
584 $this->systab= new $tabtype($this->config,
585 $this->config->data['TABS'][$tabobj], $this->dn);
586 $this->systab->set_acl(array($this->acl));
587 $this->systab->delete();
588 #$this->systab->by_object['termgeneric']->remove_from_parent ();
589 }
590 unset ($this->systab);
591 gosa_log ("System object'".$this->dn."' has been removed");
592 $this->systab= NULL;
594 /* Terminal list has changed, reload it. */
595 $this->reload ();
596 } else {
598 /* Normally this shouldn't be reached, send some extra
599 logs to notify the administrator */
600 print_red (_("You are not allowed to delete this component!"));
601 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
602 "deletion.");
603 }
605 /* Remove lock file after successfull deletion */
606 del_lock ($this->dn);
607 }
610 /********************
611 Edit system type finished, check if everything went ok
612 ********************/
613 /* Finish user edit is triggered by the tabulator dialog, so
614 the user wants to save edited data. Check and save at this
615 point. */
616 if (isset($_POST['edit_finish'])){
618 /* Check tabs, will feed message array */
619 $message= $this->systab->check();
621 /* Save, or display error message? */
622 if (count($message) == 0){
624 /* Save terminal data to ldap */
625 gosa_log ("System object'".$this->dn."' has been saved");
626 $this->systab->save();
628 /* Terminal has been saved successfully, remove lock from
629 LDAP. */
631 /* 09.02.2006 Hickert
632 * New System incoming behavior; you can select a system type and an ogroup membership.
633 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
634 * Check if we must add the new object to an object group.
635 * !! Don't forget to unset the $_SESSION['SelectedSystemType']... else all edited objects
636 * !! will be added to the object group.
637 *
638 * If this is done, delete the old incoming entry... it is still there, because this is a new
639 * entry and not an edited one.
640 */
641 if(isset($_SESSION['SelectedSystemType'])){
642 $SelectedSystemType= $_SESSION['SelectedSystemType'];
643 unset($_SESSION['SelectedSystemType']);
644 if($SelectedSystemType['ogroup'] != "none"){
645 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
646 if($og){
647 $og->AddDelMembership($this->systab->dn);
648 }
649 $og->save();
650 }
651 if(!isset($ldap)){
652 $ldap = $this->config->get_ldap_link();
653 }
654 $ldap->cd ($this->dn);
655 $ldap->cat($this->dn);
656 if(count($ldap->fetch())){
657 $ldap->cd($this->dn);
658 $ldap->rmDir($this->dn);
659 }
660 $ldap->cd($this->config->current['BASE']);
661 }
663 if ($this->dn != "new"){
664 del_lock ($this->dn);
665 }
667 /* There's no page reload so we have to read new terminals at
668 this point. */
669 $this->reload ();
670 unset ($this->systab);
671 $this->systab= NULL;
672 unset($_SESSION['objectinfo']);
674 } else {
675 /* Ok. There seem to be errors regarding to the tab data,
676 show message and continue as usual. */
677 show_errors($message);
678 }
680 }
683 /********************
684 Edit system was canceled
685 ********************/
686 /* Cancel dialogs */
687 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
688 if (isset($this->systab)){
689 del_lock ($this->systab->dn);
690 unset ($this->systab);
691 }
692 $this->systab= NULL;
693 unset($_SESSION['objectinfo']);
695 /* 09.02.2006 ; New incoming handling ; hickert
696 * remove session object which stores our ogroup selection
697 * for the new incoming handling
698 */
699 if(isset($_SESSION['SelectedSystemType'])){
700 unset($_SESSION['SelectedSystemType']);
701 }
702 }
705 /********************
706 Display edit dialog, or some other
707 ********************/
709 /* Show tab dialog if object is present */
710 if ($this->systab){
711 $display= $this->systab->execute();
714 /* Don't show buttons if tab dialog requests this */
715 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
716 $display.= "<p style=\"text-align:right\">\n";
717 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
718 $display.= " \n";
719 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
720 $display.= "</p>";
721 }
722 return ($display);
723 }
726 /********************
727 Entry handling finished (edit delete ... )
728 Now the list generation is the next part of this script.
729 ********************/
731 /* Prepare departments,
732 which are shown in the listbox on top of the listbox
733 */
734 $options= "";
735 foreach ($this->config->idepartments as $key => $value){
736 if ($terminalfilter['depselect'] == $key){
737 $options.= "<option selected='selected' value='$key'>$value</option>";
738 } else {
739 $options.= "<option value='$key'>$value</option>";
740 }
741 }
744 /* NEW LIST MANAGMENT */
746 /* Create list header
747 */
748 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
749 " <input class='center' type='image' align='middle' src='images/list_back.png'
750 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
751 " <input class='center' type='image' src='images/list_root.png' align='middle'
752 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
753 " <input class='center' type='image' align='middle' src='images/list_home.png'
754 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
755 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
756 " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'
757 name='newsystem_terminal' alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
758 " <input class='center' type='image' align='middle' src='images/select_new_workstation.png'
759 name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
760 " <input class='center' type='image' align='middle' src='images/select_new_server.png' name='newsystem_server' alt='"._("New Server")."'
761 title='"._("New Server")."'>".
762 " <input class='center' type='image' align='middle' src='images/select_new_printer.png' name='newsystem_printer' alt='"._("New Printer")."'
763 title='"._("New Printer")."'>".
764 " <input class='center' type='image' align='middle' src='images/select_new_phone.png' name='newsystem_phone' alt='"._("New Phone")."'
765 title='"._("New Phone")."'>".
766 " <input class='center' type='image' align='middle' src='images/select_new_component.png' name='newsystem_component' alt='"._("New Component")."'
767 title='"._("New Component")."'>".
768 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> "._("Base")." ".
769 " <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
770 " <input class='center' type='image' src='images/list_submit.png' align='middle'
771 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
772 "</div>";
775 /* Edit delete link for system types
776 */
777 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
778 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
779 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
781 /* Create new divlist, and add the header elements
782 */
783 $divlist = new divlist("systemstab");
784 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
785 $divlist->SetEntriesPerPage(0);
786 $divlist->SetHeader(array(
787 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
788 array("string" => _("System")." / "._("Department"), "attach" => "style=''"),
789 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
792 /* Add departments, to be able to switch into them
793 */
794 foreach($this->departments as $key=> $val){
796 /* Add missing entries ... */
797 if(!isset($this->config->departments[trim($key)])){
798 $this->config->departments[trim($key)]="";
799 }
801 /* check if this department contains sub-departments
802 Display different image in this case
803 */
804 $non_empty="";
805 $keys= str_replace("/","\/",$key);
806 foreach($this->config->departments as $keyd=>$vald ){
807 if(preg_match("/".$keys."\/.*/",$keyd)){
808 $non_empty="full";
809 }
810 }
812 /* Add to divlist */
813 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
814 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
815 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
816 $divlist->AddEntry(array($field1,$field2,$field3));
817 }
819 // Iamge spacer
820 $empty =" ";
822 // User and Template Images
823 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
825 // Pictures for Extensions
826 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
827 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
828 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
829 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
830 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
831 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
832 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
833 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
834 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
835 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
837 // Test Every Entry and generate divlist Array
838 foreach($this->terminals as $key => $val){
839 // Specify Pics for Extensions
840 if(in_array("goLdapServer" ,$val['objectClass'])){
842 }
844 /* Generate picture list, which is currently disabled */
845 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
846 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
847 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
848 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
849 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
850 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
851 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
852 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
853 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
854 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
855 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
856 $pics = "";
858 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
860 // Generate Array to Add
861 if((isset($val['is_new']))&&(!empty($val['is_new']))){
862 $display= "".$val["cn"][0]." ".$val['is_new'];
863 }else{
864 $display= "".$val["cn"][0]."";
865 }
867 if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
868 $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
869 }else{
870 $action2 = "";
871 }
873 if(isset($val['message'])){
874 $display.= " (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."' )";
875 }
877 $img=$this->convert_list($val);
879 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
880 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
881 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
882 $divlist->AddEntry( array($field1,$field2,$field3));
883 }
885 /* Show main page */
886 $smarty->assign("terminalshead", $listhead);
887 $smarty->assign("terminals", $divlist->DrawList());
888 $smarty->assign("search_image", get_template_path('images/search.png'));
889 $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
890 $smarty->assign("tree_image", get_template_path('images/tree.png'));
891 $smarty->assign("infoimage", get_template_path('images/info.png'));
892 $smarty->assign("launchimage", get_template_path('images/launch.png'));
893 foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
894 "winstations", "printers", "phones", "netdev") as $type){
896 $smarty->assign("$type", $terminalfilter[$type]);
897 }
898 $smarty->assign("deplist", $this->config->idepartments);
900 /* Extend if we are not using javascript */
901 $smarty->assign("apply", apply_filter());
902 $smarty->assign("alphabet", generate_alphabet());
903 $smarty->assign("hint", print_sizelimit_warning());
905 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
906 }
909 function convert_list($input)
910 {
911 $temp= "";
912 $conv= array(
913 "NQ" => array("select_newsystem.png",_("New System from incoming")),
914 "D" => array("select_default.png",_("Template")),
915 "T" => array("select_terminal.png",_("Terminal")),
916 "L" => array("select_workstation.png",_("Workstation")),
917 "F" => array("select_phone.png",_("Phone")),
918 "S" => array("select_server.png",_("Server")),
919 "W" => array("select_winstation.png",_("Winstation")),
920 "C" => array("select_component.png",_("Network Device")),
921 "NT"=> array("select_new_terminal.png",_("New Terminal")),
922 "NL"=> array("select_new_workstation.png",_("New Workstation")),
923 "P" => array("select_printer.png",_("Printer")));
925 if((isset($input['is_new']))&&(!empty($input['is_new']))){
926 $input['type']="N".$input['type'];
927 }
928 foreach ($conv as $key => $value){
929 if($input['type']==$key){
930 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
931 $tmp['class']=$key;
932 return $tmp;
933 }
934 }
935 }
937 function remove_from_parent()
938 {
939 /* Optionally execute a command after we're done */
940 $this->postremove();
941 }
944 /* Save data to object */
945 function save_object()
946 {
947 }
950 /* Check values */
951 function check()
952 {
953 }
956 /* Save to LDAP */
957 function save()
958 {
959 }
961 function adapt_from_template($dn)
962 {
963 }
965 function password_change_needed()
966 {
967 }
969 function show_header($button_text, $text, $disabled= FALSE)
970 {
971 }
973 function reload()
974 {
975 /* Load terminal shortcuts */
976 $responsible= array();
977 foreach ($this->config->departments as $key => $value){
978 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
979 "terminal", $value) == "#all#"){
980 $responsible[$key]= $value;
981 }
982 }
984 /* Get config */
985 $terminalfilter= get_global('terminalfilter');
986 $filter= "";
988 /* Set base for all searches */
989 $base= $terminalfilter['depselect'];
991 /* Regex filter? */
992 if ($terminalfilter['regex'] != ""){
993 $regex= $terminalfilter['regex'];
994 } else {
995 $regex= "*";
996 }
998 /* Get list of terminals to be shown */
999 if ($terminalfilter['thins'] == "checked"){
1000 $termfilter= "(&(objectClass=goHard)(cn=$regex))";
1001 } else {
1002 $termfilter= "";
1003 }
1004 if ($terminalfilter['workstations'] == "checked"){
1005 $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
1006 } else {
1007 $workfilter= "";
1008 }
1009 if ($terminalfilter['winstations'] == "checked"){
1010 if ($this->config->current['SAMBAVERSION'] == "3"){
1011 $samba= "sambaSamAccount";
1012 } else {
1013 $samba= "sambaAccount";
1014 }
1015 $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
1016 } else {
1017 $winfilter= "";
1018 }
1019 if ($terminalfilter['printers'] == "checked"){
1020 $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
1021 } else {
1022 $printfilter= "";
1023 }
1024 if ($terminalfilter['phones'] == "checked"){
1025 $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
1026 } else {
1027 $phonefilter= "";
1028 }
1029 if ($terminalfilter['netdev'] == "checked"){
1030 $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
1031 } else {
1032 $netfilter= "";
1033 }
1034 if ($terminalfilter['servers'] == "checked"){
1035 $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
1036 } else {
1037 $serverfilter= "";
1038 }
1040 /* User filter? */
1041 if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
1042 $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
1043 }
1045 /* Get all gotoTerminal's */
1046 $this->terminals= array();
1048 $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base,
1049 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
1051 $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base,
1052 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1054 $res= array_merge($res,
1055 get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base,
1056 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1058 $res= array_merge($res,
1059 get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base,
1060 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1062 $res= array_merge($res,
1063 get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base,
1064 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1066 $res= array_merge($res,
1067 get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base,
1068 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1070 $res= array_merge($res,
1071 get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,ou=systems,".$base,
1072 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1074 $res= array_merge($res,
1075 get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base,
1076 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1078 /* NEW LIST MANAGMENT
1079 * We also need to search for the departments
1080 * So we are able to navigate like in konquerer
1081 */
1083 $peopleOU = get_people_ou();
1085 if(empty($peopleOU)){
1086 $base2 = $base;
1087 }else{
1088 $base2 = preg_replace("/".$peopleOU."/i","",$base);
1089 }
1092 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1093 TRUE, $base2, array("ou", "description"), TRUE);
1095 $this->departments= array();
1096 $tmp = array();
1097 foreach ($res3 as $value){
1098 $tmp[strtolower($value['dn']).$value['dn']]=$value;
1099 }
1100 ksort($tmp);
1101 foreach($tmp as $value){
1102 if(isset($value["description"][0])){
1103 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1104 }else{
1105 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
1106 }
1107 }
1109 /* END NEW LIST MANAGMENT
1110 */
1113 foreach ($res as $value){
1115 /* Look for new terminals and mark them with '+' */
1116 $tmp= "";
1117 if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
1118 $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
1119 }
1120 if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
1121 $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
1122 }
1123 if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
1124 $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
1125 }
1126 if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
1127 $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
1128 }
1129 if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
1130 $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
1131 }
1132 if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
1133 $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
1134 }
1135 if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
1136 $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
1137 }
1138 if ($tmp == ""){
1139 $tmp= $value["dn"];
1140 }
1141 if (preg_match ("/,ou=incoming,/i", $tmp)){
1142 if (in_array('gotoTerminal', $value['objectClass'])){
1143 $add= "- "._("New terminal");
1144 }elseif (in_array('gotoWorkstation', $value['objectClass'])){
1145 $add= "- "._("New workstation");
1146 }elseif (in_array('GOhard', $value['objectClass'])){
1147 $add= "- "._("New Device");
1148 }
1149 } else {
1150 $add= "";
1151 }
1153 $terminal = array();
1155 if (in_array ($tmp, $responsible) || $add != ""){
1156 if (in_array('gotoTerminal', $value["objectClass"])){
1157 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1158 $terminal = $value;
1159 $terminal['type'] = "T";
1160 $terminal['is_new'] = $add;
1161 } else {
1162 $terminal = $value;
1163 $terminal['type'] = "D";
1164 $terminal['message'] = _("Terminal template for");
1165 $terminal['location'] = array_search($tmp, $this->config->departments);
1166 }
1167 } elseif (in_array('gotoWorkstation', $value["objectClass"])){
1168 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1169 $terminal = $value;
1170 $terminal['type'] = "L";
1171 $terminal['is_new'] = $add;
1172 } else {
1173 $terminal = $value;
1174 $terminal['type'] = "D";
1175 $terminal['location'] = array_search($tmp, $this->config->departments);
1176 $terminal['message'] = _("Workstation template for");
1177 }
1178 } elseif (in_array('gotoPrinter', $value["objectClass"])){
1179 $terminal = $value;
1180 $terminal['type'] = "P";
1181 } elseif (in_array('goServer', $value["objectClass"])){
1182 $terminal = $value;
1183 $terminal['type'] = "S";
1184 } elseif (in_array('goFonHardware', $value["objectClass"])){
1185 $terminal = $value;
1186 $terminal['type'] = "F";
1187 }elseif (in_array("GOhard",$value['objectClass'])){
1188 $terminal = $value;
1189 $terminal['type'] = "Q";
1190 $terminal['is_new'] = $add;
1191 } elseif (in_array('ieee802Device', $value["objectClass"])){
1192 $terminal = $value;
1193 $terminal['type'] = "C";
1194 } else{
1195 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1196 if (isset($value['sambaDomainName'])){
1197 $domain= " [".$value['sambaDomainName'][0]."]";
1198 } else {
1199 $domain= "";
1200 }
1201 $terminal=$value;
1202 $terminal['type'] ="W";
1203 $terminal['domain'] = $name.$domain;
1204 }
1205 $this->terminals[]=$terminal;
1206 }
1207 }
1209 $tmp=array();
1210 foreach($this->terminals as $tkey => $val ){
1211 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1212 }
1213 ksort($tmp);
1214 $this->terminals=array();
1215 foreach($tmp as $val){
1216 $this->terminals[]=$val;
1217 }
1218 reset ($this->terminals);
1219 }
1221 function remove_lock()
1222 {
1223 if (isset($this->systab->dn)){
1224 del_lock ($this->systab->dn);
1225 }
1226 }
1229 function get_system_type($classes)
1230 {
1231 $type= "";
1233 if (in_array('ieee802Device', $classes)){
1234 $type= "component";
1235 }else
1236 if (in_array('gotoTerminal', $classes)){
1237 $type= "terminal";
1238 }else
1239 if (in_array('gotoWorkstation', $classes)){
1240 $type= "workstation";
1241 }else
1242 if (in_array('gotoPrinter', $classes)){
1243 $type= "printer";
1244 }else
1245 if (in_array('goFonHardware', $classes)){
1246 $type= "phone";
1247 }else
1248 if (in_array('goServer', $classes)){
1249 $type= "server";
1250 }else
1251 if (in_array('GOhard', $classes)){
1252 $type= "NewDevice";
1253 }else
1254 if (in_array('sambaAccount', $classes) ||
1255 in_array('sambaSamAccount', $classes)){
1256 $type= "winstation";
1257 }
1259 return ($type);
1260 }
1262 }
1264 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1265 ?>