1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class systems extends plugin
24 {
25 /* Definitions */
26 var $plHeadline = "Systems";
27 var $plDescription = "This does something";
28 var $departments = array();
30 /* Dialog attributes */
31 var $systab = NULL;
32 var $terminals= array();
33 var $ui = NULL;
34 var $DivListSystem;
35 var $start_pasting_copied_objects = FALSE;
36 var $CopyPasteHandler = NULL;
38 /* Arp hanlding activated */
39 var $arp_handling_active = FALSE;
40 var $last_action = "";
42 var $dns = array();
44 var $system_activation_object = ""; // The object to activate (NewDevice)
45 var $fai_activated = FALSE;
46 var $si_active = FALSE;
48 var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
50 function systems (&$config, $ui)
51 {
52 /* Save configuration for internal use */
53 $this->config= $config;
54 $this->ui= $ui;
56 /* Add FAIstate to attributes if FAI is activated */
57 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
58 if(!empty($tmp)){
59 $this->fai_activated = TRUE;
60 }
62 /* Creat dialog object */
63 $this->DivListSystem = new divListSystem($this->config,$this);
65 /* Copy & Paste enabled ?*/
66 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
67 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
68 }
70 /* Check whether the arp handling active or not */
71 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
72 $this->arp_handling_active = TRUE;
73 }
75 /* Check if we are able to communicate with the GOsa supprot daemon
76 */
77 if(class_available("gosaSupportDaemon")){
78 $o = new gosaSupportDaemon();
79 $this->si_active = $o->connect() && class_available("DaemonEvent");
80 }
81 }
84 function execute()
85 {
86 /* Call parent execute */
87 plugin::execute();
89 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
91 /********************
92 Check for functional posts, edit|delete|add|... system devices
93 ********************/
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 /* Test Posts */
100 foreach($_POST as $key => $val){
101 // Post for delete
102 if(preg_match("/system_del.*/",$key)){
103 $s_action = "del";
104 $s_entry = preg_replace("/system_del_/i","",$key);
105 // Post for edit
106 }elseif(preg_match("/system_edit_.*/",$key)){
107 $s_action="edit";
108 $s_entry = preg_replace("/system_edit_/i","",$key);
109 // Post for new
110 }elseif(preg_match("/system_new.*/",$key)){
111 $s_action="new";
112 }elseif(preg_match("/system_tplnew.*/i",$key)){
113 $s_action="new_tpl";
114 }elseif(preg_match("/system_setpwd_.*/i",$key)){
115 $s_action="change_pw";
116 $s_entry = preg_replace("/system_setpwd_/i","",$key);
117 }elseif(preg_match("/gen_cd_.*/i",$key)){
118 $s_action="gen_cd";
119 $s_entry = preg_replace("/gen_cd_/i","",$key);
120 }elseif(preg_match("/^copy_.*/",$key)){
121 $s_action="copy";
122 $s_entry = preg_replace("/^copy_/i","",$key);
123 }elseif(preg_match("/^cut_.*/",$key)){
124 $s_action="cut";
125 $s_entry = preg_replace("/^cut_/i","",$key);
126 }
127 }
129 /* remove image tags from posted entry (posts looks like this 'name_x')*/
130 $s_entry = preg_replace("/_.$/","",$s_entry);
132 /* Edit was requested by pressing the name(link) of an item */
133 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
134 $s_action ="edit";
135 $s_entry = $_GET['id'];
136 }
137 /* Create options */
138 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
139 $s_action = "newsystem";
140 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
141 }
143 /* handle C&P from layers menu */
144 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
145 $s_action = "copy_multiple";
146 }
147 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
148 $s_action = "cut_multiple";
149 }
150 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
151 $s_action = "editPaste";
152 }
154 /* Handle daemon events */
155 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
156 $s_action = $_POST['menu_action'];
157 }
159 /* Handle daemon events */
160 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
161 $s_action = $_POST['menu_action'];
162 }
164 /* handle remove from layers menu */
165 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
166 $s_action = "del_multiple";
167 }
169 /* Handle instant actions from layers menu */
170 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
171 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
172 $s_action = "${act}_multiple";
173 }
174 }
176 /* Activate multiple machines */
177 if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
178 $s_action = "activate_multiple";
179 }
181 /* Check for exeeded sizelimit */
182 if (($message= check_sizelimit()) != ""){
183 return($message);
184 }
186 /* Try to get informations about what kind of system to create */
187 if ($s_action=="new") {
188 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
189 }
191 /* Incoming handling
192 * If someone made a systemtype and ogroup selection
193 * Display the new requested entry type ... servtab in case of server and so on.
194 */
195 if(isset($_POST['SystemTypeChoosen'])){
196 $s_action = "SelectedSystemType";
197 }
199 /********************
200 Copy & Paste Handling ...
201 ********************/
203 /* Display the copy & paste dialog, if it is currently open */
204 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
205 if($ret){
206 return($ret);
207 }
210 /********************
211 Create FAI CD ...
212 ********************/
213 if ($s_action=="gen_cd"){
214 $this->dn= $this->terminals[$s_entry]['dn'];
215 session::set('objectinfo',$this->dn);
216 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
217 }
220 /* Start CD-Creation */
221 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
222 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
223 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
224 }
227 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
229 $return_button = "<form method='get' action='main.php' target='_parent'>
230 <input type='submit' value='"._("Back")."'>
231 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
232 </form>";
234 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
236 /* Get and check command */
237 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
239 if (check_command($command)){
240 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
242 /* Print out html introduction */
243 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
244 <html>
245 <head>
246 <title></title>
247 <style type="text/css">@import url("themes/default/style.css");</style>
248 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
249 </head>
250 <body style="background: none; margin:4px;" id="body" >
251 <pre>';
253 /* Open process handle and check if it is a valid process */
254 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
255 if (is_resource($process)) {
256 fclose($pipes[0]);
258 /* Print out returned lines && write JS to scroll down each line */
259 while (!feof($pipes[1])){
260 $cur_dat = fgets($pipes[1], 1024);
261 echo $cur_dat;
262 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
263 flush();
264 }
265 }
267 /* Get error string && close streams */
268 $buffer= stream_get_contents($pipes[2]);
270 fclose($pipes[1]);
271 fclose($pipes[2]);
272 echo "</pre>";
274 /* Check return code */
275 $ret= proc_close($process);
276 if ($ret != 0){
277 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
278 echo "<pre style='color:red'>$buffer</pre>";
279 }
283 echo $return_button."<br>";
285 } else {
286 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
287 echo $tmp;
288 }
290 /* Scroll down completly */
291 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
292 echo '</body></html>';
293 flush();
294 exit;
295 }
298 /********************
299 New Device hanlding (Ogroup/System select dialog.)
300 ********************/
302 if($s_action == "SelectedSystemType"){
304 /* Possible destination system types
305 */
306 $tabs = array(
307 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric",
308 "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
309 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric",
310 "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
311 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric",
312 "TABCLASS" =>"servtabs", "ACL"=> "server"));
314 /* Remember dialog selection.
315 */
316 $selected_group = $_POST['ObjectGroup'];
317 $selected_system = $_POST['SystemType'];
319 $this->systab = NULL;
321 /* Check if system type exists. It should! */
322 if(isset($tabs[$selected_system])){
324 /* Get tab informations */
325 $class = $tabs[$selected_system]["CLASS"];
326 $tabname = $tabs[$selected_system]["TABNAME"];
327 $tabclass = $tabs[$selected_system]["TABCLASS"];
328 $acl_cat = $tabs[$selected_system]["ACL"];
331 if(!class_available($tabclass)){
332 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
333 }else{
335 /* Go through all objects that should be activated */
336 foreach($this->system_activation_object as $key => $dn){
338 /* Remove entry from list, to avoid page-reload problems */
339 unset($this->system_activation_object[$key]);
341 /* Load permissions for selected 'dn' and check if
342 we're allowed to create this 'dn' */
343 $this->dn = $dn;
344 $ui = get_userinfo();
345 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
347 /* We are allowed to create the requested system type */
348 if(preg_match("/c/",$tabacl)){
349 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
350 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
351 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
352 $this->systab->base = $this->DivListSystem->selectedBase;
355 if($selected_group != "none"){
357 /*******
358 * Set gotoMode to active if we there was an ogroup selected.
359 */
360 $found = false;
361 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
362 if(isset($this->systab->by_object[$tab]->gotoMode)) {
363 $found = true;
364 $this->systab->by_object[$tab]->gotoMode = $value;
365 }
366 }
367 if(!$found){
368 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
369 }
371 /*******
372 * Update object group membership
373 */
374 $og = new ogroup($this->config,$selected_group);
375 if($og){
376 $og->AddDelMembership($this->systab->dn);
377 $og->save();
378 }
380 /*******
381 * Set default system specific attributes
382 */
383 foreach (array("workservice", "termservice") as $cls){
384 if (isset($this->systab->by_object[$cls])){
385 $this->systab->by_object[$cls]->gotoXMouseport= "";
386 $this->systab->by_object[$cls]->gotoXMouseType= "";
387 $this->systab->by_object[$cls]->gotoXResolution= "";
388 $this->systab->by_object[$cls]->gotoXColordepth= "";
389 }
390 }
392 // Enable activation
393 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
394 if (isset($this->systab->by_object[$cls])){
395 $this->systab->by_object[$cls]->auto_activate= TRUE;
396 }
397 }
399 // Enable sending of LDAP events
400 if (isset($this->systab->by_object["workstartup"])){
401 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
402 }
403 }
405 /* Don't save directly if there is no objectGroup selected.
406 The user will then be able to configure the missing attributes
407 on his own.
408 */
409 if($selected_group != "none"){
410 $this->systab->save();
411 $this->systab = NULL;
413 if(!isset($ldap)){
414 $ldap = $this->config->get_ldap_link();
415 }
416 $ldap->cd ($this->dn);
417 $ldap->cat($this->dn, array('dn'));
418 if(count($ldap->fetch())){
419 $ldap->cd($this->dn);
420 $ldap->rmDir($this->dn);
421 }
422 }
423 }else{
424 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
425 }
426 }
427 }
428 }
429 }
432 if (isset($_POST['create_system'])||$s_action=="newsystem") {
434 $this->last_action = "";
436 /* If the current entry is an incoming object
437 * $sw = System type as posted in new incoming handling dialog
438 */
439 if(isset($_POST['system'])){
440 $sw = $_POST['system'];
441 }else{
442 $sw = $s_entry;
443 }
444 $this->dn= "new";
446 $tabs = array(
447 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
448 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
449 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
450 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
451 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
452 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
454 if(isset($tabs[$sw])){
455 $class = $tabs[$sw]["CLASS"];
456 $tabname = $tabs[$sw]["TABNAME"];
457 $tabclass = $tabs[$sw]["TABCLASS"];
458 $acl_cat = $tabs[$sw]["ACL"];
460 /* Load permissions for selected 'dn' and check if
461 we're allowed to remove this 'dn' */
462 $ui = get_userinfo();
463 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
464 if(preg_match("/c/",$tabacl)){
466 if(!class_available($tabclass)){
467 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
468 }else{
469 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
470 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
471 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
472 $this->systab->base = $this->DivListSystem->selectedBase;
473 }
474 }else{
475 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
476 }
477 }
478 }
481 /********************
482 System activation
483 ********************/
485 /* User wants to edit data? */
486 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
487 $this->system_activation_object = array();
488 foreach($this->list_get_selected_items() as $id) {
489 $obj = $this->terminals[$id];
490 $type= $this->get_system_type($obj);
491 if($type == "NewDevice"){
492 $this->system_activation_object[] = $obj['dn'];
493 }
494 }
495 if(count($this->system_activation_object)){
496 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
497 }
498 }
501 /********************
502 Edit system ...
503 ********************/
505 /* User wants to edit data? */
506 if (($s_action == "edit") && (!isset($this->systab->config))){
507 $this->last_action = "";
508 $this->dn= $this->terminals[$s_entry]['dn'];
510 /* Check locking, save current plugin in 'back_plugin', so
511 the dialog knows where to return. */
512 if (($user= get_lock($this->dn)) != ""){
513 return(gen_locked_message ($user, $this->dn));
514 }
516 /* Find out more about the object type */
517 $ldap= $this->config->get_ldap_link();
518 $ldap->cat($this->dn, array('objectClass','gotoMode'));
519 $attrs= $ldap->fetch();
520 $type= $this->get_system_type($attrs);
522 /* Lock the current entry, so everyone will get the
523 above dialog */
524 $tabs = array(
525 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
526 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
527 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
528 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
529 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
530 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
531 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
534 if($type == "ArpNewDevice"){
535 if(!class_available("ArpNewDeviceTabs")){
536 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
537 }else{
538 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
539 }
540 }elseif($type == "NewDevice"){
541 if(!class_available("SelectDeviceType")){
542 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
543 }else{
544 $this->system_activation_object= array($this->dn);
545 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
546 }
547 }elseif(isset($tabs[$type])){
549 $class = $tabs[$type]["CLASS"];
550 $acl_cat = $tabs[$type]["ACL"];
551 $tabclass = $tabs[$type]["TABCLASS"];
553 if(!class_available($tabclass)){
554 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
555 }else{
556 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
557 $this->systab->set_acl_base($this->dn);
558 session::set('objectinfo',$this->dn);
559 add_lock ($this->dn, $this->ui->dn);
560 }
561 }else{
562 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
563 $this->remove_lock();
564 }
565 }
568 /********************
569 Change password ...
570 ********************/
572 /* Set terminals root password */
573 if ($s_action=="change_pw"){
574 $tabs = array(
575 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
576 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
577 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
578 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
579 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
580 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
581 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
582 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
583 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
585 $dn = $this->terminals[$s_entry]['dn'];
586 $type = $this->get_system_type($this->terminals[$s_entry]);
588 $class = $tabs[$type]["CLASS"];
589 $acl = $tabs[$type]["ACL"];
590 $tabclass = $tabs[$type]["TABCLASS"];
591 $ui = get_userinfo();
592 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
593 if(preg_match("/w/",$tabacl)){
594 $this->dn= $this->terminals[$s_entry]['dn'];
595 session::set('objectinfo',$this->dn);
596 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
597 }else{
598 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
599 }
600 }
603 /********************
604 Password change finish, but check if entered data is ok
605 ********************/
607 /* Correctly specified? */
608 if (isset($_POST['password_finish'])){
609 if ($_POST['new_password'] != $_POST['repeated_password']){
610 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
611 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
612 }
613 }
615 /********************
616 Password change finish
617 ********************/
619 /* Change terminal password */
620 if (isset($_POST['password_finish']) &&
621 $_POST['new_password'] == $_POST['repeated_password']){
623 /* Check if user is allowed to set password */
624 $tabs = array(
625 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
626 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
627 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
628 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
630 /* Detect object type */
631 $type = "";
632 foreach($this->terminals as $terminal){
633 if($terminal['dn'] == $this->dn){
634 $type = $this->get_system_type($terminal);
635 break;
636 }
637 }
639 /* Type detected */
640 $allow_for = array("terminal","workstation","server","component");
641 if(!empty($type) && in_array($type,$allow_for)){
643 /* Get infos */
644 $plug = $tabs[$type]["PLUG"];
645 $class = $tabs[$type]["CLASS"];
646 $acl = $tabs[$type]["ACL"];
647 $tabclass = $tabs[$type]["TABCLASS"];
649 /* Get acls */
650 $ui = get_userinfo();
651 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
653 /* Check acls */
654 if(preg_match("/w/",$tabacl)){
655 $ldap = $this->config->get_ldap_link();
656 $ldap->cd($this->dn);
657 $ldap->cat($this->dn);
658 $old_attrs = $ldap->fetch();
660 $attrs= array();
661 if ($_POST['new_password'] == ""){
663 /* Remove password attribute
664 */
665 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
666 $attrs['objectClass'] = array();
667 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
668 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
669 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
670 }
671 }
672 }
673 $attrs['userPassword']= array();
674 } else {
676 /* Add/modify password attribute
677 */
678 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
679 $attrs['objectClass'] = array();
680 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
681 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
682 }
683 $attrs['objectClass'][] = "simpleSecurityObject";
684 }
686 if(class_available("passwordMethodCrypt")){
687 $pwd_m = new passwordMethodCrypt($this->config);
688 $pwd_m->set_hash("crypt/md5");
689 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
690 }else{
691 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
692 $attrs = array();
693 }
694 }
695 $ldap->modify($attrs);
696 if (!$ldap->success()){
697 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
698 }else{
699 if(class_available($plug)){
700 $p = new $plug($this->config,$this->dn);
701 $p->handle_post_events("modify");
702 }
703 }
705 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
706 }else{
707 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
708 }
709 }else{
710 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
711 }
712 session::un_set('objectinfo');
713 }
716 /********************
717 Delete system cancel
718 ********************/
720 /* Delete terminal canceled? */
721 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
722 $this->remove_lock();
723 session::un_set('objectinfo');
724 }
727 /********************
728 Action(s) for MULTIPLE
729 ********************/
731 /********************
732 SCHEDULE action in GOsa Daemon
733 ********************/
735 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
736 $this->dns = array();
737 $ids = $this->list_get_selected_items();
739 if(count($ids) && class_available("DaemonEvent")){
740 $mac= array();
742 $ldap = $this->config->get_ldap_link();
743 foreach($ids as $id){
744 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
745 $attrs= $ldap->fetch();
746 if (isset($attrs['macAddress'][0])){
747 $mac[]= $attrs['macAddress'][0];
748 }
749 }
750 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
751 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
752 $o_queue = new gosaSupportDaemon();
754 /* Skip installation or update trigerred events,
755 * if this entry is currently processing.
756 */
757 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
758 foreach($mac as $key => $mac_address){
759 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
761 $entry['STATUS'] = strtoupper($entry['STATUS']);
762 if($entry['STATUS'] == "PROCESSING" &&
763 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
764 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
765 unset($mac[$key]);
767 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
768 break;
769 }
770 }
771 }
772 }
774 /* Prepare event to be added
775 */
776 if(count($mac) && isset($events['BY_CLASS'][$type])){
777 $event = $events['BY_CLASS'][$type];
778 $this->systab = new $event['CLASS_NAME']($this->config);
779 $this->systab->add_targets($mac);
780 if(preg_match("/trigger_event/",$s_action)){
781 $this->systab->set_type(TRIGGERED_EVENT);
782 }else{
783 $this->systab->set_type(SCHEDULED_EVENT);
784 }
785 }
786 }
787 }
789 /* Insert scheduled events into queue */
790 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
791 $this->systab->save_object();
793 /* Save event
794 */
795 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
796 $o_queue = new gosaSupportDaemon();
797 $o_queue->append($this->systab);
798 if($o_queue->is_error()){
799 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
800 }else{
801 $this->systab = FALSE;
802 }
803 }
804 if(isset($_POST['abort_event_dialog'])){
805 $this->systab = FALSE;
806 }
807 }
810 /********************
811 Delete MULTIPLE entries requested, display confirm dialog
812 ********************/
814 if ($s_action=="del_multiple"){
815 $this->dns = array();
816 $ids = $this->list_get_selected_items();
818 $ui = get_userinfo();
819 $tabs = array(
820 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
821 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
822 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
823 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
824 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
825 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
826 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
827 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
828 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
831 if(count($ids)){
833 $disallowed = array();
834 foreach($ids as $id){
836 /* Get 'dn' from posted termlinst */
837 $attrs = $this->terminals[$id];
838 $type = $this->get_system_type($attrs);
839 $dn = $attrs['dn'];
840 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
841 if(preg_match("/d/",$acl)){
842 $this->dns[$id] = $dn;
843 }else{
844 $disallowed[] = $dn;
845 }
846 }
848 if(count($disallowed)){
849 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
850 }
852 if(count($this->dns)){
854 if ($user= get_multiple_locks($this->dns)){
855 return(gen_locked_message($user,$this->dns));
856 }
858 $dns_names = array();
859 foreach($this->dns as $dn){
860 add_lock ($dn, $this->ui->dn);
861 $dns_names[] = @LDAP::fix($dn);
862 }
864 /* Lock the current entry, so nobody will edit it during deletion */
865 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
866 $smarty->assign("multiple", true);
867 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
868 }
869 }
870 }
873 /********************
874 Delete MULTIPLE entries confirmed
875 ********************/
877 /* Confirmation for deletion has been passed. Users should be deleted. */
878 if (isset($_POST['delete_multiple_system_confirm'])){
880 $ui = get_userinfo();
881 $tabs = array(
882 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
883 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
884 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
885 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
886 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
887 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
888 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
889 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
890 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
893 /* Remove user by user and check acls before removeing them */
894 foreach($this->dns as $key => $dn){
896 /* Get 'dn' from posted termlinst */
897 $attrs = $this->terminals[$key];
898 $type= $this->get_system_type($attrs);
900 /* get object type */
901 $tabtype = "termtabs";
902 $tabobj = "TERMTABS";
903 $tabacl = "";
904 if(isset($tabs[$type])){
905 $tabtype = $tabs[$type]['TABCLASS'];
906 $tabobj = $tabs[$type]['CLASS'];
907 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
909 /* Load permissions for selected 'dn' and check if
910 we're allowed to remove this 'dn' */
911 if(preg_match("/d/",$tabacl)){
913 /* Delete request is permitted, perform LDAP action */
914 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
915 $this->systab= new termgeneric($this->config, $dn);
916 $this->systab->set_acl_base($dn);
917 $this->systab->remove_from_parent();
918 }elseif($tabtype=="phonetabs"){
919 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
920 $this->systab->set_acl_base($dn);
921 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
922 }else{
923 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
924 $this->systab->set_acl_base($dn);
925 $this->systab->delete();
926 }
927 unset ($this->systab);
928 $this->systab= NULL;
930 } else {
931 /* Normally this shouldn't be reached, send some extra
932 logs to notify the administrator */
933 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
934 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
935 }
936 }
938 /* Remove lock file after successfull deletion */
939 $this->remove_lock();
940 $this->dns = array();
941 }
942 }
944 /********************
945 Delete MULTIPLE entries Canceled
946 ********************/
948 /* Remove lock */
949 if(isset($_POST['delete_multiple_system_cancel'])){
951 /* Remove lock file after successfull deletion */
952 $this->remove_lock();
953 $this->dns = array();
954 }
957 /********************
958 Delete system, confirm dialog
959 ********************/
961 /* Remove terminal was requested */
962 if ($s_action=="del"){
964 /* Get 'dn' from posted termlinst */
965 $this->dn = $this->terminals[$s_entry]['dn'];
966 $attrs = $this->terminals[$s_entry];
970 $type= $this->get_system_type($attrs);
971 $ui = get_userinfo();
972 $tabs = array(
973 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
974 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
975 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
976 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
977 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
978 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
979 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
980 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
981 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
983 /* get object type */
984 $tabtype = "termtabs";
985 $tabobj = "TERMTABS";
986 $tabacl = "";
987 if(isset($tabs[$type])){
988 $tabtype = $tabs[$type]['TABCLASS'];
989 $tabobj = $tabs[$type]['CLASS'];
990 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
991 }
993 /* Load permissions for selected 'dn' and check if
994 we're allowed to remove this 'dn' */
995 if(preg_match("/d/",$tabacl)){
997 /* Check locking, save current plugin in 'back_plugin', so
998 the dialog knows where to return. */
999 if (($user= get_lock($this->dn)) != ""){
1000 return(gen_locked_message ($user, $this->dn));
1001 }
1003 /* Lock the current entry, so nobody will edit it during deletion */
1004 add_lock ($this->dn, $this->ui->dn);
1005 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
1006 $smarty->assign("multiple", false);
1007 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
1008 } else {
1010 /* Obviously the user isn't allowed to delete. Show message and
1011 clean session. */
1012 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1013 }
1014 }
1017 /********************
1018 Delete system, confirmed
1019 ********************/
1020 /* Confirmation for deletion has been passed. Terminal should be deleted. */
1021 if (isset($_POST['delete_terminal_confirm'])){
1023 /* Find out more about the object type */
1024 $ldap= $this->config->get_ldap_link();
1025 $ldap->cat($this->dn, array('objectClass'));
1026 $attrs= $ldap->fetch();
1027 $type= $this->get_system_type($attrs);
1029 $ui = get_userinfo();
1031 $tabs = array(
1032 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
1033 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
1034 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
1035 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
1036 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
1037 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
1038 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
1039 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
1040 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
1042 /* get object type */
1043 $tabtype = "termtabs";
1044 $tabobj = "TERMTABS";
1045 $tabacl = "";
1046 if(isset($tabs[$type])){
1047 $tabtype = $tabs[$type]['TABCLASS'];
1048 $tabobj = $tabs[$type]['CLASS'];
1049 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
1050 }
1052 /* Check if we are allowed to remove this object */
1053 if(preg_match("/d/",$tabacl)){
1055 /* Delete request is permitted, perform LDAP action */
1056 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
1057 $this->systab= new termgeneric($this->config, $this->dn);
1058 $this->systab->set_acl_base($this->dn);
1059 $this->systab->remove_from_parent();
1060 }elseif($tabtype=="phonetabs"){
1061 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
1062 $this->systab->set_acl_base($this->dn);
1063 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
1064 }else{
1065 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
1066 $this->systab->set_acl_base($this->dn);
1067 $this->systab->delete();
1068 }
1069 unset ($this->systab);
1070 $this->systab= NULL;
1072 /* Terminal list has changed, reload it. */
1073 } else {
1075 /* Normally this shouldn't be reached, send some extra
1076 logs to notify the administrator */
1077 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1078 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1079 }
1081 /* Remove lock file after successfull deletion */
1082 $this->remove_lock();
1083 }
1086 /********************
1087 Edit system type finished, check if everything went ok
1088 ********************/
1089 /* Finish user edit is triggered by the tabulator dialog, so
1090 the user wants to save edited data. Check and save at this
1091 point. */
1093 /* Dirty workaround - MSG_DIALOG - OK
1094 If a message dialog is shown and we press 'OK'
1095 then try to save again.
1096 */
1097 foreach($_POST as $name => $value){
1098 if(preg_match("/^MSG_OK/",$name)){
1099 $_POST[$this->last_action] = TRUE;
1100 }
1101 }
1103 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1105 /* If the save routine gets interrupted by a confirm dialog,
1106 store last action so we can trigger it again after 'Ok' was pressed.
1107 (This is the case if a system gets modified while it is installing - GOsa si)
1108 */
1109 $this->last_action = "";
1110 if(isset($_POST['edit_finish'])){
1111 $this->last_action = "edit_finish";
1112 }elseif(isset($_POST['edit_apply'])){
1113 $this->last_action = "edit_apply";
1114 }
1116 /* Check tabs, will feed message array */
1117 $message = $this->systab->check();
1119 /* Save, or display error message? */
1120 if (count($message) == 0){
1123 $this->systab->save();
1125 /* Terminal has been saved successfully, remove lock from LDAP. */
1126 if (!isset($_POST['edit_apply'])){
1127 if ($this->dn != "new"){
1128 $this->remove_lock();
1129 }
1131 unset ($this->systab);
1132 $this->systab= NULL;
1133 session::un_set('objectinfo');
1134 }else{
1136 /* Reinitialize tab */
1137 if($this->systab instanceof tabs){
1138 $this->systab->re_init();
1139 }
1140 }
1141 } else {
1142 /* Ok. There seem to be errors regarding to the tab data,
1143 show message and continue as usual. */
1144 msg_dialog::displayChecks($message);
1145 }
1146 }
1149 /********************
1150 Edit system was canceled
1151 ********************/
1152 /* Cancel dialogs */
1153 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1154 if (isset($this->systab)){
1155 $this->remove_lock();
1156 unset ($this->systab);
1157 }
1158 $this->systab= NULL;
1159 session::un_set('objectinfo');
1160 }
1162 /********************
1163 Display edit dialog, or some other
1164 ********************/
1166 /* Show tab dialog if object is present */
1167 if (isset($this->systab->config)){
1168 $display= $this->systab->execute();
1170 /* Don't show buttons if tab dialog requests this */
1172 $dialog = FALSE;
1173 $hide_apply = $this->dn == "new";
1174 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1175 if(is_object($this->systab) && !isset($this->systab->by_object)){
1176 $dialog = TRUE;
1177 $hide_apply = TRUE;
1178 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1179 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1180 if($dia === TRUE || is_object($dia)){
1181 $dialog = TRUE;
1182 }
1183 }
1184 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1185 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1186 $dialog = TRUE;
1187 }
1189 if (!$dialog){
1190 $display.= "<p style=\"text-align:right\">\n";
1191 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1192 $display.= " \n";
1193 if (!$hide_apply){
1194 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1195 $display.= " \n";
1196 }
1197 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1198 $display.= "</p>";
1199 }
1200 return ($display);
1201 }
1203 /* Check if there is a snapshot dialog open */
1204 $base = $this->DivListSystem->selectedBase;
1205 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1206 return($str);
1207 }
1209 /* Display dialog with system list */
1210 $this->DivListSystem->parent = $this;
1211 $this->DivListSystem->execute();
1213 /* Add departments if subsearch is disabled */
1214 if(!$this->DivListSystem->SubSearch){
1216 /* Add FAIstate to attributes if FAI is activated */
1217 if($this->fai_activated){
1218 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1219 }else{
1220 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1221 }
1222 }
1223 $this->reload();
1224 $this->DivListSystem->setEntries($this->terminals);
1225 return($this->DivListSystem->Draw());
1226 }
1229 /* Return departments, that will be included within snapshot detection */
1230 function get_used_snapshot_bases()
1231 {
1232 $tmp = array();
1234 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1236 $tabs = array(
1237 "terminal" => get_ou('terminalou'),
1238 "workstation" => get_ou('workstationou'),
1239 "incoming" => get_ou('incomingou'),
1240 "server" => get_ou('serverou'),
1241 "printer" => get_ou('printerou'),
1242 "phone" => get_ou('phoneou'),
1243 "winworkstation" => get_winstations_ou(),
1244 "component" => get_ou('componentou')
1245 );
1247 foreach($tabs as $acl_cat => $dn){
1249 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1250 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1251 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1252 }
1253 }
1254 return($tmp);
1255 }
1258 function remove_from_parent()
1259 {
1260 /* Optionally execute a command after we're done */
1261 $this->postremove();
1262 }
1265 /* Save data to object */
1266 function save_object()
1267 {
1268 $this->DivListSystem->save_object();
1269 if(is_object($this->CopyPasteHandler)){
1270 $this->CopyPasteHandler->save_object();
1271 }
1272 }
1275 /* Check values */
1276 function check()
1277 {
1278 }
1281 /* Save to LDAP */
1282 function save()
1283 {
1284 }
1286 function adapt_from_template($dn, $skip= array())
1287 {
1288 }
1290 function password_change_needed()
1291 {
1292 }
1294 function reload()
1295 {
1296 /* some var init */
1297 $ui = get_userinfo();
1298 $res = array();
1299 $this->terminals = array();
1300 $userregex = "";
1302 /* Set base for all searches */
1303 $base= $this->DivListSystem->selectedBase;
1305 /* Prepare samba class name */
1306 $samba ="";
1307 if ($this->DivListSystem->ShowWinWorkstations){
1308 if ($this->config->current['SAMBAVERSION'] == "3"){
1309 $samba= "sambaSamAccount";
1310 } else {
1311 $samba= "sambaAccount";
1312 }
1313 }
1315 /* This array represents the combination between checkboxes and search filters */
1316 $objs = array(
1317 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1318 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1319 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1320 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1321 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1322 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1323 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1325 /* Include the 'Display Systems of user' attribute */
1326 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1327 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1328 }
1330 /* Attributes to fetch */
1331 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1332 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1334 /* Add FAIstate to attributes if FAI is activated */
1335 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1336 if(!empty($tmp)){
1337 $sys_attrs[] = "FAIstate";
1338 }
1340 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1341 foreach($objs as $checkBox => $oc){
1342 if($this->DivListSystem->$checkBox){
1343 if($this->DivListSystem->SubSearch){
1344 if($oc['CLASS'] != ""){
1345 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1346 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1347 $res = array_merge($res,$new_res);
1348 }
1349 }else{
1350 /* User filter? */
1351 if($oc['CLASS'] != ""){
1352 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1353 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1354 }
1355 }
1356 }
1357 }
1359 /* Search for incoming objects */
1360 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1361 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1363 /* Get all gotoTerminal's */
1364 foreach ($res as $value){
1366 $tmp= $value['dn'];
1367 $add= "";
1369 /* Extract base */
1370 foreach($objs as $obj){
1371 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1372 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1373 }
1374 }
1376 /* Create a string containing the last part of the department. */
1377 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1378 if(empty($dn_name)){
1379 $dn_name = "/";
1380 }
1382 /* check if current object is a new one */
1383 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1384 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1385 $add= "- "._("New terminal");
1386 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1387 $add= "- "._("New workstation");
1388 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1389 $add= "- "._("Unknown device");
1390 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1391 $add= "- "._("New Device");
1392 }
1393 }
1395 /* Detect type of object and create an entry for $this->terminals */
1396 $terminal = array();
1397 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1399 /* check acl */
1400 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1401 if($add != "" || preg_match("/r/",$acl)) {
1402 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1403 $terminal = $value;
1404 $terminal['type'] = "T";
1405 $terminal['is_new'] = $add;
1406 } else {
1407 $terminal = $value;
1408 $terminal['type'] = "D";
1409 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1410 $terminal['location'] = array_search($tmp, $this->config->departments);
1411 }
1412 }
1413 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1415 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1416 if($add != "" || preg_match("/r/",$acl)) {
1417 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1418 $terminal = $value;
1419 $terminal['type'] = "L";
1420 $terminal['is_new'] = $add;
1421 } else {
1422 $terminal = $value;
1423 $terminal['type'] = "D";
1424 $terminal['location'] = array_search($tmp, $this->config->departments);
1425 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1426 }
1427 # if (isset($value["FAIstate"][0])){
1428 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1429 # }
1430 }
1431 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1434 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1435 if($add != "" || preg_match("/r/",$acl)) {
1437 $terminal = $value;
1438 $terminal['type'] = "P";
1439 }
1440 } elseif (in_array_ics('goServer', $value["objectClass"])){
1442 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1443 if($add != "" || preg_match("/r/",$acl)) {
1445 $terminal = $value;
1446 $terminal['type'] = "S";
1447 # if (isset($value["FAIstate"][0])){
1448 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1449 # }
1450 }
1451 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1453 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1454 if($add != "" || preg_match("/r/",$acl)) {
1456 $terminal = $value;
1457 $terminal['type'] = "F";
1458 }
1459 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1461 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1462 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1463 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1464 if($add != "" || preg_match("/r/",$acl)) {
1466 $terminal = $value;
1467 $terminal['type'] = "Q";
1468 $terminal['is_new'] = $add;
1469 }
1470 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1472 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1473 if($add != "" || preg_match("/r/",$acl)) {
1475 $terminal = $value;
1476 $terminal['type'] = "C";
1477 }
1478 } else{
1480 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1481 if (isset($value['sambaDomainName'])){
1482 $domain= " [".$value['sambaDomainName'][0]."]";
1483 } else {
1484 $domain= "";
1485 }
1486 $terminal=$value;
1487 $terminal['type'] ="W";
1488 $terminal['domain'] = $name.$domain;
1489 }
1491 if(count($terminal)){
1492 $this->terminals[]=$terminal;
1493 }
1494 }
1496 $tmp =array();
1497 $tmp2 =array();
1498 foreach($this->terminals as $tkey => $val ){
1499 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1500 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1501 }
1502 natcasesort($tmp2);
1503 $this->terminals=array();
1504 foreach($tmp2 as $val){
1505 $this->terminals[]=$tmp[$val];
1506 }
1507 reset ($this->terminals);
1508 }
1510 function remove_lock()
1511 {
1512 if (isset($this->systab->dn)){
1513 del_lock ($this->systab->dn);
1514 }
1515 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1516 del_lock($this->dn);
1517 }
1518 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1519 del_lock($this->dns);
1520 }
1521 }
1524 function copyPasteHandling_from_queue($s_action,$s_entry)
1525 {
1526 /* Check if Copy & Paste is disabled */
1527 if(!is_object($this->CopyPasteHandler)){
1528 return("");
1529 }
1531 $ui = get_userinfo();
1533 $tabs = array(
1534 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1535 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1536 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1537 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1538 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1539 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1540 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1541 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1542 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1543 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1544 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1545 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1547 /* Add a single entry to queue */
1548 if($s_action == "cut" || $s_action == "copy"){
1550 /* Cleanup object queue */
1551 $this->CopyPasteHandler->cleanup_queue();
1552 $dn = $this->terminals[$s_entry]['dn'];
1553 $oc = $this->terminals[$s_entry]['objectClass'];
1554 $type = $this->get_system_type($this->terminals[$s_entry]);
1556 $tab_o = $tabs[$type]['CLASS'];
1557 $tab_c = $tabs[$type]['TABCLASS'];
1558 $acl_c = $tabs[$type]['TABNAME'];
1559 $acl = $tabs[$type]['ACL'];
1561 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1562 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1563 }
1564 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1565 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1566 }
1567 }
1569 /* Add entries to queue */
1570 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1572 /* Cleanup object queue */
1573 $this->CopyPasteHandler->cleanup_queue();
1575 /* Add new entries to CP queue */
1576 foreach($this->list_get_selected_items() as $id){
1577 $dn = $this->terminals[$id]['dn'];
1578 $oc = $this->terminals[$id]['objectClass'];
1579 $type = $this->get_system_type($this->terminals[$id]);
1581 if(isset($tabs[$type])){
1582 $tab_o = $tabs[$type]['CLASS'];
1583 $tab_c = $tabs[$type]['TABCLASS'];
1584 $acl_c = $tabs[$type]['TABNAME'];
1585 $acl = $tabs[$type]['ACL'];
1587 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1588 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1589 }
1590 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1591 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1592 }
1593 }
1594 }
1595 }
1597 /* Start pasting entries */
1598 if($s_action == "editPaste"){
1599 $this->start_pasting_copied_objects = TRUE;
1600 }
1602 /* Return C&P dialog */
1603 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1605 /* Get dialog */
1606 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1607 $data = $this->CopyPasteHandler->execute();
1609 /* Return dialog data */
1610 if(!empty($data)){
1611 return($data);
1612 }
1613 }
1615 /* Automatically disable status for pasting */
1616 if(!$this->CopyPasteHandler->entries_queued()){
1617 $this->start_pasting_copied_objects = FALSE;
1618 }
1619 return("");
1620 }
1623 function get_system_type($attrs)
1624 {
1625 $classes = $attrs['objectClass'];
1627 $type= "";
1628 if (in_array_ics('ieee802Device', $classes)){
1629 $type= "component";
1630 }elseif (in_array_ics('gotoTerminal', $classes)){
1631 $type= "terminal";
1632 }elseif (in_array_ics('gotoWorkstation', $classes)){
1633 $type= "workstation";
1634 }elseif (in_array_ics('gotoPrinter', $classes)){
1635 $type= "printer";
1636 }elseif (in_array_ics('goFonHardware', $classes)){
1637 $type= "phone";
1638 }elseif (in_array_ics('goServer', $classes)){
1639 $type= "server";
1640 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1641 $type= "ArpNewDevice";
1642 }elseif (in_array_ics('GOhard', $classes)){
1643 $type= "NewDevice";
1644 }elseif (in_array_ics('sambaAccount', $classes) ||
1645 in_array_ics('sambaSamAccount', $classes)){
1646 $type= "winstation";
1647 }
1648 return ($type);
1649 }
1652 function convert_list($input)
1653 {
1654 $temp= "";
1656 $conv= array(
1657 "D" => array("select_default.png",_("Template")),
1658 "F" => array("select_phone.png",_("Phone")),
1659 "C" => array("select_component.png",_("Network device")),
1660 "P" => array("select_printer.png",_("Printer")),
1662 "W" => array("select_winstation.png",_("Win workstation")),
1664 "L" => array("select_workstation.png",_("Workstation")),
1665 "S" => array("select_server.png",_("Server")),
1666 "T" => array("select_terminal.png",_("Terminal")),
1668 "LX" => array("workstation_locked.png",_("Locked workstation")),
1669 "SX" => array("server_locked.png",_("Locked server")),
1670 "TX" => array("terminal_locked.png",_("Locked terminal")),
1672 "LE" => array("workstation_error.png",_("Workstation error")),
1673 "SE" => array("server_error.png",_("Server error")),
1674 "TE" => array("terminal_error.png",_("Terminal error")),
1676 "LB" => array("workstation_busy.png",_("Workstation busy")),
1677 "SB" => array("server_busy.png",_("Server busy")),
1679 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1680 "NT"=> array("select_new_terminal.png",_("New terminal")),
1681 "NL"=> array("select_new_workstation.png",_("New workstation")));
1683 /* Use locked icons
1684 */
1685 if( in_array($input['type'],array("S","T","L")) &&
1686 isset($input['gotoMode'][0]) &&
1687 preg_match("/locked/",$input['gotoMode'][0])){
1688 $input['type'].="X";
1689 } elseif(in_array($input['type'],array("S","L")) &&
1690 isset($input['FAIstate'][0])){
1692 /* Add FAI state icons
1693 */
1694 $type= "";
1695 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1696 case 'error':
1697 $type= 'E';
1698 break;
1699 case 'installing':
1700 case 'install':
1701 case 'sysinfo':
1702 case 'softupdate':
1703 case 'scheduledupdate':
1704 $type= 'B';
1705 break;
1706 }
1708 $input['type'].= $type;
1709 }
1711 /* Use new images if object is from incoming
1712 */
1713 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1714 $input['type']="N".$input['type'];
1715 }
1717 /* Check which flags this objects uses
1718 */
1719 foreach ($conv as $key => $value){
1720 $found = TRUE;
1721 if(strlen($key) != strlen($input['type'])) {
1722 $found = FALSE;
1723 }
1724 for($i = 0 ; $i < strlen($key) ; $i++){
1725 if(!preg_match("/".$key[$i]."/",$input['type'])){
1726 $found = FALSE;
1727 }
1728 }
1730 if($found){
1731 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1732 $tmp['class']=$key;
1733 return $tmp;
1734 }
1735 }
1736 }
1739 function list_get_selected_items()
1740 {
1741 $ids = array();
1742 foreach($_POST as $name => $value){
1743 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1744 $id = preg_replace("/^item_selected_/","",$name);
1745 $ids[$id] = $id;
1746 }
1747 }
1748 return($ids);
1749 }
1752 /* !! Incoming dummy acls, required to defined acls for incoming objects
1753 */
1754 static function plInfo()
1755 {
1756 return (array(
1757 "plShortName" => _("Incoming objects"),
1758 "plDescription" => _("Incoming objects"),
1759 "plSelfModify" => FALSE,
1760 "plDepends" => array(),
1761 "plPriority" => 99,
1762 "plSection" => array("administration"),
1763 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1764 "objectClass" => "")),
1765 "plProvidedAcls"=> array()
1767 ));
1768 }
1769 }
1771 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1772 ?>