diff --git a/README.md b/README.md index 35b3f19..1075952 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,12 @@ mihomo-kit.sh build # после правки /etc/nikki/profiles.d/*. | `/etc/nikki/bmstu.env`, `bmstu.ovpn` | OpenVPN: логин, пароль, TOTP-секрет | | `/etc/nikki/run/tailscale/` | ключ ноды Tailscale — не удалять | +У каждой подписки свои настройки (`SUB_*` в `common.env`, N — номер в `SUBS`): +через что качать (`SUB1_PROXY=DIRECT`), User-Agent, доп. заголовки и HWID для подписок с +лимитом устройств (`SUB1_HWID=1` + общий блок `HWID_*`: x-device-os, x-ver-os, +x-device-model, x-hwid). Мастер спрашивает это для каждой подписки и сам подставляет ОС, +версию и модель роутера. + Новый профиль = новый файл в `profiles.d/` (например `LOCATION=home` + `OPENVPN=0`), затем `mihomo-kit.sh build && mihomo-kit.sh use <имя>`. Все опции — в [router/profile.env.example](router/profile.env.example). diff --git a/router/mihomo-kit.sh b/router/mihomo-kit.sh index 7c0c4d7..25f7889 100755 --- a/router/mihomo-kit.sh +++ b/router/mihomo-kit.sh @@ -40,6 +40,7 @@ die() { log "error: $*"; exit 1; } # .each = once per subscription # line ... #@tag[,!tag] kept only if the conditions hold # line ... ${@VAR} ... repeated for every word of VAR +# line ... ${@@VAR} ... repeated for every line of VAR # text ${VAR} replaced with the variable set_defaults() { @@ -50,6 +51,7 @@ set_defaults() { : "${GEOSITE_URL:=https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat}" : "${BOOT_SERVER:=}" "${BOOT_PORT:=443}" "${BOOT_UUID:=}" "${BOOT_SNI:=}" "${BOOT_PBK:=}" "${BOOT_SID:=}" : "${TS_HOSTNAME:=mihomo}" "${TS_DOMAINS:=}" + : "${HWID_UA:=v2rayN/9.99}" "${HWID_OS:=}" "${HWID_OS_VER:=}" "${HWID_MODEL:=}" "${HWID_ID:=}" : "${OVPN_PROVIDER:=bmstu}" "${OVPN_GROUP:=BMSTU}" "${OVPN_SERVER_HOST:=openvpn4.bmstu.ru}" : "${OVPN_SERVER_IPS:=195.19.40.7 195.19.33.86}" : "${OVPN_ROUTES:=172.16.0.0/16 172.19.33.0/24 195.19.32.0/19}" @@ -84,6 +86,53 @@ check_vars() { eval "[ -n \"\${$v}\" ]" || die "$v is empty (BOOT=1)" done fi + i=0 + for u in $SUBS; do + eval "_p=\${SUB${i}_PROXY:-} _hw=\${SUB${i}_HWID:-0}" + [ "$_p" = BOOT ] && [ "$BOOT" != 1 ] && die "SUB${i}_PROXY=BOOT but BOOT=0" + if [ "$_hw" = 1 ]; then + for v in HWID_OS HWID_OS_VER HWID_MODEL HWID_ID; do + eval "[ -n \"\${$v}\" ]" || die "$v is empty (SUB${i}_HWID=1)" + done + fi + i=$((i + 1)) + done +} + +# YAML double-quoted string body +yq() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; } + +# per-subscription variables for the .each templates: sub_vars +# SUB_PROXY BOOT (default with BOOT=1) | DIRECT | any proxy/group | none +# SUB_UA User-Agent (default mihomo, with HWID: HWID_UA) +# SUB_HWID=1 send x-device-os / x-ver-os / x-device-model / x-hwid from HWID_* +# SUB_HEADERS extra headers: "key=value; key2=value 2" +sub_vars() { + SUB_NAME="sub$1" SUB_URL="$2" + eval "_p=\${SUB$1_PROXY:-} _ua=\${SUB$1_UA:-} _hw=\${SUB$1_HWID:-0} _h=\${SUB$1_HEADERS:-}" + [ -z "$_p" ] && [ "$BOOT" = 1 ] && _p=BOOT + [ "$_p" = none ] && _p="" + if [ "$_hw" = 1 ]; then + [ -n "$_ua" ] || _ua=$HWID_UA + _h="x-device-os=$HWID_OS;x-ver-os=$HWID_OS_VER;x-device-model=$HWID_MODEL;x-hwid=$HWID_ID${_h:+;$_h}" + fi + SUB_PROXY=$_p + SUB_UA=$(yq "${_ua:-mihomo}") + SUB_HEADERS="" + _old_ifs=$IFS + IFS=';' + set -f + for _item in $_h; do + _item=$(printf '%s' "$_item" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//') + [ -n "$_item" ] || continue + _k=$(printf '%s' "${_item%%=*}" | sed 's/[[:space:]]*$//') + _v=$(printf '%s' "${_item#*=}" | sed 's/^[[:space:]]*//') + SUB_HEADERS="${SUB_HEADERS:+$SUB_HEADERS +}$_k: [\"$(yq "$_v")\"]" + done + set +f + IFS=$_old_ifs + export SUB_NAME SUB_URL SUB_PROXY SUB_UA SUB_HEADERS } render_file() { @@ -111,6 +160,14 @@ render_file() { sub(/[ \t]+$/, "", line) for (k = 1; k <= n; k++) if (!active(cs[k])) next } + if ((i = index(line, "${@@")) > 0) { + j = index(substr(line, i + 4), "}") + pre = substr(line, 1, i - 1) + post = substr(line, i + 4 + j) + n = split(ENVIRON[substr(line, i + 4, j - 1)], ws, "\n") + for (k = 1; k <= n; k++) if (ws[k] != "") print subst(pre ws[k] post) + next + } if ((i = index(line, "${@")) > 0) { j = index(substr(line, i + 3), "}") pre = substr(line, 1, i - 1) @@ -150,8 +207,7 @@ render_section() { if [ "$EACH" = 1 ]; then i=0 for u in $SUBS; do - SUB_NAME="sub$i" SUB_URL="$u" - export SUB_NAME SUB_URL + sub_vars "$i" "$u" _part=$(render_file "$f") [ -n "$_part" ] && _out="${_out:+$_out @@ -392,15 +448,7 @@ wizard() { echo "== mihomo-kit: профиль роутера ==" echo "Ответы сохранятся в $PROFILES_D/common.env (chmod 600)." echo - echo "Подписки: по одному URL на строку, пустая строка — конец." } > "$TTY_OUT" - SUBS="" - while :; do - ask _u " URL" - [ -n "$_u" ] || break - SUBS="${SUBS:+$SUBS }$_u" - done - [ -n "$SUBS" ] || die "нужна хотя бы одна подписка" ask _vless "BOOT: vless:// ссылка seed-ноды (пусто = без BOOT)" BOOT=0 @@ -410,6 +458,39 @@ wizard() { BOOT=1 fi + echo "Подписки: по одной; пустой URL — конец." > "$TTY_OUT" + SUBS="" SUB_LINES="" _n=0 _any_hwid=0 + while :; do + ask _u "sub$_n URL" + [ -n "$_u" ] || break + SUBS="${SUBS:+$SUBS }$_u" + if [ "$BOOT" = 1 ]; then + ask _p " качать через (BOOT/DIRECT)" BOOT + else + _p=DIRECT + fi + [ "$_p" = BOOT ] || SUB_LINES="${SUB_LINES}SUB${_n}_PROXY=$(q "$_p") +" + yesno _hw " HWID-заголовки (x-hwid, x-device-os, ...; для подписок с лимитом устройств)" n + if [ "$_hw" = 1 ]; then + SUB_LINES="${SUB_LINES}SUB${_n}_HWID=1 +" + _any_hwid=1 + fi + _n=$((_n + 1)) + done + [ -n "$SUBS" ] || die "нужна хотя бы одна подписка" + if [ "$_any_hwid" = 1 ]; then + echo "HWID (общий для всех подписок с HWID):" > "$TTY_OUT" + [ -f /etc/openwrt_release ] && . /etc/openwrt_release + ask HWID_UA " User-Agent" "v2rayN/9.99" + ask HWID_OS " x-device-os" "OpenWrt" + ask HWID_OS_VER " x-ver-os" "${DISTRIB_RELEASE:-}" + ask HWID_MODEL " x-device-model" "$(cat /tmp/sysinfo/model 2>/dev/null)" + ask HWID_ID " x-hwid (если провайдер уже знает устройство — тот же)" \ + "$(cat /sys/class/net/br-lan/address 2>/dev/null | md5sum | cut -c1-16)" + fi + yesno TORRENT "Торренты через TORRENT-SEL (порты 20000-20199)" y ask RU_IPS "Доп. IP через RU (CIDR через пробел)" "" @@ -434,6 +515,12 @@ wizard() { echo "# written by mihomo-kit.sh setup; edit and run: mihomo-kit.sh build" echo "TARGET=router" echo "SUBS=$(q "$SUBS")" + printf '%s' "$SUB_LINES" + if [ "$_any_hwid" = 1 ]; then + for v in HWID_UA HWID_OS HWID_OS_VER HWID_MODEL HWID_ID; do + eval "echo \"$v=\$(q \"\$$v\")\"" + done + fi echo "BOOT=$BOOT" if [ "$BOOT" = 1 ]; then for v in BOOT_SERVER BOOT_PORT BOOT_UUID BOOT_SNI BOOT_PBK BOOT_SID; do diff --git a/router/profile.env.example b/router/profile.env.example index b2c7711..8fa5e3c 100644 --- a/router/profile.env.example +++ b/router/profile.env.example @@ -13,6 +13,19 @@ LOCATION=home # subscription URLs, space separated -> sub0, sub1, ... SUBS="https://sub.example.com/sub/xxxx" +# per subscription (N = 0, 1, ... as in SUBS), all optional: +#SUB1_PROXY=DIRECT # fetch through: BOOT (default with BOOT=1) | DIRECT | any proxy/group | none +#SUB1_UA="v2rayN/9.99" # User-Agent, default mihomo (with HWID: HWID_UA) +#SUB1_HWID=1 # send the HWID_* headers below (device-limited subscriptions) +#SUB1_HEADERS="x-foo=bar; x-baz=two words" # any extra headers + +# HWID headers, shared by all subscriptions with SUBn_HWID=1 +#HWID_UA="v2rayN/9.99" +#HWID_OS=OpenWrt # x-device-os +#HWID_OS_VER=24.10.3 # x-ver-os +#HWID_MODEL="Huasifei WH3000 Pro" # x-device-model +#HWID_ID=xxxxxxxxxxxxxxxx # x-hwid: keep the one the provider already knows + # BOOT: whitelisted vless reality node used to download the subscriptions BOOT=1 BOOT_SERVER=1.2.3.4 diff --git a/templates/providers/10-sub.each.yaml b/templates/providers/10-sub.each.yaml index 8533f83..29e20f0 100644 --- a/templates/providers/10-sub.each.yaml +++ b/templates/providers/10-sub.each.yaml @@ -3,10 +3,11 @@ url: "${SUB_URL}" path: ./providers/${SUB_NAME}.yaml interval: 3600 - proxy: BOOT #@boot + proxy: ${@SUB_PROXY} exclude-filter: "(?i)app not supported|приложение не|свяжитесь" header: - User-Agent: ["mihomo"] + User-Agent: ["${SUB_UA}"] + ${@@SUB_HEADERS} health-check: enable: true url: "https://www.gstatic.com/generate_204" diff --git a/tests/fixtures/router-hwid.env b/tests/fixtures/router-hwid.env new file mode 100644 index 0000000..a4c8326 --- /dev/null +++ b/tests/fixtures/router-hwid.env @@ -0,0 +1,8 @@ +SUB0_UA='my "ua" \x' +SUB0_HEADERS="x-a=1; x-b = two words ;" +SUB1_PROXY=DIRECT +SUB1_HWID=1 +HWID_OS=OpenWrt +HWID_OS_VER=24.10.3 +HWID_MODEL="Huasifei WH3000 Pro" +HWID_ID=123 diff --git a/tools/render.js b/tools/render.js index 0c5ccf3..7bbe772 100755 --- a/tools/render.js +++ b/tools/render.js @@ -13,7 +13,7 @@ for (const dir of fs.readdirSync(tplDir)) { for (const f of fs.readdirSync(full)) templates[`${dir}/${f}`] = fs.readFileSync(path.join(full, f), "utf8"); } const vars = {}; -for (const k of Object.keys(DEFAULTS)) if (k in process.env) vars[k] = process.env[k]; +for (const [k, val] of Object.entries(process.env)) if (k in DEFAULTS || /^SUB[0-9]+_/.test(k)) vars[k] = val; try { process.stdout.write(render(templates, vars)); } catch (e) { diff --git a/web/engine.js b/web/engine.js index 3474348..45155db 100644 --- a/web/engine.js +++ b/web/engine.js @@ -6,6 +6,7 @@ // .each = once per subscription // line ... #@tag[,!tag] kept only if the conditions hold // line ... ${@VAR} ... repeated for every word of VAR +// line ... ${@@VAR} ... repeated for every line of VAR // text ${VAR} replaced with the variable (function (root) { @@ -17,6 +18,7 @@ GEOSITE_URL: "https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat", BOOT_SERVER: "", BOOT_PORT: "443", BOOT_UUID: "", BOOT_SNI: "", BOOT_PBK: "", BOOT_SID: "", TS_HOSTNAME: "mihomo", TS_DOMAINS: "", + HWID_UA: "v2rayN/9.99", HWID_OS: "", HWID_OS_VER: "", HWID_MODEL: "", HWID_ID: "", OVPN_PROVIDER: "bmstu", OVPN_GROUP: "BMSTU", OVPN_SERVER_HOST: "openvpn4.bmstu.ru", OVPN_SERVER_IPS: "195.19.40.7 195.19.33.86", OVPN_ROUTES: "172.16.0.0/16 172.19.33.0/24 195.19.32.0/19", @@ -46,6 +48,39 @@ if (!v[k]) throw new Error(`${k} is empty (BOOT=1)`); } } + words(v.SUBS).forEach((_, i) => { + if (v[`SUB${i}_PROXY`] === "BOOT" && v.BOOT !== "1") throw new Error(`SUB${i}_PROXY=BOOT but BOOT=0`); + if (v[`SUB${i}_HWID`] === "1") { + for (const k of ["HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"]) { + if (!v[k]) throw new Error(`${k} is empty (SUB${i}_HWID=1)`); + } + } + }); + } + + // YAML double-quoted string body + const yq = (s) => String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"'); + + // per-subscription variables for the .each templates (see sub_vars in mihomo-kit.sh) + function subVars(v, i, url) { + let proxy = v[`SUB${i}_PROXY`] || (v.BOOT === "1" ? "BOOT" : ""); + if (proxy === "none") proxy = ""; + let ua = v[`SUB${i}_UA`] || ""; + let h = v[`SUB${i}_HEADERS`] || ""; + if (v[`SUB${i}_HWID`] === "1") { + ua = ua || v.HWID_UA; + h = `x-device-os=${v.HWID_OS};x-ver-os=${v.HWID_OS_VER};x-device-model=${v.HWID_MODEL};x-hwid=${v.HWID_ID}` + (h ? ";" + h : ""); + } + const headers = h.split(";").map((x) => x.trim()).filter(Boolean).map((item) => { + const eq = item.indexOf("="); + const key = (eq < 0 ? item : item.slice(0, eq)).replace(/\s+$/, ""); + const val = eq < 0 ? item : item.slice(eq + 1).replace(/^\s+/, ""); + return `${key}: ["${yq(val)}"]`; + }); + return { + SUB_NAME: `sub${i}`, SUB_URL: url, SUB_PROXY: proxy, + SUB_UA: yq(ua || "mihomo"), SUB_HEADERS: headers.join("\n"), + }; } function computeTags(v) { @@ -77,11 +112,12 @@ const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c))); if (!ok) continue; } - const m = line.match(/\$\{@([A-Za-z0-9_]+)\}/); + const m = line.match(/\$\{(@@?)([A-Za-z0-9_]+)\}/); if (m) { const pre = line.slice(0, m.index); const post = line.slice(m.index + m[0].length); - for (const w of words(v[m[1]])) out.push(subst(pre + w + post, v)); + const items = m[1] === "@@" ? (v[m[2]] || "").split("\n").filter(Boolean) : words(v[m[2]]); + for (const w of items) out.push(subst(pre + w + post, v)); continue; } out.push(subst(line, v)); @@ -122,7 +158,7 @@ if (!info.active) continue; if (info.each) { subs.forEach((url, i) => { - const part = renderText(templates[path], { ...v, SUB_NAME: `sub${i}`, SUB_URL: url }, tags); + const part = renderText(templates[path], { ...v, ...subVars(v, i, url) }, tags); if (part) parts.push(part); }); } else { diff --git a/web/index.html b/web/index.html index 5dcb033..ffbb3d0 100644 --- a/web/index.html +++ b/web/index.html @@ -66,6 +66,15 @@ } .error { color: var(--err); margin: 0 0 10px; font-weight: 600; } .note { color: var(--muted); font-size: 12px; margin-top: 10px; } + .sub { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 6px; margin-top: 8px; } + .sub-head { display: flex; gap: 8px; align-items: center; } + .sub-head .name { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); min-width: 34px; } + .sub-head input { flex: 1; min-width: 0; } + .sub-opts { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: 13px; } + .sub-opts select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; } + .sub-opts .check { margin: 0; font-size: 13px; } + .link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 6px 0 0; } + .x-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; } [hidden] { display: none !important; } @@ -97,8 +106,10 @@
Подписки - - +
+ +

«Через»: откуда качать подписку. Авто = BOOT, если он включён. + HWID — для подписок с лимитом устройств (x-hwid, x-device-os, …).

@@ -122,6 +133,18 @@ +
+ HWID +

Общий для всех подписок с галкой HWID. Если провайдер уже знает устройство — тот же x-hwid.

+ +
+
+
+
+ + +
+
Модули роутера @@ -171,6 +194,7 @@ // .each = once per subscription // line ... #@tag[,!tag] kept only if the conditions hold // line ... ${@VAR} ... repeated for every word of VAR +// line ... ${@@VAR} ... repeated for every line of VAR // text ${VAR} replaced with the variable (function (root) { @@ -182,6 +206,7 @@ GEOSITE_URL: "https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat", BOOT_SERVER: "", BOOT_PORT: "443", BOOT_UUID: "", BOOT_SNI: "", BOOT_PBK: "", BOOT_SID: "", TS_HOSTNAME: "mihomo", TS_DOMAINS: "", + HWID_UA: "v2rayN/9.99", HWID_OS: "", HWID_OS_VER: "", HWID_MODEL: "", HWID_ID: "", OVPN_PROVIDER: "bmstu", OVPN_GROUP: "BMSTU", OVPN_SERVER_HOST: "openvpn4.bmstu.ru", OVPN_SERVER_IPS: "195.19.40.7 195.19.33.86", OVPN_ROUTES: "172.16.0.0/16 172.19.33.0/24 195.19.32.0/19", @@ -211,6 +236,39 @@ if (!v[k]) throw new Error(`${k} is empty (BOOT=1)`); } } + words(v.SUBS).forEach((_, i) => { + if (v[`SUB${i}_PROXY`] === "BOOT" && v.BOOT !== "1") throw new Error(`SUB${i}_PROXY=BOOT but BOOT=0`); + if (v[`SUB${i}_HWID`] === "1") { + for (const k of ["HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"]) { + if (!v[k]) throw new Error(`${k} is empty (SUB${i}_HWID=1)`); + } + } + }); + } + + // YAML double-quoted string body + const yq = (s) => String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"'); + + // per-subscription variables for the .each templates (see sub_vars in mihomo-kit.sh) + function subVars(v, i, url) { + let proxy = v[`SUB${i}_PROXY`] || (v.BOOT === "1" ? "BOOT" : ""); + if (proxy === "none") proxy = ""; + let ua = v[`SUB${i}_UA`] || ""; + let h = v[`SUB${i}_HEADERS`] || ""; + if (v[`SUB${i}_HWID`] === "1") { + ua = ua || v.HWID_UA; + h = `x-device-os=${v.HWID_OS};x-ver-os=${v.HWID_OS_VER};x-device-model=${v.HWID_MODEL};x-hwid=${v.HWID_ID}` + (h ? ";" + h : ""); + } + const headers = h.split(";").map((x) => x.trim()).filter(Boolean).map((item) => { + const eq = item.indexOf("="); + const key = (eq < 0 ? item : item.slice(0, eq)).replace(/\s+$/, ""); + const val = eq < 0 ? item : item.slice(eq + 1).replace(/^\s+/, ""); + return `${key}: ["${yq(val)}"]`; + }); + return { + SUB_NAME: `sub${i}`, SUB_URL: url, SUB_PROXY: proxy, + SUB_UA: yq(ua || "mihomo"), SUB_HEADERS: headers.join("\n"), + }; } function computeTags(v) { @@ -242,11 +300,12 @@ const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c))); if (!ok) continue; } - const m = line.match(/\$\{@([A-Za-z0-9_]+)\}/); + const m = line.match(/\$\{(@@?)([A-Za-z0-9_]+)\}/); if (m) { const pre = line.slice(0, m.index); const post = line.slice(m.index + m[0].length); - for (const w of words(v[m[1]])) out.push(subst(pre + w + post, v)); + const items = m[1] === "@@" ? (v[m[2]] || "").split("\n").filter(Boolean) : words(v[m[2]]); + for (const w of items) out.push(subst(pre + w + post, v)); continue; } out.push(subst(line, v)); @@ -287,7 +346,7 @@ if (!info.active) continue; if (info.each) { subs.forEach((url, i) => { - const part = renderText(templates[path], { ...v, SUB_NAME: `sub${i}`, SUB_URL: url }, tags); + const part = renderText(templates[path], { ...v, ...subVars(v, i, url) }, tags); if (part) parts.push(part); }); } else { @@ -320,7 +379,7 @@ const TEMPLATES = { "groups/90-base.yaml": " - name: MAIN\n type: select\n proxies: [FOREIGN, RU, DIRECT]\n", "groups/91-torrent.yaml": " - name: TORRENT-SEL\n type: select\n proxies: [TORRENT, FOREIGN, DIRECT]\n", "head/10-base.yaml": "geodata-mode: true\ngeodata-loader: memconservative\ngeo-auto-update: true\ngeo-update-interval: 24\ngeox-url:\n geoip: \"${GEOIP_URL}\"\n geosite: \"${GEOSITE_URL}\"\n", - "providers/10-sub.each.yaml": " ${SUB_NAME}:\n type: http\n url: \"${SUB_URL}\"\n path: ./providers/${SUB_NAME}.yaml\n interval: 3600\n proxy: BOOT #@boot\n exclude-filter: \"(?i)app not supported|приложение не|свяжитесь\"\n header:\n User-Agent: [\"mihomo\"]\n health-check:\n enable: true\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n timeout: 3000\n lazy: false\n", + "providers/10-sub.each.yaml": " ${SUB_NAME}:\n type: http\n url: \"${SUB_URL}\"\n path: ./providers/${SUB_NAME}.yaml\n interval: 3600\n proxy: ${@SUB_PROXY}\n exclude-filter: \"(?i)app not supported|приложение не|свяжитесь\"\n header:\n User-Agent: [\"${SUB_UA}\"]\n ${@@SUB_HEADERS}\n health-check:\n enable: true\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n timeout: 3000\n lazy: false\n", "providers/20-openvpn.yaml": " # OpenVPN: file written on the router by bmstu-otp.sh (fresh TOTP in the\n # password). No health-check here: a dead tunnel would be redialed with a\n # stale OTP; the cron watchdog (bmstu-otp.sh check) handles it.\n ${OVPN_PROVIDER}:\n type: file\n path: ./providers/${OVPN_PROVIDER}.yaml\n health-check:\n enable: false\n override: #@street\n dialer-proxy: OVPN-EXIT #@street\n", "proxies/10-boot.yaml": " # BOOT: whitelisted entry node, used to download subscriptions\n - name: seed\n type: vless\n server: ${BOOT_SERVER}\n port: ${BOOT_PORT}\n uuid: ${BOOT_UUID}\n network: tcp\n udp: true\n tls: true\n flow: xtls-rprx-vision\n servername: ${BOOT_SNI}\n client-fingerprint: firefox\n reality-opts:\n public-key: ${BOOT_PBK}\n short-id: ${BOOT_SID}\n", "proxies/20-tailscale.yaml": " # Tailscale: userspace node, starts on first use. First login: open the URL\n # from the nikki log (\"To start this tsnet server ... go to: ...\"), then\n # disable key expiry for this node. Needs TS_FORCE_NOISE_443=true in the\n # mihomo environment (mihomo-kit.sh fix).\n - name: tailscale\n type: tailscale\n hostname: ${TS_HOSTNAME}\n state-dir: ./tailscale\n udp: true\n accept-routes: true\n dialer-proxy: TS-EXIT #@ts_exit\n", @@ -340,13 +399,51 @@ let current = { yaml: "", env: "", steps: "" }; for (const k of ["OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) $(k).value = D[k]; +function addSub() { + const row = document.createElement("div"); + row.className = "sub"; + row.innerHTML = ` +
+ +
+
+ + +
+
User-Agent и заголовки + + +
`; + row.querySelector(".x-btn").addEventListener("click", () => { + if (document.querySelectorAll("#subs .sub").length > 1) row.remove(); + update(); + }); + $("subs").appendChild(row); + update(); +} +$("add-sub").addEventListener("click", addSub); + +// rows with a URL, in order -> sub0, sub1, ... +function readSubs() { + const rows = [...document.querySelectorAll("#subs .sub")]; + let n = 0; + return rows.map((row) => { + const get = (k) => row.querySelector(`[data-k=${k}]`); + const url = get("url").value.trim(); + row.querySelector(".name").textContent = url ? `sub${n}` : ""; + if (!url) return null; + return { i: n++, url, proxy: get("proxy").value, hwid: get("hwid").checked, + ua: get("ua").value.trim(), headers: get("headers").value.trim() }; + }).filter(Boolean); +} + function radio(name) { return form.querySelector(`input[name=${name}]:checked`).value; } function flag(id) { return $(id).checked ? "1" : "0"; } function readVars() { const v = { TARGET: radio("TARGET"), LOCATION: radio("LOCATION"), - SUBS: $("SUBS").value.trim().split(/\s+/).filter(Boolean).join(" "), + SUBS: "", RU_IPS: $("RU_IPS").value.trim(), BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"), TAILSCALE: flag("TAILSCALE"), TS_EXIT: flag("TS_EXIT"), @@ -355,13 +452,26 @@ function readVars() { "TS_HOSTNAME", "TS_DOMAINS", "OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) { v[k] = $(k).value.trim(); } + const subs = readSubs(); + v.SUBS = subs.map((x) => x.url).join(" "); + v._HWID = subs.some((x) => x.hwid); + for (const x of subs) { + if (x.proxy) v[`SUB${x.i}_PROXY`] = x.proxy; + if (x.hwid) v[`SUB${x.i}_HWID`] = "1"; + if (x.ua) v[`SUB${x.i}_UA`] = x.ua; + if (x.headers) v[`SUB${x.i}_HEADERS`] = x.headers; + } + for (const k of ["HWID_UA", "HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"]) v[k] = $(k).value.trim(); return v; } const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'"; function envFile(v) { - const keys = ["TARGET", "LOCATION", "SUBS", "BOOT"]; + const keys = ["TARGET", "LOCATION", "SUBS"]; + keys.push(...Object.keys(v).filter((k) => /^SUB[0-9]+_/.test(k))); + if (v._HWID) keys.push("HWID_UA", "HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"); + keys.push("BOOT"); if (v.BOOT === "1") keys.push("BOOT_SERVER", "BOOT_PORT", "BOOT_UUID", "BOOT_SNI", "BOOT_PBK", "BOOT_SID"); keys.push("TORRENT", "RU_IPS", "OPENVPN"); if (v.OPENVPN === "1") keys.push("OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"); @@ -407,6 +517,7 @@ function update() { document.querySelectorAll("[data-boot]").forEach((el) => (el.hidden = v.BOOT !== "1")); document.querySelectorAll("[data-openvpn]").forEach((el) => (el.hidden = v.OPENVPN !== "1")); document.querySelectorAll("[data-tailscale]").forEach((el) => (el.hidden = v.TAILSCALE !== "1")); + document.querySelectorAll("[data-hwid]").forEach((el) => (el.hidden = !v._HWID)); if (!router && tab === "env") setTab("yaml"); const err = $("error"); @@ -443,6 +554,7 @@ function parseVless(link) { } catch (_) { /* not a full link yet */ } } +form.addEventListener("change", update); form.addEventListener("input", (e) => { if (e.target.id === "vless") parseVless(e.target.value); update(); @@ -463,7 +575,7 @@ $("download").addEventListener("click", () => { a.click(); URL.revokeObjectURL(a.href); }); -update(); +addSub(); diff --git a/web/index.src.html b/web/index.src.html index 52dfce8..75dbbab 100644 --- a/web/index.src.html +++ b/web/index.src.html @@ -66,6 +66,15 @@ } .error { color: var(--err); margin: 0 0 10px; font-weight: 600; } .note { color: var(--muted); font-size: 12px; margin-top: 10px; } + .sub { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 6px; margin-top: 8px; } + .sub-head { display: flex; gap: 8px; align-items: center; } + .sub-head .name { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); min-width: 34px; } + .sub-head input { flex: 1; min-width: 0; } + .sub-opts { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: 13px; } + .sub-opts select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; } + .sub-opts .check { margin: 0; font-size: 13px; } + .link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 6px 0 0; } + .x-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; } [hidden] { display: none !important; } @@ -97,8 +106,10 @@
Подписки - - +
+ +

«Через»: откуда качать подписку. Авто = BOOT, если он включён. + HWID — для подписок с лимитом устройств (x-hwid, x-device-os, …).

@@ -122,6 +133,18 @@
+
+ HWID +

Общий для всех подписок с галкой HWID. Если провайдер уже знает устройство — тот же x-hwid.

+ +
+
+
+
+ + +
+
Модули роутера @@ -175,13 +198,51 @@ let current = { yaml: "", env: "", steps: "" }; for (const k of ["OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) $(k).value = D[k]; +function addSub() { + const row = document.createElement("div"); + row.className = "sub"; + row.innerHTML = ` +
+ +
+
+ + +
+
User-Agent и заголовки + + +
`; + row.querySelector(".x-btn").addEventListener("click", () => { + if (document.querySelectorAll("#subs .sub").length > 1) row.remove(); + update(); + }); + $("subs").appendChild(row); + update(); +} +$("add-sub").addEventListener("click", addSub); + +// rows with a URL, in order -> sub0, sub1, ... +function readSubs() { + const rows = [...document.querySelectorAll("#subs .sub")]; + let n = 0; + return rows.map((row) => { + const get = (k) => row.querySelector(`[data-k=${k}]`); + const url = get("url").value.trim(); + row.querySelector(".name").textContent = url ? `sub${n}` : ""; + if (!url) return null; + return { i: n++, url, proxy: get("proxy").value, hwid: get("hwid").checked, + ua: get("ua").value.trim(), headers: get("headers").value.trim() }; + }).filter(Boolean); +} + function radio(name) { return form.querySelector(`input[name=${name}]:checked`).value; } function flag(id) { return $(id).checked ? "1" : "0"; } function readVars() { const v = { TARGET: radio("TARGET"), LOCATION: radio("LOCATION"), - SUBS: $("SUBS").value.trim().split(/\s+/).filter(Boolean).join(" "), + SUBS: "", RU_IPS: $("RU_IPS").value.trim(), BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"), TAILSCALE: flag("TAILSCALE"), TS_EXIT: flag("TS_EXIT"), @@ -190,13 +251,26 @@ function readVars() { "TS_HOSTNAME", "TS_DOMAINS", "OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) { v[k] = $(k).value.trim(); } + const subs = readSubs(); + v.SUBS = subs.map((x) => x.url).join(" "); + v._HWID = subs.some((x) => x.hwid); + for (const x of subs) { + if (x.proxy) v[`SUB${x.i}_PROXY`] = x.proxy; + if (x.hwid) v[`SUB${x.i}_HWID`] = "1"; + if (x.ua) v[`SUB${x.i}_UA`] = x.ua; + if (x.headers) v[`SUB${x.i}_HEADERS`] = x.headers; + } + for (const k of ["HWID_UA", "HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"]) v[k] = $(k).value.trim(); return v; } const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'"; function envFile(v) { - const keys = ["TARGET", "LOCATION", "SUBS", "BOOT"]; + const keys = ["TARGET", "LOCATION", "SUBS"]; + keys.push(...Object.keys(v).filter((k) => /^SUB[0-9]+_/.test(k))); + if (v._HWID) keys.push("HWID_UA", "HWID_OS", "HWID_OS_VER", "HWID_MODEL", "HWID_ID"); + keys.push("BOOT"); if (v.BOOT === "1") keys.push("BOOT_SERVER", "BOOT_PORT", "BOOT_UUID", "BOOT_SNI", "BOOT_PBK", "BOOT_SID"); keys.push("TORRENT", "RU_IPS", "OPENVPN"); if (v.OPENVPN === "1") keys.push("OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"); @@ -242,6 +316,7 @@ function update() { document.querySelectorAll("[data-boot]").forEach((el) => (el.hidden = v.BOOT !== "1")); document.querySelectorAll("[data-openvpn]").forEach((el) => (el.hidden = v.OPENVPN !== "1")); document.querySelectorAll("[data-tailscale]").forEach((el) => (el.hidden = v.TAILSCALE !== "1")); + document.querySelectorAll("[data-hwid]").forEach((el) => (el.hidden = !v._HWID)); if (!router && tab === "env") setTab("yaml"); const err = $("error"); @@ -278,6 +353,7 @@ function parseVless(link) { } catch (_) { /* not a full link yet */ } } +form.addEventListener("change", update); form.addEventListener("input", (e) => { if (e.target.id === "vless") parseVless(e.target.value); update(); @@ -298,7 +374,7 @@ $("download").addEventListener("click", () => { a.click(); URL.revokeObjectURL(a.href); }); -update(); +addSub();