98128010c461bdb376a1375d874c7c3760d8c2f9
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class systems extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "Systems";
25 var $plDescription = "This does something";
26 var $departments = array();
28 /* Dialog attributes */
29 var $systab = NULL;
30 var $terminals= array();
31 var $ui = NULL;
32 var $DivListSystem;
33 var $start_pasting_copied_objects = FALSE;
34 var $CopyPasteHandler = NULL;
36 /* Arp hanlding activated */
37 var $arp_handling_active = FALSE;
39 function systems (&$config, $ui)
40 {
41 /* Save configuration for internal use */
42 $this->config= $config;
43 $this->ui= $ui;
45 /* Creat dialog object */
46 $this->DivListSystem = new divListSystem($this->config,$this);
48 /* Copy & Paste enabled ?*/
49 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
50 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
51 }
53 /* Check whether the arp handling active or not */
54 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
55 $this->arp_handling_active = TRUE;
56 }
58 }
61 function execute()
62 {
63 /* Call parent execute */
64 plugin::execute();
66 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
68 /********************
69 Check for functional posts, edit|delete|add|... system devices
70 ********************/
71 $s_action = ""; // Contains the action to proceed
72 $s_entry = ""; // The value for s_action
73 $base_back = ""; // The Link for Backbutton
74 $smarty = get_smarty();
76 /* Test Posts */
77 foreach($_POST as $key => $val){
78 // Post for delete
79 if(preg_match("/system_del.*/",$key)){
80 $s_action = "del";
81 $s_entry = preg_replace("/system_del_/i","",$key);
82 // Post for edit
83 }elseif(preg_match("/system_edit_.*/",$key)){
84 $s_action="edit";
85 $s_entry = preg_replace("/system_edit_/i","",$key);
86 // Post for new
87 }elseif(preg_match("/system_new.*/",$key)){
88 $s_action="new";
89 }elseif(preg_match("/system_tplnew.*/i",$key)){
90 $s_action="new_tpl";
91 }elseif(preg_match("/system_setpwd_.*/i",$key)){
92 $s_action="change_pw";
93 $s_entry = preg_replace("/system_setpwd_/i","",$key);
94 }elseif(preg_match("/gen_cd_.*/i",$key)){
95 $s_action="gen_cd";
96 $s_entry = preg_replace("/gen_cd_/i","",$key);
97 }elseif(preg_match("/^copy_.*/",$key)){
98 $s_action="copy";
99 $s_entry = preg_replace("/^copy_/i","",$key);
100 }elseif(preg_match("/^cut_.*/",$key)){
101 $s_action="cut";
102 $s_entry = preg_replace("/^cut_/i","",$key);
103 }
104 }
106 /* Incoming handling
107 * If someone made a systemtype and ogroup selection
108 * Display the new requested entry type ... servtab in case of server and so on.
109 */
110 if(isset($_POST['SystemTypeChoosen'])){
111 $SelectedSystemType = session::get('SelectedSystemType');
112 $s_action = "SelectedSystemType";
113 $s_entry = $_POST['SystemType'];
114 $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
115 $this->systab = NULL;
116 session::set('SelectedSystemType',$SelectedSystemType);
117 }
119 /* remove image tags from posted entry (posts looks like this 'name_x')*/
120 $s_entry = preg_replace("/_.$/","",$s_entry);
122 /* Edit was requested by pressing the name(link) of an item */
123 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
124 $s_action ="edit";
125 $s_entry = $_GET['id'];
126 }
127 /* Create options */
128 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
129 $s_action = "newsystem";
130 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
131 }
133 /* handle C&P from layers menu */
134 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
135 $s_action = "copy_multiple";
136 }
137 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
138 $s_action = "cut_multiple";
139 }
140 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
141 $s_action = "editPaste";
142 }
144 /* Handle daemon events */
145 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
146 $s_action = $_POST['menu_action'];
147 }
149 /* Handle daemon events */
150 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
151 $s_action = $_POST['menu_action'];
152 }
154 /* handle remove from layers menu */
155 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
156 $s_action = "del_multiple";
157 }
159 /* Handle instant actions from layers menu */
160 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
161 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
162 $s_action = "${act}_multiple";
163 }
164 }
166 /* Check for exeeded sizelimit */
167 if (($message= check_sizelimit()) != ""){
168 return($message);
169 }
171 /* Try to get informations about what kind of system to create */
172 if ($s_action=="new") {
173 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
174 }
177 /********************
178 Copy & Paste Handling ...
179 ********************/
181 /* Display the copy & paste dialog, if it is currently open */
182 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
183 if($ret){
184 return($ret);
185 }
188 /********************
189 Create FAI CD ...
190 ********************/
191 if ($s_action=="gen_cd"){
192 $this->dn= $this->terminals[$s_entry]['dn'];
193 session::set('objectinfo',$this->dn);
194 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
195 }
198 /* Start CD-Creation */
199 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
200 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
201 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
202 }
205 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
207 $return_button = "<form method='get' action='main.php' target='_parent'>
208 <input type='submit' value='"._("Back")."'>
209 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
210 </form>";
212 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
214 /* Get and check command */
215 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
217 if (check_command($command)){
218 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
220 /* Print out html introduction */
221 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
222 <html>
223 <head>
224 <title></title>
225 <style type="text/css">@import url("themes/default/style.css");</style>
226 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
227 </head>
228 <body style="background: none; margin:4px;" id="body" >
229 <pre>';
231 /* Open process handle and check if it is a valid process */
232 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
233 if (is_resource($process)) {
234 fclose($pipes[0]);
236 /* Print out returned lines && write JS to scroll down each line */
237 while (!feof($pipes[1])){
238 $cur_dat = fgets($pipes[1], 1024);
239 echo $cur_dat;
240 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
241 flush();
242 }
243 }
245 /* Get error string && close streams */
246 $buffer= stream_get_contents($pipes[2]);
248 fclose($pipes[1]);
249 fclose($pipes[2]);
250 echo "</pre>";
252 /* Check return code */
253 $ret= proc_close($process);
254 if ($ret != 0){
255 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
256 echo "<pre style='color:red'>$buffer</pre>";
257 }
261 echo $return_button."<br>";
263 } else {
264 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
265 echo $tmp;
266 }
268 /* Scroll down completly */
269 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
270 echo '</body></html>';
271 flush();
272 exit;
273 }
276 /********************
277 Create new system ...
278 ********************/
279 /* Create new default terminal
280 * Or create specified object of selected system type, from given incoming object
281 */
283 $save_object_directly = false;
284 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
285 $save_object_directly = true;
286 }
288 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
290 /* If the current entry is an incoming object
291 * $sw = System type as posted in new incoming handling dialog
292 */
293 if($s_action == "SelectedSystemType") {
294 $sw = $s_entry;
295 }else{
296 if(isset($_POST['system'])){
297 $sw = $_POST['system'];
298 }else{
299 $sw = $s_entry;
300 }
301 $this->dn= "new";
302 }
304 $tabs = array(
305 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
306 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
307 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
308 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
309 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
310 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
312 if(isset($tabs[$sw])){
313 $class = $tabs[$sw]["CLASS"];
314 $tabname = $tabs[$sw]["TABNAME"];
315 $tabclass = $tabs[$sw]["TABCLASS"];
316 $acl_cat = $tabs[$sw]["ACL"];
318 /* Load permissions for selected 'dn' and check if
319 we're allowed to remove this 'dn' */
320 $ui = get_userinfo();
321 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
322 if(preg_match("/c/",$tabacl)){
323 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
324 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
325 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
326 $this->systab->base = $this->DivListSystem->selectedBase;
327 }else{
328 print_red(_("You are not allowed to create a new object of this type."));
329 }
330 }
331 }
333 /********************
334 Edit system ...
335 ********************/
337 /* User wants to edit data? */
338 if (($s_action == "edit") && (!isset($this->systab->config))){
340 $this->dn= $this->terminals[$s_entry]['dn'];
342 /* Check locking, save current plugin in 'back_plugin', so
343 the dialog knows where to return. */
344 if (($user= get_lock($this->dn)) != ""){
345 return(gen_locked_message ($user, $this->dn));
346 }
348 /* Find out more about the object type */
349 $ldap= $this->config->get_ldap_link();
350 $ldap->cat($this->dn, array('objectClass','gotoMode'));
351 $attrs= $ldap->fetch();
352 $type= $this->get_system_type($attrs);
354 /* Lock the current entry, so everyone will get the
355 above dialog */
356 $tabs = array(
357 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
358 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
359 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
360 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
361 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
362 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
363 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
366 if($type == "ArpNewDevice"){
367 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
368 }elseif($type == "NewDevice"){
369 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
370 }elseif(isset($tabs[$type])){
372 $class = $tabs[$type]["CLASS"];
373 $acl_cat = $tabs[$type]["ACL"];
374 $tabclass = $tabs[$type]["TABCLASS"];
376 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
377 $this->systab->set_acl_base($this->dn);
378 session::set('objectinfo',$this->dn);
379 add_lock ($this->dn, $this->ui->dn);
380 }else{
381 print_red (_("You can't edit this object type yet!"));
382 del_lock($this->dn);
383 }
384 }
387 /********************
388 Change password ...
389 ********************/
391 /* Set terminals root password */
392 if ($s_action=="change_pw"){
393 $tabs = array(
394 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
395 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
397 $type = $this->get_system_type($this->terminals[$s_entry]);
398 $class = $tabs[$type]["CLASS"];
399 $tabname = $tabs[$type]["TABNAME"];
400 $acl_cat = $tabs[$type]["ACL"];
401 $tabclass = $tabs[$type]["TABCLASS"];
402 $ui = get_userinfo();
403 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
404 if(preg_match("/w/",$tabacl)){
405 $this->dn= $this->terminals[$s_entry]['dn'];
406 session::set('objectinfo',$this->dn);
407 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
408 }else{
409 print_red(_("You are not allowed to change the password for this object."));
410 }
411 }
414 /********************
415 Password change finish, but check if entered data is ok
416 ********************/
418 /* Correctly specified? */
419 if (isset($_POST['password_finish'])){
420 if ($_POST['new_password'] != $_POST['repeated_password']){
421 print_red (_("Passwords entered as new and repeated do not match!"));
422 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
423 }
424 }
426 /********************
427 Password change finish
428 ********************/
430 /* Change terminal password */
431 if (isset($_POST['password_finish']) &&
432 $_POST['new_password'] == $_POST['repeated_password']){
434 /* Check if user is allowed to set password */
435 $tabs = array(
436 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
437 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
439 /* Detect object type */
440 $type = "";
441 foreach($this->terminals as $terminal){
442 if($terminal['dn'] == $this->dn){
443 $type = $this->get_system_type($terminal);
444 break;
445 }
446 }
448 /* Type detected */
449 if(!empty($type)){
451 /* Get infos */
452 $class = $tabs[$type]["CLASS"];
453 $tabname = $tabs[$type]["TABNAME"];
454 $acl_cat = $tabs[$type]["ACL"];
455 $tabclass = $tabs[$type]["TABCLASS"];
457 /* Get acls */
458 $ui = get_userinfo();
459 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
461 /* Check acls */
462 if(preg_match("/w/",$tabacl)){
463 $ldap = $this->config->get_ldap_link();
464 $ldap->cd($this->dn);
466 $attrs= array();
467 if ($_POST['new_password'] == ""){
468 $attrs['gotoRootPasswd']= array();
469 } else {
470 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
471 }
472 $ldap->modify($attrs);
473 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
474 }else{
475 print_red(_("You are not allowed to change the password for this object."));
476 }
477 }else{
478 print_red(_("Can't detect object to change password."));
479 }
480 session::un_set('objectinfo');
481 }
484 /********************
485 Delete system cancel
486 ********************/
488 /* Delete terminal canceled? */
489 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
490 del_lock ($this->dn);
491 session::un_set('objectinfo');
492 }
495 /********************
496 Action(s) for MULTIPLE
497 ********************/
499 /********************
500 SCHEDULE action in GOsa Daemon
501 ********************/
502 $save_events_directly = FALSE;
503 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
504 $this->dns = array();
505 $ids = $this->list_get_selected_items();
507 if(count($ids)){
508 $mac= array();
510 $ldap = $this->config->get_ldap_link();
511 foreach($ids as $id){
512 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
513 $attrs= $ldap->fetch();
514 if (isset($attrs['macAddress'][0])){
515 $mac[]= $attrs['macAddress'][0];
516 }
517 }
518 $events = DaemonEvent::get_event_types();
519 if(preg_match("/^trigger_event_/",$s_action)){
520 $type = preg_replace("/^trigger_event_/","",$s_action);
521 }else{
522 $type = preg_replace("/^schedule_event_/","",$s_action);
523 }
524 if(count($mac) && isset($events['BY_CLASS'][$type])){
525 $event = $events['BY_CLASS'][$type];
526 $this->systab = new $event['CLASS_NAME']($this->config);
527 $this->systab->add_targets($mac);
529 /* Insert event directly with current timestamp
530 * to force direct execution.
531 */
532 if(preg_match("/^trigger_event_/",$s_action)){
533 $this->systab->set_timestamp(time());
534 $save_events_directly = TRUE;
535 }
536 }
537 }
538 }
540 /* Insert scheduled events into queue */
541 if($this->systab instanceof DaemonEvent){
542 $this->systab->save_object();
543 if(isset($_POST['save_event_dialog']) || $save_events_directly){
545 /* Directly means not scheduled */
546 if($save_events_directly){
547 $header = $this->systab->get_trigger_action();
548 }else{
549 $header = $this->systab->get_schedule_action();
550 }
551 $targets = $this->systab->get_targets();
552 $data = $this->systab->save();
553 $o_queue = new gosaSupportDaemon();
554 foreach($targets as $target){
555 $data['macaddress'] = $target;
556 $o_queue->send_data($header,$target,$data,TRUE);
557 if($o_queue->is_error()){
558 msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
559 $o_queue->get_error()),ERROR_DIALOG);
560 }
561 }
562 $this->systab = FALSE;
563 }
564 if(isset($_POST['abort_event_dialog'])){
565 $this->systab = FALSE;
566 }
567 }
570 /********************
571 Delete MULTIPLE entries requested, display confirm dialog
572 ********************/
574 if ($s_action=="del_multiple"){
575 $this->dns = array();
576 $ids = $this->list_get_selected_items();
578 if(count($ids)){
580 foreach($ids as $id){
581 $dn = $this->terminals[$id]['dn'];
582 $this->dns[$id] = $dn;
583 }
584 if ($user= get_multiple_locks($this->dns)){
585 return(gen_locked_message($user,$this->dns));
586 }
588 $dns_names = "<br><pre>";
589 foreach($this->dns as $dn){
590 add_lock ($dn, $this->ui->dn);
591 $dns_names .= $dn."\n";
592 }
593 $dns_names .="</pre>";
595 /* Lock the current entry, so nobody will edit it during deletion */
596 if (count($this->dns) == 1){
597 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
598 } else {
599 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
600 }
601 $smarty->assign("multiple", true);
602 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
603 }
604 }
607 /********************
608 Delete MULTIPLE entries confirmed
609 ********************/
611 /* Confirmation for deletion has been passed. Users should be deleted. */
612 if (isset($_POST['delete_multiple_system_confirm'])){
614 $ui = get_userinfo();
615 $tabs = array(
616 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
617 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
618 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
619 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
620 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
621 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
622 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
623 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
624 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
627 /* Remove user by user and check acls before removeing them */
628 foreach($this->dns as $key => $dn){
630 /* Get 'dn' from posted termlinst */
631 $attrs = $this->terminals[$key];
632 $type= $this->get_system_type($attrs);
634 /* get object type */
635 $tabtype = "termtabs";
636 $tabobj = "TERMTABS";
637 $tabacl = "";
638 if(isset($tabs[$type])){
639 $tabtype = $tabs[$type]['TABCLASS'];
640 $tabobj = $tabs[$type]['CLASS'];
641 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
643 /* Load permissions for selected 'dn' and check if
644 we're allowed to remove this 'dn' */
645 if(preg_match("/d/",$tabacl)){
647 /* Delete request is permitted, perform LDAP action */
648 if($tabtype=="phonetabs"){
649 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
650 $this->systab->set_acl_base($dn);
651 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
652 }else{
653 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
654 $this->systab->set_acl_base($dn);
655 $this->systab->delete();
656 }
657 unset ($this->systab);
658 $this->systab= NULL;
660 } else {
661 /* Normally this shouldn't be reached, send some extra
662 logs to notify the administrator */
663 print_red (_("You are not allowed to delete this component!"));
664 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
665 }
666 /* Remove lock file after successfull deletion */
667 del_lock ($dn);
668 unset($this->dns[$key]);
669 }
670 }
671 }
673 /********************
674 Delete MULTIPLE entries Canceled
675 ********************/
677 /* Remove lock */
678 if(isset($_POST['delete_multiple_system_cancel'])){
679 foreach($this->dns as $key => $dn){
680 del_lock ($dn);
681 unset($this->dns[$key]);
682 }
683 }
686 /********************
687 Delete system, confirm dialog
688 ********************/
690 /* Remove terminal was requested */
691 if ($s_action=="del"){
693 /* Get 'dn' from posted termlinst */
694 $this->dn = $this->terminals[$s_entry]['dn'];
695 $attrs = $this->terminals[$s_entry];
699 $type= $this->get_system_type($attrs);
700 $ui = get_userinfo();
701 $tabs = array(
702 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
703 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
704 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
705 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
706 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
707 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
708 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
709 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
710 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
712 /* get object type */
713 $tabtype = "termtabs";
714 $tabobj = "TERMTABS";
715 $tabacl = "";
716 if(isset($tabs[$type])){
717 $tabtype = $tabs[$type]['TABCLASS'];
718 $tabobj = $tabs[$type]['CLASS'];
719 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
720 }
722 /* Load permissions for selected 'dn' and check if
723 we're allowed to remove this 'dn' */
724 if(preg_match("/d/",$tabacl)){
726 /* Check locking, save current plugin in 'back_plugin', so
727 the dialog knows where to return. */
728 if (($user= get_lock($this->dn)) != ""){
729 return(gen_locked_message ($user, $this->dn));
730 }
732 /* Lock the current entry, so nobody will edit it during deletion */
733 add_lock ($this->dn, $this->ui->dn);
734 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
735 $smarty->assign("multiple", false);
736 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
737 } else {
739 /* Obviously the user isn't allowed to delete. Show message and
740 clean session. */
741 print_red (_("You are not allowed to delete this component!"));
742 }
743 }
746 /********************
747 Delete system, confirmed
748 ********************/
749 /* Confirmation for deletion has been passed. Terminal should be deleted. */
750 if (isset($_POST['delete_terminal_confirm'])){
752 /* Find out more about the object type */
753 $ldap= $this->config->get_ldap_link();
754 $ldap->cat($this->dn, array('objectClass'));
755 $attrs= $ldap->fetch();
756 $type= $this->get_system_type($attrs);
758 $ui = get_userinfo();
760 $tabs = array(
761 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
762 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
763 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
764 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
765 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
766 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
767 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
768 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
769 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
771 /* get object type */
772 $tabtype = "termtabs";
773 $tabobj = "TERMTABS";
774 $tabacl = "";
775 if(isset($tabs[$type])){
776 $tabtype = $tabs[$type]['TABCLASS'];
777 $tabobj = $tabs[$type]['CLASS'];
778 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
779 }
781 /* Check if we are allowed to remove this object */
782 if(preg_match("/d/",$tabacl)){
784 /* Delete request is permitted, perform LDAP action */
785 if($tabtype=="phonetabs"){
786 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
787 $this->systab->set_acl_base($this->dn);
788 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
789 }else{
790 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
791 $this->systab->set_acl_base($this->dn);
792 $this->systab->delete();
793 }
794 unset ($this->systab);
795 $this->systab= NULL;
797 /* Terminal list has changed, reload it. */
798 } else {
800 /* Normally this shouldn't be reached, send some extra
801 logs to notify the administrator */
802 print_red (_("You are not allowed to delete this component!"));
803 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
804 }
806 /* Remove lock file after successfull deletion */
807 del_lock ($this->dn);
808 }
818 /********************
819 Edit system type finished, check if everything went ok
820 ********************/
821 /* Finish user edit is triggered by the tabulator dialog, so
822 the user wants to save edited data. Check and save at this
823 point. */
824 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
826 /* Check tabs, will feed message array */
827 $message = array();
828 if(!$save_object_directly){
829 $message = $this->systab->check();
830 }else{
831 $found = false;
833 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
834 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
835 if(isset($this->systab->by_object[$tab]->gotoMode)) {
836 $found = true;
837 $this->systab->by_object[$tab]->gotoMode = $value;
838 }
839 }
840 if(!$found){
841 print_red(sprintf(_("Can't set gotoMode to status 'active', the current object couldn't be identified.")));
842 }
844 }
845 /* Save, or display error message? */
846 if (count($message) == 0){
848 /* Incoming behavior; you can select a system type and an ogroup membership.
849 * If this object is an Incoming object, session::get('SelectedSystemType') isset.
850 * Check if we must add the new object to an object group.
851 *
852 * If this is done, delete the old incoming entry... it is still there, because this is a new
853 * entry and not an edited one, so we will delete it.
854 *
855 */
857 if(session::is_set('SelectedSystemType')){
858 $SelectedSystemType = session::get('SelectedSystemType');
859 if($SelectedSystemType['ogroup'] != "none"){
860 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
861 if($og){
862 $og->AddDelMembership($this->systab->dn);
863 $og->save();
864 }
865 }
866 }
868 /* Save terminal data to ldap */
869 $SelectedSystemType = session::get('SelectedSystemType');
870 if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
871 foreach (array("workservice", "termservice") as $cls){
872 if (isset($this->systab->by_object[$cls])){
873 $this->systab->by_object[$cls]->gotoXMouseport= "";
874 $this->systab->by_object[$cls]->gotoXMouseType= "";
875 $this->systab->by_object[$cls]->gotoXResolution= "";
876 $this->systab->by_object[$cls]->gotoXColordepth= "";
877 }
878 }
879 }
881 $this->systab->save();
883 /* Get macAddress to be able to an installation event
884 */
885 if($this->systab instanceof ArpNewDeviceTabs || session::is_set('SelectedSystemType')){
886 $events = DaemonEvent::get_event_types();
888 /* Get mac of currently edited entry */
889 $mac = "";
890 if($this->systab instanceof ArpNewDeviceTabs){
891 $mac = $this->systab->by_object['ArpNewDevice']->netConfigDNS->macAddress;
892 }else{
893 foreach(array("workgeneric","termgeneric","servgeneric") as $type){
894 if(isset($this->systab->by_object[$type]->netConfigDNS->macAddress)){
895 $mac = $this->systab->by_object[$type]->netConfigDNS->macAddress;
896 break;
897 }
898 }
899 }
901 /* Add installation event
902 */
903 if(!empty($mac) && isset($events['BY_CLASS']['DaemonEvent_install'])){
904 $evt = $events['BY_CLASS']['DaemonEvent_install'];
905 $tmp = new $evt['CLASS_NAME']($this->config);
906 $tmp->add_targets(array($mac));
907 $header = $tmp->get_trigger_action();
908 $data = $tmp->save();
909 $data['macaddress'] = $mac;
910 $o_queue = new gosaSupportDaemon();
911 $o_queue->send_data($header,$mac,$data,TRUE);
912 if($o_queue->is_error()){
913 msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
914 $o_queue->get_error()),ERROR_DIALOG);
915 }
916 }
917 }
919 if(session::is_set('SelectedSystemType')){
920 session::un_set('SelectedSystemType');
921 if(!isset($ldap)){
922 $ldap = $this->config->get_ldap_link();
923 }
924 $ldap->cd ($this->dn);
925 $ldap->cat($this->dn, array('dn'));
926 if(count($ldap->fetch())){
927 $ldap->cd($this->dn);
928 $ldap->rmDir($this->dn);
929 }
930 $ldap->cd($this->config->current['BASE']);
931 }
933 /* Terminal has been saved successfully, remove lock from LDAP. */
934 if (!isset($_POST['edit_apply'])){
935 if ($this->dn != "new"){
936 del_lock ($this->dn);
937 }
939 unset ($this->systab);
940 $this->systab= NULL;
941 session::un_set('objectinfo');
942 }
943 } else {
944 /* Ok. There seem to be errors regarding to the tab data,
945 show message and continue as usual. */
946 show_errors($message);
947 }
948 }
951 /********************
952 Edit system was canceled
953 ********************/
954 /* Cancel dialogs */
955 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
956 if (isset($this->systab)){
957 del_lock ($this->systab->dn);
958 unset ($this->systab);
959 }
960 $this->systab= NULL;
961 session::un_set('objectinfo');
963 /* Remove ogroup selection, which was set while editing a new incoming entry */
964 if(session::is_set('SelectedSystemType')){
965 session::un_set('SelectedSystemType');
966 }
967 }
969 /********************
970 Display edit dialog, or some other
971 ********************/
973 /* Show tab dialog if object is present */
974 if (isset($this->systab->config)){
975 $display= $this->systab->execute();
977 /* Don't show buttons if tab dialog requests this */
979 $dialog = FALSE;
980 $hide_apply = $this->dn == "new";
981 if(is_object($this->systab) && !isset($this->systab->by_object)){
982 $dialog = TRUE;
983 $hide_apply = TRUE;
984 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
985 $dia = $this->systab->by_object[$this->systab->current]->dialog;
986 if($dia === TRUE || is_object($dia)){
987 $dialog = TRUE;
988 }
989 }
990 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
991 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
992 $dialog = TRUE;
993 }
995 if (!$dialog){
996 $display.= "<p style=\"text-align:right\">\n";
997 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
998 $display.= " \n";
999 if (!$hide_apply){
1000 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
1001 $display.= " \n";
1002 }
1003 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
1004 $display.= "</p>";
1005 }
1006 return ($display);
1007 }
1009 /* Check if there is a snapshot dialog open */
1010 $base = $this->DivListSystem->selectedBase;
1011 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1012 return($str);
1013 }
1015 /* Display dialog with system list */
1016 $this->DivListSystem->parent = $this;
1017 $this->DivListSystem->execute();
1019 /* Add departments if subsearch is disabled */
1020 if(!$this->DivListSystem->SubSearch){
1021 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1022 }
1023 $this->reload();
1024 $this->DivListSystem->setEntries($this->terminals);
1025 return($this->DivListSystem->Draw());
1026 }
1029 /* Return departments, that will be included within snapshot detection */
1030 function get_used_snapshot_bases()
1031 {
1032 $tmp = array();
1034 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1036 $tabs = array(
1037 "terminal" => get_ou('terminalou'),
1038 "workstation" => get_ou('workstationou'),
1039 "incoming" => get_ou('incomingou'),
1040 "server" => get_ou('serverou'),
1041 "printer" => get_ou('printerou'),
1042 "phone" => get_ou('phoneou'),
1043 "winworkstation" => get_winstations_ou(),
1044 "component" => get_ou('componentou')
1045 );
1047 foreach($tabs as $acl_cat => $dn){
1049 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1050 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1051 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1052 }
1053 }
1054 return($tmp);
1055 }
1058 function remove_from_parent()
1059 {
1060 /* Optionally execute a command after we're done */
1061 $this->postremove();
1062 }
1065 /* Save data to object */
1066 function save_object()
1067 {
1068 $this->DivListSystem->save_object();
1069 }
1072 /* Check values */
1073 function check()
1074 {
1075 }
1078 /* Save to LDAP */
1079 function save()
1080 {
1081 }
1083 function adapt_from_template($dn)
1084 {
1085 }
1087 function password_change_needed()
1088 {
1089 }
1091 function reload()
1092 {
1093 /* some var init */
1094 $ui = get_userinfo();
1095 $res = array();
1096 $this->terminals = array();
1097 $userregex = "";
1099 /* Set base for all searches */
1100 $base= $this->DivListSystem->selectedBase;
1102 /* Prepare samba class name */
1103 $samba ="";
1104 if ($this->DivListSystem->ShowWinWorkstations){
1105 if ($this->config->current['SAMBAVERSION'] == "3"){
1106 $samba= "sambaSamAccount";
1107 } else {
1108 $samba= "sambaAccount";
1109 }
1110 }
1112 /* This array represents the combination between checkboxes and search filters */
1113 $objs = array(
1114 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1115 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1116 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1117 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1118 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1119 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1120 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1122 /* Include the 'Display Systems of user' attribute */
1123 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1124 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1125 }
1127 /* Attributes to fetch */
1128 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1129 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1131 /* Add FAIstate to attributes if FAI is activated */
1132 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1133 if(!empty($tmp)){
1134 $sys_attrs[] = "FAIstate";
1135 }
1137 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1138 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1139 foreach($objs as $checkBox => $oc){
1140 if($this->DivListSystem->$checkBox){
1141 if($this->DivListSystem->SubSearch){
1142 if($oc['CLASS'] != ""){
1143 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1144 $res = array_merge($res,$new_res);
1145 }
1146 }else{
1147 /* User filter? */
1148 if($oc['CLASS'] != ""){
1149 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1150 }
1151 }
1152 }
1153 }
1155 /* Search for incoming objects */
1156 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1158 /* Get all gotoTerminal's */
1159 foreach ($res as $value){
1161 $tmp= $value['dn'];
1162 $add= "";
1164 /* Extract base */
1165 foreach($objs as $obj){
1166 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1167 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1168 }
1169 }
1171 /* Create a string containing the last part of the department. */
1172 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1173 if(empty($dn_name)){
1174 $dn_name = "/";
1175 }
1177 /* check if current object is a new one */
1178 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1179 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1180 $add= "- "._("New terminal");
1181 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1182 $add= "- "._("New workstation");
1183 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1184 $add= "- "._("Unknown device");
1185 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1186 $add= "- "._("New Device");
1187 }
1188 }
1190 /* Detect type of object and create an entry for $this->terminals */
1191 $terminal = array();
1192 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1194 /* check acl */
1195 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1196 if($add != "" || preg_match("/r/",$acl)) {
1197 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1198 $terminal = $value;
1199 $terminal['type'] = "T";
1200 $terminal['is_new'] = $add;
1201 } else {
1202 $terminal = $value;
1203 $terminal['type'] = "D";
1204 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1205 $terminal['location'] = array_search($tmp, $this->config->departments);
1206 }
1207 }
1208 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1210 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1211 if($add != "" || preg_match("/r/",$acl)) {
1212 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1213 $terminal = $value;
1214 $terminal['type'] = "L";
1215 $terminal['is_new'] = $add;
1216 } else {
1217 $terminal = $value;
1218 $terminal['type'] = "D";
1219 $terminal['location'] = array_search($tmp, $this->config->departments);
1220 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1221 }
1222 if (isset($value["FAIstate"][0])){
1223 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1224 }
1225 }
1226 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1229 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1230 if($add != "" || preg_match("/r/",$acl)) {
1232 $terminal = $value;
1233 $terminal['type'] = "P";
1234 }
1235 } elseif (in_array_ics('goServer', $value["objectClass"])){
1237 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1238 if($add != "" || preg_match("/r/",$acl)) {
1240 $terminal = $value;
1241 $terminal['type'] = "S";
1242 if (isset($value["FAIstate"][0])){
1243 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1244 }
1245 }
1246 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1248 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1249 if($add != "" || preg_match("/r/",$acl)) {
1251 $terminal = $value;
1252 $terminal['type'] = "F";
1253 }
1254 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1256 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1257 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1258 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1259 if($add != "" || preg_match("/r/",$acl)) {
1261 $terminal = $value;
1262 $terminal['type'] = "Q";
1263 $terminal['is_new'] = $add;
1264 }
1265 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1267 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1268 if($add != "" || preg_match("/r/",$acl)) {
1270 $terminal = $value;
1271 $terminal['type'] = "C";
1272 }
1273 } else{
1275 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1276 if (isset($value['sambaDomainName'])){
1277 $domain= " [".$value['sambaDomainName'][0]."]";
1278 } else {
1279 $domain= "";
1280 }
1281 $terminal=$value;
1282 $terminal['type'] ="W";
1283 $terminal['domain'] = $name.$domain;
1284 }
1286 if(count($terminal)){
1287 $this->terminals[]=$terminal;
1288 }
1289 }
1291 $tmp =array();
1292 $tmp2 =array();
1293 foreach($this->terminals as $tkey => $val ){
1294 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1295 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1296 }
1297 natcasesort($tmp2);
1298 $this->terminals=array();
1299 foreach($tmp2 as $val){
1300 $this->terminals[]=$tmp[$val];
1301 }
1302 reset ($this->terminals);
1303 }
1305 function remove_lock()
1306 {
1307 if (isset($this->systab->dn)){
1308 del_lock ($this->systab->dn);
1309 }
1310 }
1313 function copyPasteHandling_from_queue($s_action,$s_entry)
1314 {
1315 /* Check if Copy & Paste is disabled */
1316 if(!is_object($this->CopyPasteHandler)){
1317 return("");
1318 }
1321 $tabs = array(
1322 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1323 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1324 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1325 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1326 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1327 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1328 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1329 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1330 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1331 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1332 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1333 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1335 /* Add a single entry to queue */
1336 if($s_action == "cut" || $s_action == "copy"){
1338 /* Cleanup object queue */
1339 $this->CopyPasteHandler->cleanup_queue();
1340 $dn = $this->terminals[$s_entry]['dn'];
1341 $oc = $this->terminals[$s_entry]['objectClass'];
1342 $type = $this->get_system_type($this->terminals[$s_entry]);
1344 $tab_o = $tabs[$type]['CLASS'];
1345 $tab_c = $tabs[$type]['TABCLASS'];
1346 $acl = $tabs[$type]['ACL'];
1348 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1349 }
1351 /* Add entries to queue */
1352 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1354 /* Cleanup object queue */
1355 $this->CopyPasteHandler->cleanup_queue();
1357 /* Add new entries to CP queue */
1358 foreach($this->list_get_selected_items() as $id){
1359 $dn = $this->terminals[$id]['dn'];
1360 $oc = $this->terminals[$id]['objectClass'];
1361 $type = $this->get_system_type($this->terminals[$id]);
1363 if(isset($tabs[$type])){
1364 $tab_o = $tabs[$type]['CLASS'];
1365 $tab_c = $tabs[$type]['TABCLASS'];
1366 $acl = $tabs[$type]['ACL'];
1368 if($s_action == "copy_multiple"){
1369 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1370 }
1371 if($s_action == "cut_multiple"){
1372 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1373 }
1374 }
1375 }
1376 }
1378 /* Start pasting entries */
1379 if($s_action == "editPaste"){
1380 $this->start_pasting_copied_objects = TRUE;
1381 }
1383 /* Return C&P dialog */
1384 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1386 /* Load entry from queue and set base */
1387 $this->CopyPasteHandler->load_entry_from_queue();
1388 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1390 /* Get dialog */
1391 $data = $this->CopyPasteHandler->execute();
1393 /* Return dialog data */
1394 if(!empty($data)){
1395 return($data);
1396 }
1397 }
1399 /* Automatically disable status for pasting */
1400 if(!$this->CopyPasteHandler->entries_queued()){
1401 $this->start_pasting_copied_objects = FALSE;
1402 }
1403 return("");
1404 }
1407 function get_system_type($attrs)
1408 {
1409 $classes = $attrs['objectClass'];
1411 $type= "";
1412 if (in_array_ics('ieee802Device', $classes)){
1413 $type= "component";
1414 }elseif (in_array_ics('gotoTerminal', $classes)){
1415 $type= "terminal";
1416 }elseif (in_array_ics('gotoWorkstation', $classes)){
1417 $type= "workstation";
1418 }elseif (in_array_ics('gotoPrinter', $classes)){
1419 $type= "printer";
1420 }elseif (in_array_ics('goFonHardware', $classes)){
1421 $type= "phone";
1422 }elseif (in_array_ics('goServer', $classes)){
1423 $type= "server";
1424 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1425 $type= "ArpNewDevice";
1426 }elseif (in_array_ics('GOhard', $classes)){
1427 $type= "NewDevice";
1428 }elseif (in_array_ics('sambaAccount', $classes) ||
1429 in_array_ics('sambaSamAccount', $classes)){
1430 $type= "winstation";
1431 }
1432 return ($type);
1433 }
1436 function convert_list($input)
1437 {
1438 $temp= "";
1439 $conv= array(
1440 "NQ" => array("select_newsystem.png",_("New System from incoming")),
1441 "D" => array("select_default.png",_("Template")),
1442 "T" => array("select_terminal.png",_("Terminal")),
1443 "L" => array("select_workstation.png",_("Workstation")),
1444 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1445 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1446 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1447 "F" => array("select_phone.png",_("Phone")),
1448 "S" => array("select_server.png",_("Server")),
1449 "GS" => array("select_server_green.png",_("Server is installing")),
1450 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1451 "RS" => array("select_server_red.png",_("Server installation failed")),
1452 "W" => array("select_winstation.png",_("Winstation")),
1453 "C" => array("select_component.png",_("Network Device")),
1454 "NT"=> array("select_new_terminal.png",_("New Terminal")),
1455 "NL"=> array("select_new_workstation.png",_("New Workstation")),
1456 "P" => array("select_printer.png",_("Printer")));
1458 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1459 $input['type']="N".$input['type'];
1460 }
1461 foreach ($conv as $key => $value){
1462 if($input['type']==$key){
1463 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1464 $tmp['class']=$key;
1465 return $tmp;
1466 }
1467 }
1468 }
1471 function getState($type, $state)
1472 {
1473 switch (preg_replace('/:.*$/', '', $state)) {
1474 case 'installing':
1475 $type= 'G'.$type;
1476 break;
1477 case 'error':
1478 $type= 'R'.$type;
1479 break;
1480 case 'install':
1481 case 'sysinfo':
1482 case 'softupdate':
1483 case 'scheduledupdate':
1484 $type= 'Y'.$type;
1485 break;
1486 }
1489 return ($type);
1490 }
1493 function list_get_selected_items()
1494 {
1495 $ids = array();
1496 foreach($_POST as $name => $value){
1497 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1498 $id = preg_replace("/^item_selected_/","",$name);
1499 $ids[$id] = $id;
1500 }
1501 }
1502 return($ids);
1503 }
1506 /* !! Incoming dummy acls, required to defined acls for incoming objects
1507 */
1508 static function plInfo()
1509 {
1510 return (array(
1511 "plShortName" => _("Incoming objects"),
1512 "plDescription" => _("Incoming objects"),
1513 "plSelfModify" => FALSE,
1514 "plDepends" => array(),
1515 "plPriority" => 99,
1516 "plSection" => array("administration"),
1517 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1518 "objectClass" => "")),
1519 "plProvidedAcls"=> array()
1521 ));
1522 }
1527 }
1529 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1530 ?>