Enhancements

Fix port generation for Surge ShadowsocksR configuration.
Fix compatibility with some non-standard subscription.
Add some node preference tags.
This commit is contained in:
Tindy X
2019-12-13 17:56:39 +08:00
parent 9756258041
commit 53f31b5d3a
4 changed files with 66 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ extern std::mutex on_configuring;
//preferences
string_array renames, emojis;
bool add_emoji = false, remove_old_emoji = false, append_proxy_type = true;
bool udp_flag = false, tfo_flag = false, do_sort = false;
std::string proxy_ruleset, proxy_subscription;
std::string clash_rule_base;
@@ -176,6 +177,17 @@ void readConf()
surge_ssr_path = ini.Get("surge_ssr_path");
}
if(ini.SectionExist("node_pref"))
{
ini.EnterSection("node_pref");
if(ini.ItemExist("udp_flag"))
udp_flag = ini.GetBool("udp_flag");
if(ini.ItemExist("tcp_fast_open_flag"))
tfo_flag = ini.GetBool("tcp_fast_open_flag");
if(ini.ItemExist("sort_flag"))
do_sort = ini.GetBool("sort_flag");
}
ini.EnterSection("managed_config");
if(ini.ItemExist("write_managed_config"))
write_managed_config = ini.GetBool("write_managed_config");
@@ -301,10 +313,11 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
else
proxy = proxy_subscription;
ext.tfo = tfo == "true";
ext.udp = udp == "true";
ext.tfo = tfo.size() ? tfo == "true" : tfo_flag;
ext.udp = udp.size() ? udp == "true" : udp_flag;
ext.sort_flag = sort_flag.size() ? sort_flag == "true" : do_sort;
ext.nodelist = nodelist == "true";
ext.sort_flag = sort_flag == "true";
ext.surge_ssr_path = surge_ssr_path;
string_array urls = split(url, "|");

View File

@@ -86,6 +86,11 @@ append_proxy_type=false
; times RE
rename_node=\(?((x|X)?(\d+)(\.?\d+)?)((\s?倍率?)|(x|X))\)?@$1x
[node_pref]
udp_flag=false
tcp_fast_open_flag=false
sort_flag=false
[managed_config]
;Append a '#!MANAGED-CONFIG' info to Surge configurations
write_managed_config=true

View File

@@ -1517,7 +1517,7 @@ void explodeSub(std::string sub, bool sslibev, bool ssrlibev, std::string custom
//try to parse as normal subscription
if(!processed)
{
sub = urlsafe_base64_decode(sub);
sub = urlsafe_base64_decode(trim(sub));
strstream << sub;
char delimiter = count(sub.begin(), sub.end(), '\n') < 1 ? count(sub.begin(), sub.end(), '\r') < 1 ? ' ' : '\r' : '\n';
while(getline(strstream, strLink, delimiter))

View File

@@ -6,6 +6,7 @@
#include "subexport.h"
#include "printout.h"
#include "multithread.h"
#include "socket.h"
#include <iostream>
#include <numeric>
@@ -19,6 +20,43 @@ extern bool add_emoji, remove_old_emoji;
extern bool api_mode;
extern string_array ss_ciphers, ssr_ciphers;
/*
std::string hostnameToIPAddr(std::string host)
{
int retVal;
std::string retAddr;
char cAddr[128] = {};
struct sockaddr_in *target;
struct sockaddr_in6 *target6;
struct addrinfo hint = {}, *retAddrInfo, *cur;
retVal = getaddrinfo(host.data(), NULL, &hint, &retAddrInfo);
if(retVal != 0)
{
freeaddrinfo(retAddrInfo);
return std::string();
}
for(cur = retAddrInfo; cur != NULL; cur=cur->ai_next)
{
if(cur->ai_family == AF_INET)
{
target = reinterpret_cast<struct sockaddr_in *>(cur->ai_addr);
inet_ntop(AF_INET, &target->sin_addr, cAddr, sizeof(cAddr));
break;
}
else if(cur->ai_family == AF_INET6)
{
target6 = reinterpret_cast<struct sockaddr_in6 *>(cur->ai_addr);
inet_ntop(AF_INET6, &target6->sin6_addr, cAddr, sizeof(cAddr));
break;
}
}
retAddr.assign(cAddr);
freeaddrinfo(retAddrInfo);
return retAddr;
}
*/
std::string vmessConstruct(std::string add, std::string port, std::string type, std::string id, std::string aid, std::string net, std::string cipher, std::string path, std::string host, std::string tls, int local_port)
{
if(!port.size())
@@ -618,6 +656,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
std::string url, group;
std::string output_nodelist;
std::vector<nodeInfo> nodelist;
unsigned short local_port = 1080;
bool tlssecure;
string_array vArray, remarks_list, filtered_nodelist;
@@ -700,14 +739,14 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
}
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSSR && ext.surge_ssr_path.size())
{
if(surge_ver < 4)
if(surge_ver < 2)
continue;
protocol = GetMember(json, "Protocol");
protoparam = GetMember(json, "ProtocolParam");
obfs = GetMember(json, "OBFS");
obfsparam = GetMember(json, "OBFSParam");
proxy = "external, exec=\"" + ext.surge_ssr_path + "\", args=\"";
string_array args = {"-l", "1080", "-s", hostname, "-p", port, "-m", method, "-k", password, "-o", obfs, "-O", protocol};
string_array args = {"-l", std::__cxx11::to_string(local_port), "-s", hostname, "-p", port, "-m", method, "-k", password, "-o", obfs, "-O", protocol};
if(obfsparam.size())
{
args.emplace_back("-g");
@@ -720,7 +759,9 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
}
proxy += std::accumulate(std::next(args.cbegin()), args.cend(), args[0], [](std::string a, std::string b){return std::move(a) + "\", args=\"" + std::move(b);});
//std::string ipaddr = (isIPv4(hostname) || isIPv6(hostname)) ? hostname : hostnameToIPAddr(hostname);
proxy += "\", local-port=1080";
//proxy += "\", local-port=" + std::__cxx11::to_string(local_port) + ", addresses=" + ipaddr;
proxy += "\", local-port=" + std::__cxx11::to_string(local_port);
local_port++;
}
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSOCKS)
{