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