Fix checkRpItemsPosition
[ryzomcore.git] / web / public_php / admin / tool_log_analyser.php
blob91fd44cd6db5821008126d1e305e65b042a50610
1 <?php
3 require_once('common.php');
4 require_once('functions_tool_main.php');
5 require_once('functions_tool_log_analyser.php');
7 if (!tool_admin_applications_check('tool_las')) nt_common_redirect('index.php');
9 nt_common_add_debug('-- Starting on \'tool_log_analyser.php\'');
11 $tpl->assign('tool_title', "Log Analyser");
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($NELTOOL['GET_VARS']['domain']))
26 if ($view_domain_id != $NELTOOL['GET_VARS']['domain'])
28 $view_domain_id = $NELTOOL['GET_VARS']['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($NELTOOL['GET_VARS']['shard']))
38 $view_shard_id = $NELTOOL['GET_VARS']['shard'];
39 nt_auth_set_session_var('view_shard_id', $view_shard_id);
42 $tpl->assign('tool_domain_list', $nel_user['access']['domains']);
43 $tpl->assign('tool_domain_selected', $view_domain_id);
45 $tpl->assign('tool_shard_list', $nel_user['access']['shards']);
46 $tpl->assign('tool_shard_selected', $view_shard_id);
48 $tool_shard_filters = tool_main_get_shard_ids($view_shard_id);
49 $tpl->assign('tool_shard_filters', $tool_shard_filters);
51 //$nel_tool_notes_meta = "<script type=\"text/javascript\" src=\"overlib/overlib_mini.js\" ></script>\n";
52 //$nel_tool_notes_meta .= "<script type=\"text/javascript\" src=\"overlib/overlib_anchor_mini.js\" ></script>\n";
53 //$nel_tool_notes_meta .= "<script type=\"text/javascript\" src=\"overlib/overlib_draggable_mini.js\" ></script>\n";
54 //$tpl->assign('nel_tool_notes_meta', $nel_tool_notes_meta);
56 $template_file = 'tool_log_analyser.tpl';
58 if ($view_domain_id)
60 $tool_as_error = null;
62 $AS_Name = tool_main_get_domain_name($view_domain_id);
63 $AS_Host = tool_main_get_domain_host($view_domain_id);
64 $AS_Port = tool_main_get_domain_port($view_domain_id);
65 $AS_ShardName = tool_main_get_shard_name($view_shard_id);
67 $tpl->assign('tool_page_title', 'Log Analyser - '. $AS_Name . ($AS_ShardName != '' ? ' / '. $AS_ShardName : ''));
69 $tool_as_error = null;
71 $AS_LAS_AdminPath = tool_main_get_domain_data($view_domain_id, 'domain_las_admin_path');
72 $AS_LAS_LocalPath = tool_main_get_domain_data($view_domain_id, 'domain_las_local_path');
73 $tool_las_file_list = tool_las_get_file_list($AS_LAS_AdminPath);
75 if (isset($NELTOOL['GET_VARS']['fileview']))
77 // FILE VIEWER
79 $template_file = 'tool_log_analyser_file_view.tpl';
80 $view_file_name = base64_decode($NELTOOL['GET_VARS']['fileview']);
81 $tpl->assign('tool_file_list', $tool_las_file_list);
83 $view_file_data = tool_las_check_for_file($tool_las_file_list, $view_file_name);
85 if (isset($NELTOOL['GET_VARS']['downloadraw']))
87 if ($fp = fopen($view_file_data['path'] . $view_file_data['name'], 'r'))
89 header("Content-type: text/plain");
90 header("Content-Disposition: attachment; filename=las_raw_". $view_file_data['name']);
91 header("Pragma: no-cache");
92 header("Expires: 0");
93 fpassthru($fp);
94 fclose($fp);
95 exit();
98 elseif (isset($NELTOOL['GET_VARS']['downloadparsed']))
100 $char_eid_data = tool_las_parse_file($view_file_data['path'] . $view_file_data['name']);
102 // NOTE: 'ring_live' needs to be replace with the ringdb field from the domain table
103 $db_char_data = tool_las_get_character_names('ring_live', $char_eid_data);
105 if (sizeof($db_char_data))
107 $search_eid_ary = array();
108 $search_char_ary = array();
110 reset($char_eid_data);
111 foreach($char_eid_data as $char_id => $char_eid)
113 if (isset($db_char_data[$char_id]))
115 $search_eid_ary[] = $char_eid;
116 $search_char_ary[] = $db_char_data[$char_id];
120 tool_las_fpassthru_replace($view_file_data['path'],$view_file_data['name'], $search_eid_ary, $search_char_ary);
121 exit();
124 //elseif (isset($NELTOOL['GET_VARS']['delete']))
126 // nt_common_add_debug('unlinking file : '. $view_file_data['path'] . $view_file_data['name']);
127 // @unlink($view_file_data['path'] . $view_file_data['name']);
128 // nt_common_redirect('tool_log_analyser.php');
129 // exit();
131 elseif (is_array($view_file_data))
133 $tpl->assign('tool_view_file_data', $view_file_data);
135 $file_line_start = 0;
136 if (isset($NELTOOL['GET_VARS']['viewstart']))
138 $file_line_start = $NELTOOL['GET_VARS']['viewstart'];
141 $file_line_read_max = 200;
143 $view_file_output_data = tool_las_read_file($view_file_data['path'] . $view_file_data['name'], $file_line_read_max, $file_line_start, $file_line_start_previous, $file_line_start_next);
144 $tpl->assign('tool_file_output', $view_file_output_data);
146 $tpl->assign('tool_view_line_start_previous', $file_line_start_previous);
147 $tpl->assign('tool_view_line_start_next', $file_line_start_next);
151 else
153 $tpl->assign('tool_file_error', 'File not found !');
156 elseif (($AS_LAS_AdminPath != '') && ($AS_LAS_LocalPath != ''))
158 // REGULAR SERVICE VIEW WITH COMMANDS
160 $tpl->assign('tool_file_list', $tool_las_file_list);
162 if (substr($AS_LAS_AdminPath,-1) != '/') $AS_LAS_AdminPath .= '/';
163 if (substr($AS_LAS_LocalPath,-1) != '/') $AS_LAS_LocalPath .= '/';
165 if ($AS_Host && $AS_Port)
167 $adminService = new MyAdminService;
168 if (@$adminService->connect($AS_Host, $AS_Port, $res) === false)
170 nt_common_add_debug($res);
171 $tpl->assign('tool_domain_error', $res );
173 else
175 if (isset($NELTOOL['POST_VARS']['services_las']))
177 $tool_services_las = $NELTOOL['POST_VARS']['services_las'];
178 $tpl->assign('tool_post_data', base64_encode(serialize($NELTOOL['POST_VARS'])));
180 $service_search_database = $NELTOOL['POST_VARS']['service_search_database'];
181 $service_search_file_name = $NELTOOL['POST_VARS']['service_search_file_name'];
182 $service_search_start_date = $NELTOOL['POST_VARS']['service_search_start_date'];
183 $service_search_end_date = $NELTOOL['POST_VARS']['service_search_end_date'];
185 $tpl->assign('tool_form_service_search_database', $service_search_database);
186 $tpl->assign('tool_form_service_search_file_name', $service_search_file_name);
187 $tpl->assign('tool_form_service_search_start_date', $service_search_start_date);
188 $tpl->assign('tool_form_service_search_end_date', $service_search_end_date);
190 $file_name_error_msg = null;
191 $start_date_error_msg = null;
193 switch ($tool_services_las)
195 case 'search eids':
197 if ($service_search_file_name == '') $file_name_error_msg = "Need to specify a filename !";
198 if ($service_search_start_date == '') $start_date_error_msg = "Need to specify a start date !";
200 $tpl->assign('tool_file_name_error_msg', $file_name_error_msg);
201 $tpl->assign('tool_start_date_error_msg', $start_date_error_msg);
203 if (isset($NELTOOL['POST_VARS']['service_eids']) && !$file_name_error_msg && !$start_date_error_msg)
205 $service_eids = trim(stripslashes($NELTOOL['POST_VARS']['service_eids']));
206 $tpl->assign('tool_form_service_eids', $service_eids);
208 $service_eids_ary = tool_las_parse_eids_to_array($service_eids);
209 nt_common_add_debug($service_eids_ary);
211 if (sizeof($service_eids_ary) > 0)
213 $service_command = 'executeToFile '. $AS_LAS_LocalPath . $service_search_file_name ;
215 if (sizeof($service_eids_ary) == 1) $service_command .= ' searchEId ';
216 else $service_command .= ' searchEIds ';
218 $service_command .= $service_search_database .' ';
219 $service_command .= implode(' ', $service_eids_ary) .' ';
221 if (sizeof($service_eids_ary) > 1) $service_command .= '- ';
222 $service_command .= $service_search_start_date;
224 if ($service_search_end_date != '') $service_command .= ' '. $service_search_end_date;
226 nt_common_add_debug($service_command);
228 $service_list = tool_main_get_checked_services();
229 if (sizeof($service_list))
231 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
232 nt_common_add_debug(array_combine($service_list, $service_list));
233 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
234 $tpl->assign('tool_execute_result', '');
235 reset($service_list);
236 foreach($service_list as $service)
238 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
239 $adminService->serviceCmd($service, $service_command);
240 if (!$adminService->waitCallback())
242 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
250 break;
252 case 'search text':
254 if ($service_search_file_name == '') $file_name_error_msg = "Need to specify a filename !";
255 if ($service_search_start_date == '') $start_date_error_msg = "Need to specify a start date !";
257 $tpl->assign('tool_file_name_error_msg', $file_name_error_msg);
258 $tpl->assign('tool_start_date_error_msg', $start_date_error_msg);
260 if (isset($NELTOOL['POST_VARS']['service_text']) && !$file_name_error_msg && !$start_date_error_msg)
262 $service_text = trim(stripslashes(html_entity_decode($NELTOOL['POST_VARS']['service_text'], ENT_QUOTES)));
263 $tpl->assign('tool_form_service_text', htmlentities($service_text,ENT_QUOTES));
265 if ($service_text != '')
267 $service_command = 'executeToFile '. $AS_LAS_LocalPath . $service_search_file_name ;
268 $service_command .= ' searchString '. $service_search_database .' "'. addslashes($service_text) .'" ';
269 $service_command .= $service_search_start_date;
270 if ($service_search_end_date != '') $service_command .= ' '. $service_search_end_date;
272 nt_common_add_debug($service_command);
274 $service_list = tool_main_get_checked_services();
275 if (sizeof($service_list))
277 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
278 nt_common_add_debug(array_combine($service_list, $service_list));
279 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
280 $tpl->assign('tool_execute_result', '');
281 reset($service_list);
282 foreach($service_list as $service)
284 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
285 $adminService->serviceCmd($service, $service_command);
286 if (!$adminService->waitCallback())
288 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
296 break;
298 case 'execute':
300 if (isset($NELTOOL['POST_VARS']['service_command']))
302 $service_command = trim(stripslashes(html_entity_decode($NELTOOL['POST_VARS']['service_command'], ENT_QUOTES)));
303 $service_list = tool_main_get_checked_services();
304 if (sizeof($service_list))
306 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
307 nt_common_add_debug(array_combine($service_list, $service_list));
308 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
309 $tpl->assign('tool_execute_result', '');
310 reset($service_list);
311 foreach($service_list as $service)
313 nt_common_add_debug("about to run command '$service_command' on '$service' ...");
314 $adminService->serviceCmd($service, $service_command);
315 if (!$adminService->waitCallback())
317 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
319 else
321 $tpl->assign('tool_execute_command', htmlentities($service_command, ENT_QUOTES));
327 break;
332 $status = $adminService->getStates();
333 nt_common_add_debug($status);
335 $domainServices = tool_main_parse_status($status);
337 $filteredServices = array();
338 reset($domainServices);
339 foreach($domainServices as $aKey => $aService)
341 // we are only interested in EGS
342 if ($aService['ShortName'] == 'LAS')
344 $filteredServices[] = $aService;
347 $tpl->assign('tool_services_list', $filteredServices);
353 $tpl->display($template_file);