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 $dn){
317 /* Load permissions for selected 'dn' and check if
318 we're allowed to create this 'dn' */
319 $this->dn = $dn;
320 $ui = get_userinfo();
321 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
323 /* We are allowed to create the requested system type */
324 if(preg_match("/c/",$tabacl)){
325 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
326 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
327 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
328 $this->systab->base = $this->DivListSystem->selectedBase;
330 /*******
331 * Set gotoMode to active if we there was an ogroup selected.
332 */
333 $found = false;
334 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
335 if(isset($this->systab->by_object[$tab]->gotoMode)) {
336 $found = true;
337 $this->systab->by_object[$tab]->gotoMode = $value;
338 }
339 }
340 if(!$found){
341 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
342 }
345 if($selected_group != "none"){
347 /*******
348 * Update object group membership
349 */
350 $og = new ogroup($this->config,$selected_group);
351 if($og){
352 $og->AddDelMembership($this->systab->dn);
353 $og->save();
354 }
356 /*******
357 * Set default system specific attributes
358 */
359 foreach (array("workservice", "termservice") as $cls){
360 if (isset($this->systab->by_object[$cls])){
361 $this->systab->by_object[$cls]->gotoXMouseport= "";
362 $this->systab->by_object[$cls]->gotoXMouseType= "";
363 $this->systab->by_object[$cls]->gotoXResolution= "";
364 $this->systab->by_object[$cls]->gotoXColordepth= "";
365 }
366 }
367 }
370 // Enable activation
371 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
372 if (isset($this->systab->by_object[$cls])){
373 $this->systab->by_object["workstartup"]->auto_activate= TRUE;
374 }
375 }
377 // Enable sending of LDAP events
378 if (isset($this->systab->by_object["workstartup"])){
379 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
380 }
382 /* Don't save directly if there is no objectGroup selected.
383 The user will then be able to configure the missing attributes
384 on his own.
385 */
386 if($selected_group != "none"){
387 $this->systab->save();
388 $this->systab = NULL;
390 if(!isset($ldap)){
391 $ldap = $this->config->get_ldap_link();
392 }
393 $ldap->cd ($this->dn);
394 $ldap->cat($this->dn, array('dn'));
395 if(count($ldap->fetch())){
396 $ldap->cd($this->dn);
397 $ldap->rmDir($this->dn);
398 }
399 }
400 }else{
401 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
402 }
403 }
404 }
405 }
408 if (isset($_POST['create_system'])||$s_action=="newsystem") {
410 /* If the current entry is an incoming object
411 * $sw = System type as posted in new incoming handling dialog
412 */
413 if(isset($_POST['system'])){
414 $sw = $_POST['system'];
415 }else{
416 $sw = $s_entry;
417 }
418 $this->dn= "new";
420 $tabs = array(
421 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
422 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
423 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
424 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
425 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
426 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
428 if(isset($tabs[$sw])){
429 $class = $tabs[$sw]["CLASS"];
430 $tabname = $tabs[$sw]["TABNAME"];
431 $tabclass = $tabs[$sw]["TABCLASS"];
432 $acl_cat = $tabs[$sw]["ACL"];
434 /* Load permissions for selected 'dn' and check if
435 we're allowed to remove this 'dn' */
436 $ui = get_userinfo();
437 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
438 if(preg_match("/c/",$tabacl)){
439 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
440 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
441 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
442 $this->systab->base = $this->DivListSystem->selectedBase;
443 }else{
444 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
445 }
446 }
447 }
450 /********************
451 System activation
452 ********************/
454 /* User wants to edit data? */
455 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
456 $this->system_activation_object = array();
457 foreach($this->list_get_selected_items() as $id) {
458 $obj = $this->terminals[$id];
459 $type= $this->get_system_type($obj);
460 if($type == "NewDevice"){
461 $this->system_activation_object[] = $obj['dn'];
462 }
463 }
464 if(count($this->system_activation_object)){
465 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
466 }
467 }
470 /********************
471 Edit system ...
472 ********************/
474 /* User wants to edit data? */
475 if (($s_action == "edit") && (!isset($this->systab->config))){
477 $this->dn= $this->terminals[$s_entry]['dn'];
479 /* Check locking, save current plugin in 'back_plugin', so
480 the dialog knows where to return. */
481 if (($user= get_lock($this->dn)) != ""){
482 return(gen_locked_message ($user, $this->dn));
483 }
485 /* Find out more about the object type */
486 $ldap= $this->config->get_ldap_link();
487 $ldap->cat($this->dn, array('objectClass','gotoMode'));
488 $attrs= $ldap->fetch();
489 $type= $this->get_system_type($attrs);
491 /* Lock the current entry, so everyone will get the
492 above dialog */
493 $tabs = array(
494 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
495 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
496 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
497 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
498 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
499 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
500 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
503 if($type == "ArpNewDevice"){
504 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
505 }elseif($type == "NewDevice"){
506 $this->system_activation_object= array($this->dn);
507 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
508 }elseif(isset($tabs[$type])){
510 $class = $tabs[$type]["CLASS"];
511 $acl_cat = $tabs[$type]["ACL"];
512 $tabclass = $tabs[$type]["TABCLASS"];
514 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
515 $this->systab->set_acl_base($this->dn);
516 session::set('objectinfo',$this->dn);
517 add_lock ($this->dn, $this->ui->dn);
518 }else{
519 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
520 $this->remove_lock();
521 }
522 }
525 /********************
526 Change password ...
527 ********************/
529 /* Set terminals root password */
530 if ($s_action=="change_pw"){
531 $tabs = array(
532 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
533 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
534 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
535 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
536 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
537 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
538 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
539 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
540 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
542 $dn = $this->terminals[$s_entry]['dn'];
543 $type = $this->get_system_type($this->terminals[$s_entry]);
545 $class = $tabs[$type]["CLASS"];
546 $acl = $tabs[$type]["ACL"];
547 $tabclass = $tabs[$type]["TABCLASS"];
548 $ui = get_userinfo();
549 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
550 if(preg_match("/w/",$tabacl)){
551 $this->dn= $this->terminals[$s_entry]['dn'];
552 session::set('objectinfo',$this->dn);
553 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
554 }else{
555 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
556 }
557 }
560 /********************
561 Password change finish, but check if entered data is ok
562 ********************/
564 /* Correctly specified? */
565 if (isset($_POST['password_finish'])){
566 if ($_POST['new_password'] != $_POST['repeated_password']){
567 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
568 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
569 }
570 }
572 /********************
573 Password change finish
574 ********************/
576 /* Change terminal password */
577 if (isset($_POST['password_finish']) &&
578 $_POST['new_password'] == $_POST['repeated_password']){
580 /* Check if user is allowed to set password */
581 $tabs = array(
582 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
583 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
584 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
585 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
587 /* Detect object type */
588 $type = "";
589 foreach($this->terminals as $terminal){
590 if($terminal['dn'] == $this->dn){
591 $type = $this->get_system_type($terminal);
592 break;
593 }
594 }
596 /* Type detected */
597 $allow_for = array("terminal","workstation","server","component");
598 if(!empty($type) && in_array($type,$allow_for)){
600 /* Get infos */
601 $plug = $tabs[$type]["PLUG"];
602 $class = $tabs[$type]["CLASS"];
603 $acl = $tabs[$type]["ACL"];
604 $tabclass = $tabs[$type]["TABCLASS"];
606 /* Get acls */
607 $ui = get_userinfo();
608 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
610 /* Check acls */
611 if(preg_match("/w/",$tabacl)){
612 $ldap = $this->config->get_ldap_link();
613 $ldap->cd($this->dn);
614 $ldap->cat($this->dn);
615 $old_attrs = $ldap->fetch();
617 $attrs= array();
618 if ($_POST['new_password'] == ""){
620 /* Remove password attribute
621 */
622 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
623 $attrs['objectClass'] = array();
624 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
625 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
626 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
627 }
628 }
629 }
630 $attrs['userPassword']= array();
631 } else {
633 /* Add/modify password attribute
634 */
635 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
636 $attrs['objectClass'] = array();
637 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
638 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
639 }
640 $attrs['objectClass'][] = "simpleSecurityObject";
641 }
643 if(class_available("passwordMethodCrypt")){
644 $pwd_m = new passwordMethodCrypt($this->config);
645 $pwd_m->set_hash("crypt/md5");
646 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
647 }else{
648 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
649 $attrs = array();
650 }
651 }
652 $ldap->modify($attrs);
653 if (!$ldap->success()){
654 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
655 }else{
656 if(class_available($plug)){
657 $p = new $plug($this->config,$this->dn);
658 $p->handle_post_events("modify");
659 }
660 }
662 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
663 }else{
664 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
665 }
666 }else{
667 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
668 }
669 session::un_set('objectinfo');
670 }
673 /********************
674 Delete system cancel
675 ********************/
677 /* Delete terminal canceled? */
678 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
679 $this->remove_lock();
680 session::un_set('objectinfo');
681 }
684 /********************
685 Action(s) for MULTIPLE
686 ********************/
688 /********************
689 SCHEDULE action in GOsa Daemon
690 ********************/
692 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
693 $this->dns = array();
694 $ids = $this->list_get_selected_items();
696 if(count($ids)){
697 $mac= array();
699 $ldap = $this->config->get_ldap_link();
700 foreach($ids as $id){
701 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
702 $attrs= $ldap->fetch();
703 if (isset($attrs['macAddress'][0])){
704 $mac[]= $attrs['macAddress'][0];
705 }
706 }
707 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
708 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
709 $o_queue = new gosaSupportDaemon();
711 /* Skip installation or update trigerred events,
712 * if this entry is currently processing.
713 */
714 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
715 foreach($mac as $key => $mac_address){
716 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
718 $entry['STATUS'] = strtoupper($entry['STATUS']);
719 if($entry['STATUS'] == "PROCESSING" &&
720 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
721 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
722 unset($mac[$key]);
724 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
725 break;
726 }
727 }
728 }
729 }
731 /* Prepare event to be added
732 */
733 if(count($mac) && isset($events['BY_CLASS'][$type])){
734 $event = $events['BY_CLASS'][$type];
735 $this->systab = new $event['CLASS_NAME']($this->config);
736 $this->systab->add_targets($mac);
737 if(preg_match("/trigger_event/",$s_action)){
738 $this->systab->set_type(TRIGGERED_EVENT);
739 }else{
740 $this->systab->set_type(SCHEDULED_EVENT);
741 }
742 }
743 }
744 }
746 /* Insert scheduled events into queue */
747 if($this->systab instanceof DaemonEvent){
748 $this->systab->save_object();
750 /* Save event
751 */
752 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
753 $o_queue = new gosaSupportDaemon();
754 $o_queue->append($this->systab);
755 if($o_queue->is_error()){
756 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
757 }else{
758 $this->systab = FALSE;
759 }
760 }
761 if(isset($_POST['abort_event_dialog'])){
762 $this->systab = FALSE;
763 }
764 }
767 /********************
768 Delete MULTIPLE entries requested, display confirm dialog
769 ********************/
771 if ($s_action=="del_multiple"){
772 $this->dns = array();
773 $ids = $this->list_get_selected_items();
775 if(count($ids)){
777 foreach($ids as $id){
778 $dn = $this->terminals[$id]['dn'];
779 $this->dns[$id] = $dn;
780 }
781 if ($user= get_multiple_locks($this->dns)){
782 return(gen_locked_message($user,$this->dns));
783 }
785 $dns_names = array();
786 foreach($this->dns as $dn){
787 add_lock ($dn, $this->ui->dn);
788 $dns_names[] = @LDAP::fix($dn);
789 }
791 /* Lock the current entry, so nobody will edit it during deletion */
792 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
793 $smarty->assign("multiple", true);
794 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
795 }
796 }
799 /********************
800 Delete MULTIPLE entries confirmed
801 ********************/
803 /* Confirmation for deletion has been passed. Users should be deleted. */
804 if (isset($_POST['delete_multiple_system_confirm'])){
806 $ui = get_userinfo();
807 $tabs = array(
808 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
809 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
810 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
811 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
812 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
813 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
814 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
815 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
816 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
819 /* Remove user by user and check acls before removeing them */
820 foreach($this->dns as $key => $dn){
822 /* Get 'dn' from posted termlinst */
823 $attrs = $this->terminals[$key];
824 $type= $this->get_system_type($attrs);
826 /* get object type */
827 $tabtype = "termtabs";
828 $tabobj = "TERMTABS";
829 $tabacl = "";
830 if(isset($tabs[$type])){
831 $tabtype = $tabs[$type]['TABCLASS'];
832 $tabobj = $tabs[$type]['CLASS'];
833 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
835 /* Load permissions for selected 'dn' and check if
836 we're allowed to remove this 'dn' */
837 if(preg_match("/d/",$tabacl)){
839 /* Delete request is permitted, perform LDAP action */
840 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
841 $this->systab= new termgeneric($this->config, $dn);
842 $this->systab->set_acl_base($dn);
843 $this->systab->remove_from_parent();
844 }elseif($tabtype=="phonetabs"){
845 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
846 $this->systab->set_acl_base($dn);
847 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
848 }else{
849 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
850 $this->systab->set_acl_base($dn);
851 $this->systab->delete();
852 }
853 unset ($this->systab);
854 $this->systab= NULL;
856 } else {
857 /* Normally this shouldn't be reached, send some extra
858 logs to notify the administrator */
859 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
860 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
861 }
862 }
864 /* Remove lock file after successfull deletion */
865 $this->remove_lock();
866 $this->dns = array();
867 }
868 }
870 /********************
871 Delete MULTIPLE entries Canceled
872 ********************/
874 /* Remove lock */
875 if(isset($_POST['delete_multiple_system_cancel'])){
877 /* Remove lock file after successfull deletion */
878 $this->remove_lock();
879 $this->dns = array();
880 }
883 /********************
884 Delete system, confirm dialog
885 ********************/
887 /* Remove terminal was requested */
888 if ($s_action=="del"){
890 /* Get 'dn' from posted termlinst */
891 $this->dn = $this->terminals[$s_entry]['dn'];
892 $attrs = $this->terminals[$s_entry];
896 $type= $this->get_system_type($attrs);
897 $ui = get_userinfo();
898 $tabs = array(
899 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
900 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
901 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
902 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
903 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
904 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
905 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
906 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
907 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
909 /* get object type */
910 $tabtype = "termtabs";
911 $tabobj = "TERMTABS";
912 $tabacl = "";
913 if(isset($tabs[$type])){
914 $tabtype = $tabs[$type]['TABCLASS'];
915 $tabobj = $tabs[$type]['CLASS'];
916 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
917 }
919 /* Load permissions for selected 'dn' and check if
920 we're allowed to remove this 'dn' */
921 if(preg_match("/d/",$tabacl)){
923 /* Check locking, save current plugin in 'back_plugin', so
924 the dialog knows where to return. */
925 if (($user= get_lock($this->dn)) != ""){
926 return(gen_locked_message ($user, $this->dn));
927 }
929 /* Lock the current entry, so nobody will edit it during deletion */
930 add_lock ($this->dn, $this->ui->dn);
931 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
932 $smarty->assign("multiple", false);
933 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
934 } else {
936 /* Obviously the user isn't allowed to delete. Show message and
937 clean session. */
938 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
939 }
940 }
943 /********************
944 Delete system, confirmed
945 ********************/
946 /* Confirmation for deletion has been passed. Terminal should be deleted. */
947 if (isset($_POST['delete_terminal_confirm'])){
949 /* Find out more about the object type */
950 $ldap= $this->config->get_ldap_link();
951 $ldap->cat($this->dn, array('objectClass'));
952 $attrs= $ldap->fetch();
953 $type= $this->get_system_type($attrs);
955 $ui = get_userinfo();
957 $tabs = array(
958 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
959 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
960 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
961 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
962 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
963 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
964 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
965 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
966 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
968 /* get object type */
969 $tabtype = "termtabs";
970 $tabobj = "TERMTABS";
971 $tabacl = "";
972 if(isset($tabs[$type])){
973 $tabtype = $tabs[$type]['TABCLASS'];
974 $tabobj = $tabs[$type]['CLASS'];
975 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
976 }
978 /* Check if we are allowed to remove this object */
979 if(preg_match("/d/",$tabacl)){
981 /* Delete request is permitted, perform LDAP action */
982 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
983 $this->systab= new termgeneric($this->config, $this->dn);
984 $this->systab->set_acl_base($this->dn);
985 $this->systab->remove_from_parent();
986 }elseif($tabtype=="phonetabs"){
987 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
988 $this->systab->set_acl_base($this->dn);
989 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
990 }else{
991 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
992 $this->systab->set_acl_base($this->dn);
993 $this->systab->delete();
994 }
995 unset ($this->systab);
996 $this->systab= NULL;
998 /* Terminal list has changed, reload it. */
999 } else {
1001 /* Normally this shouldn't be reached, send some extra
1002 logs to notify the administrator */
1003 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
1004 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
1005 }
1007 /* Remove lock file after successfull deletion */
1008 $this->remove_lock();
1009 }
1012 /********************
1013 Edit system type finished, check if everything went ok
1014 ********************/
1015 /* Finish user edit is triggered by the tabulator dialog, so
1016 the user wants to save edited data. Check and save at this
1017 point. */
1019 /* Dirty workaround - MSG_DIALOG - OK
1020 If a message dialog is shown and we press 'OK'
1021 then try to save again.
1022 */
1023 foreach($_POST as $name => $value){
1024 if(preg_match("/^MSG_OK/",$name)){
1025 $_POST[$this->last_action] = TRUE;
1026 }
1027 }
1029 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
1031 /* If the save routine gets interrupted by a confirm dialog,
1032 store last action so we can trigger it again after 'Ok' was pressed.
1033 (This is the case if a system gets modified while it is installing - GOsa si)
1034 */
1035 $this->last_action = "";
1036 if(isset($_POST['edit_finish'])){
1037 $this->last_action = "edit_finish";
1038 }elseif(isset($_POST['edit_apply'])){
1039 $this->last_action = "edit_apply";
1040 }
1042 /* Check tabs, will feed message array */
1043 $message = $this->systab->check();
1045 /* Save, or display error message? */
1046 if (count($message) == 0){
1049 $this->systab->save();
1051 /* Terminal has been saved successfully, remove lock from LDAP. */
1052 if (!isset($_POST['edit_apply'])){
1053 if ($this->dn != "new"){
1054 $this->remove_lock();
1055 }
1057 unset ($this->systab);
1058 $this->systab= NULL;
1059 session::un_set('objectinfo');
1060 }else{
1062 /* Reinitialize tab */
1063 if($this->systab instanceof tabs){
1064 $this->systab->re_init();
1065 }
1066 }
1067 } else {
1068 /* Ok. There seem to be errors regarding to the tab data,
1069 show message and continue as usual. */
1070 msg_dialog::displayChecks($message);
1071 }
1072 }
1075 /********************
1076 Edit system was canceled
1077 ********************/
1078 /* Cancel dialogs */
1079 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1080 if (isset($this->systab)){
1081 $this->remove_lock();
1082 unset ($this->systab);
1083 }
1084 $this->systab= NULL;
1085 session::un_set('objectinfo');
1086 }
1088 /********************
1089 Display edit dialog, or some other
1090 ********************/
1092 /* Show tab dialog if object is present */
1093 if (isset($this->systab->config)){
1094 $display= $this->systab->execute();
1096 /* Don't show buttons if tab dialog requests this */
1098 $dialog = FALSE;
1099 $hide_apply = $this->dn == "new";
1100 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1101 if(is_object($this->systab) && !isset($this->systab->by_object)){
1102 $dialog = TRUE;
1103 $hide_apply = TRUE;
1104 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1105 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1106 if($dia === TRUE || is_object($dia)){
1107 $dialog = TRUE;
1108 }
1109 }
1110 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1111 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1112 $dialog = TRUE;
1113 }
1115 if (!$dialog){
1116 $display.= "<p style=\"text-align:right\">\n";
1117 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1118 $display.= " \n";
1119 if (!$hide_apply){
1120 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1121 $display.= " \n";
1122 }
1123 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1124 $display.= "</p>";
1125 }
1126 return ($display);
1127 }
1129 /* Check if there is a snapshot dialog open */
1130 $base = $this->DivListSystem->selectedBase;
1131 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1132 return($str);
1133 }
1135 /* Display dialog with system list */
1136 $this->DivListSystem->parent = $this;
1137 $this->DivListSystem->execute();
1139 /* Add departments if subsearch is disabled */
1140 if(!$this->DivListSystem->SubSearch){
1141 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1142 }
1143 $this->reload();
1144 $this->DivListSystem->setEntries($this->terminals);
1145 return($this->DivListSystem->Draw());
1146 }
1149 /* Return departments, that will be included within snapshot detection */
1150 function get_used_snapshot_bases()
1151 {
1152 $tmp = array();
1154 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1156 $tabs = array(
1157 "terminal" => get_ou('terminalou'),
1158 "workstation" => get_ou('workstationou'),
1159 "incoming" => get_ou('incomingou'),
1160 "server" => get_ou('serverou'),
1161 "printer" => get_ou('printerou'),
1162 "phone" => get_ou('phoneou'),
1163 "winworkstation" => get_winstations_ou(),
1164 "component" => get_ou('componentou')
1165 );
1167 foreach($tabs as $acl_cat => $dn){
1169 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1170 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1171 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1172 }
1173 }
1174 return($tmp);
1175 }
1178 function remove_from_parent()
1179 {
1180 /* Optionally execute a command after we're done */
1181 $this->postremove();
1182 }
1185 /* Save data to object */
1186 function save_object()
1187 {
1188 $this->DivListSystem->save_object();
1189 if(is_object($this->CopyPasteHandler)){
1190 $this->CopyPasteHandler->save_object();
1191 }
1192 }
1195 /* Check values */
1196 function check()
1197 {
1198 }
1201 /* Save to LDAP */
1202 function save()
1203 {
1204 }
1206 function adapt_from_template($dn, $skip= array())
1207 {
1208 }
1210 function password_change_needed()
1211 {
1212 }
1214 function reload()
1215 {
1216 /* some var init */
1217 $ui = get_userinfo();
1218 $res = array();
1219 $this->terminals = array();
1220 $userregex = "";
1222 /* Set base for all searches */
1223 $base= $this->DivListSystem->selectedBase;
1225 /* Prepare samba class name */
1226 $samba ="";
1227 if ($this->DivListSystem->ShowWinWorkstations){
1228 if ($this->config->current['SAMBAVERSION'] == "3"){
1229 $samba= "sambaSamAccount";
1230 } else {
1231 $samba= "sambaAccount";
1232 }
1233 }
1235 /* This array represents the combination between checkboxes and search filters */
1236 $objs = array(
1237 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1238 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1239 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1240 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1241 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1242 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1243 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1245 /* Include the 'Display Systems of user' attribute */
1246 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1247 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1248 }
1250 /* Attributes to fetch */
1251 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1252 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1254 /* Add FAIstate to attributes if FAI is activated */
1255 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1256 if(!empty($tmp)){
1257 $sys_attrs[] = "FAIstate";
1258 }
1260 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1261 foreach($objs as $checkBox => $oc){
1262 if($this->DivListSystem->$checkBox){
1263 if($this->DivListSystem->SubSearch){
1264 if($oc['CLASS'] != ""){
1265 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1266 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1267 $res = array_merge($res,$new_res);
1268 }
1269 }else{
1270 /* User filter? */
1271 if($oc['CLASS'] != ""){
1272 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1273 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1274 }
1275 }
1276 }
1277 }
1279 /* Search for incoming objects */
1280 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1281 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1283 /* Get all gotoTerminal's */
1284 foreach ($res as $value){
1286 $tmp= $value['dn'];
1287 $add= "";
1289 /* Extract base */
1290 foreach($objs as $obj){
1291 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1292 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1293 }
1294 }
1296 /* Create a string containing the last part of the department. */
1297 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1298 if(empty($dn_name)){
1299 $dn_name = "/";
1300 }
1302 /* check if current object is a new one */
1303 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1304 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1305 $add= "- "._("New terminal");
1306 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1307 $add= "- "._("New workstation");
1308 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1309 $add= "- "._("Unknown device");
1310 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1311 $add= "- "._("New Device");
1312 }
1313 }
1315 /* Detect type of object and create an entry for $this->terminals */
1316 $terminal = array();
1317 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1319 /* check acl */
1320 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1321 if($add != "" || preg_match("/r/",$acl)) {
1322 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1323 $terminal = $value;
1324 $terminal['type'] = "T";
1325 $terminal['is_new'] = $add;
1326 } else {
1327 $terminal = $value;
1328 $terminal['type'] = "D";
1329 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1330 $terminal['location'] = array_search($tmp, $this->config->departments);
1331 }
1332 }
1333 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1335 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1336 if($add != "" || preg_match("/r/",$acl)) {
1337 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1338 $terminal = $value;
1339 $terminal['type'] = "L";
1340 $terminal['is_new'] = $add;
1341 } else {
1342 $terminal = $value;
1343 $terminal['type'] = "D";
1344 $terminal['location'] = array_search($tmp, $this->config->departments);
1345 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1346 }
1347 # if (isset($value["FAIstate"][0])){
1348 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1349 # }
1350 }
1351 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1354 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1355 if($add != "" || preg_match("/r/",$acl)) {
1357 $terminal = $value;
1358 $terminal['type'] = "P";
1359 }
1360 } elseif (in_array_ics('goServer', $value["objectClass"])){
1362 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1363 if($add != "" || preg_match("/r/",$acl)) {
1365 $terminal = $value;
1366 $terminal['type'] = "S";
1367 # if (isset($value["FAIstate"][0])){
1368 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1369 # }
1370 }
1371 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1373 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1374 if($add != "" || preg_match("/r/",$acl)) {
1376 $terminal = $value;
1377 $terminal['type'] = "F";
1378 }
1379 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1381 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1382 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1383 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1384 if($add != "" || preg_match("/r/",$acl)) {
1386 $terminal = $value;
1387 $terminal['type'] = "Q";
1388 $terminal['is_new'] = $add;
1389 }
1390 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1392 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1393 if($add != "" || preg_match("/r/",$acl)) {
1395 $terminal = $value;
1396 $terminal['type'] = "C";
1397 }
1398 } else{
1400 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1401 if (isset($value['sambaDomainName'])){
1402 $domain= " [".$value['sambaDomainName'][0]."]";
1403 } else {
1404 $domain= "";
1405 }
1406 $terminal=$value;
1407 $terminal['type'] ="W";
1408 $terminal['domain'] = $name.$domain;
1409 }
1411 if(count($terminal)){
1412 $this->terminals[]=$terminal;
1413 }
1414 }
1416 $tmp =array();
1417 $tmp2 =array();
1418 foreach($this->terminals as $tkey => $val ){
1419 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1420 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1421 }
1422 natcasesort($tmp2);
1423 $this->terminals=array();
1424 foreach($tmp2 as $val){
1425 $this->terminals[]=$tmp[$val];
1426 }
1427 reset ($this->terminals);
1428 }
1430 function remove_lock()
1431 {
1432 if (isset($this->systab->dn)){
1433 del_lock ($this->systab->dn);
1434 }
1435 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1436 del_lock($this->dn);
1437 }
1438 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1439 del_lock($this->dns);
1440 }
1441 }
1444 function copyPasteHandling_from_queue($s_action,$s_entry)
1445 {
1446 /* Check if Copy & Paste is disabled */
1447 if(!is_object($this->CopyPasteHandler)){
1448 return("");
1449 }
1452 $tabs = array(
1453 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1454 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1455 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1456 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1457 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1458 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1459 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1460 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1461 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1462 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1463 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1464 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1466 /* Add a single entry to queue */
1467 if($s_action == "cut" || $s_action == "copy"){
1469 /* Cleanup object queue */
1470 $this->CopyPasteHandler->cleanup_queue();
1471 $dn = $this->terminals[$s_entry]['dn'];
1472 $oc = $this->terminals[$s_entry]['objectClass'];
1473 $type = $this->get_system_type($this->terminals[$s_entry]);
1475 $tab_o = $tabs[$type]['CLASS'];
1476 $tab_c = $tabs[$type]['TABCLASS'];
1477 $acl = $tabs[$type]['ACL'];
1479 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1480 }
1482 /* Add entries to queue */
1483 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1485 /* Cleanup object queue */
1486 $this->CopyPasteHandler->cleanup_queue();
1488 /* Add new entries to CP queue */
1489 foreach($this->list_get_selected_items() as $id){
1490 $dn = $this->terminals[$id]['dn'];
1491 $oc = $this->terminals[$id]['objectClass'];
1492 $type = $this->get_system_type($this->terminals[$id]);
1494 if(isset($tabs[$type])){
1495 $tab_o = $tabs[$type]['CLASS'];
1496 $tab_c = $tabs[$type]['TABCLASS'];
1497 $acl = $tabs[$type]['ACL'];
1499 if($s_action == "copy_multiple"){
1500 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1501 }
1502 if($s_action == "cut_multiple"){
1503 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1504 }
1505 }
1506 }
1507 }
1509 /* Start pasting entries */
1510 if($s_action == "editPaste"){
1511 $this->start_pasting_copied_objects = TRUE;
1512 }
1514 /* Return C&P dialog */
1515 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1517 /* Get dialog */
1518 $data = $this->CopyPasteHandler->execute();
1519 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1521 /* Return dialog data */
1522 if(!empty($data)){
1523 return($data);
1524 }
1525 }
1527 /* Automatically disable status for pasting */
1528 if(!$this->CopyPasteHandler->entries_queued()){
1529 $this->start_pasting_copied_objects = FALSE;
1530 }
1531 return("");
1532 }
1535 function get_system_type($attrs)
1536 {
1537 $classes = $attrs['objectClass'];
1539 $type= "";
1540 if (in_array_ics('ieee802Device', $classes)){
1541 $type= "component";
1542 }elseif (in_array_ics('gotoTerminal', $classes)){
1543 $type= "terminal";
1544 }elseif (in_array_ics('gotoWorkstation', $classes)){
1545 $type= "workstation";
1546 }elseif (in_array_ics('gotoPrinter', $classes)){
1547 $type= "printer";
1548 }elseif (in_array_ics('goFonHardware', $classes)){
1549 $type= "phone";
1550 }elseif (in_array_ics('goServer', $classes)){
1551 $type= "server";
1552 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1553 $type= "ArpNewDevice";
1554 }elseif (in_array_ics('GOhard', $classes)){
1555 $type= "NewDevice";
1556 }elseif (in_array_ics('sambaAccount', $classes) ||
1557 in_array_ics('sambaSamAccount', $classes)){
1558 $type= "winstation";
1559 }
1560 return ($type);
1561 }
1564 function convert_list($input)
1565 {
1566 $temp= "";
1568 $conv= array(
1569 "D" => array("select_default.png",_("Template")),
1570 "F" => array("select_phone.png",_("Phone")),
1571 "C" => array("select_component.png",_("Network device")),
1572 "P" => array("select_printer.png",_("Printer")),
1574 "W" => array("select_winstation.png",_("Win workstation")),
1576 "L" => array("select_workstation.png",_("Workstation")),
1577 "S" => array("select_server.png",_("Server")),
1578 "T" => array("select_terminal.png",_("Terminal")),
1580 "LX" => array("workstation_locked.png",_("Locked workstation")),
1581 "SX" => array("server_locked.png",_("Locked server")),
1582 "TX" => array("terminal_locked.png",_("Locked terminal")),
1584 "LE" => array("workstation_error.png",_("Workstation error")),
1585 "SE" => array("server_error.png",_("Server error")),
1586 "TE" => array("terminal_error.png",_("Terminal error")),
1588 "LB" => array("workstation_busy.png",_("Workstation busy")),
1589 "SB" => array("server_busy.png",_("Server busy")),
1591 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1592 "NT"=> array("select_new_terminal.png",_("New terminal")),
1593 "NL"=> array("select_new_workstation.png",_("New workstation")));
1595 /* Use locked icons
1596 */
1597 if( in_array($input['type'],array("S","T","L")) &&
1598 isset($input['gotoMode'][0]) &&
1599 preg_match("/locked/",$input['gotoMode'][0])){
1600 $input['type'].="X";
1601 } elseif(in_array($input['type'],array("S","L")) &&
1602 isset($input['FAIstate'][0])){
1604 /* Add FAI state icons
1605 */
1606 $type= "";
1607 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1608 case 'error':
1609 $type= 'E';
1610 break;
1611 case 'installing':
1612 case 'install':
1613 case 'sysinfo':
1614 case 'softupdate':
1615 case 'scheduledupdate':
1616 $type= 'B';
1617 break;
1618 }
1620 $input['type'].= $type;
1621 }
1623 /* Use new images if object is from incoming
1624 */
1625 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1626 $input['type']="N".$input['type'];
1627 }
1629 /* Check which flags this objects uses
1630 */
1631 foreach ($conv as $key => $value){
1632 $found = TRUE;
1633 if(strlen($key) != strlen($input['type'])) {
1634 $found = FALSE;
1635 }
1636 for($i = 0 ; $i < strlen($key) ; $i++){
1637 if(!preg_match("/".$key[$i]."/",$input['type'])){
1638 $found = FALSE;
1639 }
1640 }
1642 if($found){
1643 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1644 $tmp['class']=$key;
1645 return $tmp;
1646 }
1647 }
1648 }
1651 function list_get_selected_items()
1652 {
1653 $ids = array();
1654 foreach($_POST as $name => $value){
1655 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1656 $id = preg_replace("/^item_selected_/","",$name);
1657 $ids[$id] = $id;
1658 }
1659 }
1660 return($ids);
1661 }
1664 /* !! Incoming dummy acls, required to defined acls for incoming objects
1665 */
1666 static function plInfo()
1667 {
1668 return (array(
1669 "plShortName" => _("Incoming objects"),
1670 "plDescription" => _("Incoming objects"),
1671 "plSelfModify" => FALSE,
1672 "plDepends" => array(),
1673 "plPriority" => 99,
1674 "plSection" => array("administration"),
1675 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1676 "objectClass" => "")),
1677 "plProvidedAcls"=> array()
1679 ));
1680 }
1685 }
1687 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1688 ?>