chore: استيراد أولي من سيرو (ecfe7568) — بلا أي تعديل
نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* generate_mock_data.php
|
||||
* Standalone JWT & Price Token generator for Stress Test.
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
|
||||
ini_set('display_errors', '0');
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'] ?? 'POST';
|
||||
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
|
||||
|
||||
// Load bootstrap if available for EncryptionHelper
|
||||
$bootstrapPath = dirname(__DIR__) . '/backend/core/bootstrap.php';
|
||||
if (file_exists($bootstrapPath)) {
|
||||
try {
|
||||
require_once $bootstrapPath;
|
||||
} catch (Throwable $e) {}
|
||||
}
|
||||
|
||||
// Fallback .env loader
|
||||
$loadedFiles = [];
|
||||
function loadEnvFile(string $path): void {
|
||||
global $loadedFiles;
|
||||
if (!file_exists($path)) {
|
||||
$loadedFiles[] = "NOT_FOUND: $path";
|
||||
return;
|
||||
}
|
||||
$loadedFiles[] = "LOADED: $path";
|
||||
foreach (file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
||||
$line = trim($line);
|
||||
if (empty($line) || $line[0] === '#' || strpos($line, '=') === false) continue;
|
||||
[$name, $value] = explode('=', $line, 2);
|
||||
$val = trim($value, "\"'");
|
||||
putenv(trim($name) . '=' . $val);
|
||||
$_ENV[trim($name)] = $val;
|
||||
$_SERVER[trim($name)] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
loadEnvFile(dirname(__DIR__) . '/docker/.env');
|
||||
loadEnvFile(dirname(__DIR__) . '/backend/.env');
|
||||
|
||||
function getJwtSecret(): string {
|
||||
$keyPath = getenv('JWT_SECRET_KEY_PATH');
|
||||
if ($keyPath && file_exists($keyPath)) {
|
||||
return trim(file_get_contents($keyPath));
|
||||
}
|
||||
$key = getenv('JWT_SECRET_KEY') ?: ($_ENV['JWT_SECRET_KEY'] ?? '');
|
||||
if ($key) return $key;
|
||||
$key = getenv('JWT_SECRET') ?: ($_ENV['JWT_SECRET'] ?? '');
|
||||
if ($key) return $key;
|
||||
return '';
|
||||
}
|
||||
|
||||
function base64url_encode(string $data): string {
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
function generate_jwt(string $secret, array $payload): string {
|
||||
$header = base64url_encode(json_encode(['alg' => 'HS256', 'typ' => 'JWT']));
|
||||
$body = base64url_encode(json_encode($payload));
|
||||
$sig = base64url_encode(hash_hmac('sha256', "$header.$body", $secret, true));
|
||||
return "$header.$body.$sig";
|
||||
}
|
||||
|
||||
$secret = getJwtSecret();
|
||||
if (empty($secret)) {
|
||||
echo json_encode(['error' => 'JWT secret not found in any .env', 'jwt' => '']);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$userId = $argv[1] ?? '999999';
|
||||
$role = $argv[2] ?? 'driver';
|
||||
|
||||
$aud = ($role === 'driver') ? (getenv('allowedDriver2') ?: 'driver-app:ios') : (getenv('allowed2') ?: 'passenger-app:ios');
|
||||
$fpPepper = getenv('FP_PEPPER') ?: ($_ENV['FP_PEPPER'] ?? '');
|
||||
$fpHeader = 'mock_device_fp_' . $userId;
|
||||
$fpInToken = (!empty($fpPepper)) ? hash('sha256', $fpHeader . $fpPepper) : null;
|
||||
|
||||
$payload = [
|
||||
'iss' => getenv('APP_ISSUER') ?: 'SiroApp',
|
||||
'aud' => $aud,
|
||||
'user_id' => (string)$userId,
|
||||
'sub' => (string)$userId,
|
||||
'role' => $role,
|
||||
'token_type' => 'access',
|
||||
'jti' => bin2hex(random_bytes(16)),
|
||||
'iat' => time(),
|
||||
'exp' => time() + 86400,
|
||||
];
|
||||
if ($fpInToken) {
|
||||
$payload['fingerPrint'] = $fpInToken;
|
||||
}
|
||||
|
||||
$jwt = generate_jwt($secret, $payload);
|
||||
|
||||
// Generate encrypted price token for passenger matching add_ride.php
|
||||
$priceToken = '';
|
||||
if ($role === 'passenger') {
|
||||
$tokenData = json_encode([
|
||||
'passenger_id' => (string)$userId,
|
||||
'start_location' => '31.95,35.91',
|
||||
'end_location' => '31.96,35.92',
|
||||
'expires' => time() + 86400,
|
||||
'prices' => [
|
||||
'Economy' => [
|
||||
'price' => '5',
|
||||
'driver_price' => '4.5'
|
||||
]
|
||||
]
|
||||
]);
|
||||
if (isset($GLOBALS['encryptionHelper']) && is_object($GLOBALS['encryptionHelper'])) {
|
||||
$priceToken = $GLOBALS['encryptionHelper']->encryptData($tokenData);
|
||||
} elseif (isset($encryptionHelper) && is_object($encryptionHelper)) {
|
||||
$priceToken = $encryptionHelper->encryptData($tokenData);
|
||||
} else {
|
||||
try {
|
||||
$encKey = getenv('ENCRYPTION_KEY') ?: $secret;
|
||||
$keyBytes = substr(hash('sha256', $encKey, true), 0, 32);
|
||||
$iv = random_bytes(12);
|
||||
$tag = '';
|
||||
$ciphertext = openssl_encrypt($tokenData, 'aes-256-gcm', $keyBytes, OPENSSL_RAW_DATA, $iv, $tag);
|
||||
$priceToken = 'GCM:' . base64_encode($iv) . ':' . base64_encode($ciphertext . $tag);
|
||||
} catch (Throwable $e) {
|
||||
$priceToken = 'dummy';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'user_id' => $userId,
|
||||
'role' => $role,
|
||||
'jwt' => $jwt,
|
||||
'fp' => $fpHeader,
|
||||
'price_token' => $priceToken
|
||||
]);
|
||||
Reference in New Issue
Block a user