Repository navigation
Expand file tree
/
Copy pathgo.php
More file actions
313 lines (280 loc) · 13.1 KB
/
Copy pathgo.php
File metadata and controls
313 lines (280 loc) · 13.1 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
// go.php - 处理短链跳转
require_once __DIR__ . '/config.php';
function loadData() {
$content = file_get_contents(DATA_FILE);
$data = json_decode($content, true);
if (!isset($data['links'])) $data['links'] = [];
if (!isset($data['total_clicks'])) $data['total_clicks'] = 0;
if (!isset($data['recent'])) $data['recent'] = [];
if (!isset($data['blocked_ips'])) $data['blocked_ips'] = [];
return $data;
}
function saveData($data) {
file_put_contents(DATA_FILE, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
function checkSensitiveUrl($url) {
$sensitiveWords = SENSITIVE_WORDS;
$foundWords = [];
$urlLower = strtolower($url);
foreach ($sensitiveWords as $word) {
if (stripos($urlLower, strtolower($word)) !== false) {
$foundWords[] = $word;
}
}
return ['is_risky' => count($foundWords) >= RISK_THRESHOLD, 'found_words' => $foundWords];
}
function deepCheckPage($url) {
$sensitiveWords = SENSITIVE_WORDS;
$foundWords = [];
if (strpos($url, SITE_URL) === 0) {
return ['is_risky' => false, 'found_words' => []];
}
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$content = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$redirectUrl = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
curl_close($ch);
if ($httpCode >= 300 && $httpCode < 400 && $redirectUrl) {
if (strpos($redirectUrl, SITE_URL) === 0) {
return ['is_risky' => false, 'found_words' => []];
}
return deepCheckPage($redirectUrl);
}
if ($content === false || $httpCode >= 400) {
return ['is_risky' => false, 'found_words' => []];
}
$contentLower = mb_strtolower($content, 'UTF-8');
foreach ($sensitiveWords as $word) {
$wordLower = mb_strtolower($word, 'UTF-8');
if (mb_strpos($contentLower, $wordLower) !== false) {
$foundWords[] = $word;
}
}
return ['is_risky' => count($foundWords) >= RISK_THRESHOLD, 'found_words' => $foundWords];
}
$code = isset($_GET['code']) ? $_GET['code'] : '';
if (empty($code)) {
$path_info = $_SERVER['PATH_INFO'] ?? '';
if (!empty($path_info)) {
$code = trim($path_info, '/');
}
}
if (empty($code)) {
header('Location: ' . SITE_URL);
exit;
}
$data = loadData();
if (!isset($data['links'][$code])) {
header('Location: ' . SITE_URL . '?error=not_found');
exit;
}
$link = &$data['links'][$code];
$status = $link['status'] ?? 'normal';
$autoCheck = !($link['manual_override'] ?? false);
// 检测循环引用
if (FORBIDDEN_LOOP && strpos($link['url'], SITE_URL) === 0) {
$target_code = str_replace(SITE_URL . '/', '', rtrim($link['url'], '/'));
if ($target_code === $code) {
$link['status'] = 'banned';
$link['risk_reason'] = '检测到自循环引用,已自动封禁';
saveData($data);
showBannedPage();
exit;
}
}
if ($status === 'banned') {
showBannedPage();
exit;
}
if ($status === 'risk') {
showRiskPage($link['risk_reason'] ?? '检测到敏感内容');
exit;
}
// AJAX 深度检测
if (isset($_GET['deep_check'])) {
header('Content-Type: application/json');
$urlCheck = checkSensitiveUrl($link['url']);
if ($urlCheck['is_risky']) {
$riskReason = '该链接包含不安全内容,已被系统拦截';
$link['status'] = 'risk';
$link['risk_reason'] = $riskReason;
saveData($data);
echo json_encode(['safe' => false, 'reason' => $riskReason]);
exit;
}
$pageCheck = deepCheckPage($link['url']);
if ($pageCheck['is_risky']) {
$riskReason = '该链接包含不安全内容,已被系统拦截';
$link['status'] = 'risk';
$link['risk_reason'] = $riskReason;
saveData($data);
echo json_encode(['safe' => false, 'reason' => $riskReason]);
exit;
}
$link['clicks']++;
$data['total_clicks']++;
saveData($data);
echo json_encode(['safe' => true]);
exit;
}
// 需要检测的正常状态
if ($autoCheck && $status === 'normal') {
showLoadingPage($code, $link['url']);
exit;
}
// 正常跳转
$link['clicks']++;
$data['total_clicks']++;
saveData($data);
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $link['url']);
exit;
function showLoadingPage($code, $targetUrl) {
$defaultBg = 'https://cdn.jsdmirror.com/gh/lqay-cn/cdn@main/img/zx/h/真寻170.png';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>安全检测中...</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; min-height: 100vh; background: url('<?php echo $defaultBg; ?>') center/cover no-repeat fixed; display: flex; justify-content: center; align-items: center; position: relative; }
body::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 0; }
.loading-card { position: relative; z-index: 1; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-radius: 28px; padding: 45px 40px; text-align: center; max-width: 380px; width: 85%; animation: fadeIn 0.3s ease; }
.result-card { position: relative; z-index: 1; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-radius: 28px; padding: 35px; text-align: center; max-width: 450px; width: 85%; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.spinner { width: 50px; height: 50px; margin: 0 auto 20px; border: 3px solid #f0f0f0; border-top: 3px solid #f472b6; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.loading-text { font-size: 18px; font-weight: 600; color: #333; margin-bottom: 8px; }
.loading-sub { color: #888; font-size: 13px; }
.tip { margin-top: 20px; font-size: 11px; color: #aaa; }
.hidden { display: none; }
.icon { font-size: 55px; margin-bottom: 15px; }
.result-card h2 { margin-bottom: 10px; font-size: 22px; }
.result-card p { color: #666; margin-bottom: 15px; font-size: 14px; }
.reason { background: #fef3c7; padding: 12px; border-radius: 16px; color: #92400e; margin: 15px 0; font-size: 12px; word-break: break-all; }
.btn { display: inline-block; background: #f472b6; color: white; padding: 10px 24px; border-radius: 40px; text-decoration: none; font-size: 14px; }
.btn:hover { background: #ec4899; }
</style>
</head>
<body>
<div class="loading-card" id="loadingCard">
<div class="spinner"></div>
<div class="loading-text">🔍 深度安全检测中</div>
<div class="loading-sub">正在扫描页面内容,请稍候...</div>
<div class="tip">首次访问需要安全检查</div>
</div>
<div class="result-card hidden" id="riskCard">
<div class="icon">⚠️</div>
<h2 style="color: #f59e0b;">链接存在风险</h2>
<p>该链接包含不安全内容,已被系统标记为风险状态。如为误判,请发送邮件至 qqzqxq@163.com 说明情况,我们核实后会解除限制。</p>
<div class="reason" id="riskReason"></div>
<a href="<?php echo SITE_URL; ?>" class="btn">返回首页</a>
</div>
<script>
const targetUrl = '<?php echo addslashes($targetUrl); ?>';
const code = '<?php echo $code; ?>';
let checked = false;
async function doDeepCheck() {
if (checked) return;
checked = true;
try {
const response = await fetch('/go.php?code=' + encodeURIComponent(code) + '&deep_check=1');
const data = await response.json();
if (data.safe) {
window.location.replace(targetUrl);
} else {
document.getElementById('loadingCard').classList.add('hidden');
document.getElementById('riskReason').innerText = data.reason;
document.getElementById('riskCard').classList.remove('hidden');
}
} catch (error) {
window.location.replace(targetUrl);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', doDeepCheck);
} else {
doDeepCheck();
}
</script>
</body>
</html>
<?php
exit;
}
function showRiskPage($reason) {
$defaultBg = 'https://cdn.jsdmirror.com/gh/lqay-cn/cdn@main/img/zx/h/真寻170.png';
?>
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>链接存在风险</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; min-height: 100vh; background: url('<?php echo $defaultBg; ?>') center/cover no-repeat fixed; display: flex; justify-content: center; align-items: center; position: relative; }
body::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 0; }
.card { position: relative; z-index: 1; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-radius: 28px; padding: 35px; text-align: center; max-width: 450px; width: 85%; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.icon { font-size: 55px; margin-bottom: 15px; }
h2 { color: #f59e0b; margin-bottom: 10px; font-size: 22px; }
p { color: #666; margin-bottom: 15px; font-size: 14px; }
.reason { background: #fef3c7; padding: 12px; border-radius: 16px; color: #92400e; margin: 15px 0; font-size: 12px; word-break: break-all; }
.btn { display: inline-block; background: #f472b6; color: white; padding: 10px 24px; border-radius: 40px; text-decoration: none; font-size: 14px; }
.btn:hover { background: #ec4899; }
</style>
</head>
<body>
<div class="card">
<div class="icon">⚠️</div>
<h2>链接存在风险</h2>
<p>该链接包含不安全内容,已被系统标记为风险状态。如为误判,请发送邮件至 qqzqxq@163.com 说明情况,我们核实后会解除限制。</p>
<div class="reason"><?php echo htmlspecialchars($reason); ?></div>
<a href="<?php echo SITE_URL; ?>" class="btn">返回首页</a>
</div>
</body>
</html>
<?php
exit;
}
function showBannedPage() {
$defaultBg = 'https://cdn.jsdmirror.com/gh/lqay-cn/cdn@main/img/zx/h/真寻170.png';
?>
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>链接已被封禁</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; min-height: 100vh; background: url('<?php echo $defaultBg; ?>') center/cover no-repeat fixed; display: flex; justify-content: center; align-items: center; position: relative; }
body::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 0; }
.card { position: relative; z-index: 1; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-radius: 28px; padding: 35px; text-align: center; max-width: 400px; width: 85%; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.icon { font-size: 55px; margin-bottom: 15px; }
h2 { color: #dc3545; margin-bottom: 10px; font-size: 22px; }
p { color: #666; margin-bottom: 20px; font-size: 14px; }
.btn { display: inline-block; background: #6c757d; color: white; padding: 10px 24px; border-radius: 40px; text-decoration: none; }
.btn:hover { background: #5a6268; }
</style>
</head>
<body>
<div class="card">
<div class="icon">🚫</div>
<h2>链接已被封禁</h2>
<p>该短链因违反使用条款已被封禁</p>
<a href="<?php echo SITE_URL; ?>" class="btn">返回首页</a>
</div>
</body>
</html>
<?php
exit;
}
?>