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 if($selected_group != "none"){
391 $this->systab->base = preg_replace("/^[^,]+,".get_ou('ogroupRDN')."/", "", $selected_group);
392 $this->systab->by_object[$tabname]->base = $this->systab->base;
393 } else {
394 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
395 $this->systab->base = $this->DivListSystem->selectedBase;
396 }
398 /* This will be used when the object is saved, to set FAIstate to 'install'
399 and to preset maybe other attributes.
400 */
401 $this->systab->was_activated = TRUE;
403 /* Assign some default values for opsi hosts
404 */
405 if($this->systab instanceOf opsi_tabs){
406 $ldap = $this->config->get_ldap_link();
407 $ldap->cat($dn);
408 $source_attrs = $ldap->fetch();
409 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
410 if(isset($source_attrs[$src][0])){
411 $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
412 }
413 }
414 }
416 if($selected_group != "none"){
418 /*******
419 * Set gotoMode to active if there was an ogroup selected.
420 */
421 $found = false;
422 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
423 if(isset($this->systab->by_object[$tab]->gotoMode)) {
424 $found = true;
425 $this->systab->by_object[$tab]->gotoMode = $value;
426 }
427 }
428 if(!$found){
429 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
430 }
432 /*******
433 * Update object group membership
434 */
435 $og = new ogroup($this->config,$selected_group);
436 if($og){
437 $og->AddDelMembership($this->systab->dn);
438 $og->save();
439 }
441 /*******
442 * Set default system specific attributes
443 */
444 foreach (array("workservice", "termservice") as $cls){
445 if (isset($this->systab->by_object[$cls])){
446 $this->systab->by_object[$cls]->gotoXMouseport= "";
447 $this->systab->by_object[$cls]->gotoXMouseType= "";
448 $this->systab->by_object[$cls]->gotoXResolution= "";
449 $this->systab->by_object[$cls]->gotoXColordepth= "";
450 }
451 }
453 // Enable activation
454 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
455 if (isset($this->systab->by_object[$cls])){
456 $this->systab->by_object[$cls]->auto_activate= TRUE;
457 }
458 }
460 // Enable sending of LDAP events
461 if (isset($this->systab->by_object["workstartup"])){
462 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
463 }
464 }
466 /* Don't save directly if there is no objectGroup selected.
467 The user will then be able to configure the missing attributes
468 on his own.
469 */
470 if($selected_group != "none"){
471 $this->systab->save();
473 /* Post handling for activated new devices
474 */
475 $this->activate_new_device($this->systab->dn);
476 $this->systab = NULL;
478 if(!isset($ldap)){
479 $ldap = $this->config->get_ldap_link();
480 }
481 $ldap->cd ($this->dn);
482 $ldap->cat($this->dn, array('dn'));
483 if(count($ldap->fetch())){
484 $ldap->cd($this->dn);
485 $ldap->rmDir($this->dn);
486 }
487 }
488 }else{
489 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
490 }
491 }
492 }
493 }
494 }
497 if (isset($_POST['create_system'])||$s_action=="newsystem") {
499 $this->last_action = "";
501 /* If the current entry is an incoming object
502 * $sw = System type as posted in new incoming handling dialog
503 */
504 if(isset($_POST['system'])){
505 $sw = $_POST['system'];
506 }else{
507 $sw = $s_entry;
508 }
509 $this->dn= "new";
511 $tabs = $this->get_tab_defs();
513 if(isset($tabs[$sw])){
514 $class = $tabs[$sw]["CLASS"];
515 $tabname = $tabs[$sw]["TABNAME"];
516 $tabclass = $tabs[$sw]["TABCLASS"];
517 $acl_cat = $tabs[$sw]["ACLC"];
519 /* Load permissions for selected 'dn' and check if
520 we're allowed to remove this 'dn' */
521 $ui = get_userinfo();
522 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
523 if(preg_match("/c/",$tabacl)){
525 if(!class_available($tabclass)){
526 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
527 }else{
528 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
529 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
530 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
531 $this->systab->base = $this->DivListSystem->selectedBase;
532 }
533 }else{
534 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
535 }
536 }
537 }
539 /********************
540 System activation
541 ********************/
543 /* User wants to edit data? */
544 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
545 $this->system_activation_object = array();
546 foreach($this->list_get_selected_items() as $id) {
547 $obj = $this->terminals[$id];
548 $type= $this->get_system_type($obj);
549 if($type == "NewDevice"){
550 $this->system_activation_object[] = $obj['dn'];
551 }
552 }
553 if(count($this->system_activation_object)){
554 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
555 }
556 }
559 /********************
560 Edit system ...
561 ********************/
563 /* User wants to edit data? */
564 if (($s_action == "edit") && (!isset($this->systab->config))){
565 $this->last_action = "";
566 $this->dn= $this->terminals[$s_entry]['dn'];
568 /* Check locking, save current plugin in 'back_plugin', so
569 the dialog knows where to return. */
570 if (($user= get_lock($this->dn)) != ""){
571 return(gen_locked_message ($user, $this->dn,TRUE));
572 }
574 /* Find out more about the object type */
575 $attrs = $this->terminals[$s_entry];
576 $type= $this->get_system_type($attrs);
578 /* Lock the current entry, so everyone will get the
579 above dialog */
580 $tabs = $this->get_tab_defs();
582 if($type == "ArpNewDevice"){
583 if(!class_available("ArpNewDeviceTabs")){
584 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
585 }else{
586 add_lock ($this->dn, $this->ui->dn);
587 $this->system_activation_object= array($this->dn);
588 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
589 }
590 }elseif($type == "NewDevice"){
591 if(!class_available("SelectDeviceType")){
592 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
593 }else{
594 add_lock ($this->dn, $this->ui->dn);
595 $this->system_activation_object= array($this->dn);
596 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
598 // see condition -$s_action == "SelectedSystemType"- for further handling
599 }
600 }elseif(isset($tabs[$type])){
602 $class = $tabs[$type]["CLASS"];
603 $acl_cat = $tabs[$type]["ACLC"];
604 $tabclass = $tabs[$type]["TABCLASS"];
606 if(!class_available($tabclass)){
607 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
608 }else{
609 add_lock ($this->dn, $this->ui->dn);
610 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
611 $this->systab->set_acl_base($this->dn);
612 set_object_info($this->dn);
613 }
614 }else{
615 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
616 $this->remove_lock();
617 }
618 }
621 /********************
622 Change password ...
623 ********************/
625 /* Set terminals root password */
626 if ($s_action=="change_pw"){
627 $tabs = $this->get_tab_defs();
629 $dn = $this->terminals[$s_entry]['dn'];
630 $type = $this->get_system_type($this->terminals[$s_entry]);
632 $class = $tabs[$type]["CLASS"];
633 $acl = $tabs[$type]["ACL"];
634 $tabclass = $tabs[$type]["TABCLASS"];
635 $ui = get_userinfo();
636 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
637 if(preg_match("/w/",$tabacl)){
638 $this->dn= $this->terminals[$s_entry]['dn'];
639 set_object_info($this->dn);
640 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
641 }else{
642 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
643 }
644 }
647 /********************
648 Password change finish, but check if entered data is ok
649 ********************/
651 /* Correctly specified? */
652 if (isset($_POST['password_finish'])){
653 if ($_POST['new_password'] != $_POST['repeated_password']){
654 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
655 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
656 }
657 }
659 /********************
660 Password change finish
661 ********************/
663 /* Change terminal password */
664 if (isset($_POST['password_finish']) &&
665 $_POST['new_password'] == $_POST['repeated_password']){
667 /* Check if user is allowed to set password */
668 $tabs = $this->get_tab_defs();
670 $type = "";
671 foreach($this->terminals as $terminal){
672 if($terminal['dn'] == $this->dn){
673 $type = $this->get_system_type($terminal);
674 break;
675 }
676 }
678 /* Type detected */
679 $allow_for = array("terminal","workstation","server","component");
680 if(!empty($type) && in_array($type,$allow_for)){
682 /* Get infos */
683 $plug = $tabs[$type]["TABNAME"];
684 $acl = $tabs[$type]["ACL"];
685 $tabclass = $tabs[$type]["TABCLASS"];
687 /* Get acls */
688 $ui = get_userinfo();
689 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
691 /* Check acls */
692 if(preg_match("/w/",$tabacl)){
693 $ldap = $this->config->get_ldap_link();
694 $ldap->cd($this->dn);
695 $ldap->cat($this->dn);
696 $old_attrs = $ldap->fetch();
698 $attrs= array();
699 if ($_POST['new_password'] == ""){
701 /* Remove password attribute
702 */
703 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
704 $attrs['objectClass'] = array();
705 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
706 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
707 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
708 }
709 }
710 }
711 $attrs['userPassword']= array();
712 } else {
714 /* Add/modify password attribute
715 */
716 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
717 $attrs['objectClass'] = array();
718 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
719 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
720 }
721 $attrs['objectClass'][] = "simpleSecurityObject";
722 }
724 if(class_available("passwordMethodCrypt")){
725 $pwd_m = new passwordMethodCrypt($this->config);
726 $pwd_m->set_hash("crypt/md5");
727 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
728 }else{
729 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
730 $attrs = array();
731 }
732 }
733 $ldap->modify($attrs);
734 if (!$ldap->success()){
735 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
736 }else{
737 if(class_available($plug)){
738 $p = new $plug($this->config,$this->dn);
739 $p->handle_post_events("modify");
740 }
741 }
743 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
744 }else{
745 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
746 }
747 }else{
748 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
749 }
750 set_object_info();
751 }
754 /********************
755 Delete system cancel
756 ********************/
758 /* Delete terminal canceled? */
759 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
760 $this->remove_lock();
761 set_object_info();
762 }
765 /********************
766 Action(s) for MULTIPLE
767 ********************/
769 /********************
770 SCHEDULE action in GOsa Daemon
771 ********************/
773 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
774 $this->dns = array();
775 $ids = $this->list_get_selected_items();
777 /* Handle opsi actions */
778 if($s_action == "trigger_event_DaemonEvent_reinstall"){
779 foreach($ids as $key => $id){
780 if($this->terminals[$id]['type'] == "O"){
781 $obj = $this->terminals[$id];
782 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
783 unset($ids[$key]);
784 }
785 }
786 }
788 if(count($ids) && class_available("DaemonEvent")){
789 $mac= array();
791 /* Collect target mac addresses */
792 $ldap = $this->config->get_ldap_link();
793 foreach($ids as $id){
794 $type = $this->get_system_type($this->terminals[$id]);
795 if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
796 if(isset($this->terminals[$id]['macAddress'][0])){
797 $mac[] = $this->terminals[$id]['macAddress'][0];
798 }else{
799 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
800 $attrs= $ldap->fetch();
801 if (isset($attrs['macAddress'][0])){
802 $mac[]= $attrs['macAddress'][0];
803 }
804 }
805 }
806 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
807 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
808 $o_queue = new gosaSupportDaemon();
810 /* Skip installation or update trigerred events,
811 * if this entry is currently processing.
812 */
813 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
814 foreach($mac as $key => $mac_address){
815 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
817 $entry['STATUS'] = strtoupper($entry['STATUS']);
818 if($entry['STATUS'] == "PROCESSING" &&
819 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
820 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
821 unset($mac[$key]);
823 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
824 break;
825 }
826 }
827 }
828 }
830 /* Prepare event to be added
831 */
832 if(count($mac) && isset($events['BY_CLASS'][$type])){
833 $event = $events['BY_CLASS'][$type];
834 $this->systab = new $event['CLASS_NAME']($this->config);
835 $this->systab->add_targets($mac);
836 if(preg_match("/trigger_event/",$s_action)){
837 $this->systab->set_type(TRIGGERED_EVENT);
838 }else{
839 $this->systab->set_type(SCHEDULED_EVENT);
840 }
841 }
842 }
843 }
845 /* Insert scheduled events into queue */
846 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
847 $this->systab->save_object();
849 /* Save event
850 */
851 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
852 $o_queue = new gosaSupportDaemon();
853 $o_queue->append($this->systab);
854 if($o_queue->is_error()){
855 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
856 }else{
857 $this->systab = FALSE;
858 }
859 }
860 if(isset($_POST['abort_event_dialog'])){
861 $this->systab = FALSE;
862 }
863 }
866 /********************
867 Delete MULTIPLE entries requested, display confirm dialog
868 ********************/
870 if ($s_action=="del_multiple" || $s_action == "del"){
871 $this->dns = array();
873 if($s_action == "del_multiple"){
874 $ids = $this->list_get_selected_items();
875 }else{
876 $ids = array($s_entry);
877 }
879 $ui = get_userinfo();
880 $tabs = $this->get_tab_defs();
882 if(count($ids)){
884 $disallowed = array();
885 foreach($ids as $id){
887 /* Get 'dn' from posted termlinst */
888 $attrs = $this->terminals[$id];
889 $type = $this->get_system_type($attrs);
890 $dn = $attrs['dn'];
891 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
892 if(preg_match("/d/",$acl)){
893 $this->dns[$id] = $dn;
894 }else{
895 $disallowed[] = $dn;
896 }
897 }
899 if(count($disallowed)){
900 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
901 }
903 if(count($this->dns)){
905 if ($user= get_multiple_locks($this->dns)){
906 return(gen_locked_message($user,$this->dns));
907 }
909 $dns_names = array();
910 foreach($this->dns as $dn){
911 add_lock ($dn, $this->ui->dn);
912 $dns_names[] = LDAP::fix($dn);
913 }
915 /* Lock the current entry, so nobody will edit it during deletion */
916 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
917 $smarty->assign("multiple", true);
918 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
919 }
920 }
921 }
924 /********************
925 Delete MULTIPLE entries confirmed
926 ********************/
928 /* Confirmation for deletion has been passed. Users should be deleted. */
929 if (isset($_POST['delete_multiple_system_confirm'])){
931 $ui = get_userinfo();
932 $tabs = $this->get_tab_defs();
934 /* Remove user by user and check acls before removeing them */
935 foreach($this->dns as $key => $dn){
937 /* Get 'dn' from posted termlinst */
938 $attrs = $this->terminals[$key];
939 $type= $this->get_system_type($attrs);
941 /* get object type */
942 $tabtype = "termtabs";
943 $tabobj = "TERMTABS";
944 $tabacl = "";
945 if(isset($tabs[$type])){
946 $tabtype = $tabs[$type]['TABCLASS'];
947 $tabobj = $tabs[$type]['CLASS'];
948 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
950 /* Load permissions for selected 'dn' and check if
951 we're allowed to remove this 'dn' */
952 if(preg_match("/d/",$tabacl)){
954 /* Delete request is permitted, perform LDAP action */
955 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
956 $this->systab= new termgeneric($this->config, $dn);
957 $this->systab->set_acl_base($dn);
958 $this->systab->remove_from_parent();
959 }elseif($tabtype=="phonetabs"){
960 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
961 $this->systab->set_acl_base($dn);
962 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
963 }else{
964 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
965 $this->systab->set_acl_base($dn);
966 $this->systab->delete();
967 }
968 unset ($this->systab);
969 $this->systab= NULL;
971 } else {
972 /* Normally this shouldn't be reached, send some extra
973 logs to notify the administrator */
974 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
975 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
976 }
977 }
979 /* Remove lock file after successfull deletion */
980 $this->remove_lock();
981 $this->dns = array();
982 }
983 }
985 /********************
986 Delete MULTIPLE entries Canceled
987 ********************/
989 /* Remove lock */
990 if(isset($_POST['delete_multiple_system_cancel'])){
992 /* Remove lock file after successfull deletion */
993 $this->remove_lock();
994 $this->dns = array();
995 }
998 /********************
999 Edit system type finished, check if everything went ok
1000 ********************/
1001 /* Finish user edit is triggered by the tabulator dialog, so
1002 the user wants to save edited data. Check and save at this
1003 point. */
1005 /* Dirty workaround - MSG_DIALOG - OK
1006 If a message dialog is shown and we press 'OK'
1007 then try to save again.
1008 */
1009 foreach($_POST as $name => $value){
1010 if(preg_match("/^MSG_OK/",$name)){
1011 $_POST[$this->last_action] = TRUE;
1012 }
1013 }
1015 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1017 /* If the save routine gets interrupted by a confirm dialog,
1018 store last action so we can trigger it again after 'Ok' was pressed.
1019 (This is the case if a system gets modified while it is installing - GOsa si)
1020 */
1021 $this->last_action = "";
1022 if(isset($_POST['edit_finish'])){
1023 $this->last_action = "edit_finish";
1024 }elseif(isset($_POST['edit_apply'])){
1025 $this->last_action = "edit_apply";
1026 }
1028 /* Check tabs, will feed message array */
1029 $message = $this->systab->check();
1031 /* Save, or display error message? */
1032 if (count($message) == 0){
1033 $this->systab->save();
1035 /* Post handling for activated systems
1036 target opsi -> Remove source.
1037 target gosa -> Activate system.
1038 */
1039 if($this->systab instanceOf opsi_tabs){
1040 $ldap = $this->config->get_ldap_link();
1041 $ldap->cd($this->config->current['BASE']);
1042 $ldap->rmdir ($this->systab->dn);
1043 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1045 $hostId = $this->systab->by_object['opsiGeneric']->hostId;
1046 $mac = $this->systab->by_object['opsiGeneric']->mac;
1047 $this->opsi->job_opsi_activate_client($hostId,$mac);
1049 }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1050 $this->activate_new_device($this->systab->dn);
1051 }
1053 /* Terminal has been saved successfully, remove lock from LDAP. */
1054 if (!isset($_POST['edit_apply'])){
1055 if ($this->dn != "new"){
1056 $this->remove_lock();
1057 }
1059 unset ($this->systab);
1060 $this->systab= NULL;
1061 set_object_info();
1062 }else{
1064 /* Reinitialize tab */
1065 if($this->systab instanceof tabs){
1066 $this->systab->re_init();
1067 }
1068 }
1069 } else {
1070 /* Ok. There seem to be errors regarding to the tab data,
1071 show message and continue as usual. */
1072 msg_dialog::displayChecks($message);
1073 }
1074 }
1077 /********************
1078 Edit system was canceled
1079 ********************/
1080 /* Cancel dialogs */
1081 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1082 if (isset($this->systab)){
1083 $this->remove_lock();
1084 unset ($this->systab);
1085 }
1086 $this->systab= NULL;
1087 set_object_info();
1088 }
1090 /********************
1091 Display edit dialog, or some other
1092 ********************/
1094 /* Show tab dialog if object is present */
1095 if (isset($this->systab->config)){
1097 if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1098 $this->systab->save_object();
1099 }
1101 $display= $this->systab->execute();
1103 /* Don't show buttons if tab dialog requests this */
1105 $dialog = FALSE;
1106 $hide_apply = $this->dn == "new";
1107 $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1108 if(is_object($this->systab) && !isset($this->systab->by_object)){
1109 $dialog = TRUE;
1110 $hide_apply = TRUE;
1111 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1112 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1113 if($dia === TRUE || is_object($dia)){
1114 $dialog = TRUE;
1115 }
1116 }
1117 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1118 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1119 $dialog = TRUE;
1120 }
1122 if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1123 $display.= "<p style=\"text-align:right\">
1124 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1125 </p>";
1126 }elseif (!$dialog){
1127 $display.= "<p style=\"text-align:right\">\n";
1128 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1129 $display.= " \n";
1130 if (!$hide_apply){
1131 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1132 $display.= " \n";
1133 }
1134 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1135 $display.= "</p>";
1136 }
1137 return ($display);
1138 }
1140 /* Check if there is a snapshot dialog open */
1141 $base = $this->DivListSystem->selectedBase;
1142 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1143 return($str);
1144 }
1146 /* Display dialog with system list */
1147 $this->DivListSystem->parent = $this;
1148 $this->DivListSystem->execute();
1150 /* Add departments if subsearch is disabled */
1151 if(!$this->DivListSystem->SubSearch){
1153 /* Add FAIstate to attributes if FAI is activated */
1154 if($this->fai_activated){
1155 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1156 }else{
1157 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1158 }
1159 }
1160 $this->reload();
1161 $this->DivListSystem->setEntries($this->terminals);
1162 return($this->DivListSystem->Draw());
1163 }
1166 /* Return departments, that will be included within snapshot detection */
1167 function get_used_snapshot_bases()
1168 {
1169 $tmp = array();
1171 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1173 $tabs = array(
1174 "terminal" => get_ou('terminalRDN'),
1175 "workstation" => get_ou('workstationRDN'),
1176 "incoming" => get_ou('systemIncomingRDN'),
1177 "server" => get_ou('serverRDN'),
1178 "printer" => get_ou('printerRDN'),
1179 "phone" => get_ou('phoneRDN'),
1180 "winworkstation" => get_winstations_ou(),
1181 "component" => get_ou('componentRDN')
1182 );
1184 foreach($tabs as $acl_cat => $dn){
1186 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1187 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1188 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1189 }
1190 }
1191 return($tmp);
1192 }
1195 function remove_from_parent()
1196 {
1197 /* Optionally execute a command after we're done */
1198 $this->postremove();
1199 }
1202 /* Save data to object */
1203 function save_object()
1204 {
1205 $this->DivListSystem->save_object();
1206 if(is_object($this->CopyPasteHandler)){
1207 $this->CopyPasteHandler->save_object();
1208 }
1209 }
1212 /* Check values */
1213 function check()
1214 {
1215 }
1218 /* Save to LDAP */
1219 function save()
1220 {
1221 }
1223 function adapt_from_template($dn, $skip= array())
1224 {
1225 }
1227 function password_change_needed()
1228 {
1229 }
1231 function reload()
1232 {
1233 /* some var init */
1234 $ui = get_userinfo();
1235 $res = array();
1236 $this->terminals = array();
1237 $userregex = "";
1238 $opsi_clients = array();
1240 /* Set base for all searches */
1241 $base= $this->DivListSystem->selectedBase;
1243 /* Prepare samba class name */
1244 $samba ="";
1245 if ($this->DivListSystem->ShowWinWorkstations){
1246 if ($this->config->get_cfg_value("sambaversion") == "3"){
1247 $samba= "sambaSamAccount";
1248 } else {
1249 $samba= "sambaAccount";
1250 }
1251 }
1253 /* This array represents the combination between checkboxes and search filters */
1254 $objs = array(
1255 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1256 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1257 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1258 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1259 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1260 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1261 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1263 /* Include the 'Display Systems of user' attribute */
1264 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1265 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1266 }
1268 /* Attributes to fetch */
1269 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1270 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1272 /* Add FAIstate to attributes if FAI is activated */
1273 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1274 if(!empty($tmp)){
1275 $sys_attrs[] = "FAIstate";
1276 }
1278 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1279 foreach($objs as $checkBox => $oc){
1281 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1282 if($this->DivListSystem->SubSearch){
1283 if($oc['CLASS'] != ""){
1284 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1285 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1286 $res = array_merge($res,$new_res);
1287 }
1288 }else{
1289 /* User filter? */
1290 if($oc['CLASS'] != ""){
1291 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1292 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1293 }
1294 }
1295 }
1296 }
1298 /* Search for incoming objects */
1299 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1300 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1302 /* Append opsi systems, the opsi extension have to installed.
1303 (Only, if we are allowed to view opsi hosts and if we're on the ldap root)
1304 */
1305 if($this->DivListSystem->selectedBase == $this->config->current['BASE'] &&
1306 $this->opsi instanceof opsi &&
1307 $this->opsi->enabled() &&
1308 $this->DivListSystem->ShowOpsiHosts){
1309 $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1310 if(preg_match("/r/",$o_acl)){
1311 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1312 if($this->opsi->is_error()){
1313 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1314 }
1315 }
1316 }
1318 /* Get all gotoTerminal's */
1319 $t_id = 0;
1320 $opsi_map = array();
1321 foreach ($res as $value){
1323 $tmp= $value['dn'];
1324 $add= "";
1326 /* Extract base */
1327 foreach($objs as $obj){
1328 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1329 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1330 }
1331 }
1333 /* Create a string containing the last part of the department. */
1334 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1335 if(empty($dn_name)){
1336 $dn_name = "/";
1337 }
1339 /* check if current object is a new one */
1340 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1341 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1342 $add= "- "._("New terminal");
1343 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1344 $add= "- "._("New workstation");
1345 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1346 $add= "- "._("Unknown device");
1347 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1348 $add= "- "._("New Device");
1349 }
1350 }
1352 /* Detect type of object and create an entry for $this->terminals */
1353 $terminal = array();
1355 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1357 /* check acl */
1358 $terminal = $value;
1359 $terminal['type'] = "O";
1361 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1363 /* check acl */
1364 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1365 if($add != "" || preg_match("/r/",$acl)) {
1366 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1367 $terminal = $value;
1368 $terminal['type'] = "T";
1369 $terminal['is_new'] = $add;
1370 } else {
1371 $terminal = $value;
1372 $terminal['type'] = "D";
1373 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1374 $terminal['location'] = array_search($tmp, $this->config->departments);
1375 }
1376 }
1377 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1379 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1380 if($add != "" || preg_match("/r/",$acl)) {
1381 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1382 $terminal = $value;
1383 $terminal['type'] = "L";
1384 $terminal['is_new'] = $add;
1385 } else {
1386 $terminal = $value;
1387 $terminal['type'] = "D";
1388 $terminal['location'] = array_search($tmp, $this->config->departments);
1389 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1390 }
1391 # if (isset($value["FAIstate"][0])){
1392 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1393 # }
1394 }
1395 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1398 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1399 if($add != "" || preg_match("/r/",$acl)) {
1401 $terminal = $value;
1402 $terminal['type'] = "P";
1403 }
1404 } elseif (in_array_ics('goServer', $value["objectClass"])){
1406 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1407 if($add != "" || preg_match("/r/",$acl)) {
1409 $terminal = $value;
1410 $terminal['type'] = "S";
1411 # if (isset($value["FAIstate"][0])){
1412 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1413 # }
1414 }
1415 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1417 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1418 if($add != "" || preg_match("/r/",$acl)) {
1420 $terminal = $value;
1421 $terminal['type'] = "F";
1422 }
1423 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1425 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1426 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1427 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1428 if($add != "" || preg_match("/r/",$acl)) {
1430 $terminal = $value;
1431 $terminal['type'] = "Q";
1432 $terminal['is_new'] = $add;
1433 }
1434 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1435 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1436 $type= "winstation";
1437 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1438 if($add != "" || preg_match("/r/",$acl)) {
1440 $terminal = $value;
1441 $terminal['type'] = "C";
1442 }
1443 } else{
1445 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1446 if (isset($value['sambaDomainName'])){
1447 $domain= " [".$value['sambaDomainName'][0]."]";
1448 } else {
1449 $domain= "";
1450 }
1451 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1452 if($add != "" || preg_match("/r/",$acl)) {
1453 $terminal=$value;
1454 $terminal['type'] ="W";
1455 $terminal['domain'] = $name.$domain;
1456 }
1457 }
1459 /* Append collected data to the host list.
1460 */
1461 if(count($terminal)){
1462 $t_id ++ ;
1463 $this->terminals[$t_id]=$terminal;
1464 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1465 }
1466 }
1469 /* Merge real hosts with opsi hosts.
1470 If there is a samba host, then merge it with the opsi host,
1471 to avoid duplicate entries.
1472 */
1473 $oRex = preg_replace("/\*/",".*",$this->DivListSystem->Regex);
1474 foreach($opsi_clients as $entry){
1475 if(isset($opsi_map[$entry['cn'][0]]) || !preg_match("/".($oRex)."/", $entry['cn'][0])){
1476 continue;
1477 }
1478 $terminal = $entry;
1479 $terminal['type'] = "O";
1480 $this->terminals[] = $terminal;
1481 }
1483 $tmp =array();
1484 $tmp2 =array();
1485 foreach($this->terminals as $tkey => $val ){
1486 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1487 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1488 }
1489 natcasesort($tmp2);
1490 $this->terminals=array();
1491 foreach($tmp2 as $val){
1492 $this->terminals[]=$tmp[$val];
1493 }
1494 reset ($this->terminals);
1495 }
1497 function remove_lock()
1498 {
1500 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1501 del_lock($this->dn);
1502 }elseif (isset($this->systab->dn)){
1503 del_lock ($this->systab->dn);
1504 }
1505 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1506 del_lock($this->dns);
1507 }
1508 }
1511 function copyPasteHandling_from_queue($s_action,$s_entry)
1512 {
1513 /* Check if Copy & Paste is disabled */
1514 if(!is_object($this->CopyPasteHandler)){
1515 return("");
1516 }
1518 $ui = get_userinfo();
1520 $tabs = $this->get_tab_defs();
1522 /* Add a single entry to queue */
1523 if($s_action == "cut" || $s_action == "copy"){
1525 /* Cleanup object queue */
1526 $this->CopyPasteHandler->cleanup_queue();
1527 $dn = $this->terminals[$s_entry]['dn'];
1528 $oc = $this->terminals[$s_entry]['objectClass'];
1529 $type = $this->get_system_type($this->terminals[$s_entry]);
1531 $tab_o = $tabs[$type]['CLASS'];
1532 $tab_c = $tabs[$type]['TABCLASS'];
1533 $acl_c = $tabs[$type]['TABNAME'];
1534 $acl = $tabs[$type]['ACLC'];
1536 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1537 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1538 }
1539 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1540 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1541 }
1542 }
1544 /* Add entries to queue */
1545 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1547 /* Cleanup object queue */
1548 $this->CopyPasteHandler->cleanup_queue();
1550 /* Add new entries to CP queue */
1551 foreach($this->list_get_selected_items() as $id){
1552 $dn = $this->terminals[$id]['dn'];
1553 $oc = $this->terminals[$id]['objectClass'];
1554 $type = $this->get_system_type($this->terminals[$id]);
1556 if(isset($tabs[$type])){
1557 $tab_o = $tabs[$type]['CLASS'];
1558 $tab_c = $tabs[$type]['TABCLASS'];
1559 $acl_c = $tabs[$type]['TABNAME'];
1560 $acl = $tabs[$type]['ACLC'];
1562 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1563 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1564 }
1565 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1566 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1567 }
1568 }
1569 }
1570 }
1572 /* Start pasting entries */
1573 if($s_action == "editPaste"){
1574 $this->start_pasting_copied_objects = TRUE;
1575 }
1577 /* Return C&P dialog */
1578 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1580 /* Get dialog */
1581 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1582 $data = $this->CopyPasteHandler->execute();
1584 /* Return dialog data */
1585 if(!empty($data)){
1586 return($data);
1587 }
1588 }
1590 /* Automatically disable status for pasting */
1591 if(!$this->CopyPasteHandler->entries_queued()){
1592 $this->start_pasting_copied_objects = FALSE;
1593 }
1594 return("");
1595 }
1598 function get_system_type($attrs)
1599 {
1600 $classes = $attrs['objectClass'];
1602 $type= "";
1603 if (in_array_ics('gosa_opsi_client', $classes)){
1604 $type= "opsi_client";
1605 }elseif (in_array_ics('sambaAccount', $classes) ||
1606 in_array_ics('sambaSamAccount', $classes)){
1607 $type= "winstation";
1608 }elseif (in_array_ics('ieee802Device', $classes)){
1609 $type= "component";
1610 }elseif (in_array_ics('gotoTerminal', $classes)){
1611 $type= "terminal";
1612 }elseif (in_array_ics('gotoWorkstation', $classes)){
1613 $type= "workstation";
1614 }elseif (in_array_ics('gotoPrinter', $classes)){
1615 $type= "printer";
1616 }elseif (in_array_ics('goFonHardware', $classes)){
1617 $type= "phone";
1618 }elseif (in_array_ics('goServer', $classes)){
1619 $type= "server";
1620 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1621 $type= "ArpNewDevice";
1622 }elseif (in_array_ics('GOhard', $classes)){
1623 $type= "NewDevice";
1624 }
1625 return ($type);
1626 }
1629 function convert_list($input)
1630 {
1631 $temp= "";
1633 $conv= array(
1634 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1635 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1636 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1637 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1639 "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1641 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1642 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1643 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1645 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1646 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1647 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1649 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1650 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1651 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1653 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1654 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1656 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1657 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1658 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1660 /* Add opsi client to system types */
1661 if($this->opsi != NULL){
1662 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1663 }
1665 /* Use locked icons
1666 */
1667 if( in_array($input['type'],array("S","T","L")) &&
1668 isset($input['gotoMode'][0]) &&
1669 preg_match("/locked/",$input['gotoMode'][0])){
1670 $input['type'].="X";
1671 } elseif(in_array($input['type'],array("S","L")) &&
1672 isset($input['FAIstate'][0])){
1674 /* Add FAI state icons
1675 */
1676 $type= "";
1677 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1678 case 'error':
1679 $type= 'E';
1680 break;
1681 case 'installing':
1682 case 'install':
1683 case 'sysinfo':
1684 case 'softupdate':
1685 case 'scheduledupdate':
1686 $type= 'B';
1687 break;
1688 }
1690 $input['type'].= $type;
1691 }
1693 /* Use new images if object is from incoming
1694 */
1695 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1696 $input['type']="N".$input['type'];
1697 }
1699 /* Check which flags this objects uses
1700 */
1701 foreach ($conv as $key => $value){
1702 $found = TRUE;
1703 if(strlen($key) != strlen($input['type'])) {
1704 $found = FALSE;
1705 }
1706 for($i = 0 ; $i < strlen($key) ; $i++){
1707 if(!preg_match("/".$key[$i]."/",$input['type'])){
1708 $found = FALSE;
1709 }
1710 }
1712 if($found){
1713 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1714 $tmp['class']=$key;
1715 return $tmp;
1716 }
1717 }
1718 }
1721 function list_get_selected_items()
1722 {
1723 $ids = array();
1724 foreach($_POST as $name => $value){
1725 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1726 $id = preg_replace("/^item_selected_/","",$name);
1727 $ids[$id] = $id;
1728 }
1729 }
1730 return($ids);
1731 }
1734 public function get_tab_defs()
1735 {
1736 $tabs = array(
1737 "incoming" => array(
1738 "CLASS" => "",
1739 "TABNAME" => "",
1740 "TABCLASS" => "",
1741 "ACLC" => "incoming",
1742 "ACL" => "incoming/systems"),
1744 "ArpNewDevice"=> array(
1745 "CLASS" => "TERMTABS",
1746 "TABNAME" => "termgeneric" ,
1747 "TABCLASS" => "termtabs",
1748 "ACLC" => "incoming",
1749 "ACL" => "incoming/systems"),
1751 "NewDevice" => array(
1752 "CLASS" => "TERMTABS",
1753 "TABNAME" => "termgeneric",
1754 "TABCLASS" => "termtabs",
1755 "ACLC" => "incoming",
1756 "ACL" => "incoming/systems"),
1758 "terminal" => array(
1759 "CLASS" => "TERMTABS",
1760 "TABNAME" => "termgeneric",
1761 "TABCLASS" => "termtabs",
1762 "ACLC" => "terminal",
1763 "ACL" => "terminal/termgeneric"),
1765 "workstation" => array(
1766 "CLASS" => "WORKTABS",
1767 "TABNAME" => "workgeneric",
1768 "TABCLASS"=> "worktabs",
1769 "ACLC" => "workstation",
1770 "ACL" => "workstation/workgeneric" ),
1772 "server" => array(
1773 "CLASS" => "SERVTABS",
1774 "TABNAME" => "servgeneric",
1775 "TABCLASS"=> "servtabs",
1776 "ACLC" => "server",
1777 "ACL" => "server/servgeneric"),
1779 "printer" => array(
1780 "CLASS" => "PRINTTABS",
1781 "TABNAME" => "printgeneric",
1782 "TABCLASS"=> "printtabs",
1783 "ACLC" => "printer",
1784 "ACL" => "printer/printgeneric"),
1786 "phone" => array(
1787 "CLASS" => "PHONETABS",
1788 "TABNAME" => "phoneGeneric",
1789 "TABCLASS"=> "phonetabs",
1790 "ACLC" => "phone",
1791 "ACL" => "phone/phoneGeneric"),
1793 "winstation" => array(
1794 "CLASS" => "WINTABS",
1795 "TABNAME" => "wingeneric",
1796 "TABCLASS"=> "wintabs",
1797 "ACLC" => "winworkstation",
1798 "ACL" => "winworkstation/wingeneric"),
1800 "component" => array(
1801 "CLASS" => "COMPONENTTABS",
1802 "TABNAME" => "componentGeneric",
1803 "TABCLASS"=> "componenttabs",
1804 "ACLC" => "component",
1805 "ACL" => "component/componentGeneric"));
1807 if($this->opsi != NULL){
1808 $tabs["opsi_client"] = array(
1809 "CLASS" => "OPSITABS",
1810 "TABNAME" => "opsiGeneric" ,
1811 "TABCLASS"=> "opsi_tabs",
1812 "ACLC" => "opsi" ,
1813 "ACL" => "opsi/opsiGeneric");
1814 }
1816 return($tabs);
1817 }
1820 /*! \brief Sets FAIstate to "install" for "New Devices".
1821 This function is some kind of "Post handler" for activated systems,
1822 it is called directly after the object (workstabs,servtabs) gets saved.
1823 @param String $dn The dn of the newly activated object.
1824 @return Boolean TRUE if activated else FALSE
1825 */
1826 function activate_new_device($dn)
1827 {
1828 $ldap = $this->config->get_ldap_link();
1829 $ldap->cd($this->config->current['BASE']);
1830 $ldap->cat($dn);
1831 if($ldap->count()){
1832 $attrs = $ldap->fetch();
1833 $type = $this->get_system_type($attrs);
1834 if(!in_array($type,array("workstation","server"))) {
1835 $ocs = $attrs['objectClass'];
1836 unset($ocs['count']);
1837 $new_attrs = array();
1838 if(!in_array("FAIobject",$ocs)){
1839 $ocs[] = "FAIobject";
1840 $new_attrs['objectClass'] = $ocs;
1841 }
1842 $new_attrs['FAIstate'] = "install";
1843 $ldap->cd($dn);
1844 $ldap->modify($new_attrs);
1845 if (!$ldap->success()){
1846 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1847 LDAP_MOD, "activate_new_device($dn)"));
1848 }else{
1849 return(TRUE);
1850 }
1851 }
1852 }
1853 return(FALSE);
1854 }
1857 /* !! Incoming dummy acls, required to defined acls for incoming objects
1858 */
1859 static function plInfo()
1860 {
1861 return (array(
1862 "plShortName" => _("Incoming objects"),
1863 "plDescription" => _("Incoming objects"),
1864 "plSelfModify" => FALSE,
1865 "plDepends" => array(),
1866 "plPriority" => 99,
1867 "plSection" => array("administration"),
1868 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1869 "objectClass" => "")),
1870 "plProvidedAcls"=> array()
1872 ));
1873 }
1874 }
1876 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1877 ?>