Update: 2026-06-21 18:58:05
This commit is contained in:
@@ -27,8 +27,8 @@ function getAllowedSocketUrls(): array {
|
||||
}
|
||||
// القيم الافتراضية لو لم تكن موجودة في .env
|
||||
return [
|
||||
'http://188.68.36.205:2021',
|
||||
'http://188.68.36.205:3031',
|
||||
'http://location.intaleq.xyz:2021',
|
||||
'http://location.intaleq.xyz:3031',
|
||||
'https://location.intaleq.xyz',
|
||||
];
|
||||
}
|
||||
@@ -44,7 +44,7 @@ function isAllowedSocketUrl(string $url): bool {
|
||||
}
|
||||
|
||||
function sendToLocationServer($action, $data) {
|
||||
$url = getenv('LOCATION_SERVER_URL') ?: 'http://188.68.36.205:2021';
|
||||
$url = getenv('LOCATION_SERVER_URL') ?: 'http://location.intaleq.xyz:2021';
|
||||
if (!isAllowedSocketUrl($url)) {
|
||||
error_log("[SSRF_BLOCKED] Attempted connection to: $url");
|
||||
return;
|
||||
@@ -67,7 +67,7 @@ function sendToLocationServer($action, $data) {
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
function findBestDrivers($con, $lat, $lng, $carType) {
|
||||
function findBestDrivers($con, $lat, $lng, $carType, $endLat = null, $endLng = null) {
|
||||
// 1. الاتصال بـ Redis لجلب الأقرب
|
||||
$locationServerUrl = "https://location.intaleq.xyz/api_get_nearby.php";
|
||||
$INTERNAL_KEY = function_exists('getInternalSocketKey') ? getInternalSocketKey() : '';
|
||||
@@ -108,16 +108,20 @@ function findBestDrivers($con, $lat, $lng, $carType) {
|
||||
// تعريف الثوابت
|
||||
$CAT_CAR = 1; $CAT_BIKE = 2; $CAT_VAN = 3; $FUEL_ELECTRIC = 3;
|
||||
|
||||
// 3. الاستعلام (بدون platform)
|
||||
// 3. الاستعلام (دمج جدول وجهات السائقين dd للتحقق من الملاءمة)
|
||||
$sql = "SELECT
|
||||
d.id AS driver_id,
|
||||
dt.token,
|
||||
cr.year,
|
||||
cr.vehicle_category_id,
|
||||
d.gender
|
||||
d.gender,
|
||||
dd.target_latitude,
|
||||
dd.target_longitude,
|
||||
dd.is_active AS has_destination
|
||||
FROM driver d
|
||||
JOIN CarRegistration cr ON cr.driverID = d.id
|
||||
JOIN driverToken dt ON dt.captain_id = d.id
|
||||
LEFT JOIN driver_destinations dd ON dd.driver_id = d.id AND dd.is_active = 1 AND dd.usage_date = CURDATE()
|
||||
WHERE d.id IN ($placeholders) ";
|
||||
|
||||
// ✅ FIX C-01: استخدام allowlist للـ carType لمنع SQL Injection
|
||||
@@ -150,10 +154,9 @@ function findBestDrivers($con, $lat, $lng, $carType) {
|
||||
$sqlParams[] = $FUEL_ELECTRIC;
|
||||
break;
|
||||
case 'Lady':
|
||||
$femaleHash = 'bQ6yWJ2EVXKZooHdGclvmFiDlZCM8UYeO+ILFjDUvpQ=';
|
||||
$sql .= " AND cr.vehicle_category_id = ? AND d.gender = ? ";
|
||||
$sqlParams[] = $CAT_CAR;
|
||||
$sqlParams[] = $femaleHash;
|
||||
$sqlParams[] = getenv('FEMALE_GENDER_HASH') ?: '';
|
||||
break;
|
||||
case 'Van':
|
||||
$sql .= " AND cr.vehicle_category_id = ? ";
|
||||
@@ -180,9 +183,27 @@ function findBestDrivers($con, $lat, $lng, $carType) {
|
||||
$stmt->execute($allParams);
|
||||
$finalDrivers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// دمج البيانات
|
||||
foreach ($finalDrivers as &$driver) {
|
||||
$filteredDrivers = [];
|
||||
|
||||
// دمج البيانات وتطبيق تصفية الوجهة
|
||||
foreach ($finalDrivers as $driver) {
|
||||
$did = $driver['driver_id'];
|
||||
|
||||
// تحقق من توافق الوجهة إذا كان السائق قد حدد وجهة والرحلة تملك إحداثيات نهاية
|
||||
if ($driver['has_destination'] && $endLat !== null && $endLng !== null) {
|
||||
$driverDestLat = (float)$driver['target_latitude'];
|
||||
$driverDestLng = (float)$driver['target_longitude'];
|
||||
|
||||
// حساب المسافة بين وجهة السائق ووجهة الرحلة
|
||||
$destDistance = getDistanceBetweenPoints((float)$endLat, (float)$endLng, $driverDestLat, $driverDestLng);
|
||||
|
||||
// إذا كانت المسافة أكبر من 5.0 كم، نستبعد السائق لأن وجهته لا تطابق مسار الرحلة
|
||||
if ($destDistance > 5.0) {
|
||||
error_log("[findBestDrivers] Filtering out driver $did because destination gap is $destDistance km (> 5km)");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($redisMap[$did])) {
|
||||
$driver['distance_km'] = $redisMap[$did]['distance'];
|
||||
$driver['lat'] = $redisMap[$did]['lat'];
|
||||
@@ -190,22 +211,34 @@ function findBestDrivers($con, $lat, $lng, $carType) {
|
||||
} else {
|
||||
$driver['distance_km'] = 999;
|
||||
}
|
||||
|
||||
$filteredDrivers[] = $driver;
|
||||
}
|
||||
|
||||
// الترتيب
|
||||
usort($finalDrivers, function($a, $b) {
|
||||
usort($filteredDrivers, function($a, $b) {
|
||||
return $a['distance_km'] <=> $b['distance_km'];
|
||||
});
|
||||
|
||||
return array_slice($finalDrivers, 0, 30);
|
||||
return array_slice($filteredDrivers, 0, 30);
|
||||
} catch (Exception $e) {
|
||||
error_log("FindBestDrivers Error: " . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// دالة مساعدة لحساب المسافة بين نقطتين جغرافيين
|
||||
function getDistanceBetweenPoints($lat1, $lon1, $lat2, $lon2) {
|
||||
$theta = $lon1 - $lon2;
|
||||
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
|
||||
$dist = acos(max(-1.0, min(1.0, $dist))); // لمنع أخطاء تجاوز نطاق acos
|
||||
$dist = rad2deg($dist);
|
||||
$miles = $dist * 60 * 1.1515;
|
||||
return ($miles * 1.609344); // إرجاع المسافة بالكيلومتر
|
||||
}
|
||||
// --- دالة مساعدة لمخاطبة سيرفر السائقين (Location Socket) ---
|
||||
function notifyDriversRideTaken($rideId, $winnerDriverId) {
|
||||
$url = "http://188.68.36.205:2021";
|
||||
$url = getenv('LOCATION_SERVER_URL') ?: 'http://location.intaleq.xyz:2021';
|
||||
if (!isAllowedSocketUrl($url)) return;
|
||||
$INTERNAL_KEY = function_exists('getInternalSocketKey') ? getInternalSocketKey() : '';
|
||||
|
||||
@@ -227,7 +260,7 @@ function notifyDriversRideTaken($rideId, $winnerDriverId) {
|
||||
curl_close($ch);
|
||||
}
|
||||
function notifyDriversOnLocationServer($drivers_ids_array, $payload, $rideId = null) {
|
||||
$url = "http://188.68.36.205:2021";
|
||||
$url = getenv('LOCATION_SERVER_URL') ?: 'http://location.intaleq.xyz:2021';
|
||||
if (!isAllowedSocketUrl($url)) return null;
|
||||
$INTERNAL_KEY = function_exists('getInternalSocketKey') ? getInternalSocketKey() : '';
|
||||
|
||||
@@ -263,7 +296,7 @@ function notifyDriversOnLocationServer($drivers_ids_array, $payload, $rideId = n
|
||||
* تخاطب السوكيت الموجود محلياً على نفس السيرفر
|
||||
*/
|
||||
function notifyPassengerOnRideServer($passenger_id, $payload) {
|
||||
$url = "http://188.68.36.205:3031";
|
||||
$url = getenv('RIDE_SOCKET_URL') ?: 'http://location.intaleq.xyz:3031';
|
||||
if (!isAllowedSocketUrl($url)) return null;
|
||||
$INTERNAL_KEY = function_exists('getInternalSocketKey') ? getInternalSocketKey() : '';
|
||||
|
||||
@@ -310,7 +343,7 @@ function dispatchRideToDrivers($driversData, $rideId, $payloadTemplate, $startNa
|
||||
$countDrivers = count($driversData);
|
||||
error_log("🚀 [DISPATCH_START] RideID: $rideId | Drivers Count: $countDrivers");
|
||||
|
||||
$socketUrl = 'http://188.68.36.205:2021';
|
||||
$socketUrl = getenv('LOCATION_SERVER_URL') ?: 'http://location.intaleq.xyz:2021';
|
||||
if (!isAllowedSocketUrl($socketUrl)) return;
|
||||
$internalKey = function_exists('getInternalSocketKey') ? getInternalSocketKey() : '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user