feat/wip: ssh-proxy

This commit is contained in:
FUFSoB committed 2026-09-08 23:36:47 +05:00
1 parent 9a1604554d
commit 7a106326ea
16 files changed
+990 -22

No files matched your search

+3
View File
@@ -42,6 +42,8 @@ let
invalidRoutingTargets
collapseNamedOutbounds
hasSubscriptions
sshProxyCfg
sshProxyOutboundEnabled
;
# Tool paths – defined once here and passed into sub-modules as needed.
@@ -74,6 +76,7 @@ let
pkgs
singBoxCfg
proxyCfg
sshProxyCfg
xrayEnabled
hybridEnabled
pureXrayEnabled
+4
View File
@@ -60,7 +60,9 @@ let
userControlEnabled
perAppZapretEnabled
hasSubscriptions
sshProxyOutboundEnabled
outboundTags
effectiveOutboundTags
subscriptionTags
invalidRoutingTargets
builtinTags
@@ -96,6 +98,7 @@ let
perAppRoutingTproxy
perAppZapretEnabled
hasSubscriptions
sshProxyOutboundEnabled
scripts
perAppRouting
routingScripts
@@ -153,6 +156,7 @@ in
inherit
builtinTags
outboundTags
effectiveOutboundTags
subscriptionTags
invalidRoutingTargets
;
@@ -4,6 +4,7 @@
pkgs,
singBoxCfg,
proxyCfg,
sshProxyCfg,
pureXrayEnabled,
hybridEnabled,
collapseNamedOutbounds,
@@ -19,6 +20,8 @@
}:
let
sshProxyTag = "ssh-proxy";
rawOutboundJson =
ob: tag: routingMark:
let
@@ -163,6 +166,47 @@ let
fi
'';
mkSshProxyOutboundBlock =
routingMark:
let
singBoxOutbound = {
type = "socks";
tag = sshProxyTag;
server = sshProxyCfg.listenAddress;
server_port = sshProxyCfg.listenPort;
version = "5";
}
// lib.optionalAttrs (routingMark != null) {
routing_mark = routingMark;
};
xrayOutbound = {
protocol = "socks";
tag = sshProxyTag;
settings = {
address = sshProxyCfg.listenAddress;
port = sshProxyCfg.listenPort;
};
}
// lib.optionalAttrs (routingMark != null) {
streamSettings.sockopt.mark = routingMark;
};
outbound = if pureXrayEnabled then xrayOutbound else singBoxOutbound;
outboundJson = builtins.toJSON outbound;
jsonFile = pkgs.writeText "proxy-suite-ob-ssh-proxy-${backend}.json" outboundJson;
in
if hybridEnabled then
''
# outbound: ${sshProxyTag} (SSH SOCKS5)
OB_JSON=$(cat "${jsonFile}")
_proxy_suite_add_sing_box_ob "$OB_JSON"
''
else
''
# outbound: ${sshProxyTag} (SSH SOCKS5)
OB_JSON=$(cat "${jsonFile}")
OUTBOUNDS_JSON=$(${jq} --argjson ob "$OB_JSON" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
'';
mkBackendOutboundBlock = if hybridEnabled then mkHybridOutboundBlock else mkOutboundBlock;
requireOutboundsBlock = ''
@@ -185,6 +229,8 @@ let
sub: mkSubscriptionBlock sub routingMark
) proxyCfg.subscriptions;
sshProxyBlock = lib.optionalString sshProxyCfg.asOutbound (mkSshProxyOutboundBlock routingMark);
wrapperBlock =
if pureXrayEnabled && selectionMode == "urltest" then
''
@@ -194,13 +240,15 @@ let
fi
''
else if collapseNamedOutbounds then
lib.optionalString (proxyCfg.outbounds == [ ] && proxyCfg.subscriptions != [ ]) ''
FIRST_TAG=$(${jq} -r 'if length > 0 then .[0].tag else "" end' <<< "$OUTBOUNDS_JSON")
if [ -n "$FIRST_TAG" ]; then
OUTBOUNDS_JSON=$(${jq} --arg t "$FIRST_TAG" \
'map(if .tag == $t then .tag = "proxy" else . end)' <<< "$OUTBOUNDS_JSON")
fi
''
lib.optionalString
(proxyCfg.outbounds == [ ] && (proxyCfg.subscriptions != [ ] || sshProxyCfg.asOutbound))
''
FIRST_TAG=$(${jq} -r 'if length > 0 then .[0].tag else "" end' <<< "$OUTBOUNDS_JSON")
if [ -n "$FIRST_TAG" ]; then
OUTBOUNDS_JSON=$(${jq} --arg t "$FIRST_TAG" \
'map(if .tag == $t then .tag = "proxy" else . end)' <<< "$OUTBOUNDS_JSON")
fi
''
else if selectionMode == "selector" then
''
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
@@ -223,7 +271,7 @@ let
OUTBOUNDS_JSON=$(${jq} --argjson w "$WRAPPER" '[$w] + .' <<< "$OUTBOUNDS_JSON")
'';
in
outboundBlocks + subscriptionBlocks + requireOutboundsBlock + wrapperBlock;
outboundBlocks + subscriptionBlocks + sshProxyBlock + requireOutboundsBlock + wrapperBlock;
in
{
inherit mkOutboundScript rawOutboundJson;
+2
View File
@@ -4,6 +4,7 @@
pkgs,
singBoxCfg,
proxyCfg,
sshProxyCfg,
xrayEnabled,
hybridEnabled,
pureXrayEnabled,
@@ -88,6 +89,7 @@ let
pkgs
singBoxCfg
proxyCfg
sshProxyCfg
pureXrayEnabled
hybridEnabled
collapseNamedOutbounds
+5 -1
View File
@@ -12,6 +12,7 @@
perAppRoutingTproxy,
perAppZapretEnabled,
hasSubscriptions,
sshProxyOutboundEnabled,
scripts,
perAppRouting,
routingScripts,
@@ -60,7 +61,10 @@ let
name = serviceNames.socks;
value = mkRestartingService {
description = "${backendDescription} proxy client (SOCKS + TProxy-ready)";
after = [ "network-online.target" ];
after = [
"network-online.target"
]
++ lib.optional sshProxyOutboundEnabled "proxy-suite-ssh-proxy.service";
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
execStart = scripts.startSocks;