feat: support warp config generators
This commit is contained in:
5 files changed
+56
-4
No files matched your search
@@ -12,7 +12,7 @@ in
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a WireGuard profile for WARP, as written by `wgcf register && wgcf generate`.
|
||||
Junk-packet lines (Jc, Jmin, Jmax) are honoured by the AmneziaWG profile only.
|
||||
AmneziaWG lines (Jc, S1-S4, H1-H4, I1-I5, AWG 3 timing) are honoured by the AmneziaWG profile only.
|
||||
|
||||
When null, proxy-suite-warp registers a device with wgcf (accepting Cloudflare's terms)
|
||||
into /var/lib/proxy-suite/warp, through the local proxy when proxy.enable is set, and
|
||||
@@ -21,6 +21,19 @@ in
|
||||
example = "/run/secrets/wgcf-profile.conf";
|
||||
};
|
||||
|
||||
generatorUrl = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
HTTPS URL of a WARP profile generator, fetched directly when wgcf registration fails
|
||||
(e.g. the Cloudflare API is blocked and there is no local proxy). It must return a
|
||||
WireGuard profile, or JSON with the base64 profile in `.content`.
|
||||
|
||||
The generator registers the device, so its operator sees the private key.
|
||||
'';
|
||||
example = "https://valokda-amnezia.vercel.app/api/warp?mode=awg2";
|
||||
};
|
||||
|
||||
asOutbound = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
|
||||
@@ -46,7 +46,20 @@ let
|
||||
[ -s wgcf-account.toml ] || wgcf register --accept-tos
|
||||
wgcf generate
|
||||
}
|
||||
${lib.optionalString (w.generatorUrl != null) ''
|
||||
|
||||
# Fallback: a third-party generator registers from abroad and hands the profile back.
|
||||
generate() {
|
||||
body=$(${pkgs.curl}/bin/curl --noproxy '*' -fsS --max-time 60 -A proxy-suite \
|
||||
${lib.escapeShellArg w.generatorUrl}) || return 1
|
||||
case "$body" in
|
||||
"[Interface]"*) printf '%s\n' "$body" ;;
|
||||
*) ${pkgs.jq}/bin/jq -er '.content | @base64d' <<< "$body" ;;
|
||||
esac > wgcf-profile.conf.tmp || return 1
|
||||
grep -q '^PrivateKey' wgcf-profile.conf.tmp || return 1
|
||||
mv wgcf-profile.conf.tmp wgcf-profile.conf
|
||||
}
|
||||
''}
|
||||
${
|
||||
if cfg.proxy.enable then
|
||||
''
|
||||
@@ -58,10 +71,12 @@ let
|
||||
done
|
||||
userinfo=
|
||||
${userinfo}
|
||||
HTTPS_PROXY="socks5://''${userinfo}${hostPart}:${toString listener.port}" register || register
|
||||
HTTPS_PROXY="socks5://''${userinfo}${hostPart}:${toString listener.port}" register || register${
|
||||
lib.optionalString (w.generatorUrl != null) " || generate"
|
||||
}
|
||||
''
|
||||
else
|
||||
"register"
|
||||
"register${lib.optionalString (w.generatorUrl != null) " || generate"}"
|
||||
}
|
||||
'';
|
||||
|
||||
|
||||
Reference in new issue
Block a user