✨feature: Initial info gathering
This commit is contained in:
94
config.php
Normal file
94
config.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Spacetraders configuration page.
|
||||
*
|
||||
* @package Spacetraders
|
||||
* @author Keith Solomon <keith@keithsolomon.net>
|
||||
* @license MIT License
|
||||
* @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">
|
||||
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Spacetraders Configuration</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>
|
||||
|
||||
<a href="agent-info.php" class="text-blue-400 hover:underline">Back to Agent Info</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user