diff --git a/src/panel.ts b/src/panel.ts index b1b5da9f..9e253aac 100644 --- a/src/panel.ts +++ b/src/panel.ts @@ -10,7 +10,7 @@ export async function GetPanel(request: Request, env: Env): Promise { const token: string | null = await env.settings.get("Token") if (hash && url.searchParams.get("token") != token) { - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}/login`, 302) + return Response.redirect(`${url.origin}/login`, 302) } const settingsVersion: string = await env.settings.get("Version") || "2.0" @@ -27,12 +27,20 @@ export async function GetPanel(request: Request, env: Env): Promise { const configs: Array = (await env.settings.get("Configs"))?.split("\n").filter(t => t.trim().length > 0) || [] const includeOriginalConfigs: string = await env.settings.get("IncludeOriginalConfigs") || "yes" const includeMergedConfigs: string = await env.settings.get("IncludeMergedConfigs") || "yes" - const enableFragments: string = await env.settings.get("EnableFragments") || "yes" + const enableFragments: string = await env.settings.get("EnableFragments") || "no" const blockPorn: string = await env.settings.get("BlockPorn") || "no" const providers = (await env.settings.get("Providers"))?.split("\n").filter(t => t.trim().length > 0) || [] - const proxies = (await env.settings.get("ManualProxies"))?.split("\n").filter(t => t.trim().length > 0) || [] + const countries = (await env.settings.get("Countries"))?.split(",").filter(t => t.trim().length > 0) || [] - var htmlMessage = "" + let allCountries = await fetch("https://raw.githubusercontent.com/vfarid/v2ray-worker/main/resources/proxy-list.txt").then(r => r.text()).then(t => { + return t.trim().split("\n").map(t => { + const arr = t.split(",") + return arr.length > 0 ? arr[1]?.toString().trim().toUpperCase() : "" + }).filter(t => t) + }) + allCountries = [...new Set(allCountries)].sort() + + let htmlMessage = "" const message = url.searchParams.get("message") if (message == "success") { htmlMessage = `
Settings saved successfully.
تنظیمات با موفقیت ذخیره شد.
` @@ -40,7 +48,7 @@ export async function GetPanel(request: Request, env: Env): Promise { htmlMessage = `
Failed to save settings!
خطا در ذخیره‌ی تنظیمات!
` } - var passwordSection = "" + let passwordSection = "" if (hash) { passwordSection = `
@@ -69,7 +77,7 @@ export async function GetPanel(request: Request, env: Env): Promise { ` } - var htmlContent = ` + let htmlContent = ` @@ -96,18 +104,14 @@ export async function GetPanel(request: Request, env: Env): Promise { }); document.getElementById('providers-check').dispatchEvent(new Event("change")); - document.getElementById('proxies-check').addEventListener("change", () => { - if (document.getElementById('proxies-check').checked) { - document.getElementById('proxies').style.display = "" - document.getElementById('proxies-remarks').style.display = "" - document.getElementById('proxies-auto-title').style.display = "none" + document.getElementById('countries-check').addEventListener("change", () => { + if (document.getElementById('countries-check').checked) { + document.getElementById('countries-div').style.display = "" } else { - document.getElementById('proxies').style.display = "none" - document.getElementById('proxies-remarks').style.display = "none" - document.getElementById('proxies-auto-title').style.display = "" + document.getElementById('countries-div').style.display = "none" } }); - document.getElementById('proxies-check').dispatchEvent(new Event("change")); + document.getElementById('countries-check').dispatchEvent(new Event("change")); document.getElementById('clean-ips-check').addEventListener("change", () => { if (document.getElementById('clean-ips-check').checked) { @@ -227,9 +231,8 @@ export async function GetPanel(request: Request, env: Env): Promise { "providers-title": "Config Providers", "providers-auto-title": "Auto load from github", "providers-remarks": "One link per line (base64, yaml, raw).", - "proxies-title": "Built-in VLESS Proxies", - "proxies-auto-title": "Auto load from github", - "proxies-remarks": "One ip/domain per line.", + "countries-title": "Limit By Country (Only for websites beind Cloudflare Network)", + "countries-all-title": "If you check this option, all protocols will be deactivated except built-in vless protocols.", "personal-configs-title": "Private Configs", "personal-configs-remarks": "One config per line.", "block-porn-title": "‌Block Porn", @@ -261,9 +264,8 @@ export async function GetPanel(request: Request, env: Env): Promise { "providers-title": "تامین کنندگان کانفیگ", "providers-auto-title": "دریافت خودکار از گیت‌هاب", "providers-remarks": "در هر سطر یک لینک وارد کنید (base64, yaml, raw).", - "proxies-title": "پروکسی‌های VLESS روی ورکر", - "proxies-auto-title": "دریافت خودکار از گیت‌هاب", - "proxies-remarks": "در هر سطر یک آی‌پی/دامین وارد کنید.", + "countries-title": "محدود کردن کشور (فقط برای وبسایت‌های پشت شبکه کلادفلر)", + "countries-all-title": "در صورت فعال‌سازی این گزینه، تمام پروتکل‌ها بجز vless های داخلی ورکر غیرفعال می‌شوند.", "personal-configs-title": "کانفیگ‌های خصوصی", "personal-configs-remarks": "در هر سطر یک کانفیگ وارد کنید.", "block-porn-title": "مسدودسازی پورن", @@ -288,12 +290,12 @@ export async function GetPanel(request: Request, env: Env): Promise {
- +
- +
@@ -357,6 +359,14 @@ export async function GetPanel(request: Request, env: Env): Promise {
+
+ + +
+
+ ${allCountries.map(t => ` `).join(`    `)} +
+
@@ -381,13 +391,6 @@ export async function GetPanel(request: Request, env: Env): Promise {
-
- -     - - - -
@@ -446,12 +449,12 @@ export async function GetPanel(request: Request, env: Env): Promise {
- +
- +
@@ -544,7 +547,7 @@ export async function GetPanel(request: Request, env: Env): Promise { "page-title": "V2ray Worker Control Panel", "text-version": "Version", "sub-link-title": "Your subscription link for v2ray clients (v2rayN, v2rayNG, v2rayA, Nekobox, Nekoray, V2Box...)", - "custom-link-title": "Your subscription link for custom configs", + // "custom-link-title": "Your subscription link for custom configs", "clash-link-title": "Your subscription link for clash clients (Clash, ClashX, ClashMeta...)", "you-can-use-your-worker-message": "You can continue using your worker without control panel.", "you-need-namespace-message": "The 'settings' namespace is not defined! Please define a namespace named 'settings' in your worker 'KV Namespace Bindings' using bellow link, as described in the video and relad the page afterward.", @@ -555,7 +558,7 @@ export async function GetPanel(request: Request, env: Env): Promise { "page-title": "پنل کنترل ورکر v2ray", "text-version": "نسخه", "sub-link-title": "لینک ثبت نام شما برای کلاینت‌های v2rayN, v2rayNG, v2rayA, Nekobox, Nekoray, V2Box و...", - "custom-link-title": "لینک ثبت نام شما برای کانفیگ‌های Custom", + // "custom-link-title": "لینک ثبت نام شما برای کانفیگ‌های Custom", "clash-link-title": "لینک ثبت نام شما برای کلاینت‌های کلش Clash, ClashX, ClashMeta و...", "you-can-use-your-worker-message": "شما می‌توانید از ورکر خود بدون پنل کنترل استفاده نمایید.", "you-need-namespace-message": "فضای نام settings تعریف نشده است. لطفا مطابق ویدیوی آموزشی، از طریق لینک‌های زیر ابتدا در بخش KV یک فضای نام به اسم settings ایجاد کنید و سپس ازطریق بخش 'KV Namespace Bindings' آن را با همان نام settings به ورکر خود متصل کنید و پس از ذخیره، مجددا پنل را باز کنید.", @@ -578,25 +581,25 @@ export async function GetPanel(request: Request, env: Env): Promise { export async function PostPanel(request: Request, env: Env): Promise { const url: URL = new URL(request.url) - var token: string | null = await env.settings.get("Token") + let token: string | null = await env.settings.get("Token") try { const formData = await request.formData() - var hashedPassword: string | null = await env.settings.get("Password") + let hashedPassword: string | null = await env.settings.get("Password") if (hashedPassword && url.searchParams.get("token") != token) { - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}/login`, 302) + return Response.redirect(`${url.origin}/login`, 302) } if (formData.get("reset_password")) { await env.settings.delete("Password") await env.settings.delete("Token") - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}?message=success`, 302) + return Response.redirect(`${url.origin}?message=success`, 302) } else if (formData.get("save")) { const password: string = formData.get("password")?.toString() || "" if (password) { if (password.length < 6 || password !== formData.get("password_confirmation")) { - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}?message=invalid-password`, 302) + return Response.redirect(`${url.origin}?message=invalid-password`, 302) } hashedPassword = await bcrypt.hash(password, 10); @@ -613,19 +616,13 @@ export async function PostPanel(request: Request, env: Env): Promise { await env.settings.put("ALPNs", formData.get("alpn_list_check")?.toString() ? formData.get("alpn_list")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") await env.settings.put("FingerPrints", formData.get("fp_list_check")?.toString() ? formData.get("fp_list")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") await env.settings.put("Providers", formData.get("providers_check")?.toString() ? formData.get("providers")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") - await env.settings.put("ManualProxies", formData.get("proxies_check")?.toString() ? formData.get("proxies")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") + await env.settings.put("Countries", formData.get("countries_check")?.toString() ? formData.getAll("countries[]")?.join(",") || "" : "") await env.settings.put("CleanDomainIPs", formData.get("clean_ips_check")?.toString() ? formData.get("clean_ips")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") await env.settings.put("Configs", formData.get("configs_check")?.toString() ? formData.get("configs")?.toString().trim().split("\n").map(str => str.trim()).join("\n") || "" : "") await env.settings.put("IncludeOriginalConfigs", formData.get("original")?.toString() || "no") await env.settings.put("IncludeMergedConfigs", formData.get("merged")?.toString() || "no") await env.settings.put("BlockPorn", formData.get("block_porn")?.toString() || "no") await env.settings.put("EnableFragments", formData.get("enable_fragments")?.toString() || "no") - - let proxies = (await env.settings.get("ManualProxies"))?.split("\n").filter(t => t.trim().length > 0) || [] - if (!proxies.length) { - proxies = await fetch("https://raw.githubusercontent.com/vfarid/v2ray-worker/main/resources/proxy-list.txt").then(r => r.text()).then(t => t.trim().split("\n").filter(t => t.trim().length > 0)) - } - await env.settings.put("Proxies", proxies.join("\n")) await env.settings.put("Version", version) } else { await env.settings.delete("MaxConfigs") @@ -633,7 +630,7 @@ export async function PostPanel(request: Request, env: Env): Promise { await env.settings.delete("ALPNs") await env.settings.delete("FingerPrints") await env.settings.delete("Providers") - await env.settings.delete("ManualProxies") + await env.settings.delete("Countries") await env.settings.delete("CleanDomainIPs") await env.settings.delete("Configs") await env.settings.delete("IncludeOriginalConfigs") @@ -645,8 +642,8 @@ export async function PostPanel(request: Request, env: Env): Promise { await env.settings.delete("EnableFragments") } - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}?message=success${token ? "&token=" + token : ""}`, 302) + return Response.redirect(`${url.origin}?message=success${token ? "&token=" + token : ""}`, 302) } catch (e) { - return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}?message=error${token ? "&token=" + token : ""}`, 302) + return Response.redirect(`${url.origin}?message=error${token ? "&token=" + token : ""}`, 302) } }