refactor(opnsense/xray): replace 310-line Jinja loop with sync_xray.py
ansible-deploy / plan (push) Successful in 1s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (opnsense, ) (push) Successful in 3s

This commit is contained in:
karpenok committed 2026-11-15 23:07:41 +07:00
1 parent ae9beee5ca
commit aab0611aaf
4 files changed
+245 -289

No files matched your search

@@ -13,11 +13,11 @@ import sys
from urllib.parse import unquote, urlparse, parse_qs
def main() -> None:
link = sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read()
def convert_vless(link: str) -> str:
"""Конвертирует vless:// ссылку в компактный JSON outbound-объекта."""
link = link.strip().strip("\"'")
if not link.startswith("vless://"):
sys.exit("error: link must start with vless://")
raise ValueError("link must start with vless://")
parsed = urlparse(link)
uuid = parsed.username
@@ -26,7 +26,7 @@ def main() -> None:
params = {k: v[0] for k, v in parse_qs(parsed.query).items()}
if not uuid or not host or not port:
sys.exit("error: link must look like vless://uuid@host:port?...")
raise ValueError("link must look like vless://uuid@host:port?...")
network = params.get("type", "tcp")
security = params.get("security", "reality")
@@ -82,8 +82,16 @@ def main() -> None:
if t or network == "grpc":
ss[transport_key] = t
json.dump(outbound, sys.stdout, separators=(",", ":"), ensure_ascii=False)
sys.stdout.write("\n")
return json.dumps(outbound, separators=(",", ":"), ensure_ascii=False)
def main() -> None:
link = sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read()
try:
out = convert_vless(link)
except ValueError as exc:
sys.exit(f"error: {exc}")
sys.stdout.write(out + "\n")
if __name__ == "__main__":