vers. 2.6.0

This commit is contained in:
2026-07-14 04:33:26 +02:00
parent 42eebc9484
commit 189a9114ff
10 changed files with 964 additions and 169 deletions
+57 -36
View File
@@ -4,10 +4,6 @@ header('Content-Type: text/html; charset=UTF-8');
// File: config/getPage.inc.php
// Whitelist delle pagine valide
$validPages = ['home', 'radio', 'tv', 'play', 'playtv', 'page', 'podcast'];
$validSubPages = ['about', 'contact', 'copyright', 'termini-condizioni', 'policy-privacy', 'changelog'];
// Rileva se l'utente sta usando un dispositivo mobile
function isMobile() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
@@ -18,8 +14,7 @@ function sanitizePageInput($input) {
// Rimuovi caratteri pericolosi
$input = preg_replace('/[^a-zA-Z0-9\-_]/', '', $input);
// Previeni path traversal
$input = str_replace(['..', '/', '\\'], '', $input);
return $input;
return str_replace(['..', '/', '\\'], '', $input);
}
// Recupera l'URL richiesto
@@ -40,45 +35,71 @@ if (isset($path_parts[0]) && $path_parts[0] == 'index.php') {
array_shift($path_parts);
}
// Determina la pagina da mostrare in base all'URL con validazione
$page = 'home'; // Default sicuro
// Determina la pagina e il parametro iniziale
$page = 'home';
$param = '';
if (isset($path_parts[0]) && !empty($path_parts[0])) {
$requestedPage = sanitizePageInput($path_parts[0]);
// Verifica se la pagina è nella whitelist
if (in_array($requestedPage, $validPages)) {
$page = $requestedPage;
} else {
// Pagina non valida, redirect a 404
$page = 'home';
error_log("Tentativo di accesso a pagina non valida: " . $path_parts[0]);
}
$page = sanitizePageInput($path_parts[0]);
}
if (isset($path_parts[1]) && !empty($path_parts[1])) {
$requestedParam = sanitizePageInput($path_parts[1]);
// Validazione specifica per tipo di pagina
if ($page === 'play' || $page === 'playtv') {
// Per play/playtv, il parametro deve essere un numero
if (ctype_digit($requestedParam)) {
$param = $requestedParam;
} else {
error_log("ID stazione non valido: " . $path_parts[1]);
$page = 'home';
$param = sanitizePageInput($path_parts[1]);
}
/**
* Risolve dinamicamente il percorso del file PHP corrispondente alla pagina e al parametro.
* Cerca automaticamente i file all'interno della cartella './pages/page/'.
* Se la pagina non esiste, restituisce il file di errore 404.
*/
function getPageFilePath($page, $param) {
$page = sanitizePageInput($page);
$param = sanitizePageInput($param);
// Gestione stazioni radio e TV (player)
if ($page === 'play') {
if (ctype_digit($param)) {
return './pages/page/player.php';
}
} elseif ($page === 'page') {
// Per page, il parametro deve essere nella whitelist
if (in_array($requestedParam, $validSubPages)) {
$param = $requestedParam;
} else {
error_log("Sottopagina non valida: " . $path_parts[1]);
$page = 'home';
return './pages/page/404.php';
}
if ($page === 'playtv') {
if (ctype_digit($param)) {
return './pages/page/player_tv.php';
}
return './pages/page/404.php';
}
// Gestione sottopagine generiche /page/{param}
if ($page === 'page' && !empty($param)) {
$param_no_dash = str_replace('-', '', $param);
$paths = [
"./pages/page/{$param}.php",
"./pages/page/{$param_no_dash}.php"
];
foreach ($paths as $path) {
if (file_exists($path)) {
return $path;
}
}
return './pages/page/404.php';
}
// Gestione pagine principali (es: /home, /radio, /tv, /podcast)
$page_no_dash = str_replace('-', '', $page);
$paths = [
"./pages/page/{$page}.php",
"./pages/page/{$page_no_dash}.php"
];
foreach ($paths as $path) {
if (file_exists($path)) {
return $path;
}
}
return './pages/page/404.php';
}
// Debug (rimuovi in produzione)
error_log("Page: $page, Param: $param, Path: $path");
error_log("Page resolved: $page, Param: $param, Path resolved file: " . getPageFilePath($page, $param));