mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 00:48:39 +08:00
add cf page
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const skipUrls = ["ws"];
|
||||
import { index401 } from './util';
|
||||
import { parse, stringify, validate } from 'uuid';
|
||||
const skipUrls = ['ws'];
|
||||
|
||||
async function errorHandling(context: EventContext<any, any, any>) {
|
||||
try {
|
||||
@@ -9,18 +11,29 @@ async function errorHandling(context: EventContext<any, any, any>) {
|
||||
}
|
||||
|
||||
function authentication(context: EventContext<any, any, any>) {
|
||||
// if not set UUID, return 401 page
|
||||
const userID = context.env['UUID'] || '';
|
||||
let isVaildUser = validate(userID);
|
||||
if (!isVaildUser) {
|
||||
return new Response(index401, {
|
||||
status: 401,
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
// skip authentication
|
||||
if (skipUrls.filter((url) => context.request.url.endsWith(url))) {
|
||||
if (skipUrls.filter((url) => context.request.url.endsWith(url)).length) {
|
||||
return context.next();
|
||||
}
|
||||
const basicAuth = context.request.headers.get("Authorization") || "";
|
||||
const authString = basicAuth.split(" ")?.[1] || "";
|
||||
if (!atob(authString).includes("test")) {
|
||||
const basicAuth = context.request.headers.get('Authorization') || '';
|
||||
const authString = basicAuth.split(' ')?.[1] || '';
|
||||
if (!atob(authString).includes(userID)) {
|
||||
return new Response(``, {
|
||||
status: 401,
|
||||
headers: {
|
||||
"content-type": "text/html; charset=utf-8",
|
||||
"WWW-Authenticate": "Basic",
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
'WWW-Authenticate': 'Basic',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user