Update status and licensing

This commit is contained in:
Will Bradley 2023-01-29 22:37:59 +00:00
parent 98e610704e
commit 37529a0c01
3 changed files with 108 additions and 17 deletions

View File

@ -1,4 +1,19 @@
#!/bin/bash
# Copyright (C) 2023 zyphlar
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
DO_STATUS_URL="http://example.com/minecraft.php"
PASSWORD="your_password_here"

View File

@ -13,10 +13,26 @@ if ($_POST['action'] == "on") {
} elseif ($_POST['action'] == "status") {
$out = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID`;
$status = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID 2>&1`;
$json = json_decode($status, true);
$statusOut = $json['InstanceStatuses'][0]['InstanceState']['Name'];
if ($json['InstanceStatuses'][0]['InstanceState']['Name'] == "running") {
$players = `python3 /var/minecraft/minestatus.py 2>&1`;
$json = json_decode($players, true);
if ($json['players'] !== null) {
$statusOut .= " with ".$json['players']." players";
} else {
$statusOut .= " but not reachable yet.";
}
}
exit($statusOut);
}
if ($out) {
$json = json_decode($out, true);
@ -33,8 +49,40 @@ if ($out) {
}
}
?><html>
<head><title>MineCollective Minecraft Server</title></head>
?><!DOCTYPE html><html>
<!--
Copyright (C) 2023 zyphlar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<head>
<title>Minecraft Server Control</title>
<meta name="generator">Minecraft-Minder</meta>
<style type="text/css">
@keyframes spinning {
from { transform: rotate(360deg) }
to { transform: rotate(0deg) }
}
.spin {
animation-name: spinning;
animation-duration: 3s;
animation-iteration-count: infinite;
/* linear | ease | ease-in | ease-out | ease-in-out */
animation-timing-function: linear;
}
</style>
</head>
<body>
<p>
Press this button to turn on the server. It'll take a couple minutes to fully turn on,
@ -44,25 +92,38 @@ if ($out) {
<input type="hidden" name="action" value="on" />
<input type="submit" value="Turn On" />
</form>
<br/>
<b>Current status:</b>
<i><?php
<i id="statusOut"></i><svg id="spinner" class="spin" style="display:none; height: 1em; margin-left: 1em;" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve"><g><path d="M355.1,137.7C355.1,67.2,412.3,10,482.9,10c70.5,0,127.7,57.2,127.7,127.7c0,70.5-57.2,127.7-127.7,127.7C412.3,265.4,355.1,208.3,355.1,137.7z M761.2,520.9L761.2,520.9c0-57.9,46.9-104.8,104.8-104.8S970.8,463,970.8,520.9l0,0c0,57.9-46.9,104.8-104.8,104.8S761.2,578.8,761.2,520.9z M658.9,791.8c0-52.4,42.5-94.9,94.9-94.9c52.4,0,94.9,42.5,94.9,94.9c0,52.4-42.5,94.9-94.9,94.9C701.4,886.7,658.9,844.2,658.9,791.8z M396.9,904c0-47.5,38.5-86,86-86s86,38.5,86,86c0,47.5-38.5,86-86,86S396.9,951.5,396.9,904L396.9,904z M134.1,791.8c0-43,34.9-77.8,77.8-77.8c43,0,77.8,34.9,77.8,77.8c0,43-34.9,77.8-77.8,77.8C168.9,869.7,134.1,834.8,134.1,791.8z M29.2,520.9c0-38.9,31.6-70.5,70.5-70.5c38.9,0,70.5,31.6,70.5,70.5s-31.6,70.5-70.5,70.5C60.8,591.4,29.2,559.8,29.2,520.9z M148.1,250L148.1,250c0-35.3,28.6-63.9,63.9-63.9c35.3,0,63.9,28.6,63.9,63.9l0,0c0,35.3-28.6,63.9-63.9,63.9C176.7,313.8,148.1,285.2,148.1,250z M869.5,250c0,63.9-51.8,115.7-115.7,115.7S638.1,313.8,638.1,250s51.8-115.7,115.7-115.7C817.7,134.3,869.5,186.1,869.5,250z"/></g></svg>
$status = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID 2>&1`;
$json = json_decode($status, true);
echo $json['InstanceStatuses'][0]['InstanceState']['Name'];
<script>
function loadStatus(){
document.getElementById("spinner").style.display = "inline";
let url = document.location;
const formData = new FormData();
formData.append('action', 'status');
let options = {
method: "POST",
body: formData
}
fetch(url, options)
.then(res => res.text())
.then(body => {
console.log('Checkout this resp: ', body);
document.getElementById("statusOut").innerText = body;
document.getElementById("spinner").style.display = "none";
})
.catch(err => { throw err });
if ($json['InstanceStatuses'][0]['InstanceState']['Name'] == "running") {
$players = `python3 /var/minecraft/minestatus.py 2>&1`;
$json = json_decode($players, true);
if ($json['players'] !== null) {
echo " with ".$json['players']." players";
} else {
echo " but not reachable yet.";
}
}
setInterval(function(){ loadStatus(); }, 30000);
loadStatus();
?></i>
</script>
</body>
</html>

View File

@ -1,3 +1,18 @@
# Copyright (C) 2023 zyphlar
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from mcstatus import JavaServer
import json