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 session::set('objectinfo',$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 hanlding (Ogroup/System select dialog.)
309 ********************/
311 if($s_action == "SelectedSystemType"){
313 /* Possible destination system types
314 */
315 $tabs = $this->get_tab_defs();
317 /* Remember dialog selection.
318 */
319 $selected_group = $_POST['ObjectGroup'];
320 $selected_system = $_POST['SystemType'];
322 $this->systab = NULL;
324 /* Check if system type exists. It should! */
325 if(isset($tabs[$selected_system])){
327 /* Get tab informations */
328 $class = $tabs[$selected_system]["CLASS"];
329 $tabname = $tabs[$selected_system]["TABNAME"];
330 $tabclass = $tabs[$selected_system]["TABCLASS"];
331 $acl_cat = $tabs[$selected_system]["ACLC"];
334 if(!class_available($tabclass)){
335 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
336 }else{
338 /* Go through all objects that should be activated */
339 foreach($this->system_activation_object as $key => $dn){
341 /* Remove entry from list, to avoid page-reload problems */
342 unset($this->system_activation_object[$key]);
344 /* Load permissions for selected 'dn' and check if
345 we're allowed to create this 'dn' */
346 $this->dn = $dn;
347 $ui = get_userinfo();
348 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
350 /* We are allowed to create the requested system type */
351 if(preg_match("/c/",$tabacl)){
352 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
353 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
354 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
355 $this->systab->base = $this->DivListSystem->selectedBase;
358 if($selected_group != "none"){
360 /*******
361 * Set gotoMode to active if we there was an ogroup selected.
362 */
363 $found = false;
364 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
365 if(isset($this->systab->by_object[$tab]->gotoMode)) {
366 $found = true;
367 $this->systab->by_object[$tab]->gotoMode = $value;
368 }
369 }
370 if(!$found){
371 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
372 }
374 /*******
375 * Update object group membership
376 */
377 $og = new ogroup($this->config,$selected_group);
378 if($og){
379 $og->AddDelMembership($this->systab->dn);
380 $og->save();
381 }
383 /*******
384 * Set default system specific attributes
385 */
386 foreach (array("workservice", "termservice") as $cls){
387 if (isset($this->systab->by_object[$cls])){
388 $this->systab->by_object[$cls]->gotoXMouseport= "";
389 $this->systab->by_object[$cls]->gotoXMouseType= "";
390 $this->systab->by_object[$cls]->gotoXResolution= "";
391 $this->systab->by_object[$cls]->gotoXColordepth= "";
392 }
393 }
395 // Enable activation
396 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
397 if (isset($this->systab->by_object[$cls])){
398 $this->systab->by_object[$cls]->auto_activate= TRUE;
399 }
400 }
402 // Enable sending of LDAP events
403 if (isset($this->systab->by_object["workstartup"])){
404 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
405 }
406 }
408 /* Don't save directly if there is no objectGroup selected.
409 The user will then be able to configure the missing attributes
410 on his own.
411 */
412 if($selected_group != "none"){
413 $this->systab->save();
414 $this->systab = NULL;
416 if(!isset($ldap)){
417 $ldap = $this->config->get_ldap_link();
418 }
419 $ldap->cd ($this->dn);
420 $ldap->cat($this->dn, array('dn'));
421 if(count($ldap->fetch())){
422 $ldap->cd($this->dn);
423 $ldap->rmDir($this->dn);
424 }
425 }
426 }else{
427 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
428 }
429 }
430 }
431 }
432 }
435 if (isset($_POST['create_system'])||$s_action=="newsystem") {
437 $this->last_action = "";
439 /* If the current entry is an incoming object
440 * $sw = System type as posted in new incoming handling dialog
441 */
442 if(isset($_POST['system'])){
443 $sw = $_POST['system'];
444 }else{
445 $sw = $s_entry;
446 }
447 $this->dn= "new";
449 $tabs = $this->get_tab_defs();
451 if(isset($tabs[$sw])){
452 $class = $tabs[$sw]["CLASS"];
453 $tabname = $tabs[$sw]["TABNAME"];
454 $tabclass = $tabs[$sw]["TABCLASS"];
455 $acl_cat = $tabs[$sw]["ACLC"];
457 /* Load permissions for selected 'dn' and check if
458 we're allowed to remove this 'dn' */
459 $ui = get_userinfo();
460 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
461 if(preg_match("/c/",$tabacl)){
463 if(!class_available($tabclass)){
464 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
465 }else{
466 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
467 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
468 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
469 $this->systab->base = $this->DivListSystem->selectedBase;
470 }
471 }else{
472 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
473 }
474 }
475 }
477 /********************
478 System activation
479 ********************/
481 /* User wants to edit data? */
482 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
483 $this->system_activation_object = array();
484 foreach($this->list_get_selected_items() as $id) {
485 $obj = $this->terminals[$id];
486 $type= $this->get_system_type($obj);
487 if($type == "NewDevice"){
488 $this->system_activation_object[] = $obj['dn'];
489 }
490 }
491 if(count($this->system_activation_object)){
492 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
493 }
494 }
497 /********************
498 Edit system ...
499 ********************/
501 /* User wants to edit data? */
502 if (($s_action == "edit") && (!isset($this->systab->config))){
503 $this->last_action = "";
504 $this->dn= $this->terminals[$s_entry]['dn'];
506 /* Check locking, save current plugin in 'back_plugin', so
507 the dialog knows where to return. */
508 if (($user= get_lock($this->dn)) != ""){
509 return(gen_locked_message ($user, $this->dn));
510 }
512 /* Find out more about the object type */
513 $attrs = $this->terminals[$s_entry];
514 $type= $this->get_system_type($attrs);
516 /* Lock the current entry, so everyone will get the
517 above dialog */
518 $tabs = $this->get_tab_defs();
520 if($type == "ArpNewDevice"){
521 if(!class_available("ArpNewDeviceTabs")){
522 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
523 }else{
524 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
525 }
526 }elseif($type == "NewDevice"){
527 if(!class_available("SelectDeviceType")){
528 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
529 }else{
530 $this->system_activation_object= array($this->dn);
531 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
532 }
533 }elseif(isset($tabs[$type])){
535 $class = $tabs[$type]["CLASS"];
536 $acl_cat = $tabs[$type]["ACLC"];
537 $tabclass = $tabs[$type]["TABCLASS"];
539 if(!class_available($tabclass)){
540 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
541 }else{
542 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
543 $this->systab->set_acl_base($this->dn);
544 session::set('objectinfo',$this->dn);
545 add_lock ($this->dn, $this->ui->dn);
546 }
547 }else{
548 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
549 $this->remove_lock();
550 }
551 }
554 /********************
555 Change password ...
556 ********************/
558 /* Set terminals root password */
559 if ($s_action=="change_pw"){
560 $tabs = $this->get_tab_defs();
562 $dn = $this->terminals[$s_entry]['dn'];
563 $type = $this->get_system_type($this->terminals[$s_entry]);
565 $class = $tabs[$type]["CLASS"];
566 $acl = $tabs[$type]["ACL"];
567 $tabclass = $tabs[$type]["TABCLASS"];
568 $ui = get_userinfo();
569 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
570 if(preg_match("/w/",$tabacl)){
571 $this->dn= $this->terminals[$s_entry]['dn'];
572 session::set('objectinfo',$this->dn);
573 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
574 }else{
575 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
576 }
577 }
580 /********************
581 Password change finish, but check if entered data is ok
582 ********************/
584 /* Correctly specified? */
585 if (isset($_POST['password_finish'])){
586 if ($_POST['new_password'] != $_POST['repeated_password']){
587 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
588 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
589 }
590 }
592 /********************
593 Password change finish
594 ********************/
596 /* Change terminal password */
597 if (isset($_POST['password_finish']) &&
598 $_POST['new_password'] == $_POST['repeated_password']){
600 /* Check if user is allowed to set password */
601 $tabs = $this->get_tab_defs();
603 $type = "";
604 foreach($this->terminals as $terminal){
605 if($terminal['dn'] == $this->dn){
606 $type = $this->get_system_type($terminal);
607 break;
608 }
609 }
611 /* Type detected */
612 $allow_for = array("terminal","workstation","server","component");
613 if(!empty($type) && in_array($type,$allow_for)){
615 /* Get infos */
616 $plug = $tabs[$type]["PLUG"];
617 $class = $tabs[$type]["CLASS"];
618 $acl = $tabs[$type]["ACL"];
619 $tabclass = $tabs[$type]["TABCLASS"];
621 /* Get acls */
622 $ui = get_userinfo();
623 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
625 /* Check acls */
626 if(preg_match("/w/",$tabacl)){
627 $ldap = $this->config->get_ldap_link();
628 $ldap->cd($this->dn);
629 $ldap->cat($this->dn);
630 $old_attrs = $ldap->fetch();
632 $attrs= array();
633 if ($_POST['new_password'] == ""){
635 /* Remove password attribute
636 */
637 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
638 $attrs['objectClass'] = array();
639 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
640 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
641 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
642 }
643 }
644 }
645 $attrs['userPassword']= array();
646 } else {
648 /* Add/modify password attribute
649 */
650 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
651 $attrs['objectClass'] = array();
652 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
653 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
654 }
655 $attrs['objectClass'][] = "simpleSecurityObject";
656 }
658 if(class_available("passwordMethodCrypt")){
659 $pwd_m = new passwordMethodCrypt($this->config);
660 $pwd_m->set_hash("crypt/md5");
661 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
662 }else{
663 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
664 $attrs = array();
665 }
666 }
667 $ldap->modify($attrs);
668 if (!$ldap->success()){
669 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
670 }else{
671 if(class_available($plug)){
672 $p = new $plug($this->config,$this->dn);
673 $p->handle_post_events("modify");
674 }
675 }
677 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
678 }else{
679 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
680 }
681 }else{
682 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
683 }
684 session::un_set('objectinfo');
685 }
688 /********************
689 Delete system cancel
690 ********************/
692 /* Delete terminal canceled? */
693 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
694 $this->remove_lock();
695 session::un_set('objectinfo');
696 }
699 /********************
700 Action(s) for MULTIPLE
701 ********************/
703 /********************
704 SCHEDULE action in GOsa Daemon
705 ********************/
707 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
708 $this->dns = array();
709 $ids = $this->list_get_selected_items();
711 /* Handle opsi actions */
712 if($s_action == "trigger_event_DaemonEvent_reinstall"){
713 foreach($ids as $key => $id){
714 if($this->terminals[$id]['type'] == "O"){
715 $obj = $this->terminals[$id];
716 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
717 unset($ids[$key]);
718 }
719 }
720 }
722 if(count($ids) && class_available("DaemonEvent")){
723 $mac= array();
725 /* Collect target mac addresses */
726 $ldap = $this->config->get_ldap_link();
727 foreach($ids as $id){
728 $type = $this->get_system_type($this->terminals[$id]);
729 if(!in_array($type,array("terminal","server","workstation","opsi_client","winstation "))) continue;
730 if(isset($this->terminals[$id]['macAddress'][0])){
731 $mac[] = $this->terminals[$id]['macAddress'][0];
732 }else{
733 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
734 $attrs= $ldap->fetch();
735 if (isset($attrs['macAddress'][0])){
736 $mac[]= $attrs['macAddress'][0];
737 }
738 }
739 }
740 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
741 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
742 $o_queue = new gosaSupportDaemon();
744 /* Skip installation or update trigerred events,
745 * if this entry is currently processing.
746 */
747 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
748 foreach($mac as $key => $mac_address){
749 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
751 $entry['STATUS'] = strtoupper($entry['STATUS']);
752 if($entry['STATUS'] == "PROCESSING" &&
753 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
754 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
755 unset($mac[$key]);
757 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
758 break;
759 }
760 }
761 }
762 }
764 /* Prepare event to be added
765 */
766 if(count($mac) && isset($events['BY_CLASS'][$type])){
767 $event = $events['BY_CLASS'][$type];
768 $this->systab = new $event['CLASS_NAME']($this->config);
769 $this->systab->add_targets($mac);
770 if(preg_match("/trigger_event/",$s_action)){
771 $this->systab->set_type(TRIGGERED_EVENT);
772 }else{
773 $this->systab->set_type(SCHEDULED_EVENT);
774 }
775 }
776 }
777 }
779 /* Insert scheduled events into queue */
780 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
781 $this->systab->save_object();
783 /* Save event
784 */
785 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
786 $o_queue = new gosaSupportDaemon();
787 $o_queue->append($this->systab);
788 if($o_queue->is_error()){
789 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
790 }else{
791 $this->systab = FALSE;
792 }
793 }
794 if(isset($_POST['abort_event_dialog'])){
795 $this->systab = FALSE;
796 }
797 }
800 /********************
801 Delete MULTIPLE entries requested, display confirm dialog
802 ********************/
804 if ($s_action=="del_multiple" || $s_action == "del"){
805 $this->dns = array();
807 if($s_action == "del_multiple"){
808 $ids = $this->list_get_selected_items();
809 }else{
810 $ids = array($s_entry);
811 }
813 $ui = get_userinfo();
814 $tabs = $this->get_tab_defs();
816 if(count($ids)){
818 $disallowed = array();
819 foreach($ids as $id){
821 /* Get 'dn' from posted termlinst */
822 $attrs = $this->terminals[$id];
823 $type = $this->get_system_type($attrs);
824 $dn = $attrs['dn'];
825 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
826 if(preg_match("/d/",$acl)){
827 $this->dns[$id] = $dn;
828 }else{
829 $disallowed[] = $dn;
830 }
831 }
833 if(count($disallowed)){
834 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
835 }
837 if(count($this->dns)){
839 if ($user= get_multiple_locks($this->dns)){
840 return(gen_locked_message($user,$this->dns));
841 }
843 $dns_names = array();
844 foreach($this->dns as $dn){
845 add_lock ($dn, $this->ui->dn);
846 $dns_names[] = @LDAP::fix($dn);
847 }
849 /* Lock the current entry, so nobody will edit it during deletion */
850 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
851 $smarty->assign("multiple", true);
852 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
853 }
854 }
855 }
858 /********************
859 Delete MULTIPLE entries confirmed
860 ********************/
862 /* Confirmation for deletion has been passed. Users should be deleted. */
863 if (isset($_POST['delete_multiple_system_confirm'])){
865 $ui = get_userinfo();
866 $tabs = $this->get_tab_defs();
868 /* Remove user by user and check acls before removeing them */
869 foreach($this->dns as $key => $dn){
871 /* Get 'dn' from posted termlinst */
872 $attrs = $this->terminals[$key];
873 $type= $this->get_system_type($attrs);
875 /* get object type */
876 $tabtype = "termtabs";
877 $tabobj = "TERMTABS";
878 $tabacl = "";
879 if(isset($tabs[$type])){
880 $tabtype = $tabs[$type]['TABCLASS'];
881 $tabobj = $tabs[$type]['CLASS'];
882 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
884 /* Load permissions for selected 'dn' and check if
885 we're allowed to remove this 'dn' */
886 if(preg_match("/d/",$tabacl)){
888 /* Delete request is permitted, perform LDAP action */
889 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
890 $this->systab= new termgeneric($this->config, $dn);
891 $this->systab->set_acl_base($dn);
892 $this->systab->remove_from_parent();
893 }elseif($tabtype=="phonetabs"){
894 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
895 $this->systab->set_acl_base($dn);
896 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
897 }else{
898 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
899 $this->systab->set_acl_base($dn);
900 $this->systab->delete();
901 }
902 unset ($this->systab);
903 $this->systab= NULL;
905 } else {
906 /* Normally this shouldn't be reached, send some extra
907 logs to notify the administrator */
908 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
909 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
910 }
911 }
913 /* Remove lock file after successfull deletion */
914 $this->remove_lock();
915 $this->dns = array();
916 }
917 }
919 /********************
920 Delete MULTIPLE entries Canceled
921 ********************/
923 /* Remove lock */
924 if(isset($_POST['delete_multiple_system_cancel'])){
926 /* Remove lock file after successfull deletion */
927 $this->remove_lock();
928 $this->dns = array();
929 }
932 /********************
933 Edit system type finished, check if everything went ok
934 ********************/
935 /* Finish user edit is triggered by the tabulator dialog, so
936 the user wants to save edited data. Check and save at this
937 point. */
939 /* Dirty workaround - MSG_DIALOG - OK
940 If a message dialog is shown and we press 'OK'
941 then try to save again.
942 */
943 foreach($_POST as $name => $value){
944 if(preg_match("/^MSG_OK/",$name)){
945 $_POST[$this->last_action] = TRUE;
946 }
947 }
949 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
951 /* If the save routine gets interrupted by a confirm dialog,
952 store last action so we can trigger it again after 'Ok' was pressed.
953 (This is the case if a system gets modified while it is installing - GOsa si)
954 */
955 $this->last_action = "";
956 if(isset($_POST['edit_finish'])){
957 $this->last_action = "edit_finish";
958 }elseif(isset($_POST['edit_apply'])){
959 $this->last_action = "edit_apply";
960 }
962 /* Check tabs, will feed message array */
963 $message = $this->systab->check();
965 /* Save, or display error message? */
966 if (count($message) == 0){
969 $this->systab->save();
971 /* Terminal has been saved successfully, remove lock from LDAP. */
972 if (!isset($_POST['edit_apply'])){
973 if ($this->dn != "new"){
974 $this->remove_lock();
975 }
977 unset ($this->systab);
978 $this->systab= NULL;
979 session::un_set('objectinfo');
980 }else{
982 /* Reinitialize tab */
983 if($this->systab instanceof tabs){
984 $this->systab->re_init();
985 }
986 }
987 } else {
988 /* Ok. There seem to be errors regarding to the tab data,
989 show message and continue as usual. */
990 msg_dialog::displayChecks($message);
991 }
992 }
995 /********************
996 Edit system was canceled
997 ********************/
998 /* Cancel dialogs */
999 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1000 if (isset($this->systab)){
1001 $this->remove_lock();
1002 unset ($this->systab);
1003 }
1004 $this->systab= NULL;
1005 session::un_set('objectinfo');
1006 }
1008 /********************
1009 Display edit dialog, or some other
1010 ********************/
1012 /* Show tab dialog if object is present */
1013 if (isset($this->systab->config)){
1014 $display= $this->systab->execute();
1016 /* Don't show buttons if tab dialog requests this */
1018 $dialog = FALSE;
1019 $hide_apply = $this->dn == "new";
1020 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("systemIncomingRDN"))."/",$this->dn));
1021 if(is_object($this->systab) && !isset($this->systab->by_object)){
1022 $dialog = TRUE;
1023 $hide_apply = TRUE;
1024 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1025 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1026 if($dia === TRUE || is_object($dia)){
1027 $dialog = TRUE;
1028 }
1029 }
1030 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1031 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1032 $dialog = TRUE;
1033 }
1035 if (!$dialog){
1036 $display.= "<p style=\"text-align:right\">\n";
1037 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1038 $display.= " \n";
1039 if (!$hide_apply){
1040 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1041 $display.= " \n";
1042 }
1043 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1044 $display.= "</p>";
1045 }
1046 return ($display);
1047 }
1049 /* Check if there is a snapshot dialog open */
1050 $base = $this->DivListSystem->selectedBase;
1051 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1052 return($str);
1053 }
1055 /* Display dialog with system list */
1056 $this->DivListSystem->parent = $this;
1057 $this->DivListSystem->execute();
1059 /* Add departments if subsearch is disabled */
1060 if(!$this->DivListSystem->SubSearch){
1062 /* Add FAIstate to attributes if FAI is activated */
1063 if($this->fai_activated){
1064 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1065 }else{
1066 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1067 }
1068 }
1069 $this->reload();
1070 $this->DivListSystem->setEntries($this->terminals);
1071 return($this->DivListSystem->Draw());
1072 }
1075 /* Return departments, that will be included within snapshot detection */
1076 function get_used_snapshot_bases()
1077 {
1078 $tmp = array();
1080 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1082 $tabs = array(
1083 "terminal" => get_ou('terminalRDN'),
1084 "workstation" => get_ou('workstationRDN'),
1085 "incoming" => get_ou('systemIncomingRDN'),
1086 "server" => get_ou('serverRDN'),
1087 "printer" => get_ou('printerRDN'),
1088 "phone" => get_ou('phoneRDN'),
1089 "winworkstation" => get_winstations_ou(),
1090 "component" => get_ou('componentRDN')
1091 );
1093 foreach($tabs as $acl_cat => $dn){
1095 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1096 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1097 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1098 }
1099 }
1100 return($tmp);
1101 }
1104 function remove_from_parent()
1105 {
1106 /* Optionally execute a command after we're done */
1107 $this->postremove();
1108 }
1111 /* Save data to object */
1112 function save_object()
1113 {
1114 $this->DivListSystem->save_object();
1115 if(is_object($this->CopyPasteHandler)){
1116 $this->CopyPasteHandler->save_object();
1117 }
1118 }
1121 /* Check values */
1122 function check()
1123 {
1124 }
1127 /* Save to LDAP */
1128 function save()
1129 {
1130 }
1132 function adapt_from_template($dn, $skip= array())
1133 {
1134 }
1136 function password_change_needed()
1137 {
1138 }
1140 function reload()
1141 {
1142 /* some var init */
1143 $ui = get_userinfo();
1144 $res = array();
1145 $this->terminals = array();
1146 $userregex = "";
1147 $opsi_clients = array();
1149 /* Set base for all searches */
1150 $base= $this->DivListSystem->selectedBase;
1152 /* Prepare samba class name */
1153 $samba ="";
1154 if ($this->DivListSystem->ShowWinWorkstations){
1155 if ($this->config->get_cfg_value("sambaversion") == "3"){
1156 $samba= "sambaSamAccount";
1157 } else {
1158 $samba= "sambaAccount";
1159 }
1160 }
1162 /* This array represents the combination between checkboxes and search filters */
1163 $objs = array(
1164 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1165 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1166 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1167 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1168 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1169 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1170 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1172 /* Include the 'Display Systems of user' attribute */
1173 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1174 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1175 }
1177 /* Attributes to fetch */
1178 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1179 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation");
1181 /* Add FAIstate to attributes if FAI is activated */
1182 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1183 if(!empty($tmp)){
1184 $sys_attrs[] = "FAIstate";
1185 }
1187 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1188 foreach($objs as $checkBox => $oc){
1190 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1191 if($this->DivListSystem->SubSearch){
1192 if($oc['CLASS'] != ""){
1193 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1194 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1195 $res = array_merge($res,$new_res);
1196 }
1197 }else{
1198 /* User filter? */
1199 if($oc['CLASS'] != ""){
1200 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1201 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1202 }
1203 }
1204 }
1205 }
1207 /* Search for incoming objects */
1208 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1209 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1211 /* Append opsi systems, the opsi extension have to installed.
1212 */
1213 if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1214 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1215 if($this->opsi->is_error()){
1216 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1217 }
1218 }
1220 /* Get all gotoTerminal's */
1221 $t_id = 0;
1222 $opsi_map = array();
1223 foreach ($res as $value){
1225 $tmp= $value['dn'];
1226 $add= "";
1228 /* Extract base */
1229 foreach($objs as $obj){
1230 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1231 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1232 }
1233 }
1235 /* Create a string containing the last part of the department. */
1236 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1237 if(empty($dn_name)){
1238 $dn_name = "/";
1239 }
1241 /* check if current object is a new one */
1242 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1243 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1244 $add= "- "._("New terminal");
1245 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1246 $add= "- "._("New workstation");
1247 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1248 $add= "- "._("Unknown device");
1249 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1250 $add= "- "._("New Device");
1251 }
1252 }
1254 /* Detect type of object and create an entry for $this->terminals */
1255 $terminal = array();
1257 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1259 /* check acl */
1260 $terminal = $value;
1261 $terminal['type'] = "O";
1263 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1265 /* check acl */
1266 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1267 if($add != "" || preg_match("/r/",$acl)) {
1268 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1269 $terminal = $value;
1270 $terminal['type'] = "T";
1271 $terminal['is_new'] = $add;
1272 } else {
1273 $terminal = $value;
1274 $terminal['type'] = "D";
1275 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1276 $terminal['location'] = array_search($tmp, $this->config->departments);
1277 }
1278 }
1279 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1281 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1282 if($add != "" || preg_match("/r/",$acl)) {
1283 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1284 $terminal = $value;
1285 $terminal['type'] = "L";
1286 $terminal['is_new'] = $add;
1287 } else {
1288 $terminal = $value;
1289 $terminal['type'] = "D";
1290 $terminal['location'] = array_search($tmp, $this->config->departments);
1291 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1292 }
1293 # if (isset($value["FAIstate"][0])){
1294 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1295 # }
1296 }
1297 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1300 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1301 if($add != "" || preg_match("/r/",$acl)) {
1303 $terminal = $value;
1304 $terminal['type'] = "P";
1305 }
1306 } elseif (in_array_ics('goServer', $value["objectClass"])){
1308 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1309 if($add != "" || preg_match("/r/",$acl)) {
1311 $terminal = $value;
1312 $terminal['type'] = "S";
1313 # if (isset($value["FAIstate"][0])){
1314 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1315 # }
1316 }
1317 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1319 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1320 if($add != "" || preg_match("/r/",$acl)) {
1322 $terminal = $value;
1323 $terminal['type'] = "F";
1324 }
1325 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1327 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1328 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1329 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1330 if($add != "" || preg_match("/r/",$acl)) {
1332 $terminal = $value;
1333 $terminal['type'] = "Q";
1334 $terminal['is_new'] = $add;
1335 }
1336 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1337 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1338 $type= "winstation";
1339 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1340 if($add != "" || preg_match("/r/",$acl)) {
1342 $terminal = $value;
1343 $terminal['type'] = "C";
1344 }
1345 } else{
1347 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1348 if (isset($value['sambaDomainName'])){
1349 $domain= " [".$value['sambaDomainName'][0]."]";
1350 } else {
1351 $domain= "";
1352 }
1353 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1354 if($add != "" || preg_match("/r/",$acl)) {
1355 $terminal=$value;
1356 $terminal['type'] ="W";
1357 $terminal['domain'] = $name.$domain;
1358 }
1359 }
1361 /* Append collected data to the host list.
1362 */
1363 if(count($terminal)){
1364 $t_id ++ ;
1365 $this->terminals[$t_id]=$terminal;
1366 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1367 }
1368 }
1371 /* Merge real hosts with opsi hosts.
1372 If there is a samba host, then merge it with the opsi host,
1373 to avoid duplicate entries.
1374 */
1375 foreach($opsi_clients as $entry){
1376 if(isset($opsi_map[$entry['cn'][0]])){
1377 continue;
1378 }
1379 $terminal = $entry;
1380 $terminal['type'] = "O";
1381 $this->terminals[] = $terminal;
1382 }
1384 $tmp =array();
1385 $tmp2 =array();
1386 foreach($this->terminals as $tkey => $val ){
1387 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1388 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1389 }
1390 natcasesort($tmp2);
1391 $this->terminals=array();
1392 foreach($tmp2 as $val){
1393 $this->terminals[]=$tmp[$val];
1394 }
1395 reset ($this->terminals);
1396 }
1398 function remove_lock()
1399 {
1400 if (isset($this->systab->dn)){
1401 del_lock ($this->systab->dn);
1402 }
1403 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1404 del_lock($this->dn);
1405 }
1406 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1407 del_lock($this->dns);
1408 }
1409 }
1412 function copyPasteHandling_from_queue($s_action,$s_entry)
1413 {
1414 /* Check if Copy & Paste is disabled */
1415 if(!is_object($this->CopyPasteHandler)){
1416 return("");
1417 }
1419 $ui = get_userinfo();
1421 $tabs = $this->get_tab_defs();
1423 /* Add a single entry to queue */
1424 if($s_action == "cut" || $s_action == "copy"){
1426 /* Cleanup object queue */
1427 $this->CopyPasteHandler->cleanup_queue();
1428 $dn = $this->terminals[$s_entry]['dn'];
1429 $oc = $this->terminals[$s_entry]['objectClass'];
1430 $type = $this->get_system_type($this->terminals[$s_entry]);
1432 $tab_o = $tabs[$type]['CLASS'];
1433 $tab_c = $tabs[$type]['TABCLASS'];
1434 $acl_c = $tabs[$type]['TABNAME'];
1435 $acl = $tabs[$type]['ACLC'];
1437 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1438 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1439 }
1440 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1441 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1442 }
1443 }
1445 /* Add entries to queue */
1446 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1448 /* Cleanup object queue */
1449 $this->CopyPasteHandler->cleanup_queue();
1451 /* Add new entries to CP queue */
1452 foreach($this->list_get_selected_items() as $id){
1453 $dn = $this->terminals[$id]['dn'];
1454 $oc = $this->terminals[$id]['objectClass'];
1455 $type = $this->get_system_type($this->terminals[$id]);
1457 if(isset($tabs[$type])){
1458 $tab_o = $tabs[$type]['CLASS'];
1459 $tab_c = $tabs[$type]['TABCLASS'];
1460 $acl_c = $tabs[$type]['TABNAME'];
1461 $acl = $tabs[$type]['ACLC'];
1463 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1464 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1465 }
1466 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1467 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1468 }
1469 }
1470 }
1471 }
1473 /* Start pasting entries */
1474 if($s_action == "editPaste"){
1475 $this->start_pasting_copied_objects = TRUE;
1476 }
1478 /* Return C&P dialog */
1479 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1481 /* Get dialog */
1482 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1483 $data = $this->CopyPasteHandler->execute();
1485 /* Return dialog data */
1486 if(!empty($data)){
1487 return($data);
1488 }
1489 }
1491 /* Automatically disable status for pasting */
1492 if(!$this->CopyPasteHandler->entries_queued()){
1493 $this->start_pasting_copied_objects = FALSE;
1494 }
1495 return("");
1496 }
1499 function get_system_type($attrs)
1500 {
1501 $classes = $attrs['objectClass'];
1503 $type= "";
1504 if (in_array_ics('gosa_opsi_client', $classes)){
1505 $type= "opsi_client";
1506 }elseif (in_array_ics('sambaAccount', $classes) ||
1507 in_array_ics('sambaSamAccount', $classes)){
1508 $type= "winstation";
1509 }elseif (in_array_ics('ieee802Device', $classes)){
1510 $type= "component";
1511 }elseif (in_array_ics('gotoTerminal', $classes)){
1512 $type= "terminal";
1513 }elseif (in_array_ics('gotoWorkstation', $classes)){
1514 $type= "workstation";
1515 }elseif (in_array_ics('gotoPrinter', $classes)){
1516 $type= "printer";
1517 }elseif (in_array_ics('goFonHardware', $classes)){
1518 $type= "phone";
1519 }elseif (in_array_ics('goServer', $classes)){
1520 $type= "server";
1521 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1522 $type= "ArpNewDevice";
1523 }elseif (in_array_ics('GOhard', $classes)){
1524 $type= "NewDevice";
1525 }
1526 return ($type);
1527 }
1530 function convert_list($input)
1531 {
1532 $temp= "";
1534 $conv= array(
1535 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1536 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1537 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1538 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1540 "W" => array("plugins/systems/images/select_winstation.png",_("Win workstation")),
1542 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1543 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1544 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1546 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1547 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1548 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1550 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1551 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1552 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1554 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1555 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1557 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1558 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1559 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1561 /* Add opsi client to system types */
1562 if($this->opsi != NULL){
1563 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1564 }
1566 /* Use locked icons
1567 */
1568 if( in_array($input['type'],array("S","T","L")) &&
1569 isset($input['gotoMode'][0]) &&
1570 preg_match("/locked/",$input['gotoMode'][0])){
1571 $input['type'].="X";
1572 } elseif(in_array($input['type'],array("S","L")) &&
1573 isset($input['FAIstate'][0])){
1575 /* Add FAI state icons
1576 */
1577 $type= "";
1578 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1579 case 'error':
1580 $type= 'E';
1581 break;
1582 case 'installing':
1583 case 'install':
1584 case 'sysinfo':
1585 case 'softupdate':
1586 case 'scheduledupdate':
1587 $type= 'B';
1588 break;
1589 }
1591 $input['type'].= $type;
1592 }
1594 /* Use new images if object is from incoming
1595 */
1596 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1597 $input['type']="N".$input['type'];
1598 }
1600 /* Check which flags this objects uses
1601 */
1602 foreach ($conv as $key => $value){
1603 $found = TRUE;
1604 if(strlen($key) != strlen($input['type'])) {
1605 $found = FALSE;
1606 }
1607 for($i = 0 ; $i < strlen($key) ; $i++){
1608 if(!preg_match("/".$key[$i]."/",$input['type'])){
1609 $found = FALSE;
1610 }
1611 }
1613 if($found){
1614 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1615 $tmp['class']=$key;
1616 return $tmp;
1617 }
1618 }
1619 }
1622 function list_get_selected_items()
1623 {
1624 $ids = array();
1625 foreach($_POST as $name => $value){
1626 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1627 $id = preg_replace("/^item_selected_/","",$name);
1628 $ids[$id] = $id;
1629 }
1630 }
1631 return($ids);
1632 }
1635 public function get_tab_defs()
1636 {
1637 $tabs = array(
1638 "incoming" => array(
1639 "CLASS" => "",
1640 "TABNAME" => "",
1641 "TABCLASS" => "",
1642 "ACLC" => "incoming",
1643 "ACL" => "incoming/systems"),
1645 "ArpNewDevice"=> array(
1646 "CLASS" => "TERMTABS",
1647 "TABNAME" => "termgeneric" ,
1648 "TABCLASS" => "termtabs",
1649 "ACLC" => "incoming",
1650 "ACL" => "incoming/systems"),
1652 "NewDevice" => array(
1653 "CLASS" => "TERMTABS",
1654 "TABNAME" => "termgeneric",
1655 "TABCLASS" => "termtabs",
1656 "ACLC" => "incoming",
1657 "ACL" => "incoming/systems"),
1659 "terminal" => array(
1660 "CLASS" => "TERMTABS",
1661 "TABNAME" => "termgeneric",
1662 "TABCLASS" => "termtabs",
1663 "ACLC" => "terminal",
1664 "ACL" => "terminal/termgeneric"),
1666 "workstation" => array(
1667 "CLASS" => "WORKTABS",
1668 "TABNAME" => "workgeneric",
1669 "TABCLASS"=> "worktabs",
1670 "ACLC" => "workstation",
1671 "ACL" => "workstation/workgeneric" ),
1673 "server" => array(
1674 "CLASS" => "SERVTABS",
1675 "TABNAME" => "servgeneric",
1676 "TABCLASS"=> "servtabs",
1677 "ACLC" => "server",
1678 "ACL" => "server/servgeneric"),
1680 "printer" => array(
1681 "CLASS" => "PRINTTABS",
1682 "TABNAME" => "printgeneric",
1683 "TABCLASS"=> "printtabs",
1684 "ACLC" => "printer",
1685 "ACL" => "printer/printgeneric"),
1687 "phone" => array(
1688 "CLASS" => "PHONETABS",
1689 "TABNAME" => "phoneGeneric",
1690 "TABCLASS"=> "phonetabs",
1691 "ACLC" => "phone",
1692 "ACL" => "phone/phoneGeneric"),
1694 "winstation" => array(
1695 "CLASS" => "WINTABS",
1696 "TABNAME" => "wingeneric",
1697 "TABCLASS"=> "wintabs",
1698 "ACLC" => "winworkstation",
1699 "ACL" => "winworkstation/wingeneric"),
1701 "component" => array(
1702 "CLASS" => "COMPONENTTABS",
1703 "TABNAME" => "componentGeneric",
1704 "TABCLASS"=> "componenttabs",
1705 "ACLC" => "component",
1706 "ACL" => "component/componentGeneric"));
1708 if($this->opsi != NULL){
1709 $tabs["opsi_client"] = array(
1710 "CLASS" => "OPSITABS",
1711 "TABNAME" => "opsiGeneric" ,
1712 "TABCLASS"=> "opsi_tabs",
1713 "ACLC" => "opsi" ,
1714 "ACL" => "opsi/opsiGeneric");
1715 }
1717 return($tabs);
1718 }
1722 /* !! Incoming dummy acls, required to defined acls for incoming objects
1723 */
1724 static function plInfo()
1725 {
1726 return (array(
1727 "plShortName" => _("Incoming objects"),
1728 "plDescription" => _("Incoming objects"),
1729 "plSelfModify" => FALSE,
1730 "plDepends" => array(),
1731 "plPriority" => 99,
1732 "plSection" => array("administration"),
1733 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1734 "objectClass" => "")),
1735 "plProvidedAcls"=> array()
1737 ));
1738 }
1739 }
1741 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1742 ?>