Hysteria2: заглушка байт в байт как у nginx

$(cat …) срезал последний перевод строки, и страница masquerade была на
байт короче той, что отдаёт nginx. Читаю файл целиком (установщик и
kit net masq on), запасная запись страницы – без лишнего перевода строки.
This commit is contained in:
maxdmitrov
2026-10-06 18:40:01 +03:00
parent 387d6ae66e
commit 25df91e79a
4 changed files with 29 additions and 4 deletions
+3 -2
View File
@@ -691,7 +691,8 @@ main() {
install -d -m 755 /var/www/kit
[[ -s /var/www/kit/index.html ]] || stub_site >/var/www/kit/index.html
chmod 644 /var/www/kit/index.html
STUB_HTML=$(cat /var/www/kit/index.html)
# Байт в байт как у nginx: $(…) срезал бы последний перевод строки, и длина ответа Hysteria2 отличалась бы.
STUB_HTML=$(cat /var/www/kit/index.html; printf x); STUB_HTML=${STUB_HTML%x}
local p
for p in "${PROTOS[@]}"; do "proto_$p"; done
# Первый пользователь – сразу на всех протоколах (как «kit user add»).
@@ -1413,7 +1414,7 @@ setup_nginx() {
fi
install -d -m 755 /var/www/kit
[[ -f /var/www/kit/index.html ]] || { if [[ -n ${STUB_HTML:-} ]]; then printf '%s\n' "$STUB_HTML"; else stub_site; fi; } >/var/www/kit/index.html
[[ -f /var/www/kit/index.html ]] || { if [[ -n ${STUB_HTML:-} ]]; then printf '%s' "$STUB_HTML"; else stub_site; fi; } >/var/www/kit/index.html
# Маршруты – из текущих подключений панели: сайты REALITY, пути WebSocket, сервисы gRPC.
local list reality_sni xhttp_sni mt_sni steal_domain locs="" kind path port
+2 -1
View File
@@ -1764,7 +1764,8 @@ hy_masq() { # on|off
id=$(api GET inbounds/list | jq -r '[.[] | select(.protocol == "hysteria")][0].id // empty')
[[ -n $id ]] || die "На сервере нет Hysteria2."
if [[ $act == on ]]; then
page=$(cat /var/www/kit/index.html 2>/dev/null || true)
# Байт в байт как у nginx (с последним переводом строки).
page=$(cat /var/www/kit/index.html 2>/dev/null && printf x || true); page=${page%x}
# Страницы нет только у старых установок с отдельными портами – тогда простая страница без названия.
[[ -n $page ]] || page='<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Welcome</title></head><body style="font-family:sans-serif;text-align:center;margin-top:20vh"><h1>Welcome</h1><p>This site is being updated. Please check back soon.</p></body></html>'
inbound_patch "$id" '.streamSettings |= ((if type == "string" then fromjson else . end) | .hysteriaSettings.masquerade = {type: "string", content: $c, statusCode: 200, headers: {"content-type": "text/html; charset=utf-8"}})' --arg c "$page" \