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;
333 /*******
334 * Set gotoMode to active if we there was an ogroup selected.
335 */
336 $found = false;
337 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
338 if(isset($this->systab->by_object[$tab]->gotoMode)) {
339 $found = true;
340 $this->systab->by_object[$tab]->gotoMode = $value;
341 }
342 }
343 if(!$found){
344 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
345 }
348 if($selected_group != "none"){
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 }
370 }
373 // Enable activation
374 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
375 if (isset($this->systab->by_object[$cls])){
376 $this->systab->by_object[$cls]->auto_activate= TRUE;
377 }
378 }
380 // Enable sending of LDAP events
381 if (isset($this->systab->by_object["workstartup"])){
382 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
383 }
385 /* Don't save directly if there is no objectGroup selected.
386 The user will then be able to configure the missing attributes
387 on his own.
388 */
389 if($selected_group != "none"){
390 $this->systab->save();
391 $this->systab = NULL;
393 if(!isset($ldap)){
394 $ldap = $this->config->get_ldap_link();
395 }
396 $ldap->cd ($this->dn);
397 $ldap->cat($this->dn, array('dn'));
398 if(count($ldap->fetch())){
399 $ldap->cd($this->dn);
400 $ldap->rmDir($this->dn);
401 }
402 }
403 }else{
404 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
405 }
406 }
407 }
408 }
411 if (isset($_POST['create_system'])||$s_action=="newsystem") {
413 /* If the current entry is an incoming object
414 * $sw = System type as posted in new incoming handling dialog
415 */
416 if(isset($_POST['system'])){
417 $sw = $_POST['system'];
418 }else{
419 $sw = $s_entry;
420 }
421 $this->dn= "new";
423 $tabs = array(
424 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
425 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
426 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
427 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
428 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
429 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
431 if(isset($tabs[$sw])){
432 $class = $tabs[$sw]["CLASS"];
433 $tabname = $tabs[$sw]["TABNAME"];
434 $tabclass = $tabs[$sw]["TABCLASS"];
435 $acl_cat = $tabs[$sw]["ACL"];
437 /* Load permissions for selected 'dn' and check if
438 we're allowed to remove this 'dn' */
439 $ui = get_userinfo();
440 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
441 if(preg_match("/c/",$tabacl)){
442 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
443 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
444 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
445 $this->systab->base = $this->DivListSystem->selectedBase;
446 }else{
447 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
448 }
449 }
450 }
453 /********************
454 System activation
455 ********************/
457 /* User wants to edit data? */
458 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
459 $this->system_activation_object = array();
460 foreach($this->list_get_selected_items() as $id) {
461 $obj = $this->terminals[$id];
462 $type= $this->get_system_type($obj);
463 if($type == "NewDevice"){
464 $this->system_activation_object[] = $obj['dn'];
465 }
466 }
467 if(count($this->system_activation_object)){
468 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
469 }
470 }
473 /********************
474 Edit system ...
475 ********************/
477 /* User wants to edit data? */
478 if (($s_action == "edit") && (!isset($this->systab->config))){
480 $this->dn= $this->terminals[$s_entry]['dn'];
482 /* Check locking, save current plugin in 'back_plugin', so
483 the dialog knows where to return. */
484 if (($user= get_lock($this->dn)) != ""){
485 return(gen_locked_message ($user, $this->dn));
486 }
488 /* Find out more about the object type */
489 $ldap= $this->config->get_ldap_link();
490 $ldap->cat($this->dn, array('objectClass','gotoMode'));
491 $attrs= $ldap->fetch();
492 $type= $this->get_system_type($attrs);
494 /* Lock the current entry, so everyone will get the
495 above dialog */
496 $tabs = array(
497 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
498 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
499 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
500 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
501 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
502 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
503 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
506 if($type == "ArpNewDevice"){
507 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
508 }elseif($type == "NewDevice"){
509 $this->system_activation_object= array($this->dn);
510 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
511 }elseif(isset($tabs[$type])){
513 $class = $tabs[$type]["CLASS"];
514 $acl_cat = $tabs[$type]["ACL"];
515 $tabclass = $tabs[$type]["TABCLASS"];
517 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
518 $this->systab->set_acl_base($this->dn);
519 session::set('objectinfo',$this->dn);
520 add_lock ($this->dn, $this->ui->dn);
521 }else{
522 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
523 $this->remove_lock();
524 }
525 }
528 /********************
529 Change password ...
530 ********************/
532 /* Set terminals root password */
533 if ($s_action=="change_pw"){
534 $tabs = array(
535 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
536 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
537 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
538 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
539 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
540 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
541 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
542 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
543 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
545 $dn = $this->terminals[$s_entry]['dn'];
546 $type = $this->get_system_type($this->terminals[$s_entry]);
548 $class = $tabs[$type]["CLASS"];
549 $acl = $tabs[$type]["ACL"];
550 $tabclass = $tabs[$type]["TABCLASS"];
551 $ui = get_userinfo();
552 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
553 if(preg_match("/w/",$tabacl)){
554 $this->dn= $this->terminals[$s_entry]['dn'];
555 session::set('objectinfo',$this->dn);
556 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
557 }else{
558 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
559 }
560 }
563 /********************
564 Password change finish, but check if entered data is ok
565 ********************/
567 /* Correctly specified? */
568 if (isset($_POST['password_finish'])){
569 if ($_POST['new_password'] != $_POST['repeated_password']){
570 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
571 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
572 }
573 }
575 /********************
576 Password change finish
577 ********************/
579 /* Change terminal password */
580 if (isset($_POST['password_finish']) &&
581 $_POST['new_password'] == $_POST['repeated_password']){
583 /* Check if user is allowed to set password */
584 $tabs = array(
585 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
586 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
587 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
588 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
590 /* Detect object type */
591 $type = "";
592 foreach($this->terminals as $terminal){
593 if($terminal['dn'] == $this->dn){
594 $type = $this->get_system_type($terminal);
595 break;
596 }
597 }
599 /* Type detected */
600 $allow_for = array("terminal","workstation","server","component");
601 if(!empty($type) && in_array($type,$allow_for)){
603 /* Get infos */
604 $plug = $tabs[$type]["PLUG"];
605 $class = $tabs[$type]["CLASS"];
606 $acl = $tabs[$type]["ACL"];
607 $tabclass = $tabs[$type]["TABCLASS"];
609 /* Get acls */
610 $ui = get_userinfo();
611 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
613 /* Check acls */
614 if(preg_match("/w/",$tabacl)){
615 $ldap = $this->config->get_ldap_link();
616 $ldap->cd($this->dn);
617 $ldap->cat($this->dn);
618 $old_attrs = $ldap->fetch();
620 $attrs= array();
621 if ($_POST['new_password'] == ""){
623 /* Remove password attribute
624 */
625 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
626 $attrs['objectClass'] = array();
627 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
628 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
629 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
630 }
631 }
632 }
633 $attrs['userPassword']= array();
634 } else {
636 /* Add/modify password attribute
637 */
638 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
639 $attrs['objectClass'] = array();
640 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
641 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
642 }
643 $attrs['objectClass'][] = "simpleSecurityObject";
644 }
646 if(class_available("passwordMethodCrypt")){
647 $pwd_m = new passwordMethodCrypt($this->config);
648 $pwd_m->set_hash("crypt/md5");
649 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
650 }else{
651 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
652 $attrs = array();
653 }
654 }
655 $ldap->modify($attrs);
656 if (!$ldap->success()){
657 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
658 }else{
659 if(class_available($plug)){
660 $p = new $plug($this->config,$this->dn);
661 $p->handle_post_events("modify");
662 }
663 }
665 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
666 }else{
667 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
668 }
669 }else{
670 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
671 }
672 session::un_set('objectinfo');
673 }
676 /********************
677 Delete system cancel
678 ********************/
680 /* Delete terminal canceled? */
681 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
682 $this->remove_lock();
683 session::un_set('objectinfo');
684 }
687 /********************
688 Action(s) for MULTIPLE
689 ********************/
691 /********************
692 SCHEDULE action in GOsa Daemon
693 ********************/
695 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
696 $this->dns = array();
697 $ids = $this->list_get_selected_items();
699 if(count($ids)){
700 $mac= array();
702 $ldap = $this->config->get_ldap_link();
703 foreach($ids as $id){
704 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
705 $attrs= $ldap->fetch();
706 if (isset($attrs['macAddress'][0])){
707 $mac[]= $attrs['macAddress'][0];
708 }
709 }
710 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
711 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
712 $o_queue = new gosaSupportDaemon();
714 /* Skip installation or update trigerred events,
715 * if this entry is currently processing.
716 */
717 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
718 foreach($mac as $key => $mac_address){
719 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
721 $entry['STATUS'] = strtoupper($entry['STATUS']);
722 if($entry['STATUS'] == "PROCESSING" &&
723 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
724 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
725 unset($mac[$key]);
727 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
728 break;
729 }
730 }
731 }
732 }
734 /* Prepare event to be added
735 */
736 if(count($mac) && isset($events['BY_CLASS'][$type])){
737 $event = $events['BY_CLASS'][$type];
738 $this->systab = new $event['CLASS_NAME']($this->config);
739 $this->systab->add_targets($mac);
740 if(preg_match("/trigger_event/",$s_action)){
741 $this->systab->set_type(TRIGGERED_EVENT);
742 }else{
743 $this->systab->set_type(SCHEDULED_EVENT);
744 }
745 }
746 }
747 }
749 /* Insert scheduled events into queue */
750 if($this->systab instanceof DaemonEvent){
751 $this->systab->save_object();
753 /* Save event
754 */
755 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
756 $o_queue = new gosaSupportDaemon();
757 $o_queue->append($this->systab);
758 if($o_queue->is_error()){
759 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
760 }else{
761 $this->systab = FALSE;
762 }
763 }
764 if(isset($_POST['abort_event_dialog'])){
765 $this->systab = FALSE;
766 }
767 }
770 /********************
771 Delete MULTIPLE entries requested, display confirm dialog
772 ********************/
774 if ($s_action=="del_multiple"){
775 $this->dns = array();
776 $ids = $this->list_get_selected_items();
778 if(count($ids)){
780 foreach($ids as $id){
781 $dn = $this->terminals[$id]['dn'];
782 $this->dns[$id] = $dn;
783 }
784 if ($user= get_multiple_locks($this->dns)){
785 return(gen_locked_message($user,$this->dns));
786 }
788 $dns_names = array();
789 foreach($this->dns as $dn){
790 add_lock ($dn, $this->ui->dn);
791 $dns_names[] = @LDAP::fix($dn);
792 }
794 /* Lock the current entry, so nobody will edit it during deletion */
795 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
796 $smarty->assign("multiple", true);
797 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
798 }
799 }
802 /********************
803 Delete MULTIPLE entries confirmed
804 ********************/
806 /* Confirmation for deletion has been passed. Users should be deleted. */
807 if (isset($_POST['delete_multiple_system_confirm'])){
809 $ui = get_userinfo();
810 $tabs = array(
811 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
812 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
813 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
814 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
815 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
816 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
817 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
818 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
819 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
822 /* Remove user by user and check acls before removeing them */
823 foreach($this->dns as $key => $dn){
825 /* Get 'dn' from posted termlinst */
826 $attrs = $this->terminals[$key];
827 $type= $this->get_system_type($attrs);
829 /* get object type */
830 $tabtype = "termtabs";
831 $tabobj = "TERMTABS";
832 $tabacl = "";
833 if(isset($tabs[$type])){
834 $tabtype = $tabs[$type]['TABCLASS'];
835 $tabobj = $tabs[$type]['CLASS'];
836 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
838 /* Load permissions for selected 'dn' and check if
839 we're allowed to remove this 'dn' */
840 if(preg_match("/d/",$tabacl)){
842 /* Delete request is permitted, perform LDAP action */
843 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
844 $this->systab= new termgeneric($this->config, $dn);
845 $this->systab->set_acl_base($dn);
846 $this->systab->remove_from_parent();
847 }elseif($tabtype=="phonetabs"){
848 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
849 $this->systab->set_acl_base($dn);
850 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
851 }else{
852 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
853 $this->systab->set_acl_base($dn);
854 $this->systab->delete();
855 }
856 unset ($this->systab);
857 $this->systab= NULL;
859 } else {
860 /* Normally this shouldn't be reached, send some extra
861 logs to notify the administrator */
862 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
863 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
864 }
865 }
867 /* Remove lock file after successfull deletion */
868 $this->remove_lock();
869 $this->dns = array();
870 }
871 }
873 /********************
874 Delete MULTIPLE entries Canceled
875 ********************/
877 /* Remove lock */
878 if(isset($_POST['delete_multiple_system_cancel'])){
880 /* Remove lock file after successfull deletion */
881 $this->remove_lock();
882 $this->dns = array();
883 }
886 /********************
887 Delete system, confirm dialog
888 ********************/
890 /* Remove terminal was requested */
891 if ($s_action=="del"){
893 /* Get 'dn' from posted termlinst */
894 $this->dn = $this->terminals[$s_entry]['dn'];
895 $attrs = $this->terminals[$s_entry];
899 $type= $this->get_system_type($attrs);
900 $ui = get_userinfo();
901 $tabs = array(
902 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
903 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
904 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
905 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
906 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
907 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
908 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
909 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
910 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
912 /* get object type */
913 $tabtype = "termtabs";
914 $tabobj = "TERMTABS";
915 $tabacl = "";
916 if(isset($tabs[$type])){
917 $tabtype = $tabs[$type]['TABCLASS'];
918 $tabobj = $tabs[$type]['CLASS'];
919 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
920 }
922 /* Load permissions for selected 'dn' and check if
923 we're allowed to remove this 'dn' */
924 if(preg_match("/d/",$tabacl)){
926 /* Check locking, save current plugin in 'back_plugin', so
927 the dialog knows where to return. */
928 if (($user= get_lock($this->dn)) != ""){
929 return(gen_locked_message ($user, $this->dn));
930 }
932 /* Lock the current entry, so nobody will edit it during deletion */
933 add_lock ($this->dn, $this->ui->dn);
934 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
935 $smarty->assign("multiple", false);
936 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
937 } else {
939 /* Obviously the user isn't allowed to delete. Show message and
940 clean session. */
941 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
942 }
943 }
946 /********************
947 Delete system, confirmed
948 ********************/
949 /* Confirmation for deletion has been passed. Terminal should be deleted. */
950 if (isset($_POST['delete_terminal_confirm'])){
952 /* Find out more about the object type */
953 $ldap= $this->config->get_ldap_link();
954 $ldap->cat($this->dn, array('objectClass'));
955 $attrs= $ldap->fetch();
956 $type= $this->get_system_type($attrs);
958 $ui = get_userinfo();
960 $tabs = array(
961 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
962 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
963 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
964 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
965 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
966 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
967 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
968 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
969 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
971 /* get object type */
972 $tabtype = "termtabs";
973 $tabobj = "TERMTABS";
974 $tabacl = "";
975 if(isset($tabs[$type])){
976 $tabtype = $tabs[$type]['TABCLASS'];
977 $tabobj = $tabs[$type]['CLASS'];
978 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
979 }
981 /* Check if we are allowed to remove this object */
982 if(preg_match("/d/",$tabacl)){
984 /* Delete request is permitted, perform LDAP action */
985 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
986 $this->systab= new termgeneric($this->config, $this->dn);
987 $this->systab->set_acl_base($this->dn);
988 $this->systab->remove_from_parent();
989 }elseif($tabtype=="phonetabs"){
990 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
991 $this->systab->set_acl_base($this->dn);
992 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
993 }else{
994 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
995 $this->systab->set_acl_base($this->dn);
996 $this->systab->delete();
997 }
998 unset ($this->systab);
999 $this->systab= NULL;
1001 /* Terminal list has changed, reload it. */
1002 } else {
1004 /* Normally this shouldn't be reached, send some extra
1005 logs to notify the administrator */
1006 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1007 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1008 }
1010 /* Remove lock file after successfull deletion */
1011 $this->remove_lock();
1012 }
1015 /********************
1016 Edit system type finished, check if everything went ok
1017 ********************/
1018 /* Finish user edit is triggered by the tabulator dialog, so
1019 the user wants to save edited data. Check and save at this
1020 point. */
1022 /* Dirty workaround - MSG_DIALOG - OK
1023 If a message dialog is shown and we press 'OK'
1024 then try to save again.
1025 */
1026 foreach($_POST as $name => $value){
1027 if(preg_match("/^MSG_OK/",$name)){
1028 $_POST[$this->last_action] = TRUE;
1029 }
1030 }
1032 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1034 /* If the save routine gets interrupted by a confirm dialog,
1035 store last action so we can trigger it again after 'Ok' was pressed.
1036 (This is the case if a system gets modified while it is installing - GOsa si)
1037 */
1038 $this->last_action = "";
1039 if(isset($_POST['edit_finish'])){
1040 $this->last_action = "edit_finish";
1041 }elseif(isset($_POST['edit_apply'])){
1042 $this->last_action = "edit_apply";
1043 }
1045 /* Check tabs, will feed message array */
1046 $message = $this->systab->check();
1048 /* Save, or display error message? */
1049 if (count($message) == 0){
1052 $this->systab->save();
1054 /* Terminal has been saved successfully, remove lock from LDAP. */
1055 if (!isset($_POST['edit_apply'])){
1056 if ($this->dn != "new"){
1057 $this->remove_lock();
1058 }
1060 unset ($this->systab);
1061 $this->systab= NULL;
1062 session::un_set('objectinfo');
1063 }else{
1065 /* Reinitialize tab */
1066 if($this->systab instanceof tabs){
1067 $this->systab->re_init();
1068 }
1069 }
1070 } else {
1071 /* Ok. There seem to be errors regarding to the tab data,
1072 show message and continue as usual. */
1073 msg_dialog::displayChecks($message);
1074 }
1075 }
1078 /********************
1079 Edit system was canceled
1080 ********************/
1081 /* Cancel dialogs */
1082 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1083 if (isset($this->systab)){
1084 $this->remove_lock();
1085 unset ($this->systab);
1086 }
1087 $this->systab= NULL;
1088 session::un_set('objectinfo');
1089 }
1091 /********************
1092 Display edit dialog, or some other
1093 ********************/
1095 /* Show tab dialog if object is present */
1096 if (isset($this->systab->config)){
1097 $display= $this->systab->execute();
1099 /* Don't show buttons if tab dialog requests this */
1101 $dialog = FALSE;
1102 $hide_apply = $this->dn == "new";
1103 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1104 if(is_object($this->systab) && !isset($this->systab->by_object)){
1105 $dialog = TRUE;
1106 $hide_apply = TRUE;
1107 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1108 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1109 if($dia === TRUE || is_object($dia)){
1110 $dialog = TRUE;
1111 }
1112 }
1113 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1114 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1115 $dialog = TRUE;
1116 }
1118 if (!$dialog){
1119 $display.= "<p style=\"text-align:right\">\n";
1120 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1121 $display.= " \n";
1122 if (!$hide_apply){
1123 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1124 $display.= " \n";
1125 }
1126 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1127 $display.= "</p>";
1128 }
1129 return ($display);
1130 }
1132 /* Check if there is a snapshot dialog open */
1133 $base = $this->DivListSystem->selectedBase;
1134 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1135 return($str);
1136 }
1138 /* Display dialog with system list */
1139 $this->DivListSystem->parent = $this;
1140 $this->DivListSystem->execute();
1142 /* Add departments if subsearch is disabled */
1143 if(!$this->DivListSystem->SubSearch){
1144 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1145 }
1146 $this->reload();
1147 $this->DivListSystem->setEntries($this->terminals);
1148 return($this->DivListSystem->Draw());
1149 }
1152 /* Return departments, that will be included within snapshot detection */
1153 function get_used_snapshot_bases()
1154 {
1155 $tmp = array();
1157 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1159 $tabs = array(
1160 "terminal" => get_ou('terminalou'),
1161 "workstation" => get_ou('workstationou'),
1162 "incoming" => get_ou('incomingou'),
1163 "server" => get_ou('serverou'),
1164 "printer" => get_ou('printerou'),
1165 "phone" => get_ou('phoneou'),
1166 "winworkstation" => get_winstations_ou(),
1167 "component" => get_ou('componentou')
1168 );
1170 foreach($tabs as $acl_cat => $dn){
1172 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1173 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1174 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1175 }
1176 }
1177 return($tmp);
1178 }
1181 function remove_from_parent()
1182 {
1183 /* Optionally execute a command after we're done */
1184 $this->postremove();
1185 }
1188 /* Save data to object */
1189 function save_object()
1190 {
1191 $this->DivListSystem->save_object();
1192 if(is_object($this->CopyPasteHandler)){
1193 $this->CopyPasteHandler->save_object();
1194 }
1195 }
1198 /* Check values */
1199 function check()
1200 {
1201 }
1204 /* Save to LDAP */
1205 function save()
1206 {
1207 }
1209 function adapt_from_template($dn, $skip= array())
1210 {
1211 }
1213 function password_change_needed()
1214 {
1215 }
1217 function reload()
1218 {
1219 /* some var init */
1220 $ui = get_userinfo();
1221 $res = array();
1222 $this->terminals = array();
1223 $userregex = "";
1225 /* Set base for all searches */
1226 $base= $this->DivListSystem->selectedBase;
1228 /* Prepare samba class name */
1229 $samba ="";
1230 if ($this->DivListSystem->ShowWinWorkstations){
1231 if ($this->config->current['SAMBAVERSION'] == "3"){
1232 $samba= "sambaSamAccount";
1233 } else {
1234 $samba= "sambaAccount";
1235 }
1236 }
1238 /* This array represents the combination between checkboxes and search filters */
1239 $objs = array(
1240 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1241 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1242 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1243 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1244 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1245 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1246 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1248 /* Include the 'Display Systems of user' attribute */
1249 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1250 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1251 }
1253 /* Attributes to fetch */
1254 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1255 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1257 /* Add FAIstate to attributes if FAI is activated */
1258 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1259 if(!empty($tmp)){
1260 $sys_attrs[] = "FAIstate";
1261 }
1263 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1264 foreach($objs as $checkBox => $oc){
1265 if($this->DivListSystem->$checkBox){
1266 if($this->DivListSystem->SubSearch){
1267 if($oc['CLASS'] != ""){
1268 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1269 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1270 $res = array_merge($res,$new_res);
1271 }
1272 }else{
1273 /* User filter? */
1274 if($oc['CLASS'] != ""){
1275 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1276 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1277 }
1278 }
1279 }
1280 }
1282 /* Search for incoming objects */
1283 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1284 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1286 /* Get all gotoTerminal's */
1287 foreach ($res as $value){
1289 $tmp= $value['dn'];
1290 $add= "";
1292 /* Extract base */
1293 foreach($objs as $obj){
1294 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1295 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1296 }
1297 }
1299 /* Create a string containing the last part of the department. */
1300 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1301 if(empty($dn_name)){
1302 $dn_name = "/";
1303 }
1305 /* check if current object is a new one */
1306 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1307 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1308 $add= "- "._("New terminal");
1309 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1310 $add= "- "._("New workstation");
1311 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1312 $add= "- "._("Unknown device");
1313 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1314 $add= "- "._("New Device");
1315 }
1316 }
1318 /* Detect type of object and create an entry for $this->terminals */
1319 $terminal = array();
1320 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1322 /* check acl */
1323 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1324 if($add != "" || preg_match("/r/",$acl)) {
1325 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1326 $terminal = $value;
1327 $terminal['type'] = "T";
1328 $terminal['is_new'] = $add;
1329 } else {
1330 $terminal = $value;
1331 $terminal['type'] = "D";
1332 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1333 $terminal['location'] = array_search($tmp, $this->config->departments);
1334 }
1335 }
1336 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1338 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1339 if($add != "" || preg_match("/r/",$acl)) {
1340 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1341 $terminal = $value;
1342 $terminal['type'] = "L";
1343 $terminal['is_new'] = $add;
1344 } else {
1345 $terminal = $value;
1346 $terminal['type'] = "D";
1347 $terminal['location'] = array_search($tmp, $this->config->departments);
1348 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1349 }
1350 # if (isset($value["FAIstate"][0])){
1351 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1352 # }
1353 }
1354 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1357 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1358 if($add != "" || preg_match("/r/",$acl)) {
1360 $terminal = $value;
1361 $terminal['type'] = "P";
1362 }
1363 } elseif (in_array_ics('goServer', $value["objectClass"])){
1365 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1366 if($add != "" || preg_match("/r/",$acl)) {
1368 $terminal = $value;
1369 $terminal['type'] = "S";
1370 # if (isset($value["FAIstate"][0])){
1371 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1372 # }
1373 }
1374 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1376 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1377 if($add != "" || preg_match("/r/",$acl)) {
1379 $terminal = $value;
1380 $terminal['type'] = "F";
1381 }
1382 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1384 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1385 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1386 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1387 if($add != "" || preg_match("/r/",$acl)) {
1389 $terminal = $value;
1390 $terminal['type'] = "Q";
1391 $terminal['is_new'] = $add;
1392 }
1393 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1395 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1396 if($add != "" || preg_match("/r/",$acl)) {
1398 $terminal = $value;
1399 $terminal['type'] = "C";
1400 }
1401 } else{
1403 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1404 if (isset($value['sambaDomainName'])){
1405 $domain= " [".$value['sambaDomainName'][0]."]";
1406 } else {
1407 $domain= "";
1408 }
1409 $terminal=$value;
1410 $terminal['type'] ="W";
1411 $terminal['domain'] = $name.$domain;
1412 }
1414 if(count($terminal)){
1415 $this->terminals[]=$terminal;
1416 }
1417 }
1419 $tmp =array();
1420 $tmp2 =array();
1421 foreach($this->terminals as $tkey => $val ){
1422 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1423 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1424 }
1425 natcasesort($tmp2);
1426 $this->terminals=array();
1427 foreach($tmp2 as $val){
1428 $this->terminals[]=$tmp[$val];
1429 }
1430 reset ($this->terminals);
1431 }
1433 function remove_lock()
1434 {
1435 if (isset($this->systab->dn)){
1436 del_lock ($this->systab->dn);
1437 }
1438 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1439 del_lock($this->dn);
1440 }
1441 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1442 del_lock($this->dns);
1443 }
1444 }
1447 function copyPasteHandling_from_queue($s_action,$s_entry)
1448 {
1449 /* Check if Copy & Paste is disabled */
1450 if(!is_object($this->CopyPasteHandler)){
1451 return("");
1452 }
1455 $tabs = array(
1456 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1457 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1458 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1459 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1460 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1461 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1462 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1463 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1464 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1465 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1466 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1467 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1469 /* Add a single entry to queue */
1470 if($s_action == "cut" || $s_action == "copy"){
1472 /* Cleanup object queue */
1473 $this->CopyPasteHandler->cleanup_queue();
1474 $dn = $this->terminals[$s_entry]['dn'];
1475 $oc = $this->terminals[$s_entry]['objectClass'];
1476 $type = $this->get_system_type($this->terminals[$s_entry]);
1478 $tab_o = $tabs[$type]['CLASS'];
1479 $tab_c = $tabs[$type]['TABCLASS'];
1480 $acl = $tabs[$type]['ACL'];
1482 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1483 }
1485 /* Add entries to queue */
1486 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1488 /* Cleanup object queue */
1489 $this->CopyPasteHandler->cleanup_queue();
1491 /* Add new entries to CP queue */
1492 foreach($this->list_get_selected_items() as $id){
1493 $dn = $this->terminals[$id]['dn'];
1494 $oc = $this->terminals[$id]['objectClass'];
1495 $type = $this->get_system_type($this->terminals[$id]);
1497 if(isset($tabs[$type])){
1498 $tab_o = $tabs[$type]['CLASS'];
1499 $tab_c = $tabs[$type]['TABCLASS'];
1500 $acl = $tabs[$type]['ACL'];
1502 if($s_action == "copy_multiple"){
1503 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1504 }
1505 if($s_action == "cut_multiple"){
1506 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1507 }
1508 }
1509 }
1510 }
1512 /* Start pasting entries */
1513 if($s_action == "editPaste"){
1514 $this->start_pasting_copied_objects = TRUE;
1515 }
1517 /* Return C&P dialog */
1518 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1520 /* Get dialog */
1521 $data = $this->CopyPasteHandler->execute();
1522 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1524 /* Return dialog data */
1525 if(!empty($data)){
1526 return($data);
1527 }
1528 }
1530 /* Automatically disable status for pasting */
1531 if(!$this->CopyPasteHandler->entries_queued()){
1532 $this->start_pasting_copied_objects = FALSE;
1533 }
1534 return("");
1535 }
1538 function get_system_type($attrs)
1539 {
1540 $classes = $attrs['objectClass'];
1542 $type= "";
1543 if (in_array_ics('ieee802Device', $classes)){
1544 $type= "component";
1545 }elseif (in_array_ics('gotoTerminal', $classes)){
1546 $type= "terminal";
1547 }elseif (in_array_ics('gotoWorkstation', $classes)){
1548 $type= "workstation";
1549 }elseif (in_array_ics('gotoPrinter', $classes)){
1550 $type= "printer";
1551 }elseif (in_array_ics('goFonHardware', $classes)){
1552 $type= "phone";
1553 }elseif (in_array_ics('goServer', $classes)){
1554 $type= "server";
1555 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1556 $type= "ArpNewDevice";
1557 }elseif (in_array_ics('GOhard', $classes)){
1558 $type= "NewDevice";
1559 }elseif (in_array_ics('sambaAccount', $classes) ||
1560 in_array_ics('sambaSamAccount', $classes)){
1561 $type= "winstation";
1562 }
1563 return ($type);
1564 }
1567 function convert_list($input)
1568 {
1569 $temp= "";
1571 $conv= array(
1572 "D" => array("select_default.png",_("Template")),
1573 "F" => array("select_phone.png",_("Phone")),
1574 "C" => array("select_component.png",_("Network device")),
1575 "P" => array("select_printer.png",_("Printer")),
1577 "W" => array("select_winstation.png",_("Win workstation")),
1579 "L" => array("select_workstation.png",_("Workstation")),
1580 "S" => array("select_server.png",_("Server")),
1581 "T" => array("select_terminal.png",_("Terminal")),
1583 "LX" => array("workstation_locked.png",_("Locked workstation")),
1584 "SX" => array("server_locked.png",_("Locked server")),
1585 "TX" => array("terminal_locked.png",_("Locked terminal")),
1587 "LE" => array("workstation_error.png",_("Workstation error")),
1588 "SE" => array("server_error.png",_("Server error")),
1589 "TE" => array("terminal_error.png",_("Terminal error")),
1591 "LB" => array("workstation_busy.png",_("Workstation busy")),
1592 "SB" => array("server_busy.png",_("Server busy")),
1594 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1595 "NT"=> array("select_new_terminal.png",_("New terminal")),
1596 "NL"=> array("select_new_workstation.png",_("New workstation")));
1598 /* Use locked icons
1599 */
1600 if( in_array($input['type'],array("S","T","L")) &&
1601 isset($input['gotoMode'][0]) &&
1602 preg_match("/locked/",$input['gotoMode'][0])){
1603 $input['type'].="X";
1604 } elseif(in_array($input['type'],array("S","L")) &&
1605 isset($input['FAIstate'][0])){
1607 /* Add FAI state icons
1608 */
1609 $type= "";
1610 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1611 case 'error':
1612 $type= 'E';
1613 break;
1614 case 'installing':
1615 case 'install':
1616 case 'sysinfo':
1617 case 'softupdate':
1618 case 'scheduledupdate':
1619 $type= 'B';
1620 break;
1621 }
1623 $input['type'].= $type;
1624 }
1626 /* Use new images if object is from incoming
1627 */
1628 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1629 $input['type']="N".$input['type'];
1630 }
1632 /* Check which flags this objects uses
1633 */
1634 foreach ($conv as $key => $value){
1635 $found = TRUE;
1636 if(strlen($key) != strlen($input['type'])) {
1637 $found = FALSE;
1638 }
1639 for($i = 0 ; $i < strlen($key) ; $i++){
1640 if(!preg_match("/".$key[$i]."/",$input['type'])){
1641 $found = FALSE;
1642 }
1643 }
1645 if($found){
1646 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1647 $tmp['class']=$key;
1648 return $tmp;
1649 }
1650 }
1651 }
1654 function list_get_selected_items()
1655 {
1656 $ids = array();
1657 foreach($_POST as $name => $value){
1658 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1659 $id = preg_replace("/^item_selected_/","",$name);
1660 $ids[$id] = $id;
1661 }
1662 }
1663 return($ids);
1664 }
1667 /* !! Incoming dummy acls, required to defined acls for incoming objects
1668 */
1669 static function plInfo()
1670 {
1671 return (array(
1672 "plShortName" => _("Incoming objects"),
1673 "plDescription" => _("Incoming objects"),
1674 "plSelfModify" => FALSE,
1675 "plDepends" => array(),
1676 "plPriority" => 99,
1677 "plSection" => array("administration"),
1678 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1679 "objectClass" => "")),
1680 "plProvidedAcls"=> array()
1682 ));
1683 }
1688 }
1690 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1691 ?>