2023-01-26 23:15:40 +00:00
|
|
|
<?php
|
|
|
|
|
2023-01-27 08:32:24 +00:00
|
|
|
$REGION="us-west-1"; // change as needed
|
|
|
|
$INSTANCE_ID="your_instance_id_here";
|
2023-01-26 23:15:40 +00:00
|
|
|
$PASSWORD="your_password_here";
|
2023-01-27 01:21:18 +00:00
|
|
|
if ($_POST['action'] == "on") {
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 08:32:24 +00:00
|
|
|
$out = `aws ec2 start-instances --region=$REGION --instance-id $INSTANCE_ID 2>&1`;
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 01:21:18 +00:00
|
|
|
} elseif ($_POST['action'] == "off") {
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 08:32:24 +00:00
|
|
|
$out = `aws ec2 stop-instances --region=$REGION --instance-id $INSTANCE_ID`;
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 01:21:18 +00:00
|
|
|
} elseif ($_POST['action'] == "status") {
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 08:32:24 +00:00
|
|
|
$out = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID`;
|
2023-01-26 23:15:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-27 01:21:18 +00:00
|
|
|
if ($out) {
|
|
|
|
$json = json_decode($out, true);
|
2023-01-26 23:15:40 +00:00
|
|
|
|
2023-01-27 08:32:24 +00:00
|
|
|
if ($_POST['action'] == "on") {
|
|
|
|
echo "<a href='javascript:history.back()'>Go back</a><br/><br/><b>Result:</b> ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($json['StartingInstances']) {
|
|
|
|
exit($json['StartingInstances'][0]['CurrentState']['Name']);
|
|
|
|
} elseif ($json['StoppingInstances']) {
|
|
|
|
exit($json['StoppingInstances'][0]['CurrentState']['Name']);
|
|
|
|
} elseif ($json['InstanceStatuses']) {
|
|
|
|
exit($json['InstanceStatuses'][0]['InstanceState']['Name']);
|
2023-01-27 01:21:18 +00:00
|
|
|
}
|
2023-01-26 23:15:40 +00:00
|
|
|
}
|
2023-01-27 01:21:18 +00:00
|
|
|
|
|
|
|
?><html>
|
|
|
|
<head><title>MineCollective Minecraft Server</title></head>
|
|
|
|
<body>
|
|
|
|
<p>
|
2023-01-27 08:32:24 +00:00
|
|
|
Press this button to turn on the server. It'll take a couple minutes to fully turn on,
|
|
|
|
and it'll turn off automatically after about 30 minutes of inactivity.
|
2023-01-27 01:21:18 +00:00
|
|
|
</p>
|
|
|
|
<form action="#" method="POST">
|
|
|
|
<input type="hidden" name="action" value="on" />
|
|
|
|
<input type="submit" value="Turn On" />
|
|
|
|
</form>
|
2023-01-27 08:32:24 +00:00
|
|
|
<b>Current status:</b>
|
|
|
|
<i><?php
|
|
|
|
|
|
|
|
$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'];
|
|
|
|
|
|
|
|
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.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?></i>
|
2023-01-27 01:21:18 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
2023-01-27 08:32:24 +00:00
|
|
|
|