feat: awg runtime add

This commit is contained in:
fufsob committed 2026-09-28 18:51:47 +00:00
1 parent cd3aa5a53f
commit 364bed8d51
39 files changed
+1581 -190

No files matched your search

+10
View File
@@ -22,6 +22,9 @@ let
proxyInboundsCfg
proxyInboundsEnabled
amneziaWgProfileNamesFile
awgRuntimeGlobal
awgRuntimeOutbounds
proxySuiteScriptsDir
ruleSets
pkgs
;
@@ -73,6 +76,13 @@ in
ROUTE_MODE_STATE_FILE = routeModeStateFile;
DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
# Profiles and outbounds added with `awg add` and `proxy outbounds add`.
AWG_RUNTIME_GLOBAL = flag awgRuntimeGlobal;
AWG_RUNTIME_OUTBOUNDS = flag awgRuntimeOutbounds;
AWG_RUNTIME_DIR = constants.runtimeAwgDir;
AWG_CONFIG_TOOL = "${proxySuiteScriptsDir}/amneziawg_config.py";
AWG_TUNNEL_BASE_PORT = toString constants.awgRuntimeTunnelBasePort;
AWG_TUNNEL_SLOTS = toString constants.awgRuntimeTunnelSlots;
WL_FILE = toString (
pkgs.writeText "proxy-suite-control" (
builtins.toJSON (
+27 -18
View File
@@ -175,24 +175,33 @@ lib.mkMerge [
# files proxy-ctl drops here inherit the group; without the outbounds scope
# only root writes them. tmpfiles rather than the start scripts, so the group can add an
# outbound before the proxy has ever run.
tmpfiles = lib.mkIf (cfg.enable && proxyEnabled) (
map
(
dir:
"d ${dir} ${
if userControlAllows "outbounds" then
"2770 root ${userControlCfg.group}"
else if constants.privileged then
"0700 root root"
else
"0700 - -"
} -"
)
[
constants.runtimeOutboundsDir
constants.runtimeSubscriptionsDir
]
);
tmpfiles = lib.mkMerge [
(lib.mkIf (cfg.enable && proxyEnabled) (
map
(
dir:
"d ${dir} ${
if userControlAllows "outbounds" then
"2770 root ${userControlCfg.group}"
else if constants.privileged then
"0700 root root"
else
"0700 - -"
} -"
)
[
constants.runtimeOutboundsDir
constants.runtimeSubscriptionsDir
]
))
# Global AmneziaWG profiles added at runtime. Listable, so the tray and TUI show
# their names to everyone; each file is 0600 (amneziawg_config.py writes it so).
(lib.mkIf (cfg.enable && derived.awgRuntimeGlobal) [
"d ${constants.runtimeAwgDir} ${
if userControlAllows "amneziaWg" then "2775 root ${userControlCfg.group}" else "0755 root root"
} -"
])
];
userServices = lib.mkMerge [
(mkNamedUnits userServiceEntries)
+4
View File
@@ -11,6 +11,10 @@ let
"proxy-suite-route-mode@" = "routing";
"proxy-suite-outbound-reload." = "outbounds";
"proxy-suite-subscription-update." = "outbounds";
# Tunnels of the AmneziaWG outbounds added at runtime; a global profile's own unit
# (proxy-suite-awg@) is "services", like the declared ones.
"proxy-suite-awg-tunnel@" = "outbounds";
"proxy-suite-awg-runtime-sync." = "outbounds";
"proxy-suite-autoproxy-learn." = "autoProxy";
"proxy-suite-zapret2-cutoff." = "zapret";
"proxy-suite-inbound-stats." = "stats";
@@ -8,6 +8,7 @@
torCfg,
whitelistBypassJoiners,
awgOutbounds,
awgRuntimeOutbounds ? false,
constants,
pureXrayEnabled,
hybridEnabled,
@@ -136,6 +137,27 @@ let
OUTBOUND_SOURCES_JSON=$(${jq} --arg t "$1" --arg s "$2" '.[$t] = $s' <<< "$OUTBOUND_SOURCES_JSON")
}
# $1 tag, $2 loopback SOCKS port, $3 source label: mkTunnelOutboundBlock, for a port
# only known at runtime (an AmneziaWG outbound added with proxy-ctl).
_proxy_suite_add_socks_hop() {
local ob
ob=$(${jq} -nc --arg t "$1" --argjson p "$2" ${
lib.escapeShellArg (
if pureXrayEnabled then
''{protocol: "socks", tag: $t, settings: {address: "127.0.0.1", port: $p}}''
else
''{type: "socks", tag: $t, server: "127.0.0.1", server_port: $p}''
)
}) || return 1
${
if hybridEnabled then
''_proxy_suite_add_sing_box_ob "$ob"''
else
''OUTBOUNDS_JSON=$(${jq} --argjson ob "$ob" '. + [$ob]' <<< "$OUTBOUNDS_JSON")''
}
_proxy_suite_record_tag_source "$1" "$3"
}
# $1 sub tag, $2 file holding its URL, $3 its links file (absent for a cache
# written before links existed: those entries share as JSON until the next update).
_proxy_suite_record_subscription_share() {
@@ -196,13 +218,14 @@ let
_proxy_suite_record_tag_source "$tag" "$source"
}
# Every runtime outbound, as "<tag>\t<file>" lines: <tag>.url or <tag>.json. proxy-ctl refuses
# Every runtime outbound, as "<tag>\t<file>" lines: <tag>.url, <tag>.json or <tag>.awg (an
# AmneziaWG config, behind a tunnel on the port in <tag>.port). proxy-ctl refuses
# the reserved names, but the spool is group-writable, so check again here:
# a second outbound tagged "proxy" would quietly shadow the real one.
_proxy_suite_runtime_outbounds() {
local f tag
[ -d "${runtimeOutboundsDir}" ] || return 0
for f in "${runtimeOutboundsDir}"/*.url "${runtimeOutboundsDir}"/*.json; do
for f in "${runtimeOutboundsDir}"/*.url "${runtimeOutboundsDir}"/*.json${lib.optionalString awgRuntimeOutbounds ''"${runtimeOutboundsDir}"/*.awg''}; do
[ -e "$f" ] || continue
tag="''${f##*/}"
tag="''${tag%.*}"
@@ -448,6 +471,8 @@ let
[ -n "$RUNTIME_OB_TAG" ] || continue
case "$RUNTIME_OB_SRC" in
*.json) _proxy_suite_add_json_outbound "$RUNTIME_OB_TAG" "$RUNTIME_OB_SRC" runtime ;;
# Its tunnel (proxy-suite-awg-tunnel@<tag>) checks the port again before listening.
*.awg) _proxy_suite_add_socks_hop "$RUNTIME_OB_TAG" "$(head -n 1 "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.port" 2>/dev/null)" runtime ;;
*) _proxy_suite_add_url_outbound "$RUNTIME_OB_TAG" "$(cat "$RUNTIME_OB_SRC")" runtime ;;
esac || { echo "proxy-suite: warning: ignoring runtime outbound '$RUNTIME_OB_TAG'" >&2; continue; }
if [ -s "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.detour" ]; then
+1
View File
@@ -128,6 +128,7 @@ let
torCfg
whitelistBypassJoiners
awgOutbounds
awgRuntimeOutbounds
constants
pureXrayEnabled
hybridEnabled