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 /* Save data */
69 $terminalfilter= get_global("terminalfilter");
70 foreach( array("depselect", "user", "regex") as $type){
71 if (isset($_POST[$type])){
72 $terminalfilter[$type]= $_POST[$type];
73 }
74 }
75 if (isset($_POST['depselect'])){
76 foreach( array("workstations", "thins", "winstations", "printers", "phones", "servers", "netdev") as $type){
78 if (isset($_POST[$type])) {
79 $terminalfilter[$type]= "checked";
80 } else {
81 $terminalfilter[$type]= "";
82 }
83 }
84 }
85 if (isset($_GET['search'])){
86 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
87 if ($s == "**"){
88 $s= "*";
89 }
90 $terminalfilter['regex']= $s;
91 }
93 $s_action = ""; // Contains the action to proceed
94 $s_entry = ""; // The value for s_action
95 $base_back = ""; // The Link for Backbutton
96 $smarty = get_smarty();
98 /* Start for New List Managment */
99 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
100 $s_action="open";
101 $s_entry = base64_decode($_GET['dep_id']);
102 $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
103 $this->reload();
104 }
106 /* Test Posts */
107 foreach($_POST as $key => $val){
108 // Post for delete
109 if(preg_match("/user_del.*/",$key)){
110 $s_action = "del";
111 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
112 // Post for edit
113 }elseif(preg_match("/user_edit_.*/",$key)){
114 $s_action="edit";
115 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
116 // Post for new
117 }elseif(preg_match("/dep_back.*/i",$key)){
118 $s_action="back";
119 }elseif(preg_match("/user_new.*/",$key)){
120 $s_action="new";
121 }elseif(preg_match("/dep_home.*/i",$key)){
122 $s_action="home";
123 }elseif(preg_match("/user_tplnew.*/i",$key)){
124 $s_action="new_tpl";
125 }elseif(preg_match("/user_setpwd_.*/i",$key)){
126 $s_action="change_pw";
127 $s_entry = preg_replace("/user_setpwd_/i","",$key);
128 }elseif(preg_match("/dep_root.*/i",$key)){
129 $s_action="root";
130 }elseif(preg_match("/newsystem_.*/i",$key)){
131 $s_action="newsystem";
132 $s_entry = preg_replace("/newsystem_/i","",$key);
133 }
134 }
136 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
137 $s_action ="edit";
138 $s_entry = $_GET['id'];
139 }
141 $s_entry = preg_replace("/_.$/","",$s_entry);
143 /* Department changed? */
144 if(isset($_POST['depselect']) && $_POST['depselect']){
145 $terminalfilter['depselect']= $_POST['depselect'];
146 }
148 /* Homebutton is posted */
149 if($s_action=="home"){
150 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
151 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
152 }
154 if($s_action=="root"){
155 $terminalfilter['depselect']=($this->config->current['BASE']);
156 }
159 /* If Backbutton is Posted */
160 if($s_action=="back"){
161 $base_back = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
162 $base_back = convert_department_dn($base_back);
164 if(isset($this->config->departments[trim($base_back)])){
165 $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
166 }else{
167 $terminalfilter['depselect']= $this->config->departments["/"];
168 }
169 }
171 register_global("terminalfilter", $terminalfilter);
172 $this->reload();
174 /* Check for exeeded sizelimit */
175 if (($message= check_sizelimit()) != ""){
176 return($message);
177 }
179 /* Try to get informations about what kind of system to create */
180 if ($s_action=="new") {
181 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
182 }
184 /* Create new default terminal */
185 if (isset($_POST['create_system'])||$s_action=="newsystem") {
186 $this->dn= "new";
187 $this->acl= array(":all");
189 if(isset($_POST['system'])){
190 $sw = $_POST['system'];
191 }else{
192 $sw = $s_entry;
193 }
195 switch ($sw){
196 case 'terminal':
197 $this->systab= new termtabs($this->config,
198 $this->config->data['TABS']['TERMTABS'], $this->dn);
199 $this->systab->set_acl ($this->acl);
200 $this->systab->by_object['termgeneric']->cn= "default";
201 $this->systab->by_object['termservice']->cn= "default";
202 $this->systab->by_object['termgeneric']->base = $_SESSION['terminalfilter']['depselect'];
203 break;
205 case 'workstation':
206 $this->systab= new worktabs($this->config,
207 $this->config->data['TABS']['WORKTABS'], $this->dn);
208 $this->systab->set_acl ($this->acl);
209 $this->systab->by_object['workgeneric']->cn= "wdefault";
210 $this->systab->by_object['workservice']->cn= "default";
211 $this->systab->by_object['workgeneric']->base = $_SESSION['terminalfilter']['depselect'];
212 break;
214 case 'server':
215 $this->systab= new servtabs($this->config,
216 $this->config->data['TABS']['SERVTABS'], $this->dn);
217 $this->systab->set_acl ($this->acl);
218 $this->systab->by_object['servgeneric']->base = $_SESSION['terminalfilter']['depselect'];
219 break;
221 case 'printer':
222 $this->systab= new printtabs($this->config,
223 $this->config->data['TABS']['PRINTTABS'], $this->dn);
224 $this->systab->set_acl ($this->acl);
225 $this->systab->by_object['printgeneric']->base = $_SESSION['terminalfilter']['depselect'];
226 break;
228 case 'phone':
229 $this->systab= new phonetabs($this->config,
230 $this->config->data['TABS']['PHONETABS'], $this->dn);
231 $this->systab->set_acl ($this->acl);
232 $this->systab->by_object['phonegeneric']->base = $_SESSION['terminalfilter']['depselect'];
233 break;
235 case 'component':
236 $this->systab= new componenttabs($this->config,
237 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
238 $this->systab->set_acl ($this->acl);
239 $this->systab->by_object['componentgeneric']->base = $_SESSION['terminalfilter']['depselect'];
240 break;
241 }
243 $this->systab->base = $_SESSION['terminalfilter']['depselect'];
244 }
247 /* User wants to edit data? */
248 if ($s_action == "edit"){
250 /* Get 'dn' from posted 'cn', must be unique */
251 $this->dn= $this->terminals[$s_entry]['dn'];
253 /* Check locking, save current plugin in 'back_plugin', so
254 the dialog knows where to return. */
255 if (($user= get_lock($this->dn)) != ""){
256 return(gen_locked_message ($user, $this->dn));
257 }
259 /* Set up the users ACL's for this 'dn' */
260 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
262 /* Find out more about the object type */
263 $ldap= $this->config->get_ldap_link();
264 $ldap->cat($this->dn);
265 $attrs= $ldap->fetch();
266 $type= $this->get_system_type($attrs['objectClass']);
268 /* Lock the current entry, so everyone will get the
269 above dialog */
270 add_lock ($this->dn, $this->ui->dn);
272 switch ($type){
273 case "terminal":
274 /* Register systab to trigger edit dialog */
275 $this->systab= new termtabs($this->config,
276 $this->config->data['TABS']['TERMTABS'], $this->dn);
277 $this->systab->set_acl($acl);
278 $_SESSION['objectinfo']= $this->dn;
279 break;
281 case "server":
282 /* Register systab to trigger edit dialog */
283 $this->systab= new servtabs($this->config,
284 $this->config->data['TABS']['SERVTABS'], $this->dn);
285 $this->systab->set_acl($acl);
286 $_SESSION['objectinfo']= $this->dn;
287 break;
289 case "workstation":
290 /* Register systab to trigger edit dialog */
291 $this->systab= new worktabs($this->config,
292 $this->config->data['TABS']['WORKTABS'], $this->dn);
293 $this->systab->set_acl($acl);
294 $_SESSION['objectinfo']= $this->dn;
295 break;
297 case "printer":
298 /* Register systab to trigger edit dialog */
299 $this->systab= new printtabs($this->config,
300 $this->config->data['TABS']['PRINTTABS'], $this->dn);
301 $this->systab->set_acl($acl);
302 $_SESSION['objectinfo']= $this->dn;
303 break;
305 case "phone":
306 /* Register systab to trigger edit dialog */
307 $this->systab= new phonetabs($this->config,
308 $this->config->data['TABS']['PHONETABS'], $this->dn);
309 $this->systab->set_acl($acl);
310 $_SESSION['objectinfo']= $this->dn;
311 break;
313 case "component":
314 /* Register systab to trigger edit dialog */
315 $this->systab= new componenttabs($this->config,
316 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
317 $this->systab->set_acl($acl);
318 $_SESSION['objectinfo']= $this->dn;
319 break;
321 case "winstation":
322 /* Register systab to trigger edit dialog */
323 $this->systab= new wintabs($this->config,
324 $this->config->data['TABS']['WINTABS'], $this->dn);
325 $this->systab->set_acl($acl);
326 $_SESSION['objectinfo']= $this->dn;
327 break;
330 default:
331 print_red (_("You can't edit this object type yet!"));
332 del_lock($this->dn);
333 break;
334 }
335 }
337 /* Set terminals root password */
338 if ($s_action=="change_pw"){
339 $this->dn= $this->terminals[$s_entry]['dn'];
340 $_SESSION['objectinfo']= $this->dn;
341 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
342 }
344 /* Correctly specified? */
345 if (isset($_POST['password_finish'])){
346 if ($_POST['new_password'] != $_POST['repeated_password']){
347 print_red (_("Passwords entered as new and repeated do not match!"));
348 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
349 }
350 }
352 /* Change terminal password */
353 if (isset($_POST['password_finish']) &&
354 $_POST['new_password'] == $_POST['repeated_password']){
356 /* Check if user is allowed to set password */
357 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
358 $acl= get_module_permission($acl, "terminal", $this->dn);
359 if (chkacl($acl, "password") != ""){
360 print_red (_("You are not allowed to set this systems password!"));
361 } else {
362 $ldap= $this->config->get_ldap_link();
363 $ldap->cd($this->dn);
365 $attrs= array();
366 if ($_POST['new_password'] == ""){
367 $attrs['gotoRootPasswd']= array();
368 } else {
369 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
370 substr(session_id(),0,2));
371 }
372 $ldap->modify($attrs);
373 gosa_log ("Password for '".$this->dn."' has been changed");
374 }
375 unset($_SESSION['objectinfo']);
376 }
378 /* Delete terminal canceled? */
379 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
380 del_lock ($this->dn);
381 unset($_SESSION['objectinfo']);
382 }
384 /* Remove terminal was requested */
385 if ($s_action=="del"){
387 /* Get 'dn' from posted termlinst */
388 $this->dn= $this->terminals[$s_entry]['dn'];
390 /* Load permissions for selected 'dn' and check if
391 we're allowed to remove this 'dn' */
392 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
393 $this->acl= get_module_permission($acl, "terminal", $this->dn);
394 if (chkacl($this->acl, "delete") == ""){
396 /* Check locking, save current plugin in 'back_plugin', so
397 the dialog knows where to return. */
398 if (($user= get_lock($this->dn)) != ""){
399 return(gen_locked_message ($user, $this->dn));
400 }
402 /* Lock the current entry, so nobody will edit it during deletion */
403 add_lock ($this->dn, $this->ui->dn);
404 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
405 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
406 } else {
408 /* Obviously the user isn't allowed to delete. Show message and
409 clean session. */
410 print_red (_("You are not allowed to delete this component!"));
411 }
412 }
414 /* Confirmation for deletion has been passed. Terminal should be deleted. */
415 if (isset($_POST['delete_terminal_confirm'])){
417 /* Some nice guy may send this as POST, so we've to check
418 for the permissions again. */
419 if (chkacl($this->acl, "delete") == ""){
421 /* Find out more about the object type */
422 $ldap= $this->config->get_ldap_link();
423 $ldap->cat($this->dn);
424 $attrs= $ldap->fetch();
425 $type= $this->get_system_type($attrs['objectClass']);
427 switch ($type){
428 case "terminal":
429 $tabtype= "termtabs";
430 break;
432 case "workstation":
433 $tabtype= "worktabs";
434 break;
436 case "phone":
437 $tabtype= "phonetabs";
438 break;
440 case "server":
441 $tabtype= "servtabs";
442 break;
444 default:
445 #print_red (_("You can't remove this object type yet!"));
446 #del_lock($this->dn);
447 #return;
448 $tabtype= "termtabs";
449 break;
450 }
452 /* Delete request is permitted, perform LDAP action */
453 if($tabtype=="phonetabs"){
454 $this->systab= new $tabtype($this->config,
455 $this->config->data['TABS']['PHONETABS'], $this->dn);
456 $this->systab->set_acl(array($this->acl));
457 $this->systab->by_object['phonegeneric']->remove_from_parent ();
458 }else{
459 $this->systab= new $tabtype($this->config,
460 $this->config->data['TABS']['TERMTABS'], $this->dn);
461 $this->systab->set_acl(array($this->acl));
462 $this->systab->by_object['termgeneric']->remove_from_parent ();
463 }
464 unset ($this->systab);
465 gosa_log ("System object'".$this->dn."' has been removed");
466 $this->systab= NULL;
468 /* Terminal list has changed, reload it. */
469 $this->reload ();
470 } else {
472 /* Normally this shouldn't be reached, send some extra
473 logs to notify the administrator */
474 print_red (_("You are not allowed to delete this component!"));
475 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
476 "deletion.");
477 }
479 /* Remove lock file after successfull deletion */
480 del_lock ($this->dn);
481 }
483 /* Finish user edit is triggered by the tabulator dialog, so
484 the user wants to save edited data. Check and save at this
485 point. */
486 if (isset($_POST['edit_finish'])){
488 /* Check tabs, will feed message array */
489 $message= $this->systab->check();
491 /* Save, or display error message? */
492 if (count($message) == 0){
494 /* Save terminal data to ldap */
495 gosa_log ("System object'".$this->dn."' has been saved");
496 $this->systab->save();
498 /* Terminal has been saved successfully, remove lock from
499 LDAP. */
500 if ($this->dn != "new"){
501 del_lock ($this->dn);
502 }
504 /* There's no page reload so we have to read new terminals at
505 this point. */
506 $this->reload ();
507 unset ($this->systab);
508 $this->systab= NULL;
509 unset($_SESSION['objectinfo']);
511 } else {
512 /* Ok. There seem to be errors regarding to the tab data,
513 show message and continue as usual. */
514 show_errors($message);
515 }
517 }
519 /* Cancel dialogs */
520 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
521 if (isset($this->systab)){
522 del_lock ($this->systab->dn);
523 unset ($this->systab);
524 }
525 $this->systab= NULL;
526 unset($_SESSION['objectinfo']);
527 }
529 /* Show tab dialog if object is present */
530 if ($this->systab){
531 $display= $this->systab->execute();
533 /* Don't show buttons if tab dialog requests this */
534 if (!$this->systab->by_object[$this->systab->current]->dialog){
535 $display.= "<p style=\"text-align:right\">\n";
536 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
537 $display.= " \n";
538 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
539 $display.= "</p>";
540 }
541 return ($display);
542 }
549 /* Prepare departments */
550 $options= "";
551 foreach ($this->config->idepartments as $key => $value){
552 if ($terminalfilter['depselect'] == $key){
553 $options.= "<option selected value='$key'>$value</option>";
554 } else {
555 $options.= "<option value='$key'>$value</option>";
556 }
557 }
560 /* NEW LIST MANAGMENT */
561 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
562 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
563 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
564 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
565 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
566 " <input type='image' align='middle' src='images/select_new_terminal.png' name='newsystem_terminal' alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
567 " <input type='image' align='middle' src='images/select_new_workstation.png' name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
568 " <input type='image' align='middle' src='images/select_new_server.png' name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'>".
569 " <input type='image' align='middle' src='images/select_new_printer.png' name='newsystem_printer' alt='"._("New Printer")."' title='"._("New Printer")."'>".
570 " <input type='image' align='middle' src='images/select_new_phone.png' name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'>".
571 " <input type='image' align='middle' src='images/select_new_component.png' name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'>".
572 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
573 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
574 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
575 "</div>";
579 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
580 $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
583 $divlist = new divlist("systemstab");
584 $divlist->SetHeader(array(
585 array("string" => " "),
586 array("string" => _("System")." / "._("Department")),
587 array("string" => _("Actions"), "attach" => "style='border:none'" )));
590 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
591 $divlist->SetEntriesPerPage(20);
593 // Defining Links
594 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
596 foreach($this->departments as $key=> $val){
598 if(!isset($this->config->departments[trim($key)])){
599 $this->config->departments[trim($key)]="";
600 }
602 $non_empty="";
603 $keys= str_replace("/","\/",$key);
604 foreach($this->config->departments as $keyd=>$vald ){
605 if(preg_match("/".$keys."\/.*/",$keyd)){
606 $non_empty="full";
607 }
608 }
610 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
611 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
612 $field3 = array("string" => " ", "attach" => "style='border:none'");
613 $divlist->AddEntry(array($field1,$field2,$field3));
614 }
616 // Space
617 $empty =" ";
619 // User and Template Images
620 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
622 // Pictures for Extensions
623 $img1 = "<img src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
624 $img2 = "<img src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
625 $img3 = "<img src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
626 $img4 = "<img src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
627 $img5 = "<img src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
628 $img6 = "<img src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
629 $img7 = "<img src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
630 $img8 = "<img src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
631 $img9 = "<img src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
632 $img10 = "<img src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
634 // Test Every Entry and generate divlist Array
635 foreach($this->terminals as $key => $val){
636 // Specify Pics for Extensions
637 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
638 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
639 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
640 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
641 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
642 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
643 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
644 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
645 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
646 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
648 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
649 $pics = "";
650 // Generate Array to Add
651 if((isset($val['is_new']))&&(!empty($val['is_new']))){
652 $display= "".$val["cn"][0]." ".$val['is_new'];
653 }else{
654 $display= "".$val["cn"][0]."";
655 }
657 if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
658 $action2 = "<input type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
659 }else{
660 $action2 = "";
661 }
663 if(isset($val['message'])){
664 $display.= " (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."' )";
665 }
667 $img=$this->convert_list($val);
669 $field1 = array("string" => sprintf($img['img'],$val['dn']),"attach"=>"style='width:20px;align:middle;'");
670 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
671 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),"attach" => "style='border:none; text-align:right;width:48px'");
672 $divlist->AddEntry( array($field1,$field2,$field3));
673 }
675 /* Show main page */
676 $smarty->assign("terminalshead", $listhead);
677 $smarty->assign("terminals", $divlist->DrawList());
678 $smarty->assign("search_image", get_template_path('images/search.png'));
679 $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
680 $smarty->assign("tree_image", get_template_path('images/tree.png'));
681 $smarty->assign("infoimage", get_template_path('images/info.png'));
682 $smarty->assign("launchimage", get_template_path('images/launch.png'));
683 foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
684 "winstations", "printers", "phones", "netdev") as $type){
686 $smarty->assign("$type", $terminalfilter[$type]);
687 }
688 $smarty->assign("deplist", $this->config->idepartments);
690 /* Extend if we are not using javascript */
691 $smarty->assign("apply", apply_filter());
692 $smarty->assign("alphabet", generate_alphabet());
693 $smarty->assign("hint", print_sizelimit_warning());
695 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
696 }
699 function convert_list($input)
700 {
701 $temp= "";
702 $conv= array(
703 "D" => array("select_default.png",_("Template")),
704 "T" => array("select_terminal.png",_("Terminal")),
705 "L" => array("select_workstation.png",_("Workstation")),
706 "F" => array("select_phone.png",_("Phone")),
707 "S" => array("select_server.png",_("Server")),
708 "NT"=> array("select_new_terminal.png",_("New Terminal")),
709 "NL"=> array("select_new_workstation.png",_("New Workstation")),
710 "W" => array("select_winstation.png",_("Winstation")),
711 "C" => array("select_component.png",_("Network Device")),
712 "P" => array("select_printer.png",_("Printer")));
714 if((isset($input['is_new']))&&(!empty($input['is_new']))){
715 $input['type']="N".$input['type'];
716 }
717 foreach ($conv as $key => $value){
718 if($input['type']==$key){
719 $tmp['img'] ="<img src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
720 $tmp['class']=$key;
721 return $tmp;
722 }
723 }
724 }
726 function remove_from_parent()
727 {
728 /* Optionally execute a command after we're done */
729 $this->postremove();
730 }
733 /* Save data to object */
734 function save_object()
735 {
736 }
739 /* Check values */
740 function check()
741 {
742 }
745 /* Save to LDAP */
746 function save()
747 {
748 }
750 function adapt_from_template($dn)
751 {
752 }
754 function password_change_needed()
755 {
756 }
758 function show_header($button_text, $text, $disabled= FALSE)
759 {
760 }
762 function reload()
763 {
764 /* Load terminal shortcuts */
765 $responsible= array();
766 foreach ($this->config->departments as $key => $value){
767 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
768 "terminal", $value) == "#all#"){
769 $responsible[$key]= $value;
770 }
771 }
773 /* Get config */
774 $terminalfilter= get_global('terminalfilter');
775 $filter= "";
777 /* Set base for all searches */
778 $base= $terminalfilter['depselect'];
780 /* Regex filter? */
781 if ($terminalfilter['regex'] != ""){
782 $regex= $terminalfilter['regex'];
783 } else {
784 $regex= "*";
785 }
787 /* Get list of terminals to be shown */
788 if ($terminalfilter['thins'] == "checked"){
789 $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
790 } else {
791 $termfilter= "";
792 }
793 if ($terminalfilter['workstations'] == "checked"){
794 $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
795 } else {
796 $workfilter= "";
797 }
798 if ($terminalfilter['winstations'] == "checked"){
799 if ($this->config->current['SAMBAVERSION'] == "3"){
800 $samba= "sambaSamAccount";
801 } else {
802 $samba= "sambaAccount";
803 }
804 $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
805 } else {
806 $winfilter= "";
807 }
808 if ($terminalfilter['printers'] == "checked"){
809 $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
810 } else {
811 $printfilter= "";
812 }
813 if ($terminalfilter['phones'] == "checked"){
814 $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
815 } else {
816 $phonefilter= "";
817 }
818 if ($terminalfilter['netdev'] == "checked"){
819 $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
820 } else {
821 $netfilter= "";
822 }
823 if ($terminalfilter['servers'] == "checked"){
824 $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
825 } else {
826 $serverfilter= "";
827 }
829 /* User filter? */
830 if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
831 $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
832 }
834 /* Get all gotoTerminal's */
835 $this->terminals= array();
837 $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base,
838 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
840 $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base,
841 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
843 $res= array_merge($res,
844 get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base,
845 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
847 $res= array_merge($res,
848 get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base,
849 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
851 $res= array_merge($res,
852 get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base,
853 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
855 $res= array_merge($res,
856 get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base,
857 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
859 $res= array_merge($res,
860 get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,ou=systems,".$base,
861 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
863 $res= array_merge($res,
864 get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=incoming,".$base,
865 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
867 $res= array_merge($res,
868 get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base,
869 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
871 /* NEW LIST MANAGMENT
872 * We also need to search for the departments
873 * So we are able to navigate like in konquerer
874 */
875 $base2 = preg_replace("/ou=people,/i","",$base);
877 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
878 TRUE, $base2, array("ou", "description"), TRUE);
880 $this->departments= array();
881 $tmp = array();
882 foreach ($res3 as $value){
883 $tmp[strtolower($value['dn']).$value['dn']]=$value;
884 }
885 ksort($tmp);
886 foreach($tmp as $value){
887 if($value["description"][0]!=".."){
888 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
889 }else{
890 $this->departments[$value['dn']]=$value["description"][0];
891 }
892 }
894 /* END NEW LIST MANAGMENT
895 */
898 foreach ($res as $value){
900 /* Look for new terminals and mark them with '+' */
901 $tmp= "";
902 if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
903 $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
904 }
905 if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
906 $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
907 }
908 if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
909 $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
910 }
911 if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
912 $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
913 }
914 if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
915 $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
916 }
917 if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
918 $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
919 }
920 if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
921 $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
922 }
923 if ($tmp == ""){
924 $tmp= $value["dn"];
925 }
926 if (preg_match ("/,ou=incoming,/i", $tmp)){
927 if (in_array('gotoTerminal', $value['objectClass'])){
928 $add= "- "._("New terminal");
929 }
930 if (in_array('gotoWorkstation', $value['objectClass'])){
931 $add= "- "._("New workstation");
932 }
933 } else {
934 $add= "";
935 }
937 $terminal = array();
939 if (in_array ($tmp, $responsible) || $add != ""){
940 if (in_array('gotoTerminal', $value["objectClass"])){
941 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
942 $terminal = $value;
943 $terminal['type'] = "T";
944 $terminal['is_new'] = $add;
945 } else {
946 $terminal = $value;
947 $terminal['type'] = "D";
948 $terminal['message'] = _("Terminal template for");
949 $terminal['location'] = array_search($tmp, $this->config->departments);
950 }
951 } elseif (in_array('gotoWorkstation', $value["objectClass"])){
952 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
953 $terminal = $value;
954 $terminal['type'] = "L";
955 $terminal['is_new'] = $add;
956 } else {
957 $terminal = $value;
958 $terminal['type'] = "D";
959 $terminal['location'] = array_search($tmp, $this->config->departments);
960 $terminal['message'] = _("Workstation template for");
961 }
962 } elseif (in_array('gotoPrinter', $value["objectClass"])){
963 $terminal = $value;
964 $terminal['type'] = "P";
965 } elseif (in_array('goServer', $value["objectClass"])){
966 $terminal = $value;
967 $terminal['type'] = "S";
968 } elseif (in_array('goFonHardware', $value["objectClass"])){
969 $terminal = $value;
970 $terminal['type'] = "F";
971 } elseif (in_array('ieee802Device', $value["objectClass"])){
972 $terminal = $value;
973 $terminal['type'] = "C";
974 } else{
975 $name= preg_replace('/\$$/', '', $value['cn'][0]);
976 if (isset($value['sambaDomainName'])){
977 $domain= " [".$value['sambaDomainName'][0]."]";
978 } else {
979 $domain= "";
980 }
981 $terminal=$value;
982 $terminal['type'] ="W";
983 $terminal['domain'] = $name.$domain;
984 }
985 $this->terminals[]=$terminal;
986 }
987 }
989 $tmp=array();
990 foreach($this->terminals as $tkey => $val ){
991 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
992 }
993 ksort($tmp);
994 $this->terminals=array();
995 foreach($tmp as $val){
996 $this->terminals[]=$val;
997 }
998 reset ($this->terminals);
999 }
1001 function remove_lock()
1002 {
1003 if (isset($this->systab->dn)){
1004 del_lock ($this->systab->dn);
1005 }
1006 }
1009 function get_system_type($classes)
1010 {
1011 $type= "";
1013 if (in_array('ieee802Device', $classes)){
1014 $type= "component";
1015 }
1016 if (in_array('gotoTerminal', $classes)){
1017 $type= "terminal";
1018 }
1019 if (in_array('gotoWorkstation', $classes)){
1020 $type= "workstation";
1021 }
1022 if (in_array('gotoPrinter', $classes)){
1023 $type= "printer";
1024 }
1025 if (in_array('goFonHardware', $classes)){
1026 $type= "phone";
1027 }
1028 if (in_array('goServer', $classes)){
1029 $type= "server";
1030 }
1031 if (in_array('sambaAccount', $classes) ||
1032 in_array('sambaSamAccount', $classes)){
1033 $type= "winstation";
1034 }
1036 return ($type);
1037 }
1039 }
1041 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1042 ?>