69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
$REGION="us-west-1"; // change as needed
|
|
$INSTANCE_ID="your_instance_id_here";
|
|
$PASSWORD="your_password_here";
|
|
if ($_POST['action'] == "on") {
|
|
|
|
$out = `aws ec2 start-instances --region=$REGION --instance-id $INSTANCE_ID 2>&1`;
|
|
|
|
} elseif ($_POST['action'] == "off") {
|
|
|
|
$out = `aws ec2 stop-instances --region=$REGION --instance-id $INSTANCE_ID`;
|
|
|
|
} elseif ($_POST['action'] == "status") {
|
|
|
|
$out = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID`;
|
|
|
|
}
|
|
|
|
if ($out) {
|
|
$json = json_decode($out, true);
|
|
|
|
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']);
|
|
}
|
|
}
|
|
|
|
?><html>
|
|
<head><title>MineCollective Minecraft Server</title></head>
|
|
<body>
|
|
<p>
|
|
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.
|
|
</p>
|
|
<form action="#" method="POST">
|
|
<input type="hidden" name="action" value="on" />
|
|
<input type="submit" value="Turn On" />
|
|
</form>
|
|
<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>
|
|
</body>
|
|
</html>
|
|
|