diff --git a/app/.env.sample b/app/.env.sample index 2d2e5d6..4bd80ba 100644 --- a/app/.env.sample +++ b/app/.env.sample @@ -1,43 +1,44 @@ -# Arquivo de exemplo para configuração de variáveis de ambiente -# Copie este arquivo para .env e ajuste os valores conforme necessário +# Sample file for environment variable configuration +# Copy this file to .env and adjust the values as needed -# Nome do site exibido no cabeçalho e meta tags -SITE_NAME=Marreta +# Site name displayed in the header and meta tags +SITE_NAME=Marreta -# Descrição do site usada em meta tags e SEO -SITE_DESCRIPTION="Chapéu de paywall é marreta!" +# Site description used in meta tags and SEO +SITE_DESCRIPTION="Chapéu de paywall é marreta!" -# Idioma do site (opções disponíveis: pt-br, en, es, de-de) -# pt-br = Português do Brasil -# en = English -# es = Español -# de-de = German -LANGUAGE=pt-br +# Site language (available options: pt-br, en, es, de-de, ru-ru) +# pt-br = Brazilian Portuguese +# en = English +# es = Spanish +# de-de = German +# ru-ru = Russian +LANGUAGE=pt-br -# URL base do site (sem barra no final) -# Use https://localhost para desenvolvimento local -SITE_URL=https://localhost +# Base URL of the site (without a trailing slash) +# Use https://localhost for local development +SITE_URL=https://localhost -# Lista de servidores DNS para resolução de domínios -# Recomendado: AdGuard DNS (94.140.14.14, 94.140.15.15) -DNS_SERVERS='94.140.14.14,94.140.15.15' +# List of DNS servers for domain resolution +# Recommended: AdGuard DNS (94.140.14.14, 94.140.15.15) +DNS_SERVERS='94.140.14.14,94.140.15.15' -# Modo sem cache (true/false) -# Quando ativo, desativa o cache do sistema -DISABLE_CACHE=false +# Disable cache mode (true/false) +# When enabled, system caching is turned off +DISABLE_CACHE=false -# Configurações de Cache S3 -S3_CACHE_ENABLED=false -S3_ACCESS_KEY= -S3_SECRET_KEY= -S3_BUCKET= -S3_REGION=us-east-1 -S3_FOLDER=cache/ -S3_ACL=private -S3_ENDPOINT= +# S3 Cache Settings +S3_CACHE_ENABLED=false +S3_ACCESS_KEY= +S3_SECRET_KEY= +S3_BUCKET= +S3_REGION=us-east-1 +S3_FOLDER=cache/ +S3_ACL=private +S3_ENDPOINT= -# Configurações do Selenium -SELENIUM_HOST=localhost:4444 +# Selenium Configuration +SELENIUM_HOST=localhost:4444 -# Configurações de Debug -DEBUG=true \ No newline at end of file +# Debug Settings +DEBUG=false diff --git a/app/src/Router.php b/app/src/Router.php index 3f8c527..1155998 100644 --- a/app/src/Router.php +++ b/app/src/Router.php @@ -7,39 +7,24 @@ require_once __DIR__ . '/../vendor/autoload.php'; use FastRoute; /** - * Classe Router - Gerenciador de rotas da aplicação * Router Class - Application route manager - * - * Esta classe implementa o sistema de roteamento usando FastRoute para: - * - Gerenciar todas as rotas da aplicação - * - Processar requisições HTTP - * - Direcionar para os manipuladores apropriados - * - * This class implements the routing system using FastRoute to: - * - Manage all application routes - * - Process HTTP requests - * - Direct to appropriate handlers + * Manages all application routes, processes HTTP requests, and directs to appropriate handlers */ class Router { /** - * Instância do dispatcher do FastRoute - * FastRoute dispatcher instance + * @var FastRoute\Dispatcher FastRoute dispatcher instance */ private $dispatcher; /** - * Construtor - Inicializa as rotas da aplicação * Constructor - Initializes application routes */ public function __construct() { $this->dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) { - // Rota principal - página inicial // Main route - home page $r->addRoute(['GET','POST'], '/', function() { - // Inicialização das variáveis para a view principal - // Initialize variables for the main view require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../inc/Cache.php'; require_once __DIR__ . '/../inc/Language.php'; @@ -71,7 +56,6 @@ class Router } } - // Inicializa o cache para contagem // Initialize cache for counting $cache = new \Cache(); $cache_folder = $cache->getCacheFileCount(); @@ -79,21 +63,18 @@ class Router require __DIR__ . '/views/home.php'; }); - // Rota da API - usa URLProcessor em modo API // API route - uses URLProcessor in API mode $r->addRoute('GET', '/api/{url:.+}', function($vars) { $processor = new URLProcessor($this->sanitizeUrl($vars['url']), true); $processor->process(); }); - // Rota da API sem parâmetros - redireciona para raiz // API route without parameters - redirects to root $r->addRoute('GET', '/api[/]', function() { header('Location: /'); exit; }); - // Rota de processamento - usa URLProcessor em modo web // Processing route - uses URLProcessor in web mode $r->addRoute('GET', '/p/{url:.+}', function($vars) { $processor = new URLProcessor($this->sanitizeUrl($vars['url']), false); @@ -103,11 +84,9 @@ class Router // Processing route with query parameter or without parameters $r->addRoute('GET', '/p[/]', function() { if (isset($_GET['url']) || isset($_GET['text'])) { - // Sanitize input parameters $url = isset($_GET['url']) ? $this->sanitizeUrl($_GET['url']) : ''; $text = isset($_GET['text']) ? $this->sanitizeUrl($_GET['text']) : ''; - // Check which parameter is a valid URL if (filter_var($url, FILTER_VALIDATE_URL)) { header('Location: /p/' . $url); exit; @@ -123,7 +102,6 @@ class Router exit; }); - // Rota do manifesto PWA - inclui manifest.php existente // PWA manifest route - includes existing manifest.php $r->addRoute('GET', '/manifest.json', function() { require __DIR__ . '/views/manifest.php'; @@ -131,17 +109,8 @@ class Router }); } - /** - * Sanitizes URLs to prevent XSS and injection attacks - * Sanitiza URLs para prevenir ataques XSS e injeções - * - * @param string $url The URL to sanitize - * @return string The sanitized URL - */ /** * Sanitizes and normalizes URLs - * Sanitiza e normaliza URLs - * * @param string $url The URL to sanitize and normalize * @return string|false The cleaned URL or false if invalid */ @@ -181,11 +150,9 @@ class Router /** * Sets security headers for all responses - * Define cabeçalhos de segurança para todas as respostas */ private function setSecurityHeaders() { - // Set security headers header("X-Content-Type-Options: nosniff"); header("X-Frame-Options: DENY"); header("X-XSS-Protection: 1; mode=block"); @@ -201,7 +168,6 @@ class Router $httpMethod = $_SERVER['REQUEST_METHOD']; $uri = $_SERVER['REQUEST_URI']; - // Remove a query string mas mantém para processamento // Strip query string but keep for processing $queryString = ''; if (false !== $pos = strpos($uri, '?')) { @@ -235,4 +201,4 @@ class Router break; } } -} +} \ No newline at end of file diff --git a/app/src/URLProcessor.php b/app/src/URLProcessor.php index 4d662b3..f2005c3 100644 --- a/app/src/URLProcessor.php +++ b/app/src/URLProcessor.php @@ -4,13 +4,7 @@ namespace App; /** * URL Processor - * Processador de URLs - * - * This class combines the functionality of the previous p.php and api.php files - * to provide a unified interface for URL processing, handling both web and API responses. - * - * Esta classe combina as funcionalidades dos arquivos p.php e api.php anteriores - * para fornecer uma interface unificada para processamento de URLs, tratando respostas web e API. + * Combines functionality for URL processing, handling both web and API responses */ class URLProcessor { @@ -20,8 +14,6 @@ class URLProcessor /** * Constructor - initializes the processor with URL and mode - * Construtor - inicializa o processador com URL e modo - * * @param string $url The URL to process * @param bool $isApi Whether to return API response */ @@ -36,10 +28,7 @@ class URLProcessor $this->analyzer = new \URLAnalyzer(); if ($isApi) { - // Initialize language system for API responses \Language::init(LANGUAGE); - - // Set API headers header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET'); @@ -48,7 +37,6 @@ class URLProcessor /** * Sends a JSON response for API requests - * Envia uma resposta JSON para requisições API */ private function sendApiResponse(array $data, int $statusCode = 200): void { @@ -67,7 +55,6 @@ class URLProcessor /** * Handles web redirects - * Trata redirecionamentos web */ private function redirect(string $path, string $message = ''): void { @@ -78,7 +65,6 @@ class URLProcessor /** * Process the URL and return appropriate response - * Processa a URL e retorna resposta apropriada */ public function process(): void { @@ -106,7 +92,6 @@ class URLProcessor $additionalInfo = $e->getAdditionalInfo(); if ($this->isApi) { - // Add error headers for API responses header('X-Error-Type: ' . $errorType); if ($additionalInfo) { header('X-Error-Info: ' . $additionalInfo); @@ -120,7 +105,6 @@ class URLProcessor ] ], $e->getCode()); } else { - // Handle blocked domain with redirect URL for web responses if ($errorType === \URLAnalyzer::ERROR_BLOCKED_DOMAIN && $additionalInfo) { $this->redirect(trim($additionalInfo), $errorType); } @@ -139,4 +123,4 @@ class URLProcessor } } } -} +} \ No newline at end of file diff --git a/app/src/views/manifest.php b/app/src/views/manifest.php index c5820c6..62f51a8 100644 --- a/app/src/views/manifest.php +++ b/app/src/views/manifest.php @@ -1,12 +1,7 @@ 'ltr' ]; -echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); +echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); \ No newline at end of file