minecraft-minder/minecraft.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2023-01-26 23:15:40 +00:00
<?php
$DIGITALOCEAN_TOKEN="dop_your_digitalocean_token_here";
$DROPLET_ID="your_droplet_id_here";
$PASSWORD="your_password_here";
if ($_GET['password'] !== $PASSWORD) {
usleep(rand(0,999999));
exit("Invalid password.");
}
if ($_POST['action'] == "on") {
2023-01-26 23:15:40 +00:00
$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"`;
} elseif ($_POST['action'] == "off") {
2023-01-26 23:15:40 +00:00
$out = `curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
2023-01-26 23:15:40 +00:00
-d '{"type":"power_off"}' \
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"`;
} elseif ($_POST['action'] == "status") {
2023-01-26 23:15:40 +00:00
$out = `curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID"`;
}
if ($out) {
$json = json_decode($out, true);
2023-01-26 23:15:40 +00:00
if ($json['action']) {
$status = $json['action']['status'];
} elseif ($json['droplet']) {
$status = $json['droplet']['status'];
}
2023-01-26 23:15:40 +00:00
}
?><html>
<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.
</p>
<form action="#" method="POST">
<input type="hidden" name="action" value="on" />
<input type="submit" value="Turn On" />
</form>
</body>
</html>