diff --git a/core/Auth/JwtService.php b/core/Auth/JwtService.php index e346e74..48fa42b 100644 --- a/core/Auth/JwtService.php +++ b/core/Auth/JwtService.php @@ -218,7 +218,7 @@ class JwtService // ── Internal API Key — للـ get_connect.php ───────────── public static function validateInternalKey(): void { - $keyPath = '/home/intaleq-api/.internal_socket_key'; + $keyPath = getenv('INTERNAL_SOCKET_KEY_PATH'); $sent = $_SERVER['HTTP_X_INTERNAL_KEY'] ?? ''; $expected = (file_exists($keyPath) ? trim(file_get_contents($keyPath)) : '') ?: 'Intaleq_Secure_Bridge_Key_2026_@!socket'; diff --git a/core/bootstrap.php b/core/bootstrap.php index d3aaec9..5a4029f 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -76,10 +76,11 @@ require_once __DIR__ . '/Auth/JwtService.php'; // 6. تهيئة Encryption Helper العام (للتوافقية) // يتم استخدام .enckey (32 بايت) لتشفير البيانات -$encKey = trim(@file_get_contents('/home/intaleq-api/.enckey') ?: ''); -if (!$encKey) { - $encKey = getenv('ENC_KEY') ?: ''; -} + $encKeyPath = getenv('ENCRYPTION_KEY_PATH'); + $encKey = trim(@file_get_contents($encKeyPath) ?: ''); + if (!$encKey) { + $encKey = getenv('ENC_KEY') ?: ''; + } if (!$encKey || strlen($encKey) !== 32) { error_log("[FATAL] Encryption key (.enckey) is missing or invalid length (must be 32 bytes)."); diff --git a/functions.php b/functions.php index 55a6a91..779fc63 100755 --- a/functions.php +++ b/functions.php @@ -8,7 +8,7 @@ use Firebase\JWT\SignatureInvalidException; use Firebase\JWT\BeforeValidException; -$INTERNAL_KEY = trim(file_get_contents('/home/intaleq-api/.internal_socket_key')); +$INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); /** @@ -22,8 +22,8 @@ $INTERNAL_KEY = trim(file_get_contents('/home/intaleq-api/.internal_socket_key') function sendToLocationServer($action, $data) { // رابط سيرفر اللوكيشن الداخلي أو العام - $url = "http://location.intaleq.xyz:2021"; - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $url = getenv('LOCATION_SOCKET_URL'); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = [ 'action' => $action, @@ -43,8 +43,8 @@ function sendToLocationServer($action, $data) { function findBestDrivers($con, $lat, $lng, $carType) { // 1. الاتصال بـ Redis لجلب الأقرب - $locationServerUrl = "https://location.intaleq.xyz/api_get_nearby.php"; - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $locationServerUrl = getenv('LOCATION_API_URL'); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = ['lat' => $lat, 'lng' => $lng, 'radius' => 5, 'limit' => 100]; @@ -158,7 +158,7 @@ function notifyDriversRideTaken($rideId, $winnerDriverId) { // رابط سيرفر السائقين الداخلي (نفس البورت المستخدم في driver_socket.php) $url = getenv('LOCATION_SOCKET_URL'); if (!$url) throw new RuntimeException('LOCATION_SOCKET_URL not configured'); - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = [ 'action' => 'ride_taken_event', // هذا الأكشن الجديد في السوكيت @@ -181,7 +181,7 @@ function notifyDriversOnLocationServer($drivers_ids_array, $payload, $rideId = n // رابط سيرفر اللوكيشن الخارجي $url = getenv('LOCATION_SOCKET_URL'); if (!$url) throw new RuntimeException('LOCATION_SOCKET_URL not configured'); - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = [ 'action' => 'dispatch_order', // اسم الحدث المتفق عليه في socket_server.php هناك @@ -221,7 +221,7 @@ function notifyPassengerOnRideServer($passenger_id, $payload) { error_log("[FATAL] PASSENGER_SOCKET_URL not configured"); throw new RuntimeException('PASSENGER_SOCKET_URL not configured'); } - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = [ 'action' => 'update_ride_status', @@ -262,7 +262,7 @@ function dispatchRideToDrivers($driversData, $rideId, $payloadTemplate, $startNa $socketUrl = getenv('LOCATION_SOCKET_URL'); if (!$socketUrl) throw new RuntimeException('LOCATION_SOCKET_URL not configured'); - $internalKeyPath = '/home/intaleq-api/.internal_socket_key'; + $internalKeyPath = getenv('INTERNAL_SOCKET_KEY_PATH'); $internalKey = file_exists($internalKeyPath) ? trim(file_get_contents($internalKeyPath)) : ''; foreach ($driversData as $driver) { diff --git a/ride/location/get.php b/ride/location/get.php index 8eb45c4..ad9b599 100755 --- a/ride/location/get.php +++ b/ride/location/get.php @@ -31,9 +31,9 @@ try { // ========================================== // 2. طلب الـ IDs والمواقع من سيرفر اللوكيشن (Redis API) // ========================================== - $locationServerUrl = "https://location.intaleq.xyz/api_get_nearby.php"; + $locationServerUrl = getenv('LOCATION_API_URL'); // تأكد من المسار الصحيح للمفتاح على السيرفر الرئيسي - $INTERNAL_KEY = trim(file_get_contents('/home/intaleq-api/.internal_socket_key')); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $locationServerUrl); diff --git a/ride/notificationCaptain/getRideWaiting.php b/ride/notificationCaptain/getRideWaiting.php index 23ed3f2..e7c4a57 100755 --- a/ride/notificationCaptain/getRideWaiting.php +++ b/ride/notificationCaptain/getRideWaiting.php @@ -21,8 +21,8 @@ $redisResultsMap = []; // 1. محاولة البحث عبر Redis try { - $locationServerUrl = "http://location.intaleq.xyz:2021"; - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $locationServerUrl = getenv('LOCATION_SOCKET_URL'); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); $postData = [ 'action' => 'get_nearby_ride_ids', diff --git a/ride/rides/add_ride.php b/ride/rides/add_ride.php index a23b629..1f28cea 100755 --- a/ride/rides/add_ride.php +++ b/ride/rides/add_ride.php @@ -16,10 +16,10 @@ ini_set('error_log', '/home/intaleq-api/add_ride_error.log'); // ================================================================================= function broadcastRideToMarket($rideId, $lat, $lng, $payloadData) { // رابط سيرفر اللوكيشن (تأكد من صحة الرابط والبورت) - $url = "http://location.intaleq.xyz:2021"; + $url = getenv('LOCATION_SOCKET_URL'); // قراءة مفتاح الأمان الداخلي للمصادقة - $INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key')); + $INTERNAL_KEY = trim(file_get_contents(getenv('INTERNAL_SOCKET_KEY_PATH'))); // تجهيز البيانات بشكل (Key-Value Map) لسهولة التعامل في التطبيق والسوكيت // ملاحظة: نستخدم القيم من $payloadData التي هي عبارة عن List حالياً