Update: 2026-06-12 20:40:40

This commit is contained in:
Hamza-Ayed
2026-06-12 20:40:40 +03:00
parent 305ae01d52
commit f907212c57
294 changed files with 3592 additions and 3581 deletions

View File

View File

@@ -0,0 +1,54 @@
<?php
/**
* Admin/Staff/activate.php
* تفعيل الحسابات المعلقة للمشرفين (Admins) وموظفي خدمة العملاء (Service) من قبل المشرف العام
*/
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../../functions.php';
$userId = filterRequest('user_id');
$type = filterRequest('type'); // 'admin' or 'service'
if (empty($userId) || empty($type)) {
jsonError("رقم المستخدم ونوع الحساب مطلوبان.");
exit;
}
try {
$con = Database::get('main');
// التحقق من صلاحية المشرف العام (Super Admin أو Admin فقط)
$jwtService = new JwtService($redis);
$auth = $jwtService->authenticate();
$authRole = $auth->role ?? '';
if ($authRole !== 'super_admin' && $authRole !== 'admin') {
jsonError("غير مصرح لك. فقط المشرف العام يمكنه تفعيل الحسابات.");
exit;
}
if ($type === 'admin') {
$stmt = $con->prepare("UPDATE adminUser SET status = 'active' WHERE id = :id AND status = 'pending'");
$stmt->execute([':id' => $userId]);
if ($stmt->rowCount() > 0) {
printSuccess(["message" => "تم تفعيل حساب المشرف بنجاح."]);
} else {
jsonError("لم يتم العثور على حساب مشرف معلق بهذا المعرف.");
}
} elseif ($type === 'service') {
$stmt = $con->prepare("UPDATE users SET status = 'approved' WHERE id = :id AND status = 'pending' AND user_type = 'service'");
$stmt->execute([':id' => $userId]);
if ($stmt->rowCount() > 0) {
printSuccess(["message" => "تم تفعيل حساب موظف الخدمة بنجاح."]);
} else {
jsonError("لم يتم العثور على حساب موظف خدمة معلق بهذا المعرف.");
}
} else {
jsonError("نوع حساب غير صالح.");
}
} catch (Exception $e) {
error_log("[Staff Activate Error] " . $e->getMessage());
jsonError("خطأ في السيرفر: " . $e->getMessage());
}
exit();

View File

@@ -7,15 +7,14 @@ require_once __DIR__ . '/../../core/bootstrap.php';
$con = Database::get('main');
// التحقق من الصلاحيات: فقط المشرفين يمكنهم الإضافة
// إذا لم يكن هناك أي مدير في النظام، نسمح// تم تعطيل التحقق للسماح بإعادة التهيئة في مرحلة التطوير
// $count = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
// if ($count > 0) die("Access Denied: Admin already initialized.");
// $auth = JwtService::authenticate($redis);
// if ($auth['role'] !== 'super_admin' && $auth['role'] !== 'admin') {
// jsonError("Unauthorized. Only Admins can add staff.");
// exit;
// }
// التحقق من الصلاحيات: فقط المشرفين (super_admin أو admin) يمكنهم الإضافة
$jwtService = new JwtService($redis);
$auth = $jwtService->authenticate();
$authRole = $auth->role ?? '';
if ($authRole !== 'super_admin' && $authRole !== 'admin') {
jsonError("غير مصرح لك. فقط المشرفون يمكنهم إضافة موظفين.");
exit;
}
$name = filterRequest("name");
$phone = filterRequest("phone");
@@ -47,14 +46,20 @@ try {
if ($role === 'admin') {
// الإضافة لجدول المديرين
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, password, role, created_at)
VALUES (:id, :fp, :fp_hash, :name, :pass, :role, NOW())";
// التأكد من وجود عمود phone في الجدول (كإجراء احترازي لتجنب الأخطاء إذا لم يكن موجوداً)
try {
$con->exec("ALTER TABLE adminUser ADD COLUMN phone VARCHAR(255) NULL AFTER name");
} catch (Exception $e) { /* العمود موجود مسبقاً */ }
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, phone, password, role, created_at)
VALUES (:id, :fp, :fp_hash, :name, :phone, :pass, :role, NOW())";
$stmt = $con->prepare($sql);
$stmt->execute([
':id' => $uniqueId,
':fp' => $encFp,
':fp_hash' => $fpHash,
':name' => $encName,
':phone' => $encPhone,
':pass' => $hashedPassword,
':role' => $role
]);

View File

@@ -0,0 +1,42 @@
<?php
/**
* Admin/Staff/pending.php
* جلب الحسابات المعلقة للإداريين والخدمة
*/
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../../functions.php';
try {
$con = Database::get('main');
// جلب الإداريين المعلقين
$stmt1 = $con->query("SELECT id, name, phone, role, created_at, 'admin' as type FROM adminUser WHERE status = 'pending'");
$admins = $stmt1->fetchAll(PDO::FETCH_ASSOC);
// فك التشفير للأسماء والأرقام للإداريين
foreach ($admins as &$admin) {
$admin['name'] = $encryptionHelper->decryptData($admin['name']) ?: $admin['name'];
$admin['phone'] = $encryptionHelper->decryptData($admin['phone']) ?: $admin['phone'];
}
// جلب موظفي الخدمة المعلقين
$stmt2 = $con->query("SELECT id, first_name, last_name, phone, user_type as role, created_at, 'service' as type FROM users WHERE status = 'pending' AND user_type = 'service'");
$services = $stmt2->fetchAll(PDO::FETCH_ASSOC);
// فك التشفير لموظفي الخدمة
foreach ($services as &$service) {
$service['name'] = trim(($encryptionHelper->decryptData($service['first_name']) ?: $service['first_name']) . ' ' . ($encryptionHelper->decryptData($service['last_name']) ?: $service['last_name']));
$service['phone'] = $encryptionHelper->decryptData($service['phone']) ?: $service['phone'];
}
$allPending = array_merge($admins, $services);
printSuccess([
"data" => $allPending
]);
} catch (Exception $e) {
error_log("[Staff Pending Error] " . $e->getMessage());
jsonError("خطأ في السيرفر: " . $e->getMessage());
}
exit();

0
backend/Admin/adminUser/add_invoice.php Executable file → Normal file
View File

0
backend/Admin/adminUser/invoice_total.php Executable file → Normal file
View File

33
backend/Admin/auth/login.php Executable file → Normal file
View File

@@ -8,6 +8,7 @@ require_once __DIR__ . '/../../functions.php';
$fingerprint = filterRequest('fingerprint');
$password = filterRequest('password');
$phone = filterRequest('phone');
$audience = filterRequest('aud') ?? 'admin';
$isRenewal = filterRequest('is_renewal') === '1';
@@ -16,6 +17,10 @@ if (empty($fingerprint) || empty($password)) {
exit;
}
// Rate Limiting: 5 محاولات في الدقيقة لكل IP
$rateLimiter = new RateLimiter($redis);
$rateLimiter->enforce(RateLimiter::identifier(), 'login');
try {
$con = Database::get('main');
@@ -25,6 +30,28 @@ try {
$stmt->execute([':fp' => $fpHash]);
$admin = $stmt->fetch(PDO::FETCH_ASSOC);
// إذا لم يتم العثور بالبصمة، وتم تمرير رقم الهاتف (تسجيل دخول لأول مرة أو جهاز جديد)
if (!$admin && !empty($phone)) {
$encPhoneInput = $encryptionHelper->encryptData($phone);
$stmtPhone = $con->prepare("SELECT * FROM adminUser WHERE phone = :phone LIMIT 1");
$stmtPhone->execute([':phone' => $encPhoneInput]);
$admin = $stmtPhone->fetch(PDO::FETCH_ASSOC);
// تأكيد كلمة المرور وتحديث بصمة الجهاز إذا تم إيجاد الحساب
if ($admin && password_verify($password, $admin['password'])) {
$encFpRaw = $encryptionHelper->encryptData($fingerprint);
$updateStmt = $con->prepare("UPDATE adminUser SET fingerprint = :fp_raw, fingerprint_hash = :fp WHERE id = :id");
$updateStmt->execute([
':fp_raw' => $encFpRaw,
':fp' => $fpHash,
':id' => $admin['id']
]);
$admin['fingerprint_hash'] = $fpHash; // Update locally
} else if ($admin) {
// Password incorrect, fail later.
}
}
if ($admin) {
// 1. التحقق من حالة الحساب
if ($admin['status'] === 'pending') {
@@ -69,8 +96,8 @@ try {
exit;
}
// 3. توليد رمز تحقق OTP وإرساله عبر WhatsApp
$otp = rand(10000, 99999);
// 3. توليد رمز تحقق OTP (6 أرقام) وإرساله عبر WhatsApp
$otp = rand(100000, 999999);
$encryptedPhone = $admin['phone'] ?? '';
if (empty($encryptedPhone)) {
@@ -112,7 +139,7 @@ try {
jsonError("كلمة المرور غير صحيحة.");
}
} else {
jsonError("الجهاز غير مسجل كمشرف.");
jsonError("الحساب أو الجهاز غير مسجل. يرجى إدخال رقم هاتفك وكلمة المرور إذا كان هذا أول تسجيل دخول لك.");
}
} catch (Exception $e) {
error_log("[Admin Login Error] " . $e->getMessage());

View File

@@ -1,9 +1,10 @@
<?php
/**
* Admin/auth/register.php
* التسجيل الذاتي للمشرفين - الحساب يكون بحالة pending بانتظار موافقة السوبر أدمن
* التسجيل الذاتي للمشرفين (Admins) مع التحقق من الصلاحيات من ملف .env
*/
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../../functions.php';
$name = filterRequest('name');
$phone = filterRequest('phone');
@@ -11,49 +12,75 @@ $password = filterRequest('password');
$fingerprint = filterRequest('fingerprint');
if (empty($name) || empty($phone) || empty($password) || empty($fingerprint)) {
jsonError("All fields are required.");
jsonError("جميع الحقول مطلوبة بما فيها بصمة الجهاز.");
exit;
}
try {
$con = Database::get('main');
// 1. التحقق من عدم وجود الحساب مسبقاً (عن طريق الهاتف أو البصمة)
$fpHash = hash('sha256', $fingerprint);
$check = $con->prepare("SELECT id FROM adminUser WHERE phone = ? OR fingerprint_hash = ? LIMIT 1");
$check->execute([$phone, $fpHash]);
// 1. التحقق من البيئة (Environment Whitelist)
$allowedPhonesStr = getenv('AUTHORIZED_ADMIN_PHONES');
if (!$allowedPhonesStr) {
// في حال لم يتم إعداد المتغير، نرفض الجميع للأمان
jsonError("غير مصرح لك بالتسجيل كمشرف (القائمة البيضاء غير معدة).");
exit;
}
if ($check->rowCount() > 0) {
jsonError("هذا الحساب أو الجهاز مسجل مسبقاً.");
$allowedPhones = array_map('trim', explode(',', $allowedPhonesStr));
if (!in_array($phone, $allowedPhones)) {
jsonError("أنت غير مصرح لك بالتسجيل كمشرف. يرجى مراجعة الإدارة.");
exit;
}
// 2. تجهيز البيانات
$id = bin2hex(random_bytes(16));
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$encName = $encryptionHelper->encryptData($name);
$encFp = $encryptionHelper->encryptData($fingerprint);
$con = Database::get('main');
// 3. الإدخال في قاعدة البيانات (الحالة الافتراضية هي pending)
$sql = "INSERT INTO adminUser (id, name, phone, password, fingerprint, fingerprint_hash, role, status, created_at)
VALUES (:id, :name, :phone, :pass, :fp, :fp_hash, 'admin', 'pending', NOW())";
// 2. التحقق من عدم وجود الحساب مسبقاً (عن طريق الهاتف أو البصمة)
$fpHash = hash('sha256', $fingerprint);
$encPhoneInput = $encryptionHelper->encryptData($phone);
$check = $con->prepare("SELECT id FROM adminUser WHERE phone = ? OR fingerprint_hash = ? LIMIT 1");
$check->execute([$encPhoneInput, $fpHash]);
if ($check->rowCount() > 0) {
jsonError("رقم الهاتف أو الجهاز مسجل مسبقاً.");
exit;
}
// 3. تجهيز البيانات
$uniqueId = bin2hex(random_bytes(16)); // UUID آمن (32 حرف hex عشوائي)
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$encName = $encryptionHelper->encryptData($name);
$encPhone = $encPhoneInput;
$encFp = $encryptionHelper->encryptData($fingerprint);
// التأكد من وجود عمود phone و status في الجدول
try {
$con->exec("ALTER TABLE adminUser ADD COLUMN phone VARCHAR(255) NULL AFTER name");
$con->exec("ALTER TABLE adminUser ADD COLUMN status VARCHAR(50) DEFAULT 'pending' AFTER role");
} catch (Exception $e) { /* الأعمدة موجودة مسبقاً */ }
// 4. الإدخال في قاعدة البيانات بحالة pending
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, phone, password, role, status, created_at)
VALUES (:id, :fp, :fp_hash, :name, :phone, :pass, 'admin', 'pending', NOW())";
$stmt = $con->prepare($sql);
$stmt->execute([
':id' => $id,
':name' => $encName,
':phone' => $phone,
':pass' => $hashedPassword,
':id' => $uniqueId,
':fp' => $encFp,
':fp_hash' => $fpHash
':fp_hash' => $fpHash,
':name' => $encName,
':phone' => $encPhone,
':pass' => $hashedPassword
]);
printSuccess([
"status" => "pending",
"message" => "تم تقديم طلب التسجيل بنجاح. يرجى انتظار موافقة الإدارة."
"message" => "تم تسجيل حسابك بنجاح وهو الآن قيد المراجعة. يرجى انتظار تفعيل المشرف العام."
]);
} catch (Exception $e) {
error_log("[Admin Register Error] " . $e->getMessage());
jsonError("خطأ في السيرفر: " . $e->getMessage());
}
exit();

0
backend/Admin/auth/send_otp_admin.php Executable file → Normal file
View File

View File

@@ -15,6 +15,10 @@ if (empty($otp) || empty($fingerprint)) {
exit;
}
// Rate Limiting: 3 محاولات OTP في 5 دقائق لكل IP
$rateLimiter = new RateLimiter($redis);
$rateLimiter->enforce(RateLimiter::identifier(), 'otp');
try {
$con = Database::get('main');

0
backend/Admin/auth/verify_otp_admin.php Executable file → Normal file
View File

0
backend/Admin/driver/deleteCaptain.php Executable file → Normal file
View File

0
backend/Admin/driver/deleteRecord.php Executable file → Normal file
View File

0
backend/Admin/driver/find_driver_by_phone.php Executable file → Normal file
View File

0
backend/Admin/driver/getBestDriver.php Executable file → Normal file
View File

0
backend/Admin/driver/getDriverGiftPayment.php Executable file → Normal file
View File

0
backend/Admin/driver/remove_from_blacklist.php Executable file → Normal file
View File

0
backend/Admin/driver/updateDriverFromAdmin.php Executable file → Normal file
View File

0
backend/Admin/employee/add.php Executable file → Normal file
View File

0
backend/Admin/employee/get.php Executable file → Normal file
View File

0
backend/Admin/error/error_list_last20.php Executable file → Normal file
View File

0
backend/Admin/error/error_search_by_phone.php Executable file → Normal file
View File

0
backend/Admin/errorApp.php Executable file → Normal file
View File

0
backend/Admin/facebook.php Executable file → Normal file
View File

4
backend/Admin/jwtService.php Executable file → Normal file
View File

@@ -45,8 +45,8 @@ try {
$startTime = microtime(true);
// دعم password_verify مع البقاء على التوافق مع كلمات السر القديمة (Plain Text)
if ($user && (password_verify($password, $user['password']) || $user['password'] === $password)) {
// التحقق من كلمة المرور باستخدام password_hash فقط (الأمان)
if ($user && password_verify($password, $user['password'])) {
$limiter->reset(RateLimiter::identifier(), 'login');

View File

0
backend/Admin/passenger/admin_unblacklist.php Executable file → Normal file
View File

0
backend/Admin/passenger/admin_update_passenger.php Executable file → Normal file
View File

0
backend/Admin/rides/admin_get_rides_by_phone.php Executable file → Normal file
View File

0
backend/Admin/rides/admin_update_ride_status.php Executable file → Normal file
View File

0
backend/Admin/rides/get_driver_live_pos.php Executable file → Normal file
View File

0
backend/Admin/rides/get_rides_by_status.php Executable file → Normal file
View File

0
backend/Admin/rides/monitorRide.php Executable file → Normal file
View File

0
backend/Admin/send_whatsapp_message.php Executable file → Normal file
View File

0
backend/Admin/view_errors.php Executable file → Normal file
View File