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 if (isset($_POST['edit_continue'])) {
153 $s_action = "select_ogroup_finished";
154 }
156 /* handle C&P from layers menu */
157 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
158 $s_action = "copy_multiple";
159 }
160 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
161 $s_action = "cut_multiple";
162 }
163 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
164 $s_action = "editPaste";
165 }
167 /* Handle daemon events */
168 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
169 $s_action = $_POST['menu_action'];
170 }
172 /* Handle daemon events */
173 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
174 $s_action = $_POST['menu_action'];
175 }
177 /* handle remove from layers menu */
178 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
179 $s_action = "del_multiple";
180 }
182 /* Handle instant actions from layers menu */
183 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
184 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
185 $s_action = "${act}_multiple";
186 }
187 }
189 /* Activate multiple machines */
190 if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
191 $s_action = "activate_multiple";
192 }
194 /* Check for exeeded sizelimit */
195 if (($message= check_sizelimit()) != ""){
196 return($message);
197 }
199 /* Try to get informations about what kind of system to create */
200 if ($s_action=="new") {
201 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
202 }
204 /* Incoming handling
205 * If someone made a systemtype and ogroup selection
206 * Display the new requested entry type ... servtab in case of server and so on.
207 */
208 if(isset($_POST['SystemTypeChoosen'])){
209 $s_action = "SelectedSystemType";
210 }
212 /********************
213 Copy & Paste Handling ...
214 ********************/
216 /* Display the copy & paste dialog, if it is currently open */
217 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
218 if($ret){
219 return($ret);
220 }
223 /********************
224 Create FAI CD ...
225 ********************/
226 if ($s_action=="gen_cd"){
227 $this->dn= $this->terminals[$s_entry]['dn'];
228 set_object_info($this->dn);
229 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
230 }
233 /* Start CD-Creation */
234 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
235 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
236 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
237 }
240 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
242 $return_button = "<form method='get' action='main.php' target='_parent'>
243 <input type='submit' value='"._("Back")."'>
244 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
245 </form>";
247 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
249 /* Get and check command */
250 $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
252 if (check_command($command)){
253 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
255 /* Print out html introduction */
256 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
257 <html>
258 <head>
259 <title></title>
260 <style type="text/css">@import url("themes/default/style.css");</style>
261 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
262 </head>
263 <body style="background: none; margin:4px;" id="body" >
264 <pre>';
266 /* Open process handle and check if it is a valid process */
267 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
268 if (is_resource($process)) {
269 fclose($pipes[0]);
271 /* Print out returned lines && write JS to scroll down each line */
272 while (!feof($pipes[1])){
273 $cur_dat = fgets($pipes[1], 1024);
274 echo $cur_dat;
275 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
276 flush();
277 }
278 }
280 /* Get error string && close streams */
281 $buffer= stream_get_contents($pipes[2]);
283 fclose($pipes[1]);
284 fclose($pipes[2]);
285 echo "</pre>";
287 /* Check return code */
288 $ret= proc_close($process);
289 if ($ret != 0){
290 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
291 echo "<pre style='color:red'>$buffer</pre>";
292 }
296 echo $return_button."<br>";
298 } else {
299 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
300 echo $tmp;
301 }
303 /* Scroll down completly */
304 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
305 echo '</body></html>';
306 flush();
307 exit;
308 }
311 /********************
312 New Device handling (Ogroup/System select dialog.)
313 ********************/
315 /* All objects that have to be activated are listed in
316 $this->system_activation_object[] = "dn";
318 If there is an object group selected we simply adopt all
319 settings from these group and then directly save the entry again.
320 If no object group was selected, then we keep the "edit" dialog of
321 the target system opened to allow to edit the objects attributes.
322 */
324 if($s_action == "SelectedSystemType"){
326 /* Possible destination system types
327 */
328 $tabs = $this->get_tab_defs();
330 /* Remember dialog selection.
331 */
332 $selected_group = $_POST['ObjectGroup'];
333 $selected_system = $_POST['SystemType'];
335 $this->systab = NULL;
337 /* Check if system type exists. It should! */
338 if(isset($tabs[$selected_system])){
340 /* Get tab informations */
341 $class = $tabs[$selected_system]["CLASS"];
342 $tabname = $tabs[$selected_system]["TABNAME"];
343 $tabclass = $tabs[$selected_system]["TABCLASS"];
344 $acl_cat = $tabs[$selected_system]["ACLC"];
347 if(!class_available($tabclass)){
348 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
349 }else{
351 /* Go through all objects that should be activated
352 Contains alls object dns that have to be activated ("New Devices" not unknown)
353 */
354 foreach($this->system_activation_object as $key => $dn){
356 /* Remove entry from list, to avoid page-reload problems */
357 unset($this->system_activation_object[$key]);
359 /* Load permissions for selected 'dn' and check if
360 we're allowed to create this 'dn' */
361 $this->dn = $dn;
362 $ui = get_userinfo();
363 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
365 /* We are allowed to create the requested system type */
366 if(preg_match("/c/",$tabacl)){
367 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
368 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
369 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
370 $this->systab->base = $this->DivListSystem->selectedBase;
372 /* This will be used when the object is saved, to set FAIstate to 'install'
373 and to preset maybe other attributes.
374 */
375 $this->systab->was_activated = TRUE;
377 /* Assign some default values for opsi hosts
378 */
379 if($this->systab instanceOf opsi_tabs){
380 $ldap = $this->config->get_ldap_link();
381 $ldap->cat($dn);
382 $source_attrs = $ldap->fetch();
383 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
384 if(isset($source_attrs[$src][0])){
385 $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
386 }
387 }
388 }
390 if($selected_group != "none"){
392 /*******
393 * Set gotoMode to active if there was an ogroup selected.
394 */
395 $found = false;
396 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
397 if(isset($this->systab->by_object[$tab]->gotoMode)) {
398 $found = true;
399 $this->systab->by_object[$tab]->gotoMode = $value;
400 }
401 }
402 if(!$found){
403 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
404 }
406 /*******
407 * Update object group membership
408 */
409 $og = new ogroup($this->config,$selected_group);
410 if($og){
411 $og->AddDelMembership($this->systab->dn);
412 $og->save();
413 }
415 /*******
416 * Enable inheritance
417 */
418 foreach (array("workgeneric", "termgeneric") as $cls){
419 if (isset($this->systab->by_object[$cls])){
420 $this->systab->by_object[$cls]->member_of_ogroup = true;
421 $this->systab->by_object[$cls]->set_everything_to_inherited();
422 $this->systab->by_object[$cls]->save();
423 }
424 }
426 // Enable activation
427 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
428 if (isset($this->systab->by_object[$cls])){
429 $this->systab->by_object[$cls]->auto_activate= TRUE;
430 }
431 }
432 }
434 /* Don't save directly if there is no objectGroup selected.
435 The user will then be able to configure the missing attributes
436 on his own.
437 */
438 if($selected_group != "none"){
439 $this->systab->save();
441 /* Post handling for activated new devices
442 */
443 $this->activate_new_device($this->systab->dn);
444 $this->systab = NULL;
446 if(!isset($ldap)){
447 $ldap = $this->config->get_ldap_link();
448 }
449 $ldap->cd ($this->dn);
450 $ldap->cat($this->dn, array('dn'));
451 if(count($ldap->fetch())){
452 $ldap->cd($this->dn);
453 $ldap->rmDir($this->dn);
454 }
455 }
456 }else{
457 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
458 }
459 }
460 }
461 }
462 }
465 if ($s_action=="select_ogroup_finished") {
466 $this->systab->save_object();
468 if (count($this->systab->check())!=0) {
469 foreach($this->systab->check() as $msg){
470 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
471 }
472 }elseif(isset($this->systab->objectClass) && isset($this->systab->sw)) {
473 $this->dn = "new";
474 $sw = $this->systab->sw;
475 $tabs = $this->get_tab_defs();
476 $class = $tabs[$sw]["CLASS"];
477 $tabname = $tabs[$sw]["TABNAME"];
478 $tabclass = $tabs[$sw]["TABCLASS"];
479 $acl_cat = $tabs[$sw]["ACLC"];
480 $ogroup = $this->systab->save();
481 if (class_exists($tabclass)) {
482 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
483 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
484 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
485 $this->systab->by_object[$tabname]->ogroup = $ogroup;
486 $this->systab->base = $this->DivListSystem->selectedBase;
487 }
488 }
489 }
491 if (isset($_POST['create_system'])||$s_action=="newsystem") {
493 $this->last_action = "";
495 /* If the current entry is an incoming object
496 * $sw = System type as posted in new incoming handling dialog
497 */
498 if(isset($_POST['system'])){
499 $sw = $_POST['system'];
500 }else{
501 $sw = $s_entry;
502 }
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)){
519 if ($tabclass == 'worktabs') {
520 $this->systab = new askObjectGroup($this->config, $this->dn, $ui, $tabclass, $sw);
521 }
522 else {
523 if(!class_available($tabclass)){
524 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
525 }else{
526 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
527 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
528 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
529 $this->systab->base = $this->DivListSystem->selectedBase;
530 }
531 }
532 }else{
533 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
534 }
535 }
536 }
538 /********************
539 System activation
540 ********************/
542 /* User wants to edit data? */
543 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
544 $this->system_activation_object = array();
545 foreach($this->list_get_selected_items() as $id) {
546 $obj = $this->terminals[$id];
547 $type= $this->get_system_type($obj);
548 if($type == "NewDevice"){
549 $this->system_activation_object[] = $obj['dn'];
550 }
551 }
552 if(count($this->system_activation_object)){
553 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
554 }
555 }
558 /********************
559 Edit system ...
560 ********************/
562 /* User wants to edit data? */
563 if (($s_action == "edit") && (!isset($this->systab->config))){
564 $this->last_action = "";
565 $this->dn= $this->terminals[$s_entry]['dn'];
567 /* Check locking, save current plugin in 'back_plugin', so
568 the dialog knows where to return. */
569 if (($user= get_lock($this->dn)) != ""){
570 return(gen_locked_message ($user, $this->dn,TRUE));
571 }
573 /* Find out more about the object type */
574 $attrs = $this->terminals[$s_entry];
575 $type= $this->get_system_type($attrs);
577 /* Lock the current entry, so everyone will get the
578 above dialog */
579 $tabs = $this->get_tab_defs();
581 if($type == "ArpNewDevice"){
582 if(!class_available("ArpNewDeviceTabs")){
583 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
584 }else{
585 add_lock ($this->dn, $this->ui->dn);
586 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
587 }
588 }elseif($type == "NewDevice"){
589 if(!class_available("SelectDeviceType")){
590 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
591 }else{
592 add_lock ($this->dn, $this->ui->dn);
593 $this->system_activation_object= array($this->dn);
594 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
596 // see condition -$s_action == "SelectedSystemType"- for further handling
597 }
598 }elseif(isset($tabs[$type])){
600 $class = $tabs[$type]["CLASS"];
601 $acl_cat = $tabs[$type]["ACLC"];
602 $tabclass = $tabs[$type]["TABCLASS"];
604 if(!class_available($tabclass)){
605 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
606 }else{
607 add_lock ($this->dn, $this->ui->dn);
608 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
609 $this->systab->set_acl_base($this->dn);
610 set_object_info($this->dn);
611 }
612 }else{
613 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
614 $this->remove_lock();
615 }
616 }
619 /********************
620 Change password ...
621 ********************/
623 /* Set terminals root password */
624 if ($s_action=="change_pw"){
625 $tabs = $this->get_tab_defs();
627 $dn = $this->terminals[$s_entry]['dn'];
628 $type = $this->get_system_type($this->terminals[$s_entry]);
630 $class = $tabs[$type]["CLASS"];
631 $acl = $tabs[$type]["ACL"];
632 $tabclass = $tabs[$type]["TABCLASS"];
633 $ui = get_userinfo();
634 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
635 if(preg_match("/w/",$tabacl)){
636 $this->dn= $this->terminals[$s_entry]['dn'];
637 set_object_info($this->dn);
638 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
639 }else{
640 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
641 }
642 }
645 /********************
646 Password change finish, but check if entered data is ok
647 ********************/
649 /* Correctly specified? */
650 if (isset($_POST['password_finish'])){
651 if ($_POST['new_password'] != $_POST['repeated_password']){
652 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
653 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
654 }
655 }
657 /********************
658 Password change finish
659 ********************/
661 /* Change terminal password */
662 if (isset($_POST['password_finish']) &&
663 $_POST['new_password'] == $_POST['repeated_password']){
665 /* Check if user is allowed to set password */
666 $tabs = $this->get_tab_defs();
668 $type = "";
669 foreach($this->terminals as $terminal){
670 if($terminal['dn'] == $this->dn){
671 $type = $this->get_system_type($terminal);
672 break;
673 }
674 }
676 /* Type detected */
677 $allow_for = array("terminal","workstation","server","component");
678 if(!empty($type) && in_array($type,$allow_for)){
680 /* Get infos */
681 $plug = $tabs[$type]["TABNAME"];
682 $acl = $tabs[$type]["ACL"];
683 $tabclass = $tabs[$type]["TABCLASS"];
685 /* Get acls */
686 $ui = get_userinfo();
687 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
689 /* Check acls */
690 if(preg_match("/w/",$tabacl)){
691 $ldap = $this->config->get_ldap_link();
692 $ldap->cd($this->dn);
693 $ldap->cat($this->dn);
694 $old_attrs = $ldap->fetch();
696 $attrs= array();
697 if ($_POST['new_password'] == ""){
699 /* Remove password attribute
700 */
701 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
702 $attrs['objectClass'] = array();
703 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
704 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
705 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
706 }
707 }
708 }
709 $attrs['userPassword']= array();
710 } else {
712 /* Add/modify password attribute
713 */
714 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
715 $attrs['objectClass'] = array();
716 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
717 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
718 }
719 $attrs['objectClass'][] = "simpleSecurityObject";
720 }
722 if(class_available("passwordMethodCrypt")){
723 $pwd_m = new passwordMethodCrypt($this->config);
724 $pwd_m->set_hash("crypt/md5");
725 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
726 }else{
727 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
728 $attrs = array();
729 }
730 }
731 $ldap->modify($attrs);
732 if (!$ldap->success()){
733 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
734 }else{
735 if(class_available($plug)){
736 $p = new $plug($this->config,$this->dn);
737 $p->handle_post_events("modify");
738 }
739 }
741 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
742 }else{
743 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
744 }
745 }else{
746 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
747 }
748 set_object_info();
749 }
752 /********************
753 Delete system cancel
754 ********************/
756 /* Delete terminal canceled? */
757 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
758 $this->remove_lock();
759 set_object_info();
760 }
763 /********************
764 Action(s) for MULTIPLE
765 ********************/
767 /********************
768 SCHEDULE action in GOsa Daemon
769 ********************/
771 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
772 $this->dns = array();
773 $ids = $this->list_get_selected_items();
775 /* Handle opsi actions */
776 if($s_action == "trigger_event_DaemonEvent_reinstall"){
777 foreach($ids as $key => $id){
778 if($this->terminals[$id]['type'] == "O"){
779 $obj = $this->terminals[$id];
780 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
781 unset($ids[$key]);
782 }
783 }
784 }
786 if(count($ids) && class_available("DaemonEvent")){
787 $mac= array();
789 /* Collect target mac addresses */
790 $ldap = $this->config->get_ldap_link();
791 foreach($ids as $id){
792 $type = $this->get_system_type($this->terminals[$id]);
793 if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
794 if(isset($this->terminals[$id]['macAddress'][0])){
795 $mac[] = $this->terminals[$id]['macAddress'][0];
796 }else{
797 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
798 $attrs= $ldap->fetch();
799 if (isset($attrs['macAddress'][0])){
800 $mac[]= $attrs['macAddress'][0];
801 }
802 }
803 }
804 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
805 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
806 $o_queue = new gosaSupportDaemon();
808 /* Skip installation or update trigerred events,
809 * if this entry is currently processing.
810 */
811 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
812 foreach($mac as $key => $mac_address){
813 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
815 $entry['STATUS'] = strtoupper($entry['STATUS']);
816 if($entry['STATUS'] == "PROCESSING" &&
817 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
818 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
819 unset($mac[$key]);
821 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
822 break;
823 }
824 }
825 }
826 }
828 /* Prepare event to be added
829 */
830 if(count($mac) && isset($events['BY_CLASS'][$type])){
831 $event = $events['BY_CLASS'][$type];
832 $this->systab = new $event['CLASS_NAME']($this->config);
833 $this->systab->add_targets($mac);
834 if(preg_match("/trigger_event/",$s_action)){
835 $this->systab->set_type(TRIGGERED_EVENT);
836 }else{
837 $this->systab->set_type(SCHEDULED_EVENT);
838 }
839 }
840 }
841 }
843 /* Insert scheduled events into queue */
844 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
845 $this->systab->save_object();
847 /* Save event
848 */
849 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
850 $o_queue = new gosaSupportDaemon();
851 $this->systab = DaemonEvent::save_event_dialog($this->systab, NULL, $o_queue, $this->config);
853 }
854 if(isset($_POST['abort_event_dialog'])){
855 $this->systab = FALSE;
856 }
857 }
860 /********************
861 Delete MULTIPLE entries requested, display confirm dialog
862 ********************/
864 if ($s_action=="del_multiple" || $s_action == "del"){
865 $this->dns = array();
867 if($s_action == "del_multiple"){
868 $ids = $this->list_get_selected_items();
869 }else{
870 $ids = array($s_entry);
871 }
873 $ui = get_userinfo();
874 $tabs = $this->get_tab_defs();
876 if(count($ids)){
878 $disallowed = array();
879 foreach($ids as $id){
881 /* Get 'dn' from posted termlinst */
882 $attrs = $this->terminals[$id];
883 $type = $this->get_system_type($attrs);
884 $dn = $attrs['dn'];
885 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
886 if(preg_match("/d/",$acl)){
887 $this->dns[$id] = $dn;
888 }else{
889 $disallowed[] = $dn;
890 }
891 }
893 if(count($disallowed)){
894 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
895 }
897 if(count($this->dns)){
899 if ($user= get_multiple_locks($this->dns)){
900 return(gen_locked_message($user,$this->dns));
901 }
903 $dns_names = array();
904 foreach($this->dns as $dn){
905 add_lock ($dn, $this->ui->dn);
906 $dns_names[] = LDAP::fix($dn);
907 }
909 /* Lock the current entry, so nobody will edit it during deletion */
910 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
911 $smarty->assign("multiple", true);
912 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
913 }
914 }
915 }
918 /********************
919 Delete MULTIPLE entries confirmed
920 ********************/
922 /* Confirmation for deletion has been passed. Users should be deleted. */
923 if (isset($_POST['delete_multiple_system_confirm'])){
925 $ui = get_userinfo();
926 $tabs = $this->get_tab_defs();
928 /* Remove user by user and check acls before removeing them */
929 foreach($this->dns as $key => $dn){
931 /* Get 'dn' from posted termlinst */
932 $attrs = $this->terminals[$key];
933 $type= $this->get_system_type($attrs);
935 /* get object type */
936 $tabtype = "termtabs";
937 $tabobj = "TERMTABS";
938 $tabacl = "";
939 if(isset($tabs[$type])){
940 $tabtype = $tabs[$type]['TABCLASS'];
941 $tabobj = $tabs[$type]['CLASS'];
942 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
944 /* Load permissions for selected 'dn' and check if
945 we're allowed to remove this 'dn' */
946 if(preg_match("/d/",$tabacl)){
948 /* Delete request is permitted, perform LDAP action */
949 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
950 $this->systab= new termgeneric($this->config, $dn);
951 $this->systab->set_acl_base($dn);
952 $this->systab->set_acl_category("terminal");
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 && $this->systab->was_activated){
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 }
1133 return ($display);
1134 }
1136 /* Check if there is a snapshot dialog open */
1137 $base = $this->DivListSystem->selectedBase;
1138 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1139 return($str);
1140 }
1142 /* Display dialog with system list */
1143 $this->DivListSystem->parent = $this;
1144 $this->DivListSystem->execute();
1146 /* Add departments if subsearch is disabled */
1147 if(!$this->DivListSystem->SubSearch){
1149 /* Add FAIstate to attributes if FAI is activated */
1150 if($this->fai_activated){
1151 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1152 }else{
1153 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1154 }
1155 }
1156 $this->reload();
1157 $this->DivListSystem->setEntries($this->terminals);
1158 return($this->DivListSystem->Draw());
1159 }
1162 /* Return departments, that will be included within snapshot detection */
1163 function get_used_snapshot_bases()
1164 {
1165 $tmp = array();
1167 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1169 $tabs = array(
1170 "terminal" => get_ou('terminalRDN'),
1171 "workstation" => get_ou('workstationRDN'),
1172 "incoming" => get_ou('systemIncomingRDN'),
1173 "server" => get_ou('serverRDN'),
1174 "printer" => get_ou('printerRDN'),
1175 "phone" => get_ou('phoneRDN'),
1176 "winworkstation" => get_winstations_ou(),
1177 "component" => get_ou('componentRDN')
1178 );
1180 foreach($tabs as $acl_cat => $dn){
1182 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1183 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1184 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1185 }
1186 }
1187 return($tmp);
1188 }
1191 function remove_from_parent()
1192 {
1193 /* Optionally execute a command after we're done */
1194 $this->postremove();
1195 }
1198 /* Save data to object */
1199 function save_object()
1200 {
1201 $this->DivListSystem->save_object();
1202 if(is_object($this->CopyPasteHandler)){
1203 $this->CopyPasteHandler->save_object();
1204 }
1205 }
1208 /* Check values */
1209 function check()
1210 {
1211 }
1214 /* Save to LDAP */
1215 function save()
1216 {
1217 }
1219 function adapt_from_template($dn, $skip= array())
1220 {
1221 }
1223 function password_change_needed()
1224 {
1225 }
1227 function reload()
1228 {
1229 /* some var init */
1230 $ui = get_userinfo();
1231 $res = array();
1232 $this->terminals = array();
1233 $userregex = "";
1234 $opsi_clients = array();
1236 /* Set base for all searches */
1237 $base= $this->DivListSystem->selectedBase;
1239 /* Prepare samba class name */
1240 $samba ="";
1241 if ($this->DivListSystem->ShowWinWorkstations){
1242 if ($this->config->get_cfg_value("sambaversion") == "3"){
1243 $samba= "sambaSamAccount";
1244 } else {
1245 $samba= "sambaAccount";
1246 }
1247 }
1249 /* This array represents the combination between checkboxes and search filters */
1250 $objs = array(
1251 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1252 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1253 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1254 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1255 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1256 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1257 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1259 /* Include the 'Display Systems of user' attribute */
1260 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1261 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1262 }
1264 /* Attributes to fetch */
1265 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1266 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1268 /* Add FAIstate to attributes if FAI is activated */
1269 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1270 if(!empty($tmp)){
1271 $sys_attrs[] = "FAIstate";
1272 }
1274 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1275 foreach($objs as $checkBox => $oc){
1277 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1278 if($this->DivListSystem->SubSearch){
1279 if($oc['CLASS'] != ""){
1280 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1281 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1282 $res = array_merge($res,$new_res);
1283 }
1284 }else{
1285 /* User filter? */
1286 if($oc['CLASS'] != ""){
1287 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")";
1288 /* Decide weither to search in description and CN or only in the CN */
1289 if ($this->DivListSystem->DescSearch) {
1290 $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1291 }
1292 else {
1293 $filter = $filter . "(cn=".$this->DivListSystem->Regex."))";
1294 }
1295 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1296 }
1297 }
1298 }
1299 }
1301 /* Search for incoming objects */
1302 $filter = "(|(&".$userregex."(objectClass=goHard)";
1303 if ($this->DivListSystem->DescSearch) {
1304 $filter = $filter . "(|(cn=".$this->DivListSystem->Regex.")(description=".$this->DivListSystem->Regex.")))";
1305 }
1306 else {
1307 $filter = $filter . "(cn=".$this->DivListSystem->Regex.")))";
1308 }
1309 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$this->config->get_cfg_value('base'),$sys_attrs, GL_SIZELIMIT));
1311 /* Append opsi systems, the opsi extension have to installed.
1312 (Only, if we are allowed to view opsi hosts)
1313 */
1314 if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1315 $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1316 if(preg_match("/r/",$o_acl)){
1317 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1318 if($this->opsi->is_error()){
1319 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1320 }
1321 }
1322 }
1324 /* Get all gotoTerminal's */
1325 $t_id = 0;
1326 $opsi_map = array();
1327 foreach ($res as $value){
1329 $tmp= $value['dn'];
1330 $add= "";
1332 /* Extract base */
1333 foreach($objs as $obj){
1334 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1335 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1336 }
1337 }
1339 /* Create a string containing the last part of the department. */
1340 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1341 if(empty($dn_name)){
1342 $dn_name = "/";
1343 }
1345 /* check if current object is a new one */
1346 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1347 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1348 $add= "- "._("New terminal");
1349 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1350 $add= "- "._("New workstation");
1351 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1352 $add= "- "._("Unknown device");
1353 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1354 $add= "- "._("New Device");
1355 }
1356 }
1358 /* Detect type of object and create an entry for $this->terminals */
1359 $terminal = array();
1361 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1363 /* check acl */
1364 $terminal = $value;
1365 $terminal['type'] = "O";
1367 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1369 /* check acl */
1370 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1371 if($add != "" || preg_match("/r/",$acl)) {
1372 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1373 $terminal = $value;
1374 $terminal['type'] = "T";
1375 $terminal['is_new'] = $add;
1376 } else {
1377 $terminal = $value;
1378 $terminal['type'] = "D";
1379 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1380 $terminal['location'] = array_search($tmp, $this->config->departments);
1381 }
1382 }
1383 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1385 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1386 if($add != "" || preg_match("/r/",$acl)) {
1387 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1388 $terminal = $value;
1389 $terminal['type'] = "L";
1390 $terminal['is_new'] = $add;
1391 } else {
1392 $terminal = $value;
1393 $terminal['type'] = "D";
1394 $terminal['location'] = array_search($tmp, $this->config->departments);
1395 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1396 }
1397 # if (isset($value["FAIstate"][0])){
1398 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1399 # }
1400 }
1401 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1404 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1405 if($add != "" || preg_match("/r/",$acl)) {
1407 $terminal = $value;
1408 $terminal['type'] = "P";
1409 }
1410 } elseif (in_array_ics('goServer', $value["objectClass"])){
1412 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1413 if($add != "" || preg_match("/r/",$acl)) {
1415 $terminal = $value;
1416 $terminal['type'] = "S";
1417 # if (isset($value["FAIstate"][0])){
1418 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1419 # }
1420 }
1421 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1423 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1424 if($add != "" || preg_match("/r/",$acl)) {
1426 $terminal = $value;
1427 $terminal['type'] = "F";
1428 }
1429 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1431 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1432 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1433 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1434 if($add != "" || preg_match("/r/",$acl)) {
1436 $terminal = $value;
1437 $terminal['type'] = "Q";
1438 $terminal['is_new'] = $add;
1439 }
1440 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1441 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1442 $type= "winstation";
1443 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1444 if($add != "" || preg_match("/r/",$acl)) {
1446 $terminal = $value;
1447 $terminal['type'] = "C";
1448 }
1449 } else{
1451 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1452 if (isset($value['sambaDomainName'])){
1453 $domain= " [".$value['sambaDomainName'][0]."]";
1454 } else {
1455 $domain= "";
1456 }
1457 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1458 if($add != "" || preg_match("/r/",$acl)) {
1459 $terminal=$value;
1460 $terminal['type'] ="W";
1461 $terminal['domain'] = $name.$domain;
1462 }
1463 }
1465 /* Append collected data to the host list.
1466 */
1467 if(count($terminal)){
1468 $t_id ++ ;
1469 $this->terminals[$t_id]=$terminal;
1470 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1471 }
1472 }
1475 /* Merge real hosts with opsi hosts.
1476 If there is a samba host, then merge it with the opsi host,
1477 to avoid duplicate entries.
1478 */
1479 foreach($opsi_clients as $entry){
1480 if(isset($opsi_map[$entry['cn'][0]])){
1481 continue;
1482 }
1483 $terminal = $entry;
1484 $terminal['type'] = "O";
1485 $this->terminals[] = $terminal;
1486 }
1488 $tmp =array();
1489 $tmp2 =array();
1490 foreach($this->terminals as $tkey => $val ){
1491 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1492 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1493 }
1494 natcasesort($tmp2);
1495 $this->terminals=array();
1496 foreach($tmp2 as $val){
1497 $this->terminals[]=$tmp[$val];
1498 }
1499 reset ($this->terminals);
1500 }
1502 function remove_lock()
1503 {
1504 if (isset($this->systab->dn)){
1505 del_lock ($this->systab->dn);
1506 }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1507 del_lock($this->dn);
1508 }
1509 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1510 del_lock($this->dns);
1511 }
1512 }
1515 function copyPasteHandling_from_queue($s_action,$s_entry)
1516 {
1517 /* Check if Copy & Paste is disabled */
1518 if(!is_object($this->CopyPasteHandler)){
1519 return("");
1520 }
1522 $ui = get_userinfo();
1524 $tabs = $this->get_tab_defs();
1526 /* Add a single entry to queue */
1527 if($s_action == "cut" || $s_action == "copy"){
1529 /* Cleanup object queue */
1530 $this->CopyPasteHandler->cleanup_queue();
1531 $dn = $this->terminals[$s_entry]['dn'];
1532 $oc = $this->terminals[$s_entry]['objectClass'];
1533 $type = $this->get_system_type($this->terminals[$s_entry]);
1535 $tab_o = $tabs[$type]['CLASS'];
1536 $tab_c = $tabs[$type]['TABCLASS'];
1537 $acl_c = $tabs[$type]['TABNAME'];
1538 $acl = $tabs[$type]['ACLC'];
1540 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1541 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1542 }
1543 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1544 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1545 }
1546 }
1548 /* Add entries to queue */
1549 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1551 /* Cleanup object queue */
1552 $this->CopyPasteHandler->cleanup_queue();
1554 /* Add new entries to CP queue */
1555 foreach($this->list_get_selected_items() as $id){
1556 $dn = $this->terminals[$id]['dn'];
1557 $oc = $this->terminals[$id]['objectClass'];
1558 $type = $this->get_system_type($this->terminals[$id]);
1560 if(isset($tabs[$type])){
1561 $tab_o = $tabs[$type]['CLASS'];
1562 $tab_c = $tabs[$type]['TABCLASS'];
1563 $acl_c = $tabs[$type]['TABNAME'];
1564 $acl = $tabs[$type]['ACLC'];
1566 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1567 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1568 }
1569 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1570 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1571 }
1572 }
1573 }
1574 }
1576 /* Start pasting entries */
1577 if($s_action == "editPaste"){
1578 $this->start_pasting_copied_objects = TRUE;
1579 }
1581 /* Return C&P dialog */
1582 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1584 /* Get dialog */
1585 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1586 $data = $this->CopyPasteHandler->execute();
1588 /* Return dialog data */
1589 if(!empty($data)){
1590 return($data);
1591 }
1592 }
1594 /* Automatically disable status for pasting */
1595 if(!$this->CopyPasteHandler->entries_queued()){
1596 $this->start_pasting_copied_objects = FALSE;
1597 }
1598 return("");
1599 }
1602 function get_system_type($attrs)
1603 {
1604 $classes = $attrs['objectClass'];
1606 $type= "";
1607 if (in_array_ics('gosa_opsi_client', $classes)){
1608 $type= "opsi_client";
1609 }elseif (in_array_ics('sambaAccount', $classes) ||
1610 in_array_ics('sambaSamAccount', $classes)){
1611 $type= "winstation";
1612 }elseif (in_array_ics('ieee802Device', $classes)){
1613 $type= "component";
1614 }elseif (in_array_ics('gotoTerminal', $classes)){
1615 $type= "terminal";
1616 }elseif (in_array_ics('gotoWorkstation', $classes)){
1617 $type= "workstation";
1618 }elseif (in_array_ics('gotoPrinter', $classes)){
1619 $type= "printer";
1620 }elseif (in_array_ics('goFonHardware', $classes)){
1621 $type= "phone";
1622 }elseif (in_array_ics('goServer', $classes)){
1623 $type= "server";
1624 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1625 $type= "ArpNewDevice";
1626 }elseif (in_array_ics('GOhard', $classes)){
1627 $type= "NewDevice";
1628 }
1629 return ($type);
1630 }
1633 function convert_list($input)
1634 {
1635 $temp= "";
1637 $conv= array(
1638 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1639 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1640 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1641 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1643 "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1645 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1646 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1647 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1649 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1650 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1651 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1653 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1654 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1655 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1657 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1658 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1660 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1661 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1662 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1664 /* Add opsi client to system types */
1665 if($this->opsi != NULL){
1666 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1667 }
1669 /* Use locked icons
1670 */
1671 if( in_array($input['type'],array("S","T","L")) &&
1672 isset($input['gotoMode'][0]) &&
1673 preg_match("/locked/",$input['gotoMode'][0])){
1674 $input['type'].="X";
1675 } elseif(in_array($input['type'],array("S","L")) &&
1676 isset($input['FAIstate'][0])){
1678 /* Add FAI state icons
1679 */
1680 $type= "";
1681 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1682 case 'error':
1683 $type= 'E';
1684 break;
1685 case 'installing':
1686 case 'install':
1687 case 'sysinfo':
1688 case 'softupdate':
1689 case 'scheduledupdate':
1690 $type= 'B';
1691 break;
1692 }
1694 $input['type'].= $type;
1695 }
1697 /* Use new images if object is from incoming
1698 */
1699 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1700 $input['type']="N".$input['type'];
1701 }
1703 /* Check which flags this objects uses
1704 */
1705 foreach ($conv as $key => $value){
1706 $found = TRUE;
1707 if(strlen($key) != strlen($input['type'])) {
1708 $found = FALSE;
1709 }
1710 for($i = 0 ; $i < strlen($key) ; $i++){
1711 if(!preg_match("/".$key[$i]."/",$input['type'])){
1712 $found = FALSE;
1713 }
1714 }
1716 if($found){
1717 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1718 $tmp['class']=$key;
1719 return $tmp;
1720 }
1721 }
1722 }
1725 function list_get_selected_items()
1726 {
1727 $ids = array();
1728 foreach($_POST as $name => $value){
1729 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1730 $id = preg_replace("/^item_selected_/","",$name);
1731 $ids[$id] = $id;
1732 }
1733 }
1734 return($ids);
1735 }
1738 public function get_tab_defs()
1739 {
1740 $tabs = array(
1741 "incoming" => array(
1742 "CLASS" => "",
1743 "TABNAME" => "",
1744 "TABCLASS" => "",
1745 "ACLC" => "incoming",
1746 "ACL" => "incoming/systems"),
1748 "ArpNewDevice"=> array(
1749 "CLASS" => "TERMTABS",
1750 "TABNAME" => "termgeneric" ,
1751 "TABCLASS" => "termtabs",
1752 "ACLC" => "incoming",
1753 "ACL" => "incoming/systems"),
1755 "NewDevice" => array(
1756 "CLASS" => "TERMTABS",
1757 "TABNAME" => "termgeneric",
1758 "TABCLASS" => "termtabs",
1759 "ACLC" => "incoming",
1760 "ACL" => "incoming/systems"),
1762 "terminal" => array(
1763 "CLASS" => "TERMTABS",
1764 "TABNAME" => "termgeneric",
1765 "TABCLASS" => "termtabs",
1766 "ACLC" => "terminal",
1767 "ACL" => "terminal/termgeneric"),
1769 "workstation" => array(
1770 "CLASS" => "WORKTABS",
1771 "TABNAME" => "workgeneric",
1772 "TABCLASS"=> "worktabs",
1773 "ACLC" => "workstation",
1774 "ACL" => "workstation/workgeneric" ),
1776 "server" => array(
1777 "CLASS" => "SERVTABS",
1778 "TABNAME" => "servgeneric",
1779 "TABCLASS"=> "servtabs",
1780 "ACLC" => "server",
1781 "ACL" => "server/servgeneric"),
1783 "printer" => array(
1784 "CLASS" => "PRINTTABS",
1785 "TABNAME" => "printgeneric",
1786 "TABCLASS"=> "printtabs",
1787 "ACLC" => "printer",
1788 "ACL" => "printer/printgeneric"),
1790 "phone" => array(
1791 "CLASS" => "PHONETABS",
1792 "TABNAME" => "phoneGeneric",
1793 "TABCLASS"=> "phonetabs",
1794 "ACLC" => "phone",
1795 "ACL" => "phone/phoneGeneric"),
1797 "winstation" => array(
1798 "CLASS" => "WINTABS",
1799 "TABNAME" => "wingeneric",
1800 "TABCLASS"=> "wintabs",
1801 "ACLC" => "winworkstation",
1802 "ACL" => "winworkstation/wingeneric"),
1804 "component" => array(
1805 "CLASS" => "COMPONENTTABS",
1806 "TABNAME" => "componentGeneric",
1807 "TABCLASS"=> "componenttabs",
1808 "ACLC" => "component",
1809 "ACL" => "component/componentGeneric"));
1811 if($this->opsi != NULL){
1812 $tabs["opsi_client"] = array(
1813 "CLASS" => "OPSITABS",
1814 "TABNAME" => "opsiGeneric" ,
1815 "TABCLASS"=> "opsi_tabs",
1816 "ACLC" => "opsi" ,
1817 "ACL" => "opsi/opsiGeneric");
1818 }
1820 return($tabs);
1821 }
1824 /*! \brief Sets FAIstate to "install" for "New Devices".
1825 This function is some kind of "Post handler" for activated systems,
1826 it is called directly after the object (workstabs,servtabs) gets saved.
1827 @param String $dn The dn of the newly activated object.
1828 @return Boolean TRUE if activated else FALSE
1829 */
1830 function activate_new_device($dn)
1831 {
1832 $ldap = $this->config->get_ldap_link();
1833 $ldap->cd($this->config->current['BASE']);
1834 $ldap->cat($dn);
1835 if($ldap->count()){
1836 $attrs = $ldap->fetch();
1837 $type = $this->get_system_type($attrs);
1838 if(!in_array($type,array("workstation","server"))) {
1839 $ocs = $attrs['objectClass'];
1840 unset($ocs['count']);
1841 $new_attrs = array();
1842 if(!in_array("FAIobject",$ocs)){
1843 $ocs[] = "FAIobject";
1844 $new_attrs['objectClass'] = $ocs;
1845 }
1846 $new_attrs['FAIstate'] = "install";
1847 $ldap->cd($dn);
1848 $ldap->modify($new_attrs);
1849 if (!$ldap->success()){
1850 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1851 LDAP_MOD, "activate_new_device($dn)"));
1852 }else{
1853 return(TRUE);
1854 }
1855 }
1856 }
1857 return(FALSE);
1858 }
1861 /* !! Incoming dummy acls, required to defined acls for incoming objects
1862 */
1863 static function plInfo()
1864 {
1865 return (array(
1866 "plShortName" => _("Incoming objects"),
1867 "plDescription" => _("Incoming objects"),
1868 "plSelfModify" => FALSE,
1869 "plDepends" => array(),
1870 "plPriority" => 99,
1871 "plSection" => array("administration"),
1872 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1873 "objectClass" => "")),
1874 "plProvidedAcls"=> array()
1876 ));
1877 }
1878 }
1880 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1881 ?>