Add HTTP single link support with Telegram-link-liked format

Optimize codes.
This commit is contained in:
Tindy X committed 2020-02-19 15:17:07 +08:00
1 parent 3db6ae9214
commit ccd623e07e
4 files changed
+29 -22

No files matched your search

+3 -15
View File
@@ -31,14 +31,10 @@ int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std
// TODO: replace with startsWith if appropriate // TODO: replace with startsWith if appropriate
link = replace_all_distinct(link, "\"", ""); link = replace_all_distinct(link, "\"", "");
writeLog(LOG_TYPE_INFO, "Received Link."); writeLog(LOG_TYPE_INFO, "Received Link.");
if(strFind(link, "vmess://") || strFind(link, "vmess1://")) if(strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
linkType = SPEEDTEST_MESSAGE_FOUNDVMESS;
else if(strFind(link, "ss://"))
linkType = SPEEDTEST_MESSAGE_FOUNDSS;
else if(strFind(link, "ssr://"))
linkType = SPEEDTEST_MESSAGE_FOUNDSSR;
else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS; linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS;
else if(strFind(link, "https://t.me/http") || strFind(link, "tg://http"))
linkType = SPEEDTEST_MESSAGE_FOUNDHTTP;
else if(startsWith(link, "http://") || startsWith(link, "https://") || startsWith(link, "data:") || strFind(link, "surge:///install-config")) else if(startsWith(link, "http://") || startsWith(link, "https://") || startsWith(link, "data:") || strFind(link, "surge:///install-config"))
linkType = SPEEDTEST_MESSAGE_FOUNDSUB; linkType = SPEEDTEST_MESSAGE_FOUNDSUB;
else if(strFind(link, "Netch://")) else if(strFind(link, "Netch://"))
@@ -118,8 +114,6 @@ int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std
copyNodes(nodes, allNodes); copyNodes(nodes, allNodes);
break; break;
default: default:
if(linkType > 0)
{
explode(link, ss_libev, ssr_libev, override_conf_port, socksport, node); explode(link, ss_libev, ssr_libev, override_conf_port, socksport, node);
if(node.linkType == -1) if(node.linkType == -1)
{ {
@@ -129,11 +123,5 @@ int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std
node.groupID = groupID; node.groupID = groupID;
allNodes.push_back(node); allNodes.push_back(node);
} }
else
{
writeLog(LOG_TYPE_ERROR, "No valid link found.");
return -1;
}
}
return 0; return 0;
} }
+23 -4
View File
@@ -560,13 +560,9 @@ void explodeSocks(std::string link, std::string custom_port, nodeInfo &node)
password = getUrlArg(link, "pass"); password = getUrlArg(link, "pass");
} }
if(remarks == "") if(remarks == "")
{
remarks = server + ":" + port; remarks = server + ":" + port;
}
if(custom_port.size()) if(custom_port.size())
{
port = custom_port; port = custom_port;
}
node.linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS; node.linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS;
node.group = SOCKS_DEFAULT_GROUP; node.group = SOCKS_DEFAULT_GROUP;
@@ -576,6 +572,27 @@ void explodeSocks(std::string link, std::string custom_port, nodeInfo &node)
node.proxyStr = socksConstruct(remarks, server, port, username, password); node.proxyStr = socksConstruct(remarks, server, port, username, password);
} }
void explodeHTTP(std::string link, std::string custom_port, nodeInfo &node)
{
std::string remarks, server, port, username, password;
server = getUrlArg(link, "server");
port = getUrlArg(link, "port");
username = getUrlArg(link, "user");
password = getUrlArg(link, "pass");
if(remarks == "")
remarks = server + ":" + port;
if(custom_port.size())
port = custom_port;
node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP;
node.group = HTTP_DEFAULT_GROUP;
node.remarks = remarks;
node.server = server;
node.port = to_int(port, 0);
node.proxyStr = httpConstruct(remarks, server, port, username, password, strFind(link, "/https"));
}
void explodeQuan(std::string quan, std::string custom_port, int local_port, nodeInfo &node) void explodeQuan(std::string quan, std::string custom_port, int local_port, nodeInfo &node)
{ {
std::string strTemp, itemName, itemVal; std::string strTemp, itemName, itemVal;
@@ -1480,6 +1497,8 @@ void explode(std::string link, bool sslibev, bool ssrlibev, std::string custom_p
explodeSS(link, sslibev, custom_port, local_port, node); explodeSS(link, sslibev, custom_port, local_port, node);
else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks")) else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
explodeSocks(link, custom_port, node); explodeSocks(link, custom_port, node);
else if(strFind(link, "https://t.me/http") || strFind(link, "tg://http")) //telegram style http link
explodeHTTP(link, custom_port, node);
else if(strFind(link, "Netch://")) else if(strFind(link, "Netch://"))
explodeNetch(link, sslibev, ssrlibev, custom_port, local_port, node); explodeNetch(link, sslibev, ssrlibev, custom_port, local_port, node);
} }
+1 -1
View File
@@ -11,7 +11,7 @@ std::string vmessConstruct(std::string add, std::string port, std::string type,
std::string ssrConstruct(std::string group, std::string remarks, std::string remarks_base64, std::string server, std::string port, std::string protocol, std::string method, std::string obfs, std::string password, std::string obfsparam, std::string protoparam, int local_port, bool libev); std::string ssrConstruct(std::string group, std::string remarks, std::string remarks_base64, std::string server, std::string port, std::string protocol, std::string method, std::string obfs, std::string password, std::string obfsparam, std::string protoparam, int local_port, bool libev);
std::string ssConstruct(std::string server, std::string port, std::string password, std::string method, std::string plugin, std::string pluginopts, std::string remarks, int local_port, bool libev); std::string ssConstruct(std::string server, std::string port, std::string password, std::string method, std::string plugin, std::string pluginopts, std::string remarks, int local_port, bool libev);
std::string socksConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password); std::string socksConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password);
std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password); std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls = false);
void explodeVmess(std::string vmess, std::string custom_port, int local_port, nodeInfo &node); void explodeVmess(std::string vmess, std::string custom_port, int local_port, nodeInfo &node);
void explodeSSR(std::string ssr, bool ss_libev, bool libev, std::string custom_port, int local_port, nodeInfo &node); void explodeSSR(std::string ssr, bool ss_libev, bool libev, std::string custom_port, int local_port, nodeInfo &node);
void explodeSS(std::string ss, bool libev, std::string custom_port, int local_port, nodeInfo &node); void explodeSS(std::string ss, bool libev, std::string custom_port, int local_port, nodeInfo &node);
+2 -2
View File
@@ -190,13 +190,13 @@ std::string socksConstruct(std::string remarks, std::string server, std::string
return sb.GetString(); return sb.GetString();
} }
std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password) std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls)
{ {
rapidjson::StringBuffer sb; rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb); rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
writer.StartObject(); writer.StartObject();
writer.Key("Type"); writer.Key("Type");
writer.String("HTTP"); writer.String(tls ? "HTTPS" : "HTTP");
writer.Key("Remark"); writer.Key("Remark");
writer.String(remarks.data()); writer.String(remarks.data());
writer.Key("Hostname"); writer.Key("Hostname");