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;
41 function systems (&$config, $ui)
42 {
43 /* Save configuration for internal use */
44 $this->config= $config;
45 $this->ui= $ui;
47 /* Creat dialog object */
48 $this->DivListSystem = new divListSystem($this->config,$this);
50 /* Copy & Paste enabled ?*/
51 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
52 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
53 }
55 /* Check whether the arp handling active or not */
56 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
57 $this->arp_handling_active = TRUE;
58 }
60 }
63 function execute()
64 {
65 /* Call parent execute */
66 plugin::execute();
68 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
70 /********************
71 Check for functional posts, edit|delete|add|... system devices
72 ********************/
73 $s_action = ""; // Contains the action to proceed
74 $s_entry = ""; // The value for s_action
75 $base_back = ""; // The Link for Backbutton
76 $smarty = get_smarty();
78 /* Test Posts */
79 foreach($_POST as $key => $val){
80 // Post for delete
81 if(preg_match("/system_del.*/",$key)){
82 $s_action = "del";
83 $s_entry = preg_replace("/system_del_/i","",$key);
84 // Post for edit
85 }elseif(preg_match("/system_edit_.*/",$key)){
86 $s_action="edit";
87 $s_entry = preg_replace("/system_edit_/i","",$key);
88 // Post for new
89 }elseif(preg_match("/system_new.*/",$key)){
90 $s_action="new";
91 }elseif(preg_match("/system_tplnew.*/i",$key)){
92 $s_action="new_tpl";
93 }elseif(preg_match("/system_setpwd_.*/i",$key)){
94 $s_action="change_pw";
95 $s_entry = preg_replace("/system_setpwd_/i","",$key);
96 }elseif(preg_match("/gen_cd_.*/i",$key)){
97 $s_action="gen_cd";
98 $s_entry = preg_replace("/gen_cd_/i","",$key);
99 }elseif(preg_match("/^copy_.*/",$key)){
100 $s_action="copy";
101 $s_entry = preg_replace("/^copy_/i","",$key);
102 }elseif(preg_match("/^cut_.*/",$key)){
103 $s_action="cut";
104 $s_entry = preg_replace("/^cut_/i","",$key);
105 }
106 }
108 /* Incoming handling
109 * If someone made a systemtype and ogroup selection
110 * Display the new requested entry type ... servtab in case of server and so on.
111 */
112 if(isset($_POST['SystemTypeChoosen'])){
113 $SelectedSystemType = session::get('SelectedSystemType');
114 $s_action = "SelectedSystemType";
115 $s_entry = $_POST['SystemType'];
116 $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
117 $this->systab = NULL;
118 session::set('SelectedSystemType',$SelectedSystemType);
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 /* Check for exeeded sizelimit */
169 if (($message= check_sizelimit()) != ""){
170 return($message);
171 }
173 /* Try to get informations about what kind of system to create */
174 if ($s_action=="new") {
175 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
176 }
179 /********************
180 Copy & Paste Handling ...
181 ********************/
183 /* Display the copy & paste dialog, if it is currently open */
184 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
185 if($ret){
186 return($ret);
187 }
190 /********************
191 Create FAI CD ...
192 ********************/
193 if ($s_action=="gen_cd"){
194 $this->dn= $this->terminals[$s_entry]['dn'];
195 session::set('objectinfo',$this->dn);
196 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
197 }
200 /* Start CD-Creation */
201 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
202 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
203 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
204 }
207 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
209 $return_button = "<form method='get' action='main.php' target='_parent'>
210 <input type='submit' value='"._("Back")."'>
211 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
212 </form>";
214 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
216 /* Get and check command */
217 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
219 if (check_command($command)){
220 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
222 /* Print out html introduction */
223 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
224 <html>
225 <head>
226 <title></title>
227 <style type="text/css">@import url("themes/default/style.css");</style>
228 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
229 </head>
230 <body style="background: none; margin:4px;" id="body" >
231 <pre>';
233 /* Open process handle and check if it is a valid process */
234 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
235 if (is_resource($process)) {
236 fclose($pipes[0]);
238 /* Print out returned lines && write JS to scroll down each line */
239 while (!feof($pipes[1])){
240 $cur_dat = fgets($pipes[1], 1024);
241 echo $cur_dat;
242 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
243 flush();
244 }
245 }
247 /* Get error string && close streams */
248 $buffer= stream_get_contents($pipes[2]);
250 fclose($pipes[1]);
251 fclose($pipes[2]);
252 echo "</pre>";
254 /* Check return code */
255 $ret= proc_close($process);
256 if ($ret != 0){
257 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
258 echo "<pre style='color:red'>$buffer</pre>";
259 }
263 echo $return_button."<br>";
265 } else {
266 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
267 echo $tmp;
268 }
270 /* Scroll down completly */
271 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
272 echo '</body></html>';
273 flush();
274 exit;
275 }
278 /********************
279 Create new system ...
280 ********************/
281 /* Create new default terminal
282 * Or create specified object of selected system type, from given incoming object
283 */
285 $save_object_directly = false;
286 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
287 $save_object_directly = true;
288 }
290 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
292 /* If the current entry is an incoming object
293 * $sw = System type as posted in new incoming handling dialog
294 */
295 if($s_action == "SelectedSystemType") {
296 $sw = $s_entry;
297 }else{
298 if(isset($_POST['system'])){
299 $sw = $_POST['system'];
300 }else{
301 $sw = $s_entry;
302 }
303 $this->dn= "new";
304 }
306 $tabs = array(
307 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
308 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
309 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
310 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
311 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
312 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
314 if(isset($tabs[$sw])){
315 $class = $tabs[$sw]["CLASS"];
316 $tabname = $tabs[$sw]["TABNAME"];
317 $tabclass = $tabs[$sw]["TABCLASS"];
318 $acl_cat = $tabs[$sw]["ACL"];
320 /* Load permissions for selected 'dn' and check if
321 we're allowed to remove this 'dn' */
322 $ui = get_userinfo();
323 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
324 if(preg_match("/c/",$tabacl)){
325 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
326 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
327 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
328 $this->systab->base = $this->DivListSystem->selectedBase;
329 }else{
330 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
331 }
332 }
333 }
335 /********************
336 Edit system ...
337 ********************/
339 /* User wants to edit data? */
340 if (($s_action == "edit") && (!isset($this->systab->config))){
342 $this->dn= $this->terminals[$s_entry]['dn'];
344 /* Check locking, save current plugin in 'back_plugin', so
345 the dialog knows where to return. */
346 if (($user= get_lock($this->dn)) != ""){
347 return(gen_locked_message ($user, $this->dn));
348 }
350 /* Find out more about the object type */
351 $ldap= $this->config->get_ldap_link();
352 $ldap->cat($this->dn, array('objectClass','gotoMode'));
353 $attrs= $ldap->fetch();
354 $type= $this->get_system_type($attrs);
356 /* Lock the current entry, so everyone will get the
357 above dialog */
358 $tabs = array(
359 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
360 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
361 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
362 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
363 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
364 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
365 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
368 if($type == "ArpNewDevice"){
369 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
370 }elseif($type == "NewDevice"){
371 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
372 }elseif(isset($tabs[$type])){
374 $class = $tabs[$type]["CLASS"];
375 $acl_cat = $tabs[$type]["ACL"];
376 $tabclass = $tabs[$type]["TABCLASS"];
378 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
379 $this->systab->set_acl_base($this->dn);
380 session::set('objectinfo',$this->dn);
381 add_lock ($this->dn, $this->ui->dn);
382 }else{
383 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
384 del_lock($this->dn);
385 }
386 }
389 /********************
390 Change password ...
391 ********************/
393 /* Set terminals root password */
394 if ($s_action=="change_pw"){
395 $tabs = array(
396 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
397 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
398 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
399 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
400 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
401 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
402 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
403 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
404 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
406 $dn = $this->terminals[$s_entry]['dn'];
407 $type = $this->get_system_type($this->terminals[$s_entry]);
409 $class = $tabs[$type]["CLASS"];
410 $acl = $tabs[$type]["ACL"];
411 $tabclass = $tabs[$type]["TABCLASS"];
412 $ui = get_userinfo();
413 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
414 if(preg_match("/w/",$tabacl)){
415 $this->dn= $this->terminals[$s_entry]['dn'];
416 session::set('objectinfo',$this->dn);
417 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
418 }else{
419 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
420 }
421 }
424 /********************
425 Password change finish, but check if entered data is ok
426 ********************/
428 /* Correctly specified? */
429 if (isset($_POST['password_finish'])){
430 if ($_POST['new_password'] != $_POST['repeated_password']){
431 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
432 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
433 }
434 }
436 /********************
437 Password change finish
438 ********************/
440 /* Change terminal password */
441 if (isset($_POST['password_finish']) &&
442 $_POST['new_password'] == $_POST['repeated_password']){
444 /* Check if user is allowed to set password */
445 $tabs = array(
446 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
447 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
448 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
449 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
451 /* Detect object type */
452 $type = "";
453 foreach($this->terminals as $terminal){
454 if($terminal['dn'] == $this->dn){
455 $type = $this->get_system_type($terminal);
456 break;
457 }
458 }
460 /* Type detected */
461 $allow_for = array("terminal","workstation","server","component");
462 if(!empty($type) && in_array($type,$allow_for)){
464 /* Get infos */
465 $plug = $tabs[$type]["PLUG"];
466 $class = $tabs[$type]["CLASS"];
467 $acl = $tabs[$type]["ACL"];
468 $tabclass = $tabs[$type]["TABCLASS"];
470 /* Get acls */
471 $ui = get_userinfo();
472 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
474 /* Check acls */
475 if(preg_match("/w/",$tabacl)){
476 $ldap = $this->config->get_ldap_link();
477 $ldap->cd($this->dn);
478 $ldap->cat($this->dn);
479 $old_attrs = $ldap->fetch();
481 $attrs= array();
482 if ($_POST['new_password'] == ""){
484 /* Remove password attribute
485 */
486 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
487 $attrs['objectClass'] = array();
488 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
489 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
490 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
491 }
492 }
493 }
494 $attrs['userPassword']= array();
495 } else {
497 /* Add/modify password attribute
498 */
499 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
500 $attrs['objectClass'] = array();
501 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
502 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
503 }
504 $attrs['objectClass'][] = "simpleSecurityObject";
505 }
507 if(class_available("passwordMethodCrypt")){
508 $pwd_m = new passwordMethodCrypt($this->config);
509 $pwd_m->set_hash("crypt/md5");
510 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
511 }else{
512 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
513 $attrs = array();
514 }
515 }
516 $ldap->modify($attrs);
517 if (!$ldap->success()){
518 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
519 }else{
520 if(class_available($plug)){
521 $p = new $plug($this->config,$this->dn);
522 $p->handle_post_events("modify");
523 }
524 }
526 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
527 }else{
528 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
529 }
530 }else{
531 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
532 }
533 session::un_set('objectinfo');
534 }
537 /********************
538 Delete system cancel
539 ********************/
541 /* Delete terminal canceled? */
542 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
543 del_lock ($this->dn);
544 session::un_set('objectinfo');
545 }
548 /********************
549 Action(s) for MULTIPLE
550 ********************/
552 /********************
553 SCHEDULE action in GOsa Daemon
554 ********************/
556 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
557 $this->dns = array();
558 $ids = $this->list_get_selected_items();
560 if(count($ids)){
561 $mac= array();
563 $ldap = $this->config->get_ldap_link();
564 foreach($ids as $id){
565 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
566 $attrs= $ldap->fetch();
567 if (isset($attrs['macAddress'][0])){
568 $mac[]= $attrs['macAddress'][0];
569 }
570 }
571 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
572 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
573 $o_queue = new gosaSupportDaemon();
575 /* Skip installation or update trigerred events,
576 * if this entry is currently processing.
577 */
578 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
579 foreach($mac as $key => $mac_address){
580 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
582 $entry['STATUS'] = strtoupper($entry['STATUS']);
583 if($entry['STATUS'] == "PROCESSING" &&
584 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
585 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
586 unset($mac[$key]);
588 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
589 break;
590 }
591 }
592 }
593 }
595 /* Prepare event to be added
596 */
597 if(count($mac) && isset($events['BY_CLASS'][$type])){
598 $event = $events['BY_CLASS'][$type];
599 $this->systab = new $event['CLASS_NAME']($this->config);
600 $this->systab->add_targets($mac);
601 if(preg_match("/trigger_event/",$s_action)){
602 $this->systab->set_type(TRIGGERED_EVENT);
603 }else{
604 $this->systab->set_type(SCHEDULED_EVENT);
605 }
606 }
607 }
608 }
610 /* Insert scheduled events into queue */
611 if($this->systab instanceof DaemonEvent){
612 $this->systab->save_object();
614 /* Save event
615 */
616 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
617 $o_queue = new gosaSupportDaemon();
618 $o_queue->append($this->systab);
619 if($o_queue->is_error()){
620 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
621 }else{
622 $this->systab = FALSE;
623 }
624 }
625 if(isset($_POST['abort_event_dialog'])){
626 $this->systab = FALSE;
627 }
628 }
631 /********************
632 Delete MULTIPLE entries requested, display confirm dialog
633 ********************/
635 if ($s_action=="del_multiple"){
636 $this->dns = array();
637 $ids = $this->list_get_selected_items();
639 if(count($ids)){
641 foreach($ids as $id){
642 $dn = $this->terminals[$id]['dn'];
643 $this->dns[$id] = $dn;
644 }
645 if ($user= get_multiple_locks($this->dns)){
646 return(gen_locked_message($user,$this->dns));
647 }
649 $dns_names = array();
650 foreach($this->dns as $dn){
651 add_lock ($dn, $this->ui->dn);
652 $dns_names[] = @LDAP::fix($dn);
653 }
655 /* Lock the current entry, so nobody will edit it during deletion */
656 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
657 $smarty->assign("multiple", true);
658 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
659 }
660 }
663 /********************
664 Delete MULTIPLE entries confirmed
665 ********************/
667 /* Confirmation for deletion has been passed. Users should be deleted. */
668 if (isset($_POST['delete_multiple_system_confirm'])){
670 $ui = get_userinfo();
671 $tabs = array(
672 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
673 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
674 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
675 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
676 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
677 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
678 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
679 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
680 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
683 /* Remove user by user and check acls before removeing them */
684 foreach($this->dns as $key => $dn){
686 /* Get 'dn' from posted termlinst */
687 $attrs = $this->terminals[$key];
688 $type= $this->get_system_type($attrs);
690 /* get object type */
691 $tabtype = "termtabs";
692 $tabobj = "TERMTABS";
693 $tabacl = "";
694 if(isset($tabs[$type])){
695 $tabtype = $tabs[$type]['TABCLASS'];
696 $tabobj = $tabs[$type]['CLASS'];
697 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
699 /* Load permissions for selected 'dn' and check if
700 we're allowed to remove this 'dn' */
701 if(preg_match("/d/",$tabacl)){
703 /* Delete request is permitted, perform LDAP action */
704 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
705 $this->systab= new termgeneric($this->config, $dn);
706 $this->systab->set_acl_base($dn);
707 $this->systab->remove_from_parent();
708 }elseif($tabtype=="phonetabs"){
709 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
710 $this->systab->set_acl_base($dn);
711 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
712 }else{
713 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
714 $this->systab->set_acl_base($dn);
715 $this->systab->delete();
716 }
717 unset ($this->systab);
718 $this->systab= NULL;
720 } else {
721 /* Normally this shouldn't be reached, send some extra
722 logs to notify the administrator */
723 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
724 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
725 }
726 /* Remove lock file after successfull deletion */
727 del_lock ($dn);
728 unset($this->dns[$key]);
729 }
730 }
731 }
733 /********************
734 Delete MULTIPLE entries Canceled
735 ********************/
737 /* Remove lock */
738 if(isset($_POST['delete_multiple_system_cancel'])){
739 foreach($this->dns as $key => $dn){
740 del_lock ($dn);
741 unset($this->dns[$key]);
742 }
743 }
746 /********************
747 Delete system, confirm dialog
748 ********************/
750 /* Remove terminal was requested */
751 if ($s_action=="del"){
753 /* Get 'dn' from posted termlinst */
754 $this->dn = $this->terminals[$s_entry]['dn'];
755 $attrs = $this->terminals[$s_entry];
759 $type= $this->get_system_type($attrs);
760 $ui = get_userinfo();
761 $tabs = array(
762 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
763 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
764 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
765 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
766 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
767 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
768 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
769 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
770 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
772 /* get object type */
773 $tabtype = "termtabs";
774 $tabobj = "TERMTABS";
775 $tabacl = "";
776 if(isset($tabs[$type])){
777 $tabtype = $tabs[$type]['TABCLASS'];
778 $tabobj = $tabs[$type]['CLASS'];
779 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
780 }
782 /* Load permissions for selected 'dn' and check if
783 we're allowed to remove this 'dn' */
784 if(preg_match("/d/",$tabacl)){
786 /* Check locking, save current plugin in 'back_plugin', so
787 the dialog knows where to return. */
788 if (($user= get_lock($this->dn)) != ""){
789 return(gen_locked_message ($user, $this->dn));
790 }
792 /* Lock the current entry, so nobody will edit it during deletion */
793 add_lock ($this->dn, $this->ui->dn);
794 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
795 $smarty->assign("multiple", false);
796 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
797 } else {
799 /* Obviously the user isn't allowed to delete. Show message and
800 clean session. */
801 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
802 }
803 }
806 /********************
807 Delete system, confirmed
808 ********************/
809 /* Confirmation for deletion has been passed. Terminal should be deleted. */
810 if (isset($_POST['delete_terminal_confirm'])){
812 /* Find out more about the object type */
813 $ldap= $this->config->get_ldap_link();
814 $ldap->cat($this->dn, array('objectClass'));
815 $attrs= $ldap->fetch();
816 $type= $this->get_system_type($attrs);
818 $ui = get_userinfo();
820 $tabs = array(
821 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
822 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
823 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
824 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
825 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
826 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
827 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
828 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
829 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
831 /* get object type */
832 $tabtype = "termtabs";
833 $tabobj = "TERMTABS";
834 $tabacl = "";
835 if(isset($tabs[$type])){
836 $tabtype = $tabs[$type]['TABCLASS'];
837 $tabobj = $tabs[$type]['CLASS'];
838 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
839 }
841 /* Check if we are allowed to remove this object */
842 if(preg_match("/d/",$tabacl)){
844 /* Delete request is permitted, perform LDAP action */
845 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
846 $this->systab= new termgeneric($this->config, $this->dn);
847 $this->systab->set_acl_base($this->dn);
848 $this->systab->remove_from_parent();
849 }elseif($tabtype=="phonetabs"){
850 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
851 $this->systab->set_acl_base($this->dn);
852 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
853 }else{
854 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
855 $this->systab->set_acl_base($this->dn);
856 $this->systab->delete();
857 }
858 unset ($this->systab);
859 $this->systab= NULL;
861 /* Terminal list has changed, reload it. */
862 } else {
864 /* Normally this shouldn't be reached, send some extra
865 logs to notify the administrator */
866 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
867 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
868 }
870 /* Remove lock file after successfull deletion */
871 del_lock ($this->dn);
872 }
875 /********************
876 Edit system type finished, check if everything went ok
877 ********************/
878 /* Finish user edit is triggered by the tabulator dialog, so
879 the user wants to save edited data. Check and save at this
880 point. */
881 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
883 /* Check tabs, will feed message array */
884 $message = array();
885 if(!$save_object_directly){
886 $message = $this->systab->check();
887 }else{
888 $found = false;
890 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
891 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
892 if(isset($this->systab->by_object[$tab]->gotoMode)) {
893 $found = true;
894 $this->systab->by_object[$tab]->gotoMode = $value;
895 }
896 }
897 if(!$found){
898 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
899 }
901 }
902 /* Save, or display error message? */
903 if (count($message) == 0){
905 /* Incoming behavior; you can select a system type and an ogroup membership.
906 * If this object is an Incoming object, session::get('SelectedSystemType') isset.
907 * Check if we must add the new object to an object group.
908 *
909 * If this is done, delete the old incoming entry... it is still there, because this is a new
910 * entry and not an edited one, so we will delete it.
911 *
912 */
913 if(session::is_set('SelectedSystemType')){
914 $SelectedSystemType = session::get('SelectedSystemType');
915 if($SelectedSystemType['ogroup'] != "none"){
916 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
917 if($og){
918 $og->AddDelMembership($this->systab->dn);
919 $og->save();
920 }
921 }
922 }
924 /* Save terminal data to ldap */
925 $SelectedSystemType = session::get('SelectedSystemType');
926 if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
927 foreach (array("workservice", "termservice") as $cls){
928 if (isset($this->systab->by_object[$cls])){
929 $this->systab->by_object[$cls]->gotoXMouseport= "";
930 $this->systab->by_object[$cls]->gotoXMouseType= "";
931 $this->systab->by_object[$cls]->gotoXResolution= "";
932 $this->systab->by_object[$cls]->gotoXColordepth= "";
933 }
934 }
935 }
937 $this->systab->save();
939 if(session::is_set('SelectedSystemType')){
940 session::un_set('SelectedSystemType');
941 if(!isset($ldap)){
942 $ldap = $this->config->get_ldap_link();
943 }
944 $ldap->cd ($this->dn);
945 $ldap->cat($this->dn, array('dn'));
946 if(count($ldap->fetch())){
947 $ldap->cd($this->dn);
948 $ldap->rmDir($this->dn);
949 }
950 $ldap->cd($this->config->current['BASE']);
951 }
953 /* Terminal has been saved successfully, remove lock from LDAP. */
954 if (!isset($_POST['edit_apply'])){
955 if ($this->dn != "new"){
956 del_lock ($this->dn);
957 }
959 unset ($this->systab);
960 $this->systab= NULL;
961 session::un_set('objectinfo');
962 }
963 } else {
964 /* Ok. There seem to be errors regarding to the tab data,
965 show message and continue as usual. */
966 msg_dialog::displayChecks($message);
967 }
968 }
971 /********************
972 Edit system was canceled
973 ********************/
974 /* Cancel dialogs */
975 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
976 if (isset($this->systab)){
977 del_lock ($this->systab->dn);
978 unset ($this->systab);
979 }
980 $this->systab= NULL;
981 session::un_set('objectinfo');
983 /* Remove ogroup selection, which was set while editing a new incoming entry */
984 if(session::is_set('SelectedSystemType')){
985 session::un_set('SelectedSystemType');
986 }
987 }
989 /********************
990 Display edit dialog, or some other
991 ********************/
993 /* Show tab dialog if object is present */
994 if (isset($this->systab->config)){
995 $display= $this->systab->execute();
997 /* Don't show buttons if tab dialog requests this */
999 $dialog = FALSE;
1000 $hide_apply = $this->dn == "new";
1001 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1002 if(is_object($this->systab) && !isset($this->systab->by_object)){
1003 $dialog = TRUE;
1004 $hide_apply = TRUE;
1005 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1006 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1007 if($dia === TRUE || is_object($dia)){
1008 $dialog = TRUE;
1009 }
1010 }
1011 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1012 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1013 $dialog = TRUE;
1014 }
1016 if (!$dialog){
1017 $display.= "<p style=\"text-align:right\">\n";
1018 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1019 $display.= " \n";
1020 if (!$hide_apply){
1021 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1022 $display.= " \n";
1023 }
1024 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1025 $display.= "</p>";
1026 }
1027 return ($display);
1028 }
1030 /* Check if there is a snapshot dialog open */
1031 $base = $this->DivListSystem->selectedBase;
1032 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1033 return($str);
1034 }
1036 /* Display dialog with system list */
1037 $this->DivListSystem->parent = $this;
1038 $this->DivListSystem->execute();
1040 /* Add departments if subsearch is disabled */
1041 if(!$this->DivListSystem->SubSearch){
1042 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1043 }
1044 $this->reload();
1045 $this->DivListSystem->setEntries($this->terminals);
1046 return($this->DivListSystem->Draw());
1047 }
1050 /* Return departments, that will be included within snapshot detection */
1051 function get_used_snapshot_bases()
1052 {
1053 $tmp = array();
1055 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1057 $tabs = array(
1058 "terminal" => get_ou('terminalou'),
1059 "workstation" => get_ou('workstationou'),
1060 "incoming" => get_ou('incomingou'),
1061 "server" => get_ou('serverou'),
1062 "printer" => get_ou('printerou'),
1063 "phone" => get_ou('phoneou'),
1064 "winworkstation" => get_winstations_ou(),
1065 "component" => get_ou('componentou')
1066 );
1068 foreach($tabs as $acl_cat => $dn){
1070 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1071 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1072 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1073 }
1074 }
1075 return($tmp);
1076 }
1079 function remove_from_parent()
1080 {
1081 /* Optionally execute a command after we're done */
1082 $this->postremove();
1083 }
1086 /* Save data to object */
1087 function save_object()
1088 {
1089 $this->DivListSystem->save_object();
1090 if(is_object($this->CopyPasteHandler)){
1091 $this->CopyPasteHandler->save_object();
1092 }
1093 }
1096 /* Check values */
1097 function check()
1098 {
1099 }
1102 /* Save to LDAP */
1103 function save()
1104 {
1105 }
1107 function adapt_from_template($dn, $skip= array())
1108 {
1109 }
1111 function password_change_needed()
1112 {
1113 }
1115 function reload()
1116 {
1117 /* some var init */
1118 $ui = get_userinfo();
1119 $res = array();
1120 $this->terminals = array();
1121 $userregex = "";
1123 /* Set base for all searches */
1124 $base= $this->DivListSystem->selectedBase;
1126 /* Prepare samba class name */
1127 $samba ="";
1128 if ($this->DivListSystem->ShowWinWorkstations){
1129 if ($this->config->current['SAMBAVERSION'] == "3"){
1130 $samba= "sambaSamAccount";
1131 } else {
1132 $samba= "sambaAccount";
1133 }
1134 }
1136 /* This array represents the combination between checkboxes and search filters */
1137 $objs = array(
1138 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1139 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1140 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1141 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1142 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1143 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1144 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1146 /* Include the 'Display Systems of user' attribute */
1147 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1148 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1149 }
1151 /* Attributes to fetch */
1152 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1153 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1155 /* Add FAIstate to attributes if FAI is activated */
1156 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1157 if(!empty($tmp)){
1158 $sys_attrs[] = "FAIstate";
1159 }
1161 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1162 foreach($objs as $checkBox => $oc){
1163 if($this->DivListSystem->$checkBox){
1164 if($this->DivListSystem->SubSearch){
1165 if($oc['CLASS'] != ""){
1166 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1167 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1168 $res = array_merge($res,$new_res);
1169 }
1170 }else{
1171 /* User filter? */
1172 if($oc['CLASS'] != ""){
1173 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1174 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1175 }
1176 }
1177 }
1178 }
1180 /* Search for incoming objects */
1181 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1182 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1184 /* Get all gotoTerminal's */
1185 foreach ($res as $value){
1187 $tmp= $value['dn'];
1188 $add= "";
1190 /* Extract base */
1191 foreach($objs as $obj){
1192 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1193 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1194 }
1195 }
1197 /* Create a string containing the last part of the department. */
1198 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1199 if(empty($dn_name)){
1200 $dn_name = "/";
1201 }
1203 /* check if current object is a new one */
1204 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1205 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1206 $add= "- "._("New terminal");
1207 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1208 $add= "- "._("New workstation");
1209 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1210 $add= "- "._("Unknown device");
1211 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1212 $add= "- "._("New Device");
1213 }
1214 }
1216 /* Detect type of object and create an entry for $this->terminals */
1217 $terminal = array();
1218 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1220 /* check acl */
1221 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1222 if($add != "" || preg_match("/r/",$acl)) {
1223 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1224 $terminal = $value;
1225 $terminal['type'] = "T";
1226 $terminal['is_new'] = $add;
1227 } else {
1228 $terminal = $value;
1229 $terminal['type'] = "D";
1230 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1231 $terminal['location'] = array_search($tmp, $this->config->departments);
1232 }
1233 }
1234 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1236 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1237 if($add != "" || preg_match("/r/",$acl)) {
1238 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1239 $terminal = $value;
1240 $terminal['type'] = "L";
1241 $terminal['is_new'] = $add;
1242 } else {
1243 $terminal = $value;
1244 $terminal['type'] = "D";
1245 $terminal['location'] = array_search($tmp, $this->config->departments);
1246 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1247 }
1248 if (isset($value["FAIstate"][0])){
1249 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1250 }
1251 }
1252 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1255 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1256 if($add != "" || preg_match("/r/",$acl)) {
1258 $terminal = $value;
1259 $terminal['type'] = "P";
1260 }
1261 } elseif (in_array_ics('goServer', $value["objectClass"])){
1263 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1264 if($add != "" || preg_match("/r/",$acl)) {
1266 $terminal = $value;
1267 $terminal['type'] = "S";
1268 if (isset($value["FAIstate"][0])){
1269 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1270 }
1271 }
1272 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1274 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1275 if($add != "" || preg_match("/r/",$acl)) {
1277 $terminal = $value;
1278 $terminal['type'] = "F";
1279 }
1280 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1282 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1283 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1284 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1285 if($add != "" || preg_match("/r/",$acl)) {
1287 $terminal = $value;
1288 $terminal['type'] = "Q";
1289 $terminal['is_new'] = $add;
1290 }
1291 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1293 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1294 if($add != "" || preg_match("/r/",$acl)) {
1296 $terminal = $value;
1297 $terminal['type'] = "C";
1298 }
1299 } else{
1301 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1302 if (isset($value['sambaDomainName'])){
1303 $domain= " [".$value['sambaDomainName'][0]."]";
1304 } else {
1305 $domain= "";
1306 }
1307 $terminal=$value;
1308 $terminal['type'] ="W";
1309 $terminal['domain'] = $name.$domain;
1310 }
1312 if(count($terminal)){
1313 $this->terminals[]=$terminal;
1314 }
1315 }
1317 $tmp =array();
1318 $tmp2 =array();
1319 foreach($this->terminals as $tkey => $val ){
1320 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1321 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1322 }
1323 natcasesort($tmp2);
1324 $this->terminals=array();
1325 foreach($tmp2 as $val){
1326 $this->terminals[]=$tmp[$val];
1327 }
1328 reset ($this->terminals);
1329 }
1331 function remove_lock()
1332 {
1333 if (isset($this->systab->dn)){
1334 del_lock ($this->systab->dn);
1335 }
1336 }
1339 function copyPasteHandling_from_queue($s_action,$s_entry)
1340 {
1341 /* Check if Copy & Paste is disabled */
1342 if(!is_object($this->CopyPasteHandler)){
1343 return("");
1344 }
1347 $tabs = array(
1348 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1349 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1350 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1351 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1352 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1353 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1354 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1355 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1356 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1357 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1358 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1359 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1361 /* Add a single entry to queue */
1362 if($s_action == "cut" || $s_action == "copy"){
1364 /* Cleanup object queue */
1365 $this->CopyPasteHandler->cleanup_queue();
1366 $dn = $this->terminals[$s_entry]['dn'];
1367 $oc = $this->terminals[$s_entry]['objectClass'];
1368 $type = $this->get_system_type($this->terminals[$s_entry]);
1370 $tab_o = $tabs[$type]['CLASS'];
1371 $tab_c = $tabs[$type]['TABCLASS'];
1372 $acl = $tabs[$type]['ACL'];
1374 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1375 }
1377 /* Add entries to queue */
1378 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1380 /* Cleanup object queue */
1381 $this->CopyPasteHandler->cleanup_queue();
1383 /* Add new entries to CP queue */
1384 foreach($this->list_get_selected_items() as $id){
1385 $dn = $this->terminals[$id]['dn'];
1386 $oc = $this->terminals[$id]['objectClass'];
1387 $type = $this->get_system_type($this->terminals[$id]);
1389 if(isset($tabs[$type])){
1390 $tab_o = $tabs[$type]['CLASS'];
1391 $tab_c = $tabs[$type]['TABCLASS'];
1392 $acl = $tabs[$type]['ACL'];
1394 if($s_action == "copy_multiple"){
1395 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1396 }
1397 if($s_action == "cut_multiple"){
1398 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1399 }
1400 }
1401 }
1402 }
1404 /* Start pasting entries */
1405 if($s_action == "editPaste"){
1406 $this->start_pasting_copied_objects = TRUE;
1407 }
1409 /* Return C&P dialog */
1410 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1412 /* Get dialog */
1413 $data = $this->CopyPasteHandler->execute();
1414 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1416 /* Return dialog data */
1417 if(!empty($data)){
1418 return($data);
1419 }
1420 }
1422 /* Automatically disable status for pasting */
1423 if(!$this->CopyPasteHandler->entries_queued()){
1424 $this->start_pasting_copied_objects = FALSE;
1425 }
1426 return("");
1427 }
1430 function get_system_type($attrs)
1431 {
1432 $classes = $attrs['objectClass'];
1434 $type= "";
1435 if (in_array_ics('ieee802Device', $classes)){
1436 $type= "component";
1437 }elseif (in_array_ics('gotoTerminal', $classes)){
1438 $type= "terminal";
1439 }elseif (in_array_ics('gotoWorkstation', $classes)){
1440 $type= "workstation";
1441 }elseif (in_array_ics('gotoPrinter', $classes)){
1442 $type= "printer";
1443 }elseif (in_array_ics('goFonHardware', $classes)){
1444 $type= "phone";
1445 }elseif (in_array_ics('goServer', $classes)){
1446 $type= "server";
1447 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1448 $type= "ArpNewDevice";
1449 }elseif (in_array_ics('GOhard', $classes)){
1450 $type= "NewDevice";
1451 }elseif (in_array_ics('sambaAccount', $classes) ||
1452 in_array_ics('sambaSamAccount', $classes)){
1453 $type= "winstation";
1454 }
1455 return ($type);
1456 }
1459 function convert_list($input)
1460 {
1461 $temp= "";
1462 $conv= array(
1463 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1464 "D" => array("select_default.png",_("Template")),
1465 "T" => array("select_terminal.png",_("Terminal")),
1466 "L" => array("select_workstation.png",_("Workstation")),
1467 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1468 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1469 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1470 "F" => array("select_phone.png",_("Phone")),
1471 "S" => array("select_server.png",_("Server")),
1472 "GS" => array("select_server_green.png",_("Server is installing")),
1473 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1474 "RS" => array("select_server_red.png",_("Server installation failed")),
1475 "W" => array("select_winstation.png",_("Win workstation")),
1476 "C" => array("select_component.png",_("Network device")),
1477 "NT"=> array("select_new_terminal.png",_("New terminal")),
1478 "NL"=> array("select_new_workstation.png",_("New workstation")),
1479 "P" => array("select_printer.png",_("Printer")));
1481 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1482 $input['type']="N".$input['type'];
1483 }
1484 foreach ($conv as $key => $value){
1485 if($input['type']==$key){
1486 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1487 $tmp['class']=$key;
1488 return $tmp;
1489 }
1490 }
1491 }
1494 function getState($type, $state)
1495 {
1496 switch (preg_replace('/:.*$/', '', $state)) {
1497 case 'installing':
1498 $type= 'G'.$type;
1499 break;
1500 case 'error':
1501 $type= 'R'.$type;
1502 break;
1503 case 'install':
1504 case 'sysinfo':
1505 case 'softupdate':
1506 case 'scheduledupdate':
1507 $type= 'Y'.$type;
1508 break;
1509 }
1512 return ($type);
1513 }
1516 function list_get_selected_items()
1517 {
1518 $ids = array();
1519 foreach($_POST as $name => $value){
1520 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1521 $id = preg_replace("/^item_selected_/","",$name);
1522 $ids[$id] = $id;
1523 }
1524 }
1525 return($ids);
1526 }
1529 /* !! Incoming dummy acls, required to defined acls for incoming objects
1530 */
1531 static function plInfo()
1532 {
1533 return (array(
1534 "plShortName" => _("Incoming objects"),
1535 "plDescription" => _("Incoming objects"),
1536 "plSelfModify" => FALSE,
1537 "plDepends" => array(),
1538 "plPriority" => 99,
1539 "plSection" => array("administration"),
1540 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1541 "objectClass" => "")),
1542 "plProvidedAcls"=> array()
1544 ));
1545 }
1550 }
1552 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1553 ?>