Retire clé export et ajoute demo

This commit is contained in:
Johnnybegood90
2026-03-15 03:08:16 +01:00
parent 16abfab05b
commit bdf3b4797d
4 changed files with 34 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
config.json
.demo
data/
.DS_Store
+20 -2
View File
@@ -1,5 +1,6 @@
<?php
$config_path = __DIR__ . '/config.json';
$demo_mode = file_exists(__DIR__ . '/.demo');
// Automatically migrate the legacy config format.
if (file_exists($config_path)) {
@@ -41,7 +42,9 @@ $error = '';
$new_key = '';
if (!$is_first_setup) {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['admin_key_input'])) {
if ($demo_mode) {
$mode = 'setup';
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['admin_key_input'])) {
if (trim($_POST['admin_key_input']) === $admin_key) {
$mode = 'setup';
} else {
@@ -61,6 +64,9 @@ if (!$is_first_setup) {
}
if ($mode === 'setup' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['group_name'])) {
if ($demo_mode) {
$error = 'Demo mode is enabled. Configuration is read-only on this instance.';
} else {
$group_name = trim($_POST['group_name'] ?? '');
$allow_personal_epg = isset($_POST['allow_personal_epg']);
@@ -108,6 +114,7 @@ if ($mode === 'setup' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['
}
}
}
}
$prefill_group = $_POST['group_name'] ?? $existing['group_name'] ?? '';
$prefill_sources = $existing['epg_sources'] ?? [];
@@ -182,12 +189,19 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
.lock-form input{flex:1;}
.setup-note{margin-top:28px;padding-top:20px;border-top:1px solid var(--border);font-size:11px;color:var(--text-dim);line-height:1.6;}
.setup-note code{font-family:'Share Tech Mono',monospace;background:var(--surface2);padding:1px 5px;border:1px solid var(--border);color:var(--accent2);font-size:11px;}
.demo-banner{padding:12px 14px;font-size:13px;margin-bottom:24px;line-height:1.5;border-left:3px solid var(--accent2);background:rgba(74,158,255,.08);color:var(--text-bright);}
.readonly-wrap{opacity:.82;}
.readonly-hint{margin-top:12px;font-size:12px;color:var(--text-dim);line-height:1.5;}
</style>
</head>
<body>
<div class="setup-card">
<div class="setup-logo">Grid<span>/</span>TV</div>
<?php if ($demo_mode): ?>
<div class="demo-banner">Demo mode is enabled on this instance. Visitors can view the current configuration, but saving changes is disabled.</div>
<?php endif; ?>
<?php if ($mode === 'lock'): ?>
<div class="setup-subtitle">Enter your admin key to access the configuration.</div>
<?php if ($error): ?><div class="alert alert-error"><?= htmlspecialchars($error) ?></div><?php endif; ?>
@@ -219,7 +233,7 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
<?php else: ?>
<div class="setup-subtitle">
<?= $is_first_setup ? 'Welcome to GridTV. Fill in the fields below to get started.' : 'Edit your GridTV configuration.' ?>
<?= $is_first_setup ? 'Welcome to GridTV. Fill in the fields below to get started.' : ($demo_mode ? 'View the current GridTV configuration.' : 'Edit your GridTV configuration.') ?>
</div>
<?php if ($error): ?><div class="alert alert-error"><?= htmlspecialchars($error) ?></div><?php endif; ?>
@@ -227,6 +241,7 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
<?php if (!$is_first_setup): ?>
<input type="hidden" name="admin_key_hidden" value="<?= htmlspecialchars($submitted_key ?: $admin_key) ?>">
<?php endif; ?>
<?php if ($demo_mode): ?><div class="readonly-wrap"><fieldset disabled style="border:none;padding:0;margin:0"><?php endif; ?>
<div class="form-group">
<label>TV Group Name <span class="required">*</span></label>
@@ -274,7 +289,10 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
</label>
</div>
<?php if (!$demo_mode): ?>
<button type="submit" class="btn-submit">Save configuration</button>
<?php endif; ?>
<?php if ($demo_mode): ?></fieldset></div><div class="readonly-hint">Saving is disabled in demo mode. Remove the <code>.demo</code> file on the server to restore normal editing.</div><?php endif; ?>
</form>
<?php endif; ?>
+5 -1
View File
@@ -3,6 +3,10 @@
require_once __DIR__ . '/common.php';
function gridtv_require_admin(array $config, string $page_title = 'Admin'): array {
if (gridtv_is_demo_mode()) {
return ['unlocked' => true, 'error' => '', 'demo' => true];
}
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
@@ -12,7 +16,7 @@ function gridtv_require_admin(array $config, string $page_title = 'Admin'): arra
$error = '';
if ($admin_key !== '' && hash_equals($admin_key, (string) $session_key)) {
return ['unlocked' => true, 'error' => ''];
return ['unlocked' => true, 'error' => '', 'demo' => false];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['admin_key_input'])) {
+8
View File
@@ -4,6 +4,14 @@ function gridtv_config_path(): string {
return dirname(__DIR__, 2) . '/config.json';
}
function gridtv_demo_path(): string {
return dirname(__DIR__, 2) . '/.demo';
}
function gridtv_is_demo_mode(): bool {
return file_exists(gridtv_demo_path());
}
function gridtv_load_config(): array {
$config_path = gridtv_config_path();
if (!file_exists($config_path)) {