From e5bebab5d2cc02d4f7089130484cce45e538d7e5 Mon Sep 17 00:00:00 2001 From: karpenok Date: Wed, 11 Nov 2026 23:55:11 +0700 Subject: [PATCH] =?UTF-8?q?feat(remnawave):=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=20Except-RU=20=D0=BD=D0=B0=20=D1=85=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B5=20yali?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Старое имя NL_YT_TG_ONLY не совпадало с правилами: это полный туннель, RU идёт напрямую. JSON в базовой подписке включён. Co-authored-by: Cursor --- .../core-net/remnawave/defaults/main.yml | 1 + .../remnawave/files/xray-except-ru.json | 151 ++++++++++++++++++ .../roles/core-net/remnawave/tasks/main.yml | 10 ++ .../remnawave/templates/bootstrap-panel.sh.j2 | 43 +++++ 4 files changed, 205 insertions(+) create mode 100644 ansible/roles/core-net/remnawave/files/xray-except-ru.json diff --git a/ansible/roles/core-net/remnawave/defaults/main.yml b/ansible/roles/core-net/remnawave/defaults/main.yml index 1a55d64..7bd932f 100644 --- a/ansible/roles/core-net/remnawave/defaults/main.yml +++ b/ansible/roles/core-net/remnawave/defaults/main.yml @@ -36,6 +36,7 @@ remnawave_xhttp_path: "/xhttp-yali" remnawave_profile_name: "DE-Yali" remnawave_inbound_tag: "Steal-Yali" remnawave_host_remark: "🇩🇪 Yali" +remnawave_xray_template_name: "Except-RU" remnawave_api_token_name: "infra-automation" # Документация WAN egress панели (см. remnanode_panel_egress_ips на ger-nod-02). diff --git a/ansible/roles/core-net/remnawave/files/xray-except-ru.json b/ansible/roles/core-net/remnawave/files/xray-except-ru.json new file mode 100644 index 0000000..e95a4a4 --- /dev/null +++ b/ansible/roles/core-net/remnawave/files/xray-except-ru.json @@ -0,0 +1,151 @@ +{ + "remnawave": { + "addVirtualHostAsOutbound": true + }, + "routing": { + "rules": [ + { + "type": "field", + "domain": [ + "regexp:^([a-z0-9-]+\\.)*2ip\\.[a-z0-9.-]+$", + "domain:ifconfig.me", + "domain:www.ifconfig.me", + "domain:ifconfig.co", + "domain:www.ifconfig.co", + "domain:ifconfig.io", + "domain:www.ifconfig.io", + "domain:ifconfig.so", + "domain:checkip.amazonaws.com", + "domain:api.ipify.org", + "domain:ipify.org", + "domain:ip.sb", + "domain:www.ip.sb", + "domain:api-ipv4.ip.sb", + "domain:api.ipv6.ip.sb", + "domain:ip-api.com", + "domain:api.ipapi.is", + "domain:ipapi.co", + "domain:ipapi.com", + "domain:iplocation.net", + "domain:iplocation.io", + "domain:iplocation.com", + "domain:ipwho.is", + "domain:ipwhois.io", + "domain:ipinfo.io", + "domain:www.ipinfo.io", + "domain:ident.me", + "domain:myip.com", + "domain:whatismyipaddress.com", + "domain:wtfismyip.com", + "domain:whatismyip.com", + "domain:showmyip.com", + "domain:icanhazip.com", + "domain:geojs.io", + "domain:ipleak.net", + "domain:ipleak.org", + "domain:browserleaks.com", + "domain:dnsleaktest.com", + "domain:dnscheck.tools", + "domain:whoer.net", + "domain:hidemy.name", + "domain:sypexgeo.net", + "domain:api.sypexgeo.net", + "domain:mail.ru", + "domain:ip.mail.ru", + "full:ipv4-internet.yandex.net", + "full:ipv6-internet.yandex.net", + "full:www.cloudflare.com/cdn-cgi/trace" + ], + "outboundTag": "direct" + }, + { + "type": "field", + "domain": [ + "domain:habr.com", + "domain:4pda.to", + "domain:4pda.ru", + "domain:kemono.su", + "domain:jut.su", + "domain:kara.su", + "domain:theins.ru", + "domain:tvrain.ru", + "domain:echo.msk.ru", + "domain:the-village.ru", + "domain:snob.ru", + "domain:novayagazeta.ru", + "domain:moscowtimes.ru", + "domain:allnorilsk.ru" + ], + "outboundTag": "proxy" + }, + { + "ip": ["geoip:ru"], + "type": "field", + "outboundTag": "direct" + }, + { + "type": "field", + "domain": ["geosite:category-ru"], + "outboundTag": "direct" + }, + { + "ip": ["geoip:private"], + "type": "field", + "outboundTag": "direct" + }, + { + "type": "field", + "protocol": ["bittorrent"], + "outboundTag": "direct" + }, + { + "type": "field", + "network": "tcp,udp", + "outboundTag": "proxy" + } + ], + "domainMatcher": "hybrid", + "domainStrategy": "IPIfNonMatch" + }, + "inbounds": [ + { + "tag": "socks", + "port": 10808, + "listen": "127.0.0.1", + "protocol": "socks", + "settings": { + "udp": true, + "auth": "noauth" + }, + "sniffing": { + "enabled": true, + "routeOnly": false, + "destOverride": ["http", "tls", "quic"] + } + }, + { + "tag": "http", + "port": 10809, + "listen": "127.0.0.1", + "protocol": "http", + "settings": { + "allowTransparent": false + }, + "sniffing": { + "enabled": true, + "routeOnly": false, + "destOverride": ["http", "tls", "quic"] + } + } + ], + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom" + }, + { + "tag": "block", + "protocol": "blackhole" + } + ] +} diff --git a/ansible/roles/core-net/remnawave/tasks/main.yml b/ansible/roles/core-net/remnawave/tasks/main.yml index 016c095..b5af694 100644 --- a/ansible/roles/core-net/remnawave/tasks/main.yml +++ b/ansible/roles/core-net/remnawave/tasks/main.yml @@ -134,6 +134,14 @@ group: root mode: "0644" +- name: Положить клиентский шаблон Xray Except-RU + ansible.builtin.copy: + src: xray-except-ru.json + dest: "{{ remnawave_dir }}/xray-except-ru.json" + owner: root + group: root + mode: "0644" + - name: Стянуть образы панели Remnawave ansible.builtin.command: docker compose -f {{ remnawave_dir }}/compose.yaml pull register: remnawave_compose_pull @@ -199,6 +207,8 @@ RW_SELFSTEAL: "{{ remnawave_selfsteal_domain }}" RW_XHTTP_PATH: "{{ remnawave_xhttp_path }}" RW_HOST_REMARK: "{{ remnawave_host_remark }}" + RW_XRAY_TEMPLATE_NAME: "{{ remnawave_xray_template_name }}" + RW_XRAY_TEMPLATE_FILE: "{{ remnawave_dir }}/xray-except-ru.json" RW_PROFILE_FILE: "{{ remnawave_dir }}/profile-de-yali.json" RW_PANEL_DOMAIN: "{{ remnawave_panel_domain }}" RW_USERS_FILE: "{{ remnawave_dir }}/users.json" diff --git a/ansible/roles/core-net/remnawave/templates/bootstrap-panel.sh.j2 b/ansible/roles/core-net/remnawave/templates/bootstrap-panel.sh.j2 index b74a620..985ed11 100644 --- a/ansible/roles/core-net/remnawave/templates/bootstrap-panel.sh.j2 +++ b/ansible/roles/core-net/remnawave/templates/bootstrap-panel.sh.j2 @@ -290,6 +290,48 @@ if [ -z "${host_uuid}" ]; then fi users_changed=0 + +# Клиентский Xray JSON. Имя Except-RU: весь tcp/udp в proxy, RU/private/торренты и +# проверки IP в direct. Блок remnawave панель снимает до выдачи клиенту и +# подставляет этот хост как outbound с тегом proxy. +if [ -n "${RW_XRAY_TEMPLATE_FILE:-}" ] && [ -f "${RW_XRAY_TEMPLATE_FILE}" ]; then + want_tpl=$(jq -c . "${RW_XRAY_TEMPLATE_FILE}") + tpl_list=$(api GET /subscription-templates/) + tpl_uuid=$(printf '%s' "${tpl_list}" | jq -r --arg n "${RW_XRAY_TEMPLATE_NAME}" ' + .response.templates[]? | select(.name == $n and .templateType == "XRAY_JSON") | .uuid' | head -1) + if [ -z "${tpl_uuid}" ]; then + tpl_body=$(jq -n --arg n "${RW_XRAY_TEMPLATE_NAME}" --argjson j "${want_tpl}" \ + '{name: $n, templateType: "XRAY_JSON", templateJson: $j}') + tpl_resp=$(api POST /subscription-templates/ -d "${tpl_body}") + tpl_uuid=$(printf '%s' "${tpl_resp}" | jq -r '.response.uuid // empty') + if [ -z "${tpl_uuid}" ]; then + echo "Не удалось создать шаблон ${RW_XRAY_TEMPLATE_NAME}" >&2 + exit 1 + fi + echo "Шаблон ${RW_XRAY_TEMPLATE_NAME} создан" >&2 + users_changed=1 + else + tpl_full=$(api GET "/subscription-templates/${tpl_uuid}") + current_tpl=$(printf '%s' "${tpl_full}" | jq -cS '.response.templateJson // {}') + wanted_tpl=$(jq -cS . "${RW_XRAY_TEMPLATE_FILE}") + if [ "${current_tpl}" != "${wanted_tpl}" ]; then + upd=$(jq -n --arg u "${tpl_uuid}" --argjson j "${want_tpl}" '{uuid: $u, templateJson: $j}') + api PATCH /subscription-templates/ -d "${upd}" >/dev/null + echo "Шаблон ${RW_XRAY_TEMPLATE_NAME} обновлён" >&2 + users_changed=1 + else + echo "Шаблон ${RW_XRAY_TEMPLATE_NAME} уже совпадает" >&2 + fi + fi + bound=$(printf '%s' "${hosts_json}" | jq -r --arg u "${host_uuid}" '.response[]? | select(.uuid == $u) | .xrayJsonTemplateUuid // empty') + if [ "${bound}" != "${tpl_uuid}" ]; then + host_bind=$(jq -n --arg u "${host_uuid}" --arg t "${tpl_uuid}" '{uuid: $u, xrayJsonTemplateUuid: $t}') + api PATCH /hosts/ -d "${host_bind}" >/dev/null + echo "Хост ${RW_SELFSTEAL} привязан к шаблону ${RW_XRAY_TEMPLATE_NAME}" >&2 + users_changed=1 + fi +fi + squad_uuid=$(api GET /internal-squads/ | jq -r --arg n "Default-Squad" ' .response.internalSquads[]? | select(.name == $n) | .uuid' | head -1) if [ -n "${squad_uuid}" ] && [ -n "${inbound_uuid}" ]; then @@ -317,6 +359,7 @@ settings=$(api GET /subscription-settings/ || echo '') if [ -n "${settings}" ]; then patched=$(printf '%s' "${settings}" | jq ' .response + | .serveJsonAtBaseSubscription = true | .responseRules.rules = ( [ {