Skip to content

Commit

Permalink
Changed proxyIPs, Automatic worker host migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Feb 2, 2024
1 parent d42c389 commit 50b9d06
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions _worker.js → worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { connect } from "cloudflare:sockets";
// https://www.uuidgenerator.net/
let userID = "XXXX";

const proxyIPs = ["proxyip.fuck.cloudns.biz"]; //['cdn.xn--b6gac.eu.org', 'cdn-all.xn--b6gac.eu.org', 'edgetunnel.anycast.eu.org'];
const proxyIPs = ['cdn.xn--b6gac.eu.org', 'cdn-all.xn--b6gac.eu.org', 'edgetunnel.anycast.eu.org'];

let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];

Expand Down Expand Up @@ -43,23 +43,25 @@ export default {
apiHost = env.API_HOST || apiHost;
const url = new URL(request.url);
const upgradeHeader = request.headers.get("Upgrade");
if (await env.bpb.get("remoteDNS") === null) await updateDataset(
env,
"https://94.140.14.14/dns-query",
"1.1.1.1",
"100",
"200",
"10",
"20",
""
);

if (!upgradeHeader || upgradeHeader !== "websocket") {

const host = request.headers.get("Host");
const searchParams = new URLSearchParams(url.search);
const client = searchParams.get("app");
const configAddr = searchParams.get("addr");
const hostValue = await env.bpb.get("host");
if (!hostValue) await updateDataset(
env,
host,
"https://94.140.14.14/dns-query",
"1.1.1.1",
"100",
"200",
"10",
"20",
""
);

switch (url.pathname) {

Expand Down Expand Up @@ -141,11 +143,12 @@ export default {
});

case `/${userID}`:

if (request.method === "POST") {
const formData = await request.formData();
await updateDataset(
env,
host,
formData.get("remoteDNS"),
formData.get("localDNS"),
formData.get("fragmentLengthMin"),
Expand All @@ -155,11 +158,12 @@ export default {
formData.get("cleanIPs")
);
}

if (request.method === "POST" || await env.bpb.get("fragConfigs") === null) {
await getVLESSConfig(env, userID, host);
await getVLESSConfig(env, userID, host);
await getFragVLESSConfig(env, userID, host);

if (hostValue !== host) await env.bpb.put("host", host);

if (request.method === "POST" || !await env.bpb.get("fragConfigs") || hostValue !== host) {
await getVLESSConfig(env, userID);
await getFragVLESSConfig(env, userID);
}

const htmlPage = await renderPage(
Expand Down Expand Up @@ -902,9 +906,10 @@ async function handleUDPOutBound(webSocket, vlessResponseHeader, log) {
* @returns {string}
*/

const getVLESSConfig = async (env, userID, hostName) => {
const getVLESSConfig = async (env, userID) => {
let vlessWsTls = "";
const cleanIPs = await env.bpb.get("cleanIPs");
const hostName = await env.bpb.get("host");
const resolved = await resolveDNS(hostName);
const Addresses = [
hostName,
Expand All @@ -930,10 +935,11 @@ const getVLESSConfig = async (env, userID, hostName) => {
await env.bpb.put("singbox-sub", singboxSub);
};

const getFragVLESSConfig = async (env, userID, hostName) => {
const getFragVLESSConfig = async (env, userID) => {
let Configs = [];
let outbounds = [];
const {
hostName,
remoteDNS,
localDNS,
lengthMin,
Expand Down Expand Up @@ -1748,8 +1754,9 @@ const renderPage = async (env, uuid, host) => {
return html;
};

const updateDataset = async (env, remoteDNS, localDNS, lengthMin, lengthMax, intervalMin, intervalMax, cleanIPs) => {
const updateDataset = async (env, host, remoteDNS, localDNS, lengthMin, lengthMax, intervalMin, intervalMax, cleanIPs) => {
const initData = {
host: host,
remoteDNS: remoteDNS,
localDNS: localDNS,
lengthMin: lengthMin,
Expand All @@ -1765,6 +1772,7 @@ const updateDataset = async (env, remoteDNS, localDNS, lengthMin, lengthMax, int
};

const getDataset = async (env) => {
const hostName = await env.bpb.get("host");
const remoteDNS = await env.bpb.get("remoteDNS");
const localDNS = await env.bpb.get("localDNS");
const lengthMin = await env.bpb.get("lengthMin");
Expand All @@ -1774,5 +1782,5 @@ const getDataset = async (env) => {
const cleanIPs = await env.bpb.get("cleanIPs");
const fragConfigs = JSON.parse(await env.bpb.get("fragConfigs"));

return {remoteDNS, localDNS, lengthMin, lengthMax, intervalMin, intervalMax, cleanIPs, fragConfigs};
return {hostName, remoteDNS, localDNS, lengthMin, lengthMax, intervalMin, intervalMax, cleanIPs, fragConfigs};
};

0 comments on commit 50b9d06

Please sign in to comment.