Skip to content

Commit 179781c

Browse files
added localhost for local DNS, revised xray routing.
1 parent c53d4ad commit 179781c

File tree

1 file changed

+58
-47
lines changed

1 file changed

+58
-47
lines changed

_worker.js

+58-47
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];
1717

1818
let dohURL = 'https://cloudflare-dns.com/dns-query';
1919

20-
let panelVersion = '2.3.2';
20+
let panelVersion = '2.3.3';
2121

2222
if (!isValidUUID(userID)) {
2323
throw new Error('uuid is not valid');
@@ -74,7 +74,7 @@ export default {
7474
case '/panel':
7575

7676
if (!env.bpb) {
77-
const errorPage = getErrorPage('KV Dataset is not properly set!');
77+
const errorPage = renderErrorPage('KV Dataset is not properly set!');
7878
return new Response(errorPage, { status: 200, headers: {'Content-Type': 'text/html'}});
7979
}
8080

@@ -118,7 +118,7 @@ export default {
118118
case '/login':
119119

120120
if (!env.bpb) {
121-
const errorPage = getErrorPage('KV Dataset is not properly set!');
121+
const errorPage = renderErrorPage('KV Dataset is not properly set!');
122122
return new Response(errorPage, { status: 200, headers: {'Content-Type': 'text/html'}});
123123
}
124124

@@ -221,7 +221,7 @@ export default {
221221
}
222222
} catch (err) {
223223
/** @type {Error} */ let e = err;
224-
const errorPage = getErrorPage('Something went wrong!', e.toString());
224+
const errorPage = renderErrorPage('Something went wrong!', e.toString());
225225
return new Response(errorPage, { status: 200, headers: {'Content-Type': 'text/html'}});
226226
}
227227
},
@@ -991,10 +991,15 @@ const getFragmentConfigs = async (env, hostName, client) => {
991991
delete fragConfig.routing.balancers;
992992
fragConfig.routing.rules.pop();
993993

994+
if (localDNS === 'localhost' && bypassIran) {
995+
fragConfig.dns.servers.pop();
996+
fragConfig.routing.rules.splice(0,1);
997+
}
998+
994999
if (!bypassIran) {
9951000
fragConfig.dns.servers.pop();
996-
fragConfig.routing.rules.splice(1,1);
997-
fragConfig.routing.rules[1].ip = ["geoip:private"];
1001+
fragConfig.routing.rules.splice(0,2);
1002+
fragConfig.routing.rules[0].ip = ["geoip:private"];
9981003
}
9991004

10001005
if (!blockAds) {
@@ -1038,11 +1043,16 @@ const getFragmentConfigs = async (env, hostName, client) => {
10381043
delete bestPing.dns.hosts;
10391044
bestPing.routing.rules.splice(3,1);
10401045
}
1046+
1047+
if (localDNS === 'localhost' && bypassIran) {
1048+
bestPing.dns.servers.pop();
1049+
bestPing.routing.rules.splice(0,1);
1050+
}
10411051

10421052
if (!bypassIran) {
10431053
bestPing.dns.servers.pop();
1044-
bestPing.routing.rules.splice(1,1);
1045-
bestPing.routing.rules[1].ip = ["geoip:private"];
1054+
bestPing.routing.rules.splice(0,2);
1055+
bestPing.routing.rules[0].ip = ["geoip:private"];
10461056
}
10471057

10481058
if (proxyOutbound) {
@@ -1477,7 +1487,7 @@ const renderHomePage = async (env, hostName, fragConfigs) => {
14771487
<div class="form-control">
14781488
<label for="localDNS">🏚️ Local DNS</label>
14791489
<input type="text" id="localDNS" name="localDNS" value="${localDNS}"
1480-
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
1490+
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|localhost$"
14811491
title="Please enter a valid DNS IP Address!" required>
14821492
</div>
14831493
<div class="form-control">
@@ -2013,6 +2023,43 @@ const renderLoginPage = async () => {
20132023
return html;
20142024
}
20152025

2026+
const renderErrorPage = (message, error) => {
2027+
return `
2028+
<!DOCTYPE html>
2029+
<html lang="en">
2030+
2031+
<head>
2032+
<meta charset="UTF-8">
2033+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2034+
<title>Error Page</title>
2035+
<style>
2036+
body,
2037+
html {
2038+
height: 100%;
2039+
margin: 0;
2040+
display: flex;
2041+
justify-content: center;
2042+
align-items: center;
2043+
font-family: system-ui;
2044+
}
2045+
h1 { text-align: center; color: #2980b9; font-size: 2.5rem; }
2046+
#error-container { text-align: center; }
2047+
</style>
2048+
</head>
2049+
2050+
<body>
2051+
<div id="error-container">
2052+
<h1>BPB Panel <span style="font-size: smaller;">${panelVersion}</span> 💦</h1>
2053+
<div id="error-message">
2054+
<h2>${message} Please try again or refer to <a href="https://github.com/bia-pain-bache/BPB-Worker-Panel/blob/main/README.md">documents</a></h2>
2055+
<p><b>${error ? `⚠️ ${error}` : ''}</b></p>
2056+
</div>
2057+
</div>
2058+
</body>
2059+
2060+
</html>`;
2061+
}
2062+
20162063
const xrayConfigTemp = {
20172064
remarks: "",
20182065
dns: {
@@ -2025,6 +2072,7 @@ const xrayConfigTemp = {
20252072
{
20262073
address: "",
20272074
domains: ["geosite:category-ir", "domain:.ir"],
2075+
expectIPs: ["geoip:ir"],
20282076
port: 53
20292077
},
20302078
],
@@ -2478,41 +2526,4 @@ const singboxOutboundTemp = {
24782526
type: "ws"
24792527
},
24802528
tag: ""
2481-
};
2482-
2483-
const getErrorPage = (message, error) => {
2484-
return `
2485-
<!DOCTYPE html>
2486-
<html lang="en">
2487-
2488-
<head>
2489-
<meta charset="UTF-8">
2490-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2491-
<title>Error Page</title>
2492-
<style>
2493-
body,
2494-
html {
2495-
height: 100%;
2496-
margin: 0;
2497-
display: flex;
2498-
justify-content: center;
2499-
align-items: center;
2500-
font-family: system-ui;
2501-
}
2502-
h1 { text-align: center; color: #2980b9; font-size: 2.5rem; }
2503-
#error-container { text-align: center; }
2504-
</style>
2505-
</head>
2506-
2507-
<body>
2508-
<div id="error-container">
2509-
<h1>BPB Panel <span style="font-size: smaller;">${panelVersion}</span> 💦</h1>
2510-
<div id="error-message">
2511-
<h2>${message} Please try again or refer to <a href="https://github.com/bia-pain-bache/BPB-Worker-Panel/blob/main/README.md">documents</a></h2>
2512-
<p><b>${error ? `⚠️ ${error}` : ''}</b></p>
2513-
</div>
2514-
</div>
2515-
</body>
2516-
2517-
</html>`;
2518-
}
2529+
};

0 commit comments

Comments
 (0)