Files
erv-ticket-dev/sms-test.php
Fedor 2c516362df feat: Secure SMS verification with Redis (Predis)
- Added Predis library for Redis connection (no PHP extension required)
- Server-side SMS code generation and storage in Redis
- Rate limiting and brute-force protection
- Integration with n8n webhook for SMS sending
- Environment variables moved to .env file
- Fixed policy verification endpoint
- Added file-based fallback if Redis unavailable
2026-01-15 15:40:13 +03:00

72 lines
2.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Прокси для обратной совместимости со старым API
* Перенаправляет запросы на новый безопасный API sms-verify.php
*
* @deprecated Используйте sms-verify.php напрямую
*/
// Устанавливаем заголовки
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
// Обработка preflight запроса
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
// Получаем данные из POST
$phone = $_POST['phonenumber'] ?? '';
$code = $_POST['smscode'] ?? ''; // Игнорируем, код теперь генерируется на сервере
if (empty($phone)) {
http_response_code(400);
echo json_encode([
'success' => false,
'message' => 'Номер телефона не указан'
], JSON_UNESCAPED_UNICODE);
exit;
}
// Перенаправляем на новый API через внутренний запрос
// Используем тот же протокол и хост
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$path = dirname($_SERVER['SCRIPT_NAME']);
$url = $protocol . '://' . $host . $path . '/sms-verify.php?action=send';
$post_data = http_build_query([
'phonenumber' => $phone
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_error) {
http_response_code(500);
echo json_encode([
'success' => false,
'message' => 'Ошибка подключения к сервису: ' . $curl_error
], JSON_UNESCAPED_UNICODE);
} else {
// Возвращаем ответ от нового API
http_response_code($http_code);
echo $response;
}