From 76dbd18ca7b86aba80be7190ec7406f96c51308e Mon Sep 17 00:00:00 2001 From: Johnnybegood90 Date: Fri, 13 Mar 2026 21:24:51 +0100 Subject: [PATCH] Feat: Reconfigure in setup.php --- setup.php | 442 ++++++++++++++++++++++++------------------------------ 1 file changed, 192 insertions(+), 250 deletions(-) diff --git a/setup.php b/setup.php index 5867366..2358d11 100644 --- a/setup.php +++ b/setup.php @@ -1,10 +1,9 @@ 'Main', @@ -15,18 +14,40 @@ if (file_exists($config_path)) { unset($existing['epg_url'], $existing['m3u_url']); file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } - http_response_code(403); - die('Configuration déjà effectuée. Modifiez config.json via SSH pour changer les paramètres.'); } -$error = ''; -$success = false; +$is_first_setup = !file_exists($config_path); +$existing = $is_first_setup ? [] : json_decode(file_get_contents($config_path), true); +$admin_key = $existing['admin_key'] ?? null; -if ($_SERVER['REQUEST_METHOD'] === 'POST') { +$mode = 'setup'; +$error = ''; +$new_key = ''; + +if (!$is_first_setup) { + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['admin_key_input'])) { + if (trim($_POST['admin_key_input']) === $admin_key) { + $mode = 'setup'; + } else { + $mode = 'lock'; + $error = 'Invalid admin key.'; + } + } elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['group_name'])) { + if (trim($_POST['admin_key_hidden'] ?? '') !== $admin_key) { + $mode = 'lock'; + $error = 'Invalid admin key.'; + } else { + $mode = 'setup'; + } + } else { + $mode = 'lock'; + } +} + +if ($mode === 'setup' && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['group_name'])) { $group_name = trim($_POST['group_name'] ?? ''); $allow_personal_epg = isset($_POST['allow_personal_epg']); - // Récupérer les sources EPG dynamiques $names = $_POST['source_name'] ?? []; $epg_urls = $_POST['source_epg_url'] ?? []; $m3u_urls = $_POST['source_m3u_url'] ?? []; @@ -37,13 +58,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $m3u_url = trim($m3u_urls[$i] ?? ''); if (empty($epg_url)) continue; if (!filter_var($epg_url, FILTER_VALIDATE_URL)) { - $error = "URL EPG invalide pour la source « $name »."; break; + $error = "Invalid EPG URL for source \"$name\"."; break; } if (!empty($m3u_url) && !filter_var($m3u_url, FILTER_VALIDATE_URL)) { - $error = "URL M3U invalide pour la source « $name »."; break; + $error = "Invalid M3U URL for source \"$name\"."; break; } $epg_sources[] = [ - 'name' => trim($name) ?: "Source " . ($i + 1), + 'name' => trim($name) ?: 'Source ' . ($i + 1), 'epg_url' => $epg_url, 'm3u_url' => $m3u_url, ]; @@ -51,303 +72,224 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($error)) { if (empty($group_name)) { - $error = 'Le nom du groupe est obligatoire.'; + $error = 'Group name is required.'; } elseif (empty($epg_sources)) { - $error = 'Au moins une source EPG est obligatoire.'; + $error = 'At least one EPG source is required.'; } else { - $config = [ + $new_key = $is_first_setup ? strtoupper(bin2hex(random_bytes(8))) : $admin_key; + $config = [ 'group_name' => $group_name, 'epg_sources' => $epg_sources, 'allow_personal_epg' => $allow_personal_epg, + 'admin_key' => $new_key, ]; - $written = file_put_contents( - $config_path, - json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) - ); + $written = file_put_contents($config_path, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); if ($written === false) { - $error = 'Impossible d\'écrire config.json. Vérifiez les permissions (chmod 775 .).'; + $error = 'Cannot write config.json. Check permissions (chmod 775 .).'; } else { - $success = true; + $mode = 'success'; } } } } + +$prefill_group = $_POST['group_name'] ?? $existing['group_name'] ?? ''; +$prefill_sources = $existing['epg_sources'] ?? []; +$prefill_epg = !empty($existing['allow_personal_epg']); +$submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden'] ?? ''); ?> - + -GridTV — Configuration +GridTV — Setup
- -
- Bienvenue sur GridTV — votre guide TV IPTV.
- Configurez votre instance en remplissant les champs ci-dessous. -
- -
- + +
Enter your admin key to access the configuration.
+
+
+
🔒
+
Configuration locked
+
GridTV is already configured.
Enter your admin key to edit the settings.
+
+
+ + +
+
+
- -
- ✓ Configuration enregistrée dans config.json.
- Cette page ne sera plus accessible. Pour modifier la config, éditez config.json via SSH. -
-
- Ouvrir GridTV → + +
Configuration saved successfully.
+
✓ Settings saved to config.json.
+ +
+
Your admin key
+
+
Save this key now. It will not be shown again.
You will need it to access this setup page in the future.
+ +
Your admin key is unchanged.
+ + + - -
- -
- - -
S'affiche en haut à gauche dans la topbar.
+
+
+
-
Sources EPG
+ + + + -
-
-
SOURCE 1
- -
-
- - -
-
- - -
-
- - -
Utilisé par le lecteur intégré pour matcher les chaînes.
+
+ + +
Displayed top-left in the topbar.
+
+ +
EPG Sources
+
+ 'Main','epg_url'=>'','m3u_url'=>'']]; + foreach ($sources_to_show as $i => $src): ?> +
+
SOURCE
+ +
+
+ + +
+
+ + +
+
+ + +
Used by the built-in player to match channels to streams.
+
+
-
+ - - -
Options
- -
-
- Autoriser les EPG personnels - Les visiteurs peuvent utiliser votre instance avec leur propre EPG/M3U. +
Options
+
+
+ Allow personal EPG + Visitors can use your instance with their own EPG/M3U URLs. +
+
- -
- - - + +
- Note : La configuration est stockée dans config.json sur le serveur. - Ce fichier est exclu du dépôt Git (.gitignore). - Pour modifier les paramètres ultérieurement, éditez ce fichier directement via SSH. + Note: Configuration is stored in config.json on the server. + This file is excluded from the Git repository (.gitignore).
-