mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-04-18 04:39:09 +00:00
simplificação de documentação
This commit is contained in:
parent
d9ef063243
commit
1f5fb428a3
19 changed files with 252 additions and 693 deletions
50
.gitignore
vendored
50
.gitignore
vendored
|
@ -6,46 +6,18 @@ app/cache/*.gz
|
|||
TODO.md
|
||||
node_modules
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/composer,windows,macos,linux
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=composer,windows,macos,linux
|
||||
|
||||
### Composer ###
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
# composer.lock
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
|
@ -53,42 +25,22 @@ Icon
|
|||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### macOS Patch ###
|
||||
# iCloud generated files
|
||||
*.icloud
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/composer,windows,macos,linux
|
||||
*.lnk
|
11
Dockerfile
11
Dockerfile
|
@ -1,7 +1,6 @@
|
|||
FROM php:8.3-fpm
|
||||
|
||||
# Install PHP dependencies and extensions
|
||||
# Instala dependências e extensões do PHP
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nginx \
|
||||
nano \
|
||||
|
@ -16,32 +15,30 @@ RUN apt-get update && apt-get install -y \
|
|||
&& docker-php-ext-enable redis opcache
|
||||
|
||||
# Copy OPCache configuration
|
||||
# Copia a configuração do OPCache
|
||||
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini
|
||||
|
||||
# Install Composer
|
||||
# Instala o Composer
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
RUN curl -sS https: //getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
# Copy webservice configuration
|
||||
# Copia a configuração do webservice
|
||||
COPY default.conf /etc/nginx/sites-available/default
|
||||
|
||||
# Create and copy app folder
|
||||
RUN mkdir -p /app
|
||||
COPY app/ /app/
|
||||
|
||||
# Install composer packages
|
||||
WORKDIR /app
|
||||
RUN composer install --no-interaction --optimize-autoloader
|
||||
|
||||
# Copy and configure initialization script permissions
|
||||
# Copia e configura permissões do script de inicialização
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Create cache and logs folders
|
||||
RUN mkdir -p /app/cache /app/logs
|
||||
|
||||
# Configure base permissions for /app directory
|
||||
# Configura permissões base para o diretório /app
|
||||
RUN chown -R www-data:www-data /app \
|
||||
&& chmod -R 755 /app
|
||||
|
||||
|
|
|
@ -1,84 +1,56 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Main configuration file
|
||||
* Arquivo de configuração principal
|
||||
*
|
||||
* This file contains all global system settings, including:
|
||||
* Este arquivo contém todas as configurações globais do sistema, incluindo:
|
||||
*
|
||||
* - Environment variables loading / Carregamento de variáveis de ambiente
|
||||
* - System constants definition / Definições de constantes do sistema
|
||||
* - Security settings / Configurações de segurança
|
||||
* - Bot and user agent settings / Configurações de bots e user agents
|
||||
* - Blocked domains list / Lista de domínios bloqueados
|
||||
* - S3 cache settings / Configurações de cache S3
|
||||
* System configuration manager
|
||||
* - Loads and validates environment variables
|
||||
* - Defines global constants for system settings
|
||||
* - Manages security rules and external service configs
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
try {
|
||||
// Initialize environment variables
|
||||
// Inicializa as variáveis de ambiente
|
||||
// Load environment variables
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
// Validate required fields
|
||||
// Valida campos obrigatórios
|
||||
$dotenv->required([
|
||||
'SITE_NAME',
|
||||
'SITE_DESCRIPTION',
|
||||
'SITE_URL'
|
||||
])->notEmpty();
|
||||
|
||||
// Custom URL validation
|
||||
// Validação personalizada de URL
|
||||
// Validate URL format
|
||||
if (!filter_var($_ENV['SITE_URL'], FILTER_VALIDATE_URL)) {
|
||||
throw new Exception('SITE_URL must be a valid URL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic system settings
|
||||
* Configurações básicas do sistema
|
||||
*/
|
||||
// Core system settings
|
||||
define('SITE_NAME', $_ENV['SITE_NAME']);
|
||||
define('SITE_DESCRIPTION', $_ENV['SITE_DESCRIPTION']);
|
||||
define('SITE_URL', $_ENV['SITE_URL']);
|
||||
|
||||
// Optional settings with default values
|
||||
// Configurações opcionais com valores padrão
|
||||
// Optional settings with defaults
|
||||
define('DNS_SERVERS', $_ENV['DNS_SERVERS'] ?? '1.1.1.1, 8.8.8.8');
|
||||
define('DISABLE_CACHE', isset($_ENV['DISABLE_CACHE']) ?
|
||||
filter_var($_ENV['DISABLE_CACHE'], FILTER_VALIDATE_BOOLEAN) : false);
|
||||
define('DISABLE_CACHE', isset($_ENV['DISABLE_CACHE']) ? filter_var($_ENV['DISABLE_CACHE'], FILTER_VALIDATE_BOOLEAN) : false);
|
||||
define('SELENIUM_HOST', $_ENV['SELENIUM_HOST'] ?? 'localhost:4444');
|
||||
define('CACHE_DIR', __DIR__ . '/cache');
|
||||
define('LANGUAGE', $_ENV['LANGUAGE'] ?? 'pt-br');
|
||||
|
||||
/**
|
||||
* Redis settings
|
||||
* Configurações do Redis
|
||||
*/
|
||||
// Redis connection settings
|
||||
define('REDIS_HOST', $_ENV['REDIS_HOST'] ?? 'localhost');
|
||||
define('REDIS_PORT', $_ENV['REDIS_PORT'] ?? 6379);
|
||||
define('REDIS_PREFIX', $_ENV['REDIS_PREFIX'] ?? 'marreta:');
|
||||
|
||||
/**
|
||||
* Logging settings
|
||||
* Configurações de log
|
||||
*/
|
||||
define('LOG_LEVEL', $_ENV['LOG_LEVEL'] ?? 'WARNING'); // Available: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
// Logging configuration
|
||||
define('LOG_LEVEL', $_ENV['LOG_LEVEL'] ?? 'WARNING'); // DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
define('LOG_DAYS_TO_KEEP', 7);
|
||||
|
||||
/**
|
||||
* S3 Cache settings
|
||||
* Configurações de Cache S3
|
||||
*/
|
||||
define('S3_CACHE_ENABLED', isset($_ENV['S3_CACHE_ENABLED']) ?
|
||||
filter_var($_ENV['S3_CACHE_ENABLED'], FILTER_VALIDATE_BOOLEAN) : false);
|
||||
// S3 cache configuration
|
||||
define('S3_CACHE_ENABLED', isset($_ENV['S3_CACHE_ENABLED']) ? filter_var($_ENV['S3_CACHE_ENABLED'], FILTER_VALIDATE_BOOLEAN) : false);
|
||||
|
||||
if (S3_CACHE_ENABLED) {
|
||||
// Validate required S3 settings when S3 cache is enabled
|
||||
// Valida configurações obrigatórias do S3 quando o cache S3 está ativado
|
||||
$dotenv->required([
|
||||
'S3_ACCESS_KEY',
|
||||
'S3_SECRET_KEY',
|
||||
|
@ -94,10 +66,7 @@ try {
|
|||
define('S3_ENDPOINT', $_ENV['S3_ENDPOINT'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load system configurations
|
||||
* Carrega as configurações do sistema
|
||||
*/
|
||||
// Load security rules
|
||||
define('BLOCKED_DOMAINS', require __DIR__ . '/data/blocked_domains.php');
|
||||
define('DOMAIN_RULES', require __DIR__ . '/data/domain_rules.php');
|
||||
define('GLOBAL_RULES', require __DIR__ . '/data/global_rules.php');
|
||||
|
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
/**
|
||||
* List of blocked domains
|
||||
* Lista de domínios bloqueados
|
||||
*
|
||||
* Defines domains that cannot be accessed by the system
|
||||
* due to usage policies or technical restrictions
|
||||
*
|
||||
* Define os domínios que não podem ser acessados pelo sistema
|
||||
* por questões de política de uso ou restrições técnicas
|
||||
*/
|
||||
return [
|
||||
// News sites / Sites de notícias
|
||||
//-- Content behind login access / Conteúdo fica atrás de um acesso de login
|
||||
// News sites
|
||||
//-- Content behind login access/hard paywall
|
||||
'wsj.com',
|
||||
'piaui.folha.uol.com.br',
|
||||
'economist.com',
|
||||
|
@ -31,14 +27,15 @@ return [
|
|||
'mittelbayerische.de',
|
||||
'josimarfootball.com',
|
||||
'nordsee-zeitung.de',
|
||||
//-- Technical access blocking / Bloqueio técnico de acesso ao conteúdo
|
||||
// List of common blocked sites to avoid unnecessary requests
|
||||
//-- Technical access blocking
|
||||
'bloomberg.com',
|
||||
'sportskeeda.com',
|
||||
'kansascity.com',
|
||||
'fastcompany.com',
|
||||
'expressnews.com',
|
||||
'nydailynews.com',
|
||||
// Tracking services / Serviços de rastreamento
|
||||
//-- Tracking services
|
||||
'metaffiliation.com',
|
||||
'google-analytics.com',
|
||||
'googletagmanager.com',
|
||||
|
@ -59,7 +56,7 @@ return [
|
|||
'fullstory.com',
|
||||
'heap.io',
|
||||
'clearbrain.com',
|
||||
// Social networks / Redes sociais
|
||||
//-- Social networks
|
||||
'facebook.com',
|
||||
'instagram.com',
|
||||
'twitter.com',
|
||||
|
@ -73,7 +70,7 @@ return [
|
|||
'redd.it',
|
||||
'bsky.app',
|
||||
'threads.net',
|
||||
// Streaming services / Serviços de streaming
|
||||
//-- Streaming services
|
||||
'netflix.com',
|
||||
'hulu.com',
|
||||
'disneyplus.com',
|
||||
|
@ -81,32 +78,32 @@ return [
|
|||
'spotify.com',
|
||||
'youtube.com',
|
||||
'twitch.tv',
|
||||
// E-commerce sites / Sites de comércio eletrônico
|
||||
//-- E-commerce sites
|
||||
'amazon.com',
|
||||
'ebay.com',
|
||||
'aliexpress.com',
|
||||
'mercadolivre.com.br',
|
||||
'shopify.com',
|
||||
// File sharing / Compartilhamento de arquivos
|
||||
//-- File sharing
|
||||
'mega.nz',
|
||||
'mediafire.com',
|
||||
'wetransfer.com',
|
||||
'dropbox.com',
|
||||
'torrent9.pe',
|
||||
'thepiratebay.org',
|
||||
// Adult sites / Sites adultos
|
||||
//-- Adult sites
|
||||
'pornhub.com',
|
||||
'xvideos.com',
|
||||
'xnxx.com',
|
||||
'onlyfans.com',
|
||||
'privacy.com.br',
|
||||
'fatalmodel.com',
|
||||
// Betting and gaming / Apostas e jogos
|
||||
//-- Betting and gaming
|
||||
'bet365.com',
|
||||
'betfair.com',
|
||||
'pokerstars.com',
|
||||
'casino.com',
|
||||
// Other popular sites / Outros sites populares
|
||||
//-- Other popular sites
|
||||
'github.com',
|
||||
'stackoverflow.com',
|
||||
'wikipedia.org',
|
||||
|
|
|
@ -2,38 +2,31 @@
|
|||
|
||||
/**
|
||||
* Specific rule configurations for individual domains
|
||||
* Configurações específicas de regras para domínios individuais
|
||||
*
|
||||
* This file contains custom rules for specific sites, allowing
|
||||
* system behavior adjustment for each domain individually.
|
||||
*
|
||||
* Este arquivo contém regras personalizadas para sites específicos, permitindo
|
||||
* ajustar o comportamento do sistema para cada domínio individualmente.
|
||||
*
|
||||
* Domain rule structure / Estrutura das regras por domínio:
|
||||
* - userAgent: Define custom User-Agent for the domain / Define um User-Agent personalizado para o domínio
|
||||
* - headers: Custom HTTP headers for requests / Headers HTTP personalizados para requisições
|
||||
* - idElementRemove: Array of HTML IDs to be removed / Array de IDs HTML que devem ser removidos da página
|
||||
* - classElementRemove: Array of HTML classes to be removed / Array de classes HTML que devem ser removidas
|
||||
* - scriptTagRemove: Array of scripts to be removed (partial match) / Array de scripts que devem ser removidos (partial match)
|
||||
* - cookies: Associative array of cookies to be set (null removes cookie) / Array associativo de cookies a serem definidos (null remove o cookie)
|
||||
* - classAttrRemove: Array of classes to be removed from elements / Array de classes a serem removidas de elementos
|
||||
* - customCode: String containing custom JavaScript code / String contendo código JavaScript personalizado
|
||||
* - customStyle: String containing custom CSS code / String contendo código CSS personalizado
|
||||
* - excludeGlobalRules: Associative array of global rules to exclude for this domain / Array associativo de regras globais a serem excluídas para este domínio
|
||||
* Example / Exemplo:
|
||||
* - userAgent: Define custom User-Agent for the domain
|
||||
* - headers: Custom HTTP headers for requests
|
||||
* - idElementRemove: Array of HTML IDs to be removed
|
||||
* - classElementRemove: Array of HTML classes to be removed
|
||||
* - scriptTagRemove: Array of scripts to be removed (partial match)
|
||||
* - cookies: Associative array of cookies to be set (null removes cookie)
|
||||
* - classAttrRemove: Array of classes to be removed from elements
|
||||
* - customCode: String containing custom JavaScript code
|
||||
* - customStyle: String containing custom CSS code
|
||||
* - excludeGlobalRules: Associative array of global rules to exclude for this domain
|
||||
* Example:
|
||||
* 'excludeGlobalRules' => [
|
||||
* 'scriptTagRemove' => ['gtm.js', 'ga.js'], // Excludes specific scripts from global rules / Exclui scripts específicos das regras globais
|
||||
* 'classElementRemove' => ['subscription'] // Excludes specific classes from global rules / Exclui classes específicas das regras globais
|
||||
* 'scriptTagRemove' => ['gtm.js', 'ga.js'],
|
||||
* 'classElementRemove' => ['subscription']
|
||||
* ]
|
||||
* - fetchStrategies: String indicating which fetch strategy to use. Available values: / String indicando qual estratégia de fetch usar. Valores disponíveis:
|
||||
* - fetchContent: Use standard fetch with domain rules / Usa fetch padrão com regras do domínio
|
||||
* - fetchFromWaybackMachine: Try to fetch from Internet Archive / Tenta buscar do Internet Archive
|
||||
* - fetchFromSelenium: Use Selenium for extraction / Usa Selenium para extração
|
||||
* - socialReferrers: Add random social media headers / Adiciona headers randomicos de redes sociais
|
||||
* - fromGoogleBot: Adds simulation of request coming from Google Bot / Adiciona simulação de requisição vinda do Google Bot
|
||||
* - removeElementsByTag: Remove specific elements via DOM / Remove elementos especificos via DOM
|
||||
* - removeCustomAttr: Remove custom attributes from elements / Remove custom attributes from elements
|
||||
* - fetchStrategies: String indicating which fetch strategy to use. Available values:
|
||||
* - fetchContent: Use standard fetch with domain rules
|
||||
* - fetchFromWaybackMachine: Try to fetch from Internet Archive
|
||||
* - fetchFromSelenium: Use Selenium for extraction
|
||||
* - socialReferrers: Add random social media headers
|
||||
* - fromGoogleBot: Adds simulation of request coming from Google Bot
|
||||
* - removeElementsByTag: Remove specific elements via DOM
|
||||
* - removeCustomAttr: Remove custom attributes from elements
|
||||
*/
|
||||
return [
|
||||
'nsctotal.com.br' => [
|
||||
|
|
|
@ -2,23 +2,12 @@
|
|||
|
||||
/**
|
||||
* Global rule configurations applied to all domains
|
||||
* Configurações globais de regras aplicadas a todos os domínios
|
||||
*
|
||||
* This file defines rules that are applied by default to all sites,
|
||||
* organized into categories for better maintenance and understanding.
|
||||
*
|
||||
* Este arquivo define regras que são aplicadas por padrão a todos os sites,
|
||||
* organizadas em categorias para melhor manutenção e compreensão.
|
||||
*
|
||||
* Note: These rules can be overridden or disabled for specific domains
|
||||
* using the 'excludeGlobalRules' configuration in domain_rules.php
|
||||
*
|
||||
* Nota: Estas regras podem ser sobrescritas ou desativadas para domínios específicos
|
||||
* usando a configuração 'excludeGlobalRules' em domain_rules.php
|
||||
*/
|
||||
return [
|
||||
// HTML classes to be removed from all pages
|
||||
// Classes HTML a serem removidas de todas as páginas
|
||||
// Classes to be removed from all pages:
|
||||
'classElementRemove' => [
|
||||
'subscription',
|
||||
'subscriber-content',
|
||||
|
@ -40,8 +29,7 @@ return [
|
|||
'signup-overlay',
|
||||
'onesignal-slidedown-container'
|
||||
],
|
||||
// Scripts to be removed from all pages
|
||||
// Scripts a serem removidos de todas as páginas
|
||||
// Scripts to be removed from all pages:
|
||||
'scriptTagRemove' => [
|
||||
'gtm.js',
|
||||
'ga.js',
|
||||
|
|
|
@ -6,48 +6,27 @@ use Inc\Cache\S3Storage;
|
|||
use Inc\Cache\RedisStorage;
|
||||
|
||||
/**
|
||||
* Class responsible for system cache management
|
||||
* Classe responsável pelo gerenciamento de cache do sistema
|
||||
*
|
||||
* This class implements functionalities to store and retrieve
|
||||
* cached content, supporting multiple storage backends (disk or S3).
|
||||
* The cache is organized by URLs converted to unique IDs using SHA-256.
|
||||
* Content is compressed using gzip to save space.
|
||||
*
|
||||
* Esta classe implementa funcionalidades para armazenar e recuperar
|
||||
* conteúdo em cache, suportando múltiplos backends de armazenamento (disco ou S3).
|
||||
* O cache é organizado por URLs convertidas em IDs únicos usando SHA-256.
|
||||
* O conteúdo é comprimido usando gzip para economizar espaço.
|
||||
* System cache management with multiple storage backends (disk/S3)
|
||||
* Uses SHA-256 hashed URLs as unique identifiers
|
||||
* Implements gzip compression for space efficiency
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
/**
|
||||
* @var CacheStorageInterface Storage implementation for cache
|
||||
* @var CacheStorageInterface Implementação de storage para o cache
|
||||
*/
|
||||
/** @var CacheStorageInterface Cache storage implementation */
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @var RedisStorage Redis instance for file counting
|
||||
* @var RedisStorage Instância do Redis para contagem de arquivos
|
||||
*/
|
||||
/** @var RedisStorage Redis instance for file counting */
|
||||
private $redisStorage;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Construtor da classe
|
||||
*
|
||||
* Initializes appropriate storage based on configuration
|
||||
* Inicializa o storage apropriado baseado na configuração
|
||||
* Initializes storage based on configuration
|
||||
* Uses S3Storage if configured and enabled
|
||||
* Defaults to DiskStorage otherwise
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Initialize RedisStorage for file counting
|
||||
// Inicializa o RedisStorage para contagem de arquivos
|
||||
$this->redisStorage = new RedisStorage(CACHE_DIR);
|
||||
|
||||
// If S3 is configured and active, use S3Storage
|
||||
// Se S3 está configurado e ativo, usa S3Storage
|
||||
if (defined('S3_CACHE_ENABLED') && S3_CACHE_ENABLED === true) {
|
||||
$this->storage = new S3Storage([
|
||||
'key' => S3_ACCESS_KEY,
|
||||
|
@ -59,51 +38,30 @@ class Cache
|
|||
'endpoint' => defined('S3_ENDPOINT') ? S3_ENDPOINT : null
|
||||
]);
|
||||
} else {
|
||||
// Otherwise, use disk storage
|
||||
// Caso contrário, usa o storage em disco
|
||||
$this->storage = new DiskStorage(CACHE_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the count of cached files
|
||||
* Obtém a contagem de arquivos em cache
|
||||
*
|
||||
* @return int Number of files in cache / Número de arquivos em cache
|
||||
*/
|
||||
/** Gets total number of cached files */
|
||||
public function getCacheFileCount(): int
|
||||
{
|
||||
return $this->redisStorage->countCacheFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique ID for a URL
|
||||
* Gera um ID único para uma URL
|
||||
*
|
||||
* @param string $url URL for which the ID will be generated / URL para qual será gerado o ID
|
||||
* @return string SHA-256 hash of the normalized URL / Hash SHA-256 da URL normalizada
|
||||
* Generates unique cache ID from URL
|
||||
* Normalizes URL by removing protocol and www
|
||||
* Returns SHA-256 hash of normalized URL
|
||||
*/
|
||||
public function generateId($url)
|
||||
{
|
||||
// Remove protocol and www
|
||||
// Remove protocolo e www
|
||||
$url = preg_replace('#^https?://(www\.)?#', '', $url);
|
||||
// Generate unique ID using SHA-256
|
||||
// Gera ID único usando SHA-256
|
||||
return hash('sha256', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if cache exists for a given URL
|
||||
* Verifica se existe cache para uma determinada URL
|
||||
*
|
||||
* @param string $url URL to check / URL a ser verificada
|
||||
* @return bool True if cache exists, False otherwise / True se existir cache, False caso contrário
|
||||
*/
|
||||
/** Checks if cached version exists for URL */
|
||||
public function exists($url)
|
||||
{
|
||||
// If DISABLE_CACHE is active, always return false
|
||||
// Se DISABLE_CACHE está ativo, sempre retorna false
|
||||
if (DISABLE_CACHE) {
|
||||
return false;
|
||||
}
|
||||
|
@ -111,17 +69,9 @@ class Cache
|
|||
return $this->storage->exists($this->generateId($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves cached content for a URL
|
||||
* Recupera o conteúdo em cache de uma URL
|
||||
*
|
||||
* @param string $url URL of the content to retrieve / URL do conteúdo a ser recuperado
|
||||
* @return string|null Cached content or null if it doesn't exist / Conteúdo em cache ou null se não existir
|
||||
*/
|
||||
/** Retrieves cached content for URL */
|
||||
public function get($url)
|
||||
{
|
||||
// If DISABLE_CACHE is active, always return null
|
||||
// Se DISABLE_CACHE está ativo, sempre retorna null
|
||||
if (DISABLE_CACHE) {
|
||||
return null;
|
||||
}
|
||||
|
@ -129,22 +79,13 @@ class Cache
|
|||
return $this->storage->get($this->generateId($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores content in cache for a URL
|
||||
* Armazena conteúdo em cache para uma URL
|
||||
*
|
||||
* @param string $url URL associated with the content / URL associada ao conteúdo
|
||||
* @param string $content Content to be cached / Conteúdo a ser armazenado em cache
|
||||
* @return bool True if cache was saved successfully, False otherwise / True se o cache foi salvo com sucesso, False caso contrário
|
||||
*/
|
||||
/** Stores content in cache for URL */
|
||||
public function set($url, $content)
|
||||
{
|
||||
// If DISABLE_CACHE is active, don't generate cache
|
||||
// Se DISABLE_CACHE está ativo, não gera cache
|
||||
if (DISABLE_CACHE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->storage->set($this->generateId($url), $content);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,39 +3,27 @@
|
|||
namespace Inc\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache storage implementations
|
||||
* Interface para implementações de armazenamento de cache
|
||||
*
|
||||
* This interface defines the required methods for any cache storage implementation.
|
||||
* Esta interface define os métodos necessários para qualquer implementação de armazenamento de cache.
|
||||
* Defines the contract for cache storage implementations
|
||||
*/
|
||||
interface CacheStorageInterface
|
||||
{
|
||||
/**
|
||||
* Checks if cache exists for a given ID
|
||||
* Verifica se existe cache para um determinado ID
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return bool True if cache exists, false otherwise / True se o cache existir, false caso contrário
|
||||
* Checks if cached content exists for given ID
|
||||
* @param string $id Unique cache identifier
|
||||
*/
|
||||
public function exists(string $id): bool;
|
||||
|
||||
/**
|
||||
* Retrieves cached content
|
||||
* Recupera o conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return string|null Cached content or null if not found / Conteúdo em cache ou null se não encontrado
|
||||
* Retrieves cached content by ID
|
||||
* @return string|null Cached content or null if missing
|
||||
*/
|
||||
public function get(string $id): ?string;
|
||||
|
||||
/**
|
||||
* Stores content in cache
|
||||
* Armazena conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @param string $content Content to be stored / Conteúdo a ser armazenado
|
||||
* @return bool True if successful, false otherwise / True se bem sucedido, false caso contrário
|
||||
* Stores content in cache with specified ID
|
||||
* @param string $id Cache entry identifier
|
||||
* @param string $content Content to store
|
||||
* @return bool Storage success status
|
||||
*/
|
||||
public function set(string $id, string $content): bool;
|
||||
}
|
||||
}
|
|
@ -3,25 +3,19 @@
|
|||
namespace Inc\Cache;
|
||||
|
||||
/**
|
||||
* Disk-based cache storage implementation
|
||||
* Implementação de armazenamento de cache em disco
|
||||
*
|
||||
* This class implements file-based caching using gzip compression
|
||||
* Esta classe implementa cache baseado em arquivos usando compressão gzip
|
||||
* Disk-based cache storage
|
||||
* Implements file-based caching using gzip compression
|
||||
*/
|
||||
class DiskStorage implements CacheStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var string Directory where cache files will be stored
|
||||
* @var string Diretório onde os arquivos de cache serão armazenados
|
||||
* @var string Directory for cache files
|
||||
*/
|
||||
private $cacheDir;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Construtor da classe
|
||||
*
|
||||
* @param string $cacheDir Base directory for cache storage / Diretório base para armazenamento do cache
|
||||
* @param string $cacheDir Base directory for cache storage
|
||||
*/
|
||||
public function __construct(string $cacheDir)
|
||||
{
|
||||
|
@ -33,10 +27,8 @@ class DiskStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Checks if cache exists for a given ID
|
||||
* Verifica se existe cache para um determinado ID
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return bool True if cache exists, false otherwise / True se o cache existir, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @return bool True if cache exists, false otherwise
|
||||
*/
|
||||
public function exists(string $id): bool
|
||||
{
|
||||
|
@ -46,10 +38,8 @@ class DiskStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Retrieves cached content
|
||||
* Recupera o conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return string|null Cached content or null if not found / Conteúdo em cache ou null se não encontrado
|
||||
* @param string $id Cache ID
|
||||
* @return string|null Cached content or null if not found
|
||||
*/
|
||||
public function get(string $id): ?string
|
||||
{
|
||||
|
@ -69,11 +59,9 @@ class DiskStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Stores content in cache
|
||||
* Armazena conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @param string $content Content to be stored / Conteúdo a ser armazenado
|
||||
* @return bool True if successful, false otherwise / True se bem sucedido, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @param string $content Content to be stored
|
||||
* @return bool True if successful, false otherwise
|
||||
*/
|
||||
public function set(string $id, string $content): bool
|
||||
{
|
||||
|
@ -86,4 +74,4 @@ class DiskStorage implements CacheStorageInterface
|
|||
|
||||
return file_put_contents($cachePath, $compressedContent) !== false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,77 +6,53 @@ use Redis;
|
|||
|
||||
/**
|
||||
* Redis-based cache storage implementation
|
||||
* Implementação de armazenamento de cache baseado em Redis
|
||||
*
|
||||
* This class provides cache storage and file counting functionality using Redis
|
||||
* Esta classe fornece armazenamento de cache e funcionalidade de contagem de arquivos usando Redis
|
||||
*
|
||||
* @property \Redis|null $redis Redis client instance
|
||||
* Provides cache storage and file counting functionality using Redis
|
||||
*/
|
||||
class RedisStorage implements CacheStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var \Redis|null Redis client instance
|
||||
* @var \Redis|null Instância do cliente Redis
|
||||
*/
|
||||
private $redis;
|
||||
|
||||
/**
|
||||
* @var string Cache directory for file counting
|
||||
* @var string Diretório de cache para contagem de arquivos
|
||||
*/
|
||||
private $cacheDir;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Construtor da classe
|
||||
*
|
||||
* @param string $cacheDir Base directory for cache storage / Diretório base para armazenamento do cache
|
||||
* @param string $cacheDir Base directory for cache storage
|
||||
*/
|
||||
public function __construct(string $cacheDir)
|
||||
{
|
||||
$this->cacheDir = $cacheDir;
|
||||
|
||||
// Try to initialize Redis connection
|
||||
// Tenta inicializar conexão Redis
|
||||
try {
|
||||
/** @var \Redis $redis */
|
||||
$this->redis = new \Redis();
|
||||
$this->redis->connect(REDIS_HOST, REDIS_PORT, 2.5);
|
||||
$this->redis->setOption(\Redis::OPT_PREFIX, REDIS_PREFIX);
|
||||
} catch (\Exception $e) {
|
||||
// If it fails, set redis to null
|
||||
// Se falhar, define redis como null
|
||||
$this->redis = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of files in the cache directory
|
||||
* Conta o número de arquivos no diretório de cache
|
||||
*
|
||||
* @return int Number of files in the cache directory / Número de arquivos no diretório de cache
|
||||
* @return int Number of files in the cache directory
|
||||
*/
|
||||
public function countCacheFiles(): int
|
||||
{
|
||||
// Key to store file count in Redis
|
||||
// Chave para armazenar a contagem de arquivos no Redis
|
||||
$cacheCountKey = 'cache_file_count';
|
||||
|
||||
// If Redis is available
|
||||
// Se Redis estiver disponível
|
||||
if ($this->redis !== null) {
|
||||
// Check if the key exists and has a value
|
||||
// Verifica se a chave existe e tem valor
|
||||
/** @var string|false $cachedCount */
|
||||
$cachedCount = $this->redis->get($cacheCountKey);
|
||||
if ($cachedCount !== false) {
|
||||
return (int)$cachedCount;
|
||||
}
|
||||
}
|
||||
|
||||
// If Redis is not available or key is empty, count .gz files
|
||||
// Se Redis não estiver disponível ou chave vazia, conta arquivos .gz
|
||||
$fileCount = 0;
|
||||
$iterator = new \FilesystemIterator($this->cacheDir);
|
||||
foreach ($iterator as $file) {
|
||||
|
@ -85,8 +61,6 @@ class RedisStorage implements CacheStorageInterface
|
|||
}
|
||||
}
|
||||
|
||||
// If Redis is available, save the count
|
||||
// Se Redis estiver disponível, salva a contagem
|
||||
if ($this->redis !== null) {
|
||||
$this->redis->set($cacheCountKey, $fileCount);
|
||||
}
|
||||
|
@ -96,9 +70,7 @@ class RedisStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Updates the file count in Redis
|
||||
* Atualiza a contagem de arquivos no Redis
|
||||
*
|
||||
* @param int $count Number of files / Número de arquivos
|
||||
* @param int $count Number of files
|
||||
*/
|
||||
public function updateCacheFileCount(int $count): void
|
||||
{
|
||||
|
@ -109,10 +81,8 @@ class RedisStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Checks if cache exists for a given ID
|
||||
* Verifica se existe cache para um determinado ID
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return bool True if cache exists, false otherwise / True se o cache existir, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @return bool True if cache exists, false otherwise
|
||||
*/
|
||||
public function exists(string $id): bool
|
||||
{
|
||||
|
@ -121,10 +91,8 @@ class RedisStorage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Retrieves cached content
|
||||
* Recupera o conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return string|null Cached content or null if not found / Conteúdo em cache ou null se não encontrado
|
||||
* @param string $id Cache ID
|
||||
* @return string|null Cached content or null if not found
|
||||
*/
|
||||
public function get(string $id): ?string
|
||||
{
|
||||
|
@ -132,40 +100,29 @@ class RedisStorage implements CacheStorageInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
/** @var string|false $content */
|
||||
$content = $this->redis->get($id);
|
||||
return $content === false ? null : $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores content in cache
|
||||
* Armazena conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @param string $content Content to be stored / Conteúdo a ser armazenado
|
||||
* @return bool True if successful, false otherwise / True se bem sucedido, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @param string $content Content to be stored
|
||||
* @return bool True if successful, false otherwise
|
||||
*/
|
||||
public function set(string $id, string $content): bool
|
||||
{
|
||||
// If Redis is not available, return false
|
||||
// Se Redis não estiver disponível, retorna false
|
||||
if ($this->redis === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// When saving a new file, update the count
|
||||
// Ao salvar um novo arquivo, atualiza a contagem
|
||||
/** @var bool $result */
|
||||
$result = $this->redis->set($id, $content);
|
||||
|
||||
if ($result) {
|
||||
// Increment file count in Redis
|
||||
// Incrementa a contagem de arquivos no Redis
|
||||
/** @var string|false $currentCount */
|
||||
$currentCount = $this->redis->get('cache_file_count') ?: 0;
|
||||
$this->redis->set('cache_file_count', $currentCount + 1);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,42 +7,33 @@ use Aws\Exception\AwsException;
|
|||
|
||||
/**
|
||||
* AWS S3-based cache storage implementation
|
||||
* Implementação de armazenamento de cache baseado em AWS S3
|
||||
*
|
||||
* This class provides cache storage functionality using Amazon S3 or compatible services
|
||||
* Esta classe fornece funcionalidade de armazenamento de cache usando Amazon S3 ou serviços compatíveis
|
||||
* Provides cache storage functionality using Amazon S3 or compatible services
|
||||
*/
|
||||
class S3Storage implements CacheStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var S3Client AWS S3 Client
|
||||
* @var S3Client Cliente AWS S3
|
||||
*/
|
||||
private $s3Client;
|
||||
|
||||
/**
|
||||
* @var string S3 bucket name
|
||||
* @var string Nome do bucket S3
|
||||
*/
|
||||
private $bucket;
|
||||
|
||||
/**
|
||||
* @var string Prefix for objects in the bucket (optional)
|
||||
* @var string Prefixo para os objetos no bucket (opcional)
|
||||
*/
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* @var string ACL for S3 objects
|
||||
* @var string ACL para os objetos no S3
|
||||
*/
|
||||
private $acl;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Construtor da classe
|
||||
*
|
||||
* @param array $config AWS S3 configuration / Configuração do AWS S3
|
||||
* @param array $config AWS S3 configuration
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
|
@ -56,11 +47,8 @@ class S3Storage implements CacheStorageInterface
|
|||
];
|
||||
|
||||
// Add custom endpoint if provided
|
||||
// Adiciona endpoint personalizado se fornecido
|
||||
if (!empty($config['endpoint'])) {
|
||||
$clientConfig['endpoint'] = $config['endpoint'];
|
||||
// Use path-style endpoints when a custom endpoint is provided
|
||||
// Use endpoints estilo path quando um endpoint personalizado é fornecido
|
||||
$clientConfig['use_path_style_endpoint'] = true;
|
||||
}
|
||||
|
||||
|
@ -73,10 +61,8 @@ class S3Storage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Generates the complete object key in S3
|
||||
* Gera a chave completa do objeto no S3
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return string Complete S3 object key / Chave completa do objeto no S3
|
||||
* @param string $id Cache ID
|
||||
* @return string Complete S3 object key
|
||||
*/
|
||||
private function getObjectKey(string $id): string
|
||||
{
|
||||
|
@ -85,10 +71,8 @@ class S3Storage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Checks if cache exists for a given ID
|
||||
* Verifica se existe cache para um determinado ID
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return bool True if cache exists, false otherwise / True se o cache existir, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @return bool True if cache exists, false otherwise
|
||||
*/
|
||||
public function exists(string $id): bool
|
||||
{
|
||||
|
@ -98,17 +82,14 @@ class S3Storage implements CacheStorageInterface
|
|||
$this->getObjectKey($id)
|
||||
);
|
||||
} catch (AwsException $e) {
|
||||
// Log error if needed / Registra erro se necessário
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves cached content
|
||||
* Recupera o conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @return string|null Cached content or null if not found / Conteúdo em cache ou null se não encontrado
|
||||
* @param string $id Cache ID
|
||||
* @return string|null Cached content or null if not found
|
||||
*/
|
||||
public function get(string $id): ?string
|
||||
{
|
||||
|
@ -136,11 +117,9 @@ class S3Storage implements CacheStorageInterface
|
|||
|
||||
/**
|
||||
* Stores content in cache
|
||||
* Armazena conteúdo em cache
|
||||
*
|
||||
* @param string $id Cache ID / ID do cache
|
||||
* @param string $content Content to be stored / Conteúdo a ser armazenado
|
||||
* @return bool True if successful, false otherwise / True se bem sucedido, false caso contrário
|
||||
* @param string $id Cache ID
|
||||
* @param string $content Content to be stored
|
||||
* @return bool True if successful, false otherwise
|
||||
*/
|
||||
public function set(string $id, string $content): bool
|
||||
{
|
||||
|
@ -156,13 +135,12 @@ class S3Storage implements CacheStorageInterface
|
|||
'Body' => $compressedContent,
|
||||
'ACL' => $this->acl,
|
||||
'ContentEncoding' => 'gzip',
|
||||
'CacheControl' => 'max-age=31536000' // 1 year / 1 ano
|
||||
'CacheControl' => 'max-age=31536000' // 1 year
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (AwsException $e) {
|
||||
// Log error if needed / Registra erro se necessário
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Language Management Class
|
||||
* Classe de Gerenciamento de Idiomas
|
||||
*
|
||||
* This class handles the loading and retrieval of language-specific strings
|
||||
* Esta classe lida com o carregamento e recuperação de strings específicas do idioma
|
||||
*
|
||||
* Features / Funcionalidades:
|
||||
* - Language initialization / Inicialização de idioma
|
||||
* - Translation retrieval / Recuperação de traduções
|
||||
* - Message handling / Manipulação de mensagens
|
||||
* - Fallback language support / Suporte a idioma de fallback
|
||||
* Manages language translations and localization
|
||||
* Loads language files based on system configuration
|
||||
* Provides fallback to default language on missing resources
|
||||
*/
|
||||
class Language {
|
||||
private static $translations = [];
|
||||
private static $currentLanguage = 'pt-br';
|
||||
|
||||
/**
|
||||
* Initialize the language system
|
||||
* Inicializa o sistema de idiomas
|
||||
*
|
||||
* @param string $language Language code (e.g., 'en', 'pt-br') / Código do idioma (ex: 'en', 'pt-br')
|
||||
* Initializes language resources
|
||||
* @param string $language ISO language code (e.g., 'en', 'pt-br')
|
||||
*/
|
||||
public static function init($language = 'pt-br') {
|
||||
self::$currentLanguage = strtolower($language);
|
||||
|
@ -30,31 +20,25 @@ class Language {
|
|||
if (file_exists($langFile)) {
|
||||
self::$translations = require $langFile;
|
||||
} else {
|
||||
// Fallback to pt-br if language file doesn't exist
|
||||
// Volta para pt-br se o arquivo de idioma não existir
|
||||
// Fallback to default language
|
||||
self::$currentLanguage = 'pt-br';
|
||||
self::$translations = require __DIR__ . '/../languages/pt-br.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a translation by key
|
||||
* Obtém uma tradução por chave
|
||||
*
|
||||
* @param string $key Translation key / Chave da tradução
|
||||
* @param string $default Default value if key not found / Valor padrão se a chave não for encontrada
|
||||
* @return string Translation text / Texto traduzido
|
||||
* Retrieves translation for specified key
|
||||
* @param string $key Translation identifier
|
||||
* @param string $default Fallback value if key not found
|
||||
*/
|
||||
public static function get($key, $default = '') {
|
||||
return self::$translations[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message by key
|
||||
* Obtém uma mensagem por chave
|
||||
*
|
||||
* @param string $key Message key / Chave da mensagem
|
||||
* @return array Message data (message and type) / Dados da mensagem (mensagem e tipo)
|
||||
* Gets structured message data
|
||||
* @param string $key Message identifier
|
||||
* @return array Message content and type
|
||||
*/
|
||||
public static function getMessage($key) {
|
||||
return self::$translations['messages'][$key] ?? [
|
||||
|
@ -63,12 +47,7 @@ class Language {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current language code
|
||||
* Obtém o código do idioma atual
|
||||
*
|
||||
* @return string Current language code / Código do idioma atual
|
||||
*/
|
||||
/** Gets active language code */
|
||||
public static function getCurrentLanguage() {
|
||||
return self::$currentLanguage;
|
||||
}
|
||||
|
|
|
@ -10,62 +10,42 @@ use Monolog\Level;
|
|||
use Exception;
|
||||
|
||||
/**
|
||||
* Error logging and monitoring class
|
||||
* Classe de monitoramento e registro de erros
|
||||
*
|
||||
* This class implements error logging functionality using Monolog
|
||||
* for monitoring and tracking application errors.
|
||||
*
|
||||
* Esta classe implementa funcionalidades de registro de erros usando Monolog
|
||||
* para monitoramento e rastreamento de erros da aplicação.
|
||||
* Centralized logging system using Monolog
|
||||
* Implements file rotation and log level configuration
|
||||
* Supports multiple output handlers
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* @var Logger|null Singleton instance
|
||||
* @var Logger|null Instância singleton
|
||||
*/
|
||||
/** @var Logger|null Singleton instance */
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* @var MonologLogger Monolog logger instance
|
||||
* @var MonologLogger Instância do logger Monolog
|
||||
*/
|
||||
/** @var MonologLogger Core logging instance */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var array Log level mapping
|
||||
* @var array Mapeamento de níveis de log
|
||||
*/
|
||||
/** @var array Log level mapping */
|
||||
private $logLevels = [
|
||||
'DEBUG' => \Monolog\Level::Debug,
|
||||
'INFO' => \Monolog\Level::Info,
|
||||
'WARNING' => \Monolog\Level::Warning,
|
||||
'ERROR' => \Monolog\Level::Error,
|
||||
'CRITICAL' => \Monolog\Level::Critical
|
||||
'DEBUG' => Level::Debug,
|
||||
'INFO' => Level::Info,
|
||||
'WARNING' => Level::Warning,
|
||||
'ERROR' => Level::Error,
|
||||
'CRITICAL' => Level::Critical
|
||||
];
|
||||
|
||||
/**
|
||||
* Private constructor to prevent direct instantiation
|
||||
* Construtor privado para prevenir instanciação direta
|
||||
*
|
||||
* Initializes Monolog logger with file rotation
|
||||
* Inicializa o logger Monolog com rotação de arquivos
|
||||
/**
|
||||
* Initializes logging system with file rotation
|
||||
* Configures log format and retention policy
|
||||
* Adds stderr output in DEBUG mode
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
$this->logger = new MonologLogger('marreta');
|
||||
|
||||
// Setup rotating file handler with 7 days retention
|
||||
// Configura manipulador de arquivo rotativo com retenção de 7 dias
|
||||
$handler = new RotatingFileHandler(
|
||||
__DIR__ . '/../logs/app.log',
|
||||
LOG_DAYS_TO_KEEP,
|
||||
$this->getLogLevel()
|
||||
);
|
||||
|
||||
// Custom line format
|
||||
// Formato de linha personalizado
|
||||
$dateFormat = "Y-m-d H:i:s";
|
||||
$output = "[%datetime%] %level_name%: %message% %context% %extra%\n";
|
||||
$formatter = new LineFormatter($output, $dateFormat);
|
||||
|
@ -73,21 +53,14 @@ class Logger
|
|||
|
||||
$this->logger->pushHandler($handler);
|
||||
|
||||
// If LOG_LEVEL is DEBUG, also log to stderr
|
||||
// Se LOG_LEVEL for DEBUG, também loga no stderr
|
||||
if (defined('LOG_LEVEL') && LOG_LEVEL === 'DEBUG') {
|
||||
$streamHandler = new StreamHandler('php://stderr', \Monolog\Level::Debug);
|
||||
$streamHandler = new StreamHandler('php://stderr', Level::Debug);
|
||||
$streamHandler->setFormatter($formatter);
|
||||
$this->logger->pushHandler($streamHandler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets singleton instance
|
||||
* Obtém instância singleton
|
||||
*
|
||||
* @return Logger Instance of Logger / Instância do Logger
|
||||
*/
|
||||
/** @return Logger Singleton instance */
|
||||
public static function getInstance(): Logger
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
|
@ -96,12 +69,7 @@ class Logger
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets configured log level from environment or default
|
||||
* Obtém nível de log configurado do ambiente ou padrão
|
||||
*
|
||||
* @return Level Monolog log level / Nível de log do Monolog
|
||||
*/
|
||||
/** Determines active log level from configuration */
|
||||
private function getLogLevel(): Level
|
||||
{
|
||||
$configLevel = defined('LOG_LEVEL') ? LOG_LEVEL : 'WARNING';
|
||||
|
@ -109,39 +77,29 @@ class Logger
|
|||
}
|
||||
|
||||
/**
|
||||
* Logs a message with context at specified level
|
||||
* Registra uma mensagem com contexto no nível especificado
|
||||
*
|
||||
* @param string $message Log message / Mensagem de log
|
||||
* @param array $context Additional context data / Dados adicionais de contexto
|
||||
* @param string $level Log level / Nível de log
|
||||
* Records log entry with context
|
||||
* @param string $message Log message
|
||||
* @param array $context Additional context data
|
||||
* @param string $level Log severity level
|
||||
*/
|
||||
public function log(string $message, array $context = [], string $level = 'WARNING'): void
|
||||
{
|
||||
$logLevel = $this->logLevels[$level] ?? \Monolog\Level::Warning;
|
||||
$logLevel = $this->logLevels[$level] ?? Level::Warning;
|
||||
$this->logger->log($logLevel, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error with context
|
||||
* Registra um erro com contexto
|
||||
*
|
||||
* @param string $message Error message / Mensagem de erro
|
||||
* @param array $context Additional context data / Dados adicionais de contexto
|
||||
*/
|
||||
/** Logs error message with context */
|
||||
public function error(string $message, array $context = []): void
|
||||
{
|
||||
$this->log($message, $context, 'ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a URL-specific error
|
||||
* Registra um erro específico de URL
|
||||
*
|
||||
* @param string $url The URL that generated the error / A URL que gerou o erro
|
||||
* @param string $error_group Error group/category / Grupo/categoria do erro
|
||||
* @param string $message_error Additional error details / Detalhes adicionais do erro
|
||||
* @param string $level Log level / Nível de log
|
||||
* Logs URL-specific error details
|
||||
* @param string $url Problematic URL
|
||||
* @param string $error_group Error category
|
||||
* @param string $message_error Additional error details
|
||||
* @param string $level Log severity level
|
||||
*/
|
||||
public function logUrl(string $url, string $error_group, string $message_error = '', string $level = 'WARNING'): void
|
||||
{
|
||||
|
@ -154,4 +112,4 @@ class Logger
|
|||
|
||||
$this->log($error_group, $context, $level);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class responsible for content manipulation rules management
|
||||
* Classe responsável pelo gerenciamento de regras de manipulação de conteúdo
|
||||
*
|
||||
* This class implements a rules system for different web domains,
|
||||
* allowing system behavior customization for each site.
|
||||
* Includes functionalities for paywall removal, specific elements,
|
||||
* cookie manipulation and custom code execution.
|
||||
*
|
||||
* Esta classe implementa um sistema de regras para diferentes domínios web,
|
||||
* permitindo a personalização do comportamento do sistema para cada site.
|
||||
* Inclui funcionalidades para remoção de paywalls, elementos específicos,
|
||||
* manipulação de cookies e execução de códigos customizados.
|
||||
* Manages domain-specific content manipulation rules
|
||||
* Handles rule merging between global and domain-specific configurations
|
||||
* Supports multiple rule types for web content manipulation
|
||||
*/
|
||||
class Rules
|
||||
{
|
||||
/**
|
||||
* Associative array containing specific rules for each domain
|
||||
* Array associativo contendo regras específicas para cada domínio
|
||||
*
|
||||
* Possible configurations for each domain:
|
||||
* Configurações possíveis para cada domínio:
|
||||
* @var array
|
||||
*/
|
||||
/** @var array Domain-specific rule configurations */
|
||||
private $domainRules = DOMAIN_RULES;
|
||||
|
||||
/**
|
||||
* Expanded global rules
|
||||
* Regras globais expandidas
|
||||
* @var array
|
||||
*/
|
||||
/** @var array Expanded global rule set */
|
||||
private $globalRules = GLOBAL_RULES;
|
||||
|
||||
/**
|
||||
* List of supported rule types
|
||||
* Lista de tipos de regras suportados
|
||||
* @var array
|
||||
*/
|
||||
/** @var array Supported rule types */
|
||||
private $supportedRuleTypes = [
|
||||
'userAgent',
|
||||
'headers',
|
||||
|
@ -57,11 +33,8 @@ class Rules
|
|||
];
|
||||
|
||||
/**
|
||||
* Gets the base domain by removing www prefix
|
||||
* Obtém o domínio base removendo o prefixo www
|
||||
*
|
||||
* @param string $domain Full domain / Domínio completo
|
||||
* @return string Base domain without www / Domínio base sem www
|
||||
* Extracts root domain by removing www prefix
|
||||
* @param string $domain Full domain name
|
||||
*/
|
||||
private function getBaseDomain($domain)
|
||||
{
|
||||
|
@ -69,11 +42,9 @@ class Rules
|
|||
}
|
||||
|
||||
/**
|
||||
* Splits a domain into its constituent parts
|
||||
* Divide um domínio em suas partes constituintes
|
||||
*
|
||||
* @param string $domain Domain to be split / Domínio a ser dividido
|
||||
* @return array Array with all possible domain combinations / Array com todas as combinações possíveis do domínio
|
||||
* Generates domain variations for rule matching
|
||||
* @param string $domain Original domain
|
||||
* @return array Sorted domain combinations by length
|
||||
*/
|
||||
private function getDomainParts($domain)
|
||||
{
|
||||
|
@ -93,11 +64,9 @@ class Rules
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets specific rules for a domain
|
||||
* Obtém as regras específicas para um domínio
|
||||
*
|
||||
* @param string $domain Domain to search rules for / Domínio para buscar regras
|
||||
* @return array|null Array with merged rules or null if not found / Array com regras mescladas ou null se não encontrar
|
||||
* Retrieves merged rules for a domain
|
||||
* @param string $domain Target domain
|
||||
* @return array|null Combined ruleset or global rules
|
||||
*/
|
||||
public function getDomainRules($domain)
|
||||
{
|
||||
|
@ -117,43 +86,28 @@ class Rules
|
|||
}
|
||||
}
|
||||
|
||||
// If no specific rules found, return only global rules
|
||||
// Se não encontrou regras específicas, retorna apenas as regras globais
|
||||
return $this->getGlobalRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges domain-specific rules with global rules
|
||||
* Mescla regras específicas do domínio com regras globais
|
||||
*
|
||||
* @param array $rules Domain-specific rules / Regras específicas do domínio
|
||||
* @return array Merged rules / Regras mescladas
|
||||
* Combines domain rules with global configuration
|
||||
* @param array $rules Domain-specific rules
|
||||
*/
|
||||
private function mergeWithGlobalRules($rules)
|
||||
{
|
||||
$globalRules = $this->getGlobalRules();
|
||||
$mergedRules = [];
|
||||
|
||||
// Process global rules exclusions
|
||||
// Processa as exclusões de regras globais
|
||||
$excludeGlobalRules = isset($rules['excludeGlobalRules']) ? $rules['excludeGlobalRules'] : [];
|
||||
unset($rules['excludeGlobalRules']); // Remove from rules array to avoid processing as normal rule / Remove do array de regras para não ser processado como regra normal
|
||||
$excludeGlobalRules = $rules['excludeGlobalRules'] ?? [];
|
||||
unset($rules['excludeGlobalRules']);
|
||||
|
||||
// First, add all global rules except excluded ones
|
||||
// Primeiro, adiciona todas as regras globais, exceto as excluídas
|
||||
foreach ($globalRules as $ruleType => $globalTypeRules) {
|
||||
if (!in_array($ruleType, $this->supportedRuleTypes)) {
|
||||
continue;
|
||||
}
|
||||
if (!in_array($ruleType, $this->supportedRuleTypes)) continue;
|
||||
|
||||
if (isset($excludeGlobalRules[$ruleType])) {
|
||||
// If rule type is an associative array (like cookies or headers)
|
||||
// Se o tipo de regra é um array associativo (como cookies ou headers)
|
||||
if (is_array($globalTypeRules) && array_keys($globalTypeRules) !== range(0, count($globalTypeRules) - 1)) {
|
||||
if (is_assoc_array($globalTypeRules)) {
|
||||
$mergedRules[$ruleType] = array_diff_key($globalTypeRules, array_flip($excludeGlobalRules[$ruleType]));
|
||||
} else {
|
||||
// For simple arrays (like classElementRemove)
|
||||
// Para arrays simples (como classElementRemove)
|
||||
$mergedRules[$ruleType] = array_diff($globalTypeRules, $excludeGlobalRules[$ruleType]);
|
||||
}
|
||||
} else {
|
||||
|
@ -161,27 +115,17 @@ class Rules
|
|||
}
|
||||
}
|
||||
|
||||
// Then, merge with domain-specific rules
|
||||
// Depois, mescla com as regras específicas do domínio
|
||||
foreach ($rules as $ruleType => $domainTypeRules) {
|
||||
if (!in_array($ruleType, $this->supportedRuleTypes)) {
|
||||
continue;
|
||||
}
|
||||
if (!in_array($ruleType, $this->supportedRuleTypes)) continue;
|
||||
|
||||
if (!isset($mergedRules[$ruleType])) {
|
||||
$mergedRules[$ruleType] = $domainTypeRules;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If rule type already exists, merge appropriately
|
||||
// Se o tipo de regra já existe, mescla apropriadamente
|
||||
if (in_array($ruleType, ['cookies', 'headers'])) {
|
||||
// For cookies and headers, preserve keys
|
||||
// Para cookies e headers, preserva as chaves
|
||||
$mergedRules[$ruleType] = array_merge($mergedRules[$ruleType], $domainTypeRules);
|
||||
} else {
|
||||
// For other types, merge as simple arrays
|
||||
// Para outros tipos, mescla como arrays simples
|
||||
$mergedRules[$ruleType] = array_values(array_unique(array_merge(
|
||||
$mergedRules[$ruleType],
|
||||
(array)$domainTypeRules
|
||||
|
@ -192,14 +136,14 @@ class Rules
|
|||
return $mergedRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all global rules
|
||||
* Retorna todas as regras globais
|
||||
*
|
||||
* @return array Array with all global rules / Array com todas as regras globais
|
||||
*/
|
||||
/** @return array Global rule configuration */
|
||||
public function getGlobalRules()
|
||||
{
|
||||
return $this->globalRules;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function for associative array check
|
||||
function is_assoc_array($array) {
|
||||
return array_keys($array) !== range(0, count($array) - 1);
|
||||
}
|
|
@ -1,19 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class responsible for URL analysis and processing
|
||||
* Classe responsável pela análise e processamento de URLs
|
||||
*
|
||||
* This class implements functionalities for:
|
||||
* Esta classe implementa funcionalidades para:
|
||||
*
|
||||
* - URL analysis and cleaning / Análise e limpeza de URLs
|
||||
* - Content caching / Cache de conteúdo
|
||||
* - DNS resolution / Resolução DNS
|
||||
* - HTTP requests with multiple attempts / Requisições HTTP com múltiplas tentativas
|
||||
* - Content processing based on domain-specific rules / Processamento de conteúdo baseado em regras específicas por domínio
|
||||
* - Wayback Machine support as fallback / Suporte a Wayback Machine como fallback
|
||||
* - Selenium extraction support when enabled by domain / Suporte a extração via Selenium quando habilitado por domínio
|
||||
* Class for URL analysis and processing
|
||||
* URL analysis and cleaning
|
||||
* Content caching
|
||||
* DNS resolution
|
||||
* HTTP requests with multiple attempts
|
||||
* Content processing based on domain-specific rules
|
||||
* Wayback Machine support
|
||||
* Selenium extraction support
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/Rules.php';
|
||||
|
@ -31,7 +26,6 @@ use Inc\Logger;
|
|||
|
||||
/**
|
||||
* Custom exception class for URL analysis errors
|
||||
* Classe de exceção personalizada para erros de análise de URL
|
||||
*/
|
||||
class URLAnalyzerException extends Exception
|
||||
{
|
||||
|
@ -81,8 +75,7 @@ class URLAnalyzer
|
|||
];
|
||||
|
||||
/**
|
||||
* Helper method to throw standardized errors
|
||||
* Método auxiliar para lançar erros padronizados
|
||||
* Helper method to throw errors
|
||||
*/
|
||||
private function throwError($errorType, $additionalInfo = '')
|
||||
{
|
||||
|
@ -95,24 +88,19 @@ class URLAnalyzer
|
|||
}
|
||||
|
||||
/**
|
||||
* @var array List of available User Agents for requests
|
||||
* @var array Lista de User Agents disponíveis para requisições
|
||||
* @var array List of User Agents
|
||||
*/
|
||||
private $userAgents = [
|
||||
// Google News bot
|
||||
// Bot do Google News
|
||||
'Googlebot-News',
|
||||
// Mobile Googlebot
|
||||
// Googlebot para dispositivos móveis
|
||||
'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
|
||||
// Desktop Googlebot
|
||||
// Googlebot para desktop
|
||||
'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array List of social media referrers
|
||||
* @var array Lista de referenciadores de mídia social
|
||||
*/
|
||||
private $socialReferrers = [
|
||||
// Twitter
|
||||
|
@ -125,35 +113,28 @@ class URLAnalyzer
|
|||
];
|
||||
|
||||
/**
|
||||
* @var array List of DNS servers for resolution
|
||||
* @var array Lista de servidores DNS para resolução
|
||||
* @var array List of DNS servers
|
||||
*/
|
||||
private $dnsServers;
|
||||
|
||||
/**
|
||||
* @var Rules Instance of rules class
|
||||
* @var Rules Instância da classe de regras
|
||||
*/
|
||||
private $rules;
|
||||
|
||||
/**
|
||||
* @var Cache Instance of cache class
|
||||
* @var Cache Instância da classe de cache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var array List of rules activated during processing
|
||||
* @var array Lista de regras ativadas durante o processamento
|
||||
* @var array List of activated rules
|
||||
*/
|
||||
private $activatedRules = [];
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Construtor da classe
|
||||
*
|
||||
* Initializes required dependencies
|
||||
* Inicializa as dependências necessárias
|
||||
* Initializes dependencies
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -164,10 +145,8 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Check if a URL has redirects and return the final URL
|
||||
* Verifica se uma URL tem redirecionamentos e retorna a URL final
|
||||
*
|
||||
* @param string $url URL to check redirects / URL para verificar redirecionamentos
|
||||
* @return array Array with final URL and if there was a redirect / Array com a URL final e se houve redirecionamento
|
||||
* @param string $url URL to check redirects
|
||||
* @return array Array with final URL and if there was a redirect
|
||||
*/
|
||||
public function checkStatus($url)
|
||||
{
|
||||
|
@ -196,10 +175,8 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Get a random user agent, with possibility of using Google bot
|
||||
* Obtém um user agent aleatório, com possibilidade de usar o Google bot
|
||||
*
|
||||
* @param bool $preferGoogleBot Whether to prefer Google bot user agents / Se deve preferir user agents do Google bot
|
||||
* @return string Selected user agent / User agent selecionado
|
||||
* @param bool $preferGoogleBot Whether to prefer Google bot user agents
|
||||
* @return string Selected user agent
|
||||
*/
|
||||
private function getRandomUserAgent($preferGoogleBot = false)
|
||||
{
|
||||
|
@ -211,9 +188,7 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Get a random social media referrer
|
||||
* Obtém um referenciador de mídia social aleatório
|
||||
*
|
||||
* @return string Selected referrer / Referenciador selecionado
|
||||
* @return string Selected referrer
|
||||
*/
|
||||
private function getRandomSocialReferrer()
|
||||
{
|
||||
|
@ -222,24 +197,21 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Main method for URL analysis
|
||||
* Método principal para análise de URLs
|
||||
*
|
||||
* @param string $url URL to be analyzed / URL a ser analisada
|
||||
* @return string Processed content / Conteúdo processado
|
||||
* @throws URLAnalyzerException In case of processing errors / Em caso de erros durante o processamento
|
||||
* @param string $url URL to be analyzed
|
||||
* @return string Processed content
|
||||
* @throws URLAnalyzerException In case of processing errors
|
||||
*/
|
||||
public function analyze($url)
|
||||
{
|
||||
// Reset activated rules for new analysis
|
||||
// Reset das regras ativadas para nova análise
|
||||
$this->activatedRules = [];
|
||||
|
||||
// 1. Check cache / Verifica cache
|
||||
// 1. Check cache
|
||||
if ($this->cache->exists($url)) {
|
||||
return $this->cache->get($url);
|
||||
}
|
||||
|
||||
// 2. Check blocked domains / Verifica domínios bloqueados
|
||||
// 2. Check blocked domains
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (!$host) {
|
||||
$this->throwError(self::ERROR_INVALID_URL);
|
||||
|
@ -263,11 +235,11 @@ class URLAnalyzer
|
|||
}
|
||||
|
||||
try {
|
||||
// 4. Get domain rules and check fetch strategy / Obtenha regras de domínio e verifique a estratégia de busca
|
||||
// 4. Get domain rules and check fetch strategy
|
||||
$domainRules = $this->getDomainRules($host);
|
||||
$fetchStrategy = isset($domainRules['fetchStrategies']) ? $domainRules['fetchStrategies'] : null;
|
||||
|
||||
// If a specific fetch strategy is defined, use only that / Se uma estratégia de busca específica for definida, use somente essa
|
||||
// If a specific fetch strategy is defined, use only that
|
||||
if ($fetchStrategy) {
|
||||
try {
|
||||
$content = null;
|
||||
|
@ -319,7 +291,7 @@ class URLAnalyzer
|
|||
}
|
||||
}
|
||||
|
||||
// If we get here, all strategies failed
|
||||
// If all strategies failed
|
||||
Logger::getInstance()->logUrl($url, 'GENERAL_FETCH_ERROR');
|
||||
if ($lastError) {
|
||||
$message = $lastError->getMessage();
|
||||
|
@ -337,7 +309,7 @@ class URLAnalyzer
|
|||
} catch (URLAnalyzerException $e) {
|
||||
throw $e;
|
||||
} catch (Exception $e) {
|
||||
// Map generic exceptions to appropriate error types
|
||||
// Map exceptions to error types
|
||||
$message = $e->getMessage();
|
||||
if (strpos($message, 'DNS') !== false) {
|
||||
$this->throwError(self::ERROR_DNS_FAILURE);
|
||||
|
@ -355,7 +327,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Fetch content from URL
|
||||
* Busca conteúdo da URL
|
||||
*/
|
||||
private function fetchContent($url)
|
||||
{
|
||||
|
@ -375,7 +346,7 @@ class URLAnalyzer
|
|||
$curl->setOpt(CURLOPT_DNS_SERVERS, implode(',', $this->dnsServers));
|
||||
$curl->setOpt(CURLOPT_ENCODING, '');
|
||||
|
||||
// Additional anti-detection headers / Cabeçalhos anti-detecção adicionais
|
||||
// Additional anti-detection headers
|
||||
$curl->setHeaders([
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language' => 'en-US,en;q=0.5',
|
||||
|
@ -384,7 +355,7 @@ class URLAnalyzer
|
|||
'DNT' => '1'
|
||||
]);
|
||||
|
||||
// Set Google bot specific headers / Definir cabeçalhos específicos do bot do Google
|
||||
// Set Google bot specific headers
|
||||
if (isset($domainRules['fromGoogleBot'])) {
|
||||
$curl->setUserAgent($this->getRandomUserAgent(true));
|
||||
$curl->setHeaders([
|
||||
|
@ -393,7 +364,7 @@ class URLAnalyzer
|
|||
]);
|
||||
}
|
||||
|
||||
// Add domain-specific headers / Adicionar cabeçalhos específicos de domínio
|
||||
// Add domain-specific headers
|
||||
if (isset($domainRules['headers'])) {
|
||||
$curl->setHeaders($domainRules['headers']);
|
||||
}
|
||||
|
@ -421,8 +392,7 @@ class URLAnalyzer
|
|||
}
|
||||
|
||||
/**
|
||||
* Try to get content from Internet Archive's Wayback Machine
|
||||
* Tenta obter conteúdo do Wayback Machine do Internet Archive
|
||||
* Try to get content from Wayback Machine
|
||||
*/
|
||||
private function fetchFromWaybackMachine($url)
|
||||
{
|
||||
|
@ -467,7 +437,7 @@ class URLAnalyzer
|
|||
|
||||
$content = $curl->response;
|
||||
|
||||
// Remove Wayback Machine toolbar and cache URLs / Remover a barra de ferramentas do Wayback Machine e URLs de cache
|
||||
// Remove Wayback Machine toolbar and cache URLs
|
||||
$content = preg_replace('/<!-- BEGIN WAYBACK TOOLBAR INSERT -->.*?<!-- END WAYBACK TOOLBAR INSERT -->/s', '', $content);
|
||||
$content = preg_replace('/https?:\/\/web\.archive\.org\/web\/\d+im_\//', '', $content);
|
||||
|
||||
|
@ -476,7 +446,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Try to get content using Selenium
|
||||
* Tenta obter conteúdo usando Selenium
|
||||
*/
|
||||
private function fetchFromSelenium($url, $browser = 'firefox')
|
||||
{
|
||||
|
@ -548,7 +517,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Get specific rules for a domain
|
||||
* Obtém regras específicas para um domínio
|
||||
*/
|
||||
private function getDomainRules($domain)
|
||||
{
|
||||
|
@ -557,7 +525,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Process HTML content applying domain rules
|
||||
* Processa conteúdo HTML aplicando regras de domínio
|
||||
*/
|
||||
private function processContent($content, $host, $url)
|
||||
{
|
||||
|
@ -573,7 +540,7 @@ class URLAnalyzer
|
|||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// Process canonical tags / Processar tags canônicas
|
||||
// Process canonical tags
|
||||
$canonicalLinks = $xpath->query("//link[@rel='canonical']");
|
||||
if ($canonicalLinks !== false) {
|
||||
foreach ($canonicalLinks as $link) {
|
||||
|
@ -583,7 +550,7 @@ class URLAnalyzer
|
|||
}
|
||||
}
|
||||
|
||||
// Add new canonical tag / Adicionar nova tag canônica
|
||||
// Add new canonical tag
|
||||
$head = $xpath->query('//head')->item(0);
|
||||
if ($head) {
|
||||
$newCanonical = $dom->createElement('link');
|
||||
|
@ -592,12 +559,12 @@ class URLAnalyzer
|
|||
$head->appendChild($newCanonical);
|
||||
}
|
||||
|
||||
// Fix relative URLs / Corrigir URLs relativas
|
||||
// Fix relative URLs
|
||||
$this->fixRelativeUrls($dom, $xpath, $url);
|
||||
|
||||
$domainRules = $this->getDomainRules($host);
|
||||
|
||||
// Apply domain rules / Aplicar regras de domínio
|
||||
// Apply domain rules
|
||||
if (isset($domainRules['customStyle'])) {
|
||||
$styleElement = $dom->createElement('style');
|
||||
$styleElement->appendChild($dom->createTextNode($domainRules['customStyle']));
|
||||
|
@ -612,16 +579,16 @@ class URLAnalyzer
|
|||
$dom->getElementsByTagName('body')[0]->appendChild($scriptElement);
|
||||
}
|
||||
|
||||
// Remove unwanted elements / Remover elementos indesejados
|
||||
// Remove unwanted elements
|
||||
$this->removeUnwantedElements($dom, $xpath, $domainRules);
|
||||
|
||||
// Clean inline styles / Limpar estilos inline
|
||||
// Clean inline styles
|
||||
$this->cleanInlineStyles($xpath);
|
||||
|
||||
// Add Brand Bar / Adicionar barra de marca
|
||||
// Add Brand bar
|
||||
$this->addBrandBar($dom, $xpath);
|
||||
|
||||
// Add debug panel / Adicionar painel de debug
|
||||
// Add Debug panel
|
||||
$this->addDebugBar($dom, $xpath);
|
||||
|
||||
return $dom->saveHTML();
|
||||
|
@ -629,7 +596,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Remove unwanted elements based on domain rules
|
||||
* Remove elementos indesejados com base nas regras de domínio
|
||||
*/
|
||||
private function removeUnwantedElements($dom, $xpath, $domainRules)
|
||||
{
|
||||
|
@ -715,7 +681,7 @@ class URLAnalyzer
|
|||
if (isset($domainRules['removeCustomAttr'])) {
|
||||
foreach ($domainRules['removeCustomAttr'] as $attrPattern) {
|
||||
if (strpos($attrPattern, '*') !== false) {
|
||||
// For wildcard attributes (e.g. data-*) / Para atributos com wildcard (ex: data-*)
|
||||
// For wildcard attributes (e.g. data-*)
|
||||
$elements = $xpath->query('//*');
|
||||
if ($elements !== false) {
|
||||
$pattern = '/^' . str_replace('*', '.*', $attrPattern) . '$/';
|
||||
|
@ -735,7 +701,7 @@ class URLAnalyzer
|
|||
$this->activatedRules[] = "removeCustomAttr: $attrPattern";
|
||||
}
|
||||
} else {
|
||||
// For non-wildcard attributes / Para atributos sem wildcard
|
||||
// For non-wildcard attributes
|
||||
$elements = $xpath->query("//*[@$attrPattern]");
|
||||
if ($elements !== false && $elements->length > 0) {
|
||||
foreach ($elements as $element) {
|
||||
|
@ -749,8 +715,7 @@ class URLAnalyzer
|
|||
}
|
||||
|
||||
/**
|
||||
* Clean inline styles that might interfere with content visibility
|
||||
* Limpa estilos inline que podem interferir na visibilidade do conteúdo
|
||||
* Clean inline styles
|
||||
*/
|
||||
private function cleanInlineStyles($xpath)
|
||||
{
|
||||
|
@ -767,8 +732,7 @@ class URLAnalyzer
|
|||
}
|
||||
|
||||
/**
|
||||
* Add Brand Bar CTA and debug panel
|
||||
* Adiciona CTA da marca e painel de debug
|
||||
* Add Brand Bar in pages
|
||||
*/
|
||||
private function addBrandBar($dom, $xpath)
|
||||
{
|
||||
|
@ -783,10 +747,8 @@ class URLAnalyzer
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add debug panel if LOG_LEVEL is DEBUG
|
||||
* Adicionar painel de depuração se LOG_LEVEL for DEBUG
|
||||
*/
|
||||
private function addDebugBar($dom, $xpath)
|
||||
{
|
||||
|
@ -815,7 +777,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Remove specific classes from an element
|
||||
* Remove classes específicas de um elemento
|
||||
*/
|
||||
private function removeClassNames($element, $classesToRemove)
|
||||
{
|
||||
|
@ -837,7 +798,6 @@ class URLAnalyzer
|
|||
|
||||
/**
|
||||
* Fix relative URLs in a DOM document
|
||||
* Corrige URLs relativas em um documento DOM
|
||||
*/
|
||||
private function fixRelativeUrls($dom, $xpath, $baseUrl)
|
||||
{
|
||||
|
@ -879,4 +839,4 @@ class URLAnalyzer
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Arquivo de entrada da aplicação
|
||||
* Application entry point
|
||||
*
|
||||
* Este arquivo inicializa o sistema de roteamento e despacha as requisições
|
||||
* para os manipuladores apropriados usando FastRoute.
|
||||
*
|
||||
* This file initializes the routing system and dispatches requests
|
||||
* Initializes the routing system and dispatches requests
|
||||
* to appropriate handlers using FastRoute.
|
||||
*/
|
||||
|
||||
|
|
|
@ -3,20 +3,15 @@
|
|||
*
|
||||
* The service worker acts as a network proxy and share target handler,
|
||||
* enabling the PWA to receive shared URLs from other applications.
|
||||
*
|
||||
* O service worker atua como um proxy de rede e manipulador de compartilhamento,
|
||||
* permitindo que o PWA receba URLs compartilhadas de outros aplicativos.
|
||||
*/
|
||||
|
||||
// Handles all network requests
|
||||
// Gerencia todas as requisições de rede
|
||||
self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(fetch(event.request));
|
||||
});
|
||||
|
||||
/**
|
||||
* Share target event handler - processes URLs shared from other applications
|
||||
* Manipulador do evento share_target - processa URLs compartilhadas de outros aplicativos
|
||||
*/
|
||||
self.addEventListener('share_target', (event) => {
|
||||
event.respondWith((async () => {
|
||||
|
|
10
default.conf
10
default.conf
|
@ -8,30 +8,24 @@ server {
|
|||
server_name _;
|
||||
|
||||
# Hide NGINX version to reduce exposed information
|
||||
# Oculta a versão do NGINX para reduzir informações expostas
|
||||
server_tokens off;
|
||||
|
||||
# NGINX-specific security configurations
|
||||
# Configurações de segurança específicas do NGINX
|
||||
|
||||
# Limit upload size to prevent denial of service attacks
|
||||
# Limita o tamanho de uploads para prevenir ataques de negação de serviço
|
||||
client_max_body_size 10M;
|
||||
client_body_buffer_size 128k;
|
||||
|
||||
# Disable directory listing to prevent structure exposure
|
||||
# Desativa listagem de diretórios para evitar exposição de estrutura
|
||||
autoindex off;
|
||||
|
||||
# Block access to sensitive directories
|
||||
# Bloqueia acesso a diretórios sensíveis
|
||||
location ~ ^/(logs|cache|inc|data|cli|bin|languages|vendor)/ {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
|
||||
# All requests go through index.php for FastRoute routing
|
||||
# Todas as requisições passam pelo index.php para roteamento FastRoute
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
@ -41,26 +35,22 @@ server {
|
|||
fastcgi_pass 127.0.0.1:9000;
|
||||
|
||||
# Hide header that reveals PHP version
|
||||
# Oculta cabeçalho que revela a versão do PHP
|
||||
fastcgi_hide_header X-Powered-By;
|
||||
}
|
||||
|
||||
# Block access to hidden files and directories
|
||||
# Bloqueia acesso a arquivos e diretórios ocultos
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Block access to configuration and database files
|
||||
# Bloqueia acesso a arquivos de configuração e banco de dados
|
||||
location ~ \.(sql|conf|ini)$ {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Minimize logs to reduce information exposure
|
||||
# Minimiza logs para reduzir exposição de informações
|
||||
access_log /dev/null;
|
||||
error_log /dev/stderr warn;
|
||||
}
|
||||
|
|
|
@ -1,55 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
###########################################
|
||||
# Marreta Docker Entrypoint
|
||||
#
|
||||
# This script initializes the Marreta container:
|
||||
# - Configures environment variables
|
||||
# - Adjusts directory permissions
|
||||
# - Starts and checks services (PHP-FPM and Nginx)
|
||||
#
|
||||
# Este script inicializa o container do Marreta:
|
||||
# - Configura variáveis de ambiente
|
||||
# - Ajusta permissões dos diretórios
|
||||
# - Inicia e verifica serviços (PHP-FPM e Nginx)
|
||||
# Docker Entrypoint
|
||||
###########################################
|
||||
|
||||
# Cores de saída / Output colors
|
||||
# Output colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color / Sem Cor
|
||||
NC='\033[0m'
|
||||
|
||||
# Função de log de sucesso / Success log function
|
||||
# Success log function
|
||||
log_success() {
|
||||
echo -e "${GREEN}[✓] $1${NC}"
|
||||
}
|
||||
|
||||
# Função de log de erro / Error log function
|
||||
# Error log function
|
||||
log_error() {
|
||||
echo -e "${RED}[✗] $1${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Função de log de informação / Info log function
|
||||
# Info log function
|
||||
log_info() {
|
||||
echo -e "${YELLOW}[i] $1${NC}"
|
||||
}
|
||||
|
||||
echo -e "\n${YELLOW}=== Starting Marreta ===${NC}\n"
|
||||
|
||||
# === Configuração das Variáveis de Ambiente / Environment Variables Configuration ===
|
||||
# Environment Variables Configuration
|
||||
log_info "Configuring environment variables..."
|
||||
|
||||
# Arquivo de ambiente (.env) / Env file (.env)
|
||||
# Env file (.env)
|
||||
ENV_FILE="/app/.env"
|
||||
|
||||
# Limpa o arquivo de ambiente / Clean Env file
|
||||
# Clean Env file
|
||||
> "$ENV_FILE"
|
||||
|
||||
while IFS='=' read -r key value; do
|
||||
# If value contains spaces and is not already quoted, add quotes
|
||||
# Se o valor contém espaços e não está entre aspas, adiciona aspas
|
||||
if [[ "$value" =~ \ ]] && ! [[ "$value" =~ ^\".*\"$ ]]; then
|
||||
value="\"$value\""
|
||||
fi
|
||||
|
@ -59,7 +48,7 @@ done < <(env)
|
|||
|
||||
log_success "Environment variables configured"
|
||||
|
||||
# === Ajuste de Permissões / Permissions Adjustment ===
|
||||
# Permissions Adjustment
|
||||
log_info "Adjusting directory permissions..."
|
||||
|
||||
chown -R www-data:www-data /app/cache /app/logs
|
||||
|
@ -67,7 +56,7 @@ chmod -R 775 /app/cache /app/logs
|
|||
|
||||
log_success "Permissions adjusted"
|
||||
|
||||
# === Funções de Verificação de Serviços / Service Check Functions ===
|
||||
# Service Check Functions
|
||||
check_nginx() {
|
||||
if ! pgrep nginx > /dev/null; then
|
||||
log_error "Failed to start Nginx"
|
||||
|
@ -84,10 +73,10 @@ check_php_fpm() {
|
|||
fi
|
||||
}
|
||||
|
||||
# === Inicialização dos Serviços / Services Initialization ===
|
||||
# Services Initialization
|
||||
echo -e "\n${YELLOW}=== Starting services ===${NC}\n"
|
||||
|
||||
# Diretório do PHP-FPM / PHP-FPM Directory
|
||||
# PHP-FPM Directory
|
||||
if [ ! -d /var/run/php ]; then
|
||||
log_info "Creating PHP-FPM directory..."
|
||||
mkdir -p /var/run/php
|
||||
|
@ -95,13 +84,13 @@ if [ ! -d /var/run/php ]; then
|
|||
log_success "PHP-FPM directory created"
|
||||
fi
|
||||
|
||||
# Iniciando PHP-FPM / Starting PHP-FPM
|
||||
# Starting PHP-FPM
|
||||
log_info "Starting PHP-FPM..."
|
||||
php-fpm &
|
||||
sleep 3
|
||||
check_php_fpm
|
||||
|
||||
# Verificando configuração do Nginx / Checking Nginx configuration
|
||||
# Checking Nginx configuration
|
||||
log_info "Checking Nginx configuration..."
|
||||
nginx -t
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -110,7 +99,7 @@ else
|
|||
log_success "Valid Nginx configuration"
|
||||
fi
|
||||
|
||||
# Iniciando Nginx / Starting Nginx
|
||||
# Starting Nginx
|
||||
log_info "Starting Nginx..."
|
||||
nginx -g "daemon off;" &
|
||||
sleep 3
|
||||
|
@ -118,8 +107,8 @@ check_nginx
|
|||
|
||||
echo -e "\n${GREEN}=== Marreta initialized ===${NC}\n"
|
||||
|
||||
# Aguarda qualquer processo terminar / Wait for any process to exit
|
||||
# Wait for any process to exit
|
||||
wait -n
|
||||
|
||||
# Sai com o status do processo que terminou primeiro / Exit with status of process that exited first
|
||||
# Exit with status of process that exited first
|
||||
exit $?
|
||||
|
|
Loading…
Add table
Reference in a new issue