Adding a demo mode via a empty file '.demo' into root.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
config.json
|
config.json
|
||||||
|
.demo
|
||||||
data/
|
data/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$config_path = __DIR__ . '/config.json';
|
$config_path = __DIR__ . '/config.json';
|
||||||
|
$demo_mode = file_exists(__DIR__ . '/.demo');
|
||||||
|
|
||||||
// Automatically migrate the legacy config format.
|
// Automatically migrate the legacy config format.
|
||||||
if (file_exists($config_path)) {
|
if (file_exists($config_path)) {
|
||||||
@@ -41,7 +42,9 @@ $error = '';
|
|||||||
$new_key = '';
|
$new_key = '';
|
||||||
|
|
||||||
if (!$is_first_setup) {
|
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) {
|
if (trim($_POST['admin_key_input']) === $admin_key) {
|
||||||
$mode = 'setup';
|
$mode = 'setup';
|
||||||
} else {
|
} else {
|
||||||
@@ -61,6 +64,9 @@ if (!$is_first_setup) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($mode === 'setup' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['group_name'])) {
|
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'] ?? '');
|
$group_name = trim($_POST['group_name'] ?? '');
|
||||||
$allow_personal_epg = isset($_POST['allow_personal_epg']);
|
$allow_personal_epg = isset($_POST['allow_personal_epg']);
|
||||||
|
|
||||||
@@ -107,6 +113,7 @@ if ($mode === 'setup' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$prefill_group = $_POST['group_name'] ?? $existing['group_name'] ?? '';
|
$prefill_group = $_POST['group_name'] ?? $existing['group_name'] ?? '';
|
||||||
@@ -182,12 +189,19 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
|
|||||||
.lock-form input{flex:1;}
|
.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{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;}
|
.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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="setup-card">
|
<div class="setup-card">
|
||||||
<div class="setup-logo">Grid<span>/</span>TV</div>
|
<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'): ?>
|
<?php if ($mode === 'lock'): ?>
|
||||||
<div class="setup-subtitle">Enter your admin key to access the configuration.</div>
|
<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; ?>
|
<?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: ?>
|
<?php else: ?>
|
||||||
<div class="setup-subtitle">
|
<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>
|
</div>
|
||||||
<?php if ($error): ?><div class="alert alert-error"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
<?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): ?>
|
<?php if (!$is_first_setup): ?>
|
||||||
<input type="hidden" name="admin_key_hidden" value="<?= htmlspecialchars($submitted_key ?: $admin_key) ?>">
|
<input type="hidden" name="admin_key_hidden" value="<?= htmlspecialchars($submitted_key ?: $admin_key) ?>">
|
||||||
<?php endif; ?>
|
<?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">
|
<div class="form-group">
|
||||||
<label>TV Group Name <span class="required">*</span></label>
|
<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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if (!$demo_mode): ?>
|
||||||
<button type="submit" class="btn-submit">Save configuration</button>
|
<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>
|
</form>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
+5
-1
@@ -3,6 +3,10 @@
|
|||||||
require_once __DIR__ . '/common.php';
|
require_once __DIR__ . '/common.php';
|
||||||
|
|
||||||
function gridtv_require_admin(array $config, string $page_title = 'Admin'): array {
|
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) {
|
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
@@ -12,7 +16,7 @@ function gridtv_require_admin(array $config, string $page_title = 'Admin'): arra
|
|||||||
$error = '';
|
$error = '';
|
||||||
|
|
||||||
if ($admin_key !== '' && hash_equals($admin_key, (string) $session_key)) {
|
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'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['admin_key_input'])) {
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ function gridtv_config_path(): string {
|
|||||||
return dirname(__DIR__, 2) . '/config.json';
|
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 {
|
function gridtv_load_config(): array {
|
||||||
$config_path = gridtv_config_path();
|
$config_path = gridtv_config_path();
|
||||||
if (!file_exists($config_path)) {
|
if (!file_exists($config_path)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user