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 $departments = array();
30 /* Dialog attributes */
31 var $systab = NULL;
32 var $terminals= array();
33 var $ui = NULL;
34 var $DivListSystem;
35 var $start_pasting_copied_objects = FALSE;
36 var $CopyPasteHandler = NULL;
38 /* Arp hanlding activated */
39 var $arp_handling_active = FALSE;
40 var $last_action = "";
42 var $dns = array();
44 var $system_activation_object = ""; // The object to activate (NewDevice)
45 var $fai_activated = FALSE;
47 var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
49 function systems (&$config, $ui)
50 {
51 /* Save configuration for internal use */
52 $this->config= $config;
53 $this->ui= $ui;
55 /* Add FAIstate to attributes if FAI is activated */
56 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
57 if(!empty($tmp)){
58 $this->fai_activated = TRUE;
59 }
61 /* Creat dialog object */
62 $this->DivListSystem = new divListSystem($this->config,$this);
64 /* Copy & Paste enabled ?*/
65 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
66 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
67 }
69 /* Check whether the arp handling active or not */
70 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
71 $this->arp_handling_active = TRUE;
72 }
73 }
76 function execute()
77 {
78 /* Call parent execute */
79 plugin::execute();
81 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
83 /********************
84 Check for functional posts, edit|delete|add|... system devices
85 ********************/
86 $s_action = ""; // Contains the action to proceed
87 $s_entry = ""; // The value for s_action
88 $base_back = ""; // The Link for Backbutton
89 $smarty = get_smarty();
91 /* Test Posts */
92 foreach($_POST as $key => $val){
93 // Post for delete
94 if(preg_match("/system_del.*/",$key)){
95 $s_action = "del";
96 $s_entry = preg_replace("/system_del_/i","",$key);
97 // Post for edit
98 }elseif(preg_match("/system_edit_.*/",$key)){
99 $s_action="edit";
100 $s_entry = preg_replace("/system_edit_/i","",$key);
101 // Post for new
102 }elseif(preg_match("/system_new.*/",$key)){
103 $s_action="new";
104 }elseif(preg_match("/system_tplnew.*/i",$key)){
105 $s_action="new_tpl";
106 }elseif(preg_match("/system_setpwd_.*/i",$key)){
107 $s_action="change_pw";
108 $s_entry = preg_replace("/system_setpwd_/i","",$key);
109 }elseif(preg_match("/gen_cd_.*/i",$key)){
110 $s_action="gen_cd";
111 $s_entry = preg_replace("/gen_cd_/i","",$key);
112 }elseif(preg_match("/^copy_.*/",$key)){
113 $s_action="copy";
114 $s_entry = preg_replace("/^copy_/i","",$key);
115 }elseif(preg_match("/^cut_.*/",$key)){
116 $s_action="cut";
117 $s_entry = preg_replace("/^cut_/i","",$key);
118 }
119 }
121 /* remove image tags from posted entry (posts looks like this 'name_x')*/
122 $s_entry = preg_replace("/_.$/","",$s_entry);
124 /* Edit was requested by pressing the name(link) of an item */
125 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
126 $s_action ="edit";
127 $s_entry = $_GET['id'];
128 }
129 /* Create options */
130 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
131 $s_action = "newsystem";
132 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
133 }
135 /* handle C&P from layers menu */
136 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
137 $s_action = "copy_multiple";
138 }
139 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
140 $s_action = "cut_multiple";
141 }
142 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
143 $s_action = "editPaste";
144 }
146 /* Handle daemon events */
147 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
148 $s_action = $_POST['menu_action'];
149 }
151 /* Handle daemon events */
152 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
153 $s_action = $_POST['menu_action'];
154 }
156 /* handle remove from layers menu */
157 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
158 $s_action = "del_multiple";
159 }
161 /* Handle instant actions from layers menu */
162 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
163 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
164 $s_action = "${act}_multiple";
165 }
166 }
168 /* Activate multiple machines */
169 if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
170 $s_action = "activate_multiple";
171 }
173 /* Check for exeeded sizelimit */
174 if (($message= check_sizelimit()) != ""){
175 return($message);
176 }
178 /* Try to get informations about what kind of system to create */
179 if ($s_action=="new") {
180 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
181 }
183 /* Incoming handling
184 * If someone made a systemtype and ogroup selection
185 * Display the new requested entry type ... servtab in case of server and so on.
186 */
187 if(isset($_POST['SystemTypeChoosen'])){
188 $s_action = "SelectedSystemType";
189 }
191 /********************
192 Copy & Paste Handling ...
193 ********************/
195 /* Display the copy & paste dialog, if it is currently open */
196 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
197 if($ret){
198 return($ret);
199 }
202 /********************
203 Create FAI CD ...
204 ********************/
205 if ($s_action=="gen_cd"){
206 $this->dn= $this->terminals[$s_entry]['dn'];
207 session::set('objectinfo',$this->dn);
208 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
209 }
212 /* Start CD-Creation */
213 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
214 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
215 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
216 }
219 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
221 $return_button = "<form method='get' action='main.php' target='_parent'>
222 <input type='submit' value='"._("Back")."'>
223 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
224 </form>";
226 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
228 /* Get and check command */
229 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
231 if (check_command($command)){
232 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
234 /* Print out html introduction */
235 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
236 <html>
237 <head>
238 <title></title>
239 <style type="text/css">@import url("themes/default/style.css");</style>
240 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
241 </head>
242 <body style="background: none; margin:4px;" id="body" >
243 <pre>';
245 /* Open process handle and check if it is a valid process */
246 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
247 if (is_resource($process)) {
248 fclose($pipes[0]);
250 /* Print out returned lines && write JS to scroll down each line */
251 while (!feof($pipes[1])){
252 $cur_dat = fgets($pipes[1], 1024);
253 echo $cur_dat;
254 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
255 flush();
256 }
257 }
259 /* Get error string && close streams */
260 $buffer= stream_get_contents($pipes[2]);
262 fclose($pipes[1]);
263 fclose($pipes[2]);
264 echo "</pre>";
266 /* Check return code */
267 $ret= proc_close($process);
268 if ($ret != 0){
269 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
270 echo "<pre style='color:red'>$buffer</pre>";
271 }
275 echo $return_button."<br>";
277 } else {
278 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
279 echo $tmp;
280 }
282 /* Scroll down completly */
283 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
284 echo '</body></html>';
285 flush();
286 exit;
287 }
290 /********************
291 New Device hanlding (Ogroup/System select dialog.)
292 ********************/
294 if($s_action == "SelectedSystemType"){
296 /* Possible destination system types
297 */
298 $tabs = array(
299 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric",
300 "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
301 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric",
302 "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
303 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric",
304 "TABCLASS" =>"servtabs", "ACL"=> "server"));
306 /* Remember dialog selection.
307 */
308 $selected_group = $_POST['ObjectGroup'];
309 $selected_system = $_POST['SystemType'];
311 $this->systab = NULL;
313 /* Check if system type exists. It should! */
314 if(isset($tabs[$selected_system])){
316 /* Get tab informations */
317 $class = $tabs[$selected_system]["CLASS"];
318 $tabname = $tabs[$selected_system]["TABNAME"];
319 $tabclass = $tabs[$selected_system]["TABCLASS"];
320 $acl_cat = $tabs[$selected_system]["ACL"];
322 /* Go through all objects that should be activated */
323 foreach($this->system_activation_object as $key => $dn){
325 /* Remove entry from list, to avoid page-reload problems */
326 unset($this->system_activation_object[$key]);
328 /* Load permissions for selected 'dn' and check if
329 we're allowed to create this 'dn' */
330 $this->dn = $dn;
331 $ui = get_userinfo();
332 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
334 /* We are allowed to create the requested system type */
335 if(preg_match("/c/",$tabacl)){
336 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
337 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
338 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
339 $this->systab->base = $this->DivListSystem->selectedBase;
342 if($selected_group != "none"){
344 /*******
345 * Set gotoMode to active if we there was an ogroup selected.
346 */
347 $found = false;
348 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
349 if(isset($this->systab->by_object[$tab]->gotoMode)) {
350 $found = true;
351 $this->systab->by_object[$tab]->gotoMode = $value;
352 }
353 }
354 if(!$found){
355 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
356 }
358 /*******
359 * Update object group membership
360 */
361 $og = new ogroup($this->config,$selected_group);
362 if($og){
363 $og->AddDelMembership($this->systab->dn);
364 $og->save();
365 }
367 /*******
368 * Set default system specific attributes
369 */
370 foreach (array("workservice", "termservice") as $cls){
371 if (isset($this->systab->by_object[$cls])){
372 $this->systab->by_object[$cls]->gotoXMouseport= "";
373 $this->systab->by_object[$cls]->gotoXMouseType= "";
374 $this->systab->by_object[$cls]->gotoXResolution= "";
375 $this->systab->by_object[$cls]->gotoXColordepth= "";
376 }
377 }
379 // Enable activation
380 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
381 if (isset($this->systab->by_object[$cls])){
382 $this->systab->by_object[$cls]->auto_activate= TRUE;
383 }
384 }
386 // Enable sending of LDAP events
387 if (isset($this->systab->by_object["workstartup"])){
388 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
389 }
390 }
392 /* Don't save directly if there is no objectGroup selected.
393 The user will then be able to configure the missing attributes
394 on his own.
395 */
396 if($selected_group != "none"){
397 $this->systab->save();
398 $this->systab = NULL;
400 if(!isset($ldap)){
401 $ldap = $this->config->get_ldap_link();
402 }
403 $ldap->cd ($this->dn);
404 $ldap->cat($this->dn, array('dn'));
405 if(count($ldap->fetch())){
406 $ldap->cd($this->dn);
407 $ldap->rmDir($this->dn);
408 }
409 }
410 }else{
411 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
412 }
413 }
414 }
415 }
418 if (isset($_POST['create_system'])||$s_action=="newsystem") {
420 /* If the current entry is an incoming object
421 * $sw = System type as posted in new incoming handling dialog
422 */
423 if(isset($_POST['system'])){
424 $sw = $_POST['system'];
425 }else{
426 $sw = $s_entry;
427 }
428 $this->dn= "new";
430 $tabs = array(
431 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
432 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
433 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
434 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
435 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
436 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
438 if(isset($tabs[$sw])){
439 $class = $tabs[$sw]["CLASS"];
440 $tabname = $tabs[$sw]["TABNAME"];
441 $tabclass = $tabs[$sw]["TABCLASS"];
442 $acl_cat = $tabs[$sw]["ACL"];
444 /* Load permissions for selected 'dn' and check if
445 we're allowed to remove this 'dn' */
446 $ui = get_userinfo();
447 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
448 if(preg_match("/c/",$tabacl)){
449 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
450 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
451 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
452 $this->systab->base = $this->DivListSystem->selectedBase;
453 }else{
454 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
455 }
456 }
457 }
460 /********************
461 System activation
462 ********************/
464 /* User wants to edit data? */
465 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
466 $this->system_activation_object = array();
467 foreach($this->list_get_selected_items() as $id) {
468 $obj = $this->terminals[$id];
469 $type= $this->get_system_type($obj);
470 if($type == "NewDevice"){
471 $this->system_activation_object[] = $obj['dn'];
472 }
473 }
474 if(count($this->system_activation_object)){
475 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
476 }
477 }
480 /********************
481 Edit system ...
482 ********************/
484 /* User wants to edit data? */
485 if (($s_action == "edit") && (!isset($this->systab->config))){
487 $this->dn= $this->terminals[$s_entry]['dn'];
489 /* Check locking, save current plugin in 'back_plugin', so
490 the dialog knows where to return. */
491 if (($user= get_lock($this->dn)) != ""){
492 return(gen_locked_message ($user, $this->dn));
493 }
495 /* Find out more about the object type */
496 $ldap= $this->config->get_ldap_link();
497 $ldap->cat($this->dn, array('objectClass','gotoMode'));
498 $attrs= $ldap->fetch();
499 $type= $this->get_system_type($attrs);
501 /* Lock the current entry, so everyone will get the
502 above dialog */
503 $tabs = array(
504 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
505 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
506 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
507 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
508 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
509 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
510 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
513 if($type == "ArpNewDevice"){
514 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
515 }elseif($type == "NewDevice"){
516 $this->system_activation_object= array($this->dn);
517 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
518 }elseif(isset($tabs[$type])){
520 $class = $tabs[$type]["CLASS"];
521 $acl_cat = $tabs[$type]["ACL"];
522 $tabclass = $tabs[$type]["TABCLASS"];
524 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
525 $this->systab->set_acl_base($this->dn);
526 session::set('objectinfo',$this->dn);
527 add_lock ($this->dn, $this->ui->dn);
528 }else{
529 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
530 $this->remove_lock();
531 }
532 }
535 /********************
536 Change password ...
537 ********************/
539 /* Set terminals root password */
540 if ($s_action=="change_pw"){
541 $tabs = array(
542 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
543 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
544 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
545 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
546 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
547 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
548 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
549 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
550 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
552 $dn = $this->terminals[$s_entry]['dn'];
553 $type = $this->get_system_type($this->terminals[$s_entry]);
555 $class = $tabs[$type]["CLASS"];
556 $acl = $tabs[$type]["ACL"];
557 $tabclass = $tabs[$type]["TABCLASS"];
558 $ui = get_userinfo();
559 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
560 if(preg_match("/w/",$tabacl)){
561 $this->dn= $this->terminals[$s_entry]['dn'];
562 session::set('objectinfo',$this->dn);
563 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
564 }else{
565 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
566 }
567 }
570 /********************
571 Password change finish, but check if entered data is ok
572 ********************/
574 /* Correctly specified? */
575 if (isset($_POST['password_finish'])){
576 if ($_POST['new_password'] != $_POST['repeated_password']){
577 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
578 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
579 }
580 }
582 /********************
583 Password change finish
584 ********************/
586 /* Change terminal password */
587 if (isset($_POST['password_finish']) &&
588 $_POST['new_password'] == $_POST['repeated_password']){
590 /* Check if user is allowed to set password */
591 $tabs = array(
592 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
593 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
594 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
595 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
597 /* Detect object type */
598 $type = "";
599 foreach($this->terminals as $terminal){
600 if($terminal['dn'] == $this->dn){
601 $type = $this->get_system_type($terminal);
602 break;
603 }
604 }
606 /* Type detected */
607 $allow_for = array("terminal","workstation","server","component");
608 if(!empty($type) && in_array($type,$allow_for)){
610 /* Get infos */
611 $plug = $tabs[$type]["PLUG"];
612 $class = $tabs[$type]["CLASS"];
613 $acl = $tabs[$type]["ACL"];
614 $tabclass = $tabs[$type]["TABCLASS"];
616 /* Get acls */
617 $ui = get_userinfo();
618 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
620 /* Check acls */
621 if(preg_match("/w/",$tabacl)){
622 $ldap = $this->config->get_ldap_link();
623 $ldap->cd($this->dn);
624 $ldap->cat($this->dn);
625 $old_attrs = $ldap->fetch();
627 $attrs= array();
628 if ($_POST['new_password'] == ""){
630 /* Remove password attribute
631 */
632 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
633 $attrs['objectClass'] = array();
634 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
635 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
636 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
637 }
638 }
639 }
640 $attrs['userPassword']= array();
641 } else {
643 /* Add/modify password attribute
644 */
645 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
646 $attrs['objectClass'] = array();
647 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
648 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
649 }
650 $attrs['objectClass'][] = "simpleSecurityObject";
651 }
653 if(class_available("passwordMethodCrypt")){
654 $pwd_m = new passwordMethodCrypt($this->config);
655 $pwd_m->set_hash("crypt/md5");
656 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
657 }else{
658 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
659 $attrs = array();
660 }
661 }
662 $ldap->modify($attrs);
663 if (!$ldap->success()){
664 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
665 }else{
666 if(class_available($plug)){
667 $p = new $plug($this->config,$this->dn);
668 $p->handle_post_events("modify");
669 }
670 }
672 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
673 }else{
674 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
675 }
676 }else{
677 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
678 }
679 session::un_set('objectinfo');
680 }
683 /********************
684 Delete system cancel
685 ********************/
687 /* Delete terminal canceled? */
688 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
689 $this->remove_lock();
690 session::un_set('objectinfo');
691 }
694 /********************
695 Action(s) for MULTIPLE
696 ********************/
698 /********************
699 SCHEDULE action in GOsa Daemon
700 ********************/
702 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
703 $this->dns = array();
704 $ids = $this->list_get_selected_items();
706 if(count($ids)){
707 $mac= array();
709 $ldap = $this->config->get_ldap_link();
710 foreach($ids as $id){
711 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
712 $attrs= $ldap->fetch();
713 if (isset($attrs['macAddress'][0])){
714 $mac[]= $attrs['macAddress'][0];
715 }
716 }
717 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
718 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
719 $o_queue = new gosaSupportDaemon();
721 /* Skip installation or update trigerred events,
722 * if this entry is currently processing.
723 */
724 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
725 foreach($mac as $key => $mac_address){
726 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
728 $entry['STATUS'] = strtoupper($entry['STATUS']);
729 if($entry['STATUS'] == "PROCESSING" &&
730 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
731 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
732 unset($mac[$key]);
734 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
735 break;
736 }
737 }
738 }
739 }
741 /* Prepare event to be added
742 */
743 if(count($mac) && isset($events['BY_CLASS'][$type])){
744 $event = $events['BY_CLASS'][$type];
745 $this->systab = new $event['CLASS_NAME']($this->config);
746 $this->systab->add_targets($mac);
747 if(preg_match("/trigger_event/",$s_action)){
748 $this->systab->set_type(TRIGGERED_EVENT);
749 }else{
750 $this->systab->set_type(SCHEDULED_EVENT);
751 }
752 }
753 }
754 }
756 /* Insert scheduled events into queue */
757 if($this->systab instanceof DaemonEvent){
758 $this->systab->save_object();
760 /* Save event
761 */
762 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
763 $o_queue = new gosaSupportDaemon();
764 $o_queue->append($this->systab);
765 if($o_queue->is_error()){
766 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
767 }else{
768 $this->systab = FALSE;
769 }
770 }
771 if(isset($_POST['abort_event_dialog'])){
772 $this->systab = FALSE;
773 }
774 }
777 /********************
778 Delete MULTIPLE entries requested, display confirm dialog
779 ********************/
781 if ($s_action=="del_multiple"){
782 $this->dns = array();
783 $ids = $this->list_get_selected_items();
785 $ui = get_userinfo();
786 $tabs = array(
787 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
788 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
789 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
790 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
791 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
792 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
793 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
794 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
795 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
798 if(count($ids)){
800 $disallowed = array();
801 foreach($ids as $id){
803 /* Get 'dn' from posted termlinst */
804 $attrs = $this->terminals[$id];
805 $type = $this->get_system_type($attrs);
806 $dn = $attrs['dn'];
807 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
808 if(preg_match("/d/",$acl)){
809 $this->dns[$id] = $dn;
810 }else{
811 $disallowed[] = $dn;
812 }
813 }
815 if(count($disallowed)){
816 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
817 }
819 if(count($this->dns)){
821 if ($user= get_multiple_locks($this->dns)){
822 return(gen_locked_message($user,$this->dns));
823 }
825 $dns_names = array();
826 foreach($this->dns as $dn){
827 add_lock ($dn, $this->ui->dn);
828 $dns_names[] = @LDAP::fix($dn);
829 }
831 /* Lock the current entry, so nobody will edit it during deletion */
832 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
833 $smarty->assign("multiple", true);
834 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
835 }
836 }
837 }
840 /********************
841 Delete MULTIPLE entries confirmed
842 ********************/
844 /* Confirmation for deletion has been passed. Users should be deleted. */
845 if (isset($_POST['delete_multiple_system_confirm'])){
847 $ui = get_userinfo();
848 $tabs = array(
849 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
850 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
851 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
852 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
853 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
854 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
855 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
856 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
857 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
860 /* Remove user by user and check acls before removeing them */
861 foreach($this->dns as $key => $dn){
863 /* Get 'dn' from posted termlinst */
864 $attrs = $this->terminals[$key];
865 $type= $this->get_system_type($attrs);
867 /* get object type */
868 $tabtype = "termtabs";
869 $tabobj = "TERMTABS";
870 $tabacl = "";
871 if(isset($tabs[$type])){
872 $tabtype = $tabs[$type]['TABCLASS'];
873 $tabobj = $tabs[$type]['CLASS'];
874 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
876 /* Load permissions for selected 'dn' and check if
877 we're allowed to remove this 'dn' */
878 if(preg_match("/d/",$tabacl)){
880 /* Delete request is permitted, perform LDAP action */
881 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
882 $this->systab= new termgeneric($this->config, $dn);
883 $this->systab->set_acl_base($dn);
884 $this->systab->remove_from_parent();
885 }elseif($tabtype=="phonetabs"){
886 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
887 $this->systab->set_acl_base($dn);
888 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
889 }else{
890 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
891 $this->systab->set_acl_base($dn);
892 $this->systab->delete();
893 }
894 unset ($this->systab);
895 $this->systab= NULL;
897 } else {
898 /* Normally this shouldn't be reached, send some extra
899 logs to notify the administrator */
900 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
901 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
902 }
903 }
905 /* Remove lock file after successfull deletion */
906 $this->remove_lock();
907 $this->dns = array();
908 }
909 }
911 /********************
912 Delete MULTIPLE entries Canceled
913 ********************/
915 /* Remove lock */
916 if(isset($_POST['delete_multiple_system_cancel'])){
918 /* Remove lock file after successfull deletion */
919 $this->remove_lock();
920 $this->dns = array();
921 }
924 /********************
925 Delete system, confirm dialog
926 ********************/
928 /* Remove terminal was requested */
929 if ($s_action=="del"){
931 /* Get 'dn' from posted termlinst */
932 $this->dn = $this->terminals[$s_entry]['dn'];
933 $attrs = $this->terminals[$s_entry];
937 $type= $this->get_system_type($attrs);
938 $ui = get_userinfo();
939 $tabs = array(
940 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
941 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
942 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
943 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
944 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
945 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
946 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
947 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
948 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
950 /* get object type */
951 $tabtype = "termtabs";
952 $tabobj = "TERMTABS";
953 $tabacl = "";
954 if(isset($tabs[$type])){
955 $tabtype = $tabs[$type]['TABCLASS'];
956 $tabobj = $tabs[$type]['CLASS'];
957 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
958 }
960 /* Load permissions for selected 'dn' and check if
961 we're allowed to remove this 'dn' */
962 if(preg_match("/d/",$tabacl)){
964 /* Check locking, save current plugin in 'back_plugin', so
965 the dialog knows where to return. */
966 if (($user= get_lock($this->dn)) != ""){
967 return(gen_locked_message ($user, $this->dn));
968 }
970 /* Lock the current entry, so nobody will edit it during deletion */
971 add_lock ($this->dn, $this->ui->dn);
972 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
973 $smarty->assign("multiple", false);
974 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
975 } else {
977 /* Obviously the user isn't allowed to delete. Show message and
978 clean session. */
979 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
980 }
981 }
984 /********************
985 Delete system, confirmed
986 ********************/
987 /* Confirmation for deletion has been passed. Terminal should be deleted. */
988 if (isset($_POST['delete_terminal_confirm'])){
990 /* Find out more about the object type */
991 $ldap= $this->config->get_ldap_link();
992 $ldap->cat($this->dn, array('objectClass'));
993 $attrs= $ldap->fetch();
994 $type= $this->get_system_type($attrs);
996 $ui = get_userinfo();
998 $tabs = array(
999 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
1000 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
1001 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
1002 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
1003 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
1004 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
1005 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
1006 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
1007 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
1009 /* get object type */
1010 $tabtype = "termtabs";
1011 $tabobj = "TERMTABS";
1012 $tabacl = "";
1013 if(isset($tabs[$type])){
1014 $tabtype = $tabs[$type]['TABCLASS'];
1015 $tabobj = $tabs[$type]['CLASS'];
1016 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
1017 }
1019 /* Check if we are allowed to remove this object */
1020 if(preg_match("/d/",$tabacl)){
1022 /* Delete request is permitted, perform LDAP action */
1023 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
1024 $this->systab= new termgeneric($this->config, $this->dn);
1025 $this->systab->set_acl_base($this->dn);
1026 $this->systab->remove_from_parent();
1027 }elseif($tabtype=="phonetabs"){
1028 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
1029 $this->systab->set_acl_base($this->dn);
1030 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
1031 }else{
1032 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
1033 $this->systab->set_acl_base($this->dn);
1034 $this->systab->delete();
1035 }
1036 unset ($this->systab);
1037 $this->systab= NULL;
1039 /* Terminal list has changed, reload it. */
1040 } else {
1042 /* Normally this shouldn't be reached, send some extra
1043 logs to notify the administrator */
1044 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1045 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1046 }
1048 /* Remove lock file after successfull deletion */
1049 $this->remove_lock();
1050 }
1053 /********************
1054 Edit system type finished, check if everything went ok
1055 ********************/
1056 /* Finish user edit is triggered by the tabulator dialog, so
1057 the user wants to save edited data. Check and save at this
1058 point. */
1060 /* Dirty workaround - MSG_DIALOG - OK
1061 If a message dialog is shown and we press 'OK'
1062 then try to save again.
1063 */
1064 foreach($_POST as $name => $value){
1065 if(preg_match("/^MSG_OK/",$name)){
1066 $_POST[$this->last_action] = TRUE;
1067 }
1068 }
1070 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1072 /* If the save routine gets interrupted by a confirm dialog,
1073 store last action so we can trigger it again after 'Ok' was pressed.
1074 (This is the case if a system gets modified while it is installing - GOsa si)
1075 */
1076 $this->last_action = "";
1077 if(isset($_POST['edit_finish'])){
1078 $this->last_action = "edit_finish";
1079 }elseif(isset($_POST['edit_apply'])){
1080 $this->last_action = "edit_apply";
1081 }
1083 /* Check tabs, will feed message array */
1084 $message = $this->systab->check();
1086 /* Save, or display error message? */
1087 if (count($message) == 0){
1090 $this->systab->save();
1092 /* Terminal has been saved successfully, remove lock from LDAP. */
1093 if (!isset($_POST['edit_apply'])){
1094 if ($this->dn != "new"){
1095 $this->remove_lock();
1096 }
1098 unset ($this->systab);
1099 $this->systab= NULL;
1100 session::un_set('objectinfo');
1101 }else{
1103 /* Reinitialize tab */
1104 if($this->systab instanceof tabs){
1105 $this->systab->re_init();
1106 }
1107 }
1108 } else {
1109 /* Ok. There seem to be errors regarding to the tab data,
1110 show message and continue as usual. */
1111 msg_dialog::displayChecks($message);
1112 }
1113 }
1116 /********************
1117 Edit system was canceled
1118 ********************/
1119 /* Cancel dialogs */
1120 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1121 if (isset($this->systab)){
1122 $this->remove_lock();
1123 unset ($this->systab);
1124 }
1125 $this->systab= NULL;
1126 session::un_set('objectinfo');
1127 }
1129 /********************
1130 Display edit dialog, or some other
1131 ********************/
1133 /* Show tab dialog if object is present */
1134 if (isset($this->systab->config)){
1135 $display= $this->systab->execute();
1137 /* Don't show buttons if tab dialog requests this */
1139 $dialog = FALSE;
1140 $hide_apply = $this->dn == "new";
1141 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1142 if(is_object($this->systab) && !isset($this->systab->by_object)){
1143 $dialog = TRUE;
1144 $hide_apply = TRUE;
1145 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1146 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1147 if($dia === TRUE || is_object($dia)){
1148 $dialog = TRUE;
1149 }
1150 }
1151 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1152 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1153 $dialog = TRUE;
1154 }
1156 if (!$dialog){
1157 $display.= "<p style=\"text-align:right\">\n";
1158 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1159 $display.= " \n";
1160 if (!$hide_apply){
1161 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1162 $display.= " \n";
1163 }
1164 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1165 $display.= "</p>";
1166 }
1167 return ($display);
1168 }
1170 /* Check if there is a snapshot dialog open */
1171 $base = $this->DivListSystem->selectedBase;
1172 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1173 return($str);
1174 }
1176 /* Display dialog with system list */
1177 $this->DivListSystem->parent = $this;
1178 $this->DivListSystem->execute();
1180 /* Add departments if subsearch is disabled */
1181 if(!$this->DivListSystem->SubSearch){
1183 /* Add FAIstate to attributes if FAI is activated */
1184 if($this->fai_activated){
1185 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1186 }else{
1187 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1188 }
1189 }
1190 $this->reload();
1191 $this->DivListSystem->setEntries($this->terminals);
1192 return($this->DivListSystem->Draw());
1193 }
1196 /* Return departments, that will be included within snapshot detection */
1197 function get_used_snapshot_bases()
1198 {
1199 $tmp = array();
1201 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1203 $tabs = array(
1204 "terminal" => get_ou('terminalou'),
1205 "workstation" => get_ou('workstationou'),
1206 "incoming" => get_ou('incomingou'),
1207 "server" => get_ou('serverou'),
1208 "printer" => get_ou('printerou'),
1209 "phone" => get_ou('phoneou'),
1210 "winworkstation" => get_winstations_ou(),
1211 "component" => get_ou('componentou')
1212 );
1214 foreach($tabs as $acl_cat => $dn){
1216 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1217 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1218 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1219 }
1220 }
1221 return($tmp);
1222 }
1225 function remove_from_parent()
1226 {
1227 /* Optionally execute a command after we're done */
1228 $this->postremove();
1229 }
1232 /* Save data to object */
1233 function save_object()
1234 {
1235 $this->DivListSystem->save_object();
1236 if(is_object($this->CopyPasteHandler)){
1237 $this->CopyPasteHandler->save_object();
1238 }
1239 }
1242 /* Check values */
1243 function check()
1244 {
1245 }
1248 /* Save to LDAP */
1249 function save()
1250 {
1251 }
1253 function adapt_from_template($dn, $skip= array())
1254 {
1255 }
1257 function password_change_needed()
1258 {
1259 }
1261 function reload()
1262 {
1263 /* some var init */
1264 $ui = get_userinfo();
1265 $res = array();
1266 $this->terminals = array();
1267 $userregex = "";
1269 /* Set base for all searches */
1270 $base= $this->DivListSystem->selectedBase;
1272 /* Prepare samba class name */
1273 $samba ="";
1274 if ($this->DivListSystem->ShowWinWorkstations){
1275 if ($this->config->current['SAMBAVERSION'] == "3"){
1276 $samba= "sambaSamAccount";
1277 } else {
1278 $samba= "sambaAccount";
1279 }
1280 }
1282 /* This array represents the combination between checkboxes and search filters */
1283 $objs = array(
1284 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1285 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1286 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1287 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1288 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1289 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1290 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1292 /* Include the 'Display Systems of user' attribute */
1293 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1294 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1295 }
1297 /* Attributes to fetch */
1298 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1299 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1301 /* Add FAIstate to attributes if FAI is activated */
1302 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1303 if(!empty($tmp)){
1304 $sys_attrs[] = "FAIstate";
1305 }
1307 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1308 foreach($objs as $checkBox => $oc){
1309 if($this->DivListSystem->$checkBox){
1310 if($this->DivListSystem->SubSearch){
1311 if($oc['CLASS'] != ""){
1312 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1313 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1314 $res = array_merge($res,$new_res);
1315 }
1316 }else{
1317 /* User filter? */
1318 if($oc['CLASS'] != ""){
1319 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1320 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1321 }
1322 }
1323 }
1324 }
1326 /* Search for incoming objects */
1327 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1328 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1330 /* Get all gotoTerminal's */
1331 foreach ($res as $value){
1333 $tmp= $value['dn'];
1334 $add= "";
1336 /* Extract base */
1337 foreach($objs as $obj){
1338 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1339 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1340 }
1341 }
1343 /* Create a string containing the last part of the department. */
1344 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1345 if(empty($dn_name)){
1346 $dn_name = "/";
1347 }
1349 /* check if current object is a new one */
1350 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1351 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1352 $add= "- "._("New terminal");
1353 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1354 $add= "- "._("New workstation");
1355 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1356 $add= "- "._("Unknown device");
1357 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1358 $add= "- "._("New Device");
1359 }
1360 }
1362 /* Detect type of object and create an entry for $this->terminals */
1363 $terminal = array();
1364 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1366 /* check acl */
1367 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1368 if($add != "" || preg_match("/r/",$acl)) {
1369 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1370 $terminal = $value;
1371 $terminal['type'] = "T";
1372 $terminal['is_new'] = $add;
1373 } else {
1374 $terminal = $value;
1375 $terminal['type'] = "D";
1376 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1377 $terminal['location'] = array_search($tmp, $this->config->departments);
1378 }
1379 }
1380 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1382 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1383 if($add != "" || preg_match("/r/",$acl)) {
1384 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1385 $terminal = $value;
1386 $terminal['type'] = "L";
1387 $terminal['is_new'] = $add;
1388 } else {
1389 $terminal = $value;
1390 $terminal['type'] = "D";
1391 $terminal['location'] = array_search($tmp, $this->config->departments);
1392 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1393 }
1394 # if (isset($value["FAIstate"][0])){
1395 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1396 # }
1397 }
1398 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1401 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1402 if($add != "" || preg_match("/r/",$acl)) {
1404 $terminal = $value;
1405 $terminal['type'] = "P";
1406 }
1407 } elseif (in_array_ics('goServer', $value["objectClass"])){
1409 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1410 if($add != "" || preg_match("/r/",$acl)) {
1412 $terminal = $value;
1413 $terminal['type'] = "S";
1414 # if (isset($value["FAIstate"][0])){
1415 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1416 # }
1417 }
1418 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1420 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1421 if($add != "" || preg_match("/r/",$acl)) {
1423 $terminal = $value;
1424 $terminal['type'] = "F";
1425 }
1426 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1428 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1429 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1430 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1431 if($add != "" || preg_match("/r/",$acl)) {
1433 $terminal = $value;
1434 $terminal['type'] = "Q";
1435 $terminal['is_new'] = $add;
1436 }
1437 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1439 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1440 if($add != "" || preg_match("/r/",$acl)) {
1442 $terminal = $value;
1443 $terminal['type'] = "C";
1444 }
1445 } else{
1447 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1448 if (isset($value['sambaDomainName'])){
1449 $domain= " [".$value['sambaDomainName'][0]."]";
1450 } else {
1451 $domain= "";
1452 }
1453 $terminal=$value;
1454 $terminal['type'] ="W";
1455 $terminal['domain'] = $name.$domain;
1456 }
1458 if(count($terminal)){
1459 $this->terminals[]=$terminal;
1460 }
1461 }
1463 $tmp =array();
1464 $tmp2 =array();
1465 foreach($this->terminals as $tkey => $val ){
1466 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1467 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1468 }
1469 natcasesort($tmp2);
1470 $this->terminals=array();
1471 foreach($tmp2 as $val){
1472 $this->terminals[]=$tmp[$val];
1473 }
1474 reset ($this->terminals);
1475 }
1477 function remove_lock()
1478 {
1479 if (isset($this->systab->dn)){
1480 del_lock ($this->systab->dn);
1481 }
1482 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1483 del_lock($this->dn);
1484 }
1485 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1486 del_lock($this->dns);
1487 }
1488 }
1491 function copyPasteHandling_from_queue($s_action,$s_entry)
1492 {
1493 /* Check if Copy & Paste is disabled */
1494 if(!is_object($this->CopyPasteHandler)){
1495 return("");
1496 }
1498 $ui = get_userinfo();
1500 $tabs = array(
1501 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1502 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1503 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1504 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1505 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1506 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1507 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1508 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1509 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1510 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1511 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1512 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1514 /* Add a single entry to queue */
1515 if($s_action == "cut" || $s_action == "copy"){
1517 /* Cleanup object queue */
1518 $this->CopyPasteHandler->cleanup_queue();
1519 $dn = $this->terminals[$s_entry]['dn'];
1520 $oc = $this->terminals[$s_entry]['objectClass'];
1521 $type = $this->get_system_type($this->terminals[$s_entry]);
1523 $tab_o = $tabs[$type]['CLASS'];
1524 $tab_c = $tabs[$type]['TABCLASS'];
1525 $acl_c = $tabs[$type]['TABNAME'];
1526 $acl = $tabs[$type]['ACL'];
1528 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1529 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1530 }
1531 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1532 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1533 }
1534 }
1536 /* Add entries to queue */
1537 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1539 /* Cleanup object queue */
1540 $this->CopyPasteHandler->cleanup_queue();
1542 /* Add new entries to CP queue */
1543 foreach($this->list_get_selected_items() as $id){
1544 $dn = $this->terminals[$id]['dn'];
1545 $oc = $this->terminals[$id]['objectClass'];
1546 $type = $this->get_system_type($this->terminals[$id]);
1548 if(isset($tabs[$type])){
1549 $tab_o = $tabs[$type]['CLASS'];
1550 $tab_c = $tabs[$type]['TABCLASS'];
1551 $acl_c = $tabs[$type]['TABNAME'];
1552 $acl = $tabs[$type]['ACL'];
1554 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1555 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1556 }
1557 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1558 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1559 }
1560 }
1561 }
1562 }
1564 /* Start pasting entries */
1565 if($s_action == "editPaste"){
1566 $this->start_pasting_copied_objects = TRUE;
1567 }
1569 /* Return C&P dialog */
1570 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1572 /* Get dialog */
1573 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1574 $data = $this->CopyPasteHandler->execute();
1576 /* Return dialog data */
1577 if(!empty($data)){
1578 return($data);
1579 }
1580 }
1582 /* Automatically disable status for pasting */
1583 if(!$this->CopyPasteHandler->entries_queued()){
1584 $this->start_pasting_copied_objects = FALSE;
1585 }
1586 return("");
1587 }
1590 function get_system_type($attrs)
1591 {
1592 $classes = $attrs['objectClass'];
1594 $type= "";
1595 if (in_array_ics('ieee802Device', $classes)){
1596 $type= "component";
1597 }elseif (in_array_ics('gotoTerminal', $classes)){
1598 $type= "terminal";
1599 }elseif (in_array_ics('gotoWorkstation', $classes)){
1600 $type= "workstation";
1601 }elseif (in_array_ics('gotoPrinter', $classes)){
1602 $type= "printer";
1603 }elseif (in_array_ics('goFonHardware', $classes)){
1604 $type= "phone";
1605 }elseif (in_array_ics('goServer', $classes)){
1606 $type= "server";
1607 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1608 $type= "ArpNewDevice";
1609 }elseif (in_array_ics('GOhard', $classes)){
1610 $type= "NewDevice";
1611 }elseif (in_array_ics('sambaAccount', $classes) ||
1612 in_array_ics('sambaSamAccount', $classes)){
1613 $type= "winstation";
1614 }
1615 return ($type);
1616 }
1619 function convert_list($input)
1620 {
1621 $temp= "";
1623 $conv= array(
1624 "D" => array("select_default.png",_("Template")),
1625 "F" => array("select_phone.png",_("Phone")),
1626 "C" => array("select_component.png",_("Network device")),
1627 "P" => array("select_printer.png",_("Printer")),
1629 "W" => array("select_winstation.png",_("Win workstation")),
1631 "L" => array("select_workstation.png",_("Workstation")),
1632 "S" => array("select_server.png",_("Server")),
1633 "T" => array("select_terminal.png",_("Terminal")),
1635 "LX" => array("workstation_locked.png",_("Locked workstation")),
1636 "SX" => array("server_locked.png",_("Locked server")),
1637 "TX" => array("terminal_locked.png",_("Locked terminal")),
1639 "LE" => array("workstation_error.png",_("Workstation error")),
1640 "SE" => array("server_error.png",_("Server error")),
1641 "TE" => array("terminal_error.png",_("Terminal error")),
1643 "LB" => array("workstation_busy.png",_("Workstation busy")),
1644 "SB" => array("server_busy.png",_("Server busy")),
1646 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1647 "NT"=> array("select_new_terminal.png",_("New terminal")),
1648 "NL"=> array("select_new_workstation.png",_("New workstation")));
1650 /* Use locked icons
1651 */
1652 if( in_array($input['type'],array("S","T","L")) &&
1653 isset($input['gotoMode'][0]) &&
1654 preg_match("/locked/",$input['gotoMode'][0])){
1655 $input['type'].="X";
1656 } elseif(in_array($input['type'],array("S","L")) &&
1657 isset($input['FAIstate'][0])){
1659 /* Add FAI state icons
1660 */
1661 $type= "";
1662 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1663 case 'error':
1664 $type= 'E';
1665 break;
1666 case 'installing':
1667 case 'install':
1668 case 'sysinfo':
1669 case 'softupdate':
1670 case 'scheduledupdate':
1671 $type= 'B';
1672 break;
1673 }
1675 $input['type'].= $type;
1676 }
1678 /* Use new images if object is from incoming
1679 */
1680 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1681 $input['type']="N".$input['type'];
1682 }
1684 /* Check which flags this objects uses
1685 */
1686 foreach ($conv as $key => $value){
1687 $found = TRUE;
1688 if(strlen($key) != strlen($input['type'])) {
1689 $found = FALSE;
1690 }
1691 for($i = 0 ; $i < strlen($key) ; $i++){
1692 if(!preg_match("/".$key[$i]."/",$input['type'])){
1693 $found = FALSE;
1694 }
1695 }
1697 if($found){
1698 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1699 $tmp['class']=$key;
1700 return $tmp;
1701 }
1702 }
1703 }
1706 function list_get_selected_items()
1707 {
1708 $ids = array();
1709 foreach($_POST as $name => $value){
1710 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1711 $id = preg_replace("/^item_selected_/","",$name);
1712 $ids[$id] = $id;
1713 }
1714 }
1715 return($ids);
1716 }
1719 /* !! Incoming dummy acls, required to defined acls for incoming objects
1720 */
1721 static function plInfo()
1722 {
1723 return (array(
1724 "plShortName" => _("Incoming objects"),
1725 "plDescription" => _("Incoming objects"),
1726 "plSelfModify" => FALSE,
1727 "plDepends" => array(),
1728 "plPriority" => 99,
1729 "plSection" => array("administration"),
1730 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1731 "objectClass" => "")),
1732 "plProvidedAcls"=> array()
1734 ));
1735 }
1736 }
1738 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1739 ?>