From bdf3b4797d29261a0e16f27cd5ada1b2a1a26ecd Mon Sep 17 00:00:00 2001 From: Johnnybegood90 Date: Sun, 15 Mar 2026 03:08:16 +0100 Subject: [PATCH] =?UTF-8?q?Retire=20cl=C3=A9=20export=20et=20ajoute=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + setup.php | 22 ++++++++++++++++++++-- src/lib/admin.php | 6 +++++- src/lib/common.php | 8 ++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f5a083b..497cd73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.json +.demo data/ .DS_Store diff --git a/setup.php b/setup.php index 1f5a4fa..ec21324 100644 --- a/setup.php +++ b/setup.php @@ -1,5 +1,6 @@
+ +
Demo mode is enabled on this instance. Visitors can view the current configuration, but saving changes is disabled.
+ +
Enter your admin key to access the configuration.
@@ -219,7 +233,7 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
- +
@@ -227,6 +241,7 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden'] +
@@ -274,7 +289,10 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
+ + +
Saving is disabled in demo mode. Remove the .demo file on the server to restore normal editing.
diff --git a/src/lib/admin.php b/src/lib/admin.php index 4c14170..c969a86 100644 --- a/src/lib/admin.php +++ b/src/lib/admin.php @@ -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'])) { diff --git a/src/lib/common.php b/src/lib/common.php index 00db619..388d72b 100644 --- a/src/lib/common.php +++ b/src/lib/common.php @@ -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)) {