Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Cookie' in Clash ws-opts #487

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: GitHub CI
on: [push]
on:
push:
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
subconverter.exe
.vscode
.idea/
cmake-build-debug/
4 changes: 4 additions & 0 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
singleproxy["ws-opts"]["headers"]["Host"] = x.Host;
if(!x.Edge.empty())
singleproxy["ws-opts"]["headers"]["Edge"] = x.Edge;
if(!x.Cookie.empty())
singleproxy["ws-opts"]["headers"]["Cookie"] = x.Cookie;
}
else
{
Expand All @@ -313,6 +315,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
singleproxy["ws-headers"]["Host"] = x.Host;
if(!x.Edge.empty())
singleproxy["ws-headers"]["Edge"] = x.Edge;
if(!x.Cookie.empty())
singleproxy["ws-headers"]["Cookie"] = x.Cookie;
}
break;
case "http"_hash:
Expand Down
1 change: 1 addition & 0 deletions src/parser/config/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct Proxy
String Host;
String Path;
String Edge;
String Cookie;

String QUICSecure;
String QUICSecret;
Expand Down
29 changes: 16 additions & 13 deletions src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ void commonConstruct(Proxy &node, ProxyType type, const std::string &group, cons
node.TLS13 = tls13;
}

void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, const std::string &sni, tribool udp, tribool tfo, tribool scv, tribool tls13)
void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &cookie, const std::string &tls, const std::string &sni, tribool udp, tribool tfo, tribool scv, tribool tls13)
{
commonConstruct(node, ProxyType::VMess, group, remarks, add, port, udp, tfo, scv, tls13);
node.UserId = id.empty() ? "00000000-0000-0000-0000-000000000000" : id;
node.AlterId = to_int(aid);
node.EncryptMethod = cipher;
node.TransferProtocol = net.empty() ? "tcp" : net;
node.Edge = edge;
node.Cookie = cookie;
node.ServerName = sni;

if(net == "quic")
Expand Down Expand Up @@ -182,7 +183,7 @@ void explodeVmess(std::string vmess, Proxy &node)

add = trim(add);

vmessConstruct(node, V2RAY_DEFAULT_GROUP, ps, add, port, type, id, aid, net, "auto", path, host, "", tls, sni);
vmessConstruct(node, V2RAY_DEFAULT_GROUP, ps, add, port, type, id, aid, net, "auto", path, host, "", "", tls, sni);
}

void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
Expand Down Expand Up @@ -260,7 +261,7 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
}
}
}
vmessConstruct(node, V2RAY_DEFAULT_GROUP, add + ":" + port, add, port, type, id, aid, net, cipher, path, host, edge, tls, "", udp, tfo, scv);
vmessConstruct(node, V2RAY_DEFAULT_GROUP, add + ":" + port, add, port, type, id, aid, net, cipher, path, host, edge, "", tls, "", udp, tfo, scv);
nodes.emplace_back(std::move(node));
}
return;
Expand Down Expand Up @@ -314,7 +315,7 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
json["vmess"][i]["streamSecurity"] >> tls;
json["vmess"][i]["security"] >> cipher;
json["vmess"][i]["sni"] >> sni;
vmessConstruct(node, V2RAY_DEFAULT_GROUP, ps, add, port, type, id, aid, net, cipher, path, host, "", tls, sni, udp, tfo, scv);
vmessConstruct(node, V2RAY_DEFAULT_GROUP, ps, add, port, type, id, aid, net, cipher, path, host, "", "", tls, sni, udp, tfo, scv);
break;
case 3: //ss config
json["vmess"][i]["id"] >> id;
Expand Down Expand Up @@ -831,7 +832,7 @@ void explodeQuan(const std::string &quan, Proxy &node)
if(path.empty())
path = "/";

vmessConstruct(node, group, ps, add, port, type, id, aid, net, cipher, path, host, edge, tls, "");
vmessConstruct(node, group, ps, add, port, type, id, aid, net, cipher, path, host, edge, "", tls, "");
}
}

Expand Down Expand Up @@ -901,7 +902,7 @@ void explodeNetch(std::string netch, Proxy &node)
sni = GetMember(json, "ServerName");
if(group.empty())
group = V2RAY_DEFAULT_GROUP;
vmessConstruct(node, group, remark, address, port, faketype, id, aid, transprot, method, path, host, edge, tls, sni, udp, tfo, scv);
vmessConstruct(node, group, remark, address, port, faketype, id, aid, transprot, method, path, host, edge, "", tls, sni, udp, tfo, scv);
break;
case "Socks5"_hash:
username = GetMember(json, "Username");
Expand Down Expand Up @@ -940,7 +941,7 @@ void explodeNetch(std::string netch, Proxy &node)
void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
{
std::string proxytype, ps, server, port, cipher, group, password; //common
std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, tls, sni; //vmess
std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, cookie, tls, sni; //vmess
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss
std::string protocol, protoparam, obfs, obfsparam; //ssr
std::string user; //socks
Expand Down Expand Up @@ -983,12 +984,14 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
path = singleproxy["ws-opts"]["path"].IsDefined() ? safe_as<std::string>(singleproxy["ws-opts"]["path"]) : "/";
singleproxy["ws-opts"]["headers"]["Host"] >>= host;
singleproxy["ws-opts"]["headers"]["Edge"] >>= edge;
singleproxy["ws-opts"]["headers"]["Cookie"] >>= cookie;
}
else
{
path = singleproxy["ws-path"].IsDefined() ? safe_as<std::string>(singleproxy["ws-path"]) : "/";
singleproxy["ws-headers"]["Host"] >>= host;
singleproxy["ws-headers"]["Edge"] >>= edge;
singleproxy["ws-headers"]["Cookie"] >>= cookie;
}
break;
case "h2"_hash:
Expand All @@ -1004,7 +1007,7 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
}
tls = safe_as<std::string>(singleproxy["tls"]) == "true" ? "tls" : "";

vmessConstruct(node, group, ps, server, port, "", id, aid, net, cipher, path, host, edge, tls, sni, udp, tfo, scv);
vmessConstruct(node, group, ps, server, port, "", id, aid, net, cipher, path, host, edge, cookie, tls, sni, udp, tfo, scv);
break;
case "ss"_hash:
group = SS_DEFAULT_GROUP;
Expand Down Expand Up @@ -1193,7 +1196,7 @@ void explodeStdVMess(std::string vmess, Proxy &node)
if(remarks.empty())
remarks = add + ":" + port;

vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, "auto", path, host, "", tls, "");
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, "auto", path, host, "", "", tls, "");
return;
}

Expand Down Expand Up @@ -1238,7 +1241,7 @@ void explodeShadowrocket(std::string rocket, Proxy &node)
if(remarks.empty())
remarks = add + ":" + port;

vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, cipher, path, host, "", tls, "");
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, cipher, path, host, "", "", tls, "");
}

void explodeKitsunebi(std::string kit, Proxy &node)
Expand Down Expand Up @@ -1276,7 +1279,7 @@ void explodeKitsunebi(std::string kit, Proxy &node)
if(remarks.empty())
remarks = add + ":" + port;

vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, cipher, path, host, "", tls, "");
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, cipher, path, host, "", "", tls, "");
}

bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
Expand Down Expand Up @@ -1540,7 +1543,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
}
}

vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, edge, tls, "", udp, tfo, scv, tls13);
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, edge, "", tls, "", udp, tfo, scv, tls13);
break;
case "http"_hash: //http proxy
server = trim(configs[1]);
Expand Down Expand Up @@ -1821,7 +1824,7 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
if(remarks.empty())
remarks = server + ":" + port;

vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, "", tls, "", udp, tfo, scv, tls13);
vmessConstruct(node, V2RAY_DEFAULT_GROUP, remarks, server, port, "", id, aead, net, method, path, host, "", "", tls, "", udp, tfo, scv, tls13);
break;
case "trojan"_hash: //quantumult x style trojan link
server = trim(configs[0].substr(0, configs[0].rfind(":")));
Expand Down
2 changes: 1 addition & 1 deletion src/parser/subparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum class ConfType
Local
};

void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, const std::string &sni, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &cookie, const std::string &tls, const std::string &sni, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void ssrConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &protocol, const std::string &method, const std::string &obfs, const std::string &password, const std::string &obfsparam, const std::string &protoparam, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool());
void ssConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &password, const std::string &method, const std::string &plugin, const std::string &pluginopts, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void socksConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &username, const std::string &password, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool());
Expand Down