45 lines
926 B
PHP
45 lines
926 B
PHP
<?php
|
|
header('Content-Type: text/plain');
|
|
|
|
// Only allow GET requests
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
http_response_code(405);
|
|
die('Method not allowed');
|
|
}
|
|
|
|
$file_path = '../server_state.txt';
|
|
|
|
// Check if file exists
|
|
if (!file_exists($file_path)) {
|
|
// Return default state if file doesn't exist
|
|
echo '0';
|
|
exit;
|
|
}
|
|
|
|
// Check if file is readable
|
|
if (!is_readable($file_path)) {
|
|
http_response_code(500);
|
|
die('Cannot read state file');
|
|
}
|
|
|
|
$state = file_get_contents($file_path);
|
|
|
|
// Validate the stored state
|
|
if ($state === false) {
|
|
http_response_code(500);
|
|
die('Failed to read state');
|
|
}
|
|
|
|
// Clean the state (remove any whitespace)
|
|
$state = trim($state);
|
|
|
|
// Validate what we read from the file
|
|
if (!in_array($state, ['0', '1'], true)) {
|
|
// File was corrupted somehow, reset to default
|
|
file_put_contents($file_path, '0', LOCK_EX);
|
|
echo '0';
|
|
exit;
|
|
}
|
|
|
|
echo $state;
|
|
?>
|