Fix VLESS reverse config

This commit is contained in:
kzolotarev95 committed 2026-06-29 04:41:27 +04:00
1 parent 071f299b86
commit cf980b5673
2 files changed
+38 -60

No files matched your search

+29 -24
View File
@@ -138,12 +138,33 @@ xray_running() {
ps_all | grep '[x]ray' | grep -F "$config" >/dev/null 2>&1
}
xray_bin_path() {
local configured candidate
configured="$(uci_get xray_bin /usr/bin/xray)"
if [ -x "$configured" ]; then
printf '%s' "$configured"
return
fi
for candidate in /usr/bin/xray /usr/bin/xray-core /usr/local/bin/xray /opt/bin/xray /tmp/xray; do
if [ -x "$candidate" ]; then
printf '%s' "$candidate"
return
fi
done
candidate="$(command -v xray 2>/dev/null || command -v xray-core 2>/dev/null || true)"
if [ -n "$candidate" ] && [ -x "$candidate" ]; then
printf '%s' "$candidate"
return
fi
printf '%s' "$configured"
}
service_enabled() {
/etc/init.d/owrt-remote enabled >/dev/null 2>&1
}
render_client_config() {
local out stdout router_id vps_host vps_port uuid encryption flow reverse_tag reverse_domain admin_host admin_port xray_config
local out stdout router_id vps_host vps_port uuid encryption flow reverse_tag admin_host admin_port xray_config
stdout="0"
if [ "${1:-}" = "--stdout" ]; then
stdout="1"
@@ -156,7 +177,6 @@ render_client_config() {
encryption="$(uci_get vless_encryption none)"
flow="$(uci_get vless_flow '')"
reverse_tag="$(safe_id "$(uci_get reverse_tag reverse-in)")"
reverse_domain="${router_id}.owrt-remote.internal"
admin_host="$(uci_get admin_host 127.0.0.1)"
admin_port="$(safe_num "$(uci_get admin_port 80)" 80)"
xray_config="$(uci_get xray_config /etc/xray/owrt-remote-client.json)"
@@ -170,14 +190,6 @@ render_client_config() {
"log": {
"loglevel": "warning"
},
"reverse": {
"bridges": [
{
"tag": "$(json_escape "$reverse_tag")",
"domain": "$(json_escape "$reverse_domain")"
}
]
},
"inbounds": [],
"outbounds": [
{
@@ -203,7 +215,10 @@ render_client_config() {
"port": $vps_port,
"id": "$(json_escape "$uuid")",
"encryption": "$(json_escape "$encryption")",
"flow": "$(json_escape "$flow")"
"flow": "$(json_escape "$flow")",
"reverse": {
"tag": "$(json_escape "$reverse_tag")"
}
},
"streamSettings": {
"network": "tcp",
@@ -213,16 +228,6 @@ render_client_config() {
],
"routing": {
"rules": [
{
"type": "field",
"inboundTag": [
"$(json_escape "$reverse_tag")"
],
"domain": [
"full:$(json_escape "$reverse_domain")"
],
"outboundTag": "vps-interconn"
},
{
"type": "field",
"inboundTag": [
@@ -254,7 +259,7 @@ run_xray() {
enabled="$(uci_get enabled 0)"
truthy "$enabled" || die "сервис выключен: включи option enabled '1'"
xray_bin="$(uci_get xray_bin /usr/bin/xray)"
xray_bin="$(xray_bin_path)"
xray_config="$(render_client_config)"
[ -x "$xray_bin" ] || die "xray не найден или не исполняемый: $xray_bin"
@@ -366,7 +371,7 @@ status() {
printf 'hub_url: %s\n' "$(uci_get hub_url '')"
printf 'vps_host: %s\n' "$(uci_get vps_host '')"
printf 'vps_port: %s\n' "$(uci_get vps_port 8443)"
printf 'xray_bin: %s\n' "$(uci_get xray_bin /usr/bin/xray)"
printf 'xray_bin: %s\n' "$(xray_bin_path)"
printf 'xray_config: %s\n' "$(uci_get xray_config /etc/xray/owrt-remote-client.json)"
if xray_running; then
printf 'xray_state: running\n'
@@ -383,7 +388,7 @@ status() {
doctor() {
local ok xray_bin
ok=1
xray_bin="$(uci_get xray_bin /usr/bin/xray)"
xray_bin="$(xray_bin_path)"
[ -x "$xray_bin" ] || {
log "нет Xray: $xray_bin"
+9 -36
View File
@@ -251,7 +251,7 @@ def heartbeat(conn, payload):
def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLESS_PORT, decryption="none"):
clients = []
users = []
inbounds = [
{
"tag": "owrt-remote-vless",
@@ -259,7 +259,7 @@ def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLE
"port": int(listen_port),
"protocol": "vless",
"settings": {
"clients": clients,
"users": users,
"decryption": decryption,
},
"streamSettings": {
@@ -269,29 +269,24 @@ def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLE
}
]
rules = []
portals = []
for row in rows:
router_id = clean_router_id(row["id"])
entry_port = int(row["entry_port"] or 0)
if entry_port <= 0:
continue
portal_tag = f"portal-{router_id}"
reverse_domain = f"{router_id}.owrt-remote.internal"
reverse_out = f"reverse-{router_id}"
portal_in = f"entry-{router_id}"
client = {
"id": row["vless_uuid"],
"email": f"{router_id}@owrt-remote",
"reverse": {
"tag": reverse_out,
},
}
if row["vless_flow"]:
client["flow"] = row["vless_flow"]
clients.append(client)
portals.append(
{
"tag": portal_tag,
"domain": reverse_domain,
}
)
users.append(client)
inbounds.append(
{
"tag": portal_in,
@@ -309,20 +304,12 @@ def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLE
{
"type": "field",
"inboundTag": [portal_in],
"outboundTag": portal_tag,
}
)
rules.append(
{
"type": "field",
"inboundTag": ["owrt-remote-vless"],
"outboundTag": portal_tag,
"outboundTag": reverse_out,
}
)
return {
"log": {"loglevel": "warning"},
"reverse": {"portals": portals},
"inbounds": inbounds,
"outbounds": [{"tag": "direct", "protocol": "freedom"}],
"routing": {"rules": rules},
@@ -332,17 +319,8 @@ def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLE
def make_router_xray_config(row):
bridge_tag = row["reverse_tag"]
reverse_domain = f"{clean_router_id(row['id'])}.owrt-remote.internal"
return {
"log": {"loglevel": "warning"},
"reverse": {
"bridges": [
{
"tag": bridge_tag,
"domain": reverse_domain,
}
]
},
"inbounds": [],
"outbounds": [
{
@@ -369,18 +347,13 @@ def make_router_xray_config(row):
"id": row["vless_uuid"],
"encryption": row["vless_encryption"],
"flow": row["vless_flow"],
"reverse": {"tag": bridge_tag},
},
"streamSettings": {"network": "tcp", "security": "none"},
},
],
"routing": {
"rules": [
{
"type": "field",
"inboundTag": [bridge_tag],
"domain": [f"full:{reverse_domain}"],
"outboundTag": "vps-interconn",
},
{
"type": "field",
"inboundTag": [bridge_tag],