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