Skip to content

Commit

Permalink
Added multiple udp noise support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Jan 30, 2025
1 parent ac634c7 commit 43e3418
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 80 deletions.
25 changes: 5 additions & 20 deletions src/cores-configs/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,7 @@ function buildFreedomOutbound (
fragmentPacket,
fragmentLength,
fragmentInterval,
udpNoiseMode,
udpNoisePacket,
udpNoiseDelay
udpNoises
) {
const outbound = {
tag: tag,
Expand All @@ -622,13 +620,7 @@ function buildFreedomOutbound (
length: fragmentLength,
interval: fragmentInterval,
},
noises: [
{
type: udpNoiseMode,
packet: udpNoisePacket,
delay: udpNoiseDelay
}
],
noises: JSON.parse(udpNoises),
domainStrategy: domainStrategy
},
streamSettings: {
Expand All @@ -640,7 +632,7 @@ function buildFreedomOutbound (
};

!fragmentPacket && delete outbound.settings.fragment;
!udpNoiseMode && delete outbound.settings.noises;
!udpNoises && delete outbound.settings.noises;
return outbound;
}

Expand Down Expand Up @@ -849,10 +841,7 @@ export async function getXrayWarpConfigs (request, env, client) {
const {
warpEndpoints,
warpEnableIPv6,
udpXrayNoiseMode,
udpXrayNoisePacket,
udpXrayNoiseDelayMin,
udpXrayNoiseDelayMax
xrayUdpNoises,
} = proxySettings;
const xrayWarpConfigs = [];
const xrayWoWConfigs = [];
Expand All @@ -869,14 +858,10 @@ export async function getXrayWarpConfigs (request, env, client) {
const WoWConfig = buildXrayConfig(proxySettings, `💦 ${index + 1} - WoW${proIndicator}🌍`, false, true, false, true);
if (client === 'xray-pro') {
const domainStrategy = warpEnableIPv6 ? "UseIPv4v6" : "UseIPv4";
freedomOutbound = buildFreedomOutbound(domainStrategy, 'udp-noise', null, null, null, udpXrayNoiseMode, udpXrayNoisePacket, `${udpXrayNoiseDelayMin}-${udpXrayNoiseDelayMax}`);
freedomOutbound = buildFreedomOutbound(domainStrategy, 'udp-noise', null, null, null, xrayUdpNoises);
warpConfig.outbounds.unshift(freedomOutbound);
WoWConfig.outbounds.unshift(freedomOutbound);
}
// if (client !== 'xray-pro') {
// warpConfig.outbounds.shift();
// WoWConfig.outbounds.shift();
// }
warpConfig.dns = WoWConfig.dns = await buildXrayDNS(proxySettings, [endpointHost], undefined, false, true);
warpConfig.routing.rules = buildXrayRoutingRules(proxySettings, [endpointHost], false, false, false, true);
WoWConfig.routing.rules = buildXrayRoutingRules(proxySettings, [endpointHost], true, false, false, true);
Expand Down
21 changes: 17 additions & 4 deletions src/kv/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ export async function updateDataset (request, env) {
let newSettings = request.method === 'POST' ? await request.formData() : null;
const isReset = newSettings?.get('resetSettings') === 'true';
let currentSettings;
let udpNoises = [];
if (!isReset) {
try {
currentSettings = await env.kv.get("proxySettings", {type: 'json'});
} catch (error) {
console.log(error);
throw new Error(`An error occurred while getting current KV settings - ${error}`);
}
const udpNoiseModes = newSettings?.getAll('udpXrayNoiseMode') || [];
const udpNoisePackets = newSettings?.getAll('udpXrayNoisePacket') || [];
const udpNoiseDelaysMin = newSettings?.getAll('udpXrayNoiseDelayMin') || [];
const udpNoiseDelaysMax = newSettings?.getAll('udpXrayNoiseDelayMax') || [];
udpNoises.push(...udpNoiseModes.map((mode, index) => ({
type: mode,
packet: udpNoisePackets[index], // Fallback to empty string if undefined
delay: `${udpNoiseDelaysMin[index]}-${udpNoiseDelaysMax[index]}`
})));
} else {
newSettings = null;
}
Expand Down Expand Up @@ -81,10 +91,13 @@ export async function updateDataset (request, env) {
warpEnableIPv6: validateField('warpEnableIPv6') ?? currentSettings?.warpEnableIPv6 ?? true,
warpPlusLicense: validateField('warpPlusLicense') ?? currentSettings?.warpPlusLicense ?? '',
bestWarpInterval: validateField('bestWarpInterval') ?? currentSettings?.bestWarpInterval ?? '30',
udpXrayNoiseMode: validateField('udpXrayNoiseMode') ?? currentSettings?.udpXrayNoiseMode ?? 'base64',
udpXrayNoisePacket: validateField('udpXrayNoisePacket') ?? currentSettings?.udpXrayNoisePacket ?? btoa(globalThis.userID),
udpXrayNoiseDelayMin: validateField('udpXrayNoiseDelayMin') ?? currentSettings?.udpXrayNoiseDelayMin ?? '1',
udpXrayNoiseDelayMax: validateField('udpXrayNoiseDelayMax') ?? currentSettings?.udpXrayNoiseDelayMax ?? '1',
xrayUdpNoises: (udpNoises.length ? JSON.stringify(udpNoises) : currentSettings?.xrayUdpNoises) ?? JSON.stringify([
{
type: 'base64',
packet: btoa(globalThis.userID),
delay: '1-1'
}
]),
hiddifyNoiseMode: validateField('hiddifyNoiseMode') ?? currentSettings?.hiddifyNoiseMode ?? 'm4',
nikaNGNoiseMode: validateField('nikaNGNoiseMode') ?? currentSettings?.nikaNGNoiseMode ?? 'quic',
noiseCountMin: validateField('noiseCountMin') ?? currentSettings?.noiseCountMin ?? '10',
Expand Down
149 changes: 93 additions & 56 deletions src/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export async function renderHomePage (proxySettings, isPassSet) {
warpEnableIPv6,
warpPlusLicense,
bestWarpInterval,
udpXrayNoiseMode,
udpXrayNoisePacket,
udpXrayNoiseDelayMin,
udpXrayNoiseDelayMax,
xrayUdpNoises,
hiddifyNoiseMode,
nikaNGNoiseMode,
noiseCountMin,
Expand Down Expand Up @@ -63,6 +60,44 @@ export async function renderHomePage (proxySettings, isPassSet) {
globalThis.defaultHttpsPorts.includes(port) ? httpsPortsBlock += portBlock : httpPortsBlock += portBlock;
});

let udpNoiseBlocks = '';
JSON.parse(xrayUdpNoises).forEach( (noise, index) => {
udpNoiseBlocks += `
<div id="udp-noise-container-${index}" class="udp-noise">
<div class="header-container">
<h4 style="margin: 0 5px;">Noise ${index + 1}</h4>
<button type="button" onclick="deleteUdpNoise(this)" style="background: none; margin: 0; border: none; cursor: pointer;">
<i class="fa fa-minus-circle fa-2x" style="color: var(--button-color);" aria-hidden="true"></i>
</button>
</div>
<div class="form-control">
<label for="udpXrayNoiseMode-${index}">😵‍💫 v2ray Mode</label>
<div class="input-with-select">
<select id="udpXrayNoiseMode-${index}" name="udpXrayNoiseMode">
<option value="base64" ${noise.type === 'base64' ? 'selected' : ''}>Base64</option>
<option value="rand" ${noise.type === 'rand' ? 'selected' : ''}>Random</option>
<option value="str" ${noise.type === 'str' ? 'selected' : ''}>String</option>
</select>
</div>
</div>
<div class="form-control">
<label for="udpXrayNoisePacket-${index}">📥 Noise Packet</label>
<input type="text" id="udpXrayNoisePacket-${index}" name="udpXrayNoisePacket" value="${noise.packet}">
</div>
<div class="form-control">
<label for="udpXrayNoiseDelayMin-${index}">🕞 Noise Delay</label>
<div class="min-max">
<input type="number" id="udpXrayNoiseDelayMin-${index}" name="udpXrayNoiseDelayMin"
value="${noise.delay.split('-')[0]}" min="1" required>
<span> - </span>
<input type="number" id="udpXrayNoiseDelayMax-${index}" name="udpXrayNoiseDelayMax"
value="${noise.delay.split('-')[1]}" min="1" required>
</div>
</div>
</div>`;
});


const supportedApps = apps => apps.map(app => `
<div>
<span class="material-symbols-outlined symbol">verified</span>
Expand Down Expand Up @@ -257,7 +292,7 @@ export async function renderHomePage (proxySettings, isPassSet) {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 100px;
}
.table-container { margin-top: 20px; overflow-x: auto; }
.table-container { overflow-x: auto; }
table {
width: 100%;
border: 1px solid var(--border-color);
Expand Down Expand Up @@ -372,7 +407,8 @@ export async function renderHomePage (proxySettings, isPassSet) {
#ips th { background-color: var(--hr-text-color); color: var(--background-color); width: unset; }
#ips td { background-color: unset; }
#ips td:first-child { background-color: var(--table-active-color); }
.header-container { display: flex; align-items: center; justify-content: center; }
.header-container { display: flex; justify-content: center; margin-bottom: 20px; }
.udp-noise { border: 1px solid var(--border-color); border-radius: 15px; padding: 20px; margin-bottom: 10px;}
@media only screen and (min-width: 768px) {
.form-container { max-width: 70%; }
.form-control {
Expand Down Expand Up @@ -576,30 +612,14 @@ export async function renderHomePage (proxySettings, isPassSet) {
</details>
<details>
<summary><h2>WARP PRO ⚙️</h2></summary>
<h3>V2RAYNG - V2RAYN 🔧</h3>
<div class="form-control">
<label for="udpXrayNoiseMode">😵‍💫 v2ray Mode</label>
<div class="input-with-select">
<select id="udpXrayNoiseMode" name="udpXrayNoiseMode">
<option value="base64" ${udpXrayNoiseMode === 'base64' ? 'selected' : ''}>Base64</option>
<option value="rand" ${udpXrayNoiseMode === 'rand' ? 'selected' : ''}>Random</option>
<option value="str" ${udpXrayNoiseMode === 'str' ? 'selected' : ''}>String</option>
</select>
</div>
</div>
<div class="form-control">
<label for="udpXrayNoisePacket">📥 Noise Packet</label>
<input type="text" id="udpXrayNoisePacket" name="udpXrayNoisePacket" value="${udpXrayNoisePacket}">
<div class="header-container">
<h3 style="margin: 0 5px;">V2RAYNG - V2RAYN</h3>
<button type="button" id="add-udp-noise" onclick="addUdpNoise()" style="background: none; margin: 0; border: none; cursor: pointer;">
<i class="fa fa-plus-circle fa-2x" style="color: var(--button-color);" aria-hidden="true"></i>
</button>
</div>
<div class="form-control">
<label for="udpXrayNoiseDelayMin">🕞 Noise Delay</label>
<div class="min-max">
<input type="number" id="udpXrayNoiseDelayMin" name="udpXrayNoiseDelayMin"
value="${udpXrayNoiseDelayMin}" min="1" required>
<span> - </span>
<input type="number" id="udpXrayNoiseDelayMax" name="udpXrayNoiseDelayMax"
value="${udpXrayNoiseDelayMax}" min="1" required>
</div>
<div id="udp-noise-container">
${udpNoiseBlocks}
</div>
<h3>MAHSANG - NIKANG - HIDDIFY 🔧</h3>
<div class="form-control">
Expand Down Expand Up @@ -1092,6 +1112,23 @@ export async function renderHomePage (proxySettings, isPassSet) {
}
}
const addUdpNoise = () => {
const container = document.getElementById("udp-noise-container");
const noiseBlock = document.getElementById("udp-noise-container-0");
const index = container.children.length;
const clone = noiseBlock.cloneNode(true);
clone.querySelector("h4").textContent = "Noise " + String(index + 1);
container.appendChild(clone);
document.getElementById("configForm").dispatchEvent(new Event("change"));
}
const deleteUdpNoise = (button) => {
const confirmReset = confirm('⚠️ This will delete the noise.\\nAre you sure?');
if(!confirmReset) return;
button.closest(".udp-noise").remove();
document.getElementById("configForm").dispatchEvent(new Event("change"));
}
const getWarpConfigs = async () => {
const license = document.getElementById('warpPlusLicense').value;
if (license !== warpPlusLicense) {
Expand Down Expand Up @@ -1219,10 +1256,10 @@ export async function renderHomePage (proxySettings, isPassSet) {
const customCdnSni = document.getElementById('customCdnSni').value;
const isCustomCdn = customCdnAddrs.length || customCdnHost !== '' || customCdnSni !== '';
const warpEndpoints = document.getElementById('warpEndpoints').value?.replaceAll(' ', '').split(',');
const xrayNoiseMode = document.getElementById('udpXrayNoiseMode').value;
const xrayNoisePacket = document.getElementById('udpXrayNoisePacket').value;
const xrayNoiseDelayMin = getValue('udpXrayNoiseDelayMin');
const xrayNoiseDelayMax = getValue('udpXrayNoiseDelayMax');
// const xrayNoiseMode = document.getElementById('udpXrayNoiseMode').value;
// const xrayNoisePacket = document.getElementById('udpXrayNoisePacket').value;
// const xrayNoiseDelayMin = getValue('udpXrayNoiseDelayMin');
// const xrayNoiseDelayMax = getValue('udpXrayNoiseDelayMax');
const noiseCountMin = getValue('noiseCountMin');
const noiseCountMax = getValue('noiseCountMax');
const noiseSizeMin = getValue('noiseSizeMin');
Expand Down Expand Up @@ -1298,31 +1335,31 @@ export async function renderHomePage (proxySettings, isPassSet) {
return false;
}
if (xrayNoiseDelayMin > xrayNoiseDelayMax) {
alert('⛔ The minimum delay should be smaller or equal to maximum! 🫤');
return;
}
// if (xrayNoiseDelayMin > xrayNoiseDelayMax) {
// alert('⛔ The minimum delay should be smaller or equal to maximum! 🫤');
// return;
// }
switch (xrayNoiseMode) {
case 'base64':
if (!base64Regex.test(xrayNoisePacket)) {
alert('⛔ The Packet is not a valid base64 value! 🫤');
return;
}
break;
// switch (xrayNoiseMode) {
// case 'base64':
// if (!base64Regex.test(xrayNoisePacket)) {
// alert('⛔ The Packet is not a valid base64 value! 🫤');
// return;
// }
// break;
case 'rand':
if (!(/^\\d+-\\d+$/.test(xrayNoisePacket))) {
alert('⛔ The Packet should be a range like 0-10 or 10-30! 🫤');
return;
}
const [min, max] = xrayNoisePacket.split("-").map(Number);
if (min > max) {
alert('⛔ The minimum value should be smaller or equal to maximum! 🫤');
return;
}
break;
}
// case 'rand':
// if (!(/^\\d+-\\d+$/.test(xrayNoisePacket))) {
// alert('⛔ The Packet should be a range like 0-10 or 10-30! 🫤');
// return;
// }
// const [min, max] = xrayNoisePacket.split("-").map(Number);
// if (min > max) {
// alert('⛔ The minimum value should be smaller or equal to maximum! 🫤');
// return;
// }
// break;
// }
try {
document.body.style.cursor = 'wait';
Expand Down

0 comments on commit 43e3418

Please sign in to comment.