admin 7
This commit is contained in:
78
ggg.php
Normal file
78
ggg.php
Normal 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.',
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user