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('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('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($s_action == "SelectedSystemType"){
322 /* Possible destination system types
323 */
324 $tabs = $this->get_tab_defs();
326 /* Remember dialog selection.
327 */
328 $selected_group = $_POST['ObjectGroup'];
329 $selected_system = $_POST['SystemType'];
331 $this->systab = NULL;
333 /* Check if system type exists. It should! */
334 if(isset($tabs[$selected_system])){
336 /* Get tab informations */
337 $class = $tabs[$selected_system]["CLASS"];
338 $tabname = $tabs[$selected_system]["TABNAME"];
339 $tabclass = $tabs[$selected_system]["TABCLASS"];
340 $acl_cat = $tabs[$selected_system]["ACLC"];
343 if(!class_available($tabclass)){
344 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
345 }else{
347 /* Go through all objects that should be activated
348 Contains alls object dns that have to be activated ("New Devices" not unknown)
349 */
350 foreach($this->system_activation_object as $key => $dn){
352 /* Remove entry from list, to avoid page-reload problems */
353 unset($this->system_activation_object[$key]);
355 /* Load permissions for selected 'dn' and check if
356 we're allowed to create this 'dn' */
357 $this->dn = $dn;
358 $ui = get_userinfo();
359 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
361 /* We are allowed to create the requested system type */
362 if(preg_match("/c/",$tabacl)){
363 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
364 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
365 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
366 $this->systab->base = $this->DivListSystem->selectedBase;
368 /* This will be used when the object is saved, to set FAIstate to 'install'
369 and to preset maybe other attributes.
370 */
371 $this->systab->was_activated = TRUE;
373 /* Assign some default values for opsi hosts
374 */
375 if($this->systab instanceOf opsi_tabs){
376 $ldap = $this->config->get_ldap_link();
377 $ldap->cat($dn);
378 $source_attrs = $ldap->fetch();
379 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
380 if(isset($source_attrs[$src][0])){
381 $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
382 }
383 }
384 }
386 if($selected_group != "none"){
388 /*******
389 * Set gotoMode to active if there was an ogroup selected.
390 */
391 $found = false;
392 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
393 if(isset($this->systab->by_object[$tab]->gotoMode)) {
394 $found = true;
395 $this->systab->by_object[$tab]->gotoMode = $value;
396 }
397 }
398 if(!$found){
399 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
400 }
402 /*******
403 * Update object group membership
404 */
405 $og = new ogroup($this->config,$selected_group);
406 if($og){
407 $og->AddDelMembership($this->systab->dn);
408 $og->save();
409 }
411 /*******
412 * Enable inheritance
413 */
414 foreach (array("workgeneric", "termgeneric") as $cls){
415 if (isset($this->systab->by_object[$cls])){
416 $this->systab->by_object[$cls]->member_of_ogroup = true;
417 $this->systab->by_object[$cls]->set_everything_to_inherited();
418 $this->systab->by_object[$cls]->save();
419 }
420 }
422 // Enable activation
423 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
424 if (isset($this->systab->by_object[$cls])){
425 $this->systab->by_object[$cls]->auto_activate= TRUE;
426 }
427 }
428 }
430 /* Don't save directly if there is no objectGroup selected.
431 The user will then be able to configure the missing attributes
432 on his own.
433 */
434 if($selected_group != "none"){
435 $this->systab->save();
437 /* Post handling for activated new devices
438 */
439 $this->activate_new_device($this->systab->dn);
440 $this->systab = NULL;
442 if(!isset($ldap)){
443 $ldap = $this->config->get_ldap_link();
444 }
445 $ldap->cd ($this->dn);
446 $ldap->cat($this->dn, array('dn'));
447 if(count($ldap->fetch())){
448 $ldap->cd($this->dn);
449 $ldap->rmDir($this->dn);
450 }
451 }
452 }else{
453 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
454 }
455 }
456 }
457 }
458 }
461 if (isset($_POST['create_system'])||$s_action=="newsystem") {
463 $this->last_action = "";
465 /* If the current entry is an incoming object
466 * $sw = System type as posted in new incoming handling dialog
467 */
468 if(isset($_POST['system'])){
469 $sw = $_POST['system'];
470 }else{
471 $sw = $s_entry;
472 }
473 $this->dn= "new";
475 $tabs = $this->get_tab_defs();
477 if(isset($tabs[$sw])){
478 $class = $tabs[$sw]["CLASS"];
479 $tabname = $tabs[$sw]["TABNAME"];
480 $tabclass = $tabs[$sw]["TABCLASS"];
481 $acl_cat = $tabs[$sw]["ACLC"];
483 /* Load permissions for selected 'dn' and check if
484 we're allowed to remove this 'dn' */
485 $ui = get_userinfo();
486 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
487 if(preg_match("/c/",$tabacl)){
489 if(!class_available($tabclass)){
490 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
491 }else{
492 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
493 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
494 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
495 $this->systab->base = $this->DivListSystem->selectedBase;
496 }
497 }else{
498 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
499 }
500 }
501 }
503 /********************
504 System activation
505 ********************/
507 /* User wants to edit data? */
508 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
509 $this->system_activation_object = array();
510 foreach($this->list_get_selected_items() as $id) {
511 $obj = $this->terminals[$id];
512 $type= $this->get_system_type($obj);
513 if($type == "NewDevice"){
514 $this->system_activation_object[] = $obj['dn'];
515 }
516 }
517 if(count($this->system_activation_object)){
518 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
519 }
520 }
523 /********************
524 Edit system ...
525 ********************/
527 /* User wants to edit data? */
528 if (($s_action == "edit") && (!isset($this->systab->config))){
529 $this->last_action = "";
530 $this->dn= $this->terminals[$s_entry]['dn'];
532 /* Check locking, save current plugin in 'back_plugin', so
533 the dialog knows where to return. */
534 if (($user= get_lock($this->dn)) != ""){
535 return(gen_locked_message ($user, $this->dn,TRUE));
536 }
538 /* Find out more about the object type */
539 $attrs = $this->terminals[$s_entry];
540 $type= $this->get_system_type($attrs);
542 /* Lock the current entry, so everyone will get the
543 above dialog */
544 $tabs = $this->get_tab_defs();
546 if($type == "ArpNewDevice"){
547 if(!class_available("ArpNewDeviceTabs")){
548 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
549 }else{
550 add_lock ($this->dn, $this->ui->dn);
551 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
552 }
553 }elseif($type == "NewDevice"){
554 if(!class_available("SelectDeviceType")){
555 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
556 }else{
557 add_lock ($this->dn, $this->ui->dn);
558 $this->system_activation_object= array($this->dn);
559 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
561 // see condition -$s_action == "SelectedSystemType"- for further handling
562 }
563 }elseif(isset($tabs[$type])){
565 $class = $tabs[$type]["CLASS"];
566 $acl_cat = $tabs[$type]["ACLC"];
567 $tabclass = $tabs[$type]["TABCLASS"];
569 if(!class_available($tabclass)){
570 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
571 }else{
572 add_lock ($this->dn, $this->ui->dn);
573 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
574 $this->systab->set_acl_base($this->dn);
575 set_object_info($this->dn);
576 }
577 }else{
578 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
579 $this->remove_lock();
580 }
581 }
584 /********************
585 Change password ...
586 ********************/
588 /* Set terminals root password */
589 if ($s_action=="change_pw"){
590 $tabs = $this->get_tab_defs();
592 $dn = $this->terminals[$s_entry]['dn'];
593 $type = $this->get_system_type($this->terminals[$s_entry]);
595 $class = $tabs[$type]["CLASS"];
596 $acl = $tabs[$type]["ACL"];
597 $tabclass = $tabs[$type]["TABCLASS"];
598 $ui = get_userinfo();
599 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
600 if(preg_match("/w/",$tabacl)){
601 $this->dn= $this->terminals[$s_entry]['dn'];
602 set_object_info($this->dn);
603 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
604 }else{
605 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
606 }
607 }
610 /********************
611 Password change finish, but check if entered data is ok
612 ********************/
614 /* Correctly specified? */
615 if (isset($_POST['password_finish'])){
616 if ($_POST['new_password'] != $_POST['repeated_password']){
617 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
618 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
619 }
620 }
622 /********************
623 Password change finish
624 ********************/
626 /* Change terminal password */
627 if (isset($_POST['password_finish']) &&
628 $_POST['new_password'] == $_POST['repeated_password']){
630 /* Check if user is allowed to set password */
631 $tabs = $this->get_tab_defs();
633 $type = "";
634 foreach($this->terminals as $terminal){
635 if($terminal['dn'] == $this->dn){
636 $type = $this->get_system_type($terminal);
637 break;
638 }
639 }
641 /* Type detected */
642 $allow_for = array("terminal","workstation","server","component");
643 if(!empty($type) && in_array($type,$allow_for)){
645 /* Get infos */
646 $plug = $tabs[$type]["TABNAME"];
647 $acl = $tabs[$type]["ACL"];
648 $tabclass = $tabs[$type]["TABCLASS"];
650 /* Get acls */
651 $ui = get_userinfo();
652 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
654 /* Check acls */
655 if(preg_match("/w/",$tabacl)){
656 $ldap = $this->config->get_ldap_link();
657 $ldap->cd($this->dn);
658 $ldap->cat($this->dn);
659 $old_attrs = $ldap->fetch();
661 $attrs= array();
662 if ($_POST['new_password'] == ""){
664 /* Remove password attribute
665 */
666 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
667 $attrs['objectClass'] = array();
668 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
669 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
670 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
671 }
672 }
673 }
674 $attrs['userPassword']= array();
675 } else {
677 /* Add/modify password attribute
678 */
679 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
680 $attrs['objectClass'] = array();
681 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
682 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
683 }
684 $attrs['objectClass'][] = "simpleSecurityObject";
685 }
687 if(class_available("passwordMethodCrypt")){
688 $pwd_m = new passwordMethodCrypt($this->config);
689 $pwd_m->set_hash("crypt/md5");
690 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
691 }else{
692 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
693 $attrs = array();
694 }
695 }
696 $ldap->modify($attrs);
697 if (!$ldap->success()){
698 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
699 }else{
700 if(class_available($plug)){
701 $p = new $plug($this->config,$this->dn);
702 $p->handle_post_events("modify");
703 }
704 }
706 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
707 }else{
708 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
709 }
710 }else{
711 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
712 }
713 set_object_info();
714 }
717 /********************
718 Delete system cancel
719 ********************/
721 /* Delete terminal canceled? */
722 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
723 $this->remove_lock();
724 set_object_info();
725 }
728 /********************
729 Action(s) for MULTIPLE
730 ********************/
732 /********************
733 SCHEDULE action in GOsa Daemon
734 ********************/
736 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
737 $this->dns = array();
738 $ids = $this->list_get_selected_items();
740 /* Handle opsi actions */
741 if($s_action == "trigger_event_DaemonEvent_reinstall"){
742 foreach($ids as $key => $id){
743 if($this->terminals[$id]['type'] == "O"){
744 $obj = $this->terminals[$id];
745 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
746 unset($ids[$key]);
747 }
748 }
749 }
751 if(count($ids) && class_available("DaemonEvent")){
752 $mac= array();
754 /* Collect target mac addresses */
755 $ldap = $this->config->get_ldap_link();
756 foreach($ids as $id){
757 $type = $this->get_system_type($this->terminals[$id]);
758 if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
759 if(isset($this->terminals[$id]['macAddress'][0])){
760 $mac[] = $this->terminals[$id]['macAddress'][0];
761 }else{
762 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
763 $attrs= $ldap->fetch();
764 if (isset($attrs['macAddress'][0])){
765 $mac[]= $attrs['macAddress'][0];
766 }
767 }
768 }
769 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
770 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
771 $o_queue = new gosaSupportDaemon();
773 /* Skip installation or update trigerred events,
774 * if this entry is currently processing.
775 */
776 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
777 foreach($mac as $key => $mac_address){
778 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
780 $entry['STATUS'] = strtoupper($entry['STATUS']);
781 if($entry['STATUS'] == "PROCESSING" &&
782 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
783 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
784 unset($mac[$key]);
786 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
787 break;
788 }
789 }
790 }
791 }
793 /* Prepare event to be added
794 */
795 if(count($mac) && isset($events['BY_CLASS'][$type])){
796 $event = $events['BY_CLASS'][$type];
797 $this->systab = new $event['CLASS_NAME']($this->config);
798 $this->systab->add_targets($mac);
799 if(preg_match("/trigger_event/",$s_action)){
800 $this->systab->set_type(TRIGGERED_EVENT);
801 }else{
802 $this->systab->set_type(SCHEDULED_EVENT);
803 }
804 }
805 }
806 }
808 /* Insert scheduled events into queue */
809 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
810 $this->systab->save_object();
812 /* Save event
813 */
814 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
815 $o_queue = new gosaSupportDaemon();
816 $o_queue->append($this->systab);
817 if($o_queue->is_error()){
818 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
819 }else{
820 $this->systab = FALSE;
821 }
822 }
823 if(isset($_POST['abort_event_dialog'])){
824 $this->systab = FALSE;
825 }
826 }
829 /********************
830 Delete MULTIPLE entries requested, display confirm dialog
831 ********************/
833 if ($s_action=="del_multiple" || $s_action == "del"){
834 $this->dns = array();
836 if($s_action == "del_multiple"){
837 $ids = $this->list_get_selected_items();
838 }else{
839 $ids = array($s_entry);
840 }
842 $ui = get_userinfo();
843 $tabs = $this->get_tab_defs();
845 if(count($ids)){
847 $disallowed = array();
848 foreach($ids as $id){
850 /* Get 'dn' from posted termlinst */
851 $attrs = $this->terminals[$id];
852 $type = $this->get_system_type($attrs);
853 $dn = $attrs['dn'];
854 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
855 if(preg_match("/d/",$acl)){
856 $this->dns[$id] = $dn;
857 }else{
858 $disallowed[] = $dn;
859 }
860 }
862 if(count($disallowed)){
863 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
864 }
866 if(count($this->dns)){
868 if ($user= get_multiple_locks($this->dns)){
869 return(gen_locked_message($user,$this->dns));
870 }
872 $dns_names = array();
873 foreach($this->dns as $dn){
874 add_lock ($dn, $this->ui->dn);
875 $dns_names[] = LDAP::fix($dn);
876 }
878 /* Lock the current entry, so nobody will edit it during deletion */
879 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
880 $smarty->assign("multiple", true);
881 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
882 }
883 }
884 }
887 /********************
888 Delete MULTIPLE entries confirmed
889 ********************/
891 /* Confirmation for deletion has been passed. Users should be deleted. */
892 if (isset($_POST['delete_multiple_system_confirm'])){
894 $ui = get_userinfo();
895 $tabs = $this->get_tab_defs();
897 /* Remove user by user and check acls before removeing them */
898 foreach($this->dns as $key => $dn){
900 /* Get 'dn' from posted termlinst */
901 $attrs = $this->terminals[$key];
902 $type= $this->get_system_type($attrs);
904 /* get object type */
905 $tabtype = "termtabs";
906 $tabobj = "TERMTABS";
907 $tabacl = "";
908 if(isset($tabs[$type])){
909 $tabtype = $tabs[$type]['TABCLASS'];
910 $tabobj = $tabs[$type]['CLASS'];
911 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
913 /* Load permissions for selected 'dn' and check if
914 we're allowed to remove this 'dn' */
915 if(preg_match("/d/",$tabacl)){
917 /* Delete request is permitted, perform LDAP action */
918 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
919 $this->systab= new termgeneric($this->config, $dn);
920 $this->systab->set_acl_base($dn);
921 $this->systab->set_acl_category("terminal");
922 $this->systab->remove_from_parent();
923 }elseif($tabtype=="phonetabs"){
924 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
925 $this->systab->set_acl_base($dn);
926 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
927 }else{
928 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
929 $this->systab->set_acl_base($dn);
930 $this->systab->delete();
931 }
932 unset ($this->systab);
933 $this->systab= NULL;
935 } else {
936 /* Normally this shouldn't be reached, send some extra
937 logs to notify the administrator */
938 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
939 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
940 }
941 }
943 /* Remove lock file after successfull deletion */
944 $this->remove_lock();
945 $this->dns = array();
946 }
947 }
949 /********************
950 Delete MULTIPLE entries Canceled
951 ********************/
953 /* Remove lock */
954 if(isset($_POST['delete_multiple_system_cancel'])){
956 /* Remove lock file after successfull deletion */
957 $this->remove_lock();
958 $this->dns = array();
959 }
962 /********************
963 Edit system type finished, check if everything went ok
964 ********************/
965 /* Finish user edit is triggered by the tabulator dialog, so
966 the user wants to save edited data. Check and save at this
967 point. */
969 /* Dirty workaround - MSG_DIALOG - OK
970 If a message dialog is shown and we press 'OK'
971 then try to save again.
972 */
973 foreach($_POST as $name => $value){
974 if(preg_match("/^MSG_OK/",$name)){
975 $_POST[$this->last_action] = TRUE;
976 }
977 }
979 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
981 /* If the save routine gets interrupted by a confirm dialog,
982 store last action so we can trigger it again after 'Ok' was pressed.
983 (This is the case if a system gets modified while it is installing - GOsa si)
984 */
985 $this->last_action = "";
986 if(isset($_POST['edit_finish'])){
987 $this->last_action = "edit_finish";
988 }elseif(isset($_POST['edit_apply'])){
989 $this->last_action = "edit_apply";
990 }
992 /* Check tabs, will feed message array */
993 $message = $this->systab->check();
995 /* Save, or display error message? */
996 if (count($message) == 0){
997 $this->systab->save();
999 /* Post handling for activated systems
1000 target opsi -> Remove source.
1001 target gosa -> Activate system.
1002 */
1003 if($this->systab instanceOf opsi_tabs && $this->systab->was_activated){
1004 $ldap = $this->config->get_ldap_link();
1005 $ldap->cd($this->config->current['BASE']);
1006 $ldap->rmdir ($this->systab->dn);
1007 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
1009 $hostId = $this->systab->by_object['opsiGeneric']->hostId;
1010 $mac = $this->systab->by_object['opsiGeneric']->mac;
1011 $this->opsi->job_opsi_activate_client($hostId,$mac);
1013 }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1014 $this->activate_new_device($this->systab->dn);
1015 }
1017 /* Terminal has been saved successfully, remove lock from LDAP. */
1018 if (!isset($_POST['edit_apply'])){
1019 if ($this->dn != "new"){
1020 $this->remove_lock();
1021 }
1023 unset ($this->systab);
1024 $this->systab= NULL;
1025 set_object_info();
1026 }else{
1028 /* Reinitialize tab */
1029 if($this->systab instanceof tabs){
1030 $this->systab->re_init();
1031 }
1032 }
1033 } else {
1034 /* Ok. There seem to be errors regarding to the tab data,
1035 show message and continue as usual. */
1036 msg_dialog::displayChecks($message);
1037 }
1038 }
1041 /********************
1042 Edit system was canceled
1043 ********************/
1044 /* Cancel dialogs */
1045 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1046 if (isset($this->systab)){
1047 $this->remove_lock();
1048 unset ($this->systab);
1049 }
1050 $this->systab= NULL;
1051 set_object_info();
1052 }
1054 /********************
1055 Display edit dialog, or some other
1056 ********************/
1058 /* Show tab dialog if object is present */
1059 if (isset($this->systab->config)){
1061 if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1062 $this->systab->save_object();
1063 }
1065 $display= $this->systab->execute();
1067 /* Don't show buttons if tab dialog requests this */
1069 $dialog = FALSE;
1070 $hide_apply = $this->dn == "new";
1071 $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1072 if(is_object($this->systab) && !isset($this->systab->by_object)){
1073 $dialog = TRUE;
1074 $hide_apply = TRUE;
1075 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1076 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1077 if($dia === TRUE || is_object($dia)){
1078 $dialog = TRUE;
1079 }
1080 }
1081 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1082 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1083 $dialog = TRUE;
1084 }
1086 if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1087 $display.= "<p style=\"text-align:right\">
1088 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1089 </p>";
1090 }elseif (!$dialog){
1091 $display.= "<p style=\"text-align:right\">\n";
1092 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1093 $display.= " \n";
1094 if (!$hide_apply){
1095 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1096 $display.= " \n";
1097 }
1098 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1099 $display.= "</p>";
1100 }
1101 return ($display);
1102 }
1104 /* Check if there is a snapshot dialog open */
1105 $base = $this->DivListSystem->selectedBase;
1106 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1107 return($str);
1108 }
1110 /* Display dialog with system list */
1111 $this->DivListSystem->parent = $this;
1112 $this->DivListSystem->execute();
1114 /* Add departments if subsearch is disabled */
1115 if(!$this->DivListSystem->SubSearch){
1117 /* Add FAIstate to attributes if FAI is activated */
1118 if($this->fai_activated){
1119 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1120 }else{
1121 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1122 }
1123 }
1124 $this->reload();
1125 $this->DivListSystem->setEntries($this->terminals);
1126 return($this->DivListSystem->Draw());
1127 }
1130 /* Return departments, that will be included within snapshot detection */
1131 function get_used_snapshot_bases()
1132 {
1133 $tmp = array();
1135 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1137 $tabs = array(
1138 "terminal" => get_ou('terminalRDN'),
1139 "workstation" => get_ou('workstationRDN'),
1140 "incoming" => get_ou('systemIncomingRDN'),
1141 "server" => get_ou('serverRDN'),
1142 "printer" => get_ou('printerRDN'),
1143 "phone" => get_ou('phoneRDN'),
1144 "winworkstation" => get_winstations_ou(),
1145 "component" => get_ou('componentRDN')
1146 );
1148 foreach($tabs as $acl_cat => $dn){
1150 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1151 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1152 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1153 }
1154 }
1155 return($tmp);
1156 }
1159 function remove_from_parent()
1160 {
1161 /* Optionally execute a command after we're done */
1162 $this->postremove();
1163 }
1166 /* Save data to object */
1167 function save_object()
1168 {
1169 $this->DivListSystem->save_object();
1170 if(is_object($this->CopyPasteHandler)){
1171 $this->CopyPasteHandler->save_object();
1172 }
1173 }
1176 /* Check values */
1177 function check()
1178 {
1179 }
1182 /* Save to LDAP */
1183 function save()
1184 {
1185 }
1187 function adapt_from_template($dn, $skip= array())
1188 {
1189 }
1191 function password_change_needed()
1192 {
1193 }
1195 function reload()
1196 {
1197 /* some var init */
1198 $ui = get_userinfo();
1199 $res = array();
1200 $this->terminals = array();
1201 $userregex = "";
1202 $opsi_clients = array();
1204 /* Set base for all searches */
1205 $base= $this->DivListSystem->selectedBase;
1207 /* Prepare samba class name */
1208 $samba ="";
1209 if ($this->DivListSystem->ShowWinWorkstations){
1210 if ($this->config->get_cfg_value("sambaversion") == "3"){
1211 $samba= "sambaSamAccount";
1212 } else {
1213 $samba= "sambaAccount";
1214 }
1215 }
1217 /* This array represents the combination between checkboxes and search filters */
1218 $objs = array(
1219 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1220 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1221 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1222 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1223 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1224 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1225 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1227 /* Include the 'Display Systems of user' attribute */
1228 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1229 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1230 }
1232 /* Attributes to fetch */
1233 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1234 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1236 /* Add FAIstate to attributes if FAI is activated */
1237 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1238 if(!empty($tmp)){
1239 $sys_attrs[] = "FAIstate";
1240 }
1242 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1243 foreach($objs as $checkBox => $oc){
1245 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1246 if($this->DivListSystem->SubSearch){
1247 if($oc['CLASS'] != ""){
1248 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1249 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1250 $res = array_merge($res,$new_res);
1251 }
1252 }else{
1253 /* User filter? */
1254 if($oc['CLASS'] != ""){
1255 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1256 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1257 }
1258 }
1259 }
1260 }
1262 /* Search for incoming objects */
1263 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1264 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1266 /* Append opsi systems, the opsi extension have to installed.
1267 (Only, if we are allowed to view opsi hosts)
1268 */
1269 if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1270 $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1271 if(preg_match("/r/",$o_acl)){
1272 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1273 if($this->opsi->is_error()){
1274 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1275 }
1276 }
1277 }
1279 /* Get all gotoTerminal's */
1280 $t_id = 0;
1281 $opsi_map = array();
1282 foreach ($res as $value){
1284 $tmp= $value['dn'];
1285 $add= "";
1287 /* Extract base */
1288 foreach($objs as $obj){
1289 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1290 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1291 }
1292 }
1294 /* Create a string containing the last part of the department. */
1295 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1296 if(empty($dn_name)){
1297 $dn_name = "/";
1298 }
1300 /* check if current object is a new one */
1301 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1302 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1303 $add= "- "._("New terminal");
1304 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1305 $add= "- "._("New workstation");
1306 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1307 $add= "- "._("Unknown device");
1308 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1309 $add= "- "._("New Device");
1310 }
1311 }
1313 /* Detect type of object and create an entry for $this->terminals */
1314 $terminal = array();
1316 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1318 /* check acl */
1319 $terminal = $value;
1320 $terminal['type'] = "O";
1322 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1324 /* check acl */
1325 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1326 if($add != "" || preg_match("/r/",$acl)) {
1327 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1328 $terminal = $value;
1329 $terminal['type'] = "T";
1330 $terminal['is_new'] = $add;
1331 } else {
1332 $terminal = $value;
1333 $terminal['type'] = "D";
1334 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1335 $terminal['location'] = array_search($tmp, $this->config->departments);
1336 }
1337 }
1338 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1340 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1341 if($add != "" || preg_match("/r/",$acl)) {
1342 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1343 $terminal = $value;
1344 $terminal['type'] = "L";
1345 $terminal['is_new'] = $add;
1346 } else {
1347 $terminal = $value;
1348 $terminal['type'] = "D";
1349 $terminal['location'] = array_search($tmp, $this->config->departments);
1350 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1351 }
1352 # if (isset($value["FAIstate"][0])){
1353 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1354 # }
1355 }
1356 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1359 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1360 if($add != "" || preg_match("/r/",$acl)) {
1362 $terminal = $value;
1363 $terminal['type'] = "P";
1364 }
1365 } elseif (in_array_ics('goServer', $value["objectClass"])){
1367 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1368 if($add != "" || preg_match("/r/",$acl)) {
1370 $terminal = $value;
1371 $terminal['type'] = "S";
1372 # if (isset($value["FAIstate"][0])){
1373 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1374 # }
1375 }
1376 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1378 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1379 if($add != "" || preg_match("/r/",$acl)) {
1381 $terminal = $value;
1382 $terminal['type'] = "F";
1383 }
1384 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1386 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1387 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1388 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1389 if($add != "" || preg_match("/r/",$acl)) {
1391 $terminal = $value;
1392 $terminal['type'] = "Q";
1393 $terminal['is_new'] = $add;
1394 }
1395 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1396 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1397 $type= "winstation";
1398 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1399 if($add != "" || preg_match("/r/",$acl)) {
1401 $terminal = $value;
1402 $terminal['type'] = "C";
1403 }
1404 } else{
1406 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1407 if (isset($value['sambaDomainName'])){
1408 $domain= " [".$value['sambaDomainName'][0]."]";
1409 } else {
1410 $domain= "";
1411 }
1412 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1413 if($add != "" || preg_match("/r/",$acl)) {
1414 $terminal=$value;
1415 $terminal['type'] ="W";
1416 $terminal['domain'] = $name.$domain;
1417 }
1418 }
1420 /* Append collected data to the host list.
1421 */
1422 if(count($terminal)){
1423 $t_id ++ ;
1424 $this->terminals[$t_id]=$terminal;
1425 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1426 }
1427 }
1430 /* Merge real hosts with opsi hosts.
1431 If there is a samba host, then merge it with the opsi host,
1432 to avoid duplicate entries.
1433 */
1434 foreach($opsi_clients as $entry){
1435 if(isset($opsi_map[$entry['cn'][0]])){
1436 continue;
1437 }
1438 $terminal = $entry;
1439 $terminal['type'] = "O";
1440 $this->terminals[] = $terminal;
1441 }
1443 $tmp =array();
1444 $tmp2 =array();
1445 foreach($this->terminals as $tkey => $val ){
1446 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1447 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1448 }
1449 natcasesort($tmp2);
1450 $this->terminals=array();
1451 foreach($tmp2 as $val){
1452 $this->terminals[]=$tmp[$val];
1453 }
1454 reset ($this->terminals);
1455 }
1457 function remove_lock()
1458 {
1459 if (isset($this->systab->dn)){
1460 del_lock ($this->systab->dn);
1461 }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1462 del_lock($this->dn);
1463 }
1464 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1465 del_lock($this->dns);
1466 }
1467 }
1470 function copyPasteHandling_from_queue($s_action,$s_entry)
1471 {
1472 /* Check if Copy & Paste is disabled */
1473 if(!is_object($this->CopyPasteHandler)){
1474 return("");
1475 }
1477 $ui = get_userinfo();
1479 $tabs = $this->get_tab_defs();
1481 /* Add a single entry to queue */
1482 if($s_action == "cut" || $s_action == "copy"){
1484 /* Cleanup object queue */
1485 $this->CopyPasteHandler->cleanup_queue();
1486 $dn = $this->terminals[$s_entry]['dn'];
1487 $oc = $this->terminals[$s_entry]['objectClass'];
1488 $type = $this->get_system_type($this->terminals[$s_entry]);
1490 $tab_o = $tabs[$type]['CLASS'];
1491 $tab_c = $tabs[$type]['TABCLASS'];
1492 $acl_c = $tabs[$type]['TABNAME'];
1493 $acl = $tabs[$type]['ACLC'];
1495 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1496 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1497 }
1498 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1499 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1500 }
1501 }
1503 /* Add entries to queue */
1504 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1506 /* Cleanup object queue */
1507 $this->CopyPasteHandler->cleanup_queue();
1509 /* Add new entries to CP queue */
1510 foreach($this->list_get_selected_items() as $id){
1511 $dn = $this->terminals[$id]['dn'];
1512 $oc = $this->terminals[$id]['objectClass'];
1513 $type = $this->get_system_type($this->terminals[$id]);
1515 if(isset($tabs[$type])){
1516 $tab_o = $tabs[$type]['CLASS'];
1517 $tab_c = $tabs[$type]['TABCLASS'];
1518 $acl_c = $tabs[$type]['TABNAME'];
1519 $acl = $tabs[$type]['ACLC'];
1521 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1522 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1523 }
1524 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1525 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1526 }
1527 }
1528 }
1529 }
1531 /* Start pasting entries */
1532 if($s_action == "editPaste"){
1533 $this->start_pasting_copied_objects = TRUE;
1534 }
1536 /* Return C&P dialog */
1537 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1539 /* Get dialog */
1540 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1541 $data = $this->CopyPasteHandler->execute();
1543 /* Return dialog data */
1544 if(!empty($data)){
1545 return($data);
1546 }
1547 }
1549 /* Automatically disable status for pasting */
1550 if(!$this->CopyPasteHandler->entries_queued()){
1551 $this->start_pasting_copied_objects = FALSE;
1552 }
1553 return("");
1554 }
1557 function get_system_type($attrs)
1558 {
1559 $classes = $attrs['objectClass'];
1561 $type= "";
1562 if (in_array_ics('gosa_opsi_client', $classes)){
1563 $type= "opsi_client";
1564 }elseif (in_array_ics('sambaAccount', $classes) ||
1565 in_array_ics('sambaSamAccount', $classes)){
1566 $type= "winstation";
1567 }elseif (in_array_ics('ieee802Device', $classes)){
1568 $type= "component";
1569 }elseif (in_array_ics('gotoTerminal', $classes)){
1570 $type= "terminal";
1571 }elseif (in_array_ics('gotoWorkstation', $classes)){
1572 $type= "workstation";
1573 }elseif (in_array_ics('gotoPrinter', $classes)){
1574 $type= "printer";
1575 }elseif (in_array_ics('goFonHardware', $classes)){
1576 $type= "phone";
1577 }elseif (in_array_ics('goServer', $classes)){
1578 $type= "server";
1579 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1580 $type= "ArpNewDevice";
1581 }elseif (in_array_ics('GOhard', $classes)){
1582 $type= "NewDevice";
1583 }
1584 return ($type);
1585 }
1588 function convert_list($input)
1589 {
1590 $temp= "";
1592 $conv= array(
1593 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1594 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1595 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1596 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1598 "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1600 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1601 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1602 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1604 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1605 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1606 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1608 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1609 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1610 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1612 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1613 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1615 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1616 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1617 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1619 /* Add opsi client to system types */
1620 if($this->opsi != NULL){
1621 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1622 }
1624 /* Use locked icons
1625 */
1626 if( in_array($input['type'],array("S","T","L")) &&
1627 isset($input['gotoMode'][0]) &&
1628 preg_match("/locked/",$input['gotoMode'][0])){
1629 $input['type'].="X";
1630 } elseif(in_array($input['type'],array("S","L")) &&
1631 isset($input['FAIstate'][0])){
1633 /* Add FAI state icons
1634 */
1635 $type= "";
1636 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1637 case 'error':
1638 $type= 'E';
1639 break;
1640 case 'installing':
1641 case 'install':
1642 case 'sysinfo':
1643 case 'softupdate':
1644 case 'scheduledupdate':
1645 $type= 'B';
1646 break;
1647 }
1649 $input['type'].= $type;
1650 }
1652 /* Use new images if object is from incoming
1653 */
1654 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1655 $input['type']="N".$input['type'];
1656 }
1658 /* Check which flags this objects uses
1659 */
1660 foreach ($conv as $key => $value){
1661 $found = TRUE;
1662 if(strlen($key) != strlen($input['type'])) {
1663 $found = FALSE;
1664 }
1665 for($i = 0 ; $i < strlen($key) ; $i++){
1666 if(!preg_match("/".$key[$i]."/",$input['type'])){
1667 $found = FALSE;
1668 }
1669 }
1671 if($found){
1672 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1673 $tmp['class']=$key;
1674 return $tmp;
1675 }
1676 }
1677 }
1680 function list_get_selected_items()
1681 {
1682 $ids = array();
1683 foreach($_POST as $name => $value){
1684 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1685 $id = preg_replace("/^item_selected_/","",$name);
1686 $ids[$id] = $id;
1687 }
1688 }
1689 return($ids);
1690 }
1693 public function get_tab_defs()
1694 {
1695 $tabs = array(
1696 "incoming" => array(
1697 "CLASS" => "",
1698 "TABNAME" => "",
1699 "TABCLASS" => "",
1700 "ACLC" => "incoming",
1701 "ACL" => "incoming/systems"),
1703 "ArpNewDevice"=> array(
1704 "CLASS" => "TERMTABS",
1705 "TABNAME" => "termgeneric" ,
1706 "TABCLASS" => "termtabs",
1707 "ACLC" => "incoming",
1708 "ACL" => "incoming/systems"),
1710 "NewDevice" => array(
1711 "CLASS" => "TERMTABS",
1712 "TABNAME" => "termgeneric",
1713 "TABCLASS" => "termtabs",
1714 "ACLC" => "incoming",
1715 "ACL" => "incoming/systems"),
1717 "terminal" => array(
1718 "CLASS" => "TERMTABS",
1719 "TABNAME" => "termgeneric",
1720 "TABCLASS" => "termtabs",
1721 "ACLC" => "terminal",
1722 "ACL" => "terminal/termgeneric"),
1724 "workstation" => array(
1725 "CLASS" => "WORKTABS",
1726 "TABNAME" => "workgeneric",
1727 "TABCLASS"=> "worktabs",
1728 "ACLC" => "workstation",
1729 "ACL" => "workstation/workgeneric" ),
1731 "server" => array(
1732 "CLASS" => "SERVTABS",
1733 "TABNAME" => "servgeneric",
1734 "TABCLASS"=> "servtabs",
1735 "ACLC" => "server",
1736 "ACL" => "server/servgeneric"),
1738 "printer" => array(
1739 "CLASS" => "PRINTTABS",
1740 "TABNAME" => "printgeneric",
1741 "TABCLASS"=> "printtabs",
1742 "ACLC" => "printer",
1743 "ACL" => "printer/printgeneric"),
1745 "phone" => array(
1746 "CLASS" => "PHONETABS",
1747 "TABNAME" => "phoneGeneric",
1748 "TABCLASS"=> "phonetabs",
1749 "ACLC" => "phone",
1750 "ACL" => "phone/phoneGeneric"),
1752 "winstation" => array(
1753 "CLASS" => "WINTABS",
1754 "TABNAME" => "wingeneric",
1755 "TABCLASS"=> "wintabs",
1756 "ACLC" => "winworkstation",
1757 "ACL" => "winworkstation/wingeneric"),
1759 "component" => array(
1760 "CLASS" => "COMPONENTTABS",
1761 "TABNAME" => "componentGeneric",
1762 "TABCLASS"=> "componenttabs",
1763 "ACLC" => "component",
1764 "ACL" => "component/componentGeneric"));
1766 if($this->opsi != NULL){
1767 $tabs["opsi_client"] = array(
1768 "CLASS" => "OPSITABS",
1769 "TABNAME" => "opsiGeneric" ,
1770 "TABCLASS"=> "opsi_tabs",
1771 "ACLC" => "opsi" ,
1772 "ACL" => "opsi/opsiGeneric");
1773 }
1775 return($tabs);
1776 }
1779 /*! \brief Sets FAIstate to "install" for "New Devices".
1780 This function is some kind of "Post handler" for activated systems,
1781 it is called directly after the object (workstabs,servtabs) gets saved.
1782 @param String $dn The dn of the newly activated object.
1783 @return Boolean TRUE if activated else FALSE
1784 */
1785 function activate_new_device($dn)
1786 {
1787 $ldap = $this->config->get_ldap_link();
1788 $ldap->cd($this->config->current['BASE']);
1789 $ldap->cat($dn);
1790 if($ldap->count()){
1791 $attrs = $ldap->fetch();
1792 $type = $this->get_system_type($attrs);
1793 if(!in_array($type,array("workstation","server"))) {
1794 $ocs = $attrs['objectClass'];
1795 unset($ocs['count']);
1796 $new_attrs = array();
1797 if(!in_array("FAIobject",$ocs)){
1798 $ocs[] = "FAIobject";
1799 $new_attrs['objectClass'] = $ocs;
1800 }
1801 $new_attrs['FAIstate'] = "install";
1802 $ldap->cd($dn);
1803 $ldap->modify($new_attrs);
1804 if (!$ldap->success()){
1805 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1806 LDAP_MOD, "activate_new_device($dn)"));
1807 }else{
1808 return(TRUE);
1809 }
1810 }
1811 }
1812 return(FALSE);
1813 }
1816 /* !! Incoming dummy acls, required to defined acls for incoming objects
1817 */
1818 static function plInfo()
1819 {
1820 return (array(
1821 "plShortName" => _("Incoming objects"),
1822 "plDescription" => _("Incoming objects"),
1823 "plSelfModify" => FALSE,
1824 "plDepends" => array(),
1825 "plPriority" => 99,
1826 "plSection" => array("administration"),
1827 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1828 "objectClass" => "")),
1829 "plProvidedAcls"=> array()
1831 ));
1832 }
1833 }
1835 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1836 ?>