6efa50af39b2dfa034c1f719944dbe153cfc0431
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 $terminalfilter = get_global("terminalfilter"); // contains Filter Settings
94 $s_action = ""; // Contains the action to proceed
95 $s_entry = ""; // The value for s_action
96 $base_back = ""; // The Link for Backbutton
97 $smarty = get_smarty();
99 /* Start for New List Managment */
100 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
101 $s_action="open";
102 $s_entry = base64_decode($_GET['dep_id']);
103 $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
104 $this->reload();
105 }
107 /* Test Posts */
108 foreach($_POST as $key => $val){
109 // Post for delete
110 if(preg_match("/user_del.*/",$key)){
111 $s_action = "del";
112 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
113 // Post for edit
114 }elseif(preg_match("/user_edit_.*/",$key)){
115 $s_action="edit";
116 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
117 // Post for new
118 }elseif(preg_match("/dep_back.*/i",$key)){
119 $s_action="back";
120 }elseif(preg_match("/user_new.*/",$key)){
121 $s_action="new";
122 }elseif(preg_match("/dep_home.*/i",$key)){
123 $s_action="home";
124 }elseif(preg_match("/user_tplnew.*/i",$key)){
125 $s_action="new_tpl";
126 }elseif(preg_match("/user_setpwd_.*/i",$key)){
127 $s_action="change_pw";
128 $s_entry = preg_replace("/user_setpwd_/i","",$key);
129 }elseif(preg_match("/dep_root.*/i",$key)){
130 $s_action="root";
131 }elseif(preg_match("/newsystem_.*/i",$key)){
132 $s_action="newsystem";
133 $s_entry = preg_replace("/newsystem_/i","",$key);
134 }
135 }
137 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
138 $s_action ="edit";
139 $s_entry = $_GET['id'];
140 }
142 $s_entry = preg_replace("/_.$/","",$s_entry);
144 /* Department changed? */
145 if(isset($_POST['depselect']) && $_POST['depselect']){
146 $terminalfilter['depselect']= $_POST['depselect'];
147 }
149 /* Homebutton is posted */
150 if($s_action=="home"){
151 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
152 $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
153 }
155 if($s_action=="root"){
156 $terminalfilter['depselect']=($this->config->current['BASE']);
157 }
160 /* If Backbutton is Posted */
161 if($s_action=="back"){
162 $base_back = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
163 $base_back = convert_department_dn($base_back);
165 if(isset($this->config->departments[trim($base_back)])){
166 $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
167 }else{
168 $terminalfilter['depselect']= $this->config->departments["/"];
169 }
170 }
172 register_global("terminalfilter", $terminalfilter);
173 $this->reload();
175 /* Check for exeeded sizelimit */
176 if (($message= check_sizelimit()) != ""){
177 return($message);
178 }
180 /* Try to get informations about what kind of system to create */
181 if ($s_action=="new") {
182 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
183 }
185 /* Create new default terminal */
186 if (isset($_POST['create_system'])||$s_action=="newsystem") {
187 $this->dn= "new";
188 $this->acl= array(":all");
190 if(isset($_POST['system'])){
191 $sw = $_POST['system'];
192 }else{
193 $sw = $s_entry;
194 }
196 switch ($sw){
197 case 'terminal':
198 $this->systab= new termtabs($this->config,
199 $this->config->data['TABS']['TERMTABS'], $this->dn);
200 $this->systab->set_acl ($this->acl);
201 $this->systab->by_object['termgeneric']->cn= "default";
202 $this->systab->by_object['termservice']->cn= "default";
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['termservice']->cn= "default";
211 break;
213 case 'server':
214 $this->systab= new servtabs($this->config,
215 $this->config->data['TABS']['SERVTABS'], $this->dn);
216 $this->systab->set_acl ($this->acl);
217 break;
219 case 'printer':
220 $this->systab= new printtabs($this->config,
221 $this->config->data['TABS']['PRINTTABS'], $this->dn);
222 $this->systab->set_acl ($this->acl);
223 break;
225 case 'phone':
226 $this->systab= new phonetabs($this->config,
227 $this->config->data['TABS']['PHONETABS'], $this->dn);
228 $this->systab->set_acl ($this->acl);
229 break;
231 case 'component':
232 $this->systab= new componenttabs($this->config,
233 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
234 $this->systab->set_acl ($this->acl);
235 break;
236 }
237 }
239 /* User wants to edit data? */
240 if ($s_action == "edit"){
242 /* Get 'dn' from posted 'cn', must be unique */
243 $this->dn= $this->terminals[$s_entry]['dn'];
245 /* Check locking, save current plugin in 'back_plugin', so
246 the dialog knows where to return. */
247 if (($user= get_lock($this->dn)) != ""){
248 return(gen_locked_message ($user, $this->dn));
249 }
251 /* Set up the users ACL's for this 'dn' */
252 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
254 /* Find out more about the object type */
255 $ldap= $this->config->get_ldap_link();
256 $ldap->cat($this->dn);
257 $attrs= $ldap->fetch();
258 $type= $this->get_system_type($attrs['objectClass']);
260 /* Lock the current entry, so everyone will get the
261 above dialog */
262 add_lock ($this->dn, $this->ui->dn);
264 switch ($type){
265 case "terminal":
266 /* Register systab to trigger edit dialog */
267 $this->systab= new termtabs($this->config,
268 $this->config->data['TABS']['TERMTABS'], $this->dn);
269 $this->systab->set_acl($acl);
270 $_SESSION['objectinfo']= $this->dn;
271 break;
273 case "server":
274 /* Register systab to trigger edit dialog */
275 $this->systab= new servtabs($this->config,
276 $this->config->data['TABS']['SERVTABS'], $this->dn);
277 $this->systab->set_acl($acl);
278 $_SESSION['objectinfo']= $this->dn;
279 break;
281 case "workstation":
282 /* Register systab to trigger edit dialog */
283 $this->systab= new worktabs($this->config,
284 $this->config->data['TABS']['WORKTABS'], $this->dn);
285 $this->systab->set_acl($acl);
286 $_SESSION['objectinfo']= $this->dn;
287 break;
289 case "printer":
290 /* Register systab to trigger edit dialog */
291 $this->systab= new printtabs($this->config,
292 $this->config->data['TABS']['PRINTTABS'], $this->dn);
293 $this->systab->set_acl($acl);
294 $_SESSION['objectinfo']= $this->dn;
295 break;
297 case "phone":
298 /* Register systab to trigger edit dialog */
299 $this->systab= new phonetabs($this->config,
300 $this->config->data['TABS']['PHONETABS'], $this->dn);
301 $this->systab->set_acl($acl);
302 $_SESSION['objectinfo']= $this->dn;
303 break;
305 case "component":
306 /* Register systab to trigger edit dialog */
307 $this->systab= new componenttabs($this->config,
308 $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
309 $this->systab->set_acl($acl);
310 $_SESSION['objectinfo']= $this->dn;
311 break;
313 case "winstation":
314 /* Register systab to trigger edit dialog */
315 $this->systab= new wintabs($this->config,
316 $this->config->data['TABS']['WINTABS'], $this->dn);
317 $this->systab->set_acl($acl);
318 $_SESSION['objectinfo']= $this->dn;
319 break;
322 default:
323 print_red (_("You can't edit this object type yet!"));
324 del_lock($this->dn);
325 break;
326 }
327 }
329 /* Set terminals root password */
330 if ($s_action=="change_pw"){
331 $this->dn= $this->terminals[$s_entry]['dn'];
332 $_SESSION['objectinfo']= $this->dn;
333 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
334 }
336 /* Correctly specified? */
337 if (isset($_POST['password_finish'])){
338 if ($_POST['new_password'] != $_POST['repeated_password']){
339 print_red (_("Passwords entered as new and repeated do not match!"));
340 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
341 }
342 }
344 /* Change terminal password */
345 if (isset($_POST['password_finish']) &&
346 $_POST['new_password'] == $_POST['repeated_password']){
348 /* Check if user is allowed to set password */
349 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
350 $acl= get_module_permission($acl, "terminal", $this->dn);
351 if (chkacl($acl, "password") != ""){
352 print_red (_("You are not allowed to set this systems password!"));
353 } else {
354 $ldap= $this->config->get_ldap_link();
355 $ldap->cd($this->dn);
357 $attrs= array();
358 if ($_POST['new_password'] == ""){
359 $attrs['gotoRootPasswd']= array();
360 } else {
361 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
362 substr(session_id(),0,2));
363 }
364 $ldap->modify($attrs);
365 gosa_log ("Password for '".$this->dn."' has been changed");
366 }
367 unset($_SESSION['objectinfo']);
368 }
370 /* Delete terminal canceled? */
371 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
372 del_lock ($this->dn);
373 unset($_SESSION['objectinfo']);
374 }
376 /* Remove terminal was requested */
377 if ($s_action=="del"){
379 /* Get 'dn' from posted termlinst */
380 $this->dn= $this->terminals[$s_entry]['dn'];
382 /* Load permissions for selected 'dn' and check if
383 we're allowed to remove this 'dn' */
384 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
385 $this->acl= get_module_permission($acl, "terminal", $this->dn);
386 if (chkacl($this->acl, "delete") == ""){
388 /* Check locking, save current plugin in 'back_plugin', so
389 the dialog knows where to return. */
390 if (($user= get_lock($this->dn)) != ""){
391 return(gen_locked_message ($user, $this->dn));
392 }
394 /* Lock the current entry, so nobody will edit it during deletion */
395 add_lock ($this->dn, $this->ui->dn);
396 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
397 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
398 } else {
400 /* Obviously the user isn't allowed to delete. Show message and
401 clean session. */
402 print_red (_("You are not allowed to delete this component!"));
403 }
404 }
406 /* Confirmation for deletion has been passed. Terminal should be deleted. */
407 if (isset($_POST['delete_terminal_confirm'])){
409 /* Some nice guy may send this as POST, so we've to check
410 for the permissions again. */
411 if (chkacl($this->acl, "delete") == ""){
413 /* Find out more about the object type */
414 $ldap= $this->config->get_ldap_link();
415 $ldap->cat($this->dn);
416 $attrs= $ldap->fetch();
417 $type= $this->get_system_type($attrs['objectClass']);
419 switch ($type){
420 case "terminal":
421 $tabtype= "termtabs";
422 break;
424 case "workstation":
425 $tabtype= "worktabs";
426 break;
428 case "server":
429 $tabtype= "servtabs";
430 break;
432 default:
433 #print_red (_("You can't remove this object type yet!"));
434 #del_lock($this->dn);
435 #return;
436 $tabtype= "termtabs";
437 break;
438 }
440 /* Delete request is permitted, perform LDAP action */
441 $this->systab= new $tabtype($this->config,
442 $this->config->data['TABS']['TERMTABS'], $this->dn);
443 $this->systab->set_acl(array($this->acl));
444 $this->systab->by_object['termgeneric']->remove_from_parent ();
445 unset ($this->systab);
446 gosa_log ("System object'".$this->dn."' has been removed");
447 $this->systab= NULL;
449 /* Terminal list has changed, reload it. */
450 $this->reload ();
451 } else {
453 /* Normally this shouldn't be reached, send some extra
454 logs to notify the administrator */
455 print_red (_("You are not allowed to delete this component!"));
456 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
457 "deletion.");
458 }
460 /* Remove lock file after successfull deletion */
461 del_lock ($this->dn);
462 }
464 /* Finish user edit is triggered by the tabulator dialog, so
465 the user wants to save edited data. Check and save at this
466 point. */
467 if (isset($_POST['edit_finish'])){
469 /* Check tabs, will feed message array */
470 $message= $this->systab->check();
472 /* Save, or display error message? */
473 if (count($message) == 0){
475 /* Save terminal data to ldap */
476 gosa_log ("System object'".$this->dn."' has been saved");
477 $this->systab->save();
479 /* Terminal has been saved successfully, remove lock from
480 LDAP. */
481 if ($this->dn != "new"){
482 del_lock ($this->dn);
483 }
485 /* There's no page reload so we have to read new terminals at
486 this point. */
487 $this->reload ();
488 unset ($this->systab);
489 $this->systab= NULL;
490 unset($_SESSION['objectinfo']);
492 } else {
493 /* Ok. There seem to be errors regarding to the tab data,
494 show message and continue as usual. */
495 show_errors($message);
496 }
498 }
500 /* Cancel dialogs */
501 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
502 if (isset($this->systab)){
503 del_lock ($this->systab->dn);
504 unset ($this->systab);
505 }
506 $this->systab= NULL;
507 unset($_SESSION['objectinfo']);
508 }
510 /* Show tab dialog if object is present */
511 if ($this->systab){
512 $display= $this->systab->execute();
514 /* Don't show buttons if tab dialog requests this */
515 if (!$this->systab->by_object[$this->systab->current]->dialog){
516 $display.= "<p style=\"text-align:right\">\n";
517 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
518 $display.= " \n";
519 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
520 $display.= "</p>";
521 }
522 return ($display);
523 }
530 /* Prepare departments */
531 $options= "";
532 foreach ($this->config->idepartments as $key => $value){
533 if ($terminalfilter['depselect'] == $key){
534 $options.= "<option selected value='$key'>$value</option>";
535 } else {
536 $options.= "<option value='$key'>$value</option>";
537 }
538 }
541 /* NEW LIST MANAGMENT */
542 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
543 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
544 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
545 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
546 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
547 " <input type='image' align='middle' src='images/select_terminal.png' name='newsystem_terminal' alt='"._("New Terminal")."' title='"._("New Terminal")."'>".
548 " <input type='image' align='middle' src='images/select_winstation.png' name='newsystem_workstation' alt='"._("New Workstation")."' title='"._("New Workstation")."'>".
549 " <input type='image' align='middle' src='images/select_server.png' name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'>".
550 " <input type='image' align='middle' src='images/select_printer.png' name='newsystem_printer' alt='"._("New Printer")."' title='"._("New Printer")."'>".
551 " <input type='image' align='middle' src='images/select_phone.png' name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'>".
552 " <input type='image' align='middle' src='images/select_component.png' name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'>".
553 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
554 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new system")."' alt='"._("New system")."' name='user_new'> ".
555 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
556 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
557 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
558 "</div>";
562 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
563 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
566 $divlist = new divlist("systemstab");
567 $divlist->SetHeader(array(
568 array("string" => " "),
569 array("string" => _("System")." / "._("Department")),
570 array("string" => _("Actions"), "attach" => "style='border:none'" )));
573 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
574 $divlist->SetEntriesPerPage(20);
576 // Defining Links
577 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
579 foreach($this->departments as $key=> $val){
581 if(!isset($this->config->departments[trim($key)])){
582 $this->config->departments[trim($key)]="";
583 }
585 $non_empty="";
586 $keys= str_replace("/","\/",$key);
587 foreach($this->config->departments as $keyd=>$vald ){
588 if(preg_match("/".$keys."\/.*/",$keyd)){
589 $non_empty="full";
590 }
591 }
593 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
594 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
595 $field3 = array("string" => " ", "attach" => "style='border:none'");
596 $divlist->AddEntry(array($field1,$field2,$field3));
597 }
599 // Space
600 $empty =" ";
602 // User and Template Images
603 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
605 // Pictures for Extensions
606 $img1 = "<img src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
607 $img2 = "<img src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
608 $img3 = "<img src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
609 $img4 = "<img src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
610 $img5 = "<img src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
611 $img6 = "<img src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
612 $img7 = "<img src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
613 $img8 = "<img src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
614 $img9 = "<img src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
615 $img10 = "<img src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
617 // Test Every Entry and generate divlist Array
618 foreach($this->terminals as $key => $val){
619 // Specify Pics for Extensions
620 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
621 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
622 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
623 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
624 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
625 if(in_array("goNfsServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
626 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
627 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
628 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
629 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
631 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
632 $pics = "";
633 // Generate Array to Add
634 if((isset($val['is_new']))&&(!empty($val['is_new']))){
635 $display= "".$val["cn"][0]." ".$val['is_new'];
636 }else{
637 $display= "".$val["cn"][0]."";
638 }
640 if(in_array("gotoTerminal",$val['objectClass'])){
641 $action2 = "<input type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
642 }else{
643 $action2 = "";
644 }
647 if(isset($val['message'])){
648 $display.= " (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."' )";
649 }
651 $img=$this->convert_list($val);
653 $field1 = array("string" => sprintf($img['img'],$val['dn']),"attach"=>"style='width:20px;align:middle;'");
654 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
655 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),"attach" => "style='border:none; text-align:right;width:48px'");
656 $divlist->AddEntry( array($field1,$field2,$field3));
657 }
663 /* Show main page */
664 $smarty->assign("terminalshead", $listhead);
665 $smarty->assign("terminals", $divlist->DrawList());
666 $smarty->assign("search_image", get_template_path('images/search.png'));
667 $smarty->assign("tree_image", get_template_path('images/tree.png'));
668 $smarty->assign("infoimage", get_template_path('images/info.png'));
669 $smarty->assign("launchimage", get_template_path('images/launch.png'));
670 foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
671 "winstations", "printers", "phones", "netdev") as $type){
673 $smarty->assign("$type", $terminalfilter[$type]);
674 }
675 $smarty->assign("deplist", $this->config->idepartments);
677 /* Extend if we are not using javascript */
678 $smarty->assign("apply", apply_filter());
679 $smarty->assign("alphabet", generate_alphabet());
680 $smarty->assign("hint", print_sizelimit_warning());
682 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
683 }
686 function convert_list($input)
687 {
688 $temp= "";
689 $conv= array(
690 "D" => array("select_default.png",_("Template")),
691 "T" => array("select_terminal.png",_("Terminal")),
692 "L" => array("select_workstation.png",_("Workstation")),
693 "F" => array("select_phone.png",_("Phone")),
694 "S" => array("select_server.png",_("Server")),
695 "NT"=> array("select_new_terminal.png",_("New Terminal")),
696 "NL"=> array("select_new_workstation.png",_("New Workstation")),
697 "W" => array("select_winstation.png",_("Winstation")),
698 "C" => array("select_component.png",_("Network Device")),
699 "P" => array("select_printer.png",_("Printer")));
701 if((isset($input['is_new']))&&(!empty($input['is_new']))){
702 $input['type']="N".$input['type'];
703 }
704 foreach ($conv as $key => $value){
705 if($input['type']==$key){
706 $tmp['img'] ="<img src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
707 $tmp['class']=$key;
708 return $tmp;
709 }
710 }
711 }
713 function remove_from_parent()
714 {
715 /* Optionally execute a command after we're done */
716 $this->postremove();
717 }
720 /* Save data to object */
721 function save_object()
722 {
723 }
726 /* Check values */
727 function check()
728 {
729 }
732 /* Save to LDAP */
733 function save()
734 {
735 }
737 function adapt_from_template($dn)
738 {
739 }
741 function password_change_needed()
742 {
743 }
745 function show_header($button_text, $text, $disabled= FALSE)
746 {
747 }
749 function reload()
750 {
751 /* Load terminal shortcuts */
752 $responsible= array();
753 foreach ($this->config->departments as $key => $value){
754 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
755 "terminal", $value) == "#all#"){
756 $responsible[$key]= $value;
757 }
758 }
760 /* Get config */
761 $terminalfilter= get_global('terminalfilter');
762 $filter= "";
764 /* Set base for all searches */
765 $base= $terminalfilter['depselect'];
767 /* Regex filter? */
768 if ($terminalfilter['regex'] != ""){
769 $regex= $terminalfilter['regex'];
770 } else {
771 $regex= "*";
772 }
774 /* Get list of terminals to be shown */
775 if ($terminalfilter['thins'] == "checked"){
776 $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
777 } else {
778 $termfilter= "";
779 }
780 if ($terminalfilter['workstations'] == "checked"){
781 $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
782 } else {
783 $workfilter= "";
784 }
785 if ($terminalfilter['winstations'] == "checked"){
786 if ($this->config->current['SAMBAVERSION'] == "3"){
787 $samba= "sambaSamAccount";
788 } else {
789 $samba= "sambaAccount";
790 }
791 $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
792 } else {
793 $winfilter= "";
794 }
795 if ($terminalfilter['printers'] == "checked"){
796 $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
797 } else {
798 $printfilter= "";
799 }
800 if ($terminalfilter['phones'] == "checked"){
801 $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
802 } else {
803 $phonefilter= "";
804 }
805 if ($terminalfilter['netdev'] == "checked"){
806 $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
807 } else {
808 $netfilter= "";
809 }
810 if ($terminalfilter['servers'] == "checked"){
811 $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
812 } else {
813 $serverfilter= "";
814 }
816 /* User filter? */
817 if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
818 $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
819 }
821 /* Get all gotoTerminal's */
822 $this->terminals= array();
824 $res= get_list($this->ui->subtreeACL, "(|$termfilter$workfilter$winfilter$printfilter$phonefilter$serverfilter$netfilter)", TRUE, $base, array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), TRUE);
827 /* NEW LIST MANAGMENT
828 * We also need to search for the departments
829 * So we are able to navigate like in konquerer
830 */
831 $base2 = preg_replace("/ou=people,/i","",$base);
833 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
834 TRUE, $base2, array("ou", "description"), TRUE);
836 $this->departments= array();
837 $tmp = array();
838 foreach ($res3 as $value){
839 $tmp[strtolower($value['dn']).$value['dn']]=$value;
840 }
841 ksort($tmp);
842 foreach($tmp as $value){
843 if($value["description"][0]!=".."){
844 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
845 }else{
846 $this->departments[$value['dn']]=$value["description"][0];
847 }
848 }
850 /* END NEW LIST MANAGMENT
851 */
854 foreach ($res as $value){
856 /* Look for new terminals and mark them with '+' */
857 $tmp= "";
858 if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
859 $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
860 }
861 if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
862 $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
863 }
864 if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
865 $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
866 }
867 if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
868 $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
869 }
870 if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
871 $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
872 }
873 if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
874 $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
875 }
876 if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
877 $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
878 }
879 if ($tmp == ""){
880 $tmp= $value["dn"];
881 }
882 if (preg_match ("/,ou=incoming,/i", $tmp)){
883 if (in_array('gotoTerminal', $value['objectClass'])){
884 $add= "+ "._("New terminal");
885 }
886 if (in_array('gotoWorkstation', $value['objectClass'])){
887 $add= "+ "._("New workstation");
888 }
889 } else {
890 $add= "";
891 }
893 $terminal = array();
895 if (in_array ($tmp, $responsible) || $add != ""){
896 if (in_array('gotoTerminal', $value["objectClass"])){
897 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
898 $terminal = $value;
899 $terminal['type'] = "T";
900 $terminal['is_new'] = $add;
901 } else {
902 $terminal = $value;
903 $terminal['type'] = "D";
904 $terminal['message'] = _("Terminal template for");
905 $terminal['location'] = array_search($tmp, $this->config->departments);
906 }
907 } elseif (in_array('gotoWorkstation', $value["objectClass"])){
908 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
909 $terminal = $value;
910 $terminal['type'] = "L";
911 } else {
912 $terminal = $value;
913 $terminal['type'] = "D";
914 $terminal['location'] = array_search($tmp, $this->config->departments);
915 $terminal['message'] = _("Workstation template for");
916 }
917 } elseif (in_array('gotoPrinter', $value["objectClass"])){
918 $terminal = $value;
919 $terminal['type'] = "P";
920 } elseif (in_array('goServer', $value["objectClass"])){
921 $terminal = $value;
922 $terminal['type'] = "S";
923 } elseif (in_array('goFonHardware', $value["objectClass"])){
924 $terminal = $value;
925 $terminal['type'] = "F";
926 } elseif (in_array('ieee802Device', $value["objectClass"])){
927 $terminal = $value;
928 $terminal['type'] = "C";
929 } else{
930 $name= preg_replace('/\$$/', '', $value['cn'][0]);
931 if (isset($value['sambaDomainName'])){
932 $domain= " [".$value['sambaDomainName'][0]."]";
933 } else {
934 $domain= "";
935 }
936 $terminal=$value;
937 $terminal['type'] ="W";
938 $terminal['domain'] = $name.$domain;
939 }
940 $this->terminals[]=$terminal;
941 }
942 }
944 $tmp=array();
945 foreach($this->terminals as $tkey => $val ){
946 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
947 }
948 ksort($tmp);
949 $this->terminals=array();
950 foreach($tmp as $val){
951 $this->terminals[]=$val;
952 }
953 reset ($this->terminals);
954 }
956 function remove_lock()
957 {
958 if (isset($this->systab->dn)){
959 del_lock ($this->systab->dn);
960 }
961 }
964 function get_system_type($classes)
965 {
966 $type= "";
968 if (in_array('ieee802Device', $classes)){
969 $type= "component";
970 }
971 if (in_array('gotoTerminal', $classes)){
972 $type= "terminal";
973 }
974 if (in_array('gotoWorkstation', $classes)){
975 $type= "workstation";
976 }
977 if (in_array('gotoPrinter', $classes)){
978 $type= "printer";
979 }
980 if (in_array('goFonHardware', $classes)){
981 $type= "phone";
982 }
983 if (in_array('goServer', $classes)){
984 $type= "server";
985 }
986 if (in_array('sambaAccount', $classes) ||
987 in_array('sambaSamAccount', $classes)){
988 $type= "winstation";
989 }
991 return ($type);
992 }
994 }
996 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
997 ?>