From 8413d52c695d8d81a044481540ccdfda75e31bcd Mon Sep 17 00:00:00 2001 From: Den Piligrim <89912505+vasiljevdenis@users.noreply.github.com> Date: Tue, 23 Dec 2025 23:25:28 +0300 Subject: [PATCH] delete inbounds --- README.md | 1 + app/builders/buildInboundLink.js | 4 ++-- app/builders/buildVmessTcp.js | 3 ++- app/index.js | 36 ++++++++++++++++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f703091..933fb5e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ - Реквизиты / донаты: - Карта МИР: `2204320436318077` - Карта MasterCard: `5395452209474530` + - ЮМоney: `4100116897060652` - PayPal: `vasiljevdenisx@gmail.com` - USDT | ETH (ERC20 | BEP20): `0x6fe140040f6Cdc1E1Ff2136cd1d60C0165809463` - USDT | TRX (TRC20): `TEWxXmJxvkAmhshp7E61XJGHB3VyM9hNAb` diff --git a/app/builders/buildInboundLink.js b/app/builders/buildInboundLink.js index fa9967e..b3f26b0 100644 --- a/app/builders/buildInboundLink.js +++ b/app/builders/buildInboundLink.js @@ -107,7 +107,7 @@ function buildVmessLink(inbound, domain, uuid) { net: stream.network || "tcp", path: "/", port: inbound.port, - ps: flag + ' ' + inbound.remark, + ps: decodeURIComponent(flag) + ' ' + inbound.remark, scy: "", sni: "", tls: stream.security || "none", @@ -157,6 +157,6 @@ function buildTrojanLink(inbound, domain, password) { `&sni=${sni}` + `&sid=${sid}` + `&spx=${spx}` + - `#${flag}%20${inbound.remark}-${password}` + `#${flag}%20${inbound.remark}` ); } \ No newline at end of file diff --git a/app/builders/buildVmessTcp.js b/app/builders/buildVmessTcp.js index 0b71e8d..c138586 100644 --- a/app/builders/buildVmessTcp.js +++ b/app/builders/buildVmessTcp.js @@ -14,7 +14,8 @@ export function buildVmessTcp({ port, uuid }) { totalGB: 0, expiryTime: 0, tgId: "", - subId: "", + subId: "0", + alterId: "0", reset: 0 }], }), diff --git a/app/index.js b/app/index.js index 50e8af0..e1435a2 100644 --- a/app/index.js +++ b/app/index.js @@ -13,6 +13,7 @@ import { buildInboundLink } from "./builders/buildInboundLink.js"; const { UI_URL, UI_LOGIN, UI_PASSWORD, UI_HOST } = process.env; const SUB_FILE = "/subscriptions/list.txt"; +const LAST_INBOUNDS = '/subscriptions/latestInbounds.json'; const cookieJar = {}; const api = axios.create({ baseURL: UI_URL, timeout: 15000, withCredentials: true }); @@ -124,6 +125,26 @@ async function getInbounds() { } catch (e) { console.error("Get inbounds failed:", e.message); return []; } } +async function deleteInbounds() { + try { + const data = fs.readFileSync(LAST_INBOUNDS, 'utf-8'); + const oldIds = JSON.parse(data); + + if (Array.isArray(oldIds) && oldIds.length > 0) { + console.log(`Удаляем старые инбаунды: ${oldIds.length} шт.`); + for (const id of oldIds) { + try { + await deleteInbound(id); + } catch (err) { + console.error(`Ошибка при удалении инбаунда ${id}:`, err.message); + } + } + } + } catch (error) { + console.log("Старых ID не найдено, пропускаем удаление."); + } +} + async function deleteInbound(id) { try { await api.post(`/panel/api/inbounds/del/${id}`); } catch { } } @@ -131,7 +152,7 @@ async function deleteInbound(id) { async function addInbound(config) { try { const res = await api.post("/panel/api/inbounds/add", config); - return res.data?.id || null; + return res.data?.obj?.id || null; } catch (e) { console.error("Add inbound failed:", e.message); return null; @@ -147,8 +168,7 @@ async function rotate() { const usedPorts = new Set(); const subs = []; - const existing = await getInbounds(); - for (const i of existing) await deleteInbound(i.id); + await deleteInbounds(); const builders = [ async (d) => buildVlessRealityTcp({ port: await isPortFree(8443) ? 8443 : await getFreePort(usedPorts), uuid: await uuid(), domain: d, keys: await generateRealityKeys() }), @@ -163,6 +183,8 @@ async function rotate() { async (d) => buildTrojanRealityTcp({ port: await getFreePort(usedPorts), uuid: await uuid(), domain: d, keys: await generateRealityKeys() }), ]; + const inboundIds = []; + for (const b of builders) { const domain = pickDomain(whitelist); const inbound = await b(domain); @@ -172,7 +194,13 @@ async function rotate() { // Build the link depending on the protocol const link = buildInboundLink(inbound, UI_HOST, idOrPass); if (link) subs.push(link); - await addInbound(inbound); + const id = await addInbound(inbound); + inboundIds.push(id); + } + + if (inboundIds.length > 0) { + fs.writeFileSync(LAST_INBOUNDS, JSON.stringify(inboundIds, null, 2)); + console.log(`Новые ID (${inboundIds.length} шт.) сохранены в ${LAST_INBOUNDS}`); } fs.writeFileSync(SUB_FILE, subs.join("\n") + "\n", "utf8");