diff --git a/README.md b/README.md index 40e50db..4c2998d 100644 --- a/README.md +++ b/README.md @@ -420,6 +420,15 @@ mihomo разбирает подписку (`luci/servers.js` — перенос сверяет с ним): reality, xhttp, ws, grpc и прочее — как в приложении. «Скопировать» отдаёт сервер как YAML для другого роутера. +«Вход» в карточке — через что подключаться к самому серверу. «Как обычно» — как остальные +свои серверы: на `main` напрямую, на `whitelist` и телефоне через `MY-EXIT`, с CSQTT через +`UPLINK`. «Через FOREIGN», «через RU», «напрямую» или «через пул» действует только для этого +сервера и во всех профилях и в конфиге телефона: например, сервер, до которого напрямую не +достучаться, идёт через ноды FOREIGN, а остальные свои серверы — как раньше. Хранится как +`dialer-proxy` в строке сервера (`/etc/nikki/my-servers`); `dialer-proxy`, вписанный в +«Настройки (YAML)», становится тем же «Входом». Пул, в который сервер входит сам, как вход +нельзя — это петля. + AmneziaWG: туда же вставляется ключ AmneziaVPN `vpn://…` («Поделиться» в приложении; файл `.vpn` тоже можно выбрать) или `.conf` AmneziaWG / обычного WireGuard (текст `[Interface]` … `[Peer]` … или файл — тогда сервер называется по имени файла). Получается сервер diff --git a/luci/mihomo-kit.js b/luci/mihomo-kit.js index 42a9ddf..42c3397 100644 --- a/luci/mihomo-kit.js +++ b/luci/mihomo-kit.js @@ -752,17 +752,39 @@ return view.extend({ servers.forEach(function(e) { t[e.name.value.trim()] = true; }); return t; }; + // "Вход" of an own server (its own dialer-proxy): what it dials through in every + // profile instead of what the kit puts in front (MY-EXIT, UPLINK, directly) + var entryOptions = function(sel) { + var cur = sel.value || sel.getAttribute('data-entry') || ''; + var names = pools.map(function(p) { return p.name.value.trim().toUpperCase(); }).filter(Boolean); + var opts = [ [ '', 'вход: как обычно' ], [ 'FOREIGN', 'вход: через FOREIGN' ], [ 'RU', 'вход: через RU' ], + [ 'DIRECT', 'вход: напрямую' ] ].concat(names.map(function(n) { return [ n, 'вход: через пул ' + n ]; })); + if (cur && !opts.some(function(o) { return o[0] == cur; })) + opts.push([ cur, 'вход: ' + cur + ' (такого нет)' ]); + dom.content(sel, opts.map(function(o) { return E('option', { 'value': o[0] }, o[1]); })); + sel.value = cur; + }; var addServer = function(p, open) { var e = { proxy: {}, error: null }; Object.keys(p).forEach(function(k) { if (k != 'name' && k != 'dialer-proxy') e.proxy[k] = p[k]; }); + e.entry = E('select', { 'class': 'cbi-input-select', 'data-entry': p['dialer-proxy'] || '', + 'title': 'через что подключаться к этому серверу, во всех профилях и на телефоне: например, через FOREIGN, ' + + 'если сам сервер напрямую недоступен. «Как обычно» — как остальные свои серверы' }); + entryOptions(e.entry); + e.entry.addEventListener('focus', function() { entryOptions(e.entry); }); + e.entry.addEventListener('mousedown', function() { entryOptions(e.entry); }); + // "как обычно" is an empty value: keep the choice for the next rebuild of the list + e.entry.addEventListener('change', function() { e.entry.setAttribute('data-entry', e.entry.value); }); e.name = text(S.freeName(p.name, taken()), 'имя в дашборде'); e.name.style.width = '16em'; e.get = function() { var o = { name: e.name.value.trim() }; Object.keys(e.proxy).forEach(function(k) { o[k] = e.proxy[k]; }); + if (e.entry.value) + o['dialer-proxy'] = e.entry.value; return o; }; var info = E('code', {}, S.summary(e.proxy)); @@ -778,6 +800,12 @@ return view.extend({ if (!v.type || v.server === undefined || v.server === null || v.server === '') throw new Error('нужны type и server'); delete v.name; + // dialer-proxy typed in the YAML: the same as the entry select + if (v['dialer-proxy']) { + e.entry.setAttribute('data-entry', v['dialer-proxy']); + e.entry.value = ''; + entryOptions(e.entry); + } delete v['dialer-proxy']; e.proxy = v; e.error = null; @@ -791,7 +819,7 @@ return view.extend({ }); var el = E('div', { 'style': 'border:1px solid #8884;border-radius:4px;padding:.5em;margin-bottom:.5em' }, [ E('div', { 'style': 'display:flex;gap:.5em;align-items:center;flex-wrap:wrap' }, [ - e.name, info, + e.name, info, e.entry, E('button', { 'class': 'btn cbi-button', 'click': function() { e.yaml.style.display = e.yaml.style.display == 'none' ? '' : 'none'; } }, 'Настройки (YAML)'), @@ -1057,6 +1085,12 @@ return view.extend({ errors.push('Свой сервер ' + n + ': ' + e.error); else if (e.proxy.server === undefined || e.proxy.server === null || e.proxy.server === '') errors.push('Свой сервер ' + n + ': пустой server (открой «Настройки (YAML)»)'); + // the entry: a pool that exists and does not hold the server itself (a loop) + var en = e.entry.value, ep = poolData.filter(function(v) { return v.name.toUpperCase() == en; })[0]; + if (en && !/^(FOREIGN|RU|DIRECT)$/.test(en) && !ep) + errors.push('Свой сервер ' + n + ': вход через пул ' + en + ', а такого пула нет'); + else if (ep && ep.servers.split(';').map(function(x) { return x.trim(); }).indexOf(n) >= 0) + errors.push('Свой сервер ' + n + ': вход через пул ' + en + ', в который он сам входит — так нельзя'); srvLines.push(S.toLine(e.get())); }); if (errors.length) { diff --git a/luci/servers.js b/luci/servers.js index 4f63056..bd6871e 100644 --- a/luci/servers.js +++ b/luci/servers.js @@ -1654,13 +1654,14 @@ return { servers: servers, errors: errors }; } - // one stored line: JSON with "name" first (mihomo-kit.sh reads it with sed), no - // dialer-proxy (the kit sets it per profile), "$" as \u0024 (no ${...} for the - // template engine; JSON and YAML both read \u escapes) + // one stored line: JSON with "name" first (mihomo-kit.sh reads it with sed), a + // dialer-proxy only as the server's own entry (LuCI "Вход"; otherwise the kit sets + // it per profile), "$" as \u0024 (no ${...} for the template engine; JSON and YAML + // both read \u escapes) function toLine(p) { var o = { name: String(p.name) }; Object.keys(p).forEach(function (k) { - if (k != 'name' && k != 'dialer-proxy') + if (k != 'name' && (k != 'dialer-proxy' || p[k])) o[k] = p[k]; }); return JSON.stringify(o).replace(/\$/g, '\\u0024'); diff --git a/router/mihomo-kit.sh b/router/mihomo-kit.sh index b78dc9c..a780ed2 100755 --- a/router/mihomo-kit.sh +++ b/router/mihomo-kit.sh @@ -400,12 +400,14 @@ hy2_json() { } # Own servers (LuCI "Свои серверы"): MY_SERVERS_FILE holds one JSON proxy per line -# with "name" first (luci/servers.js), plus the old HY2_* keys -> OWN_BODIES, the -# lines without the leading "{" (templates/proxies puts dialer-proxy in front), and -# OWN_LIST '"a", "b"' for group MY. "$" becomes \u0024: the template engine would read +# with "name" first (luci/servers.js), plus the old HY2_* keys -> OWN_PLAIN, the lines +# without an entry of their own and without the leading "{" (templates/proxies puts the +# kit's dialer-proxy in front), OWN_ENTRY, the lines with one (LuCI "Вход": their own +# "dialer-proxy", kept in every profile), OWN_BODIES, all lines as OWN_PLAIN (for the +# chains' copies, which dial through their entry), and OWN_LIST '"a", "b"' for group MY. "$" becomes \u0024: the template engine would read # ${...} in a password, JSON and YAML both read the escape. own_servers_vars() { - OWN_BODIES="" OWN_LIST="" OWN_NAMES="" + OWN_BODIES="" OWN_PLAIN="" OWN_ENTRY="" OWN_LIST="" OWN_NAMES="" _lines=$( [ -f "$MY_SERVERS_FILE" ] && grep -v '^[[:space:]]*$' "$MY_SERVERS_FILE" for _n in $HY2; do hy2_json "$_n"; done @@ -417,10 +419,26 @@ own_servers_vars() { _dup=$(printf '%s\n' "$_names" | sort | uniq -d | head -n 1) [ -z "$_dup" ] || die "own servers: the name $_dup repeats" OWN_NAMES=$_names - OWN_BODIES=$(printf '%s\n' "$_lines" | sed 's/^{//; s/\$/\\u0024/g') + OWN_BODIES=$(printf '%s\n' "$_lines" | sed 's/^{//; s/,"dialer-proxy":"[^"]*"//; s/\$/\\u0024/g') + OWN_PLAIN=$(printf '%s\n' "$_lines" | grep -v '"dialer-proxy":' | sed 's/^{//; s/\$/\\u0024/g') + OWN_ENTRY=$(printf '%s\n' "$_lines" | grep '"dialer-proxy":' | sed 's/^/- /; s/\$/\\u0024/g') OWN_LIST=$(printf '%s\n' "$_names" | sed 's/\$/\\u0024/g' | awk '{ printf "%s%s", (NR > 1 ? ", " : ""), $0 }') } +# own_entries_check (after pools_vars): an own server's entry is FOREIGN, RU, DIRECT +# or a pool that does not hold the server itself (that would be a loop) +own_entries_check() { + printf '%s\n' "$OWN_ENTRY" | sed -nE 's/^- \{"name":("([^"\\]|\\.)*"),.*"dialer-proxy":"([^"]*)".*/\3 \1/p' | + while read -r _oe _on; do + case " FOREIGN RU DIRECT$POOL_GROUPS" in *" $_oe "*) ;; *) die "own server $_on: entry $_oe is not FOREIGN, RU, DIRECT or a pool" ;; esac + case "$_oe" in FOREIGN | RU | DIRECT) continue ;; esac + # pool_vars sets _n, _e and others of its own + pool_vars "$(printf '%s' "$_oe" | tr 'A-Z' 'a-z')" + printf '%s\n' "$POOL_JSON" | grep -qxF "$_on" && die "own server $_on: its entry is the pool $_oe that holds it (a loop)" + true + done || exit 1 +} + # Services (SERVICES="claude ..."): a site or app that always takes its own way, with # a group of its own in the dashboard. Per service, keys SVC__* (upper case, - -> _): # _GEOSITE geosite lists of MetaCubeX/meta-rules-dat (GEOSITE_URL), e.g. "anthropic" @@ -963,6 +981,7 @@ render() { # after compute_tags: pools use SUB_LIST / MY_SUB_LIST services_fixed_vars pools_vars + own_entries_check services_vars [ -n "$GEOSITE_ITEMS" ] && TAGS="$TAGS geosite " variants_build @@ -971,7 +990,7 @@ render() { BOOT_PBK BOOT_SID TS_HOSTNAME TS_DOMAINS OVPN_PROVIDER OVPN_GROUP OVPN_SERVER_HOST \ OVPN_SERVER_IPS OVPN_ROUTES OVPN_CHECK_URL TS_CHECK_URL CSQTT_IFACE CSQTT_PROCESS \ RU_IPS FOREIGN_IPS MY_IPS RU_DOMAINS FOREIGN_DOMAINS MY_DOMAINS LOCAL_DOMAINS LOCAL_HOSTS_YAML \ - OWN_BODIES OWN_LIST GEOSITE_URL + OWN_PLAIN OWN_ENTRY OWN_LIST GEOSITE_URL _first=1 for s in head proxies:proxies providers:proxy-providers rule-providers:rule-providers sniffer dns \ groups:proxy-groups rules:rules; do diff --git a/templates/proxies/30-own_srv.yaml b/templates/proxies/30-own_srv.yaml index 752fdb0..93b797c 100644 --- a/templates/proxies/30-own_srv.yaml +++ b/templates/proxies/30-own_srv.yaml @@ -1,6 +1,8 @@ # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it - - {"dialer-proxy": "MY-EXIT", ${@@OWN_BODIES} #@my_exit - - {"dialer-proxy": "UPLINK", ${@@OWN_BODIES} #@uplink,!my_exit - - {${@@OWN_BODIES} #@!my_exit,!uplink + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile + - {"dialer-proxy": "MY-EXIT", ${@@OWN_PLAIN} #@my_exit + - {"dialer-proxy": "UPLINK", ${@@OWN_PLAIN} #@uplink,!my_exit + - {${@@OWN_PLAIN} #@!my_exit,!uplink + ${@@OWN_ENTRY} diff --git a/tests/expected/mobile.yaml b/tests/expected/mobile.yaml index 391a29a..2d9e481 100644 --- a/tests/expected/mobile.yaml +++ b/tests/expected/mobile.yaml @@ -16,12 +16,14 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"dialer-proxy": "MY-EXIT", "name":"m1","type":"hysteria2","server":"m.example.com","port":443,"password":"p","udp":true} + - {"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} # copies of own servers for the chains (SVC__CHAIN, POOL__UPLINK): the same # server dialing through another entry, named " ⟶ " (group " ⟶ ") @@ -260,7 +262,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "m1"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "via-foreign", "m1"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-csqtt-foreign.yaml b/tests/expected/router-csqtt-foreign.yaml index 3fbcb73..d503415 100644 --- a/tests/expected/router-csqtt-foreign.yaml +++ b/tests/expected/router-csqtt-foreign.yaml @@ -17,12 +17,14 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "UPLINK", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "UPLINK", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "UPLINK", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"dialer-proxy": "UPLINK", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"dialer-proxy": "UPLINK", "name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p","udp":true} + - {"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} # CSQTT (star-panel-csqtt): tunnel interface csqtt0 on the router, mihomo # just sends the connection out of it (the interface does not change routes) @@ -230,7 +232,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "nl-1"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "via-foreign", "nl-1"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-csqtt.yaml b/tests/expected/router-csqtt.yaml index dbad910..dca53bc 100644 --- a/tests/expected/router-csqtt.yaml +++ b/tests/expected/router-csqtt.yaml @@ -17,11 +17,13 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} + - {"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} # CSQTT (star-panel-csqtt): tunnel interface csqtt0 on the router, mihomo # just sends the connection out of it (the interface does not change routes) @@ -232,7 +234,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "via-foreign"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-foreign.yaml b/tests/expected/router-foreign.yaml index 288f4c1..52ea693 100644 --- a/tests/expected/router-foreign.yaml +++ b/tests/expected/router-foreign.yaml @@ -27,7 +27,8 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p","udp":true} proxy-providers: diff --git a/tests/expected/router-lite.yaml b/tests/expected/router-lite.yaml index 4263fa1..e7e83e4 100644 --- a/tests/expected/router-lite.yaml +++ b/tests/expected/router-lite.yaml @@ -24,7 +24,8 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p","udp":true} proxy-providers: diff --git a/tests/expected/router-main.yaml b/tests/expected/router-main.yaml index 3d8962b..0c0c7ee 100644 --- a/tests/expected/router-main.yaml +++ b/tests/expected/router-main.yaml @@ -27,12 +27,14 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"name":"home-hy","type":"hysteria2","server":"1.1.1.1","port":443,"password":"x","udp":true} + - {"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} proxy-providers: example: @@ -268,7 +270,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "home-hy"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "via-foreign", "home-hy"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-whitelist-ts-my.yaml b/tests/expected/router-whitelist-ts-my.yaml index e150093..bde372f 100644 --- a/tests/expected/router-whitelist-ts-my.yaml +++ b/tests/expected/router-whitelist-ts-my.yaml @@ -32,11 +32,13 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} + - {"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} # copies of own servers for the chains (SVC__CHAIN, POOL__UPLINK): the same # server dialing through another entry, named " ⟶ " (group " ⟶ ") @@ -46,6 +48,7 @@ proxies: - {"dialer-proxy": "FOREIGN", "name":"tr \"q\" ⟶ FOREIGN","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "FOREIGN", "name":"hy-own ⟶ FOREIGN","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} - {"dialer-proxy": "FOREIGN", "name":"awg-own ⟶ FOREIGN","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} + - {"dialer-proxy": "FOREIGN", "name":"via-foreign ⟶ FOREIGN","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x"} proxy-providers: example: @@ -421,7 +424,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "via-foreign"] use: [example-my, example2-my, my-links] url: "https://www.gstatic.com/generate_204" interval: 300 @@ -481,7 +484,7 @@ proxy-groups: # nodes, each dialing through FOREIGN - name: "MY ⟶ FOREIGN" type: fallback - proxies: ["🇩🇪 de 1 ⟶ FOREIGN", "tr \"q\" ⟶ FOREIGN", "hy-own ⟶ FOREIGN", "awg-own ⟶ FOREIGN"] + proxies: ["🇩🇪 de 1 ⟶ FOREIGN", "tr \"q\" ⟶ FOREIGN", "hy-own ⟶ FOREIGN", "awg-own ⟶ FOREIGN", "via-foreign ⟶ FOREIGN"] use: [example-my@FOREIGN, example2-my@FOREIGN, my-links@FOREIGN] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-whitelist-ts.yaml b/tests/expected/router-whitelist-ts.yaml index c047593..b737748 100644 --- a/tests/expected/router-whitelist-ts.yaml +++ b/tests/expected/router-whitelist-ts.yaml @@ -31,7 +31,8 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p","udp":true} - {"dialer-proxy": "MY-EXIT", "name":"de-2","type":"hysteria2","server":"5.6.7.8","port":443,"password":"q","udp":true} diff --git a/tests/expected/router-whitelist.yaml b/tests/expected/router-whitelist.yaml index 92d844a..fc91cdc 100644 --- a/tests/expected/router-whitelist.yaml +++ b/tests/expected/router-whitelist.yaml @@ -28,7 +28,8 @@ proxies: # own servers of the settings (LuCI "Свои серверы", /etc/nikki/my-servers): one JSON # proxy per line, as mihomo's own config would have it; the kit puts dialer-proxy in - # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it + # front: whitelist and the phone through MY-EXIT, else with UPLINK (CSQTT, pools) through it. + # A server with an entry of its own (LuCI "Вход") keeps it in every profile - {"dialer-proxy": "MY-EXIT", "name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p\"w\\1","obfs":"salamander","obfs-password":"obfs","sni":"vpn.example.com","up":"50 mbps","down":"100 mbps","udp":true} - {"dialer-proxy": "MY-EXIT", "name":"de_2","type":"hysteria2","server":"5.6.7.8","port":8443,"password":"x","sni":"www.bing.com","skip-cert-verify":true,"udp":true} diff --git a/tests/fixtures/own.servers b/tests/fixtures/own.servers index 2366ad5..fb4e0ad 100644 --- a/tests/fixtures/own.servers +++ b/tests/fixtures/own.servers @@ -2,3 +2,4 @@ {"name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} {"name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} {"name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} +{"name":"via-foreign","type":"ss","server":"f.example.com","port":8388,"cipher":"aes-256-gcm","password":"x","dialer-proxy":"FOREIGN"} diff --git a/tools/test-servers.js b/tools/test-servers.js index deebf6f..de07661 100755 --- a/tools/test-servers.js +++ b/tools/test-servers.js @@ -44,9 +44,9 @@ for (const f of fs.readdirSync(path.join(root, "amnezia"))) { check("amnezia/" + f, JSON.parse(fs.readFileSync(exp, "utf8")), s.parseText(fs.readFileSync(path.join(root, "amnezia", f), "utf8"), f.replace(/\.[^.]+$/, ""))); } -// a stored line reads back the same, without dialer-proxy, with no "$" left +// a stored line reads back the same (dialer-proxy: the server's own entry), with no "$" left const p = { name: "a$b", type: "ss", server: "h", port: 1, password: "x${Y}", "dialer-proxy": "Z" }; const line = s.toLine(p); -check("toLine", { name: "a$b", type: "ss", server: "h", port: 1, password: "x${Y}" }, +check("toLine", { name: "a$b", type: "ss", server: "h", port: 1, password: "x${Y}", "dialer-proxy": "Z" }, line.includes("$") || !line.startsWith('{"name":') ? null : JSON.parse(line)); process.exit(fail);