This commit is contained in:
Hamza-Ayed
2026-04-30 17:14:37 +03:00
parent a4c1638fb0
commit 2ca910ec32
2 changed files with 101 additions and 0 deletions

78
ggg.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
include 'connect.php';
// نضمن أن الرد دائماً JSON
header('Content-Type: application/json; charset=utf-8');
// 1) قراءة الـ body كـ JSON (من Flutter)
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
if (!is_array($data)) {
// fallback لو أرسلت form-data أو x-www-form-urlencoded
$data = $_POST;
}
// 2) التحقق من رقم هاتف الأدمن المصرّح له
// قراءة الأرقام المسموح لها من الـ ENV
$phonesRaw = getenv('ADMIN_PHONE_NUMBERS') ?: '';
$ALLOWED_TOOL_PHONES = array_values(
array_filter(
array_map(function ($p) {
// إزالة أي رموز غير رقمية (مسافات، +، - إلخ)
return preg_replace('/\D+/', '', $p);
}, explode(',', $phonesRaw))
)
);
// رقم الهاتف القادم من Flutter (parameter جديد)
$adminPhoneParam = isset($data['admin_phone'])
? preg_replace('/\D+/', '', $data['admin_phone'])
: '';
// إذا لم يُرسل رقم أو لم يكن ضمن القائمة → منع الوصول
if ($adminPhoneParam === '' || !in_array($adminPhoneParam, $ALLOWED_TOOL_PHONES, true)) {
http_response_code(403);
echo json_encode([
'status' => 'error',
'message' => 'Access denied for this admin phone.',
]);
exit;
}
// 3) التحقق من بقية المدخلات (action + text)
$action = $data['action'] ?? '';
$text = trim($data['text'] ?? '');
if ($text === '' || ($action !== 'encrypt' && $action !== 'decrypt')) {
http_response_code(400);
echo json_encode([
'status' => 'error',
'message' => 'Invalid input: need action=encrypt|decrypt and non-empty text.',
]);
exit;
}
// 4) تنفيذ التشفير / الفك
try {
// require_once __DIR__ . '/encrypt_decrypt.php';
if ($action === 'encrypt') {
$result = $encryptionHelper->encryptData($text);
} else { // decrypt
$result = $encryptionHelper->decryptData($text);
}
echo json_encode([
'status' => 'success',
'action' => $action,
'result' => (string) $result,
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => 'Operation failed.',
]);
}

23
scratch_db_check.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
require_once 'connect.php';
echo "--- ADMIN TABLE ---\n";
try {
$stmt = $con->prepare("SELECT id, name, role FROM admin");
$stmt->execute();
$admins = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($admins);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
echo "\n--- DATABASES ---\n";
try {
$stmt = $con->prepare("SHOW DATABASES");
$stmt->execute();
$dbs = $stmt->fetchAll(PDO::FETCH_COLUMN);
print_r($dbs);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>