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 $DivListSystem;
42 function systems ($config, $ui)
43 {
44 /* Save configuration for internal use */
45 $this->config= $config;
46 $this->ui= $ui;
48 /* Creat dialog object */
49 $this->DivListSystem = new divListSystem($this->config,$this);
50 }
52 function execute()
53 {
54 /* Call parent execute */
55 plugin::execute();
57 $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/");
59 /********************
60 Check for functional posts, edit|delete|add|... system devices
61 ********************/
62 $s_action = ""; // Contains the action to proceed
63 $s_entry = ""; // The value for s_action
64 $base_back = ""; // The Link for Backbutton
65 $smarty = get_smarty();
67 /* Test Posts */
68 foreach($_POST as $key => $val){
69 // Post for delete
70 if(preg_match("/system_del.*/",$key)){
71 $s_action = "del";
72 $s_entry = preg_replace("/system_del_/i","",$key);
73 // Post for edit
74 }elseif(preg_match("/system_edit_.*/",$key)){
75 $s_action="edit";
76 $s_entry = preg_replace("/system_edit_/i","",$key);
77 // Post for new
78 }elseif(preg_match("/system_new.*/",$key)){
79 $s_action="new";
80 }elseif(preg_match("/system_tplnew.*/i",$key)){
81 $s_action="new_tpl";
82 }elseif(preg_match("/system_setpwd_.*/i",$key)){
83 $s_action="change_pw";
84 $s_entry = preg_replace("/system_setpwd_/i","",$key);
85 }elseif(preg_match("/gen_cd_.*/i",$key)){
86 $s_action="gen_cd";
87 $s_entry = preg_replace("/gen_cd_/i","",$key);
88 }elseif(preg_match("/^remove_multiple_systems/i",$key)){
89 $s_action="del_multiple";
90 }elseif(preg_match("/newsystem_.*/i",$key)){
91 $s_action="newsystem";
92 $s_entry = preg_replace("/newsystem_/i","",$key);
93 }
94 }
96 /* Incoming handling
97 * If someone made a systemtype and ogroup selection
98 * Display the new requested entry type ... servtab in case of server and so on.
99 */
100 if(isset($_POST['SystemTypeChoosen'])){
101 $s_action = "SelectedSystemType";
102 $s_entry = $_POST['SystemType'];
103 $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
104 $this->systab = NULL;
105 }
107 /* remove image tags from posted entry (posts looks like this 'name_x')*/
108 $s_entry = preg_replace("/_.$/","",$s_entry);
110 /* Edit was requested by pressing the name(link) of an item */
111 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
112 $s_action ="edit";
113 $s_entry = $_GET['id'];
114 }
116 /* Check for exeeded sizelimit */
117 if (($message= check_sizelimit()) != ""){
118 return($message);
119 }
121 /* Try to get informations about what kind of system to create */
122 if ($s_action=="new") {
123 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
124 }
127 /********************
128 Create FAI CD ...
129 ********************/
130 if ($s_action=="gen_cd"){
131 $this->dn= $this->terminals[$s_entry]['dn'];
132 $_SESSION['objectinfo']= $this->dn;
133 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
134 }
137 /* Start CD-Creation */
138 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
139 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
140 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
141 }
144 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
146 $return_button = "<form method='get' action='main.php' target='_parent'>
147 <input type='submit' value='"._("Back")."'>
148 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
149 </form>";
151 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
153 /* Get and check command */
154 $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
155 if (check_command($command)){
156 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
158 /* Print out html introduction */
159 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
160 <html>
161 <head>
162 <title></title>
163 <style type="text/css">@import url("themes/default/style.css");</style>
164 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
165 </head>
166 <body style="background: none; margin:4px;" id="body" >
167 <pre>';
169 /* Open process handle and check if it is a valid process */
170 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
171 if (is_resource($process)) {
172 fclose($pipes[0]);
174 /* Print out returned lines && write JS to scroll down each line */
175 while (!feof($pipes[1])){
176 $cur_dat = fgets($pipes[1], 1024);
177 echo $cur_dat;
178 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
179 flush();
180 }
181 }
183 /* Get error string && close streams */
184 $buffer= stream_get_contents($pipes[2]);
186 fclose($pipes[1]);
187 fclose($pipes[2]);
188 echo "</pre>";
190 /* Check return code */
191 $ret= proc_close($process);
192 if ($ret != 0){
193 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
194 echo "<pre style='color:red'>$buffer</pre>";
195 }
199 echo $return_button."<br>";
201 } else {
202 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
203 echo $tmp;
204 }
206 /* Scroll down completly */
207 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
208 echo '</body></html>';
209 flush();
210 exit;
211 }
214 /********************
215 Create new system ...
216 ********************/
217 /* Create new default terminal
218 * Or create specified object of selected system type, from given incoming object
219 */
221 $save_object_directly = false;
222 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
223 $save_object_directly = true;
224 }
226 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
228 /* If the current entry is an incoming object
229 * $sw = System type as posted in new incoming handling dialog
230 */
231 if($s_action == "SelectedSystemType") {
232 $sw = $s_entry;
233 }else{
234 if(isset($_POST['system'])){
235 $sw = $_POST['system'];
236 }else{
237 $sw = $s_entry;
238 }
239 $this->dn= "new";
240 }
241 $tabs = array(
242 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
243 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
244 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
245 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
246 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phonegeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
247 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
249 if(isset($tabs[$sw])){
250 $class = $tabs[$sw]["CLASS"];
251 $tabname = $tabs[$sw]["TABNAME"];
252 $tabclass = $tabs[$sw]["TABCLASS"];
253 $acl_cat = $tabs[$sw]["ACL"];
255 /* Load permissions for selected 'dn' and check if
256 we're allowed to remove this 'dn' */
257 $ui = get_userinfo();
258 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
259 if(preg_match("/c/",$tabacl)){
260 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
261 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
262 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
263 $this->systab->base = $this->DivListSystem->selectedBase;
264 }else{
265 print_red(_("You are not allowed to create a new object of this type."));
266 }
267 }
268 }
270 /********************
271 Edit system ...
272 ********************/
274 /* User wants to edit data? */
275 if (($s_action == "edit") && (!isset($this->systab->config))){
277 $this->dn= $this->terminals[$s_entry]['dn'];
279 /* Check locking, save current plugin in 'back_plugin', so
280 the dialog knows where to return. */
281 if (($user= get_lock($this->dn)) != ""){
282 return(gen_locked_message ($user, $this->dn));
283 }
285 /* Find out more about the object type */
286 $ldap= $this->config->get_ldap_link();
287 $ldap->cat($this->dn, array('objectClass'));
288 $attrs= $ldap->fetch();
289 $type= $this->get_system_type($attrs['objectClass']);
291 /* Lock the current entry, so everyone will get the
292 above dialog */
293 $tabs = array(
294 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
295 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
296 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
297 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
298 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
299 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
300 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
303 if($type == "NewDevice"){
304 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
305 }elseif(isset($tabs[$type])){
307 $class = $tabs[$type]["CLASS"];
308 $acl_cat = $tabs[$type]["ACL"];
309 $tabclass = $tabs[$type]["TABCLASS"];
311 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
312 $this->systab->set_acl_base($this->dn);
313 $_SESSION['objectinfo']= $this->dn;
314 add_lock ($this->dn, $this->ui->dn);
315 }else{
316 print_red (_("You can't edit this object type yet!"));
317 del_lock($this->dn);
318 }
319 }
322 /********************
323 Change password ...
324 ********************/
326 /* Set terminals root password */
327 if ($s_action=="change_pw"){
328 $tabs = array(
329 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
330 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
332 $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
333 $class = $tabs[$type]["CLASS"];
334 $tabname = $tabs[$type]["TABNAME"];
335 $acl_cat = $tabs[$type]["ACL"];
336 $tabclass = $tabs[$type]["TABCLASS"];
337 $ui = get_userinfo();
338 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
339 if(preg_match("/w/",$tabacl)){
340 $this->dn= $this->terminals[$s_entry]['dn'];
341 $_SESSION['objectinfo']= $this->dn;
342 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
343 }else{
344 print_red(_("You are not allowed to change the password for this object."));
345 }
346 }
349 /********************
350 Password change finish, but check if entered data is ok
351 ********************/
353 /* Correctly specified? */
354 if (isset($_POST['password_finish'])){
355 if ($_POST['new_password'] != $_POST['repeated_password']){
356 print_red (_("Passwords entered as new and repeated do not match!"));
357 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
358 }
359 }
361 /********************
362 Password change finish
363 ********************/
365 /* Change terminal password */
366 if (isset($_POST['password_finish']) &&
367 $_POST['new_password'] == $_POST['repeated_password']){
369 /* Check if user is allowed to set password */
370 $tabs = array(
371 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
372 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
374 /* Detect object type */
375 $type = "";
376 foreach($this->terminals as $terminal){
377 if($terminal['dn'] == $this->dn){
378 $type = $this->get_system_type($terminal['objectClass']);
379 break;
380 }
381 }
383 /* Type detected */
384 if(!empty($type)){
386 /* Get infos */
387 $class = $tabs[$type]["CLASS"];
388 $tabname = $tabs[$type]["TABNAME"];
389 $acl_cat = $tabs[$type]["ACL"];
390 $tabclass = $tabs[$type]["TABCLASS"];
392 /* Get acls */
393 $ui = get_userinfo();
394 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
396 /* Check acls */
397 if(preg_match("/w/",$tabacl)){
398 $ldap = $this->config->get_ldap_link();
399 $ldap->cd($this->dn);
401 $attrs= array();
402 if ($_POST['new_password'] == ""){
403 $attrs['gotoRootPasswd']= array();
404 } else {
405 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
406 }
407 $ldap->modify($attrs);
408 gosa_log ("Password for '".$this->dn."' has been changed");
409 }else{
410 print_red(_("You are not allowed to change the password for this object."));
411 }
412 }else{
413 print_red(_("Can't detect object to change password."));
414 }
415 unset($_SESSION['objectinfo']);
416 }
419 /********************
420 Delete system cancel
421 ********************/
423 /* Delete terminal canceled? */
424 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
425 del_lock ($this->dn);
426 unset($_SESSION['objectinfo']);
427 }
430 /********************
431 Delete MULTIPLE entries requested, display confirm dialog
432 ********************/
434 if ($s_action=="del_multiple"){
435 $this->dns = array();
436 $ids = $this->list_get_selected_items();
438 if(count($ids)){
440 foreach($ids as $id){
441 $dn = $this->terminals[$id]['dn'];
442 if (($user= get_lock($dn)) != ""){
443 return(gen_locked_message ($user, $dn));
444 }
445 $this->dns[$id] = $dn;
446 }
448 $dns_names = "<br><pre>";
449 foreach($this->dns as $dn){
450 add_lock ($dn, $this->ui->dn);
451 $dns_names .= $dn."\n";
452 }
453 $dns_names .="</pre>";
455 /* Lock the current entry, so nobody will edit it during deletion */
456 if (count($this->dns) == 1){
457 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
458 } else {
459 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
460 }
461 $smarty->assign("multiple", true);
462 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
463 }
464 }
467 /********************
468 Delete MULTIPLE entries confirmed
469 ********************/
471 /* Confirmation for deletion has been passed. Users should be deleted. */
472 if (isset($_POST['delete_multiple_system_confirm'])){
474 $ui = get_userinfo();
475 $tabs = array(
476 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
477 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
478 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
479 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
480 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
481 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
482 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
485 /* Remove user by user and check acls before removeing them */
486 foreach($this->dns as $key => $dn){
488 /* Get 'dn' from posted termlinst */
489 $attrs = $this->terminals[$key];
490 $type= $this->get_system_type($attrs['objectClass']);
492 /* get object type */
493 $tabtype = "termtabs";
494 $tabobj = "TERMTABS";
495 $tabacl = "";
496 if(isset($tabs[$type])){
497 $tabtype = $tabs[$type]['TABCLASS'];
498 $tabobj = $tabs[$type]['CLASS'];
499 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
501 /* Load permissions for selected 'dn' and check if
502 we're allowed to remove this 'dn' */
503 if(preg_match("/d/",$tabacl)){
505 /* Delete request is permitted, perform LDAP action */
506 if($tabtype=="phonetabs"){
507 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
508 $this->systab->set_acl_base($dn);
509 $this->systab->by_object['phonegeneric']->remove_from_parent ();
510 }else{
511 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
512 $this->systab->set_acl_base($dn);
513 $this->systab->delete();
514 }
515 unset ($this->systab);
516 gosa_log ("System object'".$dn."' has been removed");
517 $this->systab= NULL;
519 } else {
520 /* Normally this shouldn't be reached, send some extra
521 logs to notify the administrator */
522 print_red (_("You are not allowed to delete this component!"));
523 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
524 "deletion.");
525 }
526 /* Remove lock file after successfull deletion */
527 del_lock ($dn);
528 unset($this->dns[$key]);
529 }
530 }
531 }
533 /********************
534 Delete MULTIPLE entries Canceled
535 ********************/
537 /* Remove lock */
538 if(isset($_POST['delete_multiple_system_cancel'])){
539 foreach($this->dns as $key => $dn){
540 del_lock ($dn);
541 unset($this->dns[$key]);
542 }
543 }
546 /********************
547 Delete system, confirm dialog
548 ********************/
550 /* Remove terminal was requested */
551 if ($s_action=="del"){
553 /* Get 'dn' from posted termlinst */
554 $this->dn = $this->terminals[$s_entry]['dn'];
555 $attrs = $this->terminals[$s_entry];
557 $type= $this->get_system_type($attrs['objectClass']);
558 $ui = get_userinfo();
559 $tabs = array(
560 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
561 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
562 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
563 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
564 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
565 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
566 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
569 /* get object type */
570 $tabtype = "termtabs";
571 $tabobj = "TERMTABS";
572 $tabacl = "";
573 if(isset($tabs[$type])){
574 $tabtype = $tabs[$type]['TABCLASS'];
575 $tabobj = $tabs[$type]['CLASS'];
576 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
577 }
579 /* Load permissions for selected 'dn' and check if
580 we're allowed to remove this 'dn' */
581 if(preg_match("/d/",$tabacl)){
583 /* Check locking, save current plugin in 'back_plugin', so
584 the dialog knows where to return. */
585 if (($user= get_lock($this->dn)) != ""){
586 return(gen_locked_message ($user, $this->dn));
587 }
589 /* Lock the current entry, so nobody will edit it during deletion */
590 add_lock ($this->dn, $this->ui->dn);
591 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
592 $smarty->assign("multiple", false);
593 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
594 } else {
596 /* Obviously the user isn't allowed to delete. Show message and
597 clean session. */
598 print_red (_("You are not allowed to delete this component!"));
599 }
600 }
603 /********************
604 Delete system, confirmed
605 ********************/
606 /* Confirmation for deletion has been passed. Terminal should be deleted. */
607 if (isset($_POST['delete_terminal_confirm'])){
609 /* Find out more about the object type */
610 $ldap= $this->config->get_ldap_link();
611 $ldap->cat($this->dn, array('objectClass'));
612 $attrs= $ldap->fetch();
613 $type= $this->get_system_type($attrs['objectClass']);
615 $ui = get_userinfo();
617 $tabs = array(
618 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
619 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
620 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
621 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
622 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
623 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
624 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
626 /* get object type */
627 $tabtype = "termtabs";
628 $tabobj = "TERMTABS";
629 $tabacl = "";
630 if(isset($tabs[$type])){
631 $tabtype = $tabs[$type]['TABCLASS'];
632 $tabobj = $tabs[$type]['CLASS'];
633 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
634 }
636 /* Check if we are allowed to remove this object */
637 if(preg_match("/d/",$tabacl)){
639 /* Delete request is permitted, perform LDAP action */
640 if($tabtype=="phonetabs"){
641 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
642 $this->systab->set_acl_base($this->dn);
643 $this->systab->by_object['phonegeneric']->remove_from_parent ();
644 }else{
645 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
646 $this->systab->set_acl_base($this->dn);
647 $this->systab->delete();
648 }
649 unset ($this->systab);
650 gosa_log ("System object'".$this->dn."' has been removed");
651 $this->systab= NULL;
653 /* Terminal list has changed, reload it. */
654 } else {
656 /* Normally this shouldn't be reached, send some extra
657 logs to notify the administrator */
658 print_red (_("You are not allowed to delete this component!"));
659 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
660 "deletion.");
661 }
663 /* Remove lock file after successfull deletion */
664 del_lock ($this->dn);
665 }
675 /********************
676 Edit system type finished, check if everything went ok
677 ********************/
678 /* Finish user edit is triggered by the tabulator dialog, so
679 the user wants to save edited data. Check and save at this
680 point. */
681 if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
683 /* Check tabs, will feed message array */
684 $message = array();
685 if(!$save_object_directly){
686 $message = $this->systab->check();
687 }else{
688 $found = false;
690 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
691 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
692 if(isset($this->systab->by_object[$tab]->gotoMode)) {
693 $found = true;
694 $this->systab->by_object[$tab]->gotoMode = $value;
695 }
696 }
697 if(!$found){
698 print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
699 }
701 }
702 /* Save, or display error message? */
703 if (count($message) == 0){
705 /* Save terminal data to ldap */
706 if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
707 foreach (array("workservice", "termservice") as $cls){
708 if (isset($this->systab->by_object[$cls])){
709 $this->systab->by_object[$cls]->gotoXMouseport= "";
710 $this->systab->by_object[$cls]->gotoXMouseType= "";
711 $this->systab->by_object[$cls]->gotoXResolution= "";
712 $this->systab->by_object[$cls]->gotoXColordepth= "";
713 }
714 }
715 }
717 $this->systab->save();
718 gosa_log ("System object'".$this->dn."' has been saved");
720 /* Incoming behavior; you can select a system type and an ogroup membership.
721 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
722 * Check if we must add the new object to an object group.
723 *
724 * If this is done, delete the old incoming entry... it is still there, because this is a new
725 * entry and not an edited one, so we will delete it.
726 *
727 */
729 if(isset($_SESSION['SelectedSystemType'])){
730 $SelectedSystemType= $_SESSION['SelectedSystemType'];
731 unset($_SESSION['SelectedSystemType']);
732 if($SelectedSystemType['ogroup'] != "none"){
733 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
734 if($og){
735 $og->AddDelMembership($this->systab->dn);
736 $og->save();
737 }
738 }
739 if(!isset($ldap)){
740 $ldap = $this->config->get_ldap_link();
741 }
742 $ldap->cd ($this->dn);
743 $ldap->cat($this->dn, array('dn'));
744 if(count($ldap->fetch())){
745 $ldap->cd($this->dn);
746 $ldap->rmDir($this->dn);
747 }
748 $ldap->cd($this->config->current['BASE']);
749 }
751 /* Terminal has been saved successfully, remove lock from
752 LDAP. */
753 if ($this->dn != "new"){
754 del_lock ($this->dn);
755 }
757 unset ($this->systab);
758 $this->systab= NULL;
759 unset($_SESSION['objectinfo']);
760 } else {
761 /* Ok. There seem to be errors regarding to the tab data,
762 show message and continue as usual. */
763 show_errors($message);
764 }
765 }
768 /********************
769 Edit system was canceled
770 ********************/
771 /* Cancel dialogs */
772 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
773 if (isset($this->systab)){
774 del_lock ($this->systab->dn);
775 unset ($this->systab);
776 }
777 $this->systab= NULL;
778 unset($_SESSION['objectinfo']);
780 /* Remove ogroup selection, which was set while editing a new incoming entry */
781 if(isset($_SESSION['SelectedSystemType'])){
782 unset($_SESSION['SelectedSystemType']);
783 }
784 }
786 /********************
787 Display edit dialog, or some other
788 ********************/
790 /* Show tab dialog if object is present */
791 if (isset($this->systab->config)){
792 $display= $this->systab->execute();
794 /* Don't show buttons if tab dialog requests this */
795 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
796 $display.= "<p style=\"text-align:right\">\n";
797 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
798 $display.= " \n";
799 if ($this->dn != "new"){
800 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
801 $display.= " \n";
802 }
803 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
804 $display.= "</p>";
805 }
806 return ($display);
807 }
809 /* Check if there is a snapshot dialog open */
810 $base = $this->DivListSystem->selectedBase;
811 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
812 return($str);
813 }
815 /* Display dialog with system list */
816 $this->DivListSystem->parent = $this;
817 $this->DivListSystem->execute();
819 /* Add departments if subsearch is disabled */
820 if(!$this->DivListSystem->SubSearch){
821 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
822 }
823 $this->reload();
824 $this->DivListSystem->setEntries($this->terminals);
825 return($this->DivListSystem->Draw());
826 }
829 /* Return departments, that will be included within snapshot detection */
830 function get_used_snapshot_bases()
831 {
832 $tmp = array();
834 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
836 $tabs = array(
837 "terminal" => "ou=terminals,ou=systems,",
838 "workstation" => "ou=workstations,ou=systems,",
839 "incoming" => "ou=incoming,",
840 "server" => "ou=servers,ou=systems,",
841 "printer" => "ou=printers,ou=systems,",
842 "phone" => "ou=phones,ou=systems,",
843 "winworkstation" => get_winstations_ou(),
844 "component" => "ou=netdevices,ou=systems,"
845 );
847 foreach($tabs as $acl_cat => $dn){
849 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
850 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
851 $tmp[] = $dn.$this->DivListSystem->selectedBase;
852 }
853 }
854 return($tmp);
855 }
858 function remove_from_parent()
859 {
860 /* Optionally execute a command after we're done */
861 $this->postremove();
862 }
865 /* Save data to object */
866 function save_object()
867 {
868 $this->DivListSystem->save_object();
869 }
872 /* Check values */
873 function check()
874 {
875 }
878 /* Save to LDAP */
879 function save()
880 {
881 }
883 function adapt_from_template($dn)
884 {
885 }
887 function password_change_needed()
888 {
889 }
891 function reload()
892 {
893 /* some var init */
894 $ui = get_userinfo();
895 $res = array();
896 $this->terminals = array();
897 $userregex = "";
899 /* Set base for all searches */
900 $base= $this->DivListSystem->selectedBase;
902 /* Prepare samba class name */
903 $samba ="";
904 if ($this->DivListSystem->ShowWinWorkstations){
905 if ($this->config->current['SAMBAVERSION'] == "3"){
906 $samba= "sambaSamAccount";
907 } else {
908 $samba= "sambaAccount";
909 }
910 }
912 /* This array represents the combination between checkboxes and search filters */
913 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
914 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
915 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
916 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
917 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
918 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
919 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
921 /* Include the 'Display Systems of user' attribute */
922 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
923 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
924 }
926 /* Attributes to fetch */
927 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName");
928 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer");
930 /* Add FAIstate to attributes if FAI is activated */
931 $tmp = search_config($this->config->data,"faiManagement","CLASS");
932 if(!empty($tmp)){
933 $sys_attrs[] = "FAIstate";
934 }
936 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
937 foreach($objs as $checkBox => $oc){
938 if($this->DivListSystem->$checkBox){
939 if($this->DivListSystem->SubSearch){
940 if($oc['CLASS'] != ""){
941 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
942 $new_res = get_list($filter, $sys_categories , $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
944 /* Remove all objects that are not in the expected sub department */
945 foreach($new_res as $key => $obj){
946 if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
947 $res[$obj['dn']] = $obj;
948 }
949 }
950 }
951 }else{
952 /* User filter? */
953 if($oc['CLASS'] != ""){
954 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
955 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
956 }
957 }
958 }
959 }
961 /* Search for incoming objects */
962 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
963 $res = array_merge($res,get_list($filter,$sys_categories,"ou=incoming,".$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
965 /* Get all gotoTerminal's */
966 foreach ($res as $value){
968 $tmp= $value['dn'];
969 $add= "";
971 /* Extract base */
972 foreach($objs as $obj){
973 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
974 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
975 }
976 }
978 /* Create a string containing the last part of the department. */
979 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
980 if(empty($dn_name)){
981 $dn_name = "/";
982 }
984 /* check if current object is a new one */
985 if (preg_match ("/,ou=incoming,/i", $tmp)){
986 if (in_array_ics('gotoTerminal', $value['objectClass'])){
987 $add= "- "._("New terminal");
988 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
989 $add= "- "._("New workstation");
990 }elseif (in_array_ics('GOhard', $value['objectClass'])){
991 $add= "- "._("New Device");
992 }
993 }
995 /* Detect type of object and create an entry for $this->terminals */
996 $terminal = array();
998 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1000 /* check acl */
1001 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1002 if($add != "" || preg_match("/r/",$acl)) {
1003 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1004 $terminal = $value;
1005 $terminal['type'] = "T";
1006 $terminal['is_new'] = $add;
1007 } else {
1008 $terminal = $value;
1009 $terminal['type'] = "D";
1010 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1011 $terminal['location'] = array_search($tmp, $this->config->departments);
1012 }
1013 }
1014 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1016 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1017 if($add != "" || preg_match("/r/",$acl)) {
1018 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1019 $terminal = $value;
1020 $terminal['type'] = "L";
1021 $terminal['is_new'] = $add;
1022 } else {
1023 $terminal = $value;
1024 $terminal['type'] = "D";
1025 $terminal['location'] = array_search($tmp, $this->config->departments);
1026 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1027 }
1028 if (isset($value["FAIstate"][0])){
1029 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1030 }
1031 }
1032 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1035 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1036 if($add != "" || preg_match("/r/",$acl)) {
1038 $terminal = $value;
1039 $terminal['type'] = "P";
1040 }
1041 } elseif (in_array_ics('goServer', $value["objectClass"])){
1043 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1044 if($add != "" || preg_match("/r/",$acl)) {
1046 $terminal = $value;
1047 $terminal['type'] = "S";
1048 if (isset($value["FAIstate"][0])){
1049 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1050 }
1051 }
1052 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1054 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1055 if($add != "" || preg_match("/r/",$acl)) {
1057 $terminal = $value;
1058 $terminal['type'] = "F";
1059 }
1060 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1062 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1063 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1064 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1065 if($add != "" || preg_match("/r/",$acl)) {
1067 $terminal = $value;
1068 $terminal['type'] = "Q";
1069 $terminal['is_new'] = $add;
1070 }
1071 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1073 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1074 if($add != "" || preg_match("/r/",$acl)) {
1076 $terminal = $value;
1077 $terminal['type'] = "C";
1078 }
1079 } else{
1081 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1082 if (isset($value['sambaDomainName'])){
1083 $domain= " [".$value['sambaDomainName'][0]."]";
1084 } else {
1085 $domain= "";
1086 }
1087 $terminal=$value;
1088 $terminal['type'] ="W";
1089 $terminal['domain'] = $name.$domain;
1090 }
1092 if(count($terminal)){
1093 $this->terminals[]=$terminal;
1094 }
1095 }
1097 $tmp=array();
1098 foreach($this->terminals as $tkey => $val ){
1099 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1100 }
1101 ksort($tmp);
1102 $this->terminals=array();
1103 foreach($tmp as $val){
1104 $this->terminals[]=$val;
1105 }
1106 reset ($this->terminals);
1107 }
1109 function remove_lock()
1110 {
1111 if (isset($this->systab->dn)){
1112 del_lock ($this->systab->dn);
1113 }
1114 }
1117 function get_system_type($classes)
1118 {
1119 $type= "";
1120 if (in_array_ics('ieee802Device', $classes)){
1121 $type= "component";
1122 }elseif (in_array_ics('gotoTerminal', $classes)){
1123 $type= "terminal";
1124 }elseif (in_array_ics('gotoWorkstation', $classes)){
1125 $type= "workstation";
1126 }elseif (in_array_ics('gotoPrinter', $classes)){
1127 $type= "printer";
1128 }elseif (in_array_ics('goFonHardware', $classes)){
1129 $type= "phone";
1130 }elseif (in_array_ics('goServer', $classes)){
1131 $type= "server";
1132 }elseif (in_array_ics('GOhard', $classes)){
1133 $type= "NewDevice";
1134 }elseif (in_array_ics('sambaAccount', $classes) ||
1135 in_array_ics('sambaSamAccount', $classes)){
1136 $type= "winstation";
1137 }
1138 return ($type);
1139 }
1142 function convert_list($input)
1143 {
1144 $temp= "";
1145 $conv= array(
1146 "NQ" => array("select_newsystem.png",_("New System from incoming")),
1147 "D" => array("select_default.png",_("Template")),
1148 "T" => array("select_terminal.png",_("Terminal")),
1149 "L" => array("select_workstation.png",_("Workstation")),
1150 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1151 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1152 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1153 "F" => array("select_phone.png",_("Phone")),
1154 "S" => array("select_server.png",_("Server")),
1155 "GS" => array("select_server_green.png",_("Server is installing")),
1156 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1157 "RS" => array("select_server_red.png",_("Server installation failed")),
1158 "W" => array("select_winstation.png",_("Winstation")),
1159 "C" => array("select_component.png",_("Network Device")),
1160 "NT"=> array("select_new_terminal.png",_("New Terminal")),
1161 "NL"=> array("select_new_workstation.png",_("New Workstation")),
1162 "P" => array("select_printer.png",_("Printer")));
1164 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1165 $input['type']="N".$input['type'];
1166 }
1167 foreach ($conv as $key => $value){
1168 if($input['type']==$key){
1169 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1170 $tmp['class']=$key;
1171 return $tmp;
1172 }
1173 }
1174 }
1177 function getState($type, $state)
1178 {
1179 switch (preg_replace('/:.*$/', '', $state)) {
1180 case 'installing':
1181 $type= 'G'.$type;
1182 break;
1183 case 'error':
1184 $type= 'R'.$type;
1185 break;
1186 case 'install':
1187 $type= 'Y'.$type;
1188 break;
1189 case 'sysinfo':
1190 $type= 'Y'.$type;
1191 break;
1192 case 'softupdate':
1193 $type= 'Y'.$type;
1194 break;
1195 }
1198 return ($type);
1199 }
1202 function list_get_selected_items()
1203 {
1204 $ids = array();
1205 foreach($_POST as $name => $value){
1206 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1207 $id = preg_replace("/^item_selected_/","",$name);
1208 $ids[$id] = $id;
1209 }
1210 }
1211 return($ids);
1212 }
1215 /* !! Incoming dummy acls, required to defined acls for incoming objects
1216 */
1217 function plInfo()
1218 {
1219 return (array(
1220 "plShortName" => _("Incoming objects"),
1221 "plDescription" => _("Incoming objects"),
1222 "plSelfModify" => FALSE,
1223 "plDepends" => array(),
1224 "plPriority" => 99,
1225 "plSection" => array("administration"),
1226 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1227 "objectClass" => "")),
1228 "plProvidedAcls"=> array()
1230 ));
1231 }
1236 }
1238 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1239 ?>