From 37529a0c01688d0659c1a0da77faffa6a3156c25 Mon Sep 17 00:00:00 2001 From: zyphlar Date: Sun, 29 Jan 2023 22:37:59 +0000 Subject: [PATCH] Update status and licensing --- mineautoshutdown.sh | 15 +++++++ minecraft.php | 95 +++++++++++++++++++++++++++++++++++++-------- minestatus.py | 15 +++++++ 3 files changed, 108 insertions(+), 17 deletions(-) diff --git a/mineautoshutdown.sh b/mineautoshutdown.sh index 56193a2..1a40476 100755 --- a/mineautoshutdown.sh +++ b/mineautoshutdown.sh @@ -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 . +# DO_STATUS_URL="http://example.com/minecraft.php" PASSWORD="your_password_here" diff --git a/minecraft.php b/minecraft.php index 9310d76..6500170 100644 --- a/minecraft.php +++ b/minecraft.php @@ -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) { } } -?> -MineCollective Minecraft Server +?> + + + Minecraft Server Control + Minecraft-Minder + +

Press this button to turn on the server. It'll take a couple minutes to fully turn on, @@ -44,25 +92,38 @@ if ($out) { +
Current status: - -$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']; + - diff --git a/minestatus.py b/minestatus.py index 340b2b7..45c2ca0 100644 --- a/minestatus.py +++ b/minestatus.py @@ -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 . +# from mcstatus import JavaServer import json