284 lines
8.5 KiB
PHP
284 lines
8.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) {
|
|
$datawithoutcomment = explode('#', $line);
|
|
$data = explode('=', $datawithoutcomment[0]);
|
|
if ( count($data) >= 2 ) {
|
|
list($key, $value) = explode('=', $datawithoutcomment[0], 2);
|
|
} else if ( count($data) == 1 ) {
|
|
$key = $data[0];
|
|
$value = "";
|
|
} else {
|
|
$key = "";
|
|
$value = "";
|
|
}
|
|
$key = trim($key);
|
|
if ( $key == "port" ) {
|
|
return trim($value);
|
|
}
|
|
}
|
|
fclose($fp);
|
|
}
|
|
return "8000";
|
|
}
|
|
|
|
function is_valid_type($type)
|
|
{
|
|
if ( $type == 'INF' ) { // Information
|
|
return true;
|
|
} else if ( $type == 'DBG') { // Information
|
|
return true;
|
|
} else if ( $type == 'WRN') { // Warning
|
|
return true;
|
|
} else if ( $type == 'ERR') { // Error
|
|
return true;
|
|
} else if ( $type == 'STT') { // Statistic
|
|
return true;
|
|
} else if ( $type == 'AST') { // Assert
|
|
return true;
|
|
} else if ( $type == 'UKN') { // Unknown
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
$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)
|
|
{
|
|
if ( $key == "first-line" or $key == "last-line" )
|
|
continue;
|
|
|
|
list($date, $hour, $timezone, $typesrc, $addr, $program, $line, $msg, $type) = array('', '', '', '', '', '', '', '', '?');
|
|
|
|
// 2018/08/03 10:45:36 CEST INF 442b0740 command.cpp 149
|
|
$arrayret = explode(' ', $value);
|
|
if ( count($arrayret) >= 8 ) {
|
|
list($date, $hour, $timezone, $typesrc, $addr, $program, $line, $msg) = explode(' ', $value, 8);
|
|
if ( ! is_numeric($line) ) {
|
|
if ( is_valid_type($line) ) {
|
|
list($date, $hour, $timezone, $data1, $hour1, $kind, $typesrc, $addr, $program, $line, $msg) = explode(' ', $value, 11);
|
|
$msg = "[$data1 $hour1 $kind] $msg";
|
|
} else {
|
|
list($date, $hour, $timezone, $msg) = explode(' ', $value, 4);
|
|
$msg = "$msg";
|
|
}
|
|
} else {
|
|
$msg = "$msg";
|
|
}
|
|
} else if ( count($arrayret) >= 4 ) {
|
|
$arrayret = explode(' ', $value, 4);
|
|
list($date, $hour, $timezone, $msg) = explode(' ', $value, 4);
|
|
} else {
|
|
$msg = $value;
|
|
}
|
|
|
|
$type = substr( $typesrc, strlen($typesrc) - 3 );
|
|
if ( $type == 'INF' ) { // Information
|
|
$fond = "bgcolor=\"SpringGreen \"";
|
|
} else if ( $type == 'DBG') { // Information
|
|
$fond = "bgcolor=\"AQUAMARINE\"";
|
|
} else if ( $type == 'WRN') { // Warning
|
|
$fond = "bgcolor=\"Yellow\"";
|
|
} else if ( $type == 'ERR') { // Error
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
} else if ( $type == 'STT') { // Statistic
|
|
$fond = "bgcolor=\"Yellow\"";
|
|
} else if ( $type == 'AST') { // Assert
|
|
$fond = "bgcolor=\"Tomato\"";
|
|
} else if ( $type == 'UKN') { // Unknown
|
|
$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>";
|
|
}
|
|
?>
|
|
<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>
|
|
<p>
|
|
<br>
|
|
Send to STDIN: <input type="text" id="command" value="help" size="100"/>
|
|
<input type="submit" value="Submit" onclick="send('<?php echo $rooturl; ?>', 'command');"/>
|
|
<br>
|
|
<div>
|
|
Command line :
|
|
<div id='command_shell'>
|
|
curl -XPOST --header "content-type: application/json" -d '<?php print "{\"name\": \"${_GET['command']}\", \"action\": \"help\"}";?>' <?php print $rooturl . "/STDIN";?>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
<p id="info"></p>
|
|
</body>
|
|
</html>
|