minecraft-minder/minecraft.php
2023-01-26 23:15:40 +00:00

48 lines
1.1 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 ($_GET['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 ($_GET['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 ($_GET['action'] == "status") {
$out = `curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID"`;
} else {
echo "Invalid action.";
}
$json = json_decode($out, true);
if ($json['action']) {
echo $json['action']['status'];
} elseif ($json['droplet']) {
echo $json['droplet']['status'];
}