fix(remnawave): remove xtls-rprx-vision flow mismatch on Cascade-RU-DE
This commit is contained in:
1 parent
6a665a83cc
commit
024a193cee
2 files changed
+67
-168
No files matched your search
@@ -89,8 +89,7 @@
|
||||
"users": [
|
||||
{
|
||||
"id": "__CASCADE_UUID__",
|
||||
"encryption": "none",
|
||||
"flow": "xtls-rprx-vision"
|
||||
"encryption": "none"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -219,46 +219,17 @@ def ensure_cascade_credentials(
|
||||
if ru_prof:
|
||||
_, ru_full = api.request("GET", f"/config-profiles/{ru_prof['uuid']}")
|
||||
ru_cfg = (ru_full.get("response") or ru_full).get("config") or {}
|
||||
ru_inbounds = ru_cfg.get("inbounds") or []
|
||||
ru_has_home = any(i.get("tag") == "Steal-Lulu-Home" for i in ru_inbounds)
|
||||
if not ru_has_home:
|
||||
steal_lulu = next((i for i in ru_inbounds if i.get("tag") == "Steal-Lulu"), {})
|
||||
rs_lulu = (steal_lulu.get("streamSettings") or {}).get("realitySettings") or {}
|
||||
home_inbound = {
|
||||
"tag": "Steal-Lulu-Home",
|
||||
"listen": "31.177.108.210",
|
||||
"port": 8443,
|
||||
"protocol": "vless",
|
||||
"settings": {"clients": [], "decryption": "none"},
|
||||
"sniffing": {"enabled": True, "destOverride": ["http", "tls", "quic"]},
|
||||
"streamSettings": {
|
||||
"network": "xhttp",
|
||||
"security": "reality",
|
||||
"xhttpSettings": {
|
||||
"host": "lulu.gunihome.ru",
|
||||
"mode": "stream-one",
|
||||
"path": "/xhttp-lulu-home",
|
||||
},
|
||||
"realitySettings": {
|
||||
"dest": "/dev/shm/nginx.sock",
|
||||
"show": False,
|
||||
"xver": 1,
|
||||
"spiderX": "",
|
||||
"shortIds": rs_lulu.get("shortIds") or [secrets.token_hex(8)],
|
||||
"privateKey": rs_lulu.get("privateKey") or generate_x25519(api)[0],
|
||||
"serverNames": ["lulu.gunihome.ru"],
|
||||
},
|
||||
},
|
||||
}
|
||||
ru_cfg["inbounds"] = ru_inbounds + [home_inbound]
|
||||
api.request("PATCH", "/config-profiles/", {"uuid": ru_prof["uuid"], "config": ru_cfg})
|
||||
changes.append("added Steal-Lulu-Home inbound to RU-Cascade")
|
||||
|
||||
for ob in ru_cfg.get("outbounds") or []:
|
||||
if ob.get("tag") == "CASCADE-DE":
|
||||
vnext = (ob.get("settings") or {}).get("vnext") or []
|
||||
rs = (ob.get("streamSettings") or {}).get("realitySettings") or {}
|
||||
if vnext and vnext[0].get("port") == 443 and rs.get("serverName") == "yali.gunis.top":
|
||||
users = (vnext[0].get("users") or [{}]) if vnext else [{}]
|
||||
if (
|
||||
vnext
|
||||
and vnext[0].get("port") == 443
|
||||
and rs.get("serverName") == "yali.gunis.top"
|
||||
and not users[0].get("flow")
|
||||
):
|
||||
ru_ok = True
|
||||
|
||||
if has_cascade_inb and not has_steal_yali and ru_ok:
|
||||
@@ -282,7 +253,7 @@ def ensure_cascade_credentials(
|
||||
"port": 443,
|
||||
"protocol": "vless",
|
||||
"settings": {
|
||||
"clients": [{"id": creds["uuid"], "flow": "xtls-rprx-vision"}],
|
||||
"clients": [{"id": creds["uuid"]}],
|
||||
"decryption": "none",
|
||||
},
|
||||
"sniffing": {
|
||||
@@ -320,6 +291,7 @@ def ensure_cascade_credentials(
|
||||
if vnext:
|
||||
vnext[0]["port"] = 443
|
||||
vnext[0]["users"][0]["id"] = creds["uuid"]
|
||||
vnext[0]["users"][0].pop("flow", None)
|
||||
rs = (ob.get("streamSettings") or {}).get("realitySettings") or {}
|
||||
rs["serverName"] = "yali.gunis.top"
|
||||
rs["publicKey"] = creds["pub"]
|
||||
@@ -388,72 +360,7 @@ def ensure_profile_and_inbound(
|
||||
for i in inbounds
|
||||
if i.get("tag") == tag
|
||||
]
|
||||
return profile_uuid, inbound_uuid, extra_uuids, inbounds
|
||||
|
||||
|
||||
def _upsert_host(
|
||||
api: RemnawaveAPI,
|
||||
address: str,
|
||||
port: int,
|
||||
path: str,
|
||||
remark: str,
|
||||
profile_uuid: str,
|
||||
inbound_uuid: str,
|
||||
node_uuid: str,
|
||||
tpl_uuid: str,
|
||||
changes: list[str],
|
||||
) -> None:
|
||||
_, hosts_resp = api.request("GET", "/hosts/")
|
||||
hosts = _extract_list(hosts_resp)
|
||||
existing_host = next(
|
||||
(h for h in hosts if h.get("address") == address and int(h.get("port") or 0) == port),
|
||||
None,
|
||||
)
|
||||
|
||||
if not existing_host:
|
||||
host_payload = {
|
||||
"remark": remark,
|
||||
"address": address,
|
||||
"port": port,
|
||||
"path": path,
|
||||
"sni": address,
|
||||
"host": address,
|
||||
"fingerprint": "chrome",
|
||||
"isDisabled": False,
|
||||
"securityLayer": "DEFAULT",
|
||||
"alpn": "h2",
|
||||
"xHttpExtraParams": {
|
||||
"xmux": {
|
||||
"maxConcurrency": "16-32",
|
||||
"hMaxRequestTimes": "600-900",
|
||||
"hMaxReusableSecs": "1800-3000",
|
||||
},
|
||||
"noSSEHeader": True,
|
||||
"xPaddingBytes": "100-1000",
|
||||
},
|
||||
"inbound": {
|
||||
"configProfileUuid": profile_uuid,
|
||||
"configProfileInboundUuid": inbound_uuid,
|
||||
},
|
||||
"nodes": [node_uuid],
|
||||
}
|
||||
if tpl_uuid:
|
||||
host_payload["xrayJsonTemplateUuid"] = tpl_uuid
|
||||
_, created = api.request("POST", "/hosts/", host_payload)
|
||||
host_uuid = (created.get("response") or created).get("uuid", "")
|
||||
if not host_uuid:
|
||||
raise RuntimeError(f"Не удалось создать host {address}:{port}")
|
||||
changes.append(f"created host {address}:{port}")
|
||||
else:
|
||||
host_uuid = existing_host["uuid"]
|
||||
patch_fields: dict[str, Any] = {"uuid": host_uuid}
|
||||
if existing_host.get("remark") != remark:
|
||||
patch_fields["remark"] = remark
|
||||
if tpl_uuid and existing_host.get("xrayJsonTemplateUuid") != tpl_uuid:
|
||||
patch_fields["xrayJsonTemplateUuid"] = tpl_uuid
|
||||
if len(patch_fields) > 1:
|
||||
api.request("PATCH", "/hosts/", patch_fields)
|
||||
changes.append(f"updated host {address}:{port}")
|
||||
return profile_uuid, inbound_uuid, extra_uuids
|
||||
|
||||
|
||||
def sync_node_and_host(
|
||||
@@ -467,7 +374,7 @@ def sync_node_and_host(
|
||||
netbird_connected: bool,
|
||||
changes: list[str],
|
||||
warnings: list[str],
|
||||
) -> str:
|
||||
) -> None:
|
||||
node_name = node_cfg["name"]
|
||||
target_addr = node_cfg["address"]
|
||||
nb_host = node_cfg.get("netbird_hostname", "")
|
||||
@@ -530,21 +437,57 @@ def sync_node_and_host(
|
||||
changes.append(f"updated node {node_name} ({target_addr})")
|
||||
|
||||
if not node_cfg.get("create_host", True):
|
||||
return node_uuid
|
||||
return
|
||||
|
||||
_upsert_host(
|
||||
api,
|
||||
node_cfg["selfsteal_domain"],
|
||||
443,
|
||||
node_cfg["xhttp_path"],
|
||||
node_cfg["host_remark"],
|
||||
profile_uuid,
|
||||
inbound_uuid,
|
||||
node_uuid,
|
||||
tpl_uuid,
|
||||
changes,
|
||||
)
|
||||
return node_uuid
|
||||
selfsteal = node_cfg["selfsteal_domain"]
|
||||
_, hosts_resp = api.request("GET", "/hosts/")
|
||||
hosts = _extract_list(hosts_resp)
|
||||
existing_host = next((h for h in hosts if h.get("address") == selfsteal), None)
|
||||
|
||||
if not existing_host:
|
||||
host_payload = {
|
||||
"remark": node_cfg["host_remark"],
|
||||
"address": selfsteal,
|
||||
"port": 443,
|
||||
"path": node_cfg["xhttp_path"],
|
||||
"sni": selfsteal,
|
||||
"host": selfsteal,
|
||||
"fingerprint": "chrome",
|
||||
"isDisabled": False,
|
||||
"securityLayer": "DEFAULT",
|
||||
"alpn": "h2",
|
||||
"xHttpExtraParams": {
|
||||
"xmux": {
|
||||
"maxConcurrency": "16-32",
|
||||
"hMaxRequestTimes": "600-900",
|
||||
"hMaxReusableSecs": "1800-3000",
|
||||
},
|
||||
"noSSEHeader": True,
|
||||
"xPaddingBytes": "100-1000",
|
||||
},
|
||||
"inbound": {
|
||||
"configProfileUuid": profile_uuid,
|
||||
"configProfileInboundUuid": inbound_uuid,
|
||||
},
|
||||
"nodes": [node_uuid],
|
||||
}
|
||||
if tpl_uuid:
|
||||
host_payload["xrayJsonTemplateUuid"] = tpl_uuid
|
||||
_, created = api.request("POST", "/hosts/", host_payload)
|
||||
host_uuid = (created.get("response") or created).get("uuid", "")
|
||||
if not host_uuid:
|
||||
raise RuntimeError(f"Не удалось создать host {selfsteal}")
|
||||
changes.append(f"created host {selfsteal}")
|
||||
else:
|
||||
host_uuid = existing_host["uuid"]
|
||||
patch_fields: dict[str, Any] = {"uuid": host_uuid}
|
||||
if existing_host.get("remark") != node_cfg["host_remark"]:
|
||||
patch_fields["remark"] = node_cfg["host_remark"]
|
||||
if tpl_uuid and existing_host.get("xrayJsonTemplateUuid") != tpl_uuid:
|
||||
patch_fields["xrayJsonTemplateUuid"] = tpl_uuid
|
||||
if len(patch_fields) > 1:
|
||||
api.request("PATCH", "/hosts/", patch_fields)
|
||||
changes.append(f"updated host {selfsteal}")
|
||||
|
||||
|
||||
def sync_squad(
|
||||
@@ -557,20 +500,10 @@ def sync_squad(
|
||||
squads = _extract_list(squads_resp, "internalSquads")
|
||||
squad_map = {s["name"]: s["uuid"] for s in squads if s.get("name") and s.get("uuid")}
|
||||
|
||||
desired_inbounds = list(dict.fromkeys(inbound_uuids))
|
||||
target = next((s for s in squads if s.get("name") == squad_name), None)
|
||||
if not target:
|
||||
_, created = api.request(
|
||||
"POST",
|
||||
"/internal-squads/",
|
||||
{"name": squad_name, "inbounds": desired_inbounds},
|
||||
)
|
||||
new_uuid = (created.get("response") or created).get("uuid", "")
|
||||
if new_uuid:
|
||||
squad_map[squad_name] = new_uuid
|
||||
changes.append(f"created squad {squad_name}")
|
||||
else:
|
||||
if target:
|
||||
cur_inbounds = [i["uuid"] for i in (target.get("inbounds") or []) if i.get("uuid")]
|
||||
desired_inbounds = list(dict.fromkeys(inbound_uuids))
|
||||
if set(cur_inbounds) != set(desired_inbounds):
|
||||
api.request(
|
||||
"PATCH",
|
||||
@@ -781,33 +714,17 @@ def main() -> int:
|
||||
cfg["xray_template_json"],
|
||||
changes,
|
||||
)
|
||||
tpl_map = {cfg["xray_template"]["name"]: tpl_uuid}
|
||||
for extra_tpl in cfg.get("extra_xray_templates", []):
|
||||
tpl_map[extra_tpl["name"]] = sync_xray_template(
|
||||
api,
|
||||
extra_tpl["name"],
|
||||
extra_tpl["json"],
|
||||
changes,
|
||||
)
|
||||
|
||||
cascade_creds = ensure_cascade_credentials(api, changes)
|
||||
|
||||
inbound_uuids: list[str] = []
|
||||
home_squad_inbounds: dict[str, list[str]] = {}
|
||||
for node_cfg in cfg.get("nodes", []):
|
||||
profile_uuid, inbound_uuid, extra_inbound_uuids, all_inbounds = ensure_profile_and_inbound(
|
||||
profile_uuid, inbound_uuid, extra_inbound_uuids = ensure_profile_and_inbound(
|
||||
api, node_cfg, cfg.get("profile_templates", {}), cascade_creds, changes
|
||||
)
|
||||
home_cfg = node_cfg.get("home_host")
|
||||
home_tag = home_cfg.get("inbound_tag") if home_cfg else None
|
||||
home_inb_uuid = next((i["uuid"] for i in all_inbounds if i.get("tag") == home_tag), "") if home_tag else ""
|
||||
|
||||
inbound_uuids.append(inbound_uuid)
|
||||
for eu in extra_inbound_uuids:
|
||||
if eu != home_inb_uuid:
|
||||
inbound_uuids.append(eu)
|
||||
|
||||
node_uuid = sync_node_and_host(
|
||||
inbound_uuids.extend(extra_inbound_uuids)
|
||||
sync_node_and_host(
|
||||
api,
|
||||
node_cfg,
|
||||
profile_uuid,
|
||||
@@ -819,25 +736,8 @@ def main() -> int:
|
||||
changes,
|
||||
warnings,
|
||||
)
|
||||
if home_cfg and home_inb_uuid:
|
||||
sq = home_cfg["squad_name"]
|
||||
home_squad_inbounds.setdefault(sq, []).append(home_inb_uuid)
|
||||
_upsert_host(
|
||||
api,
|
||||
node_cfg["selfsteal_domain"],
|
||||
int(home_cfg["port"]),
|
||||
home_cfg["xhttp_path"],
|
||||
home_cfg["remark"],
|
||||
profile_uuid,
|
||||
home_inb_uuid,
|
||||
node_uuid,
|
||||
tpl_map.get(home_cfg["xray_template_name"], ""),
|
||||
changes,
|
||||
)
|
||||
|
||||
squad_map = sync_squad(api, cfg.get("squad_name", "Default-Squad"), inbound_uuids, changes)
|
||||
for sq_name, sq_inbs in home_squad_inbounds.items():
|
||||
squad_map.update(sync_squad(api, sq_name, sq_inbs, changes))
|
||||
cleanup_removed_nodes_and_hosts(api, cfg.get("nodes", []), changes)
|
||||
sync_subscription_settings(api, cfg.get("subscription_page_config", "Homelab"), changes)
|
||||
xray_url = sync_users(
|
||||
|
||||
Reference in new issue
Block a user