From b3ff76cea2358ca4de8a4f74770a8f1cca09eebf Mon Sep 17 00:00:00 2001 From: zizifn <1803942+zizifn@users.noreply.github.com> Date: Sat, 20 May 2023 00:44:32 +0800 Subject: [PATCH] add default uuid --- libs/cf-worker-vless/cf-worker-vless-dev.js | 22 +++++++++++++++++---- libs/cf-worker-vless/src/cf-worker-vless.ts | 22 +++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/libs/cf-worker-vless/cf-worker-vless-dev.js b/libs/cf-worker-vless/cf-worker-vless-dev.js index 65f1eec..3dc7536 100644 --- a/libs/cf-worker-vless/cf-worker-vless-dev.js +++ b/libs/cf-worker-vless/cf-worker-vless-dev.js @@ -197,15 +197,29 @@ var cf_worker_vless_default = { async fetch(request, env, ctx) { let address = ""; let portWithRandomLog = ""; - const userID = env.UUID; + const userID = env.UUID || "7f14e42a-f453-4c39-a762-019ee493237d"; + const isVaildUUID = validate_default(userID); const log = (info, event) => { console.log(`[${address}:${portWithRandomLog}] ${info}`, event || ""); }; const upgradeHeader = request.headers.get("Upgrade"); if (!upgradeHeader || upgradeHeader !== "websocket") { - return new Response(`Expected Upgrade: websocket--uuid--${userID}`, { - status: 426 - }); + return new Response( + ` +404 Not Found + +

404 Not Found ${isVaildUUID ? "_-_" : ""}

+
nginx/1.23.4
+ +`, + { + status: 404, + headers: { + "content-type": "text/html; charset=utf-8", + "WWW-Authenticate": "Basic" + } + } + ); } const webSocketPair = new WebSocketPair(); const [client, webSocket] = Object.values(webSocketPair); diff --git a/libs/cf-worker-vless/src/cf-worker-vless.ts b/libs/cf-worker-vless/src/cf-worker-vless.ts index 8418bf8..5f4c9c6 100644 --- a/libs/cf-worker-vless/src/cf-worker-vless.ts +++ b/libs/cf-worker-vless/src/cf-worker-vless.ts @@ -21,7 +21,8 @@ export default { async fetch(request: Request, env: Env, ctx: ExecutionContext) { let address = ''; let portWithRandomLog = ''; - const userID = env.UUID; + const userID = env.UUID || '7f14e42a-f453-4c39-a762-019ee493237d'; + const isVaildUUID = validate(userID); const log = (info: string, event?: any) => { console.log(`[${address}:${portWithRandomLog}] ${info}`, event || ''); @@ -29,9 +30,22 @@ export default { const upgradeHeader = request.headers.get('Upgrade'); if (!upgradeHeader || upgradeHeader !== 'websocket') { - return new Response(`Expected Upgrade: websocket--uuid--${userID}`, { - status: 426, - }); + return new Response( + ` +404 Not Found + +

404 Not Found ${isVaildUUID ? '_-_' : ''}

+
nginx/1.23.4
+ +`, + { + status: 404, + headers: { + 'content-type': 'text/html; charset=utf-8', + 'WWW-Authenticate': 'Basic', + }, + } + ); } const webSocketPair = new WebSocketPair();