-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_code.php
More file actions
176 lines (157 loc) · 8.79 KB
/
search_code.php
File metadata and controls
176 lines (157 loc) · 8.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
// تأمين الملف بكلمة مرور لحماية أكواد موقعك من المتطفلين
define('SEARCH_PASSWORD', '123456'); // قم بتغيير 123456 إلى كلمة مرور قوية خاصة بك
session_start();
if (isset($_GET['logout'])) {
unset($_SESSION['logged_in']);
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
if (isset($_POST['password']) && $_POST['password'] === SEARCH_PASSWORD) {
$_SESSION['logged_in'] = true;
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>تسجيل الدخول لأداة البحث</title>
<style>
body { font-family: Tahoma, sans-serif; background: #f1f5f9; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
.login-box { background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); width: 300px; text-align: center; }
input[type="password"] { width: 100%; padding: 10px; margin: 15px 0; border: 1px solid #cbd5e1; border-radius: 4px; box-sizing: border-box; text-align: center; }
button { background: #2563eb; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; width: 100%; font-weight: bold; }
button:hover { background: #1d4ed8; }
</style>
</head>
<body>
<div class="login-box">
<h3>أداة البحث عن الأكواد</h3>
<form method="post">
<input type="password" name="password" placeholder="أدخل كلمة المرور الفوقية" required>
<button type="submit">دخول</button>
</form>
</div>
</body>
</html>
<?php
exit;
}
// إعدادات البحث الافتراضية
$search_term = isset($_POST['search']) ? $_POST['search'] : '';
$dir_to_search = isset($_POST['dir']) ? $_POST['dir'] : '.';
$ext_filter = isset($_POST['extensions']) ? $_POST['extensions'] : 'php,html,css,js';
$extensions = array_map('trim', explode(',', $ext_filter));
$results = [];
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($search_term)) {
try {
$directory = new RecursiveDirectoryIterator($dir_to_search, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory);
foreach ($iterator as $file) {
if ($file->isFile()) {
$file_ext = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
// التحقق من الامتدادات المحددة للبحث لحفظ الوقت والجهد والسيرفر
if (!empty($ext_filter) && !in_array($file_ext, $extensions)) {
continue;
}
// تجنب قراءة الملفات الضخمة جداً مثل ملفات الـ Zip أو الصور لتفادي بطء السيرفر
if ($file->getSize() > 2 * 1024 * 1024) {
continue;
}
$file_path = $file->getPathname();
$content = file_get_contents($file_path);
if (strpos($content, $search_term) !== false) {
$lines = file($file_path);
foreach ($lines as $line_num => $line) {
if (strpos($line, $search_term) !== false) {
$results[$file_path][] = [
'line' => $line_num + 1,
'content' => htmlspecialchars(trim($line))
];
}
}
}
}
}
} catch (Exception $e) {
$errors[] = "حدث خطأ أثناء قراءة المجلد: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>مستكشف وباحث الأكواد السريع</title>
<style>
body { font-family: Tahoma, sans-serif; background: #f8fafc; color: #334155; margin: 20px; }
.container { max-width: 1000px; margin: 0 auto; background: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #e2e8f0; padding-bottom: 15px; margin-bottom: 20px; }
.logout { color: #ef4444; text-decoration: none; font-size: 14px; font-weight: bold; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 14px; }
input[type="text"] { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 4px; box-sizing: border-box; }
.btn-search { background: #10b981; color: white; border: none; padding: 12px 25px; border-radius: 4px; cursor: pointer; font-weight: bold; width: 100%; font-size: 16px; margin-top: 10px; }
.btn-search:hover { background: #059669; }
.file-block { background: #f1f5f9; border-left: 4px solid #2563eb; padding: 12px; margin-top: 15px; border-radius: 0 4px 4px 0; }
.file-name { font-weight: bold; color: #1e3a8a; word-break: break-all; font-size: 14px; }
.match-line { background: #fff; padding: 6px; margin-top: 5px; border: 1px solid #e2e8f0; border-radius: 4px; font-family: Courier, monospace; font-size: 13px; display: flex; gap: 10px; }
.line-number { color: #ea580c; font-weight: bold; min-width: 50px; border-left: 1px solid #e2e8f0; padding-left: 5px; text-align: center; }
.line-code { color: #334155; white-space: pre-wrap; word-break: break-all; text-align: left; direction: ltr; flex-grow: 1; }
.no-results { background: #fef3c7; color: #b45309; padding: 15px; border-radius: 4px; text-align: center; margin-top: 20px; font-weight: bold; }
.error { background: #fee2e2; color: #b91c1c; padding: 10px; border-radius: 4px; margin-bottom: 15px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>مستكشف وباحث الأكواد السريع 🚀</h2>
<a href="?logout=1" class="logout">تسجيل الخروج</a>
</div>
<?php foreach($errors as $error): ?>
<div class="error"><?php echo $error; ?></div>
<?php endforeach; ?>
<form method="post">
<div class="form-group">
<label>الكلمة أو الكود المراد البحث عنه:</label>
<input type="text" name="search" value="<?php echo htmlspecialchars($search_term); ?>" placeholder="مثال: countItemTypesByUserID أو t_user_packages" required>
</div>
<div class="form-group" style="display: flex; gap: 15px;">
<div style="flex: 1;">
<label>مسار مجلد البحث (النقطة . تعني الموقع بالكامل):</label>
<input type="text" name="dir" value="<?php echo htmlspecialchars($dir_to_search); ?>">
</div>
<div style="flex: 1;">
<label>امتدادات الملفات المستهدفة (مفصولة بفاصلة):</label>
<input type="text" name="extensions" value="<?php echo htmlspecialchars($ext_filter); ?>" placeholder="php, html, css, js">
</div>
</div>
<button type="submit" class="btn-search">بدء البحث الفوري</button>
</form>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST'): ?>
<hr style="border: 0; border-top: 1px solid #e2e8f0; margin: 25px 0;">
<h3>نتائج البحث عن: <span style="color:#2563eb;"><?php echo htmlspecialchars($search_term); ?></span></h3>
<?php if (empty($results)): ?>
<div class="no-results">لم يتم العثور على هذه الكلمة في أي ملف بالامتدادات المحددة.</div>
<?php else: ?>
<p>تم العثور على الكلمة في <strong><?php echo count($results); ?></strong> ملف:</p>
<?php foreach ($results as $path => $matches): ?>
<div class="file-block">
<div class="file-name"> المسار: <?php echo $path; ?></div>
<?php foreach ($matches as $match): ?>
<div class="match-line">
<div class="line-number">سطر <?php echo $match['line']; ?></div>
<div class="line-code"><?php echo $match['content']; ?></div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</div>
</body>
</html>