initial switch commit

This commit is contained in:
dangrubbb
2025-07-16 15:34:57 -04:00
parent 9b24e45c65
commit cf6d8fc2c2
4 changed files with 230 additions and 1 deletions

45
php/get_state.php Normal file
View File

@ -0,0 +1,45 @@
<?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;
?>