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