feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
//encrypt_decrypt.php
|
||||
// ⚠️ هذا الملف للتوافقية فقط. استخدم core/Security/EncryptionHelper.php للتشفير الجديد
|
||||
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
require_once 'load_env.php';
|
||||
$siteUser = get_current_user();
|
||||
$homeDir = "/home/$siteUser";
|
||||
if (!is_dir($homeDir)) {
|
||||
$homeDir = realpath(__DIR__ . '/../../../'); // Fallback
|
||||
}
|
||||
|
||||
$env_file = getenv('ENV_FILE_PATH') ?: ($homeDir . '/.env');
|
||||
if (!file_exists($env_file)) {
|
||||
$env_file = __DIR__ . '/../.env';
|
||||
}
|
||||
loadEnvironment($env_file);
|
||||
|
||||
if (!getenv('ENCRYPTION_KEY_PATH')) {
|
||||
$encKeyDefault = "$homeDir/.enckey";
|
||||
putenv("ENCRYPTION_KEY_PATH=$encKeyDefault");
|
||||
$_ENV['ENCRYPTION_KEY_PATH'] = $encKeyDefault;
|
||||
}
|
||||
|
||||
// ✅ FIX C-02: استخدام getenv بدلاً من file_get_contents الثابت
|
||||
$keyPath = getenv('ENCRYPTION_KEY_PATH');
|
||||
$key = '';
|
||||
if ($keyPath && file_exists($keyPath)) {
|
||||
$key = trim(file_get_contents($keyPath));
|
||||
}
|
||||
if (!$key) {
|
||||
$key = getenv('ENC_KEY') ?: '';
|
||||
}
|
||||
$iv = getenv('initializationVector'); // 16 bytes
|
||||
|
||||
|
||||
class EncryptionHelper {
|
||||
private $key;
|
||||
private $iv;
|
||||
|
||||
public function __construct($key, $iv) {
|
||||
if (strlen($key) !== 32) {
|
||||
throw new Exception("❌ المفتاح (Key) لازم يكون 32 بايت.");
|
||||
}
|
||||
if (strlen($iv) !== 16) {
|
||||
throw new Exception("❌ الـ IV لازم يكون 16 بايت.");
|
||||
}
|
||||
|
||||
$this->key = $key;
|
||||
$this->iv = $iv;
|
||||
}
|
||||
|
||||
// --------- النصوص ----------
|
||||
private function addPadding($data, $blockSize = 16) {
|
||||
$pad = $blockSize - (strlen($data) % $blockSize);
|
||||
return $data . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
private function removePadding($data) {
|
||||
$pad = ord($data[strlen($data) - 1]);
|
||||
return substr($data, 0, -$pad);
|
||||
}
|
||||
|
||||
public function encryptData($plainText) {
|
||||
$plainText = mb_convert_encoding($plainText, 'UTF-8');
|
||||
$paddedText = $this->addPadding($plainText);
|
||||
$iv = random_bytes(16);
|
||||
$encrypted = openssl_encrypt($paddedText, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $iv);
|
||||
return base64_encode($iv . $encrypted);
|
||||
}
|
||||
|
||||
public function decryptData($encryptedText) {
|
||||
$decoded = base64_decode($encryptedText, true);
|
||||
|
||||
if ($decoded === false) {
|
||||
error_log("[ERROR] base64_decode failed for input: $encryptedText");
|
||||
return false;
|
||||
}
|
||||
|
||||
// محاولة أولى: استخراج IV عشوائي من أول 16 بايت
|
||||
if (strlen($decoded) >= 16) {
|
||||
$iv = substr($decoded, 0, 16);
|
||||
$payload = substr($decoded, 16);
|
||||
|
||||
$decrypted = openssl_decrypt($payload, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $iv);
|
||||
|
||||
if ($decrypted !== false) {
|
||||
$pad = ord($decrypted[strlen($decrypted) - 1]);
|
||||
if ($pad >= 1 && $pad <= 16) {
|
||||
return substr($decrypted, 0, -$pad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// محاولة ثانية: IV ثابت (للبيانات القديمة)
|
||||
$decrypted = openssl_decrypt($decoded, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
|
||||
|
||||
if ($decrypted === false) {
|
||||
error_log("[ERROR] openssl_decrypt failed for input: $encryptedText");
|
||||
return false;
|
||||
}
|
||||
|
||||
$pad = ord($decrypted[strlen($decrypted) - 1]);
|
||||
if ($pad < 1 || $pad > 16) {
|
||||
error_log("[ERROR] Invalid padding value ($pad) for decrypted input: $encryptedText");
|
||||
return false;
|
||||
}
|
||||
|
||||
return substr($decrypted, 0, -$pad);
|
||||
}
|
||||
|
||||
public function decryptFile($encryptedFilePath, $destinationPath) {
|
||||
if (!file_exists($encryptedFilePath)) {
|
||||
throw new Exception("❌ الملف المشفر غير موجود: $encryptedFilePath");
|
||||
}
|
||||
|
||||
$encryptedData = file_get_contents($encryptedFilePath);
|
||||
$decryptedData = openssl_decrypt($encryptedData, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
|
||||
|
||||
if ($decryptedData === false) {
|
||||
error_log("[ERROR] openssl_decrypt failed for file: $encryptedFilePath");
|
||||
throw new Exception("❌ فشل فك تشفير الملف: $encryptedFilePath");
|
||||
}
|
||||
|
||||
file_put_contents($destinationPath, $decryptedData);
|
||||
return true;
|
||||
}
|
||||
public function encryptBinary($data) {
|
||||
$iv = random_bytes(16);
|
||||
$encrypted = openssl_encrypt($data, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $iv);
|
||||
return $iv . $encrypted;
|
||||
}
|
||||
|
||||
public function decryptBinary($data) {
|
||||
if (strlen($data) >= 16) {
|
||||
$iv = substr($data, 0, 16);
|
||||
$payload = substr($data, 16);
|
||||
$decrypted = openssl_decrypt($payload, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $iv);
|
||||
if ($decrypted !== false) {
|
||||
return $decrypted;
|
||||
}
|
||||
}
|
||||
|
||||
// للبيانات القديمة ذات IV الثابت
|
||||
$decrypted = openssl_decrypt($data, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
|
||||
if ($decrypted === false) {
|
||||
error_log('[CRIT-07] openssl_decrypt failed in decryptBinary');
|
||||
throw new Exception('Decryption failed');
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
}
|
||||
// ✅ Load the key and IV from .env or use default values
|
||||
|
||||
// ✅ Ensure the lengths are correct
|
||||
//echo "Key Length: " . $key . PHP_EOL;
|
||||
//echo "IV Length: " . $iv . PHP_EOL;
|
||||
|
||||
try {
|
||||
$encryptionHelper = new EncryptionHelper($key, $iv);
|
||||
} catch (Exception $e) {
|
||||
error_log("[encrypt_decrypt] Initialization error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user