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