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