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