Skip to content

Commit c96dcbe

Browse files
cloudskytianYooLc
andauthored
add dialer-proxy support (#22)
* feat: add dialer-proxy export for clash * feat: add suge config parser for underlying-proxy, fix name for dialer-proxy for clash * fix: avoid breaking change, since users may already use underlying-proxy --------- Co-authored-by: YooLc <3220101835@zju.edu.cn>
1 parent fa0a9a9 commit c96dcbe

2 files changed

Lines changed: 61 additions & 14 deletions

File tree

src/generator/config/subexport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
282282
singleproxy["server"] = x.Hostname;
283283
singleproxy["port"] = x.Port;
284284

285+
if (!x.UnderlyingProxy.empty())
286+
singleproxy["dialer-proxy"] = x.UnderlyingProxy;
287+
285288
switch(x.Type)
286289
{
287290
case ProxyType::Shadowsocks:

src/parser/subparser.cpp

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,14 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
12421242
singleproxy["name"] >>= ps;
12431243
singleproxy["server"] >>= server;
12441244
singleproxy["port"] >>= port;
1245-
singleproxy["underlying-proxy"] >>= underlying_proxy;
1245+
1246+
underlying_proxy.clear();
1247+
// Use 'dialer-proxy' or 'underlying-proxy' to set underlying proxy
1248+
if (singleproxy["dialer-proxy"].IsDefined())
1249+
singleproxy["dialer-proxy"] >>= underlying_proxy;
1250+
else if (singleproxy["underlying-proxy"].IsDefined())
1251+
singleproxy["underlying-proxy"] >>= underlying_proxy;
1252+
12461253
if(port.empty() || port == "0")
12471254
continue;
12481255
udp = safe_as<std::string>(singleproxy["udp"]);
@@ -2095,6 +2102,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
20952102
std::string itemName, itemVal, config;
20962103
std::vector<std::string> configs, vArray, headers, header;
20972104
tribool udp, tfo, scv, tls13;
2105+
std::string underlying_proxy;
20982106
Proxy node;
20992107

21002108
/*
@@ -2159,6 +2167,9 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
21592167
case "tfo"_hash:
21602168
tfo = itemVal;
21612169
break;
2170+
case "underlying-proxy"_hash:
2171+
underlying_proxy = itemVal;
2172+
break;
21622173
default:
21632174
continue;
21642175
}
@@ -2169,7 +2180,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
21692180
pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host;
21702181
}
21712182

2172-
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv);
2183+
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv, tribool(), underlying_proxy);
21732184
}
21742185
//else
21752186
// continue;
@@ -2208,6 +2219,9 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
22082219
case "tfo"_hash:
22092220
tfo = itemVal;
22102221
break;
2222+
case "underlying-proxy"_hash:
2223+
underlying_proxy = itemVal;
2224+
break;
22112225
default:
22122226
continue;
22132227
}
@@ -2218,7 +2232,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
22182232
pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host;
22192233
}
22202234

2221-
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv);
2235+
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv, tribool(), underlying_proxy);
22222236
break;
22232237
case "socks5"_hash: //surge 3 style socks5 proxy
22242238
server = trim(configs[1]);
@@ -2248,11 +2262,14 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
22482262
case "skip-cert-verify"_hash:
22492263
scv = itemVal;
22502264
break;
2265+
case "underlying-proxy"_hash:
2266+
underlying_proxy = itemVal;
2267+
break;
22512268
default:
22522269
continue;
22532270
}
22542271
}
2255-
socksConstruct(node, SOCKS_DEFAULT_GROUP, remarks, server, port, username, password, udp, tfo, scv);
2272+
socksConstruct(node, SOCKS_DEFAULT_GROUP, remarks, server, port, username, password, udp, tfo, scv, underlying_proxy);
22562273
break;
22572274
case "vmess"_hash: //surge 4 style vmess proxy
22582275
server = trim(configs[1]);
@@ -2313,12 +2330,15 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
23132330
break;
23142331
case "vmess-aead"_hash:
23152332
aead = itemVal == "true" ? "0" : "1";
2333+
case "underlying-proxy"_hash:
2334+
underlying_proxy = itemVal;
2335+
break;
23162336
default:
23172337
continue;
23182338
}
23192339
}
23202340

2321-
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, edge, tls, "", udp, tfo, scv, tls13);
2341+
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, edge, tls, "", udp, tfo, scv, tls13, underlying_proxy);
23222342
break;
23232343
case "http"_hash: //http proxy
23242344
server = trim(configs[1]);
@@ -2343,11 +2363,14 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
23432363
case "skip-cert-verify"_hash:
23442364
scv = itemVal;
23452365
break;
2366+
case "underlying-proxy"_hash:
2367+
underlying_proxy = itemVal;
2368+
break;
23462369
default:
23472370
continue;
23482371
}
23492372
}
2350-
httpConstruct(node, HTTP_DEFAULT_GROUP, remarks, server, port, username, password, false, tfo, scv);
2373+
httpConstruct(node, HTTP_DEFAULT_GROUP, remarks, server, port, username, password, false, tfo, scv, tribool(), underlying_proxy);
23512374
break;
23522375
case "trojan"_hash: // surge 4 style trojan proxy
23532376
server = trim(configs[1]);
@@ -2379,12 +2402,15 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
23792402
case "skip-cert-verify"_hash:
23802403
scv = itemVal;
23812404
break;
2405+
case "underlying-proxy"_hash:
2406+
underlying_proxy = itemVal;
2407+
break;
23822408
default:
23832409
continue;
23842410
}
23852411
}
23862412

2387-
trojanConstruct(node, TROJAN_DEFAULT_GROUP, remarks, server, port, password, "", host, "", true, udp, tfo, scv);
2413+
trojanConstruct(node, TROJAN_DEFAULT_GROUP, remarks, server, port, password, "", host, "", true, udp, tfo, scv, tribool(), underlying_proxy);
23882414
break;
23892415
case "snell"_hash:
23902416
server = trim(configs[1]);
@@ -2422,12 +2448,15 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
24222448
case "version"_hash:
24232449
version = itemVal;
24242450
break;
2451+
case "underlying-proxy"_hash:
2452+
underlying_proxy = itemVal;
2453+
break;
24252454
default:
24262455
continue;
24272456
}
24282457
}
24292458

2430-
snellConstruct(node, SNELL_DEFAULT_GROUP, remarks, server, port, password, plugin, host, to_int(version, 0), udp, tfo, scv);
2459+
snellConstruct(node, SNELL_DEFAULT_GROUP, remarks, server, port, password, plugin, host, to_int(version, 0), udp, tfo, scv, underlying_proxy);
24312460
break;
24322461
case "wireguard"_hash:
24332462
for (i = 1; i < configs.size(); i++)
@@ -2445,6 +2474,9 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
24452474
case "test-url"_hash:
24462475
test_url = itemVal;
24472476
break;
2477+
case "underlying-proxy"_hash:
2478+
underlying_proxy = itemVal;
2479+
break;
24482480
}
24492481
}
24502482
if(section.empty())
@@ -2485,7 +2517,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
24852517
}
24862518
}
24872519

2488-
wireguardConstruct(node, WG_DEFAULT_GROUP, remarks, "", "0", ip, ipv6, private_key, "", "", dns_servers, mtu, keepalive, test_url, "", udp, "");
2520+
wireguardConstruct(node, WG_DEFAULT_GROUP, remarks, "", "0", ip, ipv6, private_key, "", "", dns_servers, mtu, keepalive, test_url, "", udp, underlying_proxy);
24892521
parsePeers(node, peer);
24902522
break;
24912523
default:
@@ -2557,6 +2589,9 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
25572589
case "tls13"_hash:
25582590
tls13 = itemVal;
25592591
break;
2592+
case "underlying-proxy"_hash:
2593+
underlying_proxy = itemVal;
2594+
break;
25602595
default:
25612596
continue;
25622597
}
@@ -2584,11 +2619,11 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
25842619

25852620
if(!protocol.empty())
25862621
{
2587-
ssrConstruct(node, SSR_DEFAULT_GROUP, remarks, server, port, protocol, method, pluginopts_mode, password, pluginopts_host, protoparam, udp, tfo, scv);
2622+
ssrConstruct(node, SSR_DEFAULT_GROUP, remarks, server, port, protocol, method, pluginopts_mode, password, pluginopts_host, protoparam, udp, tfo, scv, underlying_proxy);
25882623
}
25892624
else
25902625
{
2591-
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv, tls13);
2626+
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts, udp, tfo, scv, tls13, underlying_proxy);
25922627
}
25932628
break;
25942629
case "vmess"_hash: //quantumult x style vmess link
@@ -2651,14 +2686,17 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
26512686
break;
26522687
case "aead"_hash:
26532688
aead = itemVal == "true" ? "0" : "1";
2689+
case "underlying-proxy"_hash:
2690+
underlying_proxy = itemVal;
2691+
break;
26542692
default:
26552693
continue;
26562694
}
26572695
}
26582696
if(remarks.empty())
26592697
remarks = server + ":" + port;
26602698

2661-
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, "", tls, "", udp, tfo, scv, tls13);
2699+
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, "", tls, "", udp, tfo, scv, tls13, underlying_proxy);
26622700
break;
26632701
case "trojan"_hash: //quantumult x style trojan link
26642702
server = trim(configs[0].substr(0, configs[0].rfind(':')));
@@ -2699,14 +2737,17 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
26992737
case "tls13"_hash:
27002738
tls13 = itemVal;
27012739
break;
2740+
case "underlying-proxy"_hash:
2741+
underlying_proxy = itemVal;
2742+
break;
27022743
default:
27032744
continue;
27042745
}
27052746
}
27062747
if(remarks.empty())
27072748
remarks = server + ":" + port;
27082749

2709-
trojanConstruct(node, TROJAN_DEFAULT_GROUP, remarks, server, port, password, "", host, "", tls == "true", udp, tfo, scv, tls13);
2750+
trojanConstruct(node, TROJAN_DEFAULT_GROUP, remarks, server, port, password, "", host, "", tls == "true", udp, tfo, scv, tls13, underlying_proxy);
27102751
break;
27112752
case "http"_hash: //quantumult x style http links
27122753
server = trim(configs[0].substr(0, configs[0].rfind(':')));
@@ -2744,6 +2785,9 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
27442785
case "fast-open"_hash:
27452786
tfo = itemVal;
27462787
break;
2788+
case "underlying-proxy"_hash:
2789+
underlying_proxy = itemVal;
2790+
break;
27472791
default:
27482792
continue;
27492793
}
@@ -2756,7 +2800,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
27562800
if(password == "none")
27572801
password.clear();
27582802

2759-
httpConstruct(node, HTTP_DEFAULT_GROUP, remarks, server, port, username, password, tls == "true", tfo, scv, tls13);
2803+
httpConstruct(node, HTTP_DEFAULT_GROUP, remarks, server, port, username, password, tls == "true", tfo, scv, tls13, underlying_proxy);
27602804
break;
27612805
default:
27622806
continue;

0 commit comments

Comments
 (0)