"""proxy-ctl: control proxy-suite services and inspect their runtime state. Configuration arrives through the environment the Nix wrapper sets. """ import base64 import contextlib import datetime import errno import fcntl import getpass import http.client import importlib import ipaddress import json import math import os import re import shutil import signal import socket import stat import subprocess import sys import tempfile import time import urllib.error import urllib.parse import urllib.request from concurrent.futures import ThreadPoolExecutor ALL_SERVICES = [ "proxy-suite-socks", "proxy-suite-tproxy", "proxy-suite-tun", "proxy-suite-killswitch", "proxy-suite-inbounds", "proxy-suite-ssh-proxy", "proxy-suite-warp", "proxy-suite-warp-tunnel", "proxy-suite-tor", "proxy-suite-tg-ws-proxy", "proxy-suite-zapret", "proxy-suite-zapret-vm-exempt", ] RESTART_SERVICES = [ "proxy-suite-tproxy", "proxy-suite-tun", "proxy-suite-inbounds", "proxy-suite-ssh-proxy", "proxy-suite-warp-tunnel", "proxy-suite-tor", "proxy-suite-tg-ws-proxy", "proxy-suite-zapret", ] HELP = """\ Usage: proxy-ctl [verb] [args] A group alone shows its status or list. Groups with on|off also take toggle and restart. Changes and secrets need root or the userControl group. status [--json] services and routing mode (--tray: deprecated) restart restart running services logs [unit...] follow logs (default: all proxy-suite units); in a terminal, in lnav: scroll back, G follows, q quits where how a domain is routed right now debug conns [--backend socks|tun|per-app-tun] [--host ]... [--inbound ]... [--stall ] [--interval ] the backend's connections as they open, stall and close, with their rule, exit and bytes (needs root or the secrets scope); --host, --inbound: only these; --backend tun, per-app-tun: the TUN ones (root, and debug.connectionLog on) proxy [status|on|off] local proxy proxy outbounds [list] outbounds, their source, and the current pick proxy outbounds add [tag] [--detour ] add an outbound from a link or JSON (-: stdin); --detour: connect through another outbound proxy outbounds add [tag] [--container ] add an AmneziaWG outbound (runs in wireproxy) proxy outbounds chain [new tag] add a copy of an outbound that connects through another proxy outbounds rm remove a runtime outbound proxy outbounds disable|enable exclude from automatic use (selection, autoProxy), or undo proxy outbounds test [tag...] [--ping] [--delay] [--download] test ping, delay, download speed (default: ping, delay) proxy outbounds link [--qr|--json|--config] its link, QR code, JSON, or client config proxy pin [tag] [--in ] always use this outbound (no tag: pick from a menu); --in: hold a group on one of its members proxy unpin [--in ] go back to automatic selection proxy groups [list] outbound groups, their members, and what each uses proxy groups add [member...] [--sub ]... [--match ]... [--strategy failover|urltest|selector] [--no-failback] [--interval ] add a group (failover by default) proxy groups rm remove a group added with groups add proxy groups members add|rm proxy groups members set [member...] exactly these members, in this order proxy groups strategy failover|urltest|selector proxy priority [list] the top level in the order it is picked in proxy priority |up|down|--clear lower goes first; up/down renumbers the top level proxy mode [default|whitelist|blacklist|all-proxy|all-bypass] show or override the routing mode proxy rules [list] routing rules, the configuration's and runtime ones, in the order they are checked proxy rules add [--name ] [--priority ] send domains, addresses, geosite:x, geoip:x or ruleset:x to proxy, direct, block or an outbound; no --name: the rule named after the target, extended (priority 50: ahead of the configuration's, at 100 to 500) proxy rules matches add|rm proxy rules matches set [match...] exactly these matches proxy rules target proxy rules priority |up|down lower goes first; up/down moves past the next row proxy rules disable|enable|rm proxy subs [list|update] subscriptions; update refetches them proxy subs add [tag] add a subscription (no tag: named after its host; -: stdin) proxy subs rm remove a runtime subscription proxy subs link [--qr] its URL proxy rulesets [list|update] rule sets and when they were fetched; update refetches proxy config [--raw] client config to use elsewhere; --raw: as running proxy tun [status|on|off] global TUN mode proxy tproxy [status|on|off] global TProxy mode proxy auto [list] what autoProxy routed, and through which exit proxy auto probe [/path] [--json] [--keep-going] [--exits a,b | --via tag] find an exit that reaches a domain proxy auto learn probe now, and route it if an exit works proxy auto forget forget it (direct until learned again) proxy auto relearn forget it and probe again now proxy auto clear forget everything learned proxy auto queue [count] destinations waiting to be probed zapret [status|on|off] DPI bypass zapret auto [list] sites zapret2 learned as blocked zapret auto add|forget|exclude treat a site as blocked, forget it, or never touch it zapret auto unpin|include undo add or exclude zapret auto retry give zapret2 another try where it sent the proxy zapret auto clear forget learned sites and strategies zapret cutoff [status] networks cut off at 16 KB, and names that pass zapret cutoff probe probe again now awg [list] AmneziaWG profiles awg on | off [profile] | toggle [profile] | restart [profile] awg add [name] [--container ] add a global profile (-: stdin) awg rm remove a profile added with awg add killswitch [status|on|off] block traffic outside the global tunnel; stays on until turned off here or with the tunnel ssh [status|on|off] SSH tunnel warp [status|on|off] [device] WARP tunnel (every device, or the one named) tor [status|on|off] Tor tor newnym new circuits for new connections tg [status|on|off] Telegram proxy wl [list] whitelist-bypass creators and joiners wl link [--qr] the call link for its joiner wl auth [file|-] replace its login: cookies, or prompt (DION, Bitrix) wl join set the call to join wl new start a new call wl on|off|toggle|restart [name] one creator or joiner, or all apps [list] per-app routing profiles apps run -- [args] run a command through a profile apps run --via -- run a command through one outbound (--route tun|tproxy picks the method) apps add [--route r] [--via o] add a profile without a rebuild apps rm remove one added that way inbounds [list] server inbounds inbounds link [user] [--onion|--variant=] [--qr|--json] share link or client JSON; --onion: via the onion service; --variant: one of the listener's shareVariants inbounds link [user] --config [--qr] AmneziaWG client .conf or its QR code inbounds link --server-json the server's inbound JSON inbounds sub [user] [--qr] subscription users, or one user's URL inbounds stats [days] [--by user|inbound|outbound] traffic by user, listener or exit inbounds users [list] users: order, serverSource address, listeners (the rest below needs inbounds.runtime) inbounds users add [--order N] [--listener ]... add a user at runtime, with generated secrets inbounds users rm remove a runtime user inbounds users order a runtime user's order (serverSource number) inbounds bind|unbind put a user on a listener, or take it off (a runtime user, or a runtime listener) inbounds users listeners [tag...] put a user on exactly these listeners inbounds users on [user...] put exactly these users on a listener inbounds add [--port N] [--via V] [--transport T] [--path P] [--host H] [--reality SNI[,SNI]] [--tls ] [--alpn a,b] [--flow vision] [--method M] [--listen A] [--user U]... [more: see inbounds add --help] add a listener at runtime inbounds add add one from JSON shaped like inbounds.listeners. inbounds rm remove a runtime listener inbounds show a runtime listener's JSON inbounds online who is online, and when others were last seen With inbounds.manager (users' policies; the API proxy-ctl and bots use): inbounds users [list] [--json] users, whether they may connect, traffic, expiry inbounds users show [--json] one user: policy, traffic, online, subscription inbounds users add [...] [policy flags] add a runtime user with a policy inbounds users set [--expires 2026-12-31|+30d] [--on-hold 30d] [--traffic 50G] [--period monthly] [--ips 2] [--speed 20M/5M] [--enable|--disable] [--meta key=value]... change a user's policy (declared users too); --on-hold: a term that starts on the first connection inbounds users unset ... back to the config's value, or none inbounds users enable|disable switch a user on or off inbounds users reset start their traffic over inbounds users extend 30d [--reset] move the expiry on (from now, or from it if later; on hold: a longer term); --reset: traffic anew too inbounds users extend --until