Added hwid spoof support

This commit is contained in:
Sam Latsin 2026-10-09 16:11:08 +03:00
parent 2557a9aa49
commit fb5f144df9
9 changed files with 369 additions and 30 deletions

View File

@ -73,6 +73,12 @@ mihomo-kit.sh build # после правки /etc/nikki/profiles.d/*.
| `/etc/nikki/bmstu.env`, `bmstu.ovpn` | OpenVPN: логин, пароль, TOTP-секрет | | `/etc/nikki/bmstu.env`, `bmstu.ovpn` | OpenVPN: логин, пароль, TOTP-секрет |
| `/etc/nikki/run/tailscale/` | ключ ноды Tailscale — не удалять | | `/etc/nikki/run/tailscale/` | ключ ноды Tailscale — не удалять |
У каждой подписки свои настройки (`SUB<N>_*` в `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`), Новый профиль = новый файл в `profiles.d/` (например `LOCATION=home` + `OPENVPN=0`),
затем `mihomo-kit.sh build && mihomo-kit.sh use <имя>`. Все опции — в затем `mihomo-kit.sh build && mihomo-kit.sh use <имя>`. Все опции — в
[router/profile.env.example](router/profile.env.example). [router/profile.env.example](router/profile.env.example).

View File

@ -40,6 +40,7 @@ die() { log "error: $*"; exit 1; }
# .each = once per subscription # .each = once per subscription
# line ... #@tag[,!tag] kept only if the conditions hold # line ... #@tag[,!tag] kept only if the conditions hold
# line ... ${@VAR} ... repeated for every word of VAR # line ... ${@VAR} ... repeated for every word of VAR
# line ... ${@@VAR} ... repeated for every line of VAR
# text ${VAR} replaced with the variable # text ${VAR} replaced with the variable
set_defaults() { set_defaults() {
@ -50,6 +51,7 @@ set_defaults() {
: "${GEOSITE_URL:=https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat}" : "${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:=}" : "${BOOT_SERVER:=}" "${BOOT_PORT:=443}" "${BOOT_UUID:=}" "${BOOT_SNI:=}" "${BOOT_PBK:=}" "${BOOT_SID:=}"
: "${TS_HOSTNAME:=mihomo}" "${TS_DOMAINS:=}" : "${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_PROVIDER:=bmstu}" "${OVPN_GROUP:=BMSTU}" "${OVPN_SERVER_HOST:=openvpn4.bmstu.ru}"
: "${OVPN_SERVER_IPS:=195.19.40.7 195.19.33.86}" : "${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}" : "${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)" eval "[ -n \"\${$v}\" ]" || die "$v is empty (BOOT=1)"
done done
fi 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 <index> <url>
# SUB<i>_PROXY BOOT (default with BOOT=1) | DIRECT | any proxy/group | none
# SUB<i>_UA User-Agent (default mihomo, with HWID: HWID_UA)
# SUB<i>_HWID=1 send x-device-os / x-ver-os / x-device-model / x-hwid from HWID_*
# SUB<i>_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() { render_file() {
@ -111,6 +160,14 @@ render_file() {
sub(/[ \t]+$/, "", line) sub(/[ \t]+$/, "", line)
for (k = 1; k <= n; k++) if (!active(cs[k])) next 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) { if ((i = index(line, "${@")) > 0) {
j = index(substr(line, i + 3), "}") j = index(substr(line, i + 3), "}")
pre = substr(line, 1, i - 1) pre = substr(line, 1, i - 1)
@ -150,8 +207,7 @@ render_section() {
if [ "$EACH" = 1 ]; then if [ "$EACH" = 1 ]; then
i=0 i=0
for u in $SUBS; do for u in $SUBS; do
SUB_NAME="sub$i" SUB_URL="$u" sub_vars "$i" "$u"
export SUB_NAME SUB_URL
_part=$(render_file "$f") _part=$(render_file "$f")
[ -n "$_part" ] && _out="${_out:+$_out [ -n "$_part" ] && _out="${_out:+$_out
@ -392,15 +448,7 @@ wizard() {
echo "== mihomo-kit: профиль роутера ==" echo "== mihomo-kit: профиль роутера =="
echo "Ответы сохранятся в $PROFILES_D/common.env (chmod 600)." echo "Ответы сохранятся в $PROFILES_D/common.env (chmod 600)."
echo echo
echo "Подписки: по одному URL на строку, пустая строка — конец."
} > "$TTY_OUT" } > "$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)" ask _vless "BOOT: vless:// ссылка seed-ноды (пусто = без BOOT)"
BOOT=0 BOOT=0
@ -410,6 +458,39 @@ wizard() {
BOOT=1 BOOT=1
fi 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 yesno TORRENT "Торренты через TORRENT-SEL (порты 20000-20199)" y
ask RU_IPS "Доп. IP через RU (CIDR через пробел)" "" 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 "# written by mihomo-kit.sh setup; edit and run: mihomo-kit.sh build"
echo "TARGET=router" echo "TARGET=router"
echo "SUBS=$(q "$SUBS")" 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" echo "BOOT=$BOOT"
if [ "$BOOT" = 1 ]; then if [ "$BOOT" = 1 ]; then
for v in BOOT_SERVER BOOT_PORT BOOT_UUID BOOT_SNI BOOT_PBK BOOT_SID; do for v in BOOT_SERVER BOOT_PORT BOOT_UUID BOOT_SNI BOOT_PBK BOOT_SID; do

View File

@ -13,6 +13,19 @@ LOCATION=home
# subscription URLs, space separated -> sub0, sub1, ... # subscription URLs, space separated -> sub0, sub1, ...
SUBS="https://sub.example.com/sub/xxxx" 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: whitelisted vless reality node used to download the subscriptions
BOOT=1 BOOT=1
BOOT_SERVER=1.2.3.4 BOOT_SERVER=1.2.3.4

View File

@ -3,10 +3,11 @@
url: "${SUB_URL}" url: "${SUB_URL}"
path: ./providers/${SUB_NAME}.yaml path: ./providers/${SUB_NAME}.yaml
interval: 3600 interval: 3600
proxy: BOOT #@boot proxy: ${@SUB_PROXY}
exclude-filter: "(?i)app not supported|приложение не|свяжитесь" exclude-filter: "(?i)app not supported|приложение не|свяжитесь"
header: header:
User-Agent: ["mihomo"] User-Agent: ["${SUB_UA}"]
${@@SUB_HEADERS}
health-check: health-check:
enable: true enable: true
url: "https://www.gstatic.com/generate_204" url: "https://www.gstatic.com/generate_204"

8
tests/fixtures/router-hwid.env vendored Normal file
View File

@ -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

View File

@ -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"); for (const f of fs.readdirSync(full)) templates[`${dir}/${f}`] = fs.readFileSync(path.join(full, f), "utf8");
} }
const vars = {}; 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 { try {
process.stdout.write(render(templates, vars)); process.stdout.write(render(templates, vars));
} catch (e) { } catch (e) {

View File

@ -6,6 +6,7 @@
// .each = once per subscription // .each = once per subscription
// line ... #@tag[,!tag] kept only if the conditions hold // line ... #@tag[,!tag] kept only if the conditions hold
// line ... ${@VAR} ... repeated for every word of VAR // line ... ${@VAR} ... repeated for every word of VAR
// line ... ${@@VAR} ... repeated for every line of VAR
// text ${VAR} replaced with the variable // text ${VAR} replaced with the variable
(function (root) { (function (root) {
@ -17,6 +18,7 @@
GEOSITE_URL: "https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat", 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: "", BOOT_SERVER: "", BOOT_PORT: "443", BOOT_UUID: "", BOOT_SNI: "", BOOT_PBK: "", BOOT_SID: "",
TS_HOSTNAME: "mihomo", TS_DOMAINS: "", 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_PROVIDER: "bmstu", OVPN_GROUP: "BMSTU", OVPN_SERVER_HOST: "openvpn4.bmstu.ru",
OVPN_SERVER_IPS: "195.19.40.7 195.19.33.86", 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", 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)`); 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) { function computeTags(v) {
@ -77,11 +112,12 @@
const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c))); const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c)));
if (!ok) continue; if (!ok) continue;
} }
const m = line.match(/\$\{@([A-Za-z0-9_]+)\}/); const m = line.match(/\$\{(@@?)([A-Za-z0-9_]+)\}/);
if (m) { if (m) {
const pre = line.slice(0, m.index); const pre = line.slice(0, m.index);
const post = line.slice(m.index + m[0].length); 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; continue;
} }
out.push(subst(line, v)); out.push(subst(line, v));
@ -122,7 +158,7 @@
if (!info.active) continue; if (!info.active) continue;
if (info.each) { if (info.each) {
subs.forEach((url, i) => { 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); if (part) parts.push(part);
}); });
} else { } else {

View File

@ -66,6 +66,15 @@
} }
.error { color: var(--err); margin: 0 0 10px; font-weight: 600; } .error { color: var(--err); margin: 0 0 10px; font-weight: 600; }
.note { color: var(--muted); font-size: 12px; margin-top: 10px; } .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; } [hidden] { display: none !important; }
</style> </style>
</head> </head>
@ -97,8 +106,10 @@
<fieldset> <fieldset>
<legend>Подписки</legend> <legend>Подписки</legend>
<label for="SUBS">URL, по одному на строку → sub0, sub1, …</label> <div id="subs"></div>
<textarea id="SUBS" placeholder="https://sub.example.com/sub/xxxx"></textarea> <button type="button" class="link-btn" id="add-sub">+ подписка</button>
<p class="hint">«Через»: откуда качать подписку. Авто = BOOT, если он включён.
HWID — для подписок с лимитом устройств (x-hwid, x-device-os, …).</p>
<label for="RU_IPS">Доп. IP через RU (CIDR через пробел)</label> <label for="RU_IPS">Доп. IP через RU (CIDR через пробел)</label>
<input type="text" id="RU_IPS" value="194.190.191.112/32"> <input type="text" id="RU_IPS" value="194.190.191.112/32">
</fieldset> </fieldset>
@ -122,6 +133,18 @@
</div> </div>
</fieldset> </fieldset>
<fieldset data-hwid>
<legend>HWID</legend>
<p class="hint">Общий для всех подписок с галкой HWID. Если провайдер уже знает устройство — тот же x-hwid.</p>
<label for="HWID_UA">User-Agent</label><input type="text" id="HWID_UA" value="v2rayN/9.99">
<div class="two">
<div><label for="HWID_OS">x-device-os</label><input type="text" id="HWID_OS" value="OpenWrt"></div>
<div><label for="HWID_OS_VER">x-ver-os</label><input type="text" id="HWID_OS_VER" placeholder="24.10.3"></div>
</div>
<label for="HWID_MODEL">x-device-model</label><input type="text" id="HWID_MODEL" placeholder="Huasifei WH3000 Pro">
<label for="HWID_ID">x-hwid</label><input type="text" id="HWID_ID">
</fieldset>
<fieldset data-router> <fieldset data-router>
<legend>Модули роутера</legend> <legend>Модули роутера</legend>
<label class="check"><input type="checkbox" id="TORRENT" checked>Торренты (порты 20000–20199 → TORRENT-SEL)</label> <label class="check"><input type="checkbox" id="TORRENT" checked>Торренты (порты 20000–20199 → TORRENT-SEL)</label>
@ -171,6 +194,7 @@
// .each = once per subscription // .each = once per subscription
// line ... #@tag[,!tag] kept only if the conditions hold // line ... #@tag[,!tag] kept only if the conditions hold
// line ... ${@VAR} ... repeated for every word of VAR // line ... ${@VAR} ... repeated for every word of VAR
// line ... ${@@VAR} ... repeated for every line of VAR
// text ${VAR} replaced with the variable // text ${VAR} replaced with the variable
(function (root) { (function (root) {
@ -182,6 +206,7 @@
GEOSITE_URL: "https://cdn.jsdelivr.net/gh/SamLatsin/russia-only@release/geosite.dat", 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: "", BOOT_SERVER: "", BOOT_PORT: "443", BOOT_UUID: "", BOOT_SNI: "", BOOT_PBK: "", BOOT_SID: "",
TS_HOSTNAME: "mihomo", TS_DOMAINS: "", 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_PROVIDER: "bmstu", OVPN_GROUP: "BMSTU", OVPN_SERVER_HOST: "openvpn4.bmstu.ru",
OVPN_SERVER_IPS: "195.19.40.7 195.19.33.86", 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", 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)`); 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) { function computeTags(v) {
@ -242,11 +300,12 @@
const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c))); const ok = conds.every((c) => (c.startsWith("!") ? !tags.has(c.slice(1)) : tags.has(c)));
if (!ok) continue; if (!ok) continue;
} }
const m = line.match(/\$\{@([A-Za-z0-9_]+)\}/); const m = line.match(/\$\{(@@?)([A-Za-z0-9_]+)\}/);
if (m) { if (m) {
const pre = line.slice(0, m.index); const pre = line.slice(0, m.index);
const post = line.slice(m.index + m[0].length); 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; continue;
} }
out.push(subst(line, v)); out.push(subst(line, v));
@ -287,7 +346,7 @@
if (!info.active) continue; if (!info.active) continue;
if (info.each) { if (info.each) {
subs.forEach((url, i) => { 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); if (part) parts.push(part);
}); });
} else { } else {
@ -320,7 +379,7 @@ const TEMPLATES = {
"groups/90-base.yaml": " - name: MAIN\n type: select\n proxies: [FOREIGN, RU, DIRECT]\n", "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", "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", "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", "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/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", "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]; 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 = `
<div class="sub-head"><span class="name"></span>
<input type="text" data-k="url" placeholder="https://sub.example.com/sub/xxxx">
<button type="button" class="x-btn" title="убрать">×</button></div>
<div class="sub-opts">
<label>через <select data-k="proxy"><option value="">авто</option><option>BOOT</option><option>DIRECT</option></select></label>
<label class="check"><input type="checkbox" data-k="hwid">HWID</label>
</div>
<details><summary>User-Agent и заголовки</summary>
<label>User-Agent (пусто = mihomo, с HWID — из блока HWID)</label><input type="text" data-k="ua">
<label>доп. заголовки: key=value; key2=value 2</label><input type="text" data-k="headers">
</details>`;
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 radio(name) { return form.querySelector(`input[name=${name}]:checked`).value; }
function flag(id) { return $(id).checked ? "1" : "0"; } function flag(id) { return $(id).checked ? "1" : "0"; }
function readVars() { function readVars() {
const v = { const v = {
TARGET: radio("TARGET"), LOCATION: radio("LOCATION"), TARGET: radio("TARGET"), LOCATION: radio("LOCATION"),
SUBS: $("SUBS").value.trim().split(/\s+/).filter(Boolean).join(" "), SUBS: "",
RU_IPS: $("RU_IPS").value.trim(), RU_IPS: $("RU_IPS").value.trim(),
BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"), BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"),
TAILSCALE: flag("TAILSCALE"), TS_EXIT: flag("TS_EXIT"), 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"]) { "TS_HOSTNAME", "TS_DOMAINS", "OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) {
v[k] = $(k).value.trim(); 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; return v;
} }
const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'"; const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'";
function envFile(v) { 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"); if (v.BOOT === "1") keys.push("BOOT_SERVER", "BOOT_PORT", "BOOT_UUID", "BOOT_SNI", "BOOT_PBK", "BOOT_SID");
keys.push("TORRENT", "RU_IPS", "OPENVPN"); keys.push("TORRENT", "RU_IPS", "OPENVPN");
if (v.OPENVPN === "1") keys.push("OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"); 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-boot]").forEach((el) => (el.hidden = v.BOOT !== "1"));
document.querySelectorAll("[data-openvpn]").forEach((el) => (el.hidden = v.OPENVPN !== "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-tailscale]").forEach((el) => (el.hidden = v.TAILSCALE !== "1"));
document.querySelectorAll("[data-hwid]").forEach((el) => (el.hidden = !v._HWID));
if (!router && tab === "env") setTab("yaml"); if (!router && tab === "env") setTab("yaml");
const err = $("error"); const err = $("error");
@ -443,6 +554,7 @@ function parseVless(link) {
} catch (_) { /* not a full link yet */ } } catch (_) { /* not a full link yet */ }
} }
form.addEventListener("change", update);
form.addEventListener("input", (e) => { form.addEventListener("input", (e) => {
if (e.target.id === "vless") parseVless(e.target.value); if (e.target.id === "vless") parseVless(e.target.value);
update(); update();
@ -463,7 +575,7 @@ $("download").addEventListener("click", () => {
a.click(); a.click();
URL.revokeObjectURL(a.href); URL.revokeObjectURL(a.href);
}); });
update(); addSub();
</script> </script>
</body> </body>
</html> </html>

View File

@ -66,6 +66,15 @@
} }
.error { color: var(--err); margin: 0 0 10px; font-weight: 600; } .error { color: var(--err); margin: 0 0 10px; font-weight: 600; }
.note { color: var(--muted); font-size: 12px; margin-top: 10px; } .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; } [hidden] { display: none !important; }
</style> </style>
</head> </head>
@ -97,8 +106,10 @@
<fieldset> <fieldset>
<legend>Подписки</legend> <legend>Подписки</legend>
<label for="SUBS">URL, по одному на строку → sub0, sub1, …</label> <div id="subs"></div>
<textarea id="SUBS" placeholder="https://sub.example.com/sub/xxxx"></textarea> <button type="button" class="link-btn" id="add-sub">+ подписка</button>
<p class="hint">«Через»: откуда качать подписку. Авто = BOOT, если он включён.
HWID — для подписок с лимитом устройств (x-hwid, x-device-os, …).</p>
<label for="RU_IPS">Доп. IP через RU (CIDR через пробел)</label> <label for="RU_IPS">Доп. IP через RU (CIDR через пробел)</label>
<input type="text" id="RU_IPS" value="194.190.191.112/32"> <input type="text" id="RU_IPS" value="194.190.191.112/32">
</fieldset> </fieldset>
@ -122,6 +133,18 @@
</div> </div>
</fieldset> </fieldset>
<fieldset data-hwid>
<legend>HWID</legend>
<p class="hint">Общий для всех подписок с галкой HWID. Если провайдер уже знает устройство — тот же x-hwid.</p>
<label for="HWID_UA">User-Agent</label><input type="text" id="HWID_UA" value="v2rayN/9.99">
<div class="two">
<div><label for="HWID_OS">x-device-os</label><input type="text" id="HWID_OS" value="OpenWrt"></div>
<div><label for="HWID_OS_VER">x-ver-os</label><input type="text" id="HWID_OS_VER" placeholder="24.10.3"></div>
</div>
<label for="HWID_MODEL">x-device-model</label><input type="text" id="HWID_MODEL" placeholder="Huasifei WH3000 Pro">
<label for="HWID_ID">x-hwid</label><input type="text" id="HWID_ID">
</fieldset>
<fieldset data-router> <fieldset data-router>
<legend>Модули роутера</legend> <legend>Модули роутера</legend>
<label class="check"><input type="checkbox" id="TORRENT" checked>Торренты (порты 20000–20199 → TORRENT-SEL)</label> <label class="check"><input type="checkbox" id="TORRENT" checked>Торренты (порты 20000–20199 → TORRENT-SEL)</label>
@ -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]; 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 = `
<div class="sub-head"><span class="name"></span>
<input type="text" data-k="url" placeholder="https://sub.example.com/sub/xxxx">
<button type="button" class="x-btn" title="убрать">×</button></div>
<div class="sub-opts">
<label>через <select data-k="proxy"><option value="">авто</option><option>BOOT</option><option>DIRECT</option></select></label>
<label class="check"><input type="checkbox" data-k="hwid">HWID</label>
</div>
<details><summary>User-Agent и заголовки</summary>
<label>User-Agent (пусто = mihomo, с HWID — из блока HWID)</label><input type="text" data-k="ua">
<label>доп. заголовки: key=value; key2=value 2</label><input type="text" data-k="headers">
</details>`;
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 radio(name) { return form.querySelector(`input[name=${name}]:checked`).value; }
function flag(id) { return $(id).checked ? "1" : "0"; } function flag(id) { return $(id).checked ? "1" : "0"; }
function readVars() { function readVars() {
const v = { const v = {
TARGET: radio("TARGET"), LOCATION: radio("LOCATION"), TARGET: radio("TARGET"), LOCATION: radio("LOCATION"),
SUBS: $("SUBS").value.trim().split(/\s+/).filter(Boolean).join(" "), SUBS: "",
RU_IPS: $("RU_IPS").value.trim(), RU_IPS: $("RU_IPS").value.trim(),
BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"), BOOT: flag("BOOT"), TORRENT: flag("TORRENT"), OPENVPN: flag("OPENVPN"),
TAILSCALE: flag("TAILSCALE"), TS_EXIT: flag("TS_EXIT"), 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"]) { "TS_HOSTNAME", "TS_DOMAINS", "OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"]) {
v[k] = $(k).value.trim(); 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; return v;
} }
const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'"; const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'";
function envFile(v) { 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"); if (v.BOOT === "1") keys.push("BOOT_SERVER", "BOOT_PORT", "BOOT_UUID", "BOOT_SNI", "BOOT_PBK", "BOOT_SID");
keys.push("TORRENT", "RU_IPS", "OPENVPN"); keys.push("TORRENT", "RU_IPS", "OPENVPN");
if (v.OPENVPN === "1") keys.push("OVPN_SERVER_HOST", "OVPN_SERVER_IPS", "OVPN_ROUTES"); 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-boot]").forEach((el) => (el.hidden = v.BOOT !== "1"));
document.querySelectorAll("[data-openvpn]").forEach((el) => (el.hidden = v.OPENVPN !== "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-tailscale]").forEach((el) => (el.hidden = v.TAILSCALE !== "1"));
document.querySelectorAll("[data-hwid]").forEach((el) => (el.hidden = !v._HWID));
if (!router && tab === "env") setTab("yaml"); if (!router && tab === "env") setTab("yaml");
const err = $("error"); const err = $("error");
@ -278,6 +353,7 @@ function parseVless(link) {
} catch (_) { /* not a full link yet */ } } catch (_) { /* not a full link yet */ }
} }
form.addEventListener("change", update);
form.addEventListener("input", (e) => { form.addEventListener("input", (e) => {
if (e.target.id === "vless") parseVless(e.target.value); if (e.target.id === "vless") parseVless(e.target.value);
update(); update();
@ -298,7 +374,7 @@ $("download").addEventListener("click", () => {
a.click(); a.click();
URL.revokeObjectURL(a.href); URL.revokeObjectURL(a.href);
}); });
update(); addSub();
</script> </script>
</body> </body>
</html> </html>