diff --git a/README.md b/README.md index 9667dbd..f413120 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,9 @@ control-сервер и DERP идут по TCP через `dialer-proxy`. На Сборка ядра: `tools/core/build.sh v1.19.32 ts1` → `tools/core/dist/*.gz` → релиз `core-v1.19.32-ts1` в репозитории kit (`MIHOMO_VERSION` / `MIHOMO_BASE` в `router/mihomo-kit.sh`). Если ядро не скачалось, `fix` оставляет текущее и запускает -nikki. Когда исправление появится в mihomo, вернуть официальный релиз. +nikki. Другое ядро на конкретном роутере — `/etc/nikki/kit.env`, например +`MIHOMO_VERSION=v1.19.32` (версии без `-ts` качаются с GitHub MetaCubeX), затем +`mihomo-kit.sh fix`. Когда исправление появится в mihomo, вернуть официальный релиз. ## Если что-то не работает diff --git a/luci/mihomo-kit.js b/luci/mihomo-kit.js index 6a20694..0989fd2 100644 --- a/luci/mihomo-kit.js +++ b/luci/mihomo-kit.js @@ -150,6 +150,38 @@ function loadQr() { }); } +// one hysteria2 server from the form -> mihomo proxy YAML (parseHy2 reads it back) +function hy2Yaml(d) { + var q = function(v) { return '"' + String(v).replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; }; + var y = [ '- name: ' + d.name, ' type: hysteria2', ' server: ' + d.server, ' port: ' + d.port, + ' password: ' + q(d.password) ]; + if (d.obfs_password) + y.push(' obfs: salamander', ' obfs-password: ' + q(d.obfs_password)); + if (d.sni) + y.push(' sni: ' + d.sni); + if (d.insecure) + y.push(' skip-cert-verify: true'); + if (d.up) + y.push(' up: ' + q(d.up)); + if (d.down) + y.push(' down: ' + q(d.down)); + return y.join('\n') + '\n'; +} + +// clipboard: navigator.clipboard needs https, LuCI is usually plain http; +// then execCommand('copy'), and if that fails too, show the text to copy by hand +function copyText(text) { + if (navigator.clipboard && window.isSecureContext) + return navigator.clipboard.writeText(text).then(function() { return true; }); + var ta = E('textarea', { 'style': 'position:fixed;top:0;left:0;opacity:0' }, text); + document.body.appendChild(ta); + ta.select(); + var ok = false; + try { ok = document.execCommand('copy'); } catch (e) {} + document.body.removeChild(ta); + return Promise.resolve(ok); +} + function readFile(input) { var f = input.files && input.files[0]; if (!f) @@ -216,11 +248,11 @@ return view.extend({ row('nikki', st.running ? [ 'работает — ', E('a', { 'href': dash, 'target': '_blank', 'rel': 'noreferrer' }, 'открыть дашборд') ] : E('strong', 'остановлен')), - row('Ядро mihomo', [ st.core_version || 'не найдено', - /-ts\d+$/.test(st.core_version || '') ? ' — сборка kit с правкой для Tailscale' : '', - st.core_wanted && st.core_version != st.core_wanted + row('Ядро mihomo', [ st.core_version || 'не найдено' ] + .concat(/-ts\d+$/.test(st.core_version || '') ? [ ' — сборка kit с правкой для Tailscale' ] : []) + .concat(st.core_wanted && st.core_version != st.core_wanted ? [ ' — ', E('strong', { 'style': 'color:#c00' }, 'kit ждёт ' + st.core_wanted), ': нажми «Починить» в «Обслуживании»' ] - : '' ]), + : [])), row('Версия kit', [ st.kit_version || 'неизвестна (появится после «Обновить kit»)', ' ', updState ]), row('Профиль', [ select, ' ', this.button('Включить', 'apply', 'use', function() { return select.value; }) ]) @@ -426,10 +458,28 @@ return view.extend({ field('SNI', e.sni), field('Не проверять сертификат', e.insecure, 'для самоподписанного сертификата (SNI чужого сайта)'), field('Up / Down', [ e.up, e.down ], 'реальный потолок канала клиента; пусто — без ограничения'), - E('button', { 'class': 'btn cbi-button cbi-button-remove', 'click': function() { - hy2List.removeChild(el); - hy2.splice(hy2.indexOf(e), 1); - } }, 'Удалить сервер') + E('div', [ + E('button', { 'class': 'btn cbi-button cbi-button-action', 'click': function() { + var yaml = hy2Yaml({ name: e.name.value.trim(), server: e.server.value.trim(), port: e.port.value.trim(), + password: e.password.value, obfs_password: e.obfs_password.value, sni: e.sni.value.trim(), + insecure: e.insecure.checked, up: e.up.value.trim(), down: e.down.value.trim() }); + copyText(yaml).then(function(ok) { + if (ok) + return ui.addNotification(null, E('p', 'Конфиг ' + e.name.value.trim() + + ' скопирован: на другом роутере — «Импорт из YAML / ссылки». В нём пароли, не публикуй.'), 'info'); + ui.showModal('Конфиг ' + e.name.value.trim(), [ + E('p', 'Скопировать автоматически не вышло — выдели и скопируй:'), + E('textarea', { 'class': 'cbi-input-textarea', 'rows': 12, 'readonly': 'readonly', + 'style': 'width:100%;font-family:monospace', 'click': function(ev) { ev.target.select(); } }, yaml), + E('div', { 'class': 'right' }, E('button', { 'class': 'btn', 'click': ui.hideModal }, 'Закрыть')) + ]); + }); + } }, 'Скопировать'), ' ', + E('button', { 'class': 'btn cbi-button cbi-button-remove', 'click': function() { + hy2List.removeChild(el); + hy2.splice(hy2.indexOf(e), 1); + } }, 'Удалить сервер') + ]) ]); hy2.push(e); hy2List.appendChild(el); diff --git a/luci/rpcd.sh b/luci/rpcd.sh index 8b11f21..a232c5e 100644 --- a/luci/rpcd.sh +++ b/luci/rpcd.sh @@ -72,7 +72,7 @@ m_status() { json_add_string kit_version "$(cat "$NIKKI_DIR/kit/VERSION" 2>/dev/null)" # installed core vs the one the kit pins (MIHOMO_VERSION default in mihomo-kit.sh) json_add_string core_version "$(mihomo -v 2>/dev/null | awk '{print $3; exit}')" - json_add_string core_wanted "$(sed -n 's/^: "${MIHOMO_VERSION:=\(.*\)}"$/\1/p' "$NIKKI_DIR/kit/router/mihomo-kit.sh" 2>/dev/null)" + json_add_string core_wanted "$(mihomo-kit.sh core-wanted 2>/dev/null)" json_add_boolean auto_update "$(b grep -q 'mihomo-kit.sh auto-update' /etc/crontabs/root)" # phone config (MOBILE=1): /mihomo-kit/.yaml served by uhttpd mob=$(ls /www/mihomo-kit/*.yaml 2>/dev/null | head -n 1) diff --git a/router/mihomo-kit.sh b/router/mihomo-kit.sh index 59b618c..1399b2a 100755 --- a/router/mihomo-kit.sh +++ b/router/mihomo-kit.sh @@ -36,11 +36,16 @@ TPL_DIR="${TPL_DIR:-$KIT_DIR/templates}" NIKKI_DIR="${NIKKI_DIR:-/etc/nikki}" PROFILES_D="$NIKKI_DIR/profiles.d" PROFILES_OUT="$NIKKI_DIR/profiles" +# per-router overrides (MIHOMO_VERSION, MIHOMO_BASE, ...), e.g. MIHOMO_VERSION=v1.19.32 +[ -f /etc/nikki/kit.env ] && . /etc/nikki/kit.env : "${MIHOMO_VERSION:=v1.19.32-ts1}" -# where mihomo-linux--.gz is downloaded from. -ts1: own build with +# where mihomo-linux--.gz is downloaded from. -tsN: own build with # tools/core/*.patch (Tailscale through dialer-proxy, MetaCubeX/mihomo#3142) in the -# kit repo's releases; back to upstream (MetaCubeX/mihomo releases) once it is fixed there. -: "${MIHOMO_BASE:=https://git.sam-hub.net/sam/mihomo-kit/releases/download/core-$MIHOMO_VERSION}" +# kit repo's releases; other versions: upstream MetaCubeX/mihomo releases. +case "$MIHOMO_VERSION" in + *-ts*) : "${MIHOMO_BASE:=https://git.sam-hub.net/sam/mihomo-kit/releases/download/core-$MIHOMO_VERSION}" ;; + *) : "${MIHOMO_BASE:=https://github.com/MetaCubeX/mihomo/releases/download/$MIHOMO_VERSION}" ;; +esac : "${KIT_URL:=https://git.sam-hub.net/sam/mihomo-kit/archive/main.tar.gz}" log() { echo "$*" >&2; } @@ -1223,6 +1228,8 @@ case "${1:-}" in configure) shift; cmd_configure "$@" ;; mobile) shift; cmd_mobile "$@" ;; sub-ids) cmd_sub_ids ;; + # the core version the kit wants on this router (LuCI) + core-wanted) echo "$MIHOMO_VERSION" ;; update) shift; cmd_update "$@" ;; auto-update) shift; cmd_auto_update "$@" ;; check-update) cmd_check_update ;;