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.");
1013 }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
1014 $this->activate_new_device($this->systab->dn);
1015 }
1017 /* Terminal has been saved successfully, remove lock from LDAP. */
1018 if (!isset($_POST['edit_apply'])){
1019 if ($this->dn != "new"){
1020 $this->remove_lock();
1021 }
1023 unset ($this->systab);
1024 $this->systab= NULL;
1025 set_object_info();
1026 }else{
1028 /* Reinitialize tab */
1029 if($this->systab instanceof tabs){
1030 $this->systab->re_init();
1031 }
1032 }
1033 } else {
1034 /* Ok. There seem to be errors regarding to the tab data,
1035 show message and continue as usual. */
1036 msg_dialog::displayChecks($message);
1037 }
1038 }
1041 /********************
1042 Edit system was canceled
1043 ********************/
1044 /* Cancel dialogs */
1045 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1046 if (isset($this->systab)){
1047 $this->remove_lock();
1048 unset ($this->systab);
1049 }
1050 $this->systab= NULL;
1051 set_object_info();
1052 }
1054 /********************
1055 Display edit dialog, or some other
1056 ********************/
1058 /* Show tab dialog if object is present */
1059 if (isset($this->systab->config)){
1061 if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
1062 $this->systab->save_object();
1063 }
1065 $display= $this->systab->execute();
1067 /* Don't show buttons if tab dialog requests this */
1069 $dialog = FALSE;
1070 $hide_apply = $this->dn == "new";
1071 $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
1072 if(is_object($this->systab) && !isset($this->systab->by_object)){
1073 $dialog = TRUE;
1074 $hide_apply = TRUE;
1075 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1076 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1077 if($dia === TRUE || is_object($dia)){
1078 $dialog = TRUE;
1079 }
1080 }
1081 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1082 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1083 $dialog = TRUE;
1084 }
1086 if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
1087 $display.= "<p style=\"text-align:right\">
1088 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1089 </p>";
1090 }elseif (!$dialog){
1091 $display.= "<p style=\"text-align:right\">\n";
1092 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1093 $display.= " \n";
1094 if (!$hide_apply){
1095 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1096 $display.= " \n";
1097 }
1098 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1099 $display.= "</p>";
1100 }
1101 return ($display);
1102 }
1104 /* Check if there is a snapshot dialog open */
1105 $base = $this->DivListSystem->selectedBase;
1106 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1107 return($str);
1108 }
1110 /* Display dialog with system list */
1111 $this->DivListSystem->parent = $this;
1112 $this->DivListSystem->execute();
1114 /* Add departments if subsearch is disabled */
1115 if(!$this->DivListSystem->SubSearch){
1117 /* Add FAIstate to attributes if FAI is activated */
1118 if($this->fai_activated){
1119 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1120 }else{
1121 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1122 }
1123 }
1124 $this->reload();
1125 $this->DivListSystem->setEntries($this->terminals);
1126 return($this->DivListSystem->Draw());
1127 }
1130 /* Return departments, that will be included within snapshot detection */
1131 function get_used_snapshot_bases()
1132 {
1133 $tmp = array();
1135 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1137 $tabs = array(
1138 "terminal" => get_ou('terminalRDN'),
1139 "workstation" => get_ou('workstationRDN'),
1140 "incoming" => get_ou('systemIncomingRDN'),
1141 "server" => get_ou('serverRDN'),
1142 "printer" => get_ou('printerRDN'),
1143 "phone" => get_ou('phoneRDN'),
1144 "winworkstation" => get_winstations_ou(),
1145 "component" => get_ou('componentRDN')
1146 );
1148 foreach($tabs as $acl_cat => $dn){
1150 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1151 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1152 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1153 }
1154 }
1155 return($tmp);
1156 }
1159 function remove_from_parent()
1160 {
1161 /* Optionally execute a command after we're done */
1162 $this->postremove();
1163 }
1166 /* Save data to object */
1167 function save_object()
1168 {
1169 $this->DivListSystem->save_object();
1170 if(is_object($this->CopyPasteHandler)){
1171 $this->CopyPasteHandler->save_object();
1172 }
1173 }
1176 /* Check values */
1177 function check()
1178 {
1179 }
1182 /* Save to LDAP */
1183 function save()
1184 {
1185 }
1187 function adapt_from_template($dn, $skip= array())
1188 {
1189 }
1191 function password_change_needed()
1192 {
1193 }
1195 function reload()
1196 {
1197 /* some var init */
1198 $ui = get_userinfo();
1199 $res = array();
1200 $this->terminals = array();
1201 $userregex = "";
1202 $opsi_clients = array();
1204 /* Set base for all searches */
1205 $base= $this->DivListSystem->selectedBase;
1207 /* Prepare samba class name */
1208 $samba ="";
1209 if ($this->DivListSystem->ShowWinWorkstations){
1210 if ($this->config->get_cfg_value("sambaversion") == "3"){
1211 $samba= "sambaSamAccount";
1212 } else {
1213 $samba= "sambaAccount";
1214 }
1215 }
1217 /* This array represents the combination between checkboxes and search filters */
1218 $objs = array(
1219 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverRDN')),
1220 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalRDN')),
1221 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerRDN')),
1222 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentRDN')),
1223 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneRDN')),
1224 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationRDN')),
1225 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1227 /* Include the 'Display Systems of user' attribute */
1228 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1229 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1230 }
1232 /* Attributes to fetch */
1233 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1234 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming","winworkstation","component");
1236 /* Add FAIstate to attributes if FAI is activated */
1237 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1238 if(!empty($tmp)){
1239 $sys_attrs[] = "FAIstate";
1240 }
1242 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1243 foreach($objs as $checkBox => $oc){
1245 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1246 if($this->DivListSystem->SubSearch){
1247 if($oc['CLASS'] != ""){
1248 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1249 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1250 $res = array_merge($res,$new_res);
1251 }
1252 }else{
1253 /* User filter? */
1254 if($oc['CLASS'] != ""){
1255 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1256 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1257 }
1258 }
1259 }
1260 }
1262 /* Search for incoming objects */
1263 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1264 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('systemIncomingRDN').$base,$sys_attrs, GL_SIZELIMIT));
1266 /* Append opsi systems, the opsi extension have to installed.
1267 (Only, if we are allowed to view opsi hosts)
1268 */
1269 if($this->opsi instanceof opsi && $this->opsi->enabled() && $this->DivListSystem->ShowOpsiHosts){
1270 $o_acl = $this->ui->get_permissions($base,"opsi/opsiGeneric","");
1271 if(preg_match("/r/",$o_acl)){
1272 $opsi_clients = $this->opsi->get_hosts_for_system_management();
1273 if($this->opsi->is_error()){
1274 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1275 }
1276 }
1277 }
1279 /* Get all gotoTerminal's */
1280 $t_id = 0;
1281 $opsi_map = array();
1282 foreach ($res as $value){
1284 $tmp= $value['dn'];
1285 $add= "";
1287 /* Extract base */
1288 foreach($objs as $obj){
1289 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1290 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1291 }
1292 }
1294 /* Create a string containing the last part of the department. */
1295 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
1296 if(empty($dn_name)){
1297 $dn_name = "/";
1298 }
1300 /* check if current object is a new one */
1301 if (preg_match ("/,".get_ou('systemIncomingRDN')."/i", $tmp)){
1302 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1303 $add= "- "._("New terminal");
1304 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1305 $add= "- "._("New workstation");
1306 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1307 $add= "- "._("Unknown device");
1308 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1309 $add= "- "._("New Device");
1310 }
1311 }
1313 /* Detect type of object and create an entry for $this->terminals */
1314 $terminal = array();
1316 if (0 && in_array_ics('gosa_opsi_client', $value["objectClass"])){
1318 /* check acl */
1319 $terminal = $value;
1320 $terminal['type'] = "O";
1322 } elseif (in_array_ics('gotoTerminal', $value["objectClass"])){
1324 /* check acl */
1325 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1326 if($add != "" || preg_match("/r/",$acl)) {
1327 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1328 $terminal = $value;
1329 $terminal['type'] = "T";
1330 $terminal['is_new'] = $add;
1331 } else {
1332 $terminal = $value;
1333 $terminal['type'] = "D";
1334 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1335 $terminal['location'] = array_search($tmp, $this->config->departments);
1336 }
1337 }
1338 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1340 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1341 if($add != "" || preg_match("/r/",$acl)) {
1342 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1343 $terminal = $value;
1344 $terminal['type'] = "L";
1345 $terminal['is_new'] = $add;
1346 } else {
1347 $terminal = $value;
1348 $terminal['type'] = "D";
1349 $terminal['location'] = array_search($tmp, $this->config->departments);
1350 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1351 }
1352 # if (isset($value["FAIstate"][0])){
1353 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1354 # }
1355 }
1356 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1359 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1360 if($add != "" || preg_match("/r/",$acl)) {
1362 $terminal = $value;
1363 $terminal['type'] = "P";
1364 }
1365 } elseif (in_array_ics('goServer', $value["objectClass"])){
1367 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1368 if($add != "" || preg_match("/r/",$acl)) {
1370 $terminal = $value;
1371 $terminal['type'] = "S";
1372 # if (isset($value["FAIstate"][0])){
1373 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1374 # }
1375 }
1376 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1378 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1379 if($add != "" || preg_match("/r/",$acl)) {
1381 $terminal = $value;
1382 $terminal['type'] = "F";
1383 }
1384 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1386 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1387 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1388 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1389 if($add != "" || preg_match("/r/",$acl)) {
1391 $terminal = $value;
1392 $terminal['type'] = "Q";
1393 $terminal['is_new'] = $add;
1394 }
1395 } elseif (in_array_ics('ieee802Device', $value["objectClass"]) &&
1396 !( in_array_ics('sambaAccount', $value["objectClass"]) || in_array_ics('sambaSamAccount', $value["objectClass"]))){
1397 $type= "winstation";
1398 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1399 if($add != "" || preg_match("/r/",$acl)) {
1401 $terminal = $value;
1402 $terminal['type'] = "C";
1403 }
1404 } else{
1406 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1407 if (isset($value['sambaDomainName'])){
1408 $domain= " [".$value['sambaDomainName'][0]."]";
1409 } else {
1410 $domain= "";
1411 }
1412 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1413 if($add != "" || preg_match("/r/",$acl)) {
1414 $terminal=$value;
1415 $terminal['type'] ="W";
1416 $terminal['domain'] = $name.$domain;
1417 }
1418 }
1420 /* Append collected data to the host list.
1421 */
1422 if(count($terminal)){
1423 $t_id ++ ;
1424 $this->terminals[$t_id]=$terminal;
1425 $opsi_map[preg_replace('/\$$/',"",$value['cn'][0])] = $t_id;
1426 }
1427 }
1430 /* Merge real hosts with opsi hosts.
1431 If there is a samba host, then merge it with the opsi host,
1432 to avoid duplicate entries.
1433 */
1434 foreach($opsi_clients as $entry){
1435 if(isset($opsi_map[$entry['cn'][0]])){
1436 continue;
1437 }
1438 $terminal = $entry;
1439 $terminal['type'] = "O";
1440 $this->terminals[] = $terminal;
1441 }
1443 $tmp =array();
1444 $tmp2 =array();
1445 foreach($this->terminals as $tkey => $val ){
1446 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1447 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1448 }
1449 natcasesort($tmp2);
1450 $this->terminals=array();
1451 foreach($tmp2 as $val){
1452 $this->terminals[]=$tmp[$val];
1453 }
1454 reset ($this->terminals);
1455 }
1457 function remove_lock()
1458 {
1459 if (isset($this->systab->dn)){
1460 del_lock ($this->systab->dn);
1461 }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1462 del_lock($this->dn);
1463 }
1464 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1465 del_lock($this->dns);
1466 }
1467 }
1470 function copyPasteHandling_from_queue($s_action,$s_entry)
1471 {
1472 /* Check if Copy & Paste is disabled */
1473 if(!is_object($this->CopyPasteHandler)){
1474 return("");
1475 }
1477 $ui = get_userinfo();
1479 $tabs = $this->get_tab_defs();
1481 /* Add a single entry to queue */
1482 if($s_action == "cut" || $s_action == "copy"){
1484 /* Cleanup object queue */
1485 $this->CopyPasteHandler->cleanup_queue();
1486 $dn = $this->terminals[$s_entry]['dn'];
1487 $oc = $this->terminals[$s_entry]['objectClass'];
1488 $type = $this->get_system_type($this->terminals[$s_entry]);
1490 $tab_o = $tabs[$type]['CLASS'];
1491 $tab_c = $tabs[$type]['TABCLASS'];
1492 $acl_c = $tabs[$type]['TABNAME'];
1493 $acl = $tabs[$type]['ACLC'];
1495 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1496 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1497 }
1498 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1499 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1500 }
1501 }
1503 /* Add entries to queue */
1504 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1506 /* Cleanup object queue */
1507 $this->CopyPasteHandler->cleanup_queue();
1509 /* Add new entries to CP queue */
1510 foreach($this->list_get_selected_items() as $id){
1511 $dn = $this->terminals[$id]['dn'];
1512 $oc = $this->terminals[$id]['objectClass'];
1513 $type = $this->get_system_type($this->terminals[$id]);
1515 if(isset($tabs[$type])){
1516 $tab_o = $tabs[$type]['CLASS'];
1517 $tab_c = $tabs[$type]['TABCLASS'];
1518 $acl_c = $tabs[$type]['TABNAME'];
1519 $acl = $tabs[$type]['ACLC'];
1521 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1522 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1523 }
1524 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1525 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1526 }
1527 }
1528 }
1529 }
1531 /* Start pasting entries */
1532 if($s_action == "editPaste"){
1533 $this->start_pasting_copied_objects = TRUE;
1534 }
1536 /* Return C&P dialog */
1537 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1539 /* Get dialog */
1540 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1541 $data = $this->CopyPasteHandler->execute();
1543 /* Return dialog data */
1544 if(!empty($data)){
1545 return($data);
1546 }
1547 }
1549 /* Automatically disable status for pasting */
1550 if(!$this->CopyPasteHandler->entries_queued()){
1551 $this->start_pasting_copied_objects = FALSE;
1552 }
1553 return("");
1554 }
1557 function get_system_type($attrs)
1558 {
1559 $classes = $attrs['objectClass'];
1561 $type= "";
1562 if (in_array_ics('gosa_opsi_client', $classes)){
1563 $type= "opsi_client";
1564 }elseif (in_array_ics('sambaAccount', $classes) ||
1565 in_array_ics('sambaSamAccount', $classes)){
1566 $type= "winstation";
1567 }elseif (in_array_ics('ieee802Device', $classes)){
1568 $type= "component";
1569 }elseif (in_array_ics('gotoTerminal', $classes)){
1570 $type= "terminal";
1571 }elseif (in_array_ics('gotoWorkstation', $classes)){
1572 $type= "workstation";
1573 }elseif (in_array_ics('gotoPrinter', $classes)){
1574 $type= "printer";
1575 }elseif (in_array_ics('goFonHardware', $classes)){
1576 $type= "phone";
1577 }elseif (in_array_ics('goServer', $classes)){
1578 $type= "server";
1579 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1580 $type= "ArpNewDevice";
1581 }elseif (in_array_ics('GOhard', $classes)){
1582 $type= "NewDevice";
1583 }
1584 return ($type);
1585 }
1588 function convert_list($input)
1589 {
1590 $temp= "";
1592 $conv= array(
1593 "D" => array("plugins/systems/images/select_default.png",_("Template")),
1594 "F" => array("plugins/systems/images/select_phone.png",_("Phone")),
1595 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1596 "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
1598 "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
1600 "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
1601 "S" => array("plugins/systems/images/select_server.png",_("Server")),
1602 "T" => array("plugins/systems/images/select_terminal.png",_("Terminal")),
1604 "LX" => array("plugins/systems/images/workstation_locked.png",_("Locked workstation")),
1605 "SX" => array("plugins/systems/images/server_locked.png",_("Locked server")),
1606 "TX" => array("plugins/systems/images/terminal_locked.png",_("Locked terminal")),
1608 "LE" => array("plugins/systems/images/workstation_error.png",_("Workstation error")),
1609 "SE" => array("plugins/systems/images/server_error.png",_("Server error")),
1610 "TE" => array("plugins/systems/images/terminal_error.png",_("Terminal error")),
1612 "LB" => array("plugins/systems/images/workstation_busy.png",_("Workstation busy")),
1613 "SB" => array("plugins/systems/images/server_busy.png",_("Server busy")),
1615 "NQ" => array("plugins/systems/images/select_newsystem.png",_("New system from incoming")),
1616 "NT" => array("plugins/systems/images/select_new_terminal.png",_("New terminal")),
1617 "NL" => array("plugins/systems/images/select_new_workstation.png",_("New workstation")));
1619 /* Add opsi client to system types */
1620 if($this->opsi != NULL){
1621 $conv["O"] = array("plugins/systems/images/select_winstation.png",_("Opsi client"));
1622 }
1624 /* Use locked icons
1625 */
1626 if( in_array($input['type'],array("S","T","L")) &&
1627 isset($input['gotoMode'][0]) &&
1628 preg_match("/locked/",$input['gotoMode'][0])){
1629 $input['type'].="X";
1630 } elseif(in_array($input['type'],array("S","L")) &&
1631 isset($input['FAIstate'][0])){
1633 /* Add FAI state icons
1634 */
1635 $type= "";
1636 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1637 case 'error':
1638 $type= 'E';
1639 break;
1640 case 'installing':
1641 case 'install':
1642 case 'sysinfo':
1643 case 'softupdate':
1644 case 'scheduledupdate':
1645 $type= 'B';
1646 break;
1647 }
1649 $input['type'].= $type;
1650 }
1652 /* Use new images if object is from incoming
1653 */
1654 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1655 $input['type']="N".$input['type'];
1656 }
1658 /* Check which flags this objects uses
1659 */
1660 foreach ($conv as $key => $value){
1661 $found = TRUE;
1662 if(strlen($key) != strlen($input['type'])) {
1663 $found = FALSE;
1664 }
1665 for($i = 0 ; $i < strlen($key) ; $i++){
1666 if(!preg_match("/".$key[$i]."/",$input['type'])){
1667 $found = FALSE;
1668 }
1669 }
1671 if($found){
1672 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1673 $tmp['class']=$key;
1674 return $tmp;
1675 }
1676 }
1677 }
1680 function list_get_selected_items()
1681 {
1682 $ids = array();
1683 foreach($_POST as $name => $value){
1684 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1685 $id = preg_replace("/^item_selected_/","",$name);
1686 $ids[$id] = $id;
1687 }
1688 }
1689 return($ids);
1690 }
1693 public function get_tab_defs()
1694 {
1695 $tabs = array(
1696 "incoming" => array(
1697 "CLASS" => "",
1698 "TABNAME" => "",
1699 "TABCLASS" => "",
1700 "ACLC" => "incoming",
1701 "ACL" => "incoming/systems"),
1703 "ArpNewDevice"=> array(
1704 "CLASS" => "TERMTABS",
1705 "TABNAME" => "termgeneric" ,
1706 "TABCLASS" => "termtabs",
1707 "ACLC" => "incoming",
1708 "ACL" => "incoming/systems"),
1710 "NewDevice" => array(
1711 "CLASS" => "TERMTABS",
1712 "TABNAME" => "termgeneric",
1713 "TABCLASS" => "termtabs",
1714 "ACLC" => "incoming",
1715 "ACL" => "incoming/systems"),
1717 "terminal" => array(
1718 "CLASS" => "TERMTABS",
1719 "TABNAME" => "termgeneric",
1720 "TABCLASS" => "termtabs",
1721 "ACLC" => "terminal",
1722 "ACL" => "terminal/termgeneric"),
1724 "workstation" => array(
1725 "CLASS" => "WORKTABS",
1726 "TABNAME" => "workgeneric",
1727 "TABCLASS"=> "worktabs",
1728 "ACLC" => "workstation",
1729 "ACL" => "workstation/workgeneric" ),
1731 "server" => array(
1732 "CLASS" => "SERVTABS",
1733 "TABNAME" => "servgeneric",
1734 "TABCLASS"=> "servtabs",
1735 "ACLC" => "server",
1736 "ACL" => "server/servgeneric"),
1738 "printer" => array(
1739 "CLASS" => "PRINTTABS",
1740 "TABNAME" => "printgeneric",
1741 "TABCLASS"=> "printtabs",
1742 "ACLC" => "printer",
1743 "ACL" => "printer/printgeneric"),
1745 "phone" => array(
1746 "CLASS" => "PHONETABS",
1747 "TABNAME" => "phoneGeneric",
1748 "TABCLASS"=> "phonetabs",
1749 "ACLC" => "phone",
1750 "ACL" => "phone/phoneGeneric"),
1752 "winstation" => array(
1753 "CLASS" => "WINTABS",
1754 "TABNAME" => "wingeneric",
1755 "TABCLASS"=> "wintabs",
1756 "ACLC" => "winworkstation",
1757 "ACL" => "winworkstation/wingeneric"),
1759 "component" => array(
1760 "CLASS" => "COMPONENTTABS",
1761 "TABNAME" => "componentGeneric",
1762 "TABCLASS"=> "componenttabs",
1763 "ACLC" => "component",
1764 "ACL" => "component/componentGeneric"));
1766 if($this->opsi != NULL){
1767 $tabs["opsi_client"] = array(
1768 "CLASS" => "OPSITABS",
1769 "TABNAME" => "opsiGeneric" ,
1770 "TABCLASS"=> "opsi_tabs",
1771 "ACLC" => "opsi" ,
1772 "ACL" => "opsi/opsiGeneric");
1773 }
1775 return($tabs);
1776 }
1779 /*! \brief Sets FAIstate to "install" for "New Devices".
1780 This function is some kind of "Post handler" for activated systems,
1781 it is called directly after the object (workstabs,servtabs) gets saved.
1782 @param String $dn The dn of the newly activated object.
1783 @return Boolean TRUE if activated else FALSE
1784 */
1785 function activate_new_device($dn)
1786 {
1787 $ldap = $this->config->get_ldap_link();
1788 $ldap->cd($this->config->current['BASE']);
1789 $ldap->cat($dn);
1790 if($ldap->count()){
1791 $attrs = $ldap->fetch();
1792 $type = $this->get_system_type($attrs);
1793 if(!in_array($type,array("workstation","server"))) {
1794 $ocs = $attrs['objectClass'];
1795 unset($ocs['count']);
1796 $new_attrs = array();
1797 if(!in_array("FAIobject",$ocs)){
1798 $ocs[] = "FAIobject";
1799 $new_attrs['objectClass'] = $ocs;
1800 }
1801 $new_attrs['FAIstate'] = "install";
1802 $ldap->cd($dn);
1803 $ldap->modify($new_attrs);
1804 if (!$ldap->success()){
1805 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1806 LDAP_MOD, "activate_new_device($dn)"));
1807 }else{
1808 return(TRUE);
1809 }
1810 }
1811 }
1812 return(FALSE);
1813 }
1816 /* !! Incoming dummy acls, required to defined acls for incoming objects
1817 */
1818 static function plInfo()
1819 {
1820 return (array(
1821 "plShortName" => _("Incoming objects"),
1822 "plDescription" => _("Incoming objects"),
1823 "plSelfModify" => FALSE,
1824 "plDepends" => array(),
1825 "plPriority" => 99,
1826 "plSection" => array("administration"),
1827 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1828 "objectClass" => "")),
1829 "plProvidedAcls"=> array()
1831 ));
1832 }
1833 }
1835 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1836 ?>