1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class systems extends plugin
24 {
25 /* Definitions */
26 var $plHeadline = "Systems";
27 var $plDescription = "This does something";
28 var $plIcon = "plugins/systems/images/plugin.png";
29 var $departments = array();
31 /* Dialog attributes */
32 var $systab = NULL;
33 var $terminals= array();
34 var $ui = NULL;
35 var $DivListSystem;
36 var $start_pasting_copied_objects = FALSE;
37 var $CopyPasteHandler = NULL;
39 /* Arp hanlding activated */
40 var $arp_handling_active = FALSE;
41 var $last_action = "";
43 var $dns = array();
45 var $system_activation_object = ""; // The object to activate (NewDevice)
46 var $fai_activated = FALSE;
47 var $si_active = FALSE;
49 var $acl_module = array("incoming","terminal","workstation","server","printer","phone","winworkstation","component");
51 function systems (&$config, $ui)
52 {
53 /* Save configuration for internal use */
54 $this->config= $config;
55 $this->ui= $ui;
57 /* Add FAIstate to attributes if FAI is activated */
58 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
59 if(!empty($tmp)){
60 $this->fai_activated = TRUE;
61 }
63 /* Creat dialog object */
64 $this->DivListSystem = new divListSystem($this->config,$this);
66 /* Copy & Paste enabled ?*/
67 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
68 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
69 }
71 /* Check whether the arp handling active or not */
72 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
73 $this->arp_handling_active = TRUE;
74 }
76 /* Check if we are able to communicate with the GOsa supprot daemon
77 */
78 if(class_available("gosaSupportDaemon")){
79 $o = new gosaSupportDaemon();
80 $this->si_active = $o->connect() && class_available("DaemonEvent");
81 }
82 }
85 function execute()
86 {
87 /* Call parent execute */
88 plugin::execute();
90 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
92 /********************
93 Check for functional posts, edit|delete|add|... system devices
94 ********************/
95 $s_action = ""; // Contains the action to proceed
96 $s_entry = ""; // The value for s_action
97 $base_back = ""; // The Link for Backbutton
98 $smarty = get_smarty();
100 /* Test Posts */
101 foreach($_POST as $key => $val){
102 // Post for delete
103 if(preg_match("/system_del.*/",$key)){
104 $s_action = "del";
105 $s_entry = preg_replace("/system_del_/i","",$key);
106 // Post for edit
107 }elseif(preg_match("/system_edit_.*/",$key)){
108 $s_action="edit";
109 $s_entry = preg_replace("/system_edit_/i","",$key);
110 // Post for new
111 }elseif(preg_match("/system_new.*/",$key)){
112 $s_action="new";
113 }elseif(preg_match("/system_tplnew.*/i",$key)){
114 $s_action="new_tpl";
115 }elseif(preg_match("/system_setpwd_.*/i",$key)){
116 $s_action="change_pw";
117 $s_entry = preg_replace("/system_setpwd_/i","",$key);
118 }elseif(preg_match("/gen_cd_.*/i",$key)){
119 $s_action="gen_cd";
120 $s_entry = preg_replace("/gen_cd_/i","",$key);
121 }elseif(preg_match("/^copy_.*/",$key)){
122 $s_action="copy";
123 $s_entry = preg_replace("/^copy_/i","",$key);
124 }elseif(preg_match("/^cut_.*/",$key)){
125 $s_action="cut";
126 $s_entry = preg_replace("/^cut_/i","",$key);
127 }
128 }
130 /* remove image tags from posted entry (posts looks like this 'name_x')*/
131 $s_entry = preg_replace("/_.$/","",$s_entry);
133 /* Edit was requested by pressing the name(link) of an item */
134 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
135 $s_action ="edit";
136 $s_entry = $_GET['id'];
137 }
138 /* Create options */
139 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
140 $s_action = "newsystem";
141 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
142 }
144 /* handle C&P from layers menu */
145 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
146 $s_action = "copy_multiple";
147 }
148 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
149 $s_action = "cut_multiple";
150 }
151 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
152 $s_action = "editPaste";
153 }
155 /* Handle daemon events */
156 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
157 $s_action = $_POST['menu_action'];
158 }
160 /* Handle daemon events */
161 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
162 $s_action = $_POST['menu_action'];
163 }
165 /* handle remove from layers menu */
166 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
167 $s_action = "del_multiple";
168 }
170 /* Handle instant actions from layers menu */
171 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
172 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
173 $s_action = "${act}_multiple";
174 }
175 }
177 /* Activate multiple machines */
178 if(isset($_POST['menu_action']) && preg_match("/^activate_multiple/",$_POST['menu_action'])){
179 $s_action = "activate_multiple";
180 }
182 /* Check for exeeded sizelimit */
183 if (($message= check_sizelimit()) != ""){
184 return($message);
185 }
187 /* Try to get informations about what kind of system to create */
188 if ($s_action=="new") {
189 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
190 }
192 /* Incoming handling
193 * If someone made a systemtype and ogroup selection
194 * Display the new requested entry type ... servtab in case of server and so on.
195 */
196 if(isset($_POST['SystemTypeChoosen'])){
197 $s_action = "SelectedSystemType";
198 }
200 /********************
201 Copy & Paste Handling ...
202 ********************/
204 /* Display the copy & paste dialog, if it is currently open */
205 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
206 if($ret){
207 return($ret);
208 }
211 /********************
212 Create FAI CD ...
213 ********************/
214 if ($s_action=="gen_cd"){
215 $this->dn= $this->terminals[$s_entry]['dn'];
216 session::set('objectinfo',$this->dn);
217 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
218 }
221 /* Start CD-Creation */
222 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
223 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
224 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
225 }
228 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
230 $return_button = "<form method='get' action='main.php' target='_parent'>
231 <input type='submit' value='"._("Back")."'>
232 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
233 </form>";
235 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
237 /* Get and check command */
238 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
240 if (check_command($command)){
241 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
243 /* Print out html introduction */
244 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
245 <html>
246 <head>
247 <title></title>
248 <style type="text/css">@import url("themes/default/style.css");</style>
249 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
250 </head>
251 <body style="background: none; margin:4px;" id="body" >
252 <pre>';
254 /* Open process handle and check if it is a valid process */
255 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
256 if (is_resource($process)) {
257 fclose($pipes[0]);
259 /* Print out returned lines && write JS to scroll down each line */
260 while (!feof($pipes[1])){
261 $cur_dat = fgets($pipes[1], 1024);
262 echo $cur_dat;
263 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
264 flush();
265 }
266 }
268 /* Get error string && close streams */
269 $buffer= stream_get_contents($pipes[2]);
271 fclose($pipes[1]);
272 fclose($pipes[2]);
273 echo "</pre>";
275 /* Check return code */
276 $ret= proc_close($process);
277 if ($ret != 0){
278 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
279 echo "<pre style='color:red'>$buffer</pre>";
280 }
284 echo $return_button."<br>";
286 } else {
287 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
288 echo $tmp;
289 }
291 /* Scroll down completly */
292 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
293 echo '</body></html>';
294 flush();
295 exit;
296 }
299 /********************
300 New Device hanlding (Ogroup/System select dialog.)
301 ********************/
303 if($s_action == "SelectedSystemType"){
305 /* Possible destination system types
306 */
307 $tabs = array(
308 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric",
309 "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
310 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric",
311 "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
312 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric",
313 "TABCLASS" =>"servtabs", "ACL"=> "server"));
315 /* Remember dialog selection.
316 */
317 $selected_group = $_POST['ObjectGroup'];
318 $selected_system = $_POST['SystemType'];
320 $this->systab = NULL;
322 /* Check if system type exists. It should! */
323 if(isset($tabs[$selected_system])){
325 /* Get tab informations */
326 $class = $tabs[$selected_system]["CLASS"];
327 $tabname = $tabs[$selected_system]["TABNAME"];
328 $tabclass = $tabs[$selected_system]["TABCLASS"];
329 $acl_cat = $tabs[$selected_system]["ACL"];
332 if(!class_available($tabclass)){
333 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
334 }else{
336 /* Go through all objects that should be activated */
337 foreach($this->system_activation_object as $key => $dn){
339 /* Remove entry from list, to avoid page-reload problems */
340 unset($this->system_activation_object[$key]);
342 /* Load permissions for selected 'dn' and check if
343 we're allowed to create this 'dn' */
344 $this->dn = $dn;
345 $ui = get_userinfo();
346 $tabacl = $ui->get_permissions($this->dn,$acl_cat."/".$tabname);
348 /* We are allowed to create the requested system type */
349 if(preg_match("/c/",$tabacl)){
350 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$selected_system);
351 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
352 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
353 $this->systab->base = $this->DivListSystem->selectedBase;
356 if($selected_group != "none"){
358 /*******
359 * Set gotoMode to active if we there was an ogroup selected.
360 */
361 $found = false;
362 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
363 if(isset($this->systab->by_object[$tab]->gotoMode)) {
364 $found = true;
365 $this->systab->by_object[$tab]->gotoMode = $value;
366 }
367 }
368 if(!$found){
369 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
370 }
372 /*******
373 * Update object group membership
374 */
375 $og = new ogroup($this->config,$selected_group);
376 if($og){
377 $og->AddDelMembership($this->systab->dn);
378 $og->save();
379 }
381 /*******
382 * Set default system specific attributes
383 */
384 foreach (array("workservice", "termservice") as $cls){
385 if (isset($this->systab->by_object[$cls])){
386 $this->systab->by_object[$cls]->gotoXMouseport= "";
387 $this->systab->by_object[$cls]->gotoXMouseType= "";
388 $this->systab->by_object[$cls]->gotoXResolution= "";
389 $this->systab->by_object[$cls]->gotoXColordepth= "";
390 }
391 }
393 // Enable activation
394 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
395 if (isset($this->systab->by_object[$cls])){
396 $this->systab->by_object[$cls]->auto_activate= TRUE;
397 }
398 }
400 // Enable sending of LDAP events
401 if (isset($this->systab->by_object["workstartup"])){
402 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
403 }
404 }
406 /* Don't save directly if there is no objectGroup selected.
407 The user will then be able to configure the missing attributes
408 on his own.
409 */
410 if($selected_group != "none"){
411 $this->systab->save();
412 $this->systab = NULL;
414 if(!isset($ldap)){
415 $ldap = $this->config->get_ldap_link();
416 }
417 $ldap->cd ($this->dn);
418 $ldap->cat($this->dn, array('dn'));
419 if(count($ldap->fetch())){
420 $ldap->cd($this->dn);
421 $ldap->rmDir($this->dn);
422 }
423 }
424 }else{
425 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
426 }
427 }
428 }
429 }
430 }
433 if (isset($_POST['create_system'])||$s_action=="newsystem") {
435 $this->last_action = "";
437 /* If the current entry is an incoming object
438 * $sw = System type as posted in new incoming handling dialog
439 */
440 if(isset($_POST['system'])){
441 $sw = $_POST['system'];
442 }else{
443 $sw = $s_entry;
444 }
445 $this->dn= "new";
447 $tabs = array(
448 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
449 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
450 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
451 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
452 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
453 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
455 if(isset($tabs[$sw])){
456 $class = $tabs[$sw]["CLASS"];
457 $tabname = $tabs[$sw]["TABNAME"];
458 $tabclass = $tabs[$sw]["TABCLASS"];
459 $acl_cat = $tabs[$sw]["ACL"];
461 /* Load permissions for selected 'dn' and check if
462 we're allowed to remove this 'dn' */
463 $ui = get_userinfo();
464 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
465 if(preg_match("/c/",$tabacl)){
467 if(!class_available($tabclass)){
468 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
469 }else{
470 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
471 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
472 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
473 $this->systab->base = $this->DivListSystem->selectedBase;
474 }
475 }else{
476 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
477 }
478 }
479 }
482 /********************
483 System activation
484 ********************/
486 /* User wants to edit data? */
487 if (($s_action == "activate_multiple") && (!isset($this->systab->config))){
488 $this->system_activation_object = array();
489 foreach($this->list_get_selected_items() as $id) {
490 $obj = $this->terminals[$id];
491 $type= $this->get_system_type($obj);
492 if($type == "NewDevice"){
493 $this->system_activation_object[] = $obj['dn'];
494 }
495 }
496 if(count($this->system_activation_object)){
497 $this->systab = new SelectDeviceType($this->config,$this->system_activation_object) ;
498 }
499 }
502 /********************
503 Edit system ...
504 ********************/
506 /* User wants to edit data? */
507 if (($s_action == "edit") && (!isset($this->systab->config))){
508 $this->last_action = "";
509 $this->dn= $this->terminals[$s_entry]['dn'];
511 /* Check locking, save current plugin in 'back_plugin', so
512 the dialog knows where to return. */
513 if (($user= get_lock($this->dn)) != ""){
514 return(gen_locked_message ($user, $this->dn));
515 }
517 /* Find out more about the object type */
518 $ldap= $this->config->get_ldap_link();
519 $ldap->cat($this->dn, array('objectClass','gotoMode'));
520 $attrs= $ldap->fetch();
521 $type= $this->get_system_type($attrs);
523 /* Lock the current entry, so everyone will get the
524 above dialog */
525 $tabs = array(
526 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
527 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
528 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
529 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
530 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
531 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
532 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
535 if($type == "ArpNewDevice"){
536 if(!class_available("ArpNewDeviceTabs")){
537 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
538 }else{
539 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
540 }
541 }elseif($type == "NewDevice"){
542 if(!class_available("SelectDeviceType")){
543 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
544 }else{
545 $this->system_activation_object= array($this->dn);
546 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
547 }
548 }elseif(isset($tabs[$type])){
550 $class = $tabs[$type]["CLASS"];
551 $acl_cat = $tabs[$type]["ACL"];
552 $tabclass = $tabs[$type]["TABCLASS"];
554 if(!class_available($tabclass)){
555 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
556 }else{
557 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
558 $this->systab->set_acl_base($this->dn);
559 session::set('objectinfo',$this->dn);
560 add_lock ($this->dn, $this->ui->dn);
561 }
562 }else{
563 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
564 $this->remove_lock();
565 }
566 }
569 /********************
570 Change password ...
571 ********************/
573 /* Set terminals root password */
574 if ($s_action=="change_pw"){
575 $tabs = array(
576 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
577 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
578 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
579 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
580 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
581 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
582 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
583 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
584 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
586 $dn = $this->terminals[$s_entry]['dn'];
587 $type = $this->get_system_type($this->terminals[$s_entry]);
589 $class = $tabs[$type]["CLASS"];
590 $acl = $tabs[$type]["ACL"];
591 $tabclass = $tabs[$type]["TABCLASS"];
592 $ui = get_userinfo();
593 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
594 if(preg_match("/w/",$tabacl)){
595 $this->dn= $this->terminals[$s_entry]['dn'];
596 session::set('objectinfo',$this->dn);
597 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
598 }else{
599 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
600 }
601 }
604 /********************
605 Password change finish, but check if entered data is ok
606 ********************/
608 /* Correctly specified? */
609 if (isset($_POST['password_finish'])){
610 if ($_POST['new_password'] != $_POST['repeated_password']){
611 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
612 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
613 }
614 }
616 /********************
617 Password change finish
618 ********************/
620 /* Change terminal password */
621 if (isset($_POST['password_finish']) &&
622 $_POST['new_password'] == $_POST['repeated_password']){
624 /* Check if user is allowed to set password */
625 $tabs = array(
626 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
627 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
628 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
629 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
631 /* Detect object type */
632 $type = "";
633 foreach($this->terminals as $terminal){
634 if($terminal['dn'] == $this->dn){
635 $type = $this->get_system_type($terminal);
636 break;
637 }
638 }
640 /* Type detected */
641 $allow_for = array("terminal","workstation","server","component");
642 if(!empty($type) && in_array($type,$allow_for)){
644 /* Get infos */
645 $plug = $tabs[$type]["PLUG"];
646 $class = $tabs[$type]["CLASS"];
647 $acl = $tabs[$type]["ACL"];
648 $tabclass = $tabs[$type]["TABCLASS"];
650 /* Get acls */
651 $ui = get_userinfo();
652 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
654 /* Check acls */
655 if(preg_match("/w/",$tabacl)){
656 $ldap = $this->config->get_ldap_link();
657 $ldap->cd($this->dn);
658 $ldap->cat($this->dn);
659 $old_attrs = $ldap->fetch();
661 $attrs= array();
662 if ($_POST['new_password'] == ""){
664 /* Remove password attribute
665 */
666 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
667 $attrs['objectClass'] = array();
668 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
669 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
670 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
671 }
672 }
673 }
674 $attrs['userPassword']= array();
675 } else {
677 /* Add/modify password attribute
678 */
679 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
680 $attrs['objectClass'] = array();
681 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
682 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
683 }
684 $attrs['objectClass'][] = "simpleSecurityObject";
685 }
687 if(class_available("passwordMethodCrypt")){
688 $pwd_m = new passwordMethodCrypt($this->config);
689 $pwd_m->set_hash("crypt/md5");
690 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
691 }else{
692 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
693 $attrs = array();
694 }
695 }
696 $ldap->modify($attrs);
697 if (!$ldap->success()){
698 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
699 }else{
700 if(class_available($plug)){
701 $p = new $plug($this->config,$this->dn);
702 $p->handle_post_events("modify");
703 }
704 }
706 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
707 }else{
708 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
709 }
710 }else{
711 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
712 }
713 session::un_set('objectinfo');
714 }
717 /********************
718 Delete system cancel
719 ********************/
721 /* Delete terminal canceled? */
722 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
723 $this->remove_lock();
724 session::un_set('objectinfo');
725 }
728 /********************
729 Action(s) for MULTIPLE
730 ********************/
732 /********************
733 SCHEDULE action in GOsa Daemon
734 ********************/
736 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
737 $this->dns = array();
738 $ids = $this->list_get_selected_items();
740 if(count($ids) && class_available("DaemonEvent")){
741 $mac= array();
743 $ldap = $this->config->get_ldap_link();
744 foreach($ids as $id){
745 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
746 $attrs= $ldap->fetch();
747 if (isset($attrs['macAddress'][0])){
748 $mac[]= $attrs['macAddress'][0];
749 }
750 }
751 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
752 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
753 $o_queue = new gosaSupportDaemon();
755 /* Skip installation or update trigerred events,
756 * if this entry is currently processing.
757 */
758 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
759 foreach($mac as $key => $mac_address){
760 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
762 $entry['STATUS'] = strtoupper($entry['STATUS']);
763 if($entry['STATUS'] == "PROCESSING" &&
764 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
765 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
766 unset($mac[$key]);
768 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
769 break;
770 }
771 }
772 }
773 }
775 /* Prepare event to be added
776 */
777 if(count($mac) && isset($events['BY_CLASS'][$type])){
778 $event = $events['BY_CLASS'][$type];
779 $this->systab = new $event['CLASS_NAME']($this->config);
780 $this->systab->add_targets($mac);
781 if(preg_match("/trigger_event/",$s_action)){
782 $this->systab->set_type(TRIGGERED_EVENT);
783 }else{
784 $this->systab->set_type(SCHEDULED_EVENT);
785 }
786 }
787 }
788 }
790 /* Insert scheduled events into queue */
791 if(class_available("DaemonEvent") && $this->systab instanceof DaemonEvent){
792 $this->systab->save_object();
794 /* Save event
795 */
796 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
797 $o_queue = new gosaSupportDaemon();
798 $o_queue->append($this->systab);
799 if($o_queue->is_error()){
800 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
801 }else{
802 $this->systab = FALSE;
803 }
804 }
805 if(isset($_POST['abort_event_dialog'])){
806 $this->systab = FALSE;
807 }
808 }
811 /********************
812 Delete MULTIPLE entries requested, display confirm dialog
813 ********************/
815 if ($s_action=="del_multiple" || $s_action == "del"){
816 $this->dns = array();
818 if($s_action == "del_multiple"){
819 $ids = $this->list_get_selected_items();
820 }else{
821 $ids = array($s_entry);
822 }
824 $ui = get_userinfo();
825 $tabs = array(
826 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
827 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
828 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
829 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
830 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
831 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
832 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
833 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
834 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
837 if(count($ids)){
839 $disallowed = array();
840 foreach($ids as $id){
842 /* Get 'dn' from posted termlinst */
843 $attrs = $this->terminals[$id];
844 $type = $this->get_system_type($attrs);
845 $dn = $attrs['dn'];
846 $acl = $this->ui->get_permissions($dn, $tabs[$type]['ACL']);
847 if(preg_match("/d/",$acl)){
848 $this->dns[$id] = $dn;
849 }else{
850 $disallowed[] = $dn;
851 }
852 }
854 if(count($disallowed)){
855 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
856 }
858 if(count($this->dns)){
860 if ($user= get_multiple_locks($this->dns)){
861 return(gen_locked_message($user,$this->dns));
862 }
864 $dns_names = array();
865 foreach($this->dns as $dn){
866 add_lock ($dn, $this->ui->dn);
867 $dns_names[] = @LDAP::fix($dn);
868 }
870 /* Lock the current entry, so nobody will edit it during deletion */
871 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
872 $smarty->assign("multiple", true);
873 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
874 }
875 }
876 }
879 /********************
880 Delete MULTIPLE entries confirmed
881 ********************/
883 /* Confirmation for deletion has been passed. Users should be deleted. */
884 if (isset($_POST['delete_multiple_system_confirm'])){
886 $ui = get_userinfo();
887 $tabs = array(
888 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
889 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
890 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
891 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
892 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
893 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
894 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
895 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
896 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
899 /* Remove user by user and check acls before removeing them */
900 foreach($this->dns as $key => $dn){
902 /* Get 'dn' from posted termlinst */
903 $attrs = $this->terminals[$key];
904 $type= $this->get_system_type($attrs);
906 /* get object type */
907 $tabtype = "termtabs";
908 $tabobj = "TERMTABS";
909 $tabacl = "";
910 if(isset($tabs[$type])){
911 $tabtype = $tabs[$type]['TABCLASS'];
912 $tabobj = $tabs[$type]['CLASS'];
913 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
915 /* Load permissions for selected 'dn' and check if
916 we're allowed to remove this 'dn' */
917 if(preg_match("/d/",$tabacl)){
919 /* Delete request is permitted, perform LDAP action */
920 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
921 $this->systab= new termgeneric($this->config, $dn);
922 $this->systab->set_acl_base($dn);
923 $this->systab->remove_from_parent();
924 }elseif($tabtype=="phonetabs"){
925 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
926 $this->systab->set_acl_base($dn);
927 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
928 }else{
929 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
930 $this->systab->set_acl_base($dn);
931 $this->systab->delete();
932 }
933 unset ($this->systab);
934 $this->systab= NULL;
936 } else {
937 /* Normally this shouldn't be reached, send some extra
938 logs to notify the administrator */
939 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
940 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
941 }
942 }
944 /* Remove lock file after successfull deletion */
945 $this->remove_lock();
946 $this->dns = array();
947 }
948 }
950 /********************
951 Delete MULTIPLE entries Canceled
952 ********************/
954 /* Remove lock */
955 if(isset($_POST['delete_multiple_system_cancel'])){
957 /* Remove lock file after successfull deletion */
958 $this->remove_lock();
959 $this->dns = array();
960 }
963 /********************
964 Edit system type finished, check if everything went ok
965 ********************/
966 /* Finish user edit is triggered by the tabulator dialog, so
967 the user wants to save edited data. Check and save at this
968 point. */
970 /* Dirty workaround - MSG_DIALOG - OK
971 If a message dialog is shown and we press 'OK'
972 then try to save again.
973 */
974 foreach($_POST as $name => $value){
975 if(preg_match("/^MSG_OK/",$name)){
976 $_POST[$this->last_action] = TRUE;
977 }
978 }
980 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
982 /* If the save routine gets interrupted by a confirm dialog,
983 store last action so we can trigger it again after 'Ok' was pressed.
984 (This is the case if a system gets modified while it is installing - GOsa si)
985 */
986 $this->last_action = "";
987 if(isset($_POST['edit_finish'])){
988 $this->last_action = "edit_finish";
989 }elseif(isset($_POST['edit_apply'])){
990 $this->last_action = "edit_apply";
991 }
993 /* Check tabs, will feed message array */
994 $message = $this->systab->check();
996 /* Save, or display error message? */
997 if (count($message) == 0){
1000 $this->systab->save();
1002 /* Terminal has been saved successfully, remove lock from LDAP. */
1003 if (!isset($_POST['edit_apply'])){
1004 if ($this->dn != "new"){
1005 $this->remove_lock();
1006 }
1008 unset ($this->systab);
1009 $this->systab= NULL;
1010 session::un_set('objectinfo');
1011 }else{
1013 /* Reinitialize tab */
1014 if($this->systab instanceof tabs){
1015 $this->systab->re_init();
1016 }
1017 }
1018 } else {
1019 /* Ok. There seem to be errors regarding to the tab data,
1020 show message and continue as usual. */
1021 msg_dialog::displayChecks($message);
1022 }
1023 }
1026 /********************
1027 Edit system was canceled
1028 ********************/
1029 /* Cancel dialogs */
1030 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1031 if (isset($this->systab)){
1032 $this->remove_lock();
1033 unset ($this->systab);
1034 }
1035 $this->systab= NULL;
1036 session::un_set('objectinfo');
1037 }
1039 /********************
1040 Display edit dialog, or some other
1041 ********************/
1043 /* Show tab dialog if object is present */
1044 if (isset($this->systab->config)){
1045 $display= $this->systab->execute();
1047 /* Don't show buttons if tab dialog requests this */
1049 $dialog = FALSE;
1050 $hide_apply = $this->dn == "new";
1051 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1052 if(is_object($this->systab) && !isset($this->systab->by_object)){
1053 $dialog = TRUE;
1054 $hide_apply = TRUE;
1055 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1056 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1057 if($dia === TRUE || is_object($dia)){
1058 $dialog = TRUE;
1059 }
1060 }
1061 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1062 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1063 $dialog = TRUE;
1064 }
1066 if (!$dialog){
1067 $display.= "<p style=\"text-align:right\">\n";
1068 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1069 $display.= " \n";
1070 if (!$hide_apply){
1071 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1072 $display.= " \n";
1073 }
1074 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1075 $display.= "</p>";
1076 }
1077 return ($display);
1078 }
1080 /* Check if there is a snapshot dialog open */
1081 $base = $this->DivListSystem->selectedBase;
1082 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1083 return($str);
1084 }
1086 /* Display dialog with system list */
1087 $this->DivListSystem->parent = $this;
1088 $this->DivListSystem->execute();
1090 /* Add departments if subsearch is disabled */
1091 if(!$this->DivListSystem->SubSearch){
1093 /* Add FAIstate to attributes if FAI is activated */
1094 if($this->fai_activated){
1095 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,4,1);
1096 }else{
1097 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1098 }
1099 }
1100 $this->reload();
1101 $this->DivListSystem->setEntries($this->terminals);
1102 return($this->DivListSystem->Draw());
1103 }
1106 /* Return departments, that will be included within snapshot detection */
1107 function get_used_snapshot_bases()
1108 {
1109 $tmp = array();
1111 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1113 $tabs = array(
1114 "terminal" => get_ou('terminalou'),
1115 "workstation" => get_ou('workstationou'),
1116 "incoming" => get_ou('incomingou'),
1117 "server" => get_ou('serverou'),
1118 "printer" => get_ou('printerou'),
1119 "phone" => get_ou('phoneou'),
1120 "winworkstation" => get_winstations_ou(),
1121 "component" => get_ou('componentou')
1122 );
1124 foreach($tabs as $acl_cat => $dn){
1126 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1127 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1128 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1129 }
1130 }
1131 return($tmp);
1132 }
1135 function remove_from_parent()
1136 {
1137 /* Optionally execute a command after we're done */
1138 $this->postremove();
1139 }
1142 /* Save data to object */
1143 function save_object()
1144 {
1145 $this->DivListSystem->save_object();
1146 if(is_object($this->CopyPasteHandler)){
1147 $this->CopyPasteHandler->save_object();
1148 }
1149 }
1152 /* Check values */
1153 function check()
1154 {
1155 }
1158 /* Save to LDAP */
1159 function save()
1160 {
1161 }
1163 function adapt_from_template($dn, $skip= array())
1164 {
1165 }
1167 function password_change_needed()
1168 {
1169 }
1171 function reload()
1172 {
1173 /* some var init */
1174 $ui = get_userinfo();
1175 $res = array();
1176 $this->terminals = array();
1177 $userregex = "";
1179 /* Set base for all searches */
1180 $base= $this->DivListSystem->selectedBase;
1182 /* Prepare samba class name */
1183 $samba ="";
1184 if ($this->DivListSystem->ShowWinWorkstations){
1185 if ($this->config->current['SAMBAVERSION'] == "3"){
1186 $samba= "sambaSamAccount";
1187 } else {
1188 $samba= "sambaAccount";
1189 }
1190 }
1192 /* This array represents the combination between checkboxes and search filters */
1193 $objs = array(
1194 "ShowServers" => array("TAB" => "servtabs", "CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1195 "ShowTerminals" => array("TAB" => "termtabs", "CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1196 "ShowPrinters" => array("TAB" => "printtabs", "CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1197 "ShowDevices" => array("TAB" => "componenttabs", "CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1198 "ShowPhones" => array("TAB" => "phonetabs", "CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1199 "ShowWorkstations" => array("TAB" => "worktabs", "CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1200 "ShowWinWorkstations"=> array("TAB" => "wintabs", "CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1202 /* Include the 'Display Systems of user' attribute */
1203 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1204 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1205 }
1207 /* Attributes to fetch */
1208 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode","FAIclass");
1209 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1211 /* Add FAIstate to attributes if FAI is activated */
1212 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1213 if(!empty($tmp)){
1214 $sys_attrs[] = "FAIstate";
1215 }
1217 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1218 foreach($objs as $checkBox => $oc){
1220 if($this->DivListSystem->$checkBox && class_available($oc['TAB'])){
1221 if($this->DivListSystem->SubSearch){
1222 if($oc['CLASS'] != ""){
1223 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1224 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1225 $res = array_merge($res,$new_res);
1226 }
1227 }else{
1228 /* User filter? */
1229 if($oc['CLASS'] != ""){
1230 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1231 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1232 }
1233 }
1234 }
1235 }
1237 /* Search for incoming objects */
1238 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1239 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1241 /* Get all gotoTerminal's */
1242 foreach ($res as $value){
1244 $tmp= $value['dn'];
1245 $add= "";
1247 /* Extract base */
1248 foreach($objs as $obj){
1249 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1250 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1251 }
1252 }
1254 /* Create a string containing the last part of the department. */
1255 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1256 if(empty($dn_name)){
1257 $dn_name = "/";
1258 }
1260 /* check if current object is a new one */
1261 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1262 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1263 $add= "- "._("New terminal");
1264 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1265 $add= "- "._("New workstation");
1266 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1267 $add= "- "._("Unknown device");
1268 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1269 $add= "- "._("New Device");
1270 }
1271 }
1273 /* Detect type of object and create an entry for $this->terminals */
1274 $terminal = array();
1275 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1277 /* check acl */
1278 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1279 if($add != "" || preg_match("/r/",$acl)) {
1280 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1281 $terminal = $value;
1282 $terminal['type'] = "T";
1283 $terminal['is_new'] = $add;
1284 } else {
1285 $terminal = $value;
1286 $terminal['type'] = "D";
1287 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1288 $terminal['location'] = array_search($tmp, $this->config->departments);
1289 }
1290 }
1291 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1293 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1294 if($add != "" || preg_match("/r/",$acl)) {
1295 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1296 $terminal = $value;
1297 $terminal['type'] = "L";
1298 $terminal['is_new'] = $add;
1299 } else {
1300 $terminal = $value;
1301 $terminal['type'] = "D";
1302 $terminal['location'] = array_search($tmp, $this->config->departments);
1303 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1304 }
1305 # if (isset($value["FAIstate"][0])){
1306 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1307 # }
1308 }
1309 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1312 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1313 if($add != "" || preg_match("/r/",$acl)) {
1315 $terminal = $value;
1316 $terminal['type'] = "P";
1317 }
1318 } elseif (in_array_ics('goServer', $value["objectClass"])){
1320 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1321 if($add != "" || preg_match("/r/",$acl)) {
1323 $terminal = $value;
1324 $terminal['type'] = "S";
1325 # if (isset($value["FAIstate"][0])){
1326 # $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1327 # }
1328 }
1329 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1331 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1332 if($add != "" || preg_match("/r/",$acl)) {
1334 $terminal = $value;
1335 $terminal['type'] = "F";
1336 }
1337 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1339 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1340 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1341 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1342 if($add != "" || preg_match("/r/",$acl)) {
1344 $terminal = $value;
1345 $terminal['type'] = "Q";
1346 $terminal['is_new'] = $add;
1347 }
1348 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1350 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1351 if($add != "" || preg_match("/r/",$acl)) {
1353 $terminal = $value;
1354 $terminal['type'] = "C";
1355 }
1356 } else{
1358 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1359 if (isset($value['sambaDomainName'])){
1360 $domain= " [".$value['sambaDomainName'][0]."]";
1361 } else {
1362 $domain= "";
1363 }
1364 $acl = $ui->get_permissions($value['dn'],"winworkstation/wingeneric");
1365 if($add != "" || preg_match("/r/",$acl)) {
1366 $terminal=$value;
1367 $terminal['type'] ="W";
1368 $terminal['domain'] = $name.$domain;
1369 }
1370 }
1372 if(count($terminal)){
1373 $this->terminals[]=$terminal;
1374 }
1375 }
1377 $tmp =array();
1378 $tmp2 =array();
1379 foreach($this->terminals as $tkey => $val ){
1380 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1381 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1382 }
1383 natcasesort($tmp2);
1384 $this->terminals=array();
1385 foreach($tmp2 as $val){
1386 $this->terminals[]=$tmp[$val];
1387 }
1388 reset ($this->terminals);
1389 }
1391 function remove_lock()
1392 {
1393 if (isset($this->systab->dn)){
1394 del_lock ($this->systab->dn);
1395 }
1396 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
1397 del_lock($this->dn);
1398 }
1399 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1400 del_lock($this->dns);
1401 }
1402 }
1405 function copyPasteHandling_from_queue($s_action,$s_entry)
1406 {
1407 /* Check if Copy & Paste is disabled */
1408 if(!is_object($this->CopyPasteHandler)){
1409 return("");
1410 }
1412 $ui = get_userinfo();
1414 $tabs = array(
1415 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1416 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1417 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1418 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1419 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1420 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1421 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1422 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1423 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1424 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1425 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1426 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1428 /* Add a single entry to queue */
1429 if($s_action == "cut" || $s_action == "copy"){
1431 /* Cleanup object queue */
1432 $this->CopyPasteHandler->cleanup_queue();
1433 $dn = $this->terminals[$s_entry]['dn'];
1434 $oc = $this->terminals[$s_entry]['objectClass'];
1435 $type = $this->get_system_type($this->terminals[$s_entry]);
1437 $tab_o = $tabs[$type]['CLASS'];
1438 $tab_c = $tabs[$type]['TABCLASS'];
1439 $acl_c = $tabs[$type]['TABNAME'];
1440 $acl = $tabs[$type]['ACL'];
1442 if($s_action == "copy" && $ui->is_copyable($dn,$acl,$acl_c)){
1443 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1444 }
1445 if($s_action == "cut" && $ui->is_cutable($dn,$acl,$acl_c)){
1446 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1447 }
1448 }
1450 /* Add entries to queue */
1451 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1453 /* Cleanup object queue */
1454 $this->CopyPasteHandler->cleanup_queue();
1456 /* Add new entries to CP queue */
1457 foreach($this->list_get_selected_items() as $id){
1458 $dn = $this->terminals[$id]['dn'];
1459 $oc = $this->terminals[$id]['objectClass'];
1460 $type = $this->get_system_type($this->terminals[$id]);
1462 if(isset($tabs[$type])){
1463 $tab_o = $tabs[$type]['CLASS'];
1464 $tab_c = $tabs[$type]['TABCLASS'];
1465 $acl_c = $tabs[$type]['TABNAME'];
1466 $acl = $tabs[$type]['ACL'];
1468 if($s_action == "copy_multiple" && $ui->is_copyable($dn,$acl,$acl_c)){
1469 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1470 }
1471 if($s_action == "cut_multiple" && $ui->is_cutable($dn,$acl,$acl_c)){
1472 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1473 }
1474 }
1475 }
1476 }
1478 /* Start pasting entries */
1479 if($s_action == "editPaste"){
1480 $this->start_pasting_copied_objects = TRUE;
1481 }
1483 /* Return C&P dialog */
1484 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1486 /* Get dialog */
1487 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1488 $data = $this->CopyPasteHandler->execute();
1490 /* Return dialog data */
1491 if(!empty($data)){
1492 return($data);
1493 }
1494 }
1496 /* Automatically disable status for pasting */
1497 if(!$this->CopyPasteHandler->entries_queued()){
1498 $this->start_pasting_copied_objects = FALSE;
1499 }
1500 return("");
1501 }
1504 function get_system_type($attrs)
1505 {
1506 $classes = $attrs['objectClass'];
1508 $type= "";
1509 if (in_array_ics('ieee802Device', $classes)){
1510 $type= "component";
1511 }elseif (in_array_ics('gotoTerminal', $classes)){
1512 $type= "terminal";
1513 }elseif (in_array_ics('gotoWorkstation', $classes)){
1514 $type= "workstation";
1515 }elseif (in_array_ics('gotoPrinter', $classes)){
1516 $type= "printer";
1517 }elseif (in_array_ics('goFonHardware', $classes)){
1518 $type= "phone";
1519 }elseif (in_array_ics('goServer', $classes)){
1520 $type= "server";
1521 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1522 $type= "ArpNewDevice";
1523 }elseif (in_array_ics('GOhard', $classes)){
1524 $type= "NewDevice";
1525 }elseif (in_array_ics('sambaAccount', $classes) ||
1526 in_array_ics('sambaSamAccount', $classes)){
1527 $type= "winstation";
1528 }
1529 return ($type);
1530 }
1533 function convert_list($input)
1534 {
1535 $temp= "";
1537 $conv= array(
1538 "D" => array("images/select_default.png",_("Template")),
1539 "F" => array("images/select_phone.png",_("Phone")),
1540 "C" => array("plugins/systems/images/select_component.png",_("Network device")),
1541 "P" => array("images/select_printer.png",_("Printer")),
1543 "W" => array("images/select_winstation.png",_("Win workstation")),
1545 "L" => array("images/select_workstation.png",_("Workstation")),
1546 "S" => array("images/select_server.png",_("Server")),
1547 "T" => array("images/select_terminal.png",_("Terminal")),
1549 "LX" => array("images/workstation_locked.png",_("Locked workstation")),
1550 "SX" => array("images/server_locked.png",_("Locked server")),
1551 "TX" => array("images/terminal_locked.png",_("Locked terminal")),
1553 "LE" => array("images/workstation_error.png",_("Workstation error")),
1554 "SE" => array("images/server_error.png",_("Server error")),
1555 "TE" => array("images/terminal_error.png",_("Terminal error")),
1557 "LB" => array("images/workstation_busy.png",_("Workstation busy")),
1558 "SB" => array("images/server_busy.png",_("Server busy")),
1560 "NQ" => array("images/select_newsystem.png",_("New system from incoming")),
1561 "NT"=> array("images/select_new_terminal.png",_("New terminal")),
1562 "NL"=> array("images/select_new_workstation.png",_("New workstation")));
1564 /* Use locked icons
1565 */
1566 if( in_array($input['type'],array("S","T","L")) &&
1567 isset($input['gotoMode'][0]) &&
1568 preg_match("/locked/",$input['gotoMode'][0])){
1569 $input['type'].="X";
1570 } elseif(in_array($input['type'],array("S","L")) &&
1571 isset($input['FAIstate'][0])){
1573 /* Add FAI state icons
1574 */
1575 $type= "";
1576 switch (preg_replace('/:.*$/', '', $input['FAIstate'][0])) {
1577 case 'error':
1578 $type= 'E';
1579 break;
1580 case 'installing':
1581 case 'install':
1582 case 'sysinfo':
1583 case 'softupdate':
1584 case 'scheduledupdate':
1585 $type= 'B';
1586 break;
1587 }
1589 $input['type'].= $type;
1590 }
1592 /* Use new images if object is from incoming
1593 */
1594 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1595 $input['type']="N".$input['type'];
1596 }
1598 /* Check which flags this objects uses
1599 */
1600 foreach ($conv as $key => $value){
1601 $found = TRUE;
1602 if(strlen($key) != strlen($input['type'])) {
1603 $found = FALSE;
1604 }
1605 for($i = 0 ; $i < strlen($key) ; $i++){
1606 if(!preg_match("/".$key[$i]."/",$input['type'])){
1607 $found = FALSE;
1608 }
1609 }
1611 if($found){
1612 $tmp['img'] ="<img class='center' src='".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1613 $tmp['class']=$key;
1614 return $tmp;
1615 }
1616 }
1617 }
1620 function list_get_selected_items()
1621 {
1622 $ids = array();
1623 foreach($_POST as $name => $value){
1624 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1625 $id = preg_replace("/^item_selected_/","",$name);
1626 $ids[$id] = $id;
1627 }
1628 }
1629 return($ids);
1630 }
1633 /* !! Incoming dummy acls, required to defined acls for incoming objects
1634 */
1635 static function plInfo()
1636 {
1637 return (array(
1638 "plShortName" => _("Incoming objects"),
1639 "plDescription" => _("Incoming objects"),
1640 "plSelfModify" => FALSE,
1641 "plDepends" => array(),
1642 "plPriority" => 99,
1643 "plSection" => array("administration"),
1644 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1645 "objectClass" => "")),
1646 "plProvidedAcls"=> array()
1648 ));
1649 }
1650 }
1652 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1653 ?>