<?php
// ===== CONFIG =====
$statusFile = __DIR__ . '/gateway_status.txt';

// ===== READ STATUS =====
if (!file_exists($statusFile)) {
    file_put_contents($statusFile, 'OFF');
}

$currentStatus = trim(file_get_contents($statusFile));

// ===== TOGGLE STATUS =====
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $newStatus = ($currentStatus === 'ON') ? 'OFF' : 'ON';
    file_put_contents($statusFile, $newStatus);
    header("Location: " . $_SERVER['PHP_SELF']);
    exit;
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>API Gateway Status</title>
</head>
<body style="font-family: Arial; text-align: center; margin-top: 100px;">

    <h2>API Gateway</h2>

    <p>
        Current Status:
        <strong style="color: <?php echo ($currentStatus === 'ON') ? 'green' : 'red'; ?>">
            <?php echo $currentStatus; ?>
        </strong>
    </p>

    <form method="post">
        <button type="submit" style="padding: 10px 20px; font-size: 16px;">
            Toggle Status
        </button>
    </form>

</body>
</html>
