83c0468ce4eb9a69a475df159519ac243fb1e2fc
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 break;
204 case 'workstation':
205 $this->systab= new worktabs($this->config,
206 $this->config->data['TABS']['WORKTABS'], $this->dn);
207 $this->systab->set_acl ($this->acl);
208 $this->systab->by_object['workgeneric']->cn= "wdefault";
209 $this->systab->by_object['termservice']->cn= "default";
210 break;
212 case 'server':
213 $this->systab= new servtabs($this->config,
214 $this->config->data['TABS']['SERVTABS'], $this->dn);
215 $this->systab->set_acl ($this->acl);
216 break;
218 case 'printer':
219 $this->systab= new printtabs($this->config,
220 $this->config->data['TABS']['PRINTTABS'], $this->dn);
221 $this->systab->set_acl ($this->acl);
222 break;
224 case 'phone':
225 $this->systab= new phonetabs($this->config,
226 $this->config->data['TABS']['PHONETABS'], $this->dn);
227 $this->systab->set_acl ($this->acl);
228 break;
230 case 'component':
231 $this->systab= new componenttabs($this->config,
232 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
233 $this->systab->set_acl ($this->acl);
234 break;
235 }
236 }
238 /* User wants to edit data? */
239 if ($s_action == "edit"){
241 /* Get 'dn' from posted 'cn', must be unique */
242 $this->dn= $this->terminals[$s_entry]['dn'];
244 /* Check locking, save current plugin in 'back_plugin', so
245 the dialog knows where to return. */
246 if (($user= get_lock($this->dn)) != ""){
247 return(gen_locked_message ($user, $this->dn));
248 }
250 /* Set up the users ACL's for this 'dn' */
251 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
253 /* Find out more about the object type */
254 $ldap= $this->config->get_ldap_link();
255 $ldap->cat($this->dn);
256 $attrs= $ldap->fetch();
257 $type= $this->get_system_type($attrs['objectClass']);
259 /* Lock the current entry, so everyone will get the
260 above dialog */
261 add_lock ($this->dn, $this->ui->dn);
263 switch ($type){
264 case "terminal":
265 /* Register systab to trigger edit dialog */
266 $this->systab= new termtabs($this->config,
267 $this->config->data['TABS']['TERMTABS'], $this->dn);
268 $this->systab->set_acl($acl);
269 $_SESSION['objectinfo']= $this->dn;
270 break;
272 case "server":
273 /* Register systab to trigger edit dialog */
274 $this->systab= new servtabs($this->config,
275 $this->config->data['TABS']['SERVTABS'], $this->dn);
276 $this->systab->set_acl($acl);
277 $_SESSION['objectinfo']= $this->dn;
278 break;
280 case "workstation":
281 /* Register systab to trigger edit dialog */
282 $this->systab= new worktabs($this->config,
283 $this->config->data['TABS']['WORKTABS'], $this->dn);
284 $this->systab->set_acl($acl);
285 $_SESSION['objectinfo']= $this->dn;
286 break;
288 case "printer":
289 /* Register systab to trigger edit dialog */
290 $this->systab= new printtabs($this->config,
291 $this->config->data['TABS']['PRINTTABS'], $this->dn);
292 $this->systab->set_acl($acl);
293 $_SESSION['objectinfo']= $this->dn;
294 break;
296 case "phone":
297 /* Register systab to trigger edit dialog */
298 $this->systab= new phonetabs($this->config,
299 $this->config->data['TABS']['PHONETABS'], $this->dn);
300 $this->systab->set_acl($acl);
301 $_SESSION['objectinfo']= $this->dn;
302 break;
304 case "component":
305 /* Register systab to trigger edit dialog */
306 $this->systab= new componenttabs($this->config,
307 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
308 $this->systab->set_acl($acl);
309 $_SESSION['objectinfo']= $this->dn;
310 break;
312 case "winstation":
313 /* Register systab to trigger edit dialog */
314 $this->systab= new wintabs($this->config,
315 $this->config->data['TABS']['WINTABS'], $this->dn);
316 $this->systab->set_acl($acl);
317 $_SESSION['objectinfo']= $this->dn;
318 break;
321 default:
322 print_red (_("You can't edit this object type yet!"));
323 del_lock($this->dn);
324 break;
325 }
326 }
328 /* Set terminals root password */
329 if ($s_action=="change_pw"){
330 $this->dn= $this->terminals[$s_entry]['dn'];
331 $_SESSION['objectinfo']= $this->dn;
332 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
333 }
335 /* Correctly specified? */
336 if (isset($_POST['password_finish'])){
337 if ($_POST['new_password'] != $_POST['repeated_password']){
338 print_red (_("Passwords entered as new and repeated do not match!"));
339 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
340 }
341 }
343 /* Change terminal password */
344 if (isset($_POST['password_finish']) &&
345 $_POST['new_password'] == $_POST['repeated_password']){
347 /* Check if user is allowed to set password */
348 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
349 $acl= get_module_permission($acl, "terminal", $this->dn);
350 if (chkacl($acl, "password") != ""){
351 print_red (_("You are not allowed to set this systems password!"));
352 } else {
353 $ldap= $this->config->get_ldap_link();
354 $ldap->cd($this->dn);
356 $attrs= array();
357 if ($_POST['new_password'] == ""){
358 $attrs['gotoRootPasswd']= array();
359 } else {
360 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
361 substr(session_id(),0,2));
362 }
363 $ldap->modify($attrs);
364 gosa_log ("Password for '".$this->dn."' has been changed");
365 }
366 unset($_SESSION['objectinfo']);
367 }
369 /* Delete terminal canceled? */
370 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
371 del_lock ($this->dn);
372 unset($_SESSION['objectinfo']);
373 }
375 /* Remove terminal was requested */
376 if ($s_action=="del"){
378 /* Get 'dn' from posted termlinst */
379 $this->dn= $this->terminals[$s_entry]['dn'];
381 /* Load permissions for selected 'dn' and check if
382 we're allowed to remove this 'dn' */
383 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
384 $this->acl= get_module_permission($acl, "terminal", $this->dn);
385 if (chkacl($this->acl, "delete") == ""){
387 /* Check locking, save current plugin in 'back_plugin', so
388 the dialog knows where to return. */
389 if (($user= get_lock($this->dn)) != ""){
390 return(gen_locked_message ($user, $this->dn));
391 }
393 /* Lock the current entry, so nobody will edit it during deletion */
394 add_lock ($this->dn, $this->ui->dn);
395 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
396 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
397 } else {
399 /* Obviously the user isn't allowed to delete. Show message and
400 clean session. */
401 print_red (_("You are not allowed to delete this component!"));
402 }
403 }
405 /* Confirmation for deletion has been passed. Terminal should be deleted. */
406 if (isset($_POST['delete_terminal_confirm'])){
408 /* Some nice guy may send this as POST, so we've to check
409 for the permissions again. */
410 if (chkacl($this->acl, "delete") == ""){
412 /* Find out more about the object type */
413 $ldap= $this->config->get_ldap_link();
414 $ldap->cat($this->dn);
415 $attrs= $ldap->fetch();
416 $type= $this->get_system_type($attrs['objectClass']);
418 switch ($type){
419 case "terminal":
420 $tabtype= "termtabs";
421 break;
423 case "workstation":
424 $tabtype= "worktabs";
425 break;
427 case "phone":
428 $tabtype= "phonetabs";
429 break;
431 case "server":
432 $tabtype= "servtabs";
433 break;
435 default:
436 #print_red (_("You can't remove this object type yet!"));
437 #del_lock($this->dn);
438 #return;
439 $tabtype= "termtabs";
440 break;
441 }
443 /* Delete request is permitted, perform LDAP action */
444 if($tabtype=="phonetabs"){
445 $this->systab= new $tabtype($this->config,
446 $this->config->data['TABS']['PHONETABS'], $this->dn);
447 $this->systab->set_acl(array($this->acl));
448 $this->systab->by_object['phonegeneric']->remove_from_parent ();
449 }else{
450 $this->systab= new $tabtype($this->config,
451 $this->config->data['TABS']['TERMTABS'], $this->dn);
452 $this->systab->set_acl(array($this->acl));
453 $this->systab->by_object['termgeneric']->remove_from_parent ();
454 }
455 unset ($this->systab);
456 gosa_log ("System object'".$this->dn."' has been removed");
457 $this->systab= NULL;
459 /* Terminal list has changed, reload it. */
460 $this->reload ();
461 } else {
463 /* Normally this shouldn't be reached, send some extra
464 logs to notify the administrator */
465 print_red (_("You are not allowed to delete this component!"));
466 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
467 "deletion.");
468 }
470 /* Remove lock file after successfull deletion */
471 del_lock ($this->dn);
472 }
474 /* Finish user edit is triggered by the tabulator dialog, so
475 the user wants to save edited data. Check and save at this
476 point. */
477 if (isset($_POST['edit_finish'])){
479 /* Check tabs, will feed message array */
480 $message= $this->systab->check();
482 /* Save, or display error message? */
483 if (count($message) == 0){
485 /* Save terminal data to ldap */
486 gosa_log ("System object'".$this->dn."' has been saved");
487 $this->systab->save();
489 /* Terminal has been saved successfully, remove lock from
490 LDAP. */
491 if ($this->dn != "new"){
492 del_lock ($this->dn);
493 }
495 /* There's no page reload so we have to read new terminals at
496 this point. */
497 $this->reload ();
498 unset ($this->systab);
499 $this->systab= NULL;
500 unset($_SESSION['objectinfo']);
502 } else {
503 /* Ok. There seem to be errors regarding to the tab data,
504 show message and continue as usual. */
505 show_errors($message);
506 }
508 }
510 /* Cancel dialogs */
511 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
512 if (isset($this->systab)){
513 del_lock ($this->systab->dn);
514 unset ($this->systab);
515 }
516 $this->systab= NULL;
517 unset($_SESSION['objectinfo']);
518 }
520 /* Show tab dialog if object is present */
521 if ($this->systab){
522 $display= $this->systab->execute();
524 /* Don't show buttons if tab dialog requests this */
525 if (!$this->systab->by_object[$this->systab->current]->dialog){
526 $display.= "<p style=\"text-align:right\">\n";
527 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
528 $display.= " \n";
529 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
530 $display.= "</p>";
531 }
532 return ($display);
533 }
540 /* Prepare departments */
541 $options= "";
542 foreach ($this->config->idepartments as $key => $value){
543 if ($terminalfilter['depselect'] == $key){
544 $options.= "<option selected value='$key'>$value</option>";
545 } else {
546 $options.= "<option value='$key'>$value</option>";
547 }
548 }
551 /* NEW LIST MANAGMENT */
552 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
553 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
554 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
555 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
556 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
557 " <input type='image' align='middle' src='images/select_new_terminal.png' name='newsystem_terminal' alt='"._("New Terminal")."' title='"._("New Terminal")."'>".
558 " <input type='image' align='middle' src='images/select_new_workstation.png' name='newsystem_workstation' alt='"._("New Workstation")."' title='"._("New Workstation")."'>".
559 " <input type='image' align='middle' src='images/select_new_server.png' name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'>".
560 " <input type='image' align='middle' src='images/select_new_printer.png' name='newsystem_printer' alt='"._("New Printer")."' title='"._("New Printer")."'>".
561 " <input type='image' align='middle' src='images/select_new_phone.png' name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'>".
562 " <input type='image' align='middle' src='images/select_new_component.png' name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'>".
563 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
564 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
565 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
566 "</div>";
570 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
571 $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
574 $divlist = new divlist("systemstab");
575 $divlist->SetHeader(array(
576 array("string" => " "),
577 array("string" => _("System")." / "._("Department")),
578 array("string" => _("Actions"), "attach" => "style='border:none'" )));
581 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
582 $divlist->SetEntriesPerPage(20);
584 // Defining Links
585 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
587 foreach($this->departments as $key=> $val){
589 if(!isset($this->config->departments[trim($key)])){
590 $this->config->departments[trim($key)]="";
591 }
593 $non_empty="";
594 $keys= str_replace("/","\/",$key);
595 foreach($this->config->departments as $keyd=>$vald ){
596 if(preg_match("/".$keys."\/.*/",$keyd)){
597 $non_empty="full";
598 }
599 }
601 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
602 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
603 $field3 = array("string" => " ", "attach" => "style='border:none'");
604 $divlist->AddEntry(array($field1,$field2,$field3));
605 }
607 // Space
608 $empty =" ";
610 // User and Template Images
611 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
613 // Pictures for Extensions
614 $img1 = "<img src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
615 $img2 = "<img src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
616 $img3 = "<img src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
617 $img4 = "<img src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
618 $img5 = "<img src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
619 $img6 = "<img src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
620 $img7 = "<img src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
621 $img8 = "<img src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
622 $img9 = "<img src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
623 $img10 = "<img src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
625 // Test Every Entry and generate divlist Array
626 foreach($this->terminals as $key => $val){
627 // Specify Pics for Extensions
628 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
629 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
630 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
631 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
632 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
633 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
634 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
635 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
636 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
637 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
639 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
640 $pics = "";
641 // Generate Array to Add
642 if((isset($val['is_new']))&&(!empty($val['is_new']))){
643 $display= "".$val["cn"][0]." ".$val['is_new'];
644 }else{
645 $display= "".$val["cn"][0]."";
646 }
648 if(in_array("gotoTerminal",$val['objectClass'])){
649 $action2 = "<input type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
650 }else{
651 $action2 = "";
652 }
655 if(isset($val['message'])){
656 $display.= " (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."' )";
657 }
659 $img=$this->convert_list($val);
661 $field1 = array("string" => sprintf($img['img'],$val['dn']),"attach"=>"style='width:20px;align:middle;'");
662 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
663 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),"attach" => "style='border:none; text-align:right;width:48px'");
664 $divlist->AddEntry( array($field1,$field2,$field3));
665 }
671 /* Show main page */
672 $smarty->assign("terminalshead", $listhead);
673 $smarty->assign("terminals", $divlist->DrawList());
674 $smarty->assign("search_image", get_template_path('images/search.png'));
675 $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
676 $smarty->assign("tree_image", get_template_path('images/tree.png'));
677 $smarty->assign("infoimage", get_template_path('images/info.png'));
678 $smarty->assign("launchimage", get_template_path('images/launch.png'));
679 foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
680 "winstations", "printers", "phones", "netdev") as $type){
682 $smarty->assign("$type", $terminalfilter[$type]);
683 }
684 $smarty->assign("deplist", $this->config->idepartments);
686 /* Extend if we are not using javascript */
687 $smarty->assign("apply", apply_filter());
688 $smarty->assign("alphabet", generate_alphabet());
689 $smarty->assign("hint", print_sizelimit_warning());
691 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
692 }
695 function convert_list($input)
696 {
697 $temp= "";
698 $conv= array(
699 "D" => array("select_default.png",_("Template")),
700 "T" => array("select_terminal.png",_("Terminal")),
701 "L" => array("select_workstation.png",_("Workstation")),
702 "F" => array("select_phone.png",_("Phone")),
703 "S" => array("select_server.png",_("Server")),
704 "NT"=> array("select_new_terminal.png",_("New Terminal")),
705 "NL"=> array("select_new_workstation.png",_("New Workstation")),
706 "W" => array("select_winstation.png",_("Winstation")),
707 "C" => array("select_component.png",_("Network Device")),
708 "P" => array("select_printer.png",_("Printer")));
710 if((isset($input['is_new']))&&(!empty($input['is_new']))){
711 $input['type']="N".$input['type'];
712 }
713 foreach ($conv as $key => $value){
714 if($input['type']==$key){
715 $tmp['img'] ="<img src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
716 $tmp['class']=$key;
717 return $tmp;
718 }
719 }
720 }
722 function remove_from_parent()
723 {
724 /* Optionally execute a command after we're done */
725 $this->postremove();
726 }
729 /* Save data to object */
730 function save_object()
731 {
732 }
735 /* Check values */
736 function check()
737 {
738 }
741 /* Save to LDAP */
742 function save()
743 {
744 }
746 function adapt_from_template($dn)
747 {
748 }
750 function password_change_needed()
751 {
752 }
754 function show_header($button_text, $text, $disabled= FALSE)
755 {
756 }
758 function reload()
759 {
760 /* Load terminal shortcuts */
761 $responsible= array();
762 foreach ($this->config->departments as $key => $value){
763 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
764 "terminal", $value) == "#all#"){
765 $responsible[$key]= $value;
766 }
767 }
769 /* Get config */
770 $terminalfilter= get_global('terminalfilter');
771 $filter= "";
773 /* Set base for all searches */
774 $base= $terminalfilter['depselect'];
776 /* Regex filter? */
777 if ($terminalfilter['regex'] != ""){
778 $regex= $terminalfilter['regex'];
779 } else {
780 $regex= "*";
781 }
783 /* Get list of terminals to be shown */
784 if ($terminalfilter['thins'] == "checked"){
785 $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
786 } else {
787 $termfilter= "";
788 }
789 if ($terminalfilter['workstations'] == "checked"){
790 $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
791 } else {
792 $workfilter= "";
793 }
794 if ($terminalfilter['winstations'] == "checked"){
795 if ($this->config->current['SAMBAVERSION'] == "3"){
796 $samba= "sambaSamAccount";
797 } else {
798 $samba= "sambaAccount";
799 }
800 $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
801 } else {
802 $winfilter= "";
803 }
804 if ($terminalfilter['printers'] == "checked"){
805 $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
806 } else {
807 $printfilter= "";
808 }
809 if ($terminalfilter['phones'] == "checked"){
810 $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
811 } else {
812 $phonefilter= "";
813 }
814 if ($terminalfilter['netdev'] == "checked"){
815 $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
816 } else {
817 $netfilter= "";
818 }
819 if ($terminalfilter['servers'] == "checked"){
820 $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
821 } else {
822 $serverfilter= "";
823 }
825 /* User filter? */
826 if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
827 $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
828 }
830 /* Get all gotoTerminal's */
831 $this->terminals= array();
833 $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base,
834 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
836 $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base,
837 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
839 $res= array_merge($res,
840 get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base,
841 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
843 $res= array_merge($res,
844 get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base,
845 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
847 $res= array_merge($res,
848 get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base,
849 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
851 $res= array_merge($res,
852 get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base,
853 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
855 $res= array_merge($res,
856 get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,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=incoming,".$base,
861 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
863 $res= array_merge($res,
864 get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base,
865 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
867 /* NEW LIST MANAGMENT
868 * We also need to search for the departments
869 * So we are able to navigate like in konquerer
870 */
871 $base2 = preg_replace("/ou=people,/i","",$base);
873 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
874 TRUE, $base2, array("ou", "description"), TRUE);
876 $this->departments= array();
877 $tmp = array();
878 foreach ($res3 as $value){
879 $tmp[strtolower($value['dn']).$value['dn']]=$value;
880 }
881 ksort($tmp);
882 foreach($tmp as $value){
883 if($value["description"][0]!=".."){
884 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
885 }else{
886 $this->departments[$value['dn']]=$value["description"][0];
887 }
888 }
890 /* END NEW LIST MANAGMENT
891 */
894 foreach ($res as $value){
896 /* Look for new terminals and mark them with '+' */
897 $tmp= "";
898 if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
899 $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
900 }
901 if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
902 $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
903 }
904 if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
905 $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
906 }
907 if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
908 $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
909 }
910 if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
911 $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
912 }
913 if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
914 $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
915 }
916 if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
917 $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
918 }
919 if ($tmp == ""){
920 $tmp= $value["dn"];
921 }
922 if (preg_match ("/,ou=incoming,/i", $tmp)){
923 if (in_array('gotoTerminal', $value['objectClass'])){
924 $add= "- "._("New terminal");
925 }
926 if (in_array('gotoWorkstation', $value['objectClass'])){
927 $add= "- "._("New workstation");
928 }
929 } else {
930 $add= "";
931 }
933 $terminal = array();
935 if (in_array ($tmp, $responsible) || $add != ""){
936 if (in_array('gotoTerminal', $value["objectClass"])){
937 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
938 $terminal = $value;
939 $terminal['type'] = "T";
940 $terminal['is_new'] = $add;
941 } else {
942 $terminal = $value;
943 $terminal['type'] = "D";
944 $terminal['message'] = _("Terminal template for");
945 $terminal['location'] = array_search($tmp, $this->config->departments);
946 }
947 } elseif (in_array('gotoWorkstation', $value["objectClass"])){
948 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
949 $terminal = $value;
950 $terminal['type'] = "L";
951 $terminal['is_new'] = $add;
952 } else {
953 $terminal = $value;
954 $terminal['type'] = "D";
955 $terminal['location'] = array_search($tmp, $this->config->departments);
956 $terminal['message'] = _("Workstation template for");
957 }
958 } elseif (in_array('gotoPrinter', $value["objectClass"])){
959 $terminal = $value;
960 $terminal['type'] = "P";
961 } elseif (in_array('goServer', $value["objectClass"])){
962 $terminal = $value;
963 $terminal['type'] = "S";
964 } elseif (in_array('goFonHardware', $value["objectClass"])){
965 $terminal = $value;
966 $terminal['type'] = "F";
967 } elseif (in_array('ieee802Device', $value["objectClass"])){
968 $terminal = $value;
969 $terminal['type'] = "C";
970 } else{
971 $name= preg_replace('/\$$/', '', $value['cn'][0]);
972 if (isset($value['sambaDomainName'])){
973 $domain= " [".$value['sambaDomainName'][0]."]";
974 } else {
975 $domain= "";
976 }
977 $terminal=$value;
978 $terminal['type'] ="W";
979 $terminal['domain'] = $name.$domain;
980 }
981 $this->terminals[]=$terminal;
982 }
983 }
985 $tmp=array();
986 foreach($this->terminals as $tkey => $val ){
987 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
988 }
989 ksort($tmp);
990 $this->terminals=array();
991 foreach($tmp as $val){
992 $this->terminals[]=$val;
993 }
994 reset ($this->terminals);
995 }
997 function remove_lock()
998 {
999 if (isset($this->systab->dn)){
1000 del_lock ($this->systab->dn);
1001 }
1002 }
1005 function get_system_type($classes)
1006 {
1007 $type= "";
1009 if (in_array('ieee802Device', $classes)){
1010 $type= "component";
1011 }
1012 if (in_array('gotoTerminal', $classes)){
1013 $type= "terminal";
1014 }
1015 if (in_array('gotoWorkstation', $classes)){
1016 $type= "workstation";
1017 }
1018 if (in_array('gotoPrinter', $classes)){
1019 $type= "printer";
1020 }
1021 if (in_array('goFonHardware', $classes)){
1022 $type= "phone";
1023 }
1024 if (in_array('goServer', $classes)){
1025 $type= "server";
1026 }
1027 if (in_array('sambaAccount', $classes) ||
1028 in_array('sambaSamAccount', $classes)){
1029 $type= "winstation";
1030 }
1032 return ($type);
1033 }
1035 }
1037 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1038 ?>