97 lines
3.3 KiB
PHP
97 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Spacetraders configuration page.
|
|
*
|
|
* @package SpacetradersAPI
|
|
* @author Keith Solomon <keith@keithsolomon.net>
|
|
* @license MIT License
|
|
* @version GIT: <git_id>
|
|
* @link https://git.keithsolomon.net/keith/Spacetraders
|
|
*/
|
|
|
|
require_once __DIR__ . '/lib/spacetraders-storage.php';
|
|
|
|
$config = require __DIR__ . '/lib/project-config.php';
|
|
|
|
$storage = new SpacetradersStorage( $config['db_path'] );
|
|
$token = $storage->getAgentToken();
|
|
$statusMessage = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' ) {
|
|
if (isset( $_POST['agent_token'] ) ) {
|
|
$submittedToken = trim( (string) $_POST['agent_token'] );
|
|
if ($submittedToken !== '' ) {
|
|
$storage->setAgentToken( $submittedToken );
|
|
$token = $submittedToken;
|
|
$statusMessage = 'Agent token saved to SQLite settings.';
|
|
}
|
|
}
|
|
|
|
if (isset( $_POST['clear_cache'] ) ) {
|
|
$storage->clearAllCache();
|
|
$statusMessage = 'API cache cleared.';
|
|
}
|
|
}
|
|
|
|
if (! is_string( $token ) || trim( $token ) === '') {
|
|
$envToken = getenv( 'SPACETRADERS_TOKEN' );
|
|
|
|
if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
|
|
$token = trim( $envToken );
|
|
$storage->setAgentToken( $token );
|
|
$statusMessage = 'Agent token imported from SPACETRADERS_TOKEN and saved.';
|
|
}
|
|
}
|
|
|
|
$hasToken = is_string( $token ) && trim( $token ) !== '';
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Spacetraders - Configuration</title>
|
|
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
</head>
|
|
|
|
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
|
|
<?php require __DIR__ . '/main-menu.php'; ?>
|
|
|
|
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="config.php">Spacetraders - Configuration</a></h1>
|
|
|
|
<div class="mb-6 border border-gray-600 p-4 rounded">
|
|
<p class="mb-2 text-sm text-gray-300">
|
|
API responses are cached in SQLite for
|
|
<?php echo htmlspecialchars( (string) ( (int) $config['cache_ttl'] / 60 ) ); ?> minutes.
|
|
</p>
|
|
|
|
<?php if ($statusMessage !== '' ) : ?>
|
|
<p class="mb-3 text-green-300"><?php echo htmlspecialchars( $statusMessage ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<?php if (! $hasToken ) : ?>
|
|
<p class="mb-3 text-yellow-300">No token is currently stored.</p>
|
|
<?php else : ?>
|
|
<p class="mb-3 text-green-300">Token is configured.</p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" class="flex flex-wrap gap-3 items-end">
|
|
<div>
|
|
<label for="agent_token" class="block text-sm mb-1">Agent Token</label>
|
|
<input
|
|
id="agent_token"
|
|
name="agent_token"
|
|
type="password"
|
|
class="px-3 py-2 rounded text-black w-96"
|
|
placeholder="Paste your Spacetraders token"
|
|
>
|
|
</div>
|
|
<button type="submit" class="px-4 py-2 bg-blue-600 rounded hover:bg-blue-500">Save Token</button>
|
|
<button type="submit" name="clear_cache" value="1" class="px-4 py-2 bg-gray-600 rounded hover:bg-gray-500">Clear Cache</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|