Состояние
Xray настройки
Вставь сюда блок команд из OpenWrt config на VPS. Роутер сам применит UCI, пересоберет Xray config, включит сервис и отправит heartbeat.
#!/bin/sh KEY_FILE="${KEY_FILE:-/etc/owrt-remote/web.key}" AGENT="${AGENT:-/usr/sbin/owrt-remote}" OWRT_REMOTE_UI_VERSION="2026-07-02-mobile-terminal-batch-v25" PARAMS_FILE="${TMPDIR:-/tmp}/owrt-remote-cgi.$$" RESULT_TITLE="" RESULT_BODY="" RESULT_KIND="info" SHOW_XRAY_SETTINGS="0" cleanup() { rm -f "$PARAMS_FILE" } trap cleanup EXIT INT TERM html_escape() { sed 's/&/\&/g; s/\</g; s/>/\>/g; s/"/\"/g' } h() { printf '%s' "$1" | html_escape } url_decode() { local data data="$(printf '%s' "$1" | sed 's/+/ /g; s/%/\\x/g')" printf '%b' "$data" } parse_params() { local data old_ifs pair key value data="$1" old_ifs="$IFS" IFS='&' for pair in $data; do key="${pair%%=*}" value="${pair#*=}" [ "$pair" = "$key" ] && value="" key="$(url_decode "$key" | tr -d '\r\n\t')" [ -n "$key" ] && printf '%s\t%s\n' "$key" "$value" >>"$PARAMS_FILE" done IFS="$old_ifs" } param() { local raw raw="$(awk -F ' ' -v k="$1" '$1 == k { print $2; exit }' "$PARAMS_FILE")" url_decode "$raw" } has_param() { awk -F ' ' -v k="$1" '$1 == k { found = 1 } END { exit(found ? 0 : 1) }' "$PARAMS_FILE" } read_request() { local post_data : >"$PARAMS_FILE" parse_params "${QUERY_STRING:-}" case "${CONTENT_TYPE:-}" in multipart/form-data*) return ;; esac if [ "${REQUEST_METHOD:-GET}" = "POST" ] && [ -n "${CONTENT_LENGTH:-}" ]; then post_data="$(dd bs=1 count="$CONTENT_LENGTH" 2>/dev/null)" parse_params "$post_data" fi } http_html() { printf 'Content-Type: text/html; charset=utf-8\r\n' printf 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0\r\n' printf 'Pragma: no-cache\r\n' printf 'Expires: 0\r\n\r\n' } http_json() { printf 'Content-Type: application/json; charset=utf-8\r\n' printf 'Cache-Control: no-store\r\n\r\n' } web_key() { cat "$KEY_FILE" 2>/dev/null } authorized() { local expected supplied expected="$(web_key)" supplied="$(param key)" [ -n "$expected" ] && [ "$supplied" = "$expected" ] } uci_get() { local key default value key="$1" default="$2" value="$(uci -q get "owrtremote.main.$key" 2>/dev/null || true)" [ -n "$value" ] && { printf '%s' "$value" return } printf '%s' "$default" } uci_set() { local key value key="$1" value="$2" uci -q get owrtremote.main >/dev/null 2>&1 || uci set owrtremote.main=remote uci set "owrtremote.main.$key=$value" } service_enabled() { /etc/init.d/owrt-remote enabled >/dev/null 2>&1 } xray_running() { "$AGENT" status 2>/dev/null | grep -q '^xray_state: running' } set_result() { RESULT_TITLE="$1" RESULT_BODY="$2" RESULT_KIND="${3:-info}" } save_config() { local enabled field if has_param enabled; then enabled="1" else enabled="0" 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 ssh_vless_uuid ssh_reverse_tag admin_host admin_port ssh_host ssh_port public_url; do uci_set "$field" "$(param "$field")" done if has_param vps_host_auto; then uci_set vps_host_mode auto; else uci_set vps_host_mode manual; fi if has_param wan_direct; then uci_set wan_direct 1; else uci_set wan_direct 0; fi uci_set wan_interface "$(param wan_interface)" uci_set wan_dns "$(param wan_dns)" uci commit owrtremote set_result "Настройки сохранены" "Если менял Xray или VPS-поля, перезапусти сервис." "ok" } clear_config() { local field for field in role public_url hub_url hub_token heartbeat_interval xray_bin xray_config vps_host vps_host_mode wan_direct wan_interface wan_dns vps_port vless_uuid vless_encryption vless_flow reverse_tag ssh_vless_uuid ssh_reverse_tag admin_host admin_port ssh_host ssh_port; do uci -q delete "owrtremote.main.$field" done uci commit owrtremote set_result "Конфигурация очищена" "Поля VPS, Xray, LuCI и SSH очищены. Router ID и название оставлены." "warn" } 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" output="${TMPDIR:-/tmp}/owrt-remote-action.$$" rc=0 case "$action" in start) : >"$output" uci_set enabled 1 uci commit owrtremote >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote enable >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote restart >>"$output" 2>&1 || rc=$? set_result "Сервис запущен" "$(cat "$output")" "ok" ;; stop) : >"$output" uci_set enabled 0 uci commit owrtremote >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote stop >>"$output" 2>&1 || rc=$? "$AGENT" stop-xray >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote disable >>"$output" 2>&1 || rc=$? "$AGENT" heartbeat >>"$output" 2>&1 || true set_result "Сервис остановлен" "$(cat "$output")" "warn" ;; restart) : >"$output" uci_set enabled 1 uci commit owrtremote >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote enable >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote restart >>"$output" 2>&1 || rc=$? set_result "Сервис перезапущен" "$(cat "$output")" "ok" ;; heartbeat) "$AGENT" heartbeat >"$output" 2>&1 || rc=$? if [ "$rc" = "0" ] && grep -q '"ok"[[:space:]]*:[[:space:]]*true' "$output"; then set_result "Heartbeat" "OK: роутер отправил heartbeat на VPS, карточка обновлена." "ok" else set_result "Heartbeat" "$(cat "$output")" "ok" fi ;; doctor) "$AGENT" doctor >"$output" 2>&1 || rc=$? set_result "Проверка" "$(cat "$output")" "ok" ;; install_xray_tmp) if "$AGENT" install-xray-tmp >"$output" 2>&1; then "$AGENT" render-client >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote restart >>"$output" 2>&1 || rc=$? else rc=$? fi set_result "Xray установлен в /tmp" "$(cat "$output")" "ok" ;; esac if [ "$rc" != "0" ]; then set_result "$RESULT_TITLE" "$(cat "$output")" "bad" fi rm -f "$output" } field() { local name label value type help name="$1" label="$2" type="${3:-text}" help="${4:-}" value="$(uci_get "$name" '')" printf '' } metric() { local label value tone label="$1" value="$2" tone="${3:-}" printf '
Открой панель из LuCI или по ссылке, которую показал install.sh.
EOF } render_page() { local key router_id router_name hub_url service_state service_tone xray_state xray_tone enabled_checked status_text local vps_host_auto_checked wan_direct_checked vps_host_auto_checked=''; wan_direct_checked='' [ "$(uci_get vps_host_mode manual)" != auto ] || vps_host_auto_checked=checked [ "$(uci_get wan_direct 0)" != 1 ] || wan_direct_checked=checked key="$(param key)" router_id="$(uci_get router_id main)" router_name="$(uci_get router_name "$router_id")" hub_url="$(uci_get hub_url '')" if service_enabled; then service_state="Включен" service_tone="good" else service_state="Выключен" service_tone="warn" fi if xray_running; then xray_state="Запущен" xray_tone="good" else xray_state="Остановлен" xray_tone="bad" fi if [ "$(uci_get enabled 0)" = "1" ]; then enabled_checked="checked" status_text="Агент включен" else enabled_checked="" status_text="Агент выключен" fi http_html cat <Вставь сюда блок команд из OpenWrt config на VPS. Роутер сам применит UCI, пересоберет Xray config, включит сервис и отправит heartbeat.