Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Fix matching not-range does not work (#428).
Fix parsing and generating of HTTPS nodes (#450).
Add servername field for Clash VMess nodes (#449 #451).
Add VMess AEAD option for Surge and Quantumult X configs.
  • Loading branch information
tindy2013 committed Feb 9, 2022
1 parent 2f78eaf commit 80cda7b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 73 deletions.
28 changes: 15 additions & 13 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ bool matchRange(const std::string &range, int target)
}
else if(regMatch(x, reg_range))
{
/*
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
*/
regGetMatch(x, reg_range, 3, 0, &range_begin_str, &range_end_str);
range_begin = to_int(range_begin_str, INT_MAX);
range_end = to_int(range_end_str, INT_MIN);
Expand All @@ -88,15 +84,13 @@ bool matchRange(const std::string &range, int target)
}
else if(regMatch(x, reg_not))
{
match = true;
if(to_int(regReplace(x, reg_not, "$1"), INT_MAX) == target)
match = false;
}
else if(regMatch(x, reg_not_range))
{
/*
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
*/
match = true;
regGetMatch(x, reg_range, 3, 0, &range_begin_str, &range_end_str);
range_begin = to_int(range_begin_str, INT_MAX);
range_end = to_int(range_end_str, INT_MIN);
Expand Down Expand Up @@ -296,6 +290,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
singleproxy["tls"] = x.TLSSecure;
if(!scv.is_undef())
singleproxy["skip-cert-verify"] = scv.get();
if(!x.ServerName.empty())
singleproxy["servername"] = x.ServerName;
switch(hash_(x.TransferProtocol))
{
case "tcp"_hash:
Expand Down Expand Up @@ -387,6 +383,7 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
singleproxy["skip-cert-verify"] = scv.get();
break;
case ProxyType::HTTP:
case ProxyType::HTTPS:
singleproxy["type"] = "http";
if(!x.Username.empty())
singleproxy["username"] = x.Username;
Expand All @@ -396,7 +393,7 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
if(std::all_of(x.Password.begin(), x.Password.end(), ::isdigit))
singleproxy["password"].SetTag("str");
}
singleproxy["tls"] = type == "HTTPS";
singleproxy["tls"] = x.TLSSecure;
if(!scv.is_undef())
singleproxy["skip-cert-verify"] = scv.get();
break;
Expand Down Expand Up @@ -429,8 +426,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
case ProxyType::Snell:
singleproxy["type"] = "snell";
singleproxy["psk"] = x.Password;
if(x.AlterId != 0)
singleproxy["version"] = x.AlterId;
if(x.SnellVersion != 0)
singleproxy["version"] = x.SnellVersion;
if(!x.OBFS.empty())
{
singleproxy["obfs-opts"]["mode"] = x.OBFS;
Expand Down Expand Up @@ -672,7 +669,7 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
case ProxyType::VMess:
if(surge_ver < 4 && surge_ver != -3)
continue;
proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false");
proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false") + ", vmess-aead=" + (x.AlterId == 0 ? "true" : "false");
if(tlssecure && !tls13.is_undef())
proxy += ", tls13=" + std::string(tls13 ? "true" : "false");
switch(hash_(transproto))
Expand Down Expand Up @@ -723,6 +720,7 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
proxy += ", skip-cert-verify=" + scv.get_str();
break;
case ProxyType::HTTP:
case ProxyType::HTTPS:
proxy = "http, " + hostname + ", " + port;
if(!username.empty())
proxy += ", username=" + username;
Expand All @@ -736,6 +734,8 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
if(surge_ver < 4)
continue;
proxy = "trojan, " + hostname + ", " + port + ", password=" + password;
if(x.SnellVersion != 0)
proxy += ", version=" + std::to_string(x.SnellVersion);
if(!host.empty())
proxy += ", sni=" + host;
if(!scv.is_undef())
Expand Down Expand Up @@ -1104,6 +1104,7 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
}
break;
case ProxyType::HTTP:
case ProxyType::HTTPS:
proxyStr = remark + " = http, upstream-proxy-address=" + hostname + ", upstream-proxy-port=" + port + ", group=" + x.Group;
if(!username.empty() && !password.empty())
proxyStr += ", upstream-proxy-auth=true, upstream-proxy-username=" + username + ", upstream-proxy-password=" + password;
Expand Down Expand Up @@ -1290,7 +1291,7 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
case ProxyType::VMess:
if(method == "auto")
method = "chacha20-ietf-poly1305";
proxyStr = "vmess = " + hostname + ":" + port + ", method=" + method + ", password=" + id;
proxyStr = "vmess = " + hostname + ":" + port + ", method=" + method + ", password=" + id + ", aead=" + (x.AlterId == 0 ? "true" : "false");
if(tlssecure && !tls13.is_undef())
proxyStr += ", tls13=" + std::string(tls13 ? "true" : "false");
if(transproto == "ws")
Expand Down Expand Up @@ -1347,6 +1348,7 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
proxyStr += ", obfs-host=" + obfsparam;
break;
case ProxyType::HTTP:
case ProxyType::HTTPS:
proxyStr = "http = " + hostname + ":" + port + ", username=" + (username.empty() ? "none" : username) + ", password=" + (password.empty() ? "none" : password);
if(tlssecure)
{
Expand Down
3 changes: 2 additions & 1 deletion src/handler/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../config/ruleset.h"
#include "../generator/config/ruleconvert.h"
#include "../generator/template/templates.h"
#include "../utils/logger.h"
#include "../utils/string.h"
#include "../utils/stl_extra.h"
#include "../utils/tribool.h"
Expand All @@ -28,7 +29,7 @@ struct Settings
bool printDbgInfo = false, CFWChildProcess = false, appendUserinfo = true, asyncFetchRuleset = false, surgeResolveHostname = true;
std::string accessToken, basePath = "base";
std::string custom_group;
int logLevel = 0;
int logLevel = LOG_LEVEL_INFO;
long maxAllowedDownloadSize = 1048576L;
string_map aliases;

Expand Down
3 changes: 3 additions & 0 deletions src/parser/config/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ struct Proxy
tribool TCPFastOpen;
tribool AllowInsecure;
tribool TLS13;

uint16_t SnellVersion = 0;
String ServerName;
};

#define SS_DEFAULT_GROUP "SSProvider"
Expand Down
Loading

0 comments on commit 80cda7b

Please sign in to comment.