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 /* Creat dialog object */
66 $this->DivListSystem = new divListSystem($this->config,$this);
68 /* Copy & Paste enabled ?*/
69 if ($this->config->get_cfg_value("enablecopypaste") == "true"){
70 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
71 }
73 /* Check whether the arp handling active or not */
74 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
75 $this->arp_handling_active = TRUE;
76 }
78 /* Check if we are able to communicate with the GOsa supprot daemon
79 */
80 if(class_available("gosaSupportDaemon")){
81 $o = new gosaSupportDaemon();
82 $this->si_active = $o->connect() && class_available("DaemonEvent");
83 }
85 /* Check if we are able to communicate with the GOsa supprot daemon
86 */
87 if(class_available("opsi")){
88 $this->opsi = new opsi($this->config);
89 }
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", "ISOCMD",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 if(count($ids) && class_available("DaemonEvent")){
712 $mac= array();
714 $ldap = $this->config->get_ldap_link();
715 foreach($ids as $id){
716 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
717 $attrs= $ldap->fetch();
718 if (isset($attrs['macAddress'][0])){
719 $mac[]= $attrs['macAddress'][0];
720 }
721 }
722 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
723 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
724 $o_queue = new gosaSupportDaemon();
726 /* Skip installation or update trigerred events,
727 * if this entry is currently processing.
728 */
729 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
730 foreach($mac as $key => $mac_address){
731 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
733 $entry['STATUS'] = strtoupper($entry['STATUS']);
734 if($entry['STATUS'] == "PROCESSING" &&
735 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
736 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
737 unset($mac[$key]);
739 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
740 break;
741 }
742 }
743 }
744 }
746 /* Prepare event to be added
747 */
748 if(count($mac) && isset($events['BY_CLASS'][$type])){
749 $event = $events['BY_CLASS'][$type];
750 $this->systab = new $event['CLASS_NAME']($this->config);
751 $this->systab->add_targets($mac);
752 if(preg_match("/trigger_event/",$s_action)){
753 $this->systab->set_type(TRIGGERED_EVENT);
754 }else{
755 $this->systab->set_type(SCHEDULED_EVENT);
756 }
757 }
758 }
759 }
761 /* Insert scheduled events into queue */
762 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
763 $this->systab->save_object();
765 /* Save event
766 */
767 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
768 $o_queue = new gosaSupportDaemon();
769 $o_queue->append($this->systab);
770 if($o_queue->is_error()){
771 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
772 }else{
773 $this->systab = FALSE;
774 }
775 }
776 if(isset($_POST['abort_event_dialog'])){
777 $this->systab = FALSE;
778 }
779 }
782 /********************
783 Delete MULTIPLE entries requested, display confirm dialog
784 ********************/
786 if ($s_action=="del_multiple" || $s_action == "del"){
787 $this->dns = array();
789 if($s_action == "del_multiple"){
790 $ids = $this->list_get_selected_items();
791 }else{
792 $ids = array($s_entry);
793 }
795 $ui = get_userinfo();
796 $tabs = $this->get_tab_defs();
798 if(count($ids)){
800 $disallowed = array();
801 foreach($ids as $id){
803 /* Get 'dn' from posted termlinst */
804 $attrs = $this->terminals[$id];
805 $type = $this->get_system_type($attrs);
806 $dn = $attrs['dn'];
807 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
808 if(preg_match("/d/",$acl)){
809 $this->dns[$id] = $dn;
810 }else{
811 $disallowed[] = $dn;
812 }
813 }
815 if(count($disallowed)){
816 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
817 }
819 if(count($this->dns)){
821 if ($user= get_multiple_locks($this->dns)){
822 return(gen_locked_message($user,$this->dns));
823 }
825 $dns_names = array();
826 foreach($this->dns as $dn){
827 add_lock ($dn, $this->ui->dn);
828 $dns_names[] = @LDAP::fix($dn);
829 }
831 /* Lock the current entry, so nobody will edit it during deletion */
832 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
833 $smarty->assign("multiple", true);
834 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
835 }
836 }
837 }
840 /********************
841 Delete MULTIPLE entries confirmed
842 ********************/
844 /* Confirmation for deletion has been passed. Users should be deleted. */
845 if (isset($_POST['delete_multiple_system_confirm'])){
847 $ui = get_userinfo();
848 $tabs = $this->get_tab_defs();
850 /* Remove user by user and check acls before removeing them */
851 foreach($this->dns as $key => $dn){
853 /* Get 'dn' from posted termlinst */
854 $attrs = $this->terminals[$key];
855 $type= $this->get_system_type($attrs);
857 /* get object type */
858 $tabtype = "termtabs";
859 $tabobj = "TERMTABS";
860 $tabacl = "";
861 if(isset($tabs[$type])){
862 $tabtype = $tabs[$type]['TABCLASS'];
863 $tabobj = $tabs[$type]['CLASS'];
864 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
866 /* Load permissions for selected 'dn' and check if
867 we're allowed to remove this 'dn' */
868 if(preg_match("/d/",$tabacl)){
870 /* Delete request is permitted, perform LDAP action */
871 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
872 $this->systab= new termgeneric($this->config, $dn);
873 $this->systab->set_acl_base($dn);
874 $this->systab->remove_from_parent();
875 }elseif($tabtype=="phonetabs"){
876 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
877 $this->systab->set_acl_base($dn);
878 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
879 }else{
880 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
881 $this->systab->set_acl_base($dn);
882 $this->systab->delete();
883 }
884 unset ($this->systab);
885 $this->systab= NULL;
887 } else {
888 /* Normally this shouldn't be reached, send some extra
889 logs to notify the administrator */
890 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
891 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
892 }
893 }
895 /* Remove lock file after successfull deletion */
896 $this->remove_lock();
897 $this->dns = array();
898 }
899 }
901 /********************
902 Delete MULTIPLE entries Canceled
903 ********************/
905 /* Remove lock */
906 if(isset($_POST['delete_multiple_system_cancel'])){
908 /* Remove lock file after successfull deletion */
909 $this->remove_lock();
910 $this->dns = array();
911 }
914 /********************
915 Edit system type finished, check if everything went ok
916 ********************/
917 /* Finish user edit is triggered by the tabulator dialog, so
918 the user wants to save edited data. Check and save at this
919 point. */
921 /* Dirty workaround - MSG_DIALOG - OK
922 If a message dialog is shown and we press 'OK'
923 then try to save again.
924 */
925 foreach($_POST as $name => $value){
926 if(preg_match("/^MSG_OK/",$name)){
927 $_POST[$this->last_action] = TRUE;
928 }
929 }
931 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
933 /* If the save routine gets interrupted by a confirm dialog,
934 store last action so we can trigger it again after 'Ok' was pressed.
935 (This is the case if a system gets modified while it is installing - GOsa si)
936 */
937 $this->last_action = "";
938 if(isset($_POST['edit_finish'])){
939 $this->last_action = "edit_finish";
940 }elseif(isset($_POST['edit_apply'])){
941 $this->last_action = "edit_apply";
942 }
944 /* Check tabs, will feed message array */
945 $message = $this->systab->check();
947 /* Save, or display error message? */
948 if (count($message) == 0){
951 $this->systab->save();
953 /* Terminal has been saved successfully, remove lock from LDAP. */
954 if (!isset($_POST['edit_apply'])){
955 if ($this->dn != "new"){
956 $this->remove_lock();
957 }
959 unset ($this->systab);
960 $this->systab= NULL;
961 session::un_set('objectinfo');
962 }else{
964 /* Reinitialize tab */
965 if($this->systab instanceof tabs){
966 $this->systab->re_init();
967 }
968 }
969 } else {
970 /* Ok. There seem to be errors regarding to the tab data,
971 show message and continue as usual. */
972 msg_dialog::displayChecks($message);
973 }
974 }
977 /********************
978 Edit system was canceled
979 ********************/
980 /* Cancel dialogs */
981 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
982 if (isset($this->systab)){
983 $this->remove_lock();
984 unset ($this->systab);
985 }
986 $this->systab= NULL;
987 session::un_set('objectinfo');
988 }
990 /********************
991 Display edit dialog, or some other
992 ********************/
994 /* Show tab dialog if object is present */
995 if (isset($this->systab->config)){
996 $display= $this->systab->execute();
998 /* Don't show buttons if tab dialog requests this */
1000 $dialog = FALSE;
1001 $hide_apply = $this->dn == "new";
1002 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1003 if(is_object($this->systab) && !isset($this->systab->by_object)){
1004 $dialog = TRUE;
1005 $hide_apply = TRUE;
1006 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1007 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1008 if($dia === TRUE || is_object($dia)){
1009 $dialog = TRUE;
1010 }
1011 }
1012 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1013 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1014 $dialog = TRUE;
1015 }
1017 if (!$dialog){
1018 $display.= "<p style=\"text-align:right\">\n";
1019 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1020 $display.= " \n";
1021 if (!$hide_apply){
1022 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1023 $display.= " \n";
1024 }
1025 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1026 $display.= "</p>";
1027 }
1028 return ($display);
1029 }
1031 /* Check if there is a snapshot dialog open */
1032 $base = $this->DivListSystem->selectedBase;
1033 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1034 return($str);
1035 }
1037 /* Display dialog with system list */
1038 $this->DivListSystem->parent = $this;
1039 $this->DivListSystem->execute();
1041 /* Add departments if subsearch is disabled */
1042 if(!$this->DivListSystem->SubSearch){
1044 /* Add FAIstate to attributes if FAI is activated */
1045 if($this->fai_activated){
1046 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1047 }else{
1048 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1049 }
1050 }
1051 $this->reload();
1052 $this->DivListSystem->setEntries($this->terminals);
1053 return($this->DivListSystem->Draw());
1054 }
1057 /* Return departments, that will be included within snapshot detection */
1058 function get_used_snapshot_bases()
1059 {
1060 $tmp = array();
1062 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1064 $tabs = array(
1065 "terminal" => get_ou('terminalou'),
1066 "workstation" => get_ou('workstationou'),
1067 "incoming" => get_ou('incomingou'),
1068 "server" => get_ou('serverou'),
1069 "printer" => get_ou('printerou'),
1070 "phone" => get_ou('phoneou'),
1071 "winworkstation" => get_winstations_ou(),
1072 "component" => get_ou('componentou')
1073 );
1075 foreach($tabs as $acl_cat => $dn){
1077 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1078 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1079 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1080 }
1081 }
1082 return($tmp);
1083 }
1086 function remove_from_parent()
1087 {
1088 /* Optionally execute a command after we're done */
1089 $this->postremove();
1090 }
1093 /* Save data to object */
1094 function save_object()
1095 {
1096 $this->DivListSystem->save_object();
1097 if(is_object($this->CopyPasteHandler)){
1098 $this->CopyPasteHandler->save_object();
1099 }
1100 }
1103 /* Check values */
1104 function check()
1105 {
1106 }
1109 /* Save to LDAP */
1110 function save()
1111 {
1112 }
1114 function adapt_from_template($dn, $skip= array())
1115 {
1116 }
1118 function password_change_needed()
1119 {
1120 }
1122 function reload()
1123 {
1124 /* some var init */
1125 $ui = get_userinfo();
1126 $res = array();
1127 $this->terminals = array();
1128 $userregex = "";
1129 $opsi_clients = array();
1131 /* Set base for all searches */
1132 $base= $this->DivListSystem->selectedBase;
1134 /* Prepare samba class name */
1135 $samba ="";
1136 if ($this->DivListSystem->ShowWinWorkstations){
1137 if ($this->config->get_cfg_value("sambaversion") == "3"){
1138 $samba= "sambaSamAccount";
1139 } else {
1140 $samba= "sambaAccount";
1141 }
1142 }
1144 /* This array represents the combination between checkboxes and search filters */
1145 $objs = array(
1146 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1147 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1148 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1149 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1150 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1151 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1152 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1154 /* Include the 'Display Systems of user' attribute */
1155 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1156 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1157 }
1159 /* Attributes to fetch */
1160 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1161 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1163 /* Add FAIstate to attributes if FAI is activated */
1164 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1165 if(!empty($tmp)){
1166 $sys_attrs[] = "FAIstate";
1167 }
1169 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1170 foreach($objs as $checkBox => $oc){
1172 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1173 if($this->DivListSystem->SubSearch){
1174 if($oc['CLASS'] != ""){
1175 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1176 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1177 $res = array_merge($res,$new_res);
1178 }
1179 }else{
1180 /* User filter? */
1181 if($oc['CLASS'] != ""){
1182 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1183 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1184 }
1185 }
1186 }
1187 }
1189 /* Search for incoming objects */
1190 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1191 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1193 /* Append opsi systems, the opsi extension have to installed.
1194 */
1195 if($this->opsi != NULL){
1196 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1197 if($this->opsi->is_error()){
1198 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1199 }
1200 }
1202 /* Get all gotoTerminal's */
1203 $t_id = 0;
1204 $opsi_map = array();
1205 foreach ($res as $value){
1207 $tmp= $value['dn'];
1208 $add= "";
1210 /* Extract base */
1211 foreach($objs as $obj){
1212 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1213 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1214 }
1215 }
1217 /* Create a string containing the last part of the department. */
1218 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1219 if(empty($dn_name)){
1220 $dn_name = "/";
1221 }
1223 /* check if current object is a new one */
1224 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1225 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1226 $add= "- "._("New terminal");
1227 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1228 $add= "- "._("New workstation");
1229 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1230 $add= "- "._("Unknown device");
1231 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1232 $add= "- "._("New Device");
1233 }
1234 }
1236 /* Detect type of object and create an entry for $this->terminals */
1237 $terminal = array();
1239 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1241 /* check acl */
1242 $terminal = $value;
1243 $terminal['type'] = "O";
1245 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1247 /* check acl */
1248 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1249 if($add != "" || preg_match("/r/",$acl)) {
1250 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1251 $terminal = $value;
1252 $terminal['type'] = "T";
1253 $terminal['is_new'] = $add;
1254 } else {
1255 $terminal = $value;
1256 $terminal['type'] = "D";
1257 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1258 $terminal['location'] = array_search($tmp, $this->config->departments);
1259 }
1260 }
1261 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1263 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1264 if($add != "" || preg_match("/r/",$acl)) {
1265 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1266 $terminal = $value;
1267 $terminal['type'] = "L";
1268 $terminal['is_new'] = $add;
1269 } else {
1270 $terminal = $value;
1271 $terminal['type'] = "D";
1272 $terminal['location'] = array_search($tmp, $this->config->departments);
1273 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1274 }
1275 # if (isset($value["FAIstate"][0])){
1276 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1277 # }
1278 }
1279 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1282 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1283 if($add != "" || preg_match("/r/",$acl)) {
1285 $terminal = $value;
1286 $terminal['type'] = "P";
1287 }
1288 } elseif (in_array_ics('goServer', $value["objectClass"])){
1290 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1291 if($add != "" || preg_match("/r/",$acl)) {
1293 $terminal = $value;
1294 $terminal['type'] = "S";
1295 # if (isset($value["FAIstate"][0])){
1296 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1297 # }
1298 }
1299 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1301 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1302 if($add != "" || preg_match("/r/",$acl)) {
1304 $terminal = $value;
1305 $terminal['type'] = "F";
1306 }
1307 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1309 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1310 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1311 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1312 if($add != "" || preg_match("/r/",$acl)) {
1314 $terminal = $value;
1315 $terminal['type'] = "Q";
1316 $terminal['is_new'] = $add;
1317 }
1318 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1320 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1321 if($add != "" || preg_match("/r/",$acl)) {
1323 $terminal = $value;
1324 $terminal['type'] = "C";
1325 }
1326 } else{
1328 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1329 if (isset($value['sambaDomainName'])){
1330 $domain= " [".$value['sambaDomainName'][0]."]";
1331 } else {
1332 $domain= "";
1333 }
1334 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1335 if($add != "" || preg_match("/r/",$acl)) {
1336 $terminal=$value;
1337 $terminal['type'] ="W";
1338 $terminal['domain'] = $name.$domain;
1339 }
1340 }
1342 /* Append collected data to the host list.
1343 */
1344 if(count($terminal)){
1345 $t_id ++ ;
1346 $this->terminals[$t_id]=$terminal;
1347 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1348 }
1349 }
1352 /* Merge real hosts with opsi hosts.
1353 If there is a samba host, then merge it with the opsi host,
1354 to avoid duplicate entries.
1355 */
1356 foreach($opsi_clients as $entry){
1357 if(isset($opsi_map[$entry['cn'][0]])){
1358 continue;
1359 }
1360 $terminal = $entry;
1361 $terminal['type'] = "O";
1362 $this->terminals[] = $terminal;
1363 }
1365 $tmp =array();
1366 $tmp2 =array();
1367 foreach($this->terminals as $tkey => $val ){
1368 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1369 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1370 }
1371 natcasesort($tmp2);
1372 $this->terminals=array();
1373 foreach($tmp2 as $val){
1374 $this->terminals[]=$tmp[$val];
1375 }
1376 reset ($this->terminals);
1377 }
1379 function remove_lock()
1380 {
1381 if (isset($this->systab->dn)){
1382 del_lock ($this->systab->dn);
1383 }
1384 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1385 del_lock($this->dn);
1386 }
1387 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1388 del_lock($this->dns);
1389 }
1390 }
1393 function copyPasteHandling_from_queue($s_action,$s_entry)
1394 {
1395 /* Check if Copy & Paste is disabled */
1396 if(!is_object($this->CopyPasteHandler)){
1397 return("");
1398 }
1400 $ui = get_userinfo();
1402 $tabs = $this->get_tab_defs();
1404 /* Add a single entry to queue */
1405 if($s_action == "cut" || $s_action == "copy"){
1407 /* Cleanup object queue */
1408 $this->CopyPasteHandler->cleanup_queue();
1409 $dn = $this->terminals[$s_entry]['dn'];
1410 $oc = $this->terminals[$s_entry]['objectClass'];
1411 $type = $this->get_system_type($this->terminals[$s_entry]);
1413 $tab_o = $tabs[$type]['CLASS'];
1414 $tab_c = $tabs[$type]['TABCLASS'];
1415 $acl_c = $tabs[$type]['TABNAME'];
1416 $acl = $tabs[$type]['ACLC'];
1418 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1419 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1420 }
1421 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1422 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1423 }
1424 }
1426 /* Add entries to queue */
1427 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1429 /* Cleanup object queue */
1430 $this->CopyPasteHandler->cleanup_queue();
1432 /* Add new entries to CP queue */
1433 foreach($this->list_get_selected_items() as $id){
1434 $dn = $this->terminals[$id]['dn'];
1435 $oc = $this->terminals[$id]['objectClass'];
1436 $type = $this->get_system_type($this->terminals[$id]);
1438 if(isset($tabs[$type])){
1439 $tab_o = $tabs[$type]['CLASS'];
1440 $tab_c = $tabs[$type]['TABCLASS'];
1441 $acl_c = $tabs[$type]['TABNAME'];
1442 $acl = $tabs[$type]['ACLC'];
1444 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1445 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1446 }
1447 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1448 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1449 }
1450 }
1451 }
1452 }
1454 /* Start pasting entries */
1455 if($s_action == "editPaste"){
1456 $this->start_pasting_copied_objects = TRUE;
1457 }
1459 /* Return C&P dialog */
1460 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1462 /* Get dialog */
1463 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1464 $data = $this->CopyPasteHandler->execute();
1466 /* Return dialog data */
1467 if(!empty($data)){
1468 return($data);
1469 }
1470 }
1472 /* Automatically disable status for pasting */
1473 if(!$this->CopyPasteHandler->entries_queued()){
1474 $this->start_pasting_copied_objects = FALSE;
1475 }
1476 return("");
1477 }
1480 function get_system_type($attrs)
1481 {
1482 $classes = $attrs['objectClass'];
1484 $type= "";
1485 if (in_array_ics('gosa_opsi_client', $classes)){
1486 $type= "opsi_client";
1487 }elseif (in_array_ics('ieee802Device', $classes)){
1488 $type= "component";
1489 }elseif (in_array_ics('gotoTerminal', $classes)){
1490 $type= "terminal";
1491 }elseif (in_array_ics('gotoWorkstation', $classes)){
1492 $type= "workstation";
1493 }elseif (in_array_ics('gotoPrinter', $classes)){
1494 $type= "printer";
1495 }elseif (in_array_ics('goFonHardware', $classes)){
1496 $type= "phone";
1497 }elseif (in_array_ics('goServer', $classes)){
1498 $type= "server";
1499 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1500 $type= "ArpNewDevice";
1501 }elseif (in_array_ics('GOhard', $classes)){
1502 $type= "NewDevice";
1503 }elseif (in_array_ics('sambaAccount', $classes) ||
1504 in_array_ics('sambaSamAccount', $classes)){
1505 $type= "winstation";
1506 }
1507 return ($type);
1508 }
1511 function convert_list($input)
1512 {
1513 $temp= "";
1515 $conv= array(
1516 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1517 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1518 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1519 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1521 "W" => array("plugins/systems/images/select_winstation.png",_("Win workstation")),
1523 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1524 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1525 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1527 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1528 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1529 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1531 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1532 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1533 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1535 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1536 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1538 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1539 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1540 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1542 /* Add opsi client to system types */
1543 if($this->opsi != NULL){
1544 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1545 }
1547 /* Use locked icons
1548 */
1549 if( in_array($input['type'],array("S","T","L")) &&
1550 isset($input['gotoMode'][0]) &&
1551 preg_match("/locked/",$input['gotoMode'][0])){
1552 $input['type'].="X";
1553 } elseif(in_array($input['type'],array("S","L")) &&
1554 isset($input['FAIstate'][0])){
1556 /* Add FAI state icons
1557 */
1558 $type= "";
1559 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1560 case 'error':
1561 $type= 'E';
1562 break;
1563 case 'installing':
1564 case 'install':
1565 case 'sysinfo':
1566 case 'softupdate':
1567 case 'scheduledupdate':
1568 $type= 'B';
1569 break;
1570 }
1572 $input['type'].= $type;
1573 }
1575 /* Use new images if object is from incoming
1576 */
1577 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1578 $input['type']="N".$input['type'];
1579 }
1581 /* Check which flags this objects uses
1582 */
1583 foreach ($conv as $key => $value){
1584 $found = TRUE;
1585 if(strlen($key) != strlen($input['type'])) {
1586 $found = FALSE;
1587 }
1588 for($i = 0 ; $i < strlen($key) ; $i++){
1589 if(!preg_match("/".$key[$i]."/",$input['type'])){
1590 $found = FALSE;
1591 }
1592 }
1594 if($found){
1595 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1596 $tmp['class']=$key;
1597 return $tmp;
1598 }
1599 }
1600 }
1603 function list_get_selected_items()
1604 {
1605 $ids = array();
1606 foreach($_POST as $name => $value){
1607 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1608 $id = preg_replace("/^item_selected_/","",$name);
1609 $ids[$id] = $id;
1610 }
1611 }
1612 return($ids);
1613 }
1616 public function get_tab_defs()
1617 {
1618 $tabs = array(
1619 "incoming" => array(
1620 "CLASS" => "",
1621 "TABNAME" => "",
1622 "TABCLASS" => "",
1623 "ACLC" => "incoming",
1624 "ACL" => "incoming/systems"),
1626 "ArpNewDevice"=> array(
1627 "CLASS" => "TERMTABS",
1628 "TABNAME" => "termgeneric" ,
1629 "TABCLASS" => "termtabs",
1630 "ACLC" => "incoming",
1631 "ACL" => "incoming/systems"),
1633 "NewDevice" => array(
1634 "CLASS" => "TERMTABS",
1635 "TABNAME" => "termgeneric",
1636 "TABCLASS" => "termtabs",
1637 "ACLC" => "incoming",
1638 "ACL" => "incoming/systems"),
1640 "terminal" => array(
1641 "CLASS" => "TERMTABS",
1642 "TABNAME" => "termgeneric",
1643 "TABCLASS" => "termtabs",
1644 "ACLC" => "terminal",
1645 "ACL" => "terminal/termgeneric"),
1647 "workstation" => array(
1648 "CLASS" => "WORKTABS",
1649 "TABNAME" => "workgeneric",
1650 "TABCLASS"=> "worktabs",
1651 "ACLC" => "workstation",
1652 "ACL" => "workstation/workgeneric" ),
1654 "server" => array(
1655 "CLASS" => "SERVTABS",
1656 "TABNAME" => "servgeneric",
1657 "TABCLASS"=> "servtabs",
1658 "ACLC" => "server",
1659 "ACL" => "server/servgeneric"),
1661 "printer" => array(
1662 "CLASS" => "PRINTTABS",
1663 "TABNAME" => "printgeneric",
1664 "TABCLASS"=> "printtabs",
1665 "ACLC" => "printer",
1666 "ACL" => "printer/printgeneric"),
1668 "phone" => array(
1669 "CLASS" => "PHONETABS",
1670 "TABNAME" => "phoneGeneric",
1671 "TABCLASS"=> "phonetabs",
1672 "ACLC" => "phone",
1673 "ACL" => "phone/phoneGeneric"),
1675 "winstation" => array(
1676 "CLASS" => "WINTABS",
1677 "TABNAME" => "wingeneric",
1678 "TABCLASS"=> "wintabs",
1679 "ACLC" => "winworkstation",
1680 "ACL" => "winworkstation/wingeneric"),
1682 "component" => array(
1683 "CLASS" => "COMPONENTTABS",
1684 "TABNAME" => "componentGeneric",
1685 "TABCLASS"=> "componenttabs",
1686 "ACLC" => "component",
1687 "ACL" => "component/componentGeneric"));
1689 if($this->opsi != NULL){
1690 $tabs["opsi_client"] = array(
1691 "CLASS" => "OPSITABS",
1692 "TABNAME" => "opsiGeneric" ,
1693 "TABCLASS"=> "opsi_tabs",
1694 "ACLC" => "opsi" ,
1695 "ACL" => "opsi/opsiGeneric");
1696 }
1698 return($tabs);
1699 }
1703 /* !! Incoming dummy acls, required to defined acls for incoming objects
1704 */
1705 static function plInfo()
1706 {
1707 return (array(
1708 "plShortName" => _("Incoming objects"),
1709 "plDescription" => _("Incoming objects"),
1710 "plSelfModify" => FALSE,
1711 "plDepends" => array(),
1712 "plPriority" => 99,
1713 "plSection" => array("administration"),
1714 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1715 "objectClass" => "")),
1716 "plProvidedAcls"=> array()
1718 ));
1719 }
1720 }
1722 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1723 ?>