- Created separate MoneyFlix project directory - Copied Node.js redirector from production server - Added CRM PHP code (Redirects module, Core classes, Config, Routes, Views) - Created comprehensive documentation (README_MONEYFLIX.md) - Added sync script to keep CRM code updated (sync-from-crm.sh) - Configured .gitignore for Node.js and PHP - Set up proper project structure for multi-client isolation This separates MoneyFlix from the main CRM to avoid confusion between different client systems and provides a dedicated environment for MoneyFlix-specific development and maintenance.
160 lines
4.2 KiB
PHP
160 lines
4.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Core;
|
|
|
|
/**
|
|
* InputSanitizer - Sanitização automática de todos os inputs
|
|
* Implementa sanitização defensiva universal para $_POST, $_GET, $_REQUEST
|
|
*/
|
|
class InputSanitizer
|
|
{
|
|
private static array $sanitizedInputs = [];
|
|
private static bool $initialized = false;
|
|
|
|
/**
|
|
* Inicializar sanitização automática
|
|
*/
|
|
public static function initialize(): void
|
|
{
|
|
if (self::$initialized) {
|
|
return;
|
|
}
|
|
|
|
// Process JSON input for API requests
|
|
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
|
if (strpos($contentType, 'application/json') !== false) {
|
|
$jsonInput = file_get_contents('php://input');
|
|
$jsonData = json_decode($jsonInput, true);
|
|
if ($jsonData && is_array($jsonData)) {
|
|
foreach ($jsonData as $key => $value) {
|
|
self::$sanitizedInputs['POST'][$key] = self::sanitizeValue($value);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Sanitizar $_POST
|
|
foreach ($_POST as $key => $value) {
|
|
self::$sanitizedInputs['POST'][$key] = self::sanitizeValue($value);
|
|
}
|
|
|
|
// Sanitizar $_GET
|
|
foreach ($_GET as $key => $value) {
|
|
self::$sanitizedInputs['GET'][$key] = self::sanitizeValue($value);
|
|
}
|
|
|
|
// Sanitizar $_REQUEST
|
|
foreach ($_REQUEST as $key => $value) {
|
|
self::$sanitizedInputs['REQUEST'][$key] = self::sanitizeValue($value);
|
|
}
|
|
|
|
self::$initialized = true;
|
|
}
|
|
|
|
/**
|
|
* Obter input sanitizado
|
|
*/
|
|
public static function get(string $key, string $method = 'POST', $default = ''): mixed
|
|
{
|
|
self::initialize();
|
|
|
|
return self::$sanitizedInputs[$method][$key] ?? $default;
|
|
}
|
|
|
|
/**
|
|
* Obter todos os inputs sanitizados de um método
|
|
*/
|
|
public static function all(string $method = 'POST'): array
|
|
{
|
|
self::initialize();
|
|
|
|
return self::$sanitizedInputs[$method] ?? [];
|
|
}
|
|
|
|
/**
|
|
* Verificar se input existe
|
|
*/
|
|
public static function has(string $key, string $method = 'POST'): bool
|
|
{
|
|
self::initialize();
|
|
|
|
return isset(self::$sanitizedInputs[$method][$key]);
|
|
}
|
|
|
|
/**
|
|
* Sanitizar valor baseado no tipo
|
|
*/
|
|
private static function sanitizeValue($value): mixed
|
|
{
|
|
if (is_array($value)) {
|
|
return array_map([self::class, 'sanitizeValue'], $value);
|
|
}
|
|
|
|
if (is_string($value)) {
|
|
return Sanitize::string($value);
|
|
}
|
|
|
|
if (is_numeric($value)) {
|
|
return Sanitize::integer($value);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* Sanitizar input específico com tipo
|
|
*/
|
|
public static function email(string $key, string $method = 'POST'): string
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::email($value);
|
|
}
|
|
|
|
public static function integer(string $key, string $method = 'POST', ?int $min = null, ?int $max = null): int
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::integer($value, $min, $max);
|
|
}
|
|
|
|
public static function decimal(string $key, string $method = 'POST', int $decimals = 2): float
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::decimal($value, $decimals);
|
|
}
|
|
|
|
public static function url(string $key, string $method = 'POST'): string
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::url($value);
|
|
}
|
|
|
|
public static function phone(string $key, string $method = 'POST'): string
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::phone($value);
|
|
}
|
|
|
|
public static function date(string $key, string $method = 'POST'): string
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Sanitize::date($value);
|
|
}
|
|
|
|
/**
|
|
* Validar input com regras
|
|
*/
|
|
public static function validate(string $key, array $rules, string $method = 'POST'): array
|
|
{
|
|
$value = self::get($key, $method);
|
|
return Validate::rules($value, $rules);
|
|
}
|
|
|
|
/**
|
|
* Limpar dados sanitizados
|
|
*/
|
|
public static function clear(): void
|
|
{
|
|
self::$sanitizedInputs = [];
|
|
self::$initialized = false;
|
|
}
|
|
}
|