1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class systems extends plugin
24 {
25 /* Definitions */
26 var $plHeadline = "Systems";
27 var $plDescription = "This does something";
28 var $departments = array();
30 /* Dialog attributes */
31 var $systab = NULL;
32 var $terminals= array();
33 var $ui = NULL;
34 var $DivListSystem;
35 var $start_pasting_copied_objects = FALSE;
36 var $CopyPasteHandler = NULL;
38 /* Arp hanlding activated */
39 var $arp_handling_active = FALSE;
40 var $last_action = "";
42 function systems (&$config, $ui)
43 {
44 /* Save configuration for internal use */
45 $this->config= $config;
46 $this->ui= $ui;
48 /* Creat dialog object */
49 $this->DivListSystem = new divListSystem($this->config,$this);
51 /* Copy & Paste enabled ?*/
52 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
53 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
54 }
56 /* Check whether the arp handling active or not */
57 if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
58 $this->arp_handling_active = TRUE;
59 }
61 }
64 function execute()
65 {
66 /* Call parent execute */
67 plugin::execute();
69 session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/","/^menu_action/"));
71 /********************
72 Check for functional posts, edit|delete|add|... system devices
73 ********************/
74 $s_action = ""; // Contains the action to proceed
75 $s_entry = ""; // The value for s_action
76 $base_back = ""; // The Link for Backbutton
77 $smarty = get_smarty();
79 /* Test Posts */
80 foreach($_POST as $key => $val){
81 // Post for delete
82 if(preg_match("/system_del.*/",$key)){
83 $s_action = "del";
84 $s_entry = preg_replace("/system_del_/i","",$key);
85 // Post for edit
86 }elseif(preg_match("/system_edit_.*/",$key)){
87 $s_action="edit";
88 $s_entry = preg_replace("/system_edit_/i","",$key);
89 // Post for new
90 }elseif(preg_match("/system_new.*/",$key)){
91 $s_action="new";
92 }elseif(preg_match("/system_tplnew.*/i",$key)){
93 $s_action="new_tpl";
94 }elseif(preg_match("/system_setpwd_.*/i",$key)){
95 $s_action="change_pw";
96 $s_entry = preg_replace("/system_setpwd_/i","",$key);
97 }elseif(preg_match("/gen_cd_.*/i",$key)){
98 $s_action="gen_cd";
99 $s_entry = preg_replace("/gen_cd_/i","",$key);
100 }elseif(preg_match("/^copy_.*/",$key)){
101 $s_action="copy";
102 $s_entry = preg_replace("/^copy_/i","",$key);
103 }elseif(preg_match("/^cut_.*/",$key)){
104 $s_action="cut";
105 $s_entry = preg_replace("/^cut_/i","",$key);
106 }
107 }
109 /* Incoming handling
110 * If someone made a systemtype and ogroup selection
111 * Display the new requested entry type ... servtab in case of server and so on.
112 */
113 if(isset($_POST['SystemTypeChoosen'])){
114 $SelectedSystemType = session::get('SelectedSystemType');
115 $s_action = "SelectedSystemType";
116 $s_entry = $_POST['SystemType'];
117 $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
118 $this->systab = NULL;
119 session::set('SelectedSystemType',$SelectedSystemType);
120 }
122 /* remove image tags from posted entry (posts looks like this 'name_x')*/
123 $s_entry = preg_replace("/_.$/","",$s_entry);
125 /* Edit was requested by pressing the name(link) of an item */
126 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
127 $s_action ="edit";
128 $s_entry = $_GET['id'];
129 }
130 /* Create options */
131 if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
132 $s_action = "newsystem";
133 $s_entry = preg_replace("/^newsystem_/","",$_POST['menu_action']);
134 }
136 /* handle C&P from layers menu */
137 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
138 $s_action = "copy_multiple";
139 }
140 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
141 $s_action = "cut_multiple";
142 }
143 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
144 $s_action = "editPaste";
145 }
147 /* Handle daemon events */
148 if(isset($_POST['menu_action']) && preg_match("/^trigger_event_/",$_POST['menu_action'])){
149 $s_action = $_POST['menu_action'];
150 }
152 /* Handle daemon events */
153 if(isset($_POST['menu_action']) && preg_match("/^schedule_event_/",$_POST['menu_action'])){
154 $s_action = $_POST['menu_action'];
155 }
157 /* handle remove from layers menu */
158 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
159 $s_action = "del_multiple";
160 }
162 /* Handle instant actions from layers menu */
163 foreach (array("halt", "reboot", "reinstall", "update", "wake") as $act){
164 if(isset($_POST['menu_action']) && preg_match("/^${act}_multiple/",$_POST['menu_action'])){
165 $s_action = "${act}_multiple";
166 }
167 }
169 /* Check for exeeded sizelimit */
170 if (($message= check_sizelimit()) != ""){
171 return($message);
172 }
174 /* Try to get informations about what kind of system to create */
175 if ($s_action=="new") {
176 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
177 }
180 /********************
181 Copy & Paste Handling ...
182 ********************/
184 /* Display the copy & paste dialog, if it is currently open */
185 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
186 if($ret){
187 return($ret);
188 }
191 /********************
192 Create FAI CD ...
193 ********************/
194 if ($s_action=="gen_cd"){
195 $this->dn= $this->terminals[$s_entry]['dn'];
196 session::set('objectinfo',$this->dn);
197 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
198 }
201 /* Start CD-Creation */
202 if ((isset($_POST["cd_create"])) && !empty($this->dn)){
203 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
204 return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
205 }
208 if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
210 $return_button = "<form method='get' action='main.php' target='_parent'>
211 <input type='submit' value='"._("Back")."'>
212 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
213 </form>";
215 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
217 /* Get and check command */
218 $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
220 if (check_command($command)){
221 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
223 /* Print out html introduction */
224 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
225 <html>
226 <head>
227 <title></title>
228 <style type="text/css">@import url("themes/default/style.css");</style>
229 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
230 </head>
231 <body style="background: none; margin:4px;" id="body" >
232 <pre>';
234 /* Open process handle and check if it is a valid process */
235 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
236 if (is_resource($process)) {
237 fclose($pipes[0]);
239 /* Print out returned lines && write JS to scroll down each line */
240 while (!feof($pipes[1])){
241 $cur_dat = fgets($pipes[1], 1024);
242 echo $cur_dat;
243 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
244 flush();
245 }
246 }
248 /* Get error string && close streams */
249 $buffer= stream_get_contents($pipes[2]);
251 fclose($pipes[1]);
252 fclose($pipes[2]);
253 echo "</pre>";
255 /* Check return code */
256 $ret= proc_close($process);
257 if ($ret != 0){
258 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
259 echo "<pre style='color:red'>$buffer</pre>";
260 }
264 echo $return_button."<br>";
266 } else {
267 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
268 echo $tmp;
269 }
271 /* Scroll down completly */
272 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
273 echo '</body></html>';
274 flush();
275 exit;
276 }
279 /********************
280 Create new system ...
281 ********************/
282 /* Create new default terminal
283 * Or create specified object of selected system type, from given incoming object
284 */
286 $save_object_directly = false;
287 if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
288 $save_object_directly = true;
289 }
291 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
293 /* If the current entry is an incoming object
294 * $sw = System type as posted in new incoming handling dialog
295 */
296 if($s_action == "SelectedSystemType") {
297 $sw = $s_entry;
298 }else{
299 if(isset($_POST['system'])){
300 $sw = $_POST['system'];
301 }else{
302 $sw = $s_entry;
303 }
304 $this->dn= "new";
305 }
307 $tabs = array(
308 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
309 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
310 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
311 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
312 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phoneGeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
313 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
315 if(isset($tabs[$sw])){
316 $class = $tabs[$sw]["CLASS"];
317 $tabname = $tabs[$sw]["TABNAME"];
318 $tabclass = $tabs[$sw]["TABCLASS"];
319 $acl_cat = $tabs[$sw]["ACL"];
321 /* Load permissions for selected 'dn' and check if
322 we're allowed to remove this 'dn' */
323 $ui = get_userinfo();
324 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
325 if(preg_match("/c/",$tabacl)){
326 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
327 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
328 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
329 $this->systab->base = $this->DivListSystem->selectedBase;
330 }else{
331 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
332 }
333 }
334 }
336 /********************
337 Edit system ...
338 ********************/
340 /* User wants to edit data? */
341 if (($s_action == "edit") && (!isset($this->systab->config))){
343 $this->dn= $this->terminals[$s_entry]['dn'];
345 /* Check locking, save current plugin in 'back_plugin', so
346 the dialog knows where to return. */
347 if (($user= get_lock($this->dn)) != ""){
348 return(gen_locked_message ($user, $this->dn));
349 }
351 /* Find out more about the object type */
352 $ldap= $this->config->get_ldap_link();
353 $ldap->cat($this->dn, array('objectClass','gotoMode'));
354 $attrs= $ldap->fetch();
355 $type= $this->get_system_type($attrs);
357 /* Lock the current entry, so everyone will get the
358 above dialog */
359 $tabs = array(
360 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
361 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
362 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
363 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
364 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
365 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
366 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
369 if($type == "ArpNewDevice"){
370 $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
371 }elseif($type == "NewDevice"){
372 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
373 }elseif(isset($tabs[$type])){
375 $class = $tabs[$type]["CLASS"];
376 $acl_cat = $tabs[$type]["ACL"];
377 $tabclass = $tabs[$type]["TABCLASS"];
379 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
380 $this->systab->set_acl_base($this->dn);
381 session::set('objectinfo',$this->dn);
382 add_lock ($this->dn, $this->ui->dn);
383 }else{
384 msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
385 del_lock($this->dn);
386 }
387 }
390 /********************
391 Change password ...
392 ********************/
394 /* Set terminals root password */
395 if ($s_action=="change_pw"){
396 $tabs = array(
397 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
398 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
399 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
400 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
401 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
402 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
403 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
404 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
405 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
407 $dn = $this->terminals[$s_entry]['dn'];
408 $type = $this->get_system_type($this->terminals[$s_entry]);
410 $class = $tabs[$type]["CLASS"];
411 $acl = $tabs[$type]["ACL"];
412 $tabclass = $tabs[$type]["TABCLASS"];
413 $ui = get_userinfo();
414 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
415 if(preg_match("/w/",$tabacl)){
416 $this->dn= $this->terminals[$s_entry]['dn'];
417 session::set('objectinfo',$this->dn);
418 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
419 }else{
420 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
421 }
422 }
425 /********************
426 Password change finish, but check if entered data is ok
427 ********************/
429 /* Correctly specified? */
430 if (isset($_POST['password_finish'])){
431 if ($_POST['new_password'] != $_POST['repeated_password']){
432 msg_dialog::display(_("Error"), _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
433 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
434 }
435 }
437 /********************
438 Password change finish
439 ********************/
441 /* Change terminal password */
442 if (isset($_POST['password_finish']) &&
443 $_POST['new_password'] == $_POST['repeated_password']){
445 /* Check if user is allowed to set password */
446 $tabs = array(
447 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric" ,"PLUG"=>"termgeneric"),
448 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric" ,"PLUG"=>"workgeneric"),
449 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric" ,"PLUG"=>"servgeneric"),
450 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric","PLUG"=>"componentGeneric"));
452 /* Detect object type */
453 $type = "";
454 foreach($this->terminals as $terminal){
455 if($terminal['dn'] == $this->dn){
456 $type = $this->get_system_type($terminal);
457 break;
458 }
459 }
461 /* Type detected */
462 $allow_for = array("terminal","workstation","server","component");
463 if(!empty($type) && in_array($type,$allow_for)){
465 /* Get infos */
466 $plug = $tabs[$type]["PLUG"];
467 $class = $tabs[$type]["CLASS"];
468 $acl = $tabs[$type]["ACL"];
469 $tabclass = $tabs[$type]["TABCLASS"];
471 /* Get acls */
472 $ui = get_userinfo();
473 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
475 /* Check acls */
476 if(preg_match("/w/",$tabacl)){
477 $ldap = $this->config->get_ldap_link();
478 $ldap->cd($this->dn);
479 $ldap->cat($this->dn);
480 $old_attrs = $ldap->fetch();
482 $attrs= array();
483 if ($_POST['new_password'] == ""){
485 /* Remove password attribute
486 */
487 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
488 $attrs['objectClass'] = array();
489 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
490 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
491 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
492 }
493 }
494 }
495 $attrs['userPassword']= array();
496 } else {
498 /* Add/modify password attribute
499 */
500 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
501 $attrs['objectClass'] = array();
502 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
503 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
504 }
505 $attrs['objectClass'][] = "simpleSecurityObject";
506 }
508 if(class_available("passwordMethodCrypt")){
509 $pwd_m = new passwordMethodCrypt($this->config);
510 $pwd_m->set_hash("crypt/md5");
511 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
512 }else{
513 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
514 $attrs = array();
515 }
516 }
517 $ldap->modify($attrs);
518 if (!$ldap->success()){
519 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
520 }else{
521 if(class_available($plug)){
522 $p = new $plug($this->config,$this->dn);
523 $p->handle_post_events("modify");
524 }
525 }
527 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
528 }else{
529 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
530 }
531 }else{
532 msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
533 }
534 session::un_set('objectinfo');
535 }
538 /********************
539 Delete system cancel
540 ********************/
542 /* Delete terminal canceled? */
543 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
544 del_lock ($this->dn);
545 session::un_set('objectinfo');
546 }
549 /********************
550 Action(s) for MULTIPLE
551 ********************/
553 /********************
554 SCHEDULE action in GOsa Daemon
555 ********************/
557 if(preg_match("/^schedule_event_/",$s_action) || preg_match("/^trigger_event_/",$s_action)){
558 $this->dns = array();
559 $ids = $this->list_get_selected_items();
561 if(count($ids)){
562 $mac= array();
564 $ldap = $this->config->get_ldap_link();
565 foreach($ids as $id){
566 $ldap->cat ($this->terminals[$id]['dn'], array("macAddress"));
567 $attrs= $ldap->fetch();
568 if (isset($attrs['macAddress'][0])){
569 $mac[]= $attrs['macAddress'][0];
570 }
571 }
572 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
573 $type = preg_replace("/^[a-z]*_event_/","",$s_action);
574 $o_queue = new gosaSupportDaemon();
576 /* Skip installation or update trigerred events,
577 * if this entry is currently processing.
578 */
579 if(preg_match("/trigger_event/",$s_action) && in_array($type,array("DaemonEvent_reinstall","DaemonEvent_update"))){
580 foreach($mac as $key => $mac_address){
581 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
583 $entry['STATUS'] = strtoupper($entry['STATUS']);
584 if($entry['STATUS'] == "PROCESSING" &&
585 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
586 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
587 unset($mac[$key]);
589 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
590 break;
591 }
592 }
593 }
594 }
596 /* Prepare event to be added
597 */
598 if(count($mac) && isset($events['BY_CLASS'][$type])){
599 $event = $events['BY_CLASS'][$type];
600 $this->systab = new $event['CLASS_NAME']($this->config);
601 $this->systab->add_targets($mac);
602 if(preg_match("/trigger_event/",$s_action)){
603 $this->systab->set_type(TRIGGERED_EVENT);
604 }else{
605 $this->systab->set_type(SCHEDULED_EVENT);
606 }
607 }
608 }
609 }
611 /* Insert scheduled events into queue */
612 if($this->systab instanceof DaemonEvent){
613 $this->systab->save_object();
615 /* Save event
616 */
617 if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){
618 $o_queue = new gosaSupportDaemon();
619 $o_queue->append($this->systab);
620 if($o_queue->is_error()){
621 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
622 }else{
623 $this->systab = FALSE;
624 }
625 }
626 if(isset($_POST['abort_event_dialog'])){
627 $this->systab = FALSE;
628 }
629 }
632 /********************
633 Delete MULTIPLE entries requested, display confirm dialog
634 ********************/
636 if ($s_action=="del_multiple"){
637 $this->dns = array();
638 $ids = $this->list_get_selected_items();
640 if(count($ids)){
642 foreach($ids as $id){
643 $dn = $this->terminals[$id]['dn'];
644 $this->dns[$id] = $dn;
645 }
646 if ($user= get_multiple_locks($this->dns)){
647 return(gen_locked_message($user,$this->dns));
648 }
650 $dns_names = array();
651 foreach($this->dns as $dn){
652 add_lock ($dn, $this->ui->dn);
653 $dns_names[] = @LDAP::fix($dn);
654 }
656 /* Lock the current entry, so nobody will edit it during deletion */
657 $smarty->assign("warning", msgPool::deleteInfo($dns_names));
658 $smarty->assign("multiple", true);
659 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
660 }
661 }
664 /********************
665 Delete MULTIPLE entries confirmed
666 ********************/
668 /* Confirmation for deletion has been passed. Users should be deleted. */
669 if (isset($_POST['delete_multiple_system_confirm'])){
671 $ui = get_userinfo();
672 $tabs = array(
673 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
674 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
675 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
676 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
677 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
678 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
679 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
680 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
681 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
684 /* Remove user by user and check acls before removeing them */
685 foreach($this->dns as $key => $dn){
687 /* Get 'dn' from posted termlinst */
688 $attrs = $this->terminals[$key];
689 $type= $this->get_system_type($attrs);
691 /* get object type */
692 $tabtype = "termtabs";
693 $tabobj = "TERMTABS";
694 $tabacl = "";
695 if(isset($tabs[$type])){
696 $tabtype = $tabs[$type]['TABCLASS'];
697 $tabobj = $tabs[$type]['CLASS'];
698 $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']);
700 /* Load permissions for selected 'dn' and check if
701 we're allowed to remove this 'dn' */
702 if(preg_match("/d/",$tabacl)){
704 /* Delete request is permitted, perform LDAP action */
705 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
706 $this->systab= new termgeneric($this->config, $dn);
707 $this->systab->set_acl_base($dn);
708 $this->systab->remove_from_parent();
709 }elseif($tabtype=="phonetabs"){
710 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
711 $this->systab->set_acl_base($dn);
712 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
713 }else{
714 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
715 $this->systab->set_acl_base($dn);
716 $this->systab->delete();
717 }
718 unset ($this->systab);
719 $this->systab= NULL;
721 } else {
722 /* Normally this shouldn't be reached, send some extra
723 logs to notify the administrator */
724 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
725 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
726 }
727 /* Remove lock file after successfull deletion */
728 del_lock ($dn);
729 unset($this->dns[$key]);
730 }
731 }
732 }
734 /********************
735 Delete MULTIPLE entries Canceled
736 ********************/
738 /* Remove lock */
739 if(isset($_POST['delete_multiple_system_cancel'])){
740 foreach($this->dns as $key => $dn){
741 del_lock ($dn);
742 unset($this->dns[$key]);
743 }
744 }
747 /********************
748 Delete system, confirm dialog
749 ********************/
751 /* Remove terminal was requested */
752 if ($s_action=="del"){
754 /* Get 'dn' from posted termlinst */
755 $this->dn = $this->terminals[$s_entry]['dn'];
756 $attrs = $this->terminals[$s_entry];
760 $type= $this->get_system_type($attrs);
761 $ui = get_userinfo();
762 $tabs = array(
763 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
764 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
765 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
766 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
767 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
768 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
769 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
770 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
771 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
773 /* get object type */
774 $tabtype = "termtabs";
775 $tabobj = "TERMTABS";
776 $tabacl = "";
777 if(isset($tabs[$type])){
778 $tabtype = $tabs[$type]['TABCLASS'];
779 $tabobj = $tabs[$type]['CLASS'];
780 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
781 }
783 /* Load permissions for selected 'dn' and check if
784 we're allowed to remove this 'dn' */
785 if(preg_match("/d/",$tabacl)){
787 /* Check locking, save current plugin in 'back_plugin', so
788 the dialog knows where to return. */
789 if (($user= get_lock($this->dn)) != ""){
790 return(gen_locked_message ($user, $this->dn));
791 }
793 /* Lock the current entry, so nobody will edit it during deletion */
794 add_lock ($this->dn, $this->ui->dn);
795 $smarty->assign("warning", msgPool::deleteInfo(@LDAP::fix($this->dn)));
796 $smarty->assign("multiple", false);
797 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
798 } else {
800 /* Obviously the user isn't allowed to delete. Show message and
801 clean session. */
802 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
803 }
804 }
807 /********************
808 Delete system, confirmed
809 ********************/
810 /* Confirmation for deletion has been passed. Terminal should be deleted. */
811 if (isset($_POST['delete_terminal_confirm'])){
813 /* Find out more about the object type */
814 $ldap= $this->config->get_ldap_link();
815 $ldap->cat($this->dn, array('objectClass'));
816 $attrs= $ldap->fetch();
817 $type= $this->get_system_type($attrs);
819 $ui = get_userinfo();
821 $tabs = array(
822 "ArpNewDevice"=> array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
823 "NewDevice" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "incoming/systems"),
824 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
825 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
826 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
827 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
828 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
829 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
830 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
832 /* get object type */
833 $tabtype = "termtabs";
834 $tabobj = "TERMTABS";
835 $tabacl = "";
836 if(isset($tabs[$type])){
837 $tabtype = $tabs[$type]['TABCLASS'];
838 $tabobj = $tabs[$type]['CLASS'];
839 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
840 }
842 /* Check if we are allowed to remove this object */
843 if(preg_match("/d/",$tabacl)){
845 /* Delete request is permitted, perform LDAP action */
846 if(in_array($type,array("ArpNewDevice","NewDevice")) && class_available("termgeneric")){
847 $this->systab= new termgeneric($this->config, $this->dn);
848 $this->systab->set_acl_base($this->dn);
849 $this->systab->remove_from_parent();
850 }elseif($tabtype=="phonetabs"){
851 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
852 $this->systab->set_acl_base($this->dn);
853 $this->systab->by_object['phoneGeneric']->remove_from_parent ();
854 }else{
855 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
856 $this->systab->set_acl_base($this->dn);
857 $this->systab->delete();
858 }
859 unset ($this->systab);
860 $this->systab= NULL;
862 /* Terminal list has changed, reload it. */
863 } else {
865 /* Normally this shouldn't be reached, send some extra
866 logs to notify the administrator */
867 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
868 new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
869 }
871 /* Remove lock file after successfull deletion */
872 del_lock ($this->dn);
873 }
876 /********************
877 Edit system type finished, check if everything went ok
878 ********************/
879 /* Finish user edit is triggered by the tabulator dialog, so
880 the user wants to save edited data. Check and save at this
881 point. */
883 /* Dirty workaround - MSG_DIALOG - OK
884 If a message dialog is shown and we press 'OK'
885 then try to save again.
886 */
887 foreach($_POST as $name => $value){
888 if(preg_match("/^MSG_OK/",$name)){
889 $_POST[$this->last_action] = TRUE;
890 }
891 }
893 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
895 /* If the save routine gets interrupted by a confirm dialog,
896 store last action so we can trigger it again after 'Ok' was pressed.
897 (This is the case if a system gets modified while it is installing - GOsa si)
898 */
899 $this->last_action = "";
900 if(isset($_POST['edit_finish'])){
901 $this->last_action = "edit_finish";
902 }elseif(isset($_POST['edit_apply'])){
903 $this->last_action = "edit_apply";
904 }
906 /* Check tabs, will feed message array */
907 $message = array();
908 if(!$save_object_directly){
909 $message = $this->systab->check();
910 }else{
911 $found = false;
913 /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
914 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
915 if(isset($this->systab->by_object[$tab]->gotoMode)) {
916 $found = true;
917 $this->systab->by_object[$tab]->gotoMode = $value;
918 }
919 }
920 if(!$found){
921 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
922 }
924 }
925 /* Save, or display error message? */
926 if (count($message) == 0){
928 /* Incoming behavior; you can select a system type and an ogroup membership.
929 * If this object is an Incoming object, session::get('SelectedSystemType') isset.
930 * Check if we must add the new object to an object group.
931 *
932 * If this is done, delete the old incoming entry... it is still there, because this is a new
933 * entry and not an edited one, so we will delete it.
934 *
935 */
936 if(session::is_set('SelectedSystemType')){
937 $SelectedSystemType = session::get('SelectedSystemType');
938 if($SelectedSystemType['ogroup'] != "none"){
939 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
940 if($og){
941 $og->AddDelMembership($this->systab->dn);
942 $og->save();
943 }
944 }
945 }
947 /* Save terminal data to ldap */
948 $SelectedSystemType = session::get('SelectedSystemType');
949 if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
950 foreach (array("workservice", "termservice") as $cls){
951 if (isset($this->systab->by_object[$cls])){
952 $this->systab->by_object[$cls]->gotoXMouseport= "";
953 $this->systab->by_object[$cls]->gotoXMouseType= "";
954 $this->systab->by_object[$cls]->gotoXResolution= "";
955 $this->systab->by_object[$cls]->gotoXColordepth= "";
956 }
957 }
959 # Enable activation
960 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
961 if (isset($this->systab->by_object[$cls])){
962 $this->systab->by_object["workstartup"]->auto_activate= TRUE;
963 }
964 }
966 # Enable sending of LDAP events
967 if (isset($this->systab->by_object["workstartup"])){
968 $this->systab->by_object["workstartup"]->gotoLdap_inherit= TRUE;
969 }
970 }
972 $this->systab->save();
974 if(session::is_set('SelectedSystemType')){
975 session::un_set('SelectedSystemType');
976 if(!isset($ldap)){
977 $ldap = $this->config->get_ldap_link();
978 }
979 $ldap->cd ($this->dn);
980 $ldap->cat($this->dn, array('dn'));
981 if(count($ldap->fetch())){
982 $ldap->cd($this->dn);
983 $ldap->rmDir($this->dn);
984 }
985 $ldap->cd($this->config->current['BASE']);
986 }
988 /* Terminal has been saved successfully, remove lock from LDAP. */
989 if (!isset($_POST['edit_apply'])){
990 if ($this->dn != "new"){
991 del_lock ($this->dn);
992 }
994 unset ($this->systab);
995 $this->systab= NULL;
996 session::un_set('objectinfo');
997 }else{
999 /* Reinitialize tab */
1000 if($this->systab instanceof tabs){
1001 $this->systab->re_init();
1002 }
1003 }
1004 } else {
1005 /* Ok. There seem to be errors regarding to the tab data,
1006 show message and continue as usual. */
1007 msg_dialog::displayChecks($message);
1008 }
1009 }
1012 /********************
1013 Edit system was canceled
1014 ********************/
1015 /* Cancel dialogs */
1016 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
1017 if (isset($this->systab)){
1018 del_lock ($this->systab->dn);
1019 unset ($this->systab);
1020 }
1021 $this->systab= NULL;
1022 session::un_set('objectinfo');
1024 /* Remove ogroup selection, which was set while editing a new incoming entry */
1025 if(session::is_set('SelectedSystemType')){
1026 session::un_set('SelectedSystemType');
1027 }
1028 }
1030 /********************
1031 Display edit dialog, or some other
1032 ********************/
1034 /* Show tab dialog if object is present */
1035 if (isset($this->systab->config)){
1036 $display= $this->systab->execute();
1038 /* Don't show buttons if tab dialog requests this */
1040 $dialog = FALSE;
1041 $hide_apply = $this->dn == "new";
1042 $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->dn));
1043 if(is_object($this->systab) && !isset($this->systab->by_object)){
1044 $dialog = TRUE;
1045 $hide_apply = TRUE;
1046 }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
1047 $dia = $this->systab->by_object[$this->systab->current]->dialog;
1048 if($dia === TRUE || is_object($dia)){
1049 $dialog = TRUE;
1050 }
1051 }
1052 if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) &&
1053 $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
1054 $dialog = TRUE;
1055 }
1057 if (!$dialog){
1058 $display.= "<p style=\"text-align:right\">\n";
1059 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1060 $display.= " \n";
1061 if (!$hide_apply){
1062 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1063 $display.= " \n";
1064 }
1065 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1066 $display.= "</p>";
1067 }
1068 return ($display);
1069 }
1071 /* Check if there is a snapshot dialog open */
1072 $base = $this->DivListSystem->selectedBase;
1073 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
1074 return($str);
1075 }
1077 /* Display dialog with system list */
1078 $this->DivListSystem->parent = $this;
1079 $this->DivListSystem->execute();
1081 /* Add departments if subsearch is disabled */
1082 if(!$this->DivListSystem->SubSearch){
1083 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
1084 }
1085 $this->reload();
1086 $this->DivListSystem->setEntries($this->terminals);
1087 return($this->DivListSystem->Draw());
1088 }
1091 /* Return departments, that will be included within snapshot detection */
1092 function get_used_snapshot_bases()
1093 {
1094 $tmp = array();
1096 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
1098 $tabs = array(
1099 "terminal" => get_ou('terminalou'),
1100 "workstation" => get_ou('workstationou'),
1101 "incoming" => get_ou('incomingou'),
1102 "server" => get_ou('serverou'),
1103 "printer" => get_ou('printerou'),
1104 "phone" => get_ou('phoneou'),
1105 "winworkstation" => get_winstations_ou(),
1106 "component" => get_ou('componentou')
1107 );
1109 foreach($tabs as $acl_cat => $dn){
1111 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
1112 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
1113 $tmp[] = $dn.$this->DivListSystem->selectedBase;
1114 }
1115 }
1116 return($tmp);
1117 }
1120 function remove_from_parent()
1121 {
1122 /* Optionally execute a command after we're done */
1123 $this->postremove();
1124 }
1127 /* Save data to object */
1128 function save_object()
1129 {
1130 $this->DivListSystem->save_object();
1131 if(is_object($this->CopyPasteHandler)){
1132 $this->CopyPasteHandler->save_object();
1133 }
1134 }
1137 /* Check values */
1138 function check()
1139 {
1140 }
1143 /* Save to LDAP */
1144 function save()
1145 {
1146 }
1148 function adapt_from_template($dn, $skip= array())
1149 {
1150 }
1152 function password_change_needed()
1153 {
1154 }
1156 function reload()
1157 {
1158 /* some var init */
1159 $ui = get_userinfo();
1160 $res = array();
1161 $this->terminals = array();
1162 $userregex = "";
1164 /* Set base for all searches */
1165 $base= $this->DivListSystem->selectedBase;
1167 /* Prepare samba class name */
1168 $samba ="";
1169 if ($this->DivListSystem->ShowWinWorkstations){
1170 if ($this->config->current['SAMBAVERSION'] == "3"){
1171 $samba= "sambaSamAccount";
1172 } else {
1173 $samba= "sambaAccount";
1174 }
1175 }
1177 /* This array represents the combination between checkboxes and search filters */
1178 $objs = array(
1179 "ShowServers" => array("CLASS" => "goServer" ,"TREE" => get_ou('serverou')),
1180 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => get_ou('terminalou')),
1181 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => get_ou('printerou')),
1182 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => get_ou('componentou')),
1183 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => get_ou('phoneou')),
1184 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
1185 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
1187 /* Include the 'Display Systems of user' attribute */
1188 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
1189 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
1190 }
1192 /* Attributes to fetch */
1193 $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1194 $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1196 /* Add FAIstate to attributes if FAI is activated */
1197 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1198 if(!empty($tmp)){
1199 $sys_attrs[] = "FAIstate";
1200 }
1202 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
1203 foreach($objs as $checkBox => $oc){
1204 if($this->DivListSystem->$checkBox){
1205 if($this->DivListSystem->SubSearch){
1206 if($oc['CLASS'] != ""){
1207 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1208 $new_res = get_sub_list($filter, $sys_categories ,$oc['TREE'], $base,$sys_attrs, GL_SUBSEARCH | GL_SIZELIMIT);
1209 $res = array_merge($res,$new_res);
1210 }
1211 }else{
1212 /* User filter? */
1213 if($oc['CLASS'] != ""){
1214 $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1215 $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_SIZELIMIT));
1216 }
1217 }
1218 }
1219 }
1221 /* Search for incoming objects */
1222 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1223 $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_SIZELIMIT));
1225 /* Get all gotoTerminal's */
1226 foreach ($res as $value){
1228 $tmp= $value['dn'];
1229 $add= "";
1231 /* Extract base */
1232 foreach($objs as $obj){
1233 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1234 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1235 }
1236 }
1238 /* Create a string containing the last part of the department. */
1239 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1240 if(empty($dn_name)){
1241 $dn_name = "/";
1242 }
1244 /* check if current object is a new one */
1245 if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1246 if (in_array_ics('gotoTerminal', $value['objectClass'])){
1247 $add= "- "._("New terminal");
1248 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1249 $add= "- "._("New workstation");
1250 }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1251 $add= "- "._("Unknown device");
1252 }elseif (in_array_ics('GOhard', $value['objectClass'])){
1253 $add= "- "._("New Device");
1254 }
1255 }
1257 /* Detect type of object and create an entry for $this->terminals */
1258 $terminal = array();
1259 if (in_array_ics('gotoTerminal', $value["objectClass"])){
1261 /* check acl */
1262 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1263 if($add != "" || preg_match("/r/",$acl)) {
1264 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1265 $terminal = $value;
1266 $terminal['type'] = "T";
1267 $terminal['is_new'] = $add;
1268 } else {
1269 $terminal = $value;
1270 $terminal['type'] = "D";
1271 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
1272 $terminal['location'] = array_search($tmp, $this->config->departments);
1273 }
1274 }
1275 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1277 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1278 if($add != "" || preg_match("/r/",$acl)) {
1279 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1280 $terminal = $value;
1281 $terminal['type'] = "L";
1282 $terminal['is_new'] = $add;
1283 } else {
1284 $terminal = $value;
1285 $terminal['type'] = "D";
1286 $terminal['location'] = array_search($tmp, $this->config->departments);
1287 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
1288 }
1289 if (isset($value["FAIstate"][0])){
1290 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1291 }
1292 }
1293 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1296 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1297 if($add != "" || preg_match("/r/",$acl)) {
1299 $terminal = $value;
1300 $terminal['type'] = "P";
1301 }
1302 } elseif (in_array_ics('goServer', $value["objectClass"])){
1304 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1305 if($add != "" || preg_match("/r/",$acl)) {
1307 $terminal = $value;
1308 $terminal['type'] = "S";
1309 if (isset($value["FAIstate"][0])){
1310 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1311 }
1312 }
1313 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1315 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1316 if($add != "" || preg_match("/r/",$acl)) {
1318 $terminal = $value;
1319 $terminal['type'] = "F";
1320 }
1321 }elseif (in_array_ics("GOhard",$value['objectClass'])){
1323 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
1324 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1325 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1326 if($add != "" || preg_match("/r/",$acl)) {
1328 $terminal = $value;
1329 $terminal['type'] = "Q";
1330 $terminal['is_new'] = $add;
1331 }
1332 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1334 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1335 if($add != "" || preg_match("/r/",$acl)) {
1337 $terminal = $value;
1338 $terminal['type'] = "C";
1339 }
1340 } else{
1342 $name= preg_replace('/\$$/', '', $value['cn'][0]);
1343 if (isset($value['sambaDomainName'])){
1344 $domain= " [".$value['sambaDomainName'][0]."]";
1345 } else {
1346 $domain= "";
1347 }
1348 $terminal=$value;
1349 $terminal['type'] ="W";
1350 $terminal['domain'] = $name.$domain;
1351 }
1353 if(count($terminal)){
1354 $this->terminals[]=$terminal;
1355 }
1356 }
1358 $tmp =array();
1359 $tmp2 =array();
1360 foreach($this->terminals as $tkey => $val ){
1361 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1362 $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1363 }
1364 natcasesort($tmp2);
1365 $this->terminals=array();
1366 foreach($tmp2 as $val){
1367 $this->terminals[]=$tmp[$val];
1368 }
1369 reset ($this->terminals);
1370 }
1372 function remove_lock()
1373 {
1374 if (isset($this->systab->dn)){
1375 del_lock ($this->systab->dn);
1376 }
1377 }
1380 function copyPasteHandling_from_queue($s_action,$s_entry)
1381 {
1382 /* Check if Copy & Paste is disabled */
1383 if(!is_object($this->CopyPasteHandler)){
1384 return("");
1385 }
1388 $tabs = array(
1389 "terminal" => array( "CLASS" =>"TERMTABS", "TABNAME" =>"termgeneric",
1390 "TABCLASS" =>"termtabs", "ACL" =>"terminal"),
1391 "workstation" => array( "CLASS" =>"WORKTABS", "TABNAME" =>"workgeneric",
1392 "TABCLASS" =>"worktabs", "ACL" =>"workstation"),
1393 "server" => array( "CLASS" =>"SERVTABS", "TABNAME" =>"servgeneric",
1394 "TABCLASS" =>"servtabs", "ACL" =>"server"),
1395 "printer" => array( "CLASS" =>"PRINTTABS", "TABNAME" =>"printgeneric",
1396 "TABCLASS" =>"printtabs", "ACL" =>"printer"),
1397 "phone" => array( "CLASS" =>"PHONETABS", "TABNAME" =>"phoneGeneric",
1398 "TABCLASS" =>"phonetabs", "ACL" =>"phone"),
1399 "component" => array( "CLASS" =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1400 "TABCLASS" =>"componenttabs","ACL" =>"component"));
1402 /* Add a single entry to queue */
1403 if($s_action == "cut" || $s_action == "copy"){
1405 /* Cleanup object queue */
1406 $this->CopyPasteHandler->cleanup_queue();
1407 $dn = $this->terminals[$s_entry]['dn'];
1408 $oc = $this->terminals[$s_entry]['objectClass'];
1409 $type = $this->get_system_type($this->terminals[$s_entry]);
1411 $tab_o = $tabs[$type]['CLASS'];
1412 $tab_c = $tabs[$type]['TABCLASS'];
1413 $acl = $tabs[$type]['ACL'];
1415 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1416 }
1418 /* Add entries to queue */
1419 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1421 /* Cleanup object queue */
1422 $this->CopyPasteHandler->cleanup_queue();
1424 /* Add new entries to CP queue */
1425 foreach($this->list_get_selected_items() as $id){
1426 $dn = $this->terminals[$id]['dn'];
1427 $oc = $this->terminals[$id]['objectClass'];
1428 $type = $this->get_system_type($this->terminals[$id]);
1430 if(isset($tabs[$type])){
1431 $tab_o = $tabs[$type]['CLASS'];
1432 $tab_c = $tabs[$type]['TABCLASS'];
1433 $acl = $tabs[$type]['ACL'];
1435 if($s_action == "copy_multiple"){
1436 $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1437 }
1438 if($s_action == "cut_multiple"){
1439 $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1440 }
1441 }
1442 }
1443 }
1445 /* Start pasting entries */
1446 if($s_action == "editPaste"){
1447 $this->start_pasting_copied_objects = TRUE;
1448 }
1450 /* Return C&P dialog */
1451 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1453 /* Get dialog */
1454 $data = $this->CopyPasteHandler->execute();
1455 $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1457 /* Return dialog data */
1458 if(!empty($data)){
1459 return($data);
1460 }
1461 }
1463 /* Automatically disable status for pasting */
1464 if(!$this->CopyPasteHandler->entries_queued()){
1465 $this->start_pasting_copied_objects = FALSE;
1466 }
1467 return("");
1468 }
1471 function get_system_type($attrs)
1472 {
1473 $classes = $attrs['objectClass'];
1475 $type= "";
1476 if (in_array_ics('ieee802Device', $classes)){
1477 $type= "component";
1478 }elseif (in_array_ics('gotoTerminal', $classes)){
1479 $type= "terminal";
1480 }elseif (in_array_ics('gotoWorkstation', $classes)){
1481 $type= "workstation";
1482 }elseif (in_array_ics('gotoPrinter', $classes)){
1483 $type= "printer";
1484 }elseif (in_array_ics('goFonHardware', $classes)){
1485 $type= "phone";
1486 }elseif (in_array_ics('goServer', $classes)){
1487 $type= "server";
1488 }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1489 $type= "ArpNewDevice";
1490 }elseif (in_array_ics('GOhard', $classes)){
1491 $type= "NewDevice";
1492 }elseif (in_array_ics('sambaAccount', $classes) ||
1493 in_array_ics('sambaSamAccount', $classes)){
1494 $type= "winstation";
1495 }
1496 return ($type);
1497 }
1500 function convert_list($input)
1501 {
1502 $temp= "";
1503 $conv= array(
1504 "NQ" => array("select_newsystem.png",_("New system from incoming")),
1505 "D" => array("select_default.png",_("Template")),
1506 "T" => array("select_terminal.png",_("Terminal")),
1507 "L" => array("select_workstation.png",_("Workstation")),
1508 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1509 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1510 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1511 "F" => array("select_phone.png",_("Phone")),
1512 "S" => array("select_server.png",_("Server")),
1513 "GS" => array("select_server_green.png",_("Server is installing")),
1514 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1515 "RS" => array("select_server_red.png",_("Server installation failed")),
1516 "W" => array("select_winstation.png",_("Win workstation")),
1517 "C" => array("select_component.png",_("Network device")),
1518 "NT"=> array("select_new_terminal.png",_("New terminal")),
1519 "NL"=> array("select_new_workstation.png",_("New workstation")),
1520 "P" => array("select_printer.png",_("Printer")));
1522 if((isset($input['is_new']))&&(!empty($input['is_new']))){
1523 $input['type']="N".$input['type'];
1524 }
1525 foreach ($conv as $key => $value){
1526 if($input['type']==$key){
1527 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1528 $tmp['class']=$key;
1529 return $tmp;
1530 }
1531 }
1532 }
1535 function getState($type, $state)
1536 {
1537 switch (preg_replace('/:.*$/', '', $state)) {
1538 case 'installing':
1539 $type= 'G'.$type;
1540 break;
1541 case 'error':
1542 $type= 'R'.$type;
1543 break;
1544 case 'install':
1545 case 'sysinfo':
1546 case 'softupdate':
1547 case 'scheduledupdate':
1548 $type= 'Y'.$type;
1549 break;
1550 }
1553 return ($type);
1554 }
1557 function list_get_selected_items()
1558 {
1559 $ids = array();
1560 foreach($_POST as $name => $value){
1561 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1562 $id = preg_replace("/^item_selected_/","",$name);
1563 $ids[$id] = $id;
1564 }
1565 }
1566 return($ids);
1567 }
1570 /* !! Incoming dummy acls, required to defined acls for incoming objects
1571 */
1572 static function plInfo()
1573 {
1574 return (array(
1575 "plShortName" => _("Incoming objects"),
1576 "plDescription" => _("Incoming objects"),
1577 "plSelfModify" => FALSE,
1578 "plDepends" => array(),
1579 "plPriority" => 99,
1580 "plSection" => array("administration"),
1581 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1582 "objectClass" => "")),
1583 "plProvidedAcls"=> array()
1585 ));
1586 }
1591 }
1593 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1594 ?>