Linux multi-monitor fullscreen support
[ryzomcore.git] / nelns / admin / public_html / las_interface.php
blobe4341fcc2a3c6f29046e00ca87e122781d908c63
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 global $HTTP_POST_VARS, $HTTP_GET_VARS;
20 $publicAccess = false;
21 $allowNevrax = true;
22 include('authenticate.php');
24 include('request_interface.php');
25 include_once('las_connection.php');
27 if (!isset($_POST) && isset($HTTP_POST_VARS))
28 $_POST = &$HTTP_POST_VARS;
29 if (!isset($_GET) && isset($HTTP_GET_VARS))
30 $_GET = &$HTTP_GET_VARS;
32 function importParam($var)
34 global $_POST, $_GET;
35 if (isset($_POST[$var]))
36 $GLOBALS[$var] = $_POST[$var];
37 else if (isset($_GET[$var]))
38 $GLOBALS[$var] = $_GET[$var];
39 else
40 unset($GLOBALS[$var]);
43 htmlProlog($_SERVER['PHP_SELF'], "Log Analysis");
45 // look for LAS
46 $las_query = "*.*.LAS.State";
47 $qstate = nel_query($las_query, $result);
49 unset($availableLAS);
50 if ($qstate)
52 $arr = explode(' ', $result);
53 $numRes = count($arr);
54 $numRows = current($arr);
55 $numLines = ($numRes-$numRows-2)/$numRows;
56 next($arr);
57 for ($i=0; $i<$numRows; ++$i)
59 $vars[] = current($arr);
60 next($arr);
62 unset($shards);
63 for ($i=0; $i<$numLines; ++$i)
65 unset($l);
66 foreach($vars as $var)
68 $l[$var] = current($arr);
69 next($arr);
72 $sql_query = "SELECT * FROM server WHERE name='".$l['server']."'";
73 $sql_res = sqlquery($sql_query);
74 if ($sql_res && ($sql_arr = sqlfetch($sql_res)))
75 $l['address'] = $sql_arr['address'];
77 $availableLAS[] = $l;
81 echo "<pre>";
82 print_r($availableLAS);
83 echo "</pre>";
85 importParam('exec_query');
86 importParam('refresh_result');
87 importParam('query');
88 importParam('query_id');
89 importParam('page');
91 importParam('build_display_query');
92 importParam('build_eid_query');
93 importParam('database');
94 for ($i=0; $i<10; ++$i)
95 importParam("eid_$i");
96 importParam('string');
97 importParam('start_date');
98 importParam('end_date');
100 $string = stripslashes($string);
101 $query = stripslashes($query);
103 // ------------------------------------------------------------------------------------------------------------------------
105 echo "<br>";
107 echo "<table border=0>\n";
108 echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>\n";
110 echo "<tr valign=top>\n";
112 $selectedLAS = '';
114 // mandatory information
115 echo "<td>\n";
116 echo "<table>\n";
117 echo "<tr><th align=left>LAS Host</th></tr>\n";
118 echo "<tr><td>";
119 echo "<select name='las_address'>\n";
120 if (count($availableLAS) > 0)
122 foreach ($availableLAS as $las)
124 if ($las_address == $las['address'])
126 $selectedLAS = $las;
127 echo "<option value='".$las['address']."' selected>".$las['shard']." ".$las['server']." ".$las['service']."\n";
129 else
131 echo "<option value='".$las['address']."'>".$las['shard']." ".$las['server']." ".$las['service']."\n";
135 if (!$selectedLAS['address'])
137 echo "<option value='' selected>---- Select a LAS Host";
139 else
141 echo "<option value=''>---- Select a LAS Host";
143 echo "</select>\n";
144 echo "</td></tr>";
145 echo "<tr><th align=left>Database</th></tr>\n";
146 echo "<tr><td><input type='text' name='database' size=10 maxlength=10 value='$database'></td></tr>";
147 echo "<tr><th align=left>Start Date</th></tr>\n";
148 echo "<tr><td><input type='text' name='start_date' size=30 maxlength=20 value='$start_date'></td></tr>";
149 echo "<tr><th align=left>End Date</th></tr>\n";
150 echo "<tr><td><input type='text' name='end_date' size=30 maxlength=20 value='$end_date'></td></tr>";
151 echo "</table>\n";
152 echo "</td>\n";
154 // search by eid
155 echo "<td>\n";
156 echo "<table>\n";
157 echo "<tr><th align=left>EntityIds</th></tr>\n";
158 echo "<tr><td>\n";
159 for ($i=0; $i<10; ++$i)
160 echo "<input id='eid_$i' type='text' name='eid_$i' size=30 maxlength=25 value='".$GLOBALS["eid_$i"]."'><br>\n";
161 echo "</td></tr>\n";
162 echo "</table>\n";
163 echo "</td>\n";
165 echo "<script>\n";
166 echo "<!--\n";
167 echo " function reorderEId()\n";
168 echo " {\n";
169 echo " lastNull = -1;\n";
170 echo " for (i=0; i<10; ++i)\n";
171 echo " {\n";
172 echo " if (document.getElementById('eid_'+i).value == '')\n";
173 echo " lastNull = i;\n";
174 echo " else if (lastNull >= 0)\n";
175 echo " {\n";
176 echo " document.getElementById('eid_'+lastNull).value = document.getElementById('eid_'+i).value\n";
177 echo " document.getElementById('eid_'+i).value = ''\n";
178 echo " ++lastNull;\n";
179 echo " }\n";
180 echo " }\n";
181 echo " }\n";
182 echo " function selectEId(id)\n";
183 echo " {\n";
184 echo " reorderEId();\n";
185 echo " for (i=0; i<10; ++i)\n";
186 echo " if (document.getElementById('eid_'+i).value == id)\n";
187 echo " return;\n";
188 echo " for (i=0; i<10; ++i)\n";
189 echo " if (document.getElementById('eid_'+i).value == '')\n";
190 echo " {\n";
191 echo " document.getElementById('eid_'+i).value = id;\n";
192 echo " return;\n";
193 echo " }\n";
194 echo " }\n";
195 echo " reorderEId();\n";
196 echo "-->\n";
197 echo "</script>\n";
199 // search by string
200 echo "<td>\n";
201 echo "<table>\n";
202 echo "<tr><th align=left>String</th></tr>\n";
203 echo "<tr><td><input type='text' name='string' size=100 maxlength=40 value='$string'></td></tr>";
204 echo "</table>\n";
205 echo "</td>\n";
207 echo "</tr>\n";
208 echo "<tr valign=top>\n";
210 echo "<td align=center><input type='submit' name='build_display_query' value='Display'></td>";
211 echo "<td align=center><input type='submit' name='build_eid_query' value='Search Id(s)'></td>";
212 echo "<td align=center><input type='submit' name='build_string_query' value='Search String'></td>";
214 echo "</tr>\n";
216 echo "</tr>\n";
217 echo "<tr valign=top>\n";
219 echo "<td align=center><input type='submit' name='display_queries' value='Display Queries'></td>";
221 echo "</tr>\n";
223 echo "</form>\n";
224 echo "</table>\n";
226 // ------------------------------------------------------------------------------------------------------------------------
228 echo "<br>\n";
231 if ($build_eid_query || $build_display_query)
233 $eids = array();
234 for ($i=0; $i<10; ++$i)
235 if ($GLOBALS["eid_$i"] != '')
236 $eids[] = $GLOBALS["eid_$i"];
238 if (count($eids) == 0 || $build_display_query)
240 $query = "displayLogs $database $start_date";
241 if ($end_date != '')
242 $query .= " $end_date";
243 $exec_query = true;
245 else if (count($eids) > 1)
247 $query = "searchEIds $database ".join(' ', $eids)." - $start_date";
248 if ($end_date != '')
249 $query .= " $end_date";
250 $exec_query = true;
252 else
254 $query = "searchEId $database ".$eids[0]." $start_date";
255 if ($end_date != '')
256 $query .= " $end_date";
257 $exec_query = true;
260 else if ($build_string_query)
262 if ($string != '')
264 $query = "searchString $database \"$string\" $start_date";
265 if ($end_date != '')
266 $query .= " $end_date";
267 $exec_query = true;
272 // display query input
273 echo "<table>\n";
274 echo "<form method='post' action='$_SERVER['PHP_SELF']'>\n";
275 echo "<tr>\n";
276 echo "<td>Query</td>";
277 echo "<td><input type=text name='query' value='$query' size=128 maxlength=255></td>";
278 echo "<td><input type=submit name='exec_query' value='Submit Query'></td>\n";
279 echo "</tr>\n";
280 echo "<input type='hidden' name='database' value='$database'>\n";
281 for ($i=0; $i<10; ++$i)
282 echo "<input type='hidden' name='eid_$i' value='".$GLOBALS["eid_$i"]."'>\n";
283 echo "<input type='hidden' name='start_date' value='$start_date'>\n";
284 echo "<input type='hidden' name='end_date' value='$end_date'>\n";
285 echo "</form>\n";
286 echo "</table>\n";
289 if ($display_queries && $selectedLAS['address'])
291 $success = displayLASQueries($selectedLAS['address'], $result);
293 if ($success)
295 $a = explode("\n", $result);
296 if (count($a) > 0)
298 echo "<table border=1 width='100%'><tr><td>";
299 echo "<table width='100%'>\n";
300 $i = 0;
301 foreach ($a as $query)
303 if ($query == '')
304 continue;
306 $qa = explode(':', $query, 4);
308 $bg = (($i & 1) == 0 ? '#F8F8FF' : '#F0F0F8');
309 ++$i;
310 echo "<tr bgcolor=$bg>";
311 if ($qa[1] == 2)
313 echo "<td>".$qa[0]."</td>";
314 $refstr = $_SERVER['PHP_SELF']."?refresh_result=1&las_address=".$selectedLAS['address']."&query_id=".$qa[0]."&query=".$qa[2]."&database=$database&string=$string&start_date=$start_date&end_date=$end_date";
315 echo "<td><a href='$refstr'>Display</a></td>";
316 echo "<td>".$qa[3]."</td>";
318 else if ($qa[1] == 1)
320 echo "<td>".$qa[0]."</td>";
321 echo "<td>Processing ".$qa[2]."%</td>";
322 echo "<td>".$qa[3]."</td>";
324 else
326 echo "<td>".$qa[0]."</td>";
327 echo "<td>Cancel</td>";
328 echo "<td>".$qa[3]."</td>";
330 echo "</tr>\n";
332 echo "</table>";
333 echo "</td></tr></table>";
337 else if ($exec_query && $query && $selectedLAS['address'])
339 $success = logQuery($selectedLAS['address'], $query, $result, $query_id);
341 echo "<br><br>";
343 if ($success)
345 echo "<b>Query '$query' successfully executed ($result)</b><br>\n";
346 echo "Please wait while result is being computed and click 'Refresh result' to display query result.<br>\n";
347 echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>\n";
348 echo "<input type=submit name='refresh_result' value='Refresh result'>\n";
349 echo "<input type=hidden name='las_address' value='".$selectedLAS['address']."'>\n";
350 echo "<input type=hidden name='query_id' value='$query_id'>\n";
351 echo "<input type=hidden name='query' value='$query'>\n";
352 echo "<input type='hidden' name='database' value='$database'>\n";
353 for ($i=0; $i<10; ++$i)
354 echo "<input type='hidden' name='eid_$i' value='".$GLOBALS["eid_$i"]."'>\n";
355 echo "<input type='hidden' name='string' value='$string'>\n";
356 echo "<input type='hidden' name='start_date' value='$start_date'>\n";
357 echo "<input type='hidden' name='end_date' value='$end_date'>\n";
358 echo "</form>\n";
360 else
362 echo "<b>Query '$query' failed</b>: '$result'<br>\n";
365 else if ($refresh_result && isset($query_id) && $selectedLAS['address'])
367 $success = getQueryResult($selectedLAS['address'], $query_id, $result, $page, $numpages);
369 echo "<br><br>";
371 if ($success)
373 echo "<b>Query '$query' result</b>:<br>\n";
375 echo "<b>";
377 $refstr = $_SERVER['PHP_SELF']."?refresh_result=1&las_address=".$selectedLAS['address']."&query_id=$query_id&query=$query&database=$database&string=$string&start_date=$start_date&end_date=$end_date";
378 for ($i=0; $i<10; ++$i)
379 if ($GLOBALS["eid_$i"] != '')
380 $refstr .= "&eid_$i=".$GLOBALS["eid_$i"];
382 if ($page > 0)
383 echo "<a href='$refstr&page=0'>&lt;&lt;</a>\n ";
384 else
385 echo "&lt;&lt; ";
387 if ($page > 0)
388 echo "<a href='$refstr&page=".($page-1)."'>&lt;</a>\n";
389 else
390 echo "&lt;";
392 if ($page+1 < $numpages)
393 echo " <a href='$refstr&page=".($page+1)."'>&gt;</a>\n";
394 else
395 echo " &gt;";
397 if ($page+1 < $numpages)
398 echo " <a href='$refstr&page=".($numpages-1)."'>&gt;&gt;</a>\n";
399 else
400 echo " &gt;&gt;";
402 echo "</b>\n";
404 if ($numpages < 20)
406 $minpage = 0;
407 $maxpage = $numpages-1;
409 else
411 $minpage = $page-10;
412 if ($minpage < 0)
413 $minpage = 0;
414 $maxpage = $minpage+20;
415 if ($maxpage >= $numpages)
416 $maxpage = $numpages-1;
417 $minpage = $maxpage-20;
420 for ($p=$minpage; $p<=$maxpage; ++$p)
422 if ($p == $page)
424 echo " <b>$page</b>";
426 else
428 echo " <a href='$refstr&page=$p'>$p</a>\n";
432 echo " [$numpages pages]";
434 echo "<br>\n";
436 $disp = htmlentities($result);
438 echo "<table border=1 width='100%'><tr><td>";
439 echo "<table width='100%'>\n";
441 $a = explode("\n", $disp);
442 $i = 0;
443 foreach ($a as $l)
445 if (trim($l) == '')
446 continue;
447 $bg = (($i & 1) == 0 ? '#F8F8FF' : '#F0F0F8');
448 ++$i;
449 $prefix = substr($l, 0, 3);
450 echo "<tr bgcolor=$bg>";
451 if ($prefix == '#! ')
453 echo "<td colspan=3><font color=#FF0000>";
454 echo substr($l, 3);
455 echo "</font></td>";
457 else if ($prefix == '#? ')
459 echo "<td colspan=3><font color=#008800>";
460 echo substr($l, 3);
461 echo "</font></td>";
463 else if ($prefix == '## ')
465 echo "<td colspan=3><font color=#0000FF>";
466 echo substr($l, 3);
467 echo "</font></td>";
469 else if ($prefix == '#$ ')
471 $al = explode(':', substr($l, 3), 4);
472 echo "<td width=50>".$al[0]."</td>";
473 echo "<td width=100>".trim($al[2])."</td>";
475 $d = str_repeat('-&nbsp;', $al[1]).$al[3];
477 $d = ereg_replace('(\(0x[0-9a-fA-F]{10}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\))', '<a onClick="return selectEId('."'".'\\1'."'".')">\\1</a>', $d);
478 //$d = ereg_replace('(\(0x[0-9a-fA-F]{10}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\))', '<a onClick="return alert('."'".'tamere'."'".')">\\1</a>', $d);
480 echo "<td>$d</td>";
482 else
484 echo "<td colspan=3><font color=#AAAAAA><i>// $l</i></font></td>";
486 echo "</tr>\n";
489 echo "</table>";
490 echo "</td></tr></table>";
492 else
494 echo "<b>Failed to get query result</b>: '$result'<br>\n";
495 echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>\n";
496 echo "<input type=submit name='refresh_result' value='Refresh result'>\n";
497 echo "<input type=hidden name='las_address' value='".$selectedLAS['address']."'>\n";
498 echo "<input type=hidden name='query_id' value='$query_id'>\n";
499 echo "<input type=hidden name='query' value='$query'>\n";
500 echo "<input type='hidden' name='database' value='$database'>\n";
501 for ($i=0; $i<10; ++$i)
502 echo "<input type='hidden' name='eid_$i' value='".$GLOBALS["eid_$i"]."'>\n";
503 echo "<input type='hidden' name='string' value='$string'>\n";
504 echo "<input type='hidden' name='start_date' value='$start_date'>\n";
505 echo "<input type='hidden' name='end_date' value='$end_date'>\n";
506 echo "</form>\n";
509 else if (($exec_query || $refresh_result) && (!$selectedLAS['address']))
511 echo "<b>No LAS Host selected</b>, please restart query with a LAS Host specified.<br>\n";
514 echo "<br>";
516 htmlEpilog();