Fix checkRpItemsPosition
[ryzomcore.git] / web / public_php / admin / index.php
blob9fdada32f84528d2f76c0f16e5f67e0ca53d231b
1 <?php
3 // Enw4k.XHXuULw
5 require_once('common.php');
6 require_once('functions_tool_main.php');
7 require_once('functions_tool_notes.php');
9 nt_common_add_debug('-- Starting on \'index.php\'');
11 $tpl->assign('tool_title', "Main");
13 $view_domain_id = nt_auth_get_session_var('view_domain_id');
14 $view_shard_id = nt_auth_get_session_var('view_shard_id');
16 if (!$view_domain_id)
18 $view_domain_id = $nel_user['group_default_domain_id'];
19 $view_shard_id = $nel_user['group_default_shard_id'];
20 nt_auth_set_session_var('view_domain_id', $view_domain_id);
21 nt_auth_set_session_var('view_shard_id', $view_shard_id);
24 if (isset($_GET['domain']))
26 if ($view_domain_id != $_GET['domain'])
28 $view_domain_id = $_GET['domain'];
29 nt_auth_set_session_var('view_domain_id', $view_domain_id);
31 $view_shard_id = null;
32 nt_auth_unset_session_var('view_shard_id');
36 if (isset($_GET['shard']))
38 $view_shard_id = $_GET['shard'];
39 nt_auth_set_session_var('view_shard_id', $view_shard_id);
42 if (!tool_main_check_user_domain($view_domain_id)) $view_domain_id = null;
43 if (!tool_main_check_user_shard($view_shard_id)) $view_shard_id = null;
45 $current_refresh_rate = nt_auth_get_session_var('current_refresh_rate');
47 if (isset($_POST['services_refresh']))
49 if ($current_refresh_rate != $_POST['services_refresh'])
51 $current_refresh_rate = $_POST['services_refresh'];
52 nt_auth_set_session_var('current_refresh_rate',$current_refresh_rate);
56 if ($current_refresh_rate == null)
58 $current_refresh_rate = 0;
60 elseif ($current_refresh_rate > 0)
62 $tpl->assign('nel_tool_refresh', '<meta http-equiv=refresh content="'. $current_refresh_rate .'">');
65 $tpl->assign('tool_refresh_list', $refresh_rates);
66 $tpl->assign('tool_refresh_rate', $current_refresh_rate);
68 $tpl->assign('tool_domain_list', $nel_user['access']['domains']);
69 $tpl->assign('tool_domain_selected', $view_domain_id);
71 $tpl->assign('tool_shard_list', $nel_user['access']['shards']);
72 $tpl->assign('tool_shard_selected', $view_shard_id);
74 $tool_shard_filters = tool_main_get_shard_ids($view_shard_id);
75 $tpl->assign('tool_shard_filters', $tool_shard_filters);
77 $AS_Host = tool_main_get_domain_host($view_domain_id);
78 $AS_Port = tool_main_get_domain_port($view_domain_id);
79 $AS_Name = tool_main_get_domain_name($view_domain_id);
80 $AS_Application = tool_main_get_domain_data($view_domain_id, 'domain_application');
81 $AS_RingSQL = tool_main_get_domain_data($view_domain_id, 'domain_sql_string');
82 $AS_CsSQL = tool_main_get_domain_data($view_domain_id, 'domain_cs_sql_string');
83 $AS_ShardName = tool_main_get_shard_name($view_shard_id);
84 $AS_InternalName = tool_main_get_shard_as_id($view_shard_id);
85 $AS_ShardRestart = tool_main_get_shard_data($view_shard_id, 'shard_restart');
86 $AS_ShardDomainRestart = tool_main_get_domain_shard_restart($view_domain_id);
87 $AS_ShardLang = tool_main_get_shard_data($view_shard_id, 'shard_lang');
89 $tpl->assign('tool_shard_restart_status', $AS_ShardRestart);
90 $tpl->assign('tool_domain_has_shard_restart', $AS_ShardDomainRestart);
92 $tool_no_domain_lock = false;
93 if (($AS_InternalName == '*') && ($AS_ShardDomainRestart > 0))
95 $tool_no_domain_lock = true;
96 $tpl->assign('tool_no_domain_lock', $tool_no_domain_lock);
99 $tpl->assign('tool_page_title', $AS_Name . ($AS_ShardName != '' ? ' / '. $AS_ShardName : ''));
101 $tool_annotation_info = tool_main_get_annotation($view_domain_id, $view_shard_id);
102 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
104 // we check if the last activity on the lock is too old, in which case we unlock
105 // and only if there are no restart sequence going on (prevent loosing lock when inactive for too long during restart sequence - patch ...)
106 if ((LOCK_TIMEOUT > 0) && is_array($tool_lock_info) && ($AS_ShardRestart == 0) && !$tool_no_domain_lock)
108 $now = time();
109 if ($tool_lock_info['lock_update'] + LOCK_TIMEOUT < $now)
111 if ($tool_lock_info['lock_domain_id']) tool_main_delete_lock_domain($view_domain_id);
112 if ($tool_lock_info['lock_shard_id']) tool_main_delete_lock_shard($view_shard_id);
114 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
118 // we update the lock data for the last activity time
119 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'])
121 if ($tool_lock_info['lock_domain_id']) tool_main_set_lock_domain($view_domain_id, false);
122 if ($tool_lock_info['lock_shard_id']) tool_main_set_lock_shard($view_domain_id, $view_shard_id, false);
124 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
127 if (tool_admin_applications_check('tool_main_lock_shard') || tool_admin_applications_check('tool_main_lock_domain'))
129 if (isset($NELTOOL['POST_VARS']['lock']))
131 $tool_lock_mode = $NELTOOL['POST_VARS']['lock'];
132 switch ($tool_lock_mode)
134 case 'lock shard':
136 if (tool_admin_applications_check('tool_main_lock_shard'))
138 tool_main_set_lock_shard($view_domain_id, $view_shard_id);
139 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
141 if ($AS_ShardRestart > 0)
143 tool_main_set_restart_sequence_user($AS_ShardRestart);
147 break;
149 case 'lock domain':
151 if (tool_admin_applications_check('tool_main_lock_domain'))
153 tool_main_set_lock_domain($view_domain_id);
154 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
157 break;
159 case 'unlock shard':
161 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'])
163 tool_main_delete_lock_shard($view_shard_id);
164 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
167 break;
169 case 'unlock domain':
171 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'])
173 tool_main_delete_lock_domain($view_domain_id);
174 $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
177 break;
179 case 'update annotation':
181 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'])
183 $tool_annotation = $NELTOOL['POST_VARS']['annotation'];
184 tool_main_set_annotation($view_domain_id, $view_shard_id, $tool_annotation);
185 $tool_annotation_info = tool_main_get_annotation($view_domain_id, $view_shard_id);
188 break;
190 case 'restart sequence':
192 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'] && tool_admin_applications_check('tool_main_easy_restart'))
194 $restart_ws_state = $NELTOOL['POST_VARS']['restart_ws_state'];
196 $restart_first_step = 0;
198 // if restart_ws_state == '' means that i didn't find a shard_id
199 // which means the shard has been shutdown completely including AES and RAS
200 if ($restart_ws_state == 'close' || $restart_ws_state == '') $restart_first_step = 3;
202 $tool_restart_info = tool_main_set_restart_mode($view_domain_id, $view_shard_id, $restart_first_step);
205 break;
209 if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name'])
211 if (tool_admin_applications_check('tool_main_start')) $tpl->assign('restriction_tool_main_start', true);
212 if (tool_admin_applications_check('tool_main_stop')) $tpl->assign('restriction_tool_main_stop', true);
213 if (tool_admin_applications_check('tool_main_restart')) $tpl->assign('restriction_tool_main_restart', true);
214 if (tool_admin_applications_check('tool_main_kill')) $tpl->assign('restriction_tool_main_kill', true);
215 if (tool_admin_applications_check('tool_main_abort')) $tpl->assign('restriction_tool_main_abort', true);
216 if (tool_admin_applications_check('tool_main_execute')) $tpl->assign('restriction_tool_main_execute', true);
217 if (tool_admin_applications_check('tool_main_ws')) $tpl->assign('restriction_tool_main_ws', true);
218 if (tool_admin_applications_check('tool_main_ws_old')) $tpl->assign('restriction_tool_main_ws_old', true);
219 if (tool_admin_applications_check('tool_main_reset_counters')) $tpl->assign('restriction_tool_main_reset_counters', true);
220 if (tool_admin_applications_check('tool_main_service_autostart')) $tpl->assign('restriction_tool_main_service_autostart', true);
221 if (tool_admin_applications_check('tool_main_shard_autostart')) $tpl->assign('restriction_tool_main_shard_autostart', true);
222 if (tool_admin_applications_check('tool_main_easy_restart')) $tpl->assign('restriction_tool_main_easy_restart', true);
224 $nel_user['has_lock'] = true;
225 if ($tool_lock_info['lock_shard_id'] > 0) $tpl->assign('tool_has_shard_lock', true);
226 elseif ($tool_lock_info['lock_domain_id'] > 0) $tpl->assign('tool_has_domain_lock', true);
228 if ($AS_ShardRestart > 0)
230 // define the shards language
231 $tpl->assign('tool_shard_language', $AS_ShardLang);
232 $tpl->assign('tool_language_list', $tool_language_list);
234 $tool_restart_message_reboot_list = tool_admin_restart_messages_get_list_from_name('reboot');
235 $tpl->assign('tool_restart_message_reboot_list', $tool_restart_message_reboot_list);
237 $tool_restart_stop_list = tool_admin_restarts_get_list('DESC');
238 $tool_restart_start_list = tool_admin_restarts_get_list('ASC');
240 // they are assigned at the end of the script
241 //$tpl->assign('tool_restart_stop_actions', $tool_restart_stop_list);
242 //$tpl->assign('tool_restart_start_actions', $tool_restart_start_list);
244 //$tool_restart_message_ready_list = tool_admin_restart_messages_get_list_from_name('ready');
245 //$tpl->assign('tool_restart_message_ready_list', $tool_restart_message_ready_list);
247 //$tool_restart_message_list = tool_admin_restart_messages_get_list_from_name('open');
249 // restart information
250 $tool_restart_info = tool_main_get_restart_sequence_by_id($AS_ShardRestart);
251 $tpl->assign('tool_restart_info', $tool_restart_info);
256 $tpl->assign('tool_has_lock', true);
258 else
260 $tpl->assign('tool_no_lock', true);
261 $tpl->assign('tool_no_annotation', true);
265 if (tool_admin_applications_check('tool_main_lock_shard')) $tpl->assign('restriction_tool_main_lock_shard',true);
266 if (tool_admin_applications_check('tool_main_lock_domain')) $tpl->assign('restriction_tool_main_lock_domain',true);
267 elseif (!tool_admin_applications_check('tool_main_lock_domain')
268 && tool_admin_applications_check('tool_main_lock_shard')
269 && (tool_main_get_shard_as_id($view_shard_id) == "*"))
271 // you have shard lock access
272 // but you don't have domain access
273 // and you are viewing the * shard
274 // locking the shard * will lock the domain
275 // so you must not be able to lock this shard
276 $tpl->assign('tool_cant_lock', true);
279 $tpl->assign('tool_lock_info', $tool_lock_info);
280 $tpl->assign('tool_annotation_info', $tool_annotation_info);
282 if (tool_admin_applications_check('tool_notes'))
284 $tool_note_list = tool_notes_get_list($nel_user['user_id'], 1);
286 if (sizeof($tool_note_list))
288 $tpl->assign('restriction_tool_notes', true);
289 $tpl->assign('tool_note_list', $tool_note_list);
294 $tool_as_error = null;
296 if ($AS_Host && $AS_Port)
298 $adminService = new MyAdminService;
299 if (@$adminService->connect($AS_Host, $AS_Port, $res) === false)
301 nt_common_add_debug($res);
302 $tpl->assign('tool_domain_error', $res );
304 else
306 if ($nel_user['has_lock'])
308 //nt_common_add_debug("HTTP_POST_VARS");
309 //nt_common_add_debug($HTTP_POST_VARS);
310 //echo '<pre>'. print_r($HTTP_POST_VARS,true) .'</pre>';
311 //die();
313 // make sure you are the one who has its name in the restart info
314 // as you can take over the lock and the restart sequence
315 // we don't want more than 1 client executing the restart commands if they think they still have the lock
316 if (isset($tool_restart_info) && ($tool_restart_info['restart_sequence_user_name'] == $nel_user['user_name']) && tool_admin_applications_check('tool_main_easy_restart'))
318 $tool_seq_id = $NELTOOL['POST_VARS']['restart_sequence_id'];
319 $tool_seq_step = $NELTOOL['POST_VARS']['restart_sequence_step'];
321 $restart_shard_id = $NELTOOL['POST_VARS']['restart_shard_id'];
322 $service_su = $NELTOOL['POST_VARS']['restart_su'];
323 $service_egs = $NELTOOL['POST_VARS']['restart_egs'];
325 $restart_stop_services = $NELTOOL['POST_VARS']['restart_stop_services'];
327 if (isset($NELTOOL['POST_VARS']['restart_check_ws']))
329 // we are starting the restart sequence
330 $restart_ws_state = $NELTOOL['POST_VARS']['restart_ws_state'];
332 if ($restart_ws_state == 'open')
334 // shard needs a regular restart
336 // - broadcast a message on the shard
338 $restart_reboot_message_id = $NELTOOL['POST_VARS']['restart_message_reboot_id'];
339 $restart_reboot_message_data = tool_admin_restart_messages_get_id($restart_reboot_message_id);
340 $restart_reboot_message = $restart_reboot_message_data['restart_message_value'];
342 if ($restart_reboot_message != '')
344 $service_command = "broadcast repeat=10 every=60 ". $restart_reboot_message;
346 nt_log("Domain '$AS_Name' : '$service_command' on ". $service_egs);
347 nt_common_add_debug("about to run command '$service_command' on '$service_egs' ...");
348 $adminService->serviceCmd($service_egs, $service_command);
349 if (!$adminService->waitCallback())
351 nt_common_add_debug('Error while waiting for callback on service \''. $service_egs .'\' for command : '. $service_command);
354 $tpl->clear_assign('tool_execute_result');
357 // - prepare next step (timer countdown to 10 minutes)
359 if($restart_shard_id == 301)
361 // Fast restart for yubo shard (1mn)
362 tool_main_set_restart_sequence_timer($tool_seq_id, 60);
363 nt_common_add_debug("fast restart for yubo shard 301");
365 else
367 tool_main_set_restart_sequence_timer($tool_seq_id, 600);
368 nt_common_add_debug("normal restart for live shard");
371 // - lets start by locking the WS
373 $service_command = 'rsm.setWSState '. $restart_shard_id .' RESTRICTED ""';
374 nt_common_add_debug("about to run command '$service_command' on '$service_su' ...");
376 $adminService->serviceCmd($service_su, $service_command);
377 if (!$adminService->waitCallback())
379 nt_common_add_debug('Error while waiting for callback on service \''. $service_su .'\' for command : '. $service_command);
382 $tpl->clear_assign('tool_execute_result');
383 nt_sleep(VIEW_DELAY);
385 else
387 // shard needs an immediate restart
389 // - prepare next step (timer countdown to a few seconds)
391 tool_main_set_restart_sequence_timer($tool_seq_id, 30);
394 // - inform CS about the restart
395 tool_main_add_restart_notification($tool_seq_id, $service_su, $service_egs, $restart_shard_id, 4101, $AS_CsSQL, $AS_ShardLang);
397 // - resend the services to stop for the next step
399 $tpl->assign('tool_restart_stop_actions', $restart_stop_services);
401 // - move on to the next step
403 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
404 $tpl->assign('tool_restart_info', $tool_restart_info);
407 elseif (isset($NELTOOL['POST_VARS']['restart_back']))
409 // this makes you go to the next step
410 if ($tool_seq_id == $tool_restart_info['restart_sequence_id'])
412 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step - 1);
413 $tpl->assign('tool_restart_info', $tool_restart_info);
416 elseif (isset($NELTOOL['POST_VARS']['restart_end']))
418 tool_main_set_end_restart_sequence($tool_seq_id);
419 nt_common_redirect('index.php');
420 exit();
422 elseif (isset($NELTOOL['POST_VARS']['restart_continue']))
424 // this makes you go to the next step
425 if ($tool_seq_id == $tool_restart_info['restart_sequence_id'])
427 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
428 $tpl->assign('tool_restart_info', $tool_restart_info);
431 elseif (isset($NELTOOL['POST_VARS']['restart_giveup']))
433 // update klients events to giveup mode
435 //$klients_events = explode(',',$tool_restart_info['restart_sequence_events']);
436 //tool_main_change_restart_notification($klients_events, 4105, $AS_CsSQL);
437 tool_main_add_restart_notification($tool_seq_id, $service_su, $service_egs, $restart_shard_id, 4105, $AS_CsSQL, $AS_ShardLang);
439 tool_main_set_end_restart_sequence($tool_seq_id);
440 nt_common_redirect('index.php');
441 exit();
443 elseif (isset($NELTOOL['POST_VARS']['restart_cancel']))
445 if ($restart_ws_state != 'open')
447 // - broadcast a message on the shard
449 $restart_reboot_message_data = tool_admin_restart_messages_get_list_from_name('cancel', $AS_ShardLang);
451 if (sizeof($restart_reboot_message_data))
453 $restart_reboot_message = $restart_reboot_message_data[0]['restart_message_value'];
455 if ($restart_reboot_message != '')
457 $service_command = "broadcast ". $restart_reboot_message;
459 nt_log("Domain '$AS_Name' : '$service_command' on ". $service_egs);
460 nt_common_add_debug("about to run command '$service_command' on '$service_egs' ...");
461 $adminService->serviceCmd($service_egs, $service_command);
462 if (!$adminService->waitCallback())
464 nt_common_add_debug('Error while waiting for callback on service \''. $service_egs .'\' for command : '. $service_command);
467 $tpl->clear_assign('tool_execute_result');
472 // update the klients events to cancelled mode
474 $klients_events = explode(',',$tool_restart_info['restart_sequence_events']);
475 tool_main_change_restart_notification($klients_events, 4104, $AS_CsSQL);
477 // - open the WS again
479 $service_command = 'rsm.setWSState '. $restart_shard_id .' OPEN ""';
480 nt_common_add_debug("about to run command '$service_command' on '$service_su' ...");
482 $adminService->serviceCmd($service_su, $service_command);
483 if (!$adminService->waitCallback())
485 nt_common_add_debug('Error while waiting for callback on service \''. $service_su .'\' for command : '. $service_command);
488 $tpl->clear_assign('tool_execute_result');
489 nt_sleep(VIEW_DELAY);
491 // end the sequence and refresh
493 tool_main_set_end_restart_sequence($tool_seq_id);
494 nt_common_redirect('index.php');
495 exit();
498 elseif (isset($NELTOOL['POST_VARS']['restart_wait_timer']))
500 // step 1, waited for the timer, lets shutdown the shard
502 $service_list = explode(',', $restart_stop_services);
504 if (sizeof($service_list))
506 // comment out to prevent stopping services for testing purposes
507 nt_log("Domain '$AS_Name' : 'stopService' on ". implode(', ',array_values($service_list)));
508 reset($service_list);
509 foreach($service_list as $service)
511 nt_common_add_debug("about to run 'stopService' on '$service' ...");
512 $adminService->controlCmd($service, 'stopService');
513 if (!$adminService->waitCallback())
515 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for stopService');
518 nt_sleep(VIEW_DELAY);
521 // - prepare next step (timer countdown to a few seconds)
523 tool_main_set_restart_sequence_timer($tool_seq_id, 30);
525 // - move on to the next step
527 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
528 $tpl->assign('tool_restart_info', $tool_restart_info);
530 elseif (isset($NELTOOL['POST_VARS']['restart_shutdown_timer']))
532 // step 2, waited for the shutdown timer, lets move on
534 // - move on to the next step
536 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
537 $tpl->assign('tool_restart_info', $tool_restart_info);
539 elseif (isset($NELTOOL['POST_VARS']['restart_start_group']))
541 // step 4, start a group of services
542 $tool_seq_start_id = $NELTOOL['POST_VARS']['restart_start_group_id'];
543 $tool_seq_start_list = $NELTOOL['POST_VARS']['restart_start_group_list'];
545 if (isset($tool_restart_start_list))
547 foreach($tool_restart_start_list as $restart_start_group)
549 if ($restart_start_group['restart_group_id'] == $tool_seq_start_id)
551 $service_list = explode(',', $tool_seq_start_list);
553 if (sizeof($service_list))
555 nt_log("Domain '$AS_Name' : 'startService' on ". implode(', ',array_values($service_list)));
556 reset($service_list);
557 foreach($service_list as $service)
559 nt_common_add_debug("about to run 'startService' on '$service' ...");
560 $adminService->controlCmd($service, 'startService');
561 if (!$adminService->waitCallback())
563 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for startService');
567 nt_sleep(VIEW_DELAY);
570 break;
575 elseif (isset($NELTOOL['POST_VARS']['restart_stop_group']))
577 // step 3, stop a group of services
578 $tool_seq_stop_id = $NELTOOL['POST_VARS']['restart_stop_group_id'];
579 $tool_seq_stop_list = $NELTOOL['POST_VARS']['restart_stop_group_list'];
581 if (isset($tool_restart_stop_list))
583 $service_list = explode(',', $tool_seq_stop_list);
585 if (sizeof($service_list))
587 nt_log("Domain '$AS_Name' : 'stopService' on ". implode(', ',array_values($service_list)));
588 reset($service_list);
589 foreach($service_list as $service)
591 nt_common_add_debug("about to run 'stopService' on '$service' ...");
592 $adminService->controlCmd($service, 'stopService');
593 if (!$adminService->waitCallback())
595 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for stopService');
598 nt_sleep(VIEW_DELAY);
602 elseif (isset($NELTOOL['POST_VARS']['restart_over']))
604 // this makes you go to the next step
605 if ($tool_seq_id == $tool_restart_info['restart_sequence_id'])
607 // - inform CS that the shard is ready and locked
608 tool_main_add_restart_notification($tool_seq_id, $service_su, $service_egs, $restart_shard_id, 4102, $AS_CsSQL, $AS_ShardLang);
610 $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
611 $tpl->assign('tool_restart_info', $tool_restart_info);
614 //elseif (isset($NELTOOL['POST_VARS']['restart_broadcast_open']))
616 // // step 6, open ws, end restart sequence
618 // // - open WS
619 // $service = $NELTOOL['POST_VARS']['restart_su'];
620 // $restart_shard_id = $NELTOOL['POST_VARS']['restart_shard_id'];
622 // $service_command = 'rsm.setWSState '. $restart_shard_id .' OPEN ""';
623 // nt_common_add_debug("about to run command '$service_command' on '$service' ...");
625 // $adminService->serviceCmd($service, $service_command);
626 // if (!$adminService->waitCallback())
627 // {
628 // nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
629 // }
631 // $tpl->clear_assign('tool_execute_result');
632 // nt_sleep(VIEW_DELAY);
634 // // - end restart sequence
635 // tool_main_set_end_restart_sequence($tool_seq_id);
636 // nt_common_redirect('index.php');
637 // exit();
640 elseif (isset($_POST['shards_update']) && tool_admin_applications_check('tool_main_shard_autostart'))
642 $shard_update_mode = $_POST['shards_update'];
643 $shard_update_name = $_POST['shards_update_name'];
645 switch ($shard_update_mode)
647 case 'auto restart on':
649 $as_command = "setShardStartMode ". $shard_update_name ." on";
651 nt_log("Domain '$AS_Name' : $as_command");
652 nt_common_add_debug("about to run '$as_command' ...");
653 $adminService->globalCmd($as_command);
654 if (!$adminService->waitCallback())
656 nt_common_add_debug('Error while waiting for callback for \''. $as_command .'\'');
659 nt_sleep(VIEW_DELAY);
661 break;
663 case 'auto restart off':
665 $as_command = "setShardStartMode ". $shard_update_name ." off";
667 nt_log("Domain '$AS_Name' : $as_command");
668 nt_common_add_debug("about to run '$as_command' ...");
669 $adminService->globalCmd($as_command);
670 if (!$adminService->waitCallback())
672 nt_common_add_debug('Error while waiting for callback for \''. $as_command .'\'');
675 nt_sleep(VIEW_DELAY);
677 break;
681 elseif (isset($_POST['ws_update']) && tool_admin_applications_check('tool_main_ws'))
683 $shard_ws_su = $_POST['ws_su'];
684 $shard_ws_shard_name = $_POST['ws_shard_name'];
685 $shard_ws_shard_id = $_POST['ws_shard_id'];
687 $shard_ws_state = $_POST['ws_state_'. $shard_ws_shard_name];
688 $shard_ws_motd = $_POST['ws_motd_'. $shard_ws_shard_name];
690 // coders don't know how to write it seems
691 // ace: now they know if ($shard_ws_state == 'close') $shard_ws_state = 'closed';
693 //nt_common_add_debug("request for ". $shard_ws_su ."/". $shard_ws_shard_name ." to set STATE:". $shard_ws_state ." (". $shard_ws_motd .")");
695 $service = $shard_ws_su;
696 $service_command = 'rsm.setWSState '. $shard_ws_shard_id .' '. strtoupper($shard_ws_state) .' "'. $shard_ws_motd .'"';
697 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
699 $adminService->serviceCmd($service, $service_command);
700 if (!$adminService->waitCallback())
702 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
705 $tpl->clear_assign('tool_execute_result');
706 nt_sleep(VIEW_DELAY);
708 elseif (isset($_POST['services_update']))
710 $service_update_mode = $_POST['services_update'];
712 switch ($service_update_mode)
714 case 'open ws': // 2
715 if (tool_admin_applications_check('tool_main_ws_old'))
717 $service_command = "ShardOpen 2";
718 $service_list = tool_main_get_checked_services();
720 if (sizeof($service_list))
722 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
723 nt_common_add_debug(array_combine($service_list, $service_list));
724 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
725 $tpl->assign('tool_execute_result', '');
726 reset($service_list);
727 foreach($service_list as $service)
729 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
730 $adminService->serviceCmd($service, $service_command);
731 if (!$adminService->waitCallback())
733 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
737 $tpl->clear_assign('tool_execute_result');
738 nt_sleep(VIEW_DELAY);
742 break;
744 case 'lock ws': // 1
745 if (tool_admin_applications_check('tool_main_ws_old'))
747 $service_command = "ShardOpen 1";
748 $service_list = tool_main_get_checked_services();
750 if (sizeof($service_list))
752 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
753 nt_common_add_debug(array_combine($service_list, $service_list));
754 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
755 $tpl->assign('tool_execute_result', '');
756 reset($service_list);
757 foreach($service_list as $service)
759 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
760 $adminService->serviceCmd($service, $service_command);
761 if (!$adminService->waitCallback())
763 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
767 $tpl->clear_assign('tool_execute_result');
768 nt_sleep(VIEW_DELAY);
772 break;
774 case 'close ws':
775 if (tool_admin_applications_check('tool_main_ws_old'))
777 $service_command = "ShardOpen 0";
778 $service_list = tool_main_get_checked_services();
780 if (sizeof($service_list))
782 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
783 nt_common_add_debug(array_combine($service_list, $service_list));
784 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
785 $tpl->assign('tool_execute_result', '');
786 reset($service_list);
787 foreach($service_list as $service)
789 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
790 $adminService->serviceCmd($service, $service_command);
791 if (!$adminService->waitCallback())
793 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
797 $tpl->clear_assign('tool_execute_result');
798 nt_sleep(VIEW_DELAY);
802 break;
804 case 'activate':
805 if (tool_admin_applications_check('tool_main_service_autostart'))
807 $service_list = tool_main_get_checked_services();
808 if (sizeof($service_list))
810 nt_log("Domain '$AS_Name' : 'activateService' on ". implode(', ',array_values($service_list)));
811 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
812 reset($service_list);
813 foreach($service_list as $service)
815 nt_common_add_debug("about to run 'activateService' on '$service' ...");
816 $adminService->controlCmd($service, 'activateService');
817 if (!$adminService->waitCallback())
819 nt_common_add_debug('Error while waiting for callback for \''. $service .'\'');
823 nt_sleep(VIEW_DELAY);
828 break;
830 case 'deactivate':
831 if (tool_admin_applications_check('tool_main_service_autostart'))
833 $service_list = tool_main_get_checked_services();
834 if (sizeof($service_list))
836 nt_log("Domain '$AS_Name' : 'deactivateService' on ". implode(', ',array_values($service_list)));
837 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
838 reset($service_list);
839 foreach($service_list as $service)
841 nt_common_add_debug("about to run 'deactivateService' on '$service' ...");
842 $adminService->controlCmd($service, 'deactivateService');
843 if (!$adminService->waitCallback())
845 nt_common_add_debug('Error while waiting for callback for \''. $service .'\'');
849 nt_sleep(VIEW_DELAY);
854 break;
856 case 'reset counters':
857 if (tool_admin_applications_check('tool_main_reset_counters'))
859 $service_list = tool_main_get_checked_services();
860 if (sizeof($service_list))
862 nt_log("Domain '$AS_Name' : 'resetStartCounter' on ". implode(', ',array_values($service_list)));
863 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
864 reset($service_list);
865 foreach($service_list as $service)
867 nt_common_add_debug("about to run 'resetStartCounter' on '$service' ...");
868 $adminService->serviceCmd($service, 'aes.resetStartCounter');
869 if (!$adminService->waitCallback())
871 nt_common_add_debug('Error while waiting for callback for \''. $service .'\'');
875 nt_sleep(VIEW_DELAY);
879 break;
881 case 'start':
882 if (tool_admin_applications_check('tool_main_start'))
884 $service_list = tool_main_get_checked_services();
885 if (sizeof($service_list))
887 nt_log("Domain '$AS_Name' : 'startService' on ". implode(', ',array_values($service_list)));
888 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
889 reset($service_list);
890 foreach($service_list as $service)
892 nt_common_add_debug("about to run 'startService' on '$service' ...");
893 $adminService->controlCmd($service, 'startService');
894 if (!$adminService->waitCallback())
896 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for startService');
899 nt_sleep(VIEW_DELAY);
903 break;
905 case 'stop':
906 if (tool_admin_applications_check('tool_main_stop'))
908 $service_list = tool_main_get_checked_services();
909 if (sizeof($service_list))
911 nt_log("Domain '$AS_Name' : 'stopService' on ". implode(', ',array_values($service_list)));
912 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
913 reset($service_list);
914 foreach($service_list as $service)
916 nt_common_add_debug("about to run 'stopService' on '$service' ...");
917 $adminService->controlCmd($service, 'stopService');
918 if (!$adminService->waitCallback())
920 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for stopService');
923 nt_sleep(VIEW_DELAY);
926 break;
928 case 'restart':
929 if (tool_admin_applications_check('tool_main_restart'))
931 $service_list = tool_main_get_checked_services();
932 if (sizeof($service_list))
934 nt_log("Domain '$AS_Name' : 'restartService' on ". implode(', ',array_values($service_list)));
935 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
936 reset($service_list);
937 foreach($service_list as $service)
939 nt_common_add_debug("about to run 'restartService' on '$service' ...");
940 $adminService->controlCmd($service, 'restartService');
941 if (!$adminService->waitCallback())
943 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for restartService');
946 nt_sleep(VIEW_DELAY);
949 break;
951 case 'kill':
952 if (tool_admin_applications_check('tool_main_kill'))
954 $service_list = tool_main_get_checked_services();
955 if (sizeof($service_list))
957 nt_log("Domain '$AS_Name' : 'killService' on ". implode(', ',array_values($service_list)));
958 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
959 reset($service_list);
960 foreach($service_list as $service)
962 nt_common_add_debug("about to run 'killService' on '$service' ...");
963 $adminService->controlCmd($service, 'killService');
964 if (!$adminService->waitCallback())
966 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for killService');
969 nt_sleep(VIEW_DELAY);
972 break;
974 case 'abort':
975 if (tool_admin_applications_check('tool_main_abort'))
977 $service_list = tool_main_get_checked_services();
978 if (sizeof($service_list))
980 nt_log("Domain '$AS_Name' : 'abortService' on ". implode(', ',array_values($service_list)));
981 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
982 reset($service_list);
983 foreach($service_list as $service)
985 nt_common_add_debug("about to run 'abortService' on '$service' ...");
986 $adminService->controlCmd($service, 'abortService');
987 if (!$adminService->waitCallback())
989 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for abortService');
992 nt_sleep(VIEW_DELAY);
995 break;
997 case 'execute':
998 if (tool_admin_applications_check('tool_main_execute'))
1000 if (isset($_POST['service_command']))
1002 $service_command = trim(stripslashes(html_entity_decode($_POST['service_command'], ENT_QUOTES)));
1003 $service_list = tool_main_get_checked_services();
1004 if (sizeof($service_list))
1006 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
1007 nt_common_add_debug(array_combine($service_list, $service_list));
1008 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
1009 $tpl->assign('tool_execute_result', '');
1010 reset($service_list);
1011 foreach($service_list as $service)
1013 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
1014 $adminService->serviceCmd($service, $service_command);
1015 if (!$adminService->waitCallback())
1017 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
1019 else
1021 $tpl->assign('tool_execute_command', htmlentities($service_command, ENT_QUOTES));
1028 break;
1031 } // if ($nel_user['has_lock'])
1033 $status_orders = $adminService->getShardOrders();
1034 $status = $adminService->getStates();
1035 nt_common_add_debug($status_orders);
1036 nt_common_add_debug($status);
1038 $domainServices = tool_main_parse_status($status);
1039 $shardRunList = tool_main_get_shards_from_status($domainServices, $tool_shard_filters);
1040 $shardRunOrders = tool_main_get_shards_orders($status_orders);
1041 nt_common_add_debug($shardRunList);
1042 nt_common_add_debug($shardRunOrders);
1044 $shardInfos = tool_main_get_shards_info_from_db($AS_Application, $domainServices, $tool_shard_filters, $AS_RingSQL);
1045 nt_common_add_debug("shard infos :");
1046 nt_common_add_debug($shardInfos);
1048 $tpl->assign('tool_services_list', $domainServices);
1049 $tpl->assign('tool_shard_run_list', $shardRunList);
1050 $tpl->assign('tool_shard_orders', $shardRunOrders);
1052 $tpl->assign('tool_shard_su_name', tool_main_get_su_from_status($domainServices));
1053 $tpl->assign('tool_shard_infos', $shardInfos);
1054 $tpl->assign('tool_shard_ws_states',array('close','dev','restricted','open'));
1056 if (isset($shardInfos[$AS_InternalName]))
1058 $tpl->assign('tool_restart_ws_state', $shardInfos[$AS_InternalName]['state']);
1061 if (isset($tool_restart_stop_list) && isset($tool_restart_info) && tool_admin_applications_check('tool_main_easy_restart'))
1063 // lets get a list of services for each group
1064 $tool_restart_start_group_list = tool_main_get_restart_services($AS_InternalName, $domainServices, $tool_restart_start_list);
1065 $tpl->assign('tool_restart_start_actions', $tool_restart_start_group_list);
1067 $tool_restart_stop_group_list = tool_main_get_all_restart_services($tool_restart_start_group_list);
1068 $tpl->assign('tool_restart_stop_actions', $tool_restart_stop_group_list);
1070 // get the shard id
1071 $tool_restart_shard_id = tool_main_get_shardid_from_status($domainServices, $AS_InternalName);
1072 $tpl->assign('tool_restart_shard_id', $tool_restart_shard_id);
1074 // find the shard egs for broadcasts
1075 $tool_restart_egs_name = tool_main_get_egs_from_status($domainServices, $AS_InternalName);
1076 $tpl->assign('tool_restart_egs_name', $tool_restart_egs_name);
1081 $tool_hd_list = tool_main_get_hd_data_for_domain($view_domain_id);
1082 nt_common_add_debug($tool_hd_list);
1083 $tpl->assign('tool_hd_list', $tool_hd_list);
1084 $tpl->assign('tool_hd_time', tool_main_get_last_hd_time_for_domain($view_domain_id));
1086 //else
1088 // nt_common_add_debug('invalid host/port!');
1091 $tpl->display('index.tpl');