minecraft-minder/minecraft.php
zyphlar 6d22b4d999 Update 3 files
- /minecraft.php
- /README.md
- /mineautoshutdown.sh
2023-01-27 01:21:18 +00:00

61 lines
1.5 KiB
PHP

<?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") {
$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") {
$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"`;
} 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"`;
}
if ($out) {
$json = json_decode($out, true);
if ($json['action']) {
$status = $json['action']['status'];
} elseif ($json['droplet']) {
$status = $json['droplet']['status'];
}
}
?><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>