feat: update tg-ws-proxy and its options
This commit is contained in:
6 files changed
+732
-29
No files matched your search
@@ -131,6 +131,128 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
verbose = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable debug logging in tg-ws-proxy.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
logFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Optional path where tg-ws-proxy writes rotating logs.
|
||||
When unset, tg-ws-proxy logs to stderr only.
|
||||
'';
|
||||
example = "/var/log/tg-ws-proxy.log";
|
||||
};
|
||||
|
||||
logMaxMb = mkOption {
|
||||
type = types.numbers.positive;
|
||||
default = 5.0;
|
||||
description = ''
|
||||
Maximum tg-ws-proxy log file size in MiB before rotation.
|
||||
Only used when tgWsProxy.logFile is set.
|
||||
'';
|
||||
example = 10.0;
|
||||
};
|
||||
|
||||
logBackups = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1;
|
||||
description = ''
|
||||
Number of rotated tg-ws-proxy log files to keep.
|
||||
Only used when tgWsProxy.logFile is set.
|
||||
'';
|
||||
example = 3;
|
||||
};
|
||||
|
||||
bufKb = mkOption {
|
||||
type = types.ints.between 4 2147483647;
|
||||
default = 256;
|
||||
description = ''
|
||||
Socket send and receive buffer size for tg-ws-proxy, in KiB.
|
||||
'';
|
||||
example = 512;
|
||||
};
|
||||
|
||||
poolSize = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 4;
|
||||
description = ''
|
||||
WebSocket connection pool size per Telegram DC.
|
||||
Set to 0 to disable connection pooling.
|
||||
'';
|
||||
example = 8;
|
||||
};
|
||||
|
||||
cfProxyDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
User-defined Cloudflare-proxied domains used by tg-ws-proxy for
|
||||
WebSocket fallback. Each entry is passed as a separate
|
||||
--cfproxy-domain argument.
|
||||
'';
|
||||
example = [
|
||||
"cdn.example.com"
|
||||
"edge.example.net"
|
||||
];
|
||||
};
|
||||
|
||||
cfProxyWorkerDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Cloudflare Worker domains used by tg-ws-proxy for WebSocket fallback.
|
||||
These are tried before other fallback methods.
|
||||
'';
|
||||
example = [ "worker.example.com" ];
|
||||
};
|
||||
|
||||
cfProxyFallback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to allow tg-ws-proxy to use Cloudflare proxy fallback when
|
||||
direct WebSocket routing is unavailable.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
fakeTlsDomain = mkOption {
|
||||
type = types.nullOr (types.strMatching ".+");
|
||||
default = null;
|
||||
description = ''
|
||||
Optional SNI domain used to enable tg-ws-proxy Fake TLS masking.
|
||||
When set, tg-ws-proxy emits an ee-secret connection link.
|
||||
'';
|
||||
example = "www.example.com";
|
||||
};
|
||||
|
||||
proxyProtocol = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether tg-ws-proxy should accept a PROXY protocol v1 header from a
|
||||
fronting reverse proxy such as nginx or HAProxy.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
wsKeepalive = mkOption {
|
||||
type = types.numbers.nonnegative;
|
||||
default = 30.0;
|
||||
description = ''
|
||||
Seconds between upstream WebSocket keepalive pings.
|
||||
Set to 0 to disable keepalive pings.
|
||||
'';
|
||||
example = 15.0;
|
||||
};
|
||||
|
||||
bypassTransparentProxy = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
|
||||
@@ -12,24 +12,40 @@ let
|
||||
ip = "${pkgs.iproute2}/bin/ip";
|
||||
|
||||
transparentBypassEnabled =
|
||||
t.bypassTransparentProxy
|
||||
&& cfg.proxy.enable
|
||||
&& (cfg.proxy.tun.enable || cfg.proxy.tproxy.enable);
|
||||
t.bypassTransparentProxy && cfg.proxy.enable && (cfg.proxy.tun.enable || cfg.proxy.tproxy.enable);
|
||||
bypassRulePriority = 8999;
|
||||
|
||||
dcArgs = lib.concatMapStrings
|
||||
(id: " --dc-ip=${lib.escapeShellArg "${id}:${t.dcIps.${id}}"}")
|
||||
(builtins.attrNames t.dcIps);
|
||||
mkValueArg = name: value: " args+=(${name}=${lib.escapeShellArg value})\n";
|
||||
mkRawValueArg = name: value: " args+=(${name}=${toString value})\n";
|
||||
mkFlagArg = condition: name: lib.optionalString condition " args+=(${name})\n";
|
||||
mkOptionalValueArg =
|
||||
condition: name: value:
|
||||
lib.optionalString condition (mkValueArg name value);
|
||||
mkRepeatedValueArgs = name: values: lib.concatMapStrings (value: mkValueArg name value) values;
|
||||
dcArgs = lib.concatMapStrings (id: mkValueArg "--dc-ip" "${id}:${t.dcIps.${id}}") (
|
||||
builtins.attrNames t.dcIps
|
||||
);
|
||||
startScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-start" ''
|
||||
exec ${tgPkg}/bin/tg-ws-proxy \
|
||||
--port=${toString t.port} \
|
||||
--host=${lib.escapeShellArg t.host} \
|
||||
${
|
||||
if t.secretFile != null then
|
||||
"--secret-file=$CREDENTIALS_DIRECTORY/tg_ws_proxy_secret"
|
||||
else
|
||||
"--secret=${lib.escapeShellArg t.secret}"
|
||||
}${dcArgs}
|
||||
args=(
|
||||
--port=${toString t.port}
|
||||
--host=${lib.escapeShellArg t.host}
|
||||
)
|
||||
${
|
||||
if t.secretFile != null then
|
||||
''args+=(--secret-file="$CREDENTIALS_DIRECTORY/tg_ws_proxy_secret")''
|
||||
else
|
||||
"args+=(--secret=${lib.escapeShellArg t.secret})"
|
||||
}
|
||||
${dcArgs}${mkFlagArg t.verbose "--verbose"}${
|
||||
mkOptionalValueArg (t.logFile != null) "--log-file" t.logFile
|
||||
}${lib.optionalString (t.logFile != null) (mkRawValueArg "--log-max-mb" t.logMaxMb)}${
|
||||
lib.optionalString (t.logFile != null) (mkRawValueArg "--log-backups" t.logBackups)
|
||||
}${mkRawValueArg "--buf-kb" t.bufKb}${mkRawValueArg "--pool-size" t.poolSize}${mkRepeatedValueArgs "--cfproxy-domain" t.cfProxyDomains}${mkRepeatedValueArgs "--cfproxy-worker-domain" t.cfProxyWorkerDomains}${
|
||||
mkFlagArg (!t.cfProxyFallback) "--no-cfproxy"
|
||||
}${
|
||||
mkOptionalValueArg (t.fakeTlsDomain != null) "--fake-tls-domain" t.fakeTlsDomain
|
||||
}${mkFlagArg t.proxyProtocol "--proxy-protocol"}${mkRawValueArg "--ws-keepalive" t.wsKeepalive}
|
||||
exec ${tgPkg}/bin/tg-ws-proxy "''${args[@]}"
|
||||
'';
|
||||
|
||||
bypassUpScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-bypass-up" ''
|
||||
|
||||
Reference in new issue
Block a user