Skip to content

Commit ad7ccec

Browse files
committed
رفع ملف استقبال الوكيل على onlainee.space
1 parent 2ba5ad2 commit ad7ccec

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* ملف استقبال بيانات الوكيل الذكي
4+
* المخصص لدومين onlainee.space
5+
* تم إنشاؤه بواسطة Zapier في Nov 18, 2025 08:42:42 PM
6+
*/
7+
8+
header('Content-Type: application/json; charset=utf-8');
9+
header('Access-Control-Allow-Origin: *');
10+
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
11+
header('Access-Control-Allow-Headers: Content-Type, X-Agent-Token, X-Agent-Source');
12+
13+
// معالجة طلبات OPTIONS
14+
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
15+
exit(0);
16+
}
17+
18+
// التحقق من طريقة الطلب
19+
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
20+
http_response_code(405);
21+
echo json_encode([
22+
'error' => 'Method not allowed',
23+
'allowed_methods' => ['POST'],
24+
'server' => 'onlainee.space'
25+
], JSON_UNESCAPED_UNICODE);
26+
exit;
27+
}
28+
29+
// التحقق من المفتاح الأمني
30+
$headers = getallheaders();
31+
$expected_token = 'QweAsdZxc@555_SECURE';
32+
33+
if (!isset($headers['X-Agent-Token']) || $headers['X-Agent-Token'] !== $expected_token) {
34+
http_response_code(401);
35+
echo json_encode([
36+
'error' => 'Unauthorized - Invalid token',
37+
'server' => 'onlainee.space',
38+
'timestamp' => date('Y-m-d H:i:s')
39+
], JSON_UNESCAPED_UNICODE);
40+
exit;
41+
}
42+
43+
// قراءة البيانات الواردة
44+
$input = file_get_contents('php://input');
45+
$data = json_decode($input, true);
46+
47+
if (!$data) {
48+
http_response_code(400);
49+
echo json_encode([
50+
'error' => 'Invalid JSON format',
51+
'received_data' => substr($input, 0, 200)
52+
], JSON_UNESCAPED_UNICODE);
53+
exit;
54+
}
55+
56+
// ملفات التسجيل
57+
$reports_file = __DIR__ . '/agent_reports.json';
58+
$activity_log = __DIR__ . '/agent_activity.log';
59+
$error_log = __DIR__ . '/agent_errors.log';
60+
61+
try {
62+
// قراءة التقارير الحالية
63+
$reports = [];
64+
if (file_exists($reports_file)) {
65+
$reports = json_decode(file_get_contents($reports_file), true) ?: [];
66+
}
67+
68+
// إضافة معلومات الخادم
69+
$data['received_at'] = date('Y-m-d H:i:s');
70+
$data['server_domain'] = 'onlainee.space';
71+
$data['server_ip'] = $_SERVER['SERVER_ADDR'] ?? gethostbyname($_SERVER['SERVER_NAME']);
72+
$data['processed_by'] = 'onlainee-webhook-v1.0';
73+
$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'] ?? 'unknown';
74+
75+
// إضافة التقرير الجديد
76+
$reports[] = $data;
77+
78+
// الاحتفاظ بآخر 150 تقرير
79+
if (count($reports) > 150) {
80+
$reports = array_slice($reports, -150);
81+
}
82+
83+
// حفظ التقارير
84+
file_put_contents($reports_file, json_encode($reports, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
85+
86+
// تسجيل النشاط
87+
$log_entry = date('[Y-m-d H:i:s] ') . "SUCCESS: {$data['agent_name']} - Status: {$data['status']} - Tasks: {$data['tasks_completed']}\n";
88+
file_put_contents($activity_log, $log_entry, FILE_APPEND | LOCK_EX);
89+
90+
// معالجة التقارير الناجحة
91+
if ($data['status'] === 'completed') {
92+
processSuccessfulReport($data);
93+
}
94+
95+
// إرسال رد ناجح
96+
echo json_encode([
97+
'status' => 'success',
98+
'message' => 'تم استلام التقرير بنجاح',
99+
'report_id' => count($reports),
100+
'timestamp' => date('c'),
101+
'server_info' => [
102+
'domain' => 'onlainee.space',
103+
'php_version' => PHP_VERSION,
104+
'server_time' => date('Y-m-d H:i:s'),
105+
'total_reports' => count($reports)
106+
],
107+
'received_data' => [
108+
'agent_name' => $data['agent_name'],
109+
'report_date' => $data['report_date'],
110+
'tasks_completed' => $data['tasks_completed']
111+
]
112+
], JSON_UNESCAPED_UNICODE);
113+
114+
} catch (Exception $e) {
115+
// تسجيل الأخطاء
116+
$error_entry = date('[Y-m-d H:i:s] ') . "ERROR: " . $e->getMessage() . "\n";
117+
file_put_contents($error_log, $error_entry, FILE_APPEND | LOCK_EX);
118+
119+
http_response_code(500);
120+
echo json_encode([
121+
'status' => 'error',
122+
'message' => 'خطأ في معالجة التقرير',
123+
'error_details' => $e->getMessage(),
124+
'timestamp' => date('c')
125+
], JSON_UNESCAPED_UNICODE);
126+
}
127+
128+
function processSuccessfulReport($data) {
129+
// معالجة إضافية للتقارير الناجحة
130+
$success_log = __DIR__ . '/successful_reports.log';
131+
$entry = date('[Y-m-d H:i:s] ') . "COMPLETED: Agent '{$data['agent_name']}' finished {$data['tasks_completed']} tasks\n";
132+
file_put_contents($success_log, $entry, FILE_APPEND | LOCK_EX);
133+
134+
// يمكن إضافة المزيد من المعالجة هنا:
135+
// - إرسال إشعارات
136+
// - تحديث قواعد البيانات
137+
// - تشغيل مهام إضافية
138+
139+
return true;
140+
}
141+
?>

0 commit comments

Comments
 (0)