khanat-server-docker-NeL/server/common/rootweb/opennelmanager.php
2018-08-05 13:36:12 +02:00

223 lines
6.1 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<title>Test Khanat States</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 type="text/javascript">
function setHref() {
document.getElementById('admin-href').href = window.location.protocol + "//" + window.location.hostname + ":40916/ams/";
}
function start(rooturl, cmd) {
//document.getElementById("info").innerHTML = "Start " + rooturl + " " + cmd;
var xhr = new XMLHttpRequest();
var url = rooturl + "/START";
//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": cmd});
//console.log(data);
xhr.send(data);
}
function stop(rooturl, cmd) {
//document.getElementById("info").innerHTML = "Stop " + rooturl + " " + cmd;
var xhr = new XMLHttpRequest();
var url = rooturl + "/STOP";
//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": cmd});
//console.log(data);
xhr.send(data);
}
var timeout = setTimeout("updateRefresh();",1000);
var enable = true;
var timer = 10;
function updateRefresh() {
//clearTimeout(timeout);
//timeout = setTimeout("updateRefresh();",10000);
//document.getElementById("refreshMsg").value = "Refresh";
timer = timer - 1;
if ( timer > 0 ) {
clearTimeout(timeout);
document.getElementById("refreshMsg").lastChild.textContent = timer + "s" ;
timeout = setTimeout("updateRefresh();",1000);
} else {
timer = 10;
location.reload(true);
}
}
function toggleRefresh()
{
if ( enable ) {
enable = false;
document.getElementById("refreshMsg").lastChild.textContent = "Off";
clearTimeout(timeout);
} else {
enable = true;
timer = 10;
document.getElementById("refreshMsg").lastChild.textContent = "10s";
clearTimeout(timeout);
timeout = setTimeout("updateRefresh();",1000);
}
}
</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>
<a>OpenNelManager</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 - STATES)</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";
}
if (file_exists('/home/gameserver/opennelmanager.flag')) {
$cfgfile = "/home/gameserver/khanat/khaganat.cfg";
if (file_exists($cfgfile)) {
$info = get_port($cfgfile);
$rooturl = "http://" . getHostByName(gethostname()) . ":" . $info ;
$url = $rooturl . "/STATUSALL";
// Initiate curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
$data = json_decode($result,true);
///Count
$total=count($data);
echo '<div>Number command:'.$total.'<br/>';
echo "<table>";
echo "<tr><th>Command</th><th>Start</th><th>Stop</th><th>State</th><th>Log</th></tr>";
ksort($data);
foreach ($data as $key => $value)
{
if ( $value == 'started' ) {
$fond = "bgcolor=\"SpringGreen \"";
} else {
$fond = "bgcolor=\"Tomato\"";
}
list($type, $command) = explode(':', $key, 2);
echo "<tr><td>$command</td><td><button onclick=\"start('$rooturl', '$key')\">Start</button></td><td><button onclick=\"stop('$rooturl', '$key')\">Stop</button></td><td $fond>$value</td><td><a href=\"/opennelmanager_log.php?command=$key\">log</a></td></tr>";
}
echo "</table></div>";
} else {
echo "<a>OpenNelManager not used</a>";
}
} else {
echo "<a>OpenNelManager not actiavted</a>";
}
?>
</p>
<div>
Command line :
<div id='command_shell'>
curl -XGET <?php print $url;?>
</div>
</div>
<p id="info"></p>
<p>Refresh : <button id="refreshMsg" size="10" onclick="toggleRefresh();"/>10s</button></p>
</body>
</html>