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