Update for AWS
This commit is contained in:
@@ -1,47 +1,35 @@
|
||||
<?php
|
||||
|
||||
$DIGITALOCEAN_TOKEN="dop_your_digitalocean_token_here";
|
||||
$DROPLET_ID="your_droplet_id_here";
|
||||
$REGION="us-west-1"; // change as needed
|
||||
$INSTANCE_ID="your_instance_id_here";
|
||||
$PASSWORD="your_password_here";
|
||||
|
||||
if ($_GET['password'] !== $PASSWORD) {
|
||||
usleep(rand(0,999999));
|
||||
exit("Invalid password.");
|
||||
}
|
||||
|
||||
if ($_POST['action'] == "on") {
|
||||
|
||||
$out = `curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
-d '{"type":"power_on"}' \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"`;
|
||||
$out = `aws ec2 start-instances --region=$REGION --instance-id $INSTANCE_ID 2>&1`;
|
||||
|
||||
} elseif ($_POST['action'] == "off") {
|
||||
|
||||
$out = `curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
|
||||
-d '{"type":"power_off"}' \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"`;
|
||||
$out = `aws ec2 stop-instances --region=$REGION --instance-id $INSTANCE_ID`;
|
||||
|
||||
} elseif ($_POST['action'] == "status") {
|
||||
|
||||
$out = `curl -X GET \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID"`;
|
||||
$out = `aws ec2 describe-instance-status --region=$REGION --include-all-instances --instance-id $INSTANCE_ID`;
|
||||
|
||||
}
|
||||
|
||||
if ($out) {
|
||||
$json = json_decode($out, true);
|
||||
|
||||
if ($json['action']) {
|
||||
$status = $json['action']['status'];
|
||||
} elseif ($json['droplet']) {
|
||||
$status = $json['droplet']['status'];
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +37,32 @@ if ($out) {
|
||||
<head><title>MineCollective Minecraft Server</title></head>
|
||||
<body>
|
||||
<p>
|
||||
Press this button to turn on the server. It'll take up to 5 minutes to boot, and turn off
|
||||
after about 30 minutes of inactivity.
|
||||
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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user