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 $plIcon = "plugins/systems/images/plugin.png";
29 var $departments = array();
31 /* Dialog attributes */
32 var $systab = NULL;
33 var $terminals= array();
34 var $ui = NULL;
35 var $DivListSystem;
36 var $start_pasting_copied_objects = FALSE;
37 var $CopyPasteHandler = NULL;
39 /* Arp hanlding activated */
40 var $arp_handling_active = FALSE;
41 var $last_action = "";
43 var $dns = array();
45 var $system_activation_object = ""; // The object to activate (NewDevice)
46 var $fai_activated = FALSE;
47 var $si_active = FALSE;
49 var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
51 var $opsi = NULL;
53 function systems (&$config, $ui)
54 {
55 /* Save configuration for internal use */
56 $this->config= $config;
57 $this->ui= $ui;
59 /* Add FAIstate to attributes if FAI is activated */
60 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
61 if(!empty($tmp)){
62 $this->fai_activated = TRUE;
63 }
65 /* Copy & Paste enabled ?*/
66 if ($this->config->get_cfg_value("copyPaste") == "true"){
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 }
82 /* Check if we are able to communicate with the GOsa supprot daemon
83 */
84 if(class_available("opsi")){
85 $this->opsi = new opsi($this->config);
86 }
88 /* Creat dialog object */
89 $this->DivListSystem = new divListSystem($this->config,$this);
90 }
93 function execute()
94 {
95 /* Call parent execute */
96 plugin::execute();
98 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
100 /********************
101 Check for functional posts, edit|delete|add|... system devices
102 ********************/
103 $s_action = ""; // Contains the action to proceed
104 $s_entry = ""; // The value for s_action
105 $base_back = ""; // The Link for Backbutton
106 $smarty = get_smarty();
108 /* Test Posts */
109 foreach($_POST as $key => $val){
110 // Post for delete
111 if(preg_match("/system_del.*/",$key)){
112 $s_action = "del";
113 $s_entry = preg_replace("/system_del_/i","",$key);
114 // Post for edit
115 }elseif(preg_match("/system_edit_.*/",$key)){
116 $s_action="edit";
117 $s_entry = preg_replace("/system_edit_/i","",$key);
118 // Post for new
119 }elseif(preg_match("/system_new.*/",$key)){
120 $s_action="new";
121 }elseif(preg_match("/system_tplnew.*/i",$key)){
122 $s_action="new_tpl";
123 }elseif(preg_match("/system_setpwd_.*/i",$key)){
124 $s_action="change_pw";
125 $s_entry = preg_replace("/system_setpwd_/i","",$key);
126 }elseif(preg_match("/gen_cd_.*/i",$key)){
127 $s_action="gen_cd";
128 $s_entry = preg_replace("/gen_cd_/i","",$key);
129 }elseif(preg_match("/^copy_.*/",$key)){
130 $s_action="copy";
131 $s_entry = preg_replace("/^copy_/i","",$key);
132 }elseif(preg_match("/^cut_.*/",$key)){
133 $s_action="cut";
134 $s_entry = preg_replace("/^cut_/i","",$key);
135 }
136 }
138 /* remove image tags from posted entry (posts looks like this 'name_x')*/
139 $s_entry = preg_replace("/_.$/","",$s_entry);
141 /* Edit was requested by pressing the name(link) of an item */
142 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
143 $s_action ="edit";
144 $s_entry = $_GET['id'];
145 }
146 /* Create options */
147 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
148 $s_action = "newsystem";
149 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
150 }
152 /* handle C&P from layers menu */
153 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
154 $s_action = "copy_multiple";
155 }
156 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
157 $s_action = "cut_multiple";
158 }
159 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
160 $s_action = "editPaste";
161 }
163 /* Handle daemon events */
164 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
165 $s_action = $_POST['menu_action'];
166 }
168 /* Handle daemon events */
169 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
170 $s_action = $_POST['menu_action'];
171 }
173 /* handle remove from layers menu */
174 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
175 $s_action = "del_multiple";
176 }
178 /* Handle instant actions from layers menu */
179 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
180 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
181 $s_action = "${act}_multiple";
182 }
183 }
185 /* Activate multiple machines */
186 if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
187 $s_action = "activate_multiple";
188 }
190 /* Check for exeeded sizelimit */
191 if (($message= check_sizelimit()) != ""){
192 return($message);
193 }
195 /* Try to get informations about what kind of system to create */
196 if ($s_action=="new") {
197 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
198 }
200 /* Incoming handling
201 * If someone made a systemtype and ogroup selection
202 * Display the new requested entry type ... servtab in case of server and so on.
203 */
204 if(isset($_POST['SystemTypeChoosen'])){
205 $s_action = "SelectedSystemType";
206 }
208 /********************
209 Copy & Paste Handling ...
210 ********************/
212 /* Display the copy & paste dialog, if it is currently open */
213 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
214 if($ret){
215 return($ret);
216 }
219 /********************
220 Create FAI CD ...
221 ********************/
222 if ($s_action=="gen_cd"){
223 $this->dn= $this->terminals[$s_entry]['dn'];
224 set_object_info($this->dn);
225 return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE)));
226 }
229 /* Start CD-Creation */
230 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
231 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
232 return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE)));
233 }
236 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
238 $return_button = "<form method='get' action='main.php' target='_parent'>
239 <input type='submit' value='"._("Back")."'>
240 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
241 </form>";
243 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
245 /* Get and check command */
246 $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
248 if (check_command($command)){
249 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
251 /* Print out html introduction */
252 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
253 <html>
254 <head>
255 <title></title>
256 <style type="text/css">@import url("themes/default/style.css");</style>
257 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
258 </head>
259 <body style="background: none; margin:4px;" id="body" >
260 <pre>';
262 /* Open process handle and check if it is a valid process */
263 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
264 if (is_resource($process)) {
265 fclose($pipes[0]);
267 /* Print out returned lines && write JS to scroll down each line */
268 while (!feof($pipes[1])){
269 $cur_dat = fgets($pipes[1], 1024);
270 echo $cur_dat;
271 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
272 flush();
273 }
274 }
276 /* Get error string && close streams */
277 $buffer= stream_get_contents($pipes[2]);
279 fclose($pipes[1]);
280 fclose($pipes[2]);
281 echo "</pre>";
283 /* Check return code */
284 $ret= proc_close($process);
285 if ($ret != 0){
286 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
287 echo "<pre style='color:red'>$buffer</pre>";
288 }
292 echo $return_button."<br>";
294 } else {
295 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
296 echo $tmp;
297 }
299 /* Scroll down completly */
300 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
301 echo '</body></html>';
302 flush();
303 exit;
304 }
307 /********************
308 New Device handling (Ogroup/System select dialog.)
309 ********************/
311 /* All objects that have to be activated are listed in
312 $this->system_activation_object[] = "dn";
314 If there is an object group selected we simply adopt all
315 settings from these group and then directly save the entry again.
316 If no object group was selected, then we keep the "edit" dialog of
317 the target system opened to allow to edit the objects attributes.
318 */
320 if($this->systab instanceOf ArpNewDeviceTabs &&
321 isset($_POST['edit_finish']) &&
322 isset($_POST['gotoIntegration'])){
324 $this->systab->save_object();
326 if($this->systab->by_object['ArpNewDevice']->gotoIntegration){
328 /* Check tabs, will feed message array */
329 $message = $this->systab->check();
330 if(count($message)){
331 msg_dialog::displayChecks($message);
332 }else{
333 $s_action = "SelectedSystemType";
334 $this->systab->save();
335 $this->systab = null;
336 unset($_POST['edit_finish']);
337 }
338 }
339 }
341 if($s_action == "SelectedSystemType"){
343 /* Possible destination system types
344 */
345 $tabs = $this->get_tab_defs();
347 /* Remember dialog selection.
348 */
350 $selected_group = "none";
351 if(isset($_POST['ObjectGroup'])){
352 $selected_group = $_POST['ObjectGroup'];
353 }
354 $selected_system = $_POST['SystemType'];
356 $this->systab = NULL;
358 /* Check if system type exists. It should! */
359 if(isset($tabs[$selected_system])){
361 /* Get tab informations */
362 $class = $tabs[$selected_system]["CLASS"];
363 $tabname = $tabs[$selected_system]["TABNAME"];
364 $tabclass = $tabs[$selected_system]["TABCLASS"];
365 $acl_cat = $tabs[$selected_system]["ACLC"];
368 if(!class_available($tabclass)){
369 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
370 }else{
372 /* Go through all objects that should be activated
373 Contains alls object dns that have to be activated ("New Devices" not unknown)
374 */
375 foreach($this->system_activation_object as $key => $dn){
377 /* Remove entry from list, to avoid page-reload problems */
378 unset($this->system_activation_object[$key]);
380 /* Load permissions for selected 'dn' and check if
381 we're allowed to create this 'dn' */
382 $this->dn = $dn;
383 $ui = get_userinfo();
384 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
386 /* We are allowed to create the requested system type */
387 if(preg_match("/c/",$tabacl)){
388 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
389 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
390 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
391 $this->systab->base = $this->DivListSystem->selectedBase;
393 /* This will be used when the object is saved, to set FAIstate to 'install'
394 and to preset maybe other attributes.
395 */
396 $this->systab->was_activated = TRUE;
398 /* Assign some default values for opsi hosts
399 */
400 if($this->systab instanceOf opsi_tabs){
401 $ldap = $this->config->get_ldap_link();
402 $ldap->cat($dn);
403 $source_attrs = $ldap->fetch();
404 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
405 if(isset($source_attrs[$src][0])){
406 $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
407 }
408 }
409 }
411 if($selected_group != "none"){
413 /*******
414 * Set gotoMode to active if there was an ogroup selected.
415 */
416 $found = false;
417 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
418 if(isset($this->systab->by_object[$tab]->gotoMode)) {
419 $found = true;
420 $this->systab->by_object[$tab]->gotoMode = $value;
421 }
422 }
423 if(!$found){
424 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
425 }
427 /*******
428 * Update object group membership
429 */
430 $og = new ogroup($this->config,$selected_group);
431 if($og){
432 $og->AddDelMembership($this->systab->dn);
433 $og->save();
434 }
436 /*******
437 * Set default system specific attributes
438 */
439 foreach (array("workservice", "termservice") as $cls){
440 if (isset($this->systab->by_object[$cls])){
441 $this->systab->by_object[$cls]->gotoXMouseport= "";
442 $this->systab->by_object[$cls]->gotoXMouseType= "";
443 $this->systab->by_object[$cls]->gotoXResolution= "";
444 $this->systab->by_object[$cls]->gotoXColordepth= "";
445 }
446 }
448 // Enable activation
449 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
450 if (isset($this->systab->by_object[$cls])){
451 $this->systab->by_object[$cls]->auto_activate= TRUE;
452 }
453 }
455 // Enable sending of LDAP events
456 if (isset($this->systab->by_object["workstartup"])){
457 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
458 }
459 }
461 /* Don't save directly if there is no objectGroup selected.
462 The user will then be able to configure the missing attributes
463 on his own.
464 */
465 if($selected_group != "none"){
466 $this->systab->save();
468 /* Post handling for activated new devices
469 */
470 $this->activate_new_device($this->systab->dn);
471 $this->systab = NULL;
473 if(!isset($ldap)){
474 $ldap = $this->config->get_ldap_link();
475 }
476 $ldap->cd ($this->dn);
477 $ldap->cat($this->dn, array('dn'));
478 if(count($ldap->fetch())){
479 $ldap->cd($this->dn);
480 $ldap->rmDir($this->dn);
481 }
482 }
483 }else{
484 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
485 }
486 }
487 }
488 }
489 }
492 if (isset($_POST['create_system'])||$s_action=="newsystem") {
494 $this->last_action = "";
496 /* If the current entry is an incoming object
497 * $sw = System type as posted in new incoming handling dialog
498 */
499 if(isset($_POST['system'])){
500 $sw = $_POST['system'];
501 }else{
502 $sw = $s_entry;
503 }
504 $this->dn= "new";
506 $tabs = $this->get_tab_defs();
508 if(isset($tabs[$sw])){
509 $class = $tabs[$sw]["CLASS"];
510 $tabname = $tabs[$sw]["TABNAME"];
511 $tabclass = $tabs[$sw]["TABCLASS"];
512 $acl_cat = $tabs[$sw]["ACLC"];
514 /* Load permissions for selected 'dn' and check if
515 we're allowed to remove this 'dn' */
516 $ui = get_userinfo();
517 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
518 if(preg_match("/c/",$tabacl)){
520 if(!class_available($tabclass)){
521 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
522 }else{
523 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
524 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
525 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
526 $this->systab->base = $this->DivListSystem->selectedBase;
527 }
528 }else{
529 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
530 }
531 }
532 }
534 /********************
535 System activation
536 ********************/
538 /* User wants to edit data? */
539 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
540 $this->system_activation_object = array();
541 foreach($this->list_get_selected_items() as $id) {
542 $obj = $this->terminals[$id];
543 $type= $this->get_system_type($obj);
544 if($type == "NewDevice"){
545 $this->system_activation_object[] = $obj['dn'];
546 }
547 }
548 if(count($this->system_activation_object)){
549 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
550 }
551 }
554 /********************
555 Edit system ...
556 ********************/
558 /* User wants to edit data? */
559 if (($s_action == "edit") && (!isset($this->systab->config))){
560 $this->last_action = "";
561 $this->dn= $this->terminals[$s_entry]['dn'];
563 /* Check locking, save current plugin in 'back_plugin', so
564 the dialog knows where to return. */
565 if (($user= get_lock($this->dn)) != ""){
566 return(gen_locked_message ($user, $this->dn,TRUE));
567 }
569 /* Find out more about the object type */
570 $attrs = $this->terminals[$s_entry];
571 $type= $this->get_system_type($attrs);
573 /* Lock the current entry, so everyone will get the
574 above dialog */
575 $tabs = $this->get_tab_defs();
577 if($type == "ArpNewDevice"){
578 if(!class_available("ArpNewDeviceTabs")){
579 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
580 }else{
581 add_lock ($this->dn, $this->ui->dn);
582 $this->system_activation_object= array($this->dn);
583 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
584 }
585 }elseif($type == "NewDevice"){
586 if(!class_available("SelectDeviceType")){
587 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
588 }else{
589 add_lock ($this->dn, $this->ui->dn);
590 $this->system_activation_object= array($this->dn);
591 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
593 // see condition -$s_action == "SelectedSystemType"- for further handling
594 }
595 }elseif(isset($tabs[$type])){
597 $class = $tabs[$type]["CLASS"];
598 $acl_cat = $tabs[$type]["ACLC"];
599 $tabclass = $tabs[$type]["TABCLASS"];
601 if(!class_available($tabclass)){
602 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
603 }else{
604 add_lock ($this->dn, $this->ui->dn);
605 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
606 $this->systab->set_acl_base($this->dn);
607 set_object_info($this->dn);
608 }
609 }else{
610 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
611 $this->remove_lock();
612 }
613 }
616 /********************
617 Change password ...
618 ********************/
620 /* Set terminals root password */
621 if ($s_action=="change_pw"){
622 $tabs = $this->get_tab_defs();
624 $dn = $this->terminals[$s_entry]['dn'];
625 $type = $this->get_system_type($this->terminals[$s_entry]);
627 $class = $tabs[$type]["CLASS"];
628 $acl = $tabs[$type]["ACL"];
629 $tabclass = $tabs[$type]["TABCLASS"];
630 $ui = get_userinfo();
631 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
632 if(preg_match("/w/",$tabacl)){
633 $this->dn= $this->terminals[$s_entry]['dn'];
634 set_object_info($this->dn);
635 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
636 }else{
637 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
638 }
639 }
642 /********************
643 Password change finish, but check if entered data is ok
644 ********************/
646 /* Correctly specified? */
647 if (isset($_POST['password_finish'])){
648 if ($_POST['new_password'] != $_POST['repeated_password']){
649 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
650 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
651 }
652 }
654 /********************
655 Password change finish
656 ********************/
658 /* Change terminal password */
659 if (isset($_POST['password_finish']) &&
660 $_POST['new_password'] == $_POST['repeated_password']){
662 /* Check if user is allowed to set password */
663 $tabs = $this->get_tab_defs();
665 $type = "";
666 foreach($this->terminals as $terminal){
667 if($terminal['dn'] == $this->dn){
668 $type = $this->get_system_type($terminal);
669 break;
670 }
671 }
673 /* Type detected */
674 $allow_for = array("terminal","workstation","server","component");
675 if(!empty($type) && in_array($type,$allow_for)){
677 /* Get infos */
678 $plug = $tabs[$type]["TABNAME"];
679 $acl = $tabs[$type]["ACL"];
680 $tabclass = $tabs[$type]["TABCLASS"];
682 /* Get acls */
683 $ui = get_userinfo();
684 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
686 /* Check acls */
687 if(preg_match("/w/",$tabacl)){
688 $ldap = $this->config->get_ldap_link();
689 $ldap->cd($this->dn);
690 $ldap->cat($this->dn);
691 $old_attrs = $ldap->fetch();
693 $attrs= array();
694 if ($_POST['new_password'] == ""){
696 /* Remove password attribute
697 */
698 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
699 $attrs['objectClass'] = array();
700 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
701 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
702 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
703 }
704 }
705 }
706 $attrs['userPassword']= array();
707 } else {
709 /* Add/modify password attribute
710 */
711 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
712 $attrs['objectClass'] = array();
713 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
714 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
715 }
716 $attrs['objectClass'][] = "simpleSecurityObject";
717 }
719 if(class_available("passwordMethodCrypt")){
720 $pwd_m = new passwordMethodCrypt($this->config);
721 $pwd_m->set_hash("crypt/md5");
722 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
723 }else{
724 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
725 $attrs = array();
726 }
727 }
728 $ldap->modify($attrs);
729 if (!$ldap->success()){
730 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
731 }else{
732 if(class_available($plug)){
733 $p = new $plug($this->config,$this->dn);
734 $p->handle_post_events("modify");
735 }
736 }
738 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
739 }else{
740 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
741 }
742 }else{
743 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
744 }
745 set_object_info();
746 }
749 /********************
750 Delete system cancel
751 ********************/
753 /* Delete terminal canceled? */
754 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
755 $this->remove_lock();
756 set_object_info();
757 }
760 /********************
761 Action(s) for MULTIPLE
762 ********************/
764 /********************
765 SCHEDULE action in GOsa Daemon
766 ********************/
768 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
769 $this->dns = array();
770 $ids = $this->list_get_selected_items();
772 /* Handle opsi actions */
773 if($s_action == "trigger_event_DaemonEvent_reinstall"){
774 foreach($ids as $key => $id){
775 if($this->terminals[$id]['type'] == "O"){
776 $obj = $this->terminals[$id];
777 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
778 unset($ids[$key]);
779 }
780 }
781 }
783 if(count($ids) && class_available("DaemonEvent")){
784 $mac= array();
786 /* Collect target mac addresses */
787 $ldap = $this->config->get_ldap_link();
788 foreach($ids as $id){
789 $type = $this->get_system_type($this->terminals[$id]);
790 if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
791 if(isset($this->terminals[$id]['macAddress'][0])){
792 $mac[] = $this->terminals[$id]['macAddress'][0];
793 }else{
794 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
795 $attrs= $ldap->fetch();
796 if (isset($attrs['macAddress'][0])){
797 $mac[]= $attrs['macAddress'][0];
798 }
799 }
800 }
801 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
802 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
803 $o_queue = new gosaSupportDaemon();
805 /* Skip installation or update trigerred events,
806 * if this entry is currently processing.
807 */
808 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
809 foreach($mac as $key => $mac_address){
810 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
812 $entry['STATUS'] = strtoupper($entry['STATUS']);
813 if($entry['STATUS'] == "PROCESSING" &&
814 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
815 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
816 unset($mac[$key]);
818 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
819 break;
820 }
821 }
822 }
823 }
825 /* Prepare event to be added
826 */
827 if(count($mac) && isset($events['BY_CLASS'][$type])){
828 $event = $events['BY_CLASS'][$type];
829 $this->systab = new $event['CLASS_NAME']($this->config);
830 $this->systab->add_targets($mac);
831 if(preg_match("/trigger_event/",$s_action)){
832 $this->systab->set_type(TRIGGERED_EVENT);
833 }else{
834 $this->systab->set_type(SCHEDULED_EVENT);
835 }
836 }
837 }
838 }
840 /* Insert scheduled events into queue */
841 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
842 $this->systab->save_object();
844 /* Save event
845 */
846 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
847 $o_queue = new gosaSupportDaemon();
848 $o_queue->append($this->systab);
849 if($o_queue->is_error()){
850 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
851 }else{
852 $this->systab = FALSE;
853 }
854 }
855 if(isset($_POST['abort_event_dialog'])){
856 $this->systab = FALSE;
857 }
858 }
861 /********************
862 Delete MULTIPLE entries requested, display confirm dialog
863 ********************/
865 if ($s_action=="del_multiple" || $s_action == "del"){
866 $this->dns = array();
868 if($s_action == "del_multiple"){
869 $ids = $this->list_get_selected_items();
870 }else{
871 $ids = array($s_entry);
872 }
874 $ui = get_userinfo();
875 $tabs = $this->get_tab_defs();
877 if(count($ids)){
879 $disallowed = array();
880 foreach($ids as $id){
882 /* Get 'dn' from posted termlinst */
883 $attrs = $this->terminals[$id];
884 $type = $this->get_system_type($attrs);
885 $dn = $attrs['dn'];
886 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
887 if(preg_match("/d/",$acl)){
888 $this->dns[$id] = $dn;
889 }else{
890 $disallowed[] = $dn;
891 }
892 }
894 if(count($disallowed)){
895 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
896 }
898 if(count($this->dns)){
900 if ($user= get_multiple_locks($this->dns)){
901 return(gen_locked_message($user,$this->dns));
902 }
904 $dns_names = array();
905 foreach($this->dns as $dn){
906 add_lock ($dn, $this->ui->dn);
907 $dns_names[] = LDAP::fix($dn);
908 }
910 /* Lock the current entry, so nobody will edit it during deletion */
911 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
912 $smarty->assign("multiple", true);
913 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
914 }
915 }
916 }
919 /********************
920 Delete MULTIPLE entries confirmed
921 ********************/
923 /* Confirmation for deletion has been passed. Users should be deleted. */
924 if (isset($_POST['delete_multiple_system_confirm'])){
926 $ui = get_userinfo();
927 $tabs = $this->get_tab_defs();
929 /* Remove user by user and check acls before removeing them */
930 foreach($this->dns as $key => $dn){
932 /* Get 'dn' from posted termlinst */
933 $attrs = $this->terminals[$key];
934 $type= $this->get_system_type($attrs);
936 /* get object type */
937 $tabtype = "termtabs";
938 $tabobj = "TERMTABS";
939 $tabacl = "";
940 if(isset($tabs[$type])){
941 $tabtype = $tabs[$type]['TABCLASS'];
942 $tabobj = $tabs[$type]['CLASS'];
943 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
945 /* Load permissions for selected 'dn' and check if
946 we're allowed to remove this 'dn' */
947 if(preg_match("/d/",$tabacl)){
949 /* Delete request is permitted, perform LDAP action */
950 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
951 $this->systab= new termgeneric($this->config, $dn);
952 $this->systab->set_acl_base($dn);
953 $this->systab->remove_from_parent();
954 }elseif($tabtype=="phonetabs"){
955 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
956 $this->systab->set_acl_base($dn);
957 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
958 }else{
959 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
960 $this->systab->set_acl_base($dn);
961 $this->systab->delete();
962 }
963 unset ($this->systab);
964 $this->systab= NULL;
966 } else {
967 /* Normally this shouldn't be reached, send some extra
968 logs to notify the administrator */
969 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
970 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
971 }
972 }
974 /* Remove lock file after successfull deletion */
975 $this->remove_lock();
976 $this->dns = array();
977 }
978 }
980 /********************
981 Delete MULTIPLE entries Canceled
982 ********************/
984 /* Remove lock */
985 if(isset($_POST['delete_multiple_system_cancel'])){
987 /* Remove lock file after successfull deletion */
988 $this->remove_lock();
989 $this->dns = array();
990 }
993 /********************
994 Edit system type finished, check if everything went ok
995 ********************/
996 /* Finish user edit is triggered by the tabulator dialog, so
997 the user wants to save edited data. Check and save at this
998 point. */
1000 /* Dirty workaround - MSG_DIALOG - OK
1001 If a message dialog is shown and we press 'OK'
1002 then try to save again.
1003 */
1004 foreach($_POST as $name => $value){
1005 if(preg_match("/^MSG_OK/",$name)){
1006 $_POST[$this->last_action] = TRUE;
1007 }
1008 }
1010 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1012 /* If the save routine gets interrupted by a confirm dialog,
1013 store last action so we can trigger it again after 'Ok' was pressed.
1014 (This is the case if a system gets modified while it is installing - GOsa si)
1015 */
1016 $this->last_action = "";
1017 if(isset($_POST['edit_finish'])){
1018 $this->last_action = "edit_finish";
1019 }elseif(isset($_POST['edit_apply'])){
1020 $this->last_action = "edit_apply";
1021 }
1023 /* Check tabs, will feed message array */
1024 $message = $this->systab->check();
1026 /* Save, or display error message? */
1027 if (count($message) == 0){
1028 $this->systab->save();
1030 /* Post handling for activated systems
1031 target opsi -> Remove source.
1032 target gosa -> Activate system.
1033 */
1034 if($this->systab instanceOf opsi_tabs){
1035 $ldap = $this->config->get_ldap_link();
1036 $ldap->cd($this->config->current['BASE']);
1037 $ldap->rmdir ($this->systab->dn);
1038 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1040 $hostId = $this->systab->by_object['opsiGeneric']->hostId;
1041 $mac = $this->systab->by_object['opsiGeneric']->mac;
1042 $this->opsi->job_opsi_activate_client($hostId,$mac);
1044 }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1045 $this->activate_new_device($this->systab->dn);
1046 }
1048 /* Terminal has been saved successfully, remove lock from LDAP. */
1049 if (!isset($_POST['edit_apply'])){
1050 if ($this->dn != "new"){
1051 $this->remove_lock();
1052 }
1054 unset ($this->systab);
1055 $this->systab= NULL;
1056 set_object_info();
1057 }else{
1059 /* Reinitialize tab */
1060 if($this->systab instanceof tabs){
1061 $this->systab->re_init();
1062 }
1063 }
1064 } else {
1065 /* Ok. There seem to be errors regarding to the tab data,
1066 show message and continue as usual. */
1067 msg_dialog::displayChecks($message);
1068 }
1069 }
1072 /********************
1073 Edit system was canceled
1074 ********************/
1075 /* Cancel dialogs */
1076 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1077 if (isset($this->systab)){
1078 $this->remove_lock();
1079 unset ($this->systab);
1080 }
1081 $this->systab= NULL;
1082 set_object_info();
1083 }
1085 /********************
1086 Display edit dialog, or some other
1087 ********************/
1089 /* Show tab dialog if object is present */
1090 if (isset($this->systab->config)){
1092 if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1093 $this->systab->save_object();
1094 }
1096 $display= $this->systab->execute();
1098 /* Don't show buttons if tab dialog requests this */
1100 $dialog = FALSE;
1101 $hide_apply = $this->dn == "new";
1102 $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1103 if(is_object($this->systab) && !isset($this->systab->by_object)){
1104 $dialog = TRUE;
1105 $hide_apply = TRUE;
1106 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1107 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1108 if($dia === TRUE || is_object($dia)){
1109 $dialog = TRUE;
1110 }
1111 }
1112 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1113 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1114 $dialog = TRUE;
1115 }
1117 if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1118 $display.= "<p style=\"text-align:right\">
1119 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1120 </p>";
1121 }elseif (!$dialog){
1122 $display.= "<p style=\"text-align:right\">\n";
1123 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1124 $display.= " \n";
1125 if (!$hide_apply){
1126 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1127 $display.= " \n";
1128 }
1129 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1130 $display.= "</p>";
1131 }
1132 return ($display);
1133 }
1135 /* Check if there is a snapshot dialog open */
1136 $base = $this->DivListSystem->selectedBase;
1137 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1138 return($str);
1139 }
1141 /* Display dialog with system list */
1142 $this->DivListSystem->parent = $this;
1143 $this->DivListSystem->execute();
1145 /* Add departments if subsearch is disabled */
1146 if(!$this->DivListSystem->SubSearch){
1148 /* Add FAIstate to attributes if FAI is activated */
1149 if($this->fai_activated){
1150 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1151 }else{
1152 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1153 }
1154 }
1155 $this->reload();
1156 $this->DivListSystem->setEntries($this->terminals);
1157 return($this->DivListSystem->Draw());
1158 }
1161 /* Return departments, that will be included within snapshot detection */
1162 function get_used_snapshot_bases()
1163 {
1164 $tmp = array();
1166 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1168 $tabs = array(
1169 "terminal" => get_ou('terminalRDN'),
1170 "workstation" => get_ou('workstationRDN'),
1171 "incoming" => get_ou('systemIncomingRDN'),
1172 "server" => get_ou('serverRDN'),
1173 "printer" => get_ou('printerRDN'),
1174 "phone" => get_ou('phoneRDN'),
1175 "winworkstation" => get_winstations_ou(),
1176 "component" => get_ou('componentRDN')
1177 );
1179 foreach($tabs as $acl_cat => $dn){
1181 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1182 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1183 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1184 }
1185 }
1186 return($tmp);
1187 }
1190 function remove_from_parent()
1191 {
1192 /* Optionally execute a command after we're done */
1193 $this->postremove();
1194 }
1197 /* Save data to object */
1198 function save_object()
1199 {
1200 $this->DivListSystem->save_object();
1201 if(is_object($this->CopyPasteHandler)){
1202 $this->CopyPasteHandler->save_object();
1203 }
1204 }
1207 /* Check values */
1208 function check()
1209 {
1210 }
1213 /* Save to LDAP */
1214 function save()
1215 {
1216 }
1218 function adapt_from_template($dn, $skip= array())
1219 {
1220 }
1222 function password_change_needed()
1223 {
1224 }
1226 function reload()
1227 {
1228 /* some var init */
1229 $ui = get_userinfo();
1230 $res = array();
1231 $this->terminals = array();
1232 $userregex = "";
1233 $opsi_clients = array();
1235 /* Set base for all searches */
1236 $base= $this->DivListSystem->selectedBase;
1238 /* Prepare samba class name */
1239 $samba ="";
1240 if ($this->DivListSystem->ShowWinWorkstations){
1241 if ($this->config->get_cfg_value("sambaversion") == "3"){
1242 $samba= "sambaSamAccount";
1243 } else {
1244 $samba= "sambaAccount";
1245 }
1246 }
1248 /* This array represents the combination between checkboxes and search filters */
1249 $objs = array(
1250 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1251 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1252 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1253 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1254 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1255 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1256 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1258 /* Include the 'Display Systems of user' attribute */
1259 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1260 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1261 }
1263 /* Attributes to fetch */
1264 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1265 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1267 /* Add FAIstate to attributes if FAI is activated */
1268 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1269 if(!empty($tmp)){
1270 $sys_attrs[] = "FAIstate";
1271 }
1273 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1274 foreach($objs as $checkBox => $oc){
1276 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1277 if($this->DivListSystem->SubSearch){
1278 if($oc['CLASS'] != ""){
1279 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1280 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1281 $res = array_merge($res,$new_res);
1282 }
1283 }else{
1284 /* User filter? */
1285 if($oc['CLASS'] != ""){
1286 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1287 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1288 }
1289 }
1290 }
1291 }
1293 /* Search for incoming objects */
1294 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1295 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1297 /* Append opsi systems, the opsi extension have to installed.
1298 (Only, if we are allowed to view opsi hosts)
1299 */
1300 if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1301 $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1302 if(preg_match("/r/",$o_acl)){
1303 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1304 if($this->opsi->is_error()){
1305 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1306 }
1307 }
1308 }
1310 /* Get all gotoTerminal's */
1311 $t_id = 0;
1312 $opsi_map = array();
1313 foreach ($res as $value){
1315 $tmp= $value['dn'];
1316 $add= "";
1318 /* Extract base */
1319 foreach($objs as $obj){
1320 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1321 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1322 }
1323 }
1325 /* Create a string containing the last part of the department. */
1326 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1327 if(empty($dn_name)){
1328 $dn_name = "/";
1329 }
1331 /* check if current object is a new one */
1332 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1333 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1334 $add= "- "._("New terminal");
1335 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1336 $add= "- "._("New workstation");
1337 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1338 $add= "- "._("Unknown device");
1339 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1340 $add= "- "._("New Device");
1341 }
1342 }
1344 /* Detect type of object and create an entry for $this->terminals */
1345 $terminal = array();
1347 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1349 /* check acl */
1350 $terminal = $value;
1351 $terminal['type'] = "O";
1353 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1355 /* check acl */
1356 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1357 if($add != "" || preg_match("/r/",$acl)) {
1358 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1359 $terminal = $value;
1360 $terminal['type'] = "T";
1361 $terminal['is_new'] = $add;
1362 } else {
1363 $terminal = $value;
1364 $terminal['type'] = "D";
1365 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1366 $terminal['location'] = array_search($tmp, $this->config->departments);
1367 }
1368 }
1369 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1371 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1372 if($add != "" || preg_match("/r/",$acl)) {
1373 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1374 $terminal = $value;
1375 $terminal['type'] = "L";
1376 $terminal['is_new'] = $add;
1377 } else {
1378 $terminal = $value;
1379 $terminal['type'] = "D";
1380 $terminal['location'] = array_search($tmp, $this->config->departments);
1381 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1382 }
1383 # if (isset($value["FAIstate"][0])){
1384 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1385 # }
1386 }
1387 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1390 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1391 if($add != "" || preg_match("/r/",$acl)) {
1393 $terminal = $value;
1394 $terminal['type'] = "P";
1395 }
1396 } elseif (in_array_ics('goServer', $value["objectClass"])){
1398 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1399 if($add != "" || preg_match("/r/",$acl)) {
1401 $terminal = $value;
1402 $terminal['type'] = "S";
1403 # if (isset($value["FAIstate"][0])){
1404 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1405 # }
1406 }
1407 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1409 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1410 if($add != "" || preg_match("/r/",$acl)) {
1412 $terminal = $value;
1413 $terminal['type'] = "F";
1414 }
1415 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1417 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1418 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1419 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1420 if($add != "" || preg_match("/r/",$acl)) {
1422 $terminal = $value;
1423 $terminal['type'] = "Q";
1424 $terminal['is_new'] = $add;
1425 }
1426 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1427 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1428 $type= "winstation";
1429 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1430 if($add != "" || preg_match("/r/",$acl)) {
1432 $terminal = $value;
1433 $terminal['type'] = "C";
1434 }
1435 } else{
1437 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1438 if (isset($value['sambaDomainName'])){
1439 $domain= " [".$value['sambaDomainName'][0]."]";
1440 } else {
1441 $domain= "";
1442 }
1443 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1444 if($add != "" || preg_match("/r/",$acl)) {
1445 $terminal=$value;
1446 $terminal['type'] ="W";
1447 $terminal['domain'] = $name.$domain;
1448 }
1449 }
1451 /* Append collected data to the host list.
1452 */
1453 if(count($terminal)){
1454 $t_id ++ ;
1455 $this->terminals[$t_id]=$terminal;
1456 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1457 }
1458 }
1461 /* Merge real hosts with opsi hosts.
1462 If there is a samba host, then merge it with the opsi host,
1463 to avoid duplicate entries.
1464 */
1465 foreach($opsi_clients as $entry){
1466 if(isset($opsi_map[$entry['cn'][0]])){
1467 continue;
1468 }
1469 $terminal = $entry;
1470 $terminal['type'] = "O";
1471 $this->terminals[] = $terminal;
1472 }
1474 $tmp =array();
1475 $tmp2 =array();
1476 foreach($this->terminals as $tkey => $val ){
1477 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1478 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1479 }
1480 natcasesort($tmp2);
1481 $this->terminals=array();
1482 foreach($tmp2 as $val){
1483 $this->terminals[]=$tmp[$val];
1484 }
1485 reset ($this->terminals);
1486 }
1488 function remove_lock()
1489 {
1491 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1492 del_lock($this->dn);
1493 }elseif (isset($this->systab->dn)){
1494 del_lock ($this->systab->dn);
1495 }
1496 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1497 del_lock($this->dns);
1498 }
1499 }
1502 function copyPasteHandling_from_queue($s_action,$s_entry)
1503 {
1504 /* Check if Copy & Paste is disabled */
1505 if(!is_object($this->CopyPasteHandler)){
1506 return("");
1507 }
1509 $ui = get_userinfo();
1511 $tabs = $this->get_tab_defs();
1513 /* Add a single entry to queue */
1514 if($s_action == "cut" || $s_action == "copy"){
1516 /* Cleanup object queue */
1517 $this->CopyPasteHandler->cleanup_queue();
1518 $dn = $this->terminals[$s_entry]['dn'];
1519 $oc = $this->terminals[$s_entry]['objectClass'];
1520 $type = $this->get_system_type($this->terminals[$s_entry]);
1522 $tab_o = $tabs[$type]['CLASS'];
1523 $tab_c = $tabs[$type]['TABCLASS'];
1524 $acl_c = $tabs[$type]['TABNAME'];
1525 $acl = $tabs[$type]['ACLC'];
1527 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1528 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1529 }
1530 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1531 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1532 }
1533 }
1535 /* Add entries to queue */
1536 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1538 /* Cleanup object queue */
1539 $this->CopyPasteHandler->cleanup_queue();
1541 /* Add new entries to CP queue */
1542 foreach($this->list_get_selected_items() as $id){
1543 $dn = $this->terminals[$id]['dn'];
1544 $oc = $this->terminals[$id]['objectClass'];
1545 $type = $this->get_system_type($this->terminals[$id]);
1547 if(isset($tabs[$type])){
1548 $tab_o = $tabs[$type]['CLASS'];
1549 $tab_c = $tabs[$type]['TABCLASS'];
1550 $acl_c = $tabs[$type]['TABNAME'];
1551 $acl = $tabs[$type]['ACLC'];
1553 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1554 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1555 }
1556 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1557 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1558 }
1559 }
1560 }
1561 }
1563 /* Start pasting entries */
1564 if($s_action == "editPaste"){
1565 $this->start_pasting_copied_objects = TRUE;
1566 }
1568 /* Return C&P dialog */
1569 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1571 /* Get dialog */
1572 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1573 $data = $this->CopyPasteHandler->execute();
1575 /* Return dialog data */
1576 if(!empty($data)){
1577 return($data);
1578 }
1579 }
1581 /* Automatically disable status for pasting */
1582 if(!$this->CopyPasteHandler->entries_queued()){
1583 $this->start_pasting_copied_objects = FALSE;
1584 }
1585 return("");
1586 }
1589 function get_system_type($attrs)
1590 {
1591 $classes = $attrs['objectClass'];
1593 $type= "";
1594 if (in_array_ics('gosa_opsi_client', $classes)){
1595 $type= "opsi_client";
1596 }elseif (in_array_ics('sambaAccount', $classes) ||
1597 in_array_ics('sambaSamAccount', $classes)){
1598 $type= "winstation";
1599 }elseif (in_array_ics('ieee802Device', $classes)){
1600 $type= "component";
1601 }elseif (in_array_ics('gotoTerminal', $classes)){
1602 $type= "terminal";
1603 }elseif (in_array_ics('gotoWorkstation', $classes)){
1604 $type= "workstation";
1605 }elseif (in_array_ics('gotoPrinter', $classes)){
1606 $type= "printer";
1607 }elseif (in_array_ics('goFonHardware', $classes)){
1608 $type= "phone";
1609 }elseif (in_array_ics('goServer', $classes)){
1610 $type= "server";
1611 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1612 $type= "ArpNewDevice";
1613 }elseif (in_array_ics('GOhard', $classes)){
1614 $type= "NewDevice";
1615 }
1616 return ($type);
1617 }
1620 function convert_list($input)
1621 {
1622 $temp= "";
1624 $conv= array(
1625 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1626 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1627 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1628 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1630 "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1632 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1633 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1634 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1636 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1637 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1638 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1640 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1641 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1642 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1644 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1645 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1647 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1648 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1649 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1651 /* Add opsi client to system types */
1652 if($this->opsi != NULL){
1653 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1654 }
1656 /* Use locked icons
1657 */
1658 if( in_array($input['type'],array("S","T","L")) &&
1659 isset($input['gotoMode'][0]) &&
1660 preg_match("/locked/",$input['gotoMode'][0])){
1661 $input['type'].="X";
1662 } elseif(in_array($input['type'],array("S","L")) &&
1663 isset($input['FAIstate'][0])){
1665 /* Add FAI state icons
1666 */
1667 $type= "";
1668 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1669 case 'error':
1670 $type= 'E';
1671 break;
1672 case 'installing':
1673 case 'install':
1674 case 'sysinfo':
1675 case 'softupdate':
1676 case 'scheduledupdate':
1677 $type= 'B';
1678 break;
1679 }
1681 $input['type'].= $type;
1682 }
1684 /* Use new images if object is from incoming
1685 */
1686 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1687 $input['type']="N".$input['type'];
1688 }
1690 /* Check which flags this objects uses
1691 */
1692 foreach ($conv as $key => $value){
1693 $found = TRUE;
1694 if(strlen($key) != strlen($input['type'])) {
1695 $found = FALSE;
1696 }
1697 for($i = 0 ; $i < strlen($key) ; $i++){
1698 if(!preg_match("/".$key[$i]."/",$input['type'])){
1699 $found = FALSE;
1700 }
1701 }
1703 if($found){
1704 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1705 $tmp['class']=$key;
1706 return $tmp;
1707 }
1708 }
1709 }
1712 function list_get_selected_items()
1713 {
1714 $ids = array();
1715 foreach($_POST as $name => $value){
1716 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1717 $id = preg_replace("/^item_selected_/","",$name);
1718 $ids[$id] = $id;
1719 }
1720 }
1721 return($ids);
1722 }
1725 public function get_tab_defs()
1726 {
1727 $tabs = array(
1728 "incoming" => array(
1729 "CLASS" => "",
1730 "TABNAME" => "",
1731 "TABCLASS" => "",
1732 "ACLC" => "incoming",
1733 "ACL" => "incoming/systems"),
1735 "ArpNewDevice"=> array(
1736 "CLASS" => "TERMTABS",
1737 "TABNAME" => "termgeneric" ,
1738 "TABCLASS" => "termtabs",
1739 "ACLC" => "incoming",
1740 "ACL" => "incoming/systems"),
1742 "NewDevice" => array(
1743 "CLASS" => "TERMTABS",
1744 "TABNAME" => "termgeneric",
1745 "TABCLASS" => "termtabs",
1746 "ACLC" => "incoming",
1747 "ACL" => "incoming/systems"),
1749 "terminal" => array(
1750 "CLASS" => "TERMTABS",
1751 "TABNAME" => "termgeneric",
1752 "TABCLASS" => "termtabs",
1753 "ACLC" => "terminal",
1754 "ACL" => "terminal/termgeneric"),
1756 "workstation" => array(
1757 "CLASS" => "WORKTABS",
1758 "TABNAME" => "workgeneric",
1759 "TABCLASS"=> "worktabs",
1760 "ACLC" => "workstation",
1761 "ACL" => "workstation/workgeneric" ),
1763 "server" => array(
1764 "CLASS" => "SERVTABS",
1765 "TABNAME" => "servgeneric",
1766 "TABCLASS"=> "servtabs",
1767 "ACLC" => "server",
1768 "ACL" => "server/servgeneric"),
1770 "printer" => array(
1771 "CLASS" => "PRINTTABS",
1772 "TABNAME" => "printgeneric",
1773 "TABCLASS"=> "printtabs",
1774 "ACLC" => "printer",
1775 "ACL" => "printer/printgeneric"),
1777 "phone" => array(
1778 "CLASS" => "PHONETABS",
1779 "TABNAME" => "phoneGeneric",
1780 "TABCLASS"=> "phonetabs",
1781 "ACLC" => "phone",
1782 "ACL" => "phone/phoneGeneric"),
1784 "winstation" => array(
1785 "CLASS" => "WINTABS",
1786 "TABNAME" => "wingeneric",
1787 "TABCLASS"=> "wintabs",
1788 "ACLC" => "winworkstation",
1789 "ACL" => "winworkstation/wingeneric"),
1791 "component" => array(
1792 "CLASS" => "COMPONENTTABS",
1793 "TABNAME" => "componentGeneric",
1794 "TABCLASS"=> "componenttabs",
1795 "ACLC" => "component",
1796 "ACL" => "component/componentGeneric"));
1798 if($this->opsi != NULL){
1799 $tabs["opsi_client"] = array(
1800 "CLASS" => "OPSITABS",
1801 "TABNAME" => "opsiGeneric" ,
1802 "TABCLASS"=> "opsi_tabs",
1803 "ACLC" => "opsi" ,
1804 "ACL" => "opsi/opsiGeneric");
1805 }
1807 return($tabs);
1808 }
1811 /*! \brief Sets FAIstate to "install" for "New Devices".
1812 This function is some kind of "Post handler" for activated systems,
1813 it is called directly after the object (workstabs,servtabs) gets saved.
1814 @param String $dn The dn of the newly activated object.
1815 @return Boolean TRUE if activated else FALSE
1816 */
1817 function activate_new_device($dn)
1818 {
1819 $ldap = $this->config->get_ldap_link();
1820 $ldap->cd($this->config->current['BASE']);
1821 $ldap->cat($dn);
1822 if($ldap->count()){
1823 $attrs = $ldap->fetch();
1824 $type = $this->get_system_type($attrs);
1825 if(!in_array($type,array("workstation","server"))) {
1826 $ocs = $attrs['objectClass'];
1827 unset($ocs['count']);
1828 $new_attrs = array();
1829 if(!in_array("FAIobject",$ocs)){
1830 $ocs[] = "FAIobject";
1831 $new_attrs['objectClass'] = $ocs;
1832 }
1833 $new_attrs['FAIstate'] = "install";
1834 $ldap->cd($dn);
1835 $ldap->modify($new_attrs);
1836 if (!$ldap->success()){
1837 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1838 LDAP_MOD, "activate_new_device($dn)"));
1839 }else{
1840 return(TRUE);
1841 }
1842 }
1843 }
1844 return(FALSE);
1845 }
1848 /* !! Incoming dummy acls, required to defined acls for incoming objects
1849 */
1850 static function plInfo()
1851 {
1852 return (array(
1853 "plShortName" => _("Incoming objects"),
1854 "plDescription" => _("Incoming objects"),
1855 "plSelfModify" => FALSE,
1856 "plDepends" => array(),
1857 "plPriority" => 99,
1858 "plSection" => array("administration"),
1859 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1860 "objectClass" => "")),
1861 "plProvidedAcls"=> array()
1863 ));
1864 }
1865 }
1867 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1868 ?>