226 lines
6.5 KiB
PHP
226 lines
6.5 KiB
PHP
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Test Khanat Log</title>
|
|
</head>
|
|
|
|
<style>
|
|
#command_shell{
|
|
background: #F3E2A9;
|
|
border:3px solid #151515;
|
|
color: #000000;
|
|
margin:10px;
|
|
padding:3px;
|
|
top:40px;left:3%;right:3%;
|
|
text-align:left;
|
|
max-width:100vw;
|
|
}
|
|
#title_info{
|
|
background: #00FFFF;
|
|
border:3px solid #8A0808;
|
|
color: #000000;
|
|
font-size:20px;
|
|
font-weight:500;
|
|
margin:50px;
|
|
padding:3px;
|
|
top:40px;left:3%;right:3%;
|
|
text-align:center;
|
|
}
|
|
#important_info{
|
|
background: #A9E2F3;
|
|
border:3px solid #088A08;
|
|
color: #000000;
|
|
font-size:15px;
|
|
font-weight:500;
|
|
margin:30px;
|
|
padding:3px;
|
|
top:40px;left:3%;right:3%;
|
|
text-align:left;
|
|
}
|
|
table, th, td {
|
|
border: 1px solid black;
|
|
border-collapse: collapse;
|
|
}
|
|
#alert_javascript{
|
|
background: #F3F781;
|
|
border:3px solid #610B0B;
|
|
color: #DF0101;
|
|
font-size:20px;
|
|
font-weight:700;
|
|
margin:0;
|
|
padding:3px;
|
|
top:40px;left:3%;right:3%;
|
|
text-align:center;
|
|
max-width:100vw;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
function setHref() {
|
|
document.getElementById('admin-href').href = window.location.protocol + "//" + window.location.hostname + ":40916/ams/";
|
|
}
|
|
|
|
function send(rooturl, id) {
|
|
//document.getElementById("info").innerHTML = "send " + rooturl + ", " + document.getElementById(id).value;
|
|
var xhr = new XMLHttpRequest();
|
|
var url = rooturl + "/STDIN";
|
|
//console.log(url);
|
|
xhr.open("POST", url, true);
|
|
xhr.setRequestHeader("content-type", "application/json");
|
|
xhr.onreadystatechange = function () {
|
|
console.log(xhr.readyState);
|
|
console.log(xhr.status);
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
//var json = JSON.parse(xhr.responseText);
|
|
console.log(xhr.responseText);
|
|
}
|
|
};
|
|
var data = JSON.stringify({"name": "<?php echo $_GET['command']; ?>", "action": document.getElementById(id).value});
|
|
//console.log(data);
|
|
xhr.send(data);
|
|
}
|
|
</script>
|
|
<noscript>
|
|
<div id='alert_javascript'>
|
|
This website need Javascript.<br>
|
|
Could you please enable Javascript?
|
|
</div>
|
|
</noscript>
|
|
|
|
<body onload="setHref()">
|
|
<p>
|
|
<a href="/" id="home" >Home</a>
|
|
<?php
|
|
if (file_exists('/home/gameserver/opennelmanager.flag')) {
|
|
echo "<a href=\"/opennelmanager.php\">OpenNelManager</a>";
|
|
} else {
|
|
echo "<a>opennelmanager not used</a>";
|
|
}
|
|
?>
|
|
<a href="/EnableJavascript" id="admin-href" >Administration</a>
|
|
<a href="/phpmyadmin/">phpmyadmin</a>
|
|
<a href="/patch/">patch</a>
|
|
</p>
|
|
<div id='title_info'>KHANAT SERVER DOCKER (TEST ENVIRONMENT - LOG)</div>
|
|
<div id='important_info'><?php echo $_GET['command']; ?></div>
|
|
|
|
<?php
|
|
|
|
function get_port($filecfg)
|
|
{
|
|
// $ini_array = parse_ini_file($filecfg);
|
|
// return "${ini_array['port']}";
|
|
|
|
$fp = fopen($filecfg, "r");
|
|
if ($fp) {
|
|
while (($line = fgets($fp)) !== false) {
|
|
list($data, $comment) = explode('#', $line, 2);
|
|
list($key, $value) = explode('=', $line, 2);
|
|
$key = trim($key);
|
|
if ( $key == "port" ) {
|
|
return trim($value);
|
|
}
|
|
}
|
|
fclose($fp);
|
|
}
|
|
return "8000";
|
|
}
|
|
|
|
$cfgfile = "/home/gameserver/khanat/khaganat.cfg";
|
|
|
|
if (file_exists($cfgfile)) {
|
|
$info = get_port($cfgfile);
|
|
$rooturl = "http://" . getHostByName(gethostname()) . ":" . $info ;
|
|
$url = $rooturl . "/STDOUT";
|
|
|
|
// Initiate curl
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL,$url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$data = "{\"name\": \"${_GET['command']}\", \"first-line\": 0}";
|
|
|
|
$headers = array(
|
|
"GET /STDOUT HTTP/1.0",
|
|
'Content-type: application/json',
|
|
'Content-Length: ' . strlen($data)
|
|
);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
// Execute
|
|
$result=curl_exec($ch);
|
|
// Closing
|
|
curl_close($ch);
|
|
// var_dump($result);
|
|
$data = json_decode($result,true);
|
|
// var_dump($data);
|
|
///Count
|
|
$total=count($data);
|
|
echo "<div>First line:${data['first-line']} Last line:${data['last-line']}<br/>";
|
|
echo "<table>";
|
|
echo "<tr><th>Pos</th><th>Date</th><th>Time</th><th>Zone</th><th>Type</th><th>Address</th><th>Program Line</th><th>Message</th></tr>";
|
|
ksort($data);
|
|
foreach ($data as $key => $value)
|
|
{
|
|
// 2018/08/03 10:45:36 CEST INF 442b0740 command.cpp 149
|
|
list($date, $hour, $timezone, $typesrc, $addr, $program, $line, $msg) = explode(' ', $value, 8);
|
|
|
|
if ( $key == "first-line" or $key == "last-line" )
|
|
continue;
|
|
|
|
$type = substr( $typesrc, strlen($typesrc) - 3 );
|
|
if ( $type == 'INF' ) {
|
|
$fond = "bgcolor=\"SpringGreen \"";
|
|
} else if ( $type == 'DBG') {
|
|
$fond = "bgcolor=\"AQUAMARINE\"";
|
|
} else if ( $type == 'WRN') {
|
|
$fond = "bgcolor=\"Yellow\"";
|
|
} else if ( $type == 'ERR') {
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
} else if ( $type == 'STT') {
|
|
$fond = "bgcolor=\"Yellow\"";
|
|
} else if ( $type == 'AST') {
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
} else if ( $type == 'UKN') {
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
} else {
|
|
$msg = "$typesrc $addr $program $line $msg";
|
|
$type = "?";
|
|
$addr = "";
|
|
$program = "";
|
|
$line = "";
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
}
|
|
if ( $program != "" && $line != "" )
|
|
{
|
|
if ( substr( $program, strlen($program) - 4 ) != ".cpp" and substr( $program, strlen($program) - 2 ) != ".h" )
|
|
{
|
|
$msg = "$program $line $msg";
|
|
$program = "";
|
|
$line = "";
|
|
}
|
|
}
|
|
echo "<tr><td>$key</td><td>$date</td><td>$hour</td><td>$timezone</td><td $fond>$type</td><td>$addr</td><td>$program $line</td><td $fond>$msg</td></tr>";
|
|
|
|
}
|
|
echo "</table></div>";
|
|
|
|
} else {
|
|
echo "<a>OpenNelManager not enabled</a>";
|
|
}
|
|
?>
|
|
<br>
|
|
Send to STDIN: <input type="text" id="command" value="command" size="100"/>
|
|
<input type="submit" value="Submit" onclick="send('<?php echo $rooturl; ?>', 'command');"/>
|
|
<br>
|
|
</p>
|
|
<div>
|
|
Command line :
|
|
<div id='command_shell'>
|
|
curl -XGET --header "content-type: application/json" -d '<?php print "{\"name\": \"${_GET['command']}\", \"first-line\": 0}";?>' <?php print $url;?>
|
|
</div>
|
|
</div>
|
|
<p id="info"></p>
|
|
</body>
|
|
</html>
|