diff --git a/backend/Admin/auth/login.php b/backend/Admin/auth/login.php index ba1f486..68efe8c 100644 --- a/backend/Admin/auth/login.php +++ b/backend/Admin/auth/login.php @@ -140,11 +140,12 @@ try { $success = sendWhatsAppFromServer($phone, $messageBody); if ($success) { - // حفظ الرمز كما هو في قاعدة البيانات (بدون تشفير) + // تخزين هاش للـ OTP بدلاً من النص الصريح + $otpHash = hash('sha256', (string)$otp); $stmt = $con->prepare("INSERT INTO token_verification_admin (phone_number, token, expiration_time) VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 10 MINUTE)) ON DUPLICATE KEY UPDATE token = VALUES(token), expiration_time = VALUES(expiration_time)"); - $stmt->execute([$encryptedPhone, $otp]); + $stmt->execute([$encryptedPhone, $otpHash]); // إخفاء جزء من الرقم في الاستجابة للأمان $maskedPhone = substr($phone, 0, 4) . '****' . substr($phone, -3); diff --git a/backend/Admin/auth/loginWallet.php b/backend/Admin/auth/loginWallet.php index b2342ef..dee34b6 100644 --- a/backend/Admin/auth/loginWallet.php +++ b/backend/Admin/auth/loginWallet.php @@ -22,12 +22,13 @@ if ($admin->role !== 'admin' && $admin->role !== 'super_admin') { } try { - // جلب المفتاح المشترك لسيرفر المحفظة - $payKeyPath = '/home/siro-api/.secret_key_pay'; - $payKey = file_exists($payKeyPath) ? trim(file_get_contents($payKeyPath)) : getenv('SECRET_KEY_PAY'); + // جلب المفتاح المشترك لسيرفر المحفظة من متغير البيئة أو الملف + $payKeyPath = getenv('SECRET_KEY_PAY_PATH'); + $payKey = ($payKeyPath && file_exists($payKeyPath)) ? trim(file_get_contents($payKeyPath)) : getenv('SECRET_KEY_PAY'); if (empty($payKey)) { - $payKey = trim(@file_get_contents('/home/siro-api/.secret_key')); + $fallbackPath = getenv('SECRET_KEY_PATH'); + $payKey = ($fallbackPath && file_exists($fallbackPath)) ? trim(file_get_contents($fallbackPath)) : null; } if (empty($payKey)) { diff --git a/backend/Admin/auth/verify_login.php b/backend/Admin/auth/verify_login.php index 5b262bd..65a8678 100644 --- a/backend/Admin/auth/verify_login.php +++ b/backend/Admin/auth/verify_login.php @@ -39,14 +39,14 @@ try { // فك تشفيره لو احتجنا إرساله أو عرضه، لكن هنا نحن نحتاج المشفر للبحث // $phone = $encryptionHelper->decryptData($encryptedPhone); - // تشفير الرمز (OTP) القادم من التطبيق للمقارنة - $encryptedOtp = $encryptionHelper->encryptData((string)$otp); + // هاش الرمز (OTP) القادم من التطبيق للمقارنة + $otpHash = hash('sha256', (string)$otp); - // 3. التحقق من الـ OTP (باستخدام القيم المشفرة) + // 3. التحقق من الـ OTP $stmt = $con->prepare("SELECT * FROM token_verification_admin WHERE phone_number = ? AND token = ? AND expiration_time >= NOW()"); - $stmt->execute([$encryptedPhone, $encryptedOtp]); + $stmt->execute([$encryptedPhone, $otpHash]); if ($stmt->rowCount() === 0) { jsonError("رمز التحقق غير صالح أو منتهي الصلاحية."); diff --git a/backend/core/bootstrap.php b/backend/core/bootstrap.php index ea7ab8c..444e216 100644 --- a/backend/core/bootstrap.php +++ b/backend/core/bootstrap.php @@ -20,10 +20,7 @@ if ($debugMode) { ini_set('log_errors', '1'); // تحديد مسار اللوج بشكل ديناميكي (محلياً أو سيرفر) -$logPath = '/home/siro-api/logs/php_errors.log'; -if (!file_exists(dirname($logPath)) || !is_writable(dirname($logPath))) { - $logPath = __DIR__ . '/../logs/php_errors.log'; -} +$logPath = getenv('ERROR_LOG_PATH') ?: (__DIR__ . '/../logs/php_errors.log'); ini_set('error_log', $logPath); header_remove('X-Powered-By'); @@ -54,10 +51,7 @@ if ($vendorPath) require_once $vendorPath; require_once __DIR__ . '/helpers.php'; // تحديد مسار الـ .env بشكل ديناميكي -$envFile = '/home/siro-api/env/.env'; -if (!file_exists($envFile)) { - $envFile = __DIR__ . '/../.env'; // مسار محلي افتراضي -} +$envFile = getenv('ENV_FILE_PATH') ?: (__DIR__ . '/../.env'); loadEnvironment($envFile); // 4. Redis Connection (Singleton) diff --git a/backend/encrypt_decrypt.php b/backend/encrypt_decrypt.php index a6c5242..b2c7cbc 100644 --- a/backend/encrypt_decrypt.php +++ b/backend/encrypt_decrypt.php @@ -4,7 +4,7 @@ require_once realpath(__DIR__ . '/../vendor/autoload.php'); require_once 'load_env.php'; -$env_file = '/home/siro-api/env/.env'; +$env_file = getenv('ENV_FILE_PATH') ?: (__DIR__ . '/../../../env/.env'); loadEnvironment($env_file); // ✅ FIX C-02: استخدام getenv بدلاً من file_get_contents الثابت