Improve mobile SSH and router xray apply
This commit is contained in:
1 parent
4b0ada054b
commit
807a32a238
3 files changed
+151
-21
No files matched your search
@@ -2,11 +2,12 @@
|
||||
|
||||
KEY_FILE="${KEY_FILE:-/etc/owrt-remote/web.key}"
|
||||
AGENT="${AGENT:-/usr/sbin/owrt-remote}"
|
||||
OWRT_REMOTE_UI_VERSION="2026-06-29-ssh-terminal-v15"
|
||||
OWRT_REMOTE_UI_VERSION="2026-06-29-xray-apply-v16"
|
||||
PARAMS_FILE="${TMPDIR:-/tmp}/owrt-remote-cgi.$$"
|
||||
RESULT_TITLE=""
|
||||
RESULT_BODY=""
|
||||
RESULT_KIND="info"
|
||||
SHOW_XRAY_SETTINGS="0"
|
||||
|
||||
cleanup() {
|
||||
rm -f "$PARAMS_FILE"
|
||||
@@ -38,14 +39,15 @@ parse_params() {
|
||||
value="${pair#*=}"
|
||||
[ "$pair" = "$key" ] && value=""
|
||||
key="$(url_decode "$key" | tr -d '\r\n\t')"
|
||||
value="$(url_decode "$value" | tr '\r\n\t' ' ')"
|
||||
[ -n "$key" ] && printf '%s\t%s\n' "$key" "$value" >>"$PARAMS_FILE"
|
||||
done
|
||||
IFS="$old_ifs"
|
||||
}
|
||||
|
||||
param() {
|
||||
awk -F ' ' -v k="$1" '$1 == k { print $2; exit }' "$PARAMS_FILE"
|
||||
local raw
|
||||
raw="$(awk -F ' ' -v k="$1" '$1 == k { print $2; exit }' "$PARAMS_FILE")"
|
||||
url_decode "$raw"
|
||||
}
|
||||
|
||||
has_param() {
|
||||
@@ -131,13 +133,42 @@ save_config() {
|
||||
fi
|
||||
uci_set enabled "$enabled"
|
||||
|
||||
for field in router_id router_name role hub_url hub_token heartbeat_interval xray_bin xray_config vps_host vps_port vless_uuid vless_encryption vless_flow reverse_tag admin_host admin_port public_url; do
|
||||
for field in router_id router_name role hub_url hub_token heartbeat_interval xray_bin xray_config vps_host vps_port vless_uuid vless_encryption vless_flow reverse_tag ssh_vless_uuid ssh_reverse_tag admin_host admin_port ssh_host ssh_port public_url; do
|
||||
uci_set "$field" "$(param "$field")"
|
||||
done
|
||||
uci commit owrtremote
|
||||
set_result "Настройки сохранены" "Если менял Xray или VPS-поля, перезапусти сервис." "ok"
|
||||
}
|
||||
|
||||
apply_xray_settings() {
|
||||
local script script_file output rc
|
||||
script="$(param xray_settings_script)"
|
||||
output="${TMPDIR:-/tmp}/owrt-remote-apply.$$"
|
||||
script_file="${TMPDIR:-/tmp}/owrt-remote-apply-script.$$"
|
||||
rc=0
|
||||
SHOW_XRAY_SETTINGS="1"
|
||||
|
||||
if [ -z "$(printf '%s' "$script" | tr -d '[:space:]')" ]; then
|
||||
set_result "Xray настройки" "Вставь команды из OpenWrt config на VPS и нажми Применить." "warn"
|
||||
return
|
||||
fi
|
||||
|
||||
{
|
||||
printf '%s\n' "#!/bin/sh"
|
||||
printf '%s\n' "$script"
|
||||
} >"$script_file"
|
||||
chmod 600 "$script_file" 2>/dev/null || true
|
||||
|
||||
if sh "$script_file" >"$output" 2>&1; then
|
||||
set_result "Xray настройки применены" "$(cat "$output")" "ok"
|
||||
else
|
||||
rc=$?
|
||||
set_result "Ошибка применения Xray настроек" "$(cat "$output")
|
||||
rc=$rc" "bad"
|
||||
fi
|
||||
rm -f "$script_file" "$output"
|
||||
}
|
||||
|
||||
run_action() {
|
||||
local action output rc
|
||||
action="$1"
|
||||
@@ -264,7 +295,7 @@ body::before{content:"";position:fixed;inset:-25%;z-index:0;pointer-events:none;
|
||||
@keyframes auraSpin{from{transform:rotate(0deg) scale(1)}to{transform:rotate(360deg) scale(1.08)}}
|
||||
.wrap{position:relative;z-index:1;max-width:1180px;margin:0 auto;padding:22px}.hero{display:flex;gap:18px;align-items:flex-start;justify-content:space-between;padding:20px 0 18px;border-bottom:1px solid var(--line)}
|
||||
.brand{display:flex;gap:14px;align-items:center}.titleRow{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
||||
h1{margin:0;font-size:28px;line-height:1.2;letter-spacing:0}.sub{margin:4px 0 0;color:var(--muted)}.topActions,.links{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.topActions{justify-content:flex-end;padding-top:42px}.links{margin-top:8px}.vpnCard{display:inline-flex;align-items:center}.uiPill{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:8px;width:132px;min-width:132px;min-height:36px;padding:8px 14px;box-sizing:border-box;border:1px solid var(--line);border-radius:999px;background:rgba(255,255,255,.08);color:#f3e8ff;text-decoration:none;font-weight:800;font-size:13px;line-height:1;white-space:nowrap;overflow:hidden}.nethaven{border-color:rgba(34,211,238,.46);background:linear-gradient(110deg,rgba(14,165,233,.22),rgba(168,85,247,.24),rgba(34,197,94,.16));color:#ecfeff;box-shadow:0 14px 32px rgba(14,165,233,.18)}.nethaven::before{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent,rgba(255,255,255,.24),transparent);transform:translateX(-120%);animation:bannerShine 5.8s ease-in-out infinite}.nethaven span{position:relative}.nethavenDot{position:relative;width:8px;height:8px;border-radius:50%;background:#22d3ee;box-shadow:0 0 14px #22d3ee;animation:pulseDot 2.8s ease-in-out infinite}.returnCard{display:inline-flex}.backBtn{width:auto;min-width:208px;background:#f59e0b;color:#160f06;box-shadow:0 10px 22px rgba(245,158,11,.22)}
|
||||
h1{margin:0;font-size:28px;line-height:1.2;letter-spacing:0}.appBanner{position:relative;display:inline-flex;align-items:center;min-height:44px;padding:8px 18px;border:1px solid rgba(34,211,238,.38);border-radius:999px;background:linear-gradient(110deg,rgba(34,211,238,.18),rgba(124,58,237,.34),rgba(236,72,153,.18));box-shadow:0 16px 42px rgba(124,58,237,.24),inset 0 1px 0 rgba(255,255,255,.12);overflow:hidden}.appBanner::before{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent,rgba(255,255,255,.22),transparent);transform:translateX(-120%);animation:bannerShine 6.2s ease-in-out infinite}.appBanner span{position:relative}.sub{margin:4px 0 0;color:var(--muted)}.topActions,.links{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.topActions{justify-content:flex-end;padding-top:42px}.links{margin-top:8px}.vpnCard{display:inline-flex;align-items:center}.uiPill{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:8px;width:132px;min-width:132px;min-height:36px;padding:8px 14px;box-sizing:border-box;border:1px solid var(--line);border-radius:999px;background:rgba(255,255,255,.08);color:#f3e8ff;text-decoration:none;font-weight:800;font-size:13px;line-height:1;white-space:nowrap;overflow:hidden}.nethaven{border-color:rgba(34,211,238,.46);background:linear-gradient(110deg,rgba(14,165,233,.22),rgba(168,85,247,.24),rgba(34,197,94,.16));color:#ecfeff;box-shadow:0 14px 32px rgba(14,165,233,.18)}.nethaven::before{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent,rgba(255,255,255,.24),transparent);transform:translateX(-120%);animation:bannerShine 5.8s ease-in-out infinite}.nethaven span{position:relative}.nethavenDot{position:relative;width:8px;height:8px;border-radius:50%;background:#22d3ee;box-shadow:0 0 14px #22d3ee;animation:pulseDot 2.8s ease-in-out infinite}.returnCard{display:inline-flex}.backBtn{width:auto;min-width:208px;background:#f59e0b;color:#160f06;box-shadow:0 10px 22px rgba(245,158,11,.22)}
|
||||
@keyframes bannerShine{0%,42%{transform:translateX(-120%)}70%,100%{transform:translateX(120%)}}@keyframes pulseDot{0%,100%{transform:scale(1);opacity:.72}50%{transform:scale(1.35);opacity:1}}
|
||||
.pill{min-width:118px;background:var(--panel);color:var(--muted)}.dot{width:9px;height:9px;border-radius:50%;background:var(--amber)}.dot.good{background:var(--green)}.dot.bad{background:var(--red)}
|
||||
.grid{display:grid;grid-template-columns:minmax(0,1.18fr) minmax(280px,.82fr);gap:16px;margin-top:18px}.panel{min-width:0;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:16px;box-shadow:0 18px 46px rgba(0,0,0,.28);backdrop-filter:blur(10px)}
|
||||
@@ -273,8 +304,8 @@ form{margin:0}.formgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr
|
||||
.check{display:flex;gap:10px;align-items:center;margin-bottom:12px;font-weight:700}.check input{width:18px;height:18px}.actions{display:flex;flex-wrap:wrap;gap:10px;margin-top:14px}.btn{border:1px solid rgba(255,255,255,.08);border-radius:8px;padding:10px 13px;font-weight:750;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;justify-content:center;background:rgba(255,255,255,.10);color:#f7f2ff}.btn.primary{background:var(--blue);color:#fff}.btn.good{background:var(--green);color:#07120a}.btn.bad{background:rgba(251,113,133,.18);color:#fecdd3}.btn.warn{background:rgba(245,158,11,.16);color:#fde68a;border:1px solid rgba(245,158,11,.34)}
|
||||
.notice{max-height:280px;overflow:auto;margin-top:16px;border-radius:8px;padding:12px;border:1px solid var(--line);background:rgba(255,255,255,.08);white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;font:12px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace}.notice strong{display:block;margin-bottom:4px;font:700 14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}.notice.ok{border-color:rgba(34,197,94,.46);background:rgba(34,197,94,.12)}.notice.bad{border-color:rgba(251,113,133,.46);background:rgba(251,113,133,.12)}.notice.warn{border-color:rgba(245,158,11,.46);background:rgba(245,158,11,.12)}
|
||||
.code{background:rgba(255,255,255,.06);border:1px solid var(--line);color:var(--text);border-radius:8px;padding:12px;overflow:auto;overflow-wrap:anywhere;min-height:120px;white-space:pre-wrap;font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;box-shadow:inset 0 1px 0 rgba(255,255,255,.04)}
|
||||
.helperText{margin:0 0 12px;color:var(--muted)}
|
||||
@media(max-width:820px){.grid,.formgrid,.metrics{grid-template-columns:1fr}.hero{align-items:flex-start;flex-direction:column}.topActions{justify-content:flex-start;padding-top:0}.wrap{padding:14px}h1{font-size:24px}}
|
||||
.helperText{margin:0 0 12px;color:var(--muted)}.xrayApply{margin-top:14px;padding:14px;border:1px solid var(--line);border-radius:8px;background:rgba(255,255,255,.055)}.xrayApply h3{margin:0 0 8px;font-size:16px}.scriptBox{width:100%;min-height:240px;resize:vertical;border:1px solid var(--line);border-radius:8px;background:rgba(8,5,18,.72);padding:12px;color:var(--text);font:12px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre;overflow:auto}
|
||||
@media(max-width:820px){.grid,.formgrid,.metrics{grid-template-columns:1fr}.hero{align-items:flex-start;flex-direction:column}.topActions{justify-content:flex-start;padding-top:0}.wrap{padding:14px}h1{font-size:24px}.appBanner{width:100%;justify-content:center;min-height:42px;padding:8px 12px}.actions .btn,.actions button{width:100%}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -283,7 +314,7 @@ form{margin:0}.formgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr
|
||||
<div class="brand">
|
||||
<div>
|
||||
<div class="titleRow">
|
||||
<h1>OpenWrt Remote Hub</h1>
|
||||
<h1 class="appBanner"><span>OpenWrt Remote Hub</span></h1>
|
||||
</div>
|
||||
<div class="links">
|
||||
<a class="uiPill" href="https://t.me/kzolotarev95" target="_blank" rel="noopener noreferrer">Telegram</a>
|
||||
@@ -325,11 +356,32 @@ EOF
|
||||
<button class="btn" name="action" value="doctor">Проверка</button>
|
||||
<button class="btn primary" name="action" value="install_xray_tmp">Поставить Xray в /tmp</button>
|
||||
<a class="btn" href="?key=$(h "$key")&action=download_config">Скачать Xray config</a>
|
||||
<button class="btn primary" name="action" value="show_xray_settings">Xray настройки</button>
|
||||
</form>
|
||||
EOF
|
||||
if [ -n "$RESULT_TITLE" ]; then
|
||||
printf '<div class="notice %s"><strong>%s</strong>\n%s</div>' "$(h "$RESULT_KIND")" "$(h "$RESULT_TITLE")" "$(h "$RESULT_BODY")"
|
||||
fi
|
||||
if [ "$SHOW_XRAY_SETTINGS" = "1" ]; then
|
||||
cat <<EOF
|
||||
<div class="xrayApply">
|
||||
<h3>Xray настройки</h3>
|
||||
<p class="helperText">Вставь сюда блок команд из OpenWrt config на VPS. Роутер сам применит UCI, пересоберет Xray config, включит сервис и отправит heartbeat.</p>
|
||||
<form method="post">
|
||||
<input type="hidden" name="key" value="$(h "$key")">
|
||||
<textarea class="scriptBox" name="xray_settings_script" spellcheck="false" placeholder="uci -q delete owrtremote.main
|
||||
uci set owrtremote.main=remote
|
||||
uci set owrtremote.main.enabled='1'
|
||||
...
|
||||
owrt-remote heartbeat"></textarea>
|
||||
<div class="actions">
|
||||
<button class="btn good" name="action" value="apply_xray_settings">Применить настройки</button>
|
||||
<button class="btn" name="action" value="show_xray_settings">Очистить поле</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
EOF
|
||||
fi
|
||||
cat <<EOF
|
||||
</div>
|
||||
|
||||
@@ -365,8 +417,12 @@ EOF
|
||||
field vless_encryption "VLESS encryption" text "Для этой схемы оставь none. Меняй только если сам меняешь Xray-конфиг на VPS."
|
||||
field vless_flow "VLESS flow" text "Обычно оставь пустым. Нужно только для специальных режимов Xray."
|
||||
field reverse_tag "Reverse tag" text "Метка reverse-туннеля внутри Xray. Обычно оставь reverse-in, если на VPS не задавал другое."
|
||||
field ssh_vless_uuid "SSH VLESS UUID" text "UUID отдельного SSH reverse-туннеля. Бери из OpenWrt config на VPS для этого роутера."
|
||||
field ssh_reverse_tag "SSH reverse tag" text "Метка reverse-туннеля для SSH. Обычно reverse-in-ssh."
|
||||
field admin_host "Admin host" text "Куда внутри роутера вести админку LuCI. Обычно 127.0.0.1, потому что uhttpd слушает локально."
|
||||
field admin_port "Admin port" number "Порт LuCI/uhttpd внутри роутера. Обычно 80; если LuCI на другом порту, укажи его."
|
||||
field ssh_host "SSH host" text "Куда внутри роутера вести SSH. Обычно 127.0.0.1."
|
||||
field ssh_port "SSH port" number "Порт Dropbear/SSH внутри роутера. Обычно 22."
|
||||
cat <<EOF
|
||||
</div>
|
||||
<div class="actions">
|
||||
@@ -405,6 +461,12 @@ if [ "${REQUEST_METHOD:-GET}" = "POST" ]; then
|
||||
save_config
|
||||
run_action start
|
||||
;;
|
||||
show_xray_settings)
|
||||
SHOW_XRAY_SETTINGS="1"
|
||||
;;
|
||||
apply_xray_settings)
|
||||
apply_xray_settings
|
||||
;;
|
||||
start|stop|restart|heartbeat|doctor|install_xray_tmp)
|
||||
run_action "$action"
|
||||
;;
|
||||
|
||||
Reference in new issue
Block a user