forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nekobox_core linux: use sing-box for vpn
- Loading branch information
Showing
87 changed files
with
3,433 additions
and
1,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#include "db/ProxyEntity.hpp" | ||
#include "fmt/includes.h" | ||
|
||
namespace NekoRay::fmt { | ||
void V2rayStreamSettings::BuildStreamSettingsSingBox(QJsonObject *outbound) { | ||
// https://sing-box.sagernet.org/configuration/shared/v2ray-transport | ||
|
||
if (network != "tcp") { | ||
QJsonObject transport{ | ||
{"type", network.replace("h2", "http")}, | ||
}; | ||
if (network == "ws") { | ||
if (!path.isEmpty()) transport["path"] = path; | ||
if (!host.isEmpty()) transport["headers"] = QJsonObject{{"Host", host}}; | ||
if (ws_early_data_length > 0) { | ||
transport["max_early_data"] = ws_early_data_length; | ||
transport["early_data_header_name"] = ws_early_data_name; | ||
} | ||
} else if (network == "http") { | ||
if (!path.isEmpty()) transport["path"] = path; | ||
if (!host.isEmpty()) transport["host"] = QList2QJsonArray(host.split(",")); | ||
} else if (network == "grpc") { | ||
if (!path.isEmpty()) transport["service_name"] = path; | ||
} | ||
outbound->insert("transport", transport); | ||
} | ||
|
||
// 对应字段 tls | ||
if (security == "tls") { | ||
QJsonObject tls{{"enabled", true}}; | ||
if (allow_insecure || dataStore->skip_cert) tls["insecure"] = true; | ||
if (!sni.trimmed().isEmpty()) tls["server_name"] = sni; | ||
if (!certificate.trimmed().isEmpty()) { | ||
tls["certificate"] = certificate.trimmed(); | ||
} | ||
if (!alpn.trimmed().isEmpty()) { | ||
tls["alpn"] = QList2QJsonArray(alpn.split(",")); | ||
} | ||
outbound->insert("tls", tls); | ||
} | ||
|
||
if (!packet_encoding.isEmpty()) { | ||
outbound->insert("packet_encoding", packet_encoding); | ||
} | ||
} | ||
|
||
CoreObjOutboundBuildResult SocksHttpBean::BuildCoreObjSingBox() { | ||
CoreObjOutboundBuildResult result; | ||
|
||
QJsonObject outbound; | ||
outbound["type"] = socks_http_type == type_HTTP ? "http" : "socks"; | ||
outbound["server"] = serverAddress; | ||
outbound["server_port"] = serverPort; | ||
|
||
QJsonArray users; | ||
QJsonObject user; | ||
user["username"] = username; | ||
user["password"] = password; | ||
users.push_back(user); | ||
if (!username.isEmpty() && !password.isEmpty()) outbound["users"] = users; | ||
|
||
stream->BuildStreamSettingsSingBox(&outbound); | ||
result.outbound = outbound; | ||
return result; | ||
} | ||
|
||
CoreObjOutboundBuildResult ShadowSocksBean::BuildCoreObjSingBox() { | ||
CoreObjOutboundBuildResult result; | ||
|
||
QJsonObject outbound{{"type", "shadowsocks"}}; | ||
outbound["server"] = serverAddress; | ||
outbound["server_port"] = serverPort; | ||
outbound["method"] = method; | ||
outbound["password"] = password; | ||
|
||
if (!plugin.trimmed().isEmpty()) { | ||
outbound["plugin"] = SubStrBefore(plugin, ";"); | ||
outbound["plugin_opts"] = SubStrAfter(plugin, ";"); | ||
} | ||
|
||
stream->BuildStreamSettingsSingBox(&outbound); | ||
result.outbound = outbound; | ||
return result; | ||
} | ||
|
||
CoreObjOutboundBuildResult VMessBean::BuildCoreObjSingBox() { | ||
CoreObjOutboundBuildResult result; | ||
QJsonObject outbound{ | ||
{"type", "vmess"}, | ||
{"server", serverAddress}, | ||
{"server_port", serverPort}, | ||
{"uuid", uuid}, | ||
{"alter_id", aid}, | ||
{"security", security}, | ||
}; | ||
|
||
stream->BuildStreamSettingsSingBox(&outbound); | ||
result.outbound = outbound; | ||
return result; | ||
} | ||
|
||
CoreObjOutboundBuildResult TrojanVLESSBean::BuildCoreObjSingBox() { | ||
CoreObjOutboundBuildResult result; | ||
QJsonObject outbound{ | ||
{"type", proxy_type == proxy_VLESS ? "vless" : "trojan"}, | ||
{"server", serverAddress}, | ||
{"server_port", serverPort}, | ||
}; | ||
|
||
QJsonObject settings; | ||
if (proxy_type == proxy_VLESS) { | ||
outbound["uuid"] = password; | ||
} else { | ||
outbound["password"] = password; | ||
} | ||
|
||
stream->BuildStreamSettingsSingBox(&outbound); | ||
result.outbound = outbound; | ||
return result; | ||
} | ||
|
||
CoreObjOutboundBuildResult CustomBean::BuildCoreObjSingBox() { | ||
CoreObjOutboundBuildResult result; | ||
|
||
if (core == "hysteria") { | ||
QJsonObject outbound{{"type", "hysteria"}}; | ||
outbound["server"] = serverAddress; | ||
outbound["server_port"] = serverPort; | ||
auto hy = QString2QJsonObject(config_simple); | ||
QJSONOBJECT_COPY(hy, outbound, "up") | ||
QJSONOBJECT_COPY(hy, outbound, "down") | ||
QJSONOBJECT_COPY(hy, outbound, "up_mbps") | ||
QJSONOBJECT_COPY(hy, outbound, "down_mbps") | ||
QJSONOBJECT_COPY(hy, outbound, "obfs") | ||
QJSONOBJECT_COPY(hy, outbound, "auth") | ||
QJSONOBJECT_COPY(hy, outbound, "auth_str") | ||
QJSONOBJECT_COPY(hy, outbound, "recv_window_conn") | ||
QJSONOBJECT_COPY(hy, outbound, "recv_window_client") | ||
QJSONOBJECT_COPY(hy, outbound, "disable_mtu_discovery") | ||
QJsonObject tls{{"enabled", true}}; | ||
QJSONOBJECT_COPY(hy, tls, "server_name") | ||
QJSONOBJECT_COPY(hy, tls, "alpn") | ||
QJSONOBJECT_COPY(hy, tls, "insecure") | ||
QJSONOBJECT_COPY2(hy, tls, "ca", "certificate_path") | ||
outbound["tls"] = tls; | ||
result.outbound = outbound; | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.