ver. 2.1.1
This commit is contained in:
@@ -1,84 +1,84 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// File: config/getPage.inc.php
|
||||
|
||||
// Whitelist delle pagine valide
|
||||
$validPages = ['home', 'radio', 'tv', 'play', 'playtv', 'page'];
|
||||
$validSubPages = ['about', 'contact', 'copyright', 'addradio', '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"]);
|
||||
}
|
||||
|
||||
// Funzione per sanitizzare l'input
|
||||
function sanitizePageInput($input) {
|
||||
// Rimuovi caratteri pericolosi
|
||||
$input = preg_replace('/[^a-zA-Z0-9\-_]/', '', $input);
|
||||
// Previeni path traversal
|
||||
$input = str_replace(['..', '/', '\\'], '', $input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
// Recupera l'URL richiesto
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$path = substr(urldecode($request_uri), strlen($base_path));
|
||||
$path = parse_url($path, PHP_URL_PATH);
|
||||
$path = trim($path, '/');
|
||||
|
||||
// Rimuovi parametri GET dall'URL se presenti
|
||||
if (strpos($path, '?') !== false) {
|
||||
$path = substr($path, 0, strpos($path, '?'));
|
||||
}
|
||||
|
||||
$path_parts = explode('/', $path);
|
||||
|
||||
// Rimuovi index.php dall'URL se presente
|
||||
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
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
} 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Debug (rimuovi in produzione)
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// File: config/getPage.inc.php
|
||||
|
||||
// Whitelist delle pagine valide
|
||||
$validPages = ['home', 'radio', 'tv', 'play', 'playtv', 'page'];
|
||||
$validSubPages = ['about', 'contact', 'copyright', 'addradio', '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"]);
|
||||
}
|
||||
|
||||
// Funzione per sanitizzare l'input
|
||||
function sanitizePageInput($input) {
|
||||
// Rimuovi caratteri pericolosi
|
||||
$input = preg_replace('/[^a-zA-Z0-9\-_]/', '', $input);
|
||||
// Previeni path traversal
|
||||
$input = str_replace(['..', '/', '\\'], '', $input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
// Recupera l'URL richiesto
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$path = substr(urldecode($request_uri), strlen($base_path));
|
||||
$path = parse_url($path, PHP_URL_PATH);
|
||||
$path = trim($path, '/');
|
||||
|
||||
// Rimuovi parametri GET dall'URL se presenti
|
||||
if (strpos($path, '?') !== false) {
|
||||
$path = substr($path, 0, strpos($path, '?'));
|
||||
}
|
||||
|
||||
$path_parts = explode('/', $path);
|
||||
|
||||
// Rimuovi index.php dall'URL se presente
|
||||
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
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
} 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Debug (rimuovi in produzione)
|
||||
error_log("Page: $page, Param: $param, Path: $path");
|
||||
Reference in New Issue
Block a user