|
|
<?php
|
|
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
if (file_exists(__DIR__ . '/.env')) {
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
|
|
$dotenv->load();
|
|
|
}
|
|
|
|
|
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
|
session_start();
|
|
|
}
|
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
header('Content-Type: application/json');
|
|
|
header('X-Content-Type-Options: nosniff');
|
|
|
header('X-Frame-Options: DENY');
|
|
|
header('X-XSS-Protection: 1; mode=block');
|
|
|
|
|
|
try {
|
|
|
|
|
|
$rateLimitFile = __DIR__ . '/logs/rate_limit_' . md5($_SERVER['REMOTE_ADDR'] ?? 'unknown') . '.txt';
|
|
|
$currentTime = time();
|
|
|
|
|
|
if (file_exists($rateLimitFile)) {
|
|
|
$lastRequest = (int)file_get_contents($rateLimitFile);
|
|
|
if ($currentTime - $lastRequest < 60) {
|
|
|
echo json_encode(['success' => false, 'error' => 'Aguarde um momento antes de enviar outra mensagem.']);
|
|
|
exit;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
file_put_contents($rateLimitFile, $currentTime);
|
|
|
|
|
|
|
|
|
$nome = trim($_POST['nome'] ?? '');
|
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
$empresa = trim($_POST['empresa'] ?? '(não informado)');
|
|
|
$mensagem = trim($_POST['mensagem'] ?? '');
|
|
|
|
|
|
|
|
|
$csrfToken = $_POST['csrf_token'] ?? '';
|
|
|
$sessionToken = $_SESSION['csrf_token'] ?? '';
|
|
|
|
|
|
if (empty($csrfToken) || $csrfToken !== $sessionToken) {
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro de segurança. Recarregue a página e tente novamente.']);
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
|
|
|
$contactData = [
|
|
|
'nome' => $nome,
|
|
|
'email' => $email,
|
|
|
'empresa' => $empresa,
|
|
|
'mensagem' => $mensagem
|
|
|
];
|
|
|
|
|
|
|
|
|
$emailService = new \SoftEdge\EmailService();
|
|
|
|
|
|
if ($emailService->sendContactEmail($contactData)) {
|
|
|
echo json_encode(['success' => true]);
|
|
|
} else {
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro ao enviar mensagem. Por favor, tente novamente ou entre em contato via WhatsApp.']);
|
|
|
}
|
|
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
|
} catch (\Exception $e) {
|
|
|
error_log('Contact form error: ' . $e->getMessage());
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro interno do servidor. Nossa equipe foi notificada.']);
|
|
|
}
|
|
|
|
|
|
exit;
|
|
|
}
|
|
|
?>
|
|
|
=======
|
|
|
<?php
|
|
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
if (file_exists(__DIR__ . '/.env')) {
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
|
|
$dotenv->load();
|
|
|
}
|
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
header('Content-Type: application/json');
|
|
|
header('X-Content-Type-Options: nosniff');
|
|
|
header('X-Frame-Options: DENY');
|
|
|
header('X-XSS-Protection: 1; mode=block');
|
|
|
|
|
|
try {
|
|
|
|
|
|
$rateLimitFile = __DIR__ . '/logs/rate_limit_' . md5($_SERVER['REMOTE_ADDR'] ?? 'unknown') . '.txt';
|
|
|
$currentTime = time();
|
|
|
|
|
|
if (file_exists($rateLimitFile)) {
|
|
|
$lastRequest = (int)file_get_contents($rateLimitFile);
|
|
|
if ($currentTime - $lastRequest < 60) {
|
|
|
echo json_encode(['success' => false, 'error' => 'Aguarde um momento antes de enviar outra mensagem.']);
|
|
|
exit;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
file_put_contents($rateLimitFile, $currentTime);
|
|
|
|
|
|
|
|
|
$nome = trim($_POST['nome'] ?? '');
|
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
$empresa = trim($_POST['empresa'] ?? '(não informado)');
|
|
|
$mensagem = trim($_POST['mensagem'] ?? '');
|
|
|
|
|
|
|
|
|
$csrfToken = $_POST['csrf_token'] ?? '';
|
|
|
$sessionToken = $_SESSION['csrf_token'] ?? '';
|
|
|
|
|
|
if (empty($csrfToken) || $csrfToken !== $sessionToken) {
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro de segurança. Recarregue a página e tente novamente.']);
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
|
|
|
$contactData = [
|
|
|
'nome' => $nome,
|
|
|
'email' => $email,
|
|
|
'empresa' => $empresa,
|
|
|
'mensagem' => $mensagem
|
|
|
];
|
|
|
|
|
|
|
|
|
$emailService = new \SoftEdge\EmailService();
|
|
|
|
|
|
if ($emailService->sendContactEmail($contactData)) {
|
|
|
echo json_encode(['success' => true]);
|
|
|
} else {
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro ao enviar mensagem. Por favor, tente novamente ou entre em contato via WhatsApp.']);
|
|
|
}
|
|
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
|
} catch (\Exception $e) {
|
|
|
error_log('Contact form error: ' . $e->getMessage());
|
|
|
echo json_encode(['success' => false, 'error' => 'Erro interno do servidor. Nossa equipe foi notificada.']);
|
|
|
}
|
|
|
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
|
session_start();
|
|
|
}
|
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
|
?>
|
|
|
|