diff --git a/CMakeLists.txt b/CMakeLists.txt index d9397a9ee..f3866057d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,6 +221,16 @@ set(PROJECT_SOURCES include/sys/windows/eventHandler.h src/dataStore/Group.cpp src/dataStore/ProxyEntity.cpp + include/configs/baseConfig.h + include/configs/common/DialFields.h + include/configs/common/TLS.h + include/configs/common/multiplex.h + include/configs/common/transport.h + include/configs/common/Outbound.h + include/configs/outbounds/socks.h + include/configs/outbounds/http.h + include/configs/outbounds/shadowsocks.h + include/configs/outbounds/vmess.h ) if (NOT APPLE AND Qt6_VERSION VERSION_GREATER_EQUAL 6.9.0) diff --git a/include/configs/baseConfig.h b/include/configs/baseConfig.h new file mode 100644 index 000000000..e563921a5 --- /dev/null +++ b/include/configs/baseConfig.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include "include/global/ConfigItem.hpp" + +namespace Configs +{ + class baseConfig : public JsonStore + { + public: + virtual bool ParseFromLink(QString link); + + virtual bool ParseFromJson(QJsonObject object); + + virtual QString ExportToLink(); + + virtual QJsonObject ExportToJson(); + + virtual QJsonObject Build(); + }; +} diff --git a/include/configs/common/DialFields.h b/include/configs/common/DialFields.h new file mode 100644 index 000000000..e85cec05e --- /dev/null +++ b/include/configs/common/DialFields.h @@ -0,0 +1,24 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs +{ + class DialFields : baseConfig + { + public: + bool reuse_addr = false; + QString connect_timeout; + bool tcp_fast_open = false; + bool tcp_multi_path = false; + bool udp_fragment = false; + + DialFields() + { + _add(new configItem("reuse_addr", &reuse_addr, itemType::boolean)); + _add(new configItem("connect_timeout", &connect_timeout, itemType::string)); + _add(new configItem("tcp_fast_open", &tcp_fast_open, itemType::boolean)); + _add(new configItem("tcp_multi_path", &tcp_multi_path, itemType::boolean)); + _add(new configItem("udp_fragment", &udp_fragment, itemType::boolean)); + } + }; +} diff --git a/include/configs/common/Outbound.h b/include/configs/common/Outbound.h new file mode 100644 index 000000000..2bea1ffa3 --- /dev/null +++ b/include/configs/common/Outbound.h @@ -0,0 +1,24 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs +{ + class OutboundCommons : public baseConfig + { + public: + QString type; + QString name; + int id = -1; + QString server; + int server_port = 0; + + OutboundCommons() + { + _add(new configItem("type", &type, string)); + _add(new configItem("name", &name, string)); + _add(new configItem("id", &id, integer)); + _add(new configItem("server", &server, string)); + _add(new configItem("server_port", &server_port, integer)); + } + }; +} diff --git a/include/configs/common/TLS.h b/include/configs/common/TLS.h new file mode 100644 index 000000000..bcdd5e0ae --- /dev/null +++ b/include/configs/common/TLS.h @@ -0,0 +1,104 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs +{ + + inline QStringList tlsFingerprints = {"", "chrome", "firefox", "edge", "safari", "360", "qq", "ios", "android", "random", "randomized"}; + + class uTLS : public baseConfig + { + public: + bool enabled = false; + QString fingerPrint; + + uTLS() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("fingerprint", &fingerPrint, string)); + } + }; + + class ECH : public baseConfig + { + public: + bool enabled = false; + QStringList config; + QString config_path; + + ECH() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("config", &config, stringList)); + _add(new configItem("config_path", &config_path, string)); + } + }; + + class Reality : public baseConfig + { + public: + bool enabled = false; + QString public_key; + QString short_id; + + Reality() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("public_key", &public_key, string)); + _add(new configItem("short_id", &short_id, string)); + } + }; + + class TLS : public baseConfig + { + public: + bool enabled = false; + bool disable_sni = false; + QString server_name; + bool insecure = false; + QStringList alpn; + QString min_version; + QString max_version; + QStringList cipher_suites; + QStringList curve_preferences; + QString certificate; + QString certificate_path; + QStringList certificate_public_key_sha256; + QString client_certificate; + QString client_certificate_path; + QStringList client_key; + QString client_key_path; + bool fragment = false; + QString fragment_fallback_delay; + bool record_fragment = false; + std::shared_ptr ech = std::make_shared(); + std::shared_ptr utls = std::make_shared(); + std::shared_ptr reality = std::make_shared(); + + TLS() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("disable_sni", &disable_sni, boolean)); + _add(new configItem("server_name", &server_name, string)); + _add(new configItem("insecure", &insecure, boolean)); + _add(new configItem("alpn", &alpn, stringList)); + _add(new configItem("min_version", &min_version, string)); + _add(new configItem("max_version", &max_version, string)); + _add(new configItem("cipher_suites", &cipher_suites, stringList)); + _add(new configItem("curve_preferences", &curve_preferences, stringList)); + _add(new configItem("certificate", &certificate, string)); + _add(new configItem("certificate_path", &certificate_path, string)); + _add(new configItem("certificate_public_key_sha256", &certificate_public_key_sha256, stringList)); + _add(new configItem("client_certificate", &client_certificate, string)); + _add(new configItem("client_certificate_path", &client_certificate_path, string)); + _add(new configItem("client_key", &client_key, stringList)); + _add(new configItem("client_key_path", &client_key_path, string)); + _add(new configItem("fragment", &fragment, boolean)); + _add(new configItem("fragment_fallback_delay", &fragment_fallback_delay, string)); + _add(new configItem("record_fragment", &record_fragment, boolean)); + _add(new configItem("ech", dynamic_cast(ech.get()), jsonStore)); + _add(new configItem("utls", dynamic_cast(utls.get()), jsonStore)); + _add(new configItem("reality", dynamic_cast(reality.get()), jsonStore)); + } + }; +} diff --git a/include/configs/common/multiplex.h b/include/configs/common/multiplex.h new file mode 100644 index 000000000..917908132 --- /dev/null +++ b/include/configs/common/multiplex.h @@ -0,0 +1,45 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs +{ + inline QStringLists muxProtocols = {"smux", "yamux", "h2mux"}; + + class TcpBrutal : public baseConfig + { + public: + bool enabled = false; + int up_mbps = 0; + int down_mbps = 0; + + TcpBrutal() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("up_mbps", &up_mbps, integer)); + _add(new configItem("down_mbps", &down_mbps, integer)); + } + }; + + class Multiplex : public baseConfig + { + public: + bool enabled = false; + QString protocol; + int max_connections = 0; + int min_streams = 0; + int max_streams = 0; + bool padding = false; + std::shared_ptr brutal = std::make_shared(); + + Multiplex() + { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("protocol", &protocol, string)); + _add(new configItem("max_connections", &max_connections, integer)); + _add(new configItem("min_streams", &min_streams, integer)); + _add(new configItem("max_streams", &max_streams, integer)); + _add(new configItem("padding", &padding, boolean)); + _add(new configItem("brutal", dynamic_cast(brutal.get()), jsonStore)); + } + }; +} diff --git a/include/configs/common/transport.h b/include/configs/common/transport.h new file mode 100644 index 000000000..b26b67626 --- /dev/null +++ b/include/configs/common/transport.h @@ -0,0 +1,40 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs +{ + class Transport : public baseConfig + { + public: + QString type; + + // HTTP + QString host; + QString path; + QString method; + QStringList headers; + QString idle_timeout; + QString ping_timeout; + + // Websocket + int max_early_data = 0; + QString early_data_header_name; + + // gRPC + QString service_name; + + Transport() + { + _add(new configItem("type", &type, string)); + _add(new configItem("host", &host, string)); + _add(new configItem("path", &path, string)); + _add(new configItem("method", &method, string)); + _add(new configItem("headers", &headers, stringList)); + _add(new configItem("idle_timeout", &idle_timeout, string)); + _add(new configItem("ping_timeout", &ping_timeout, string)); + _add(new configItem("max_early_data", &max_early_data, integer)); + _add(new configItem("early_data_header_name", &early_data_header_name, string)); + _add(new configItem("service_name", &service_name, string)); + } + }; +} diff --git a/include/configs/outbounds/http.h b/include/configs/outbounds/http.h new file mode 100644 index 000000000..c004917ad --- /dev/null +++ b/include/configs/outbounds/http.h @@ -0,0 +1,28 @@ +#pragma once +#include "include/configs/baseConfig.h" +#include "include/configs/common/Outbound.h" +#include "include/configs/common/TLS.h" + +namespace Configs +{ + class http : public baseConfig + { + public: + std::shared_ptr commons = std::make_shared(); + QString username; + QString password; + QString path; + QStringList headers; + std::shared_ptr tls = std::make_shared(); + + http() + { + _add(new configItem("commons", dynamic_cast(commons.get()), jsonStore)); + _add(new configItem("username", &username, string)); + _add(new configItem("password", &password, string)); + _add(new configItem("path", &path, string)); + _add(new configItem("headers", &headers, stringList)); + _add(new configItem("tls", dynamic_cast(tls.get()), jsonStore)); + } + }; +} diff --git a/include/configs/outbounds/shadowsocks.h b/include/configs/outbounds/shadowsocks.h new file mode 100644 index 000000000..9103dc896 --- /dev/null +++ b/include/configs/outbounds/shadowsocks.h @@ -0,0 +1,35 @@ +#pragma once +#include + +#include "include/configs/baseConfig.h" +#include "include/configs/common/multiplex.h" +#include "include/configs/common/Outbound.h" + +namespace Configs +{ + + inline QStringList shadowsocksMethods = {"2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "none", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "rc4-md5", "chacha20-ietf", "xchacha20"}; + + class shadowsocks : public baseConfig + { + public: + std::shared_ptr commons = std::make_shared(); + QString method; + QString password; + QString plugin; + QString plugin_opts; + bool uot = false; + std::shared_ptr mux = std::make_shared(); + + shadowsocks() + { + _add(new configItem("commons", dynamic_cast(commons.get()), jsonStore)); + _add(new configItem("method", &method, string)); + _add(new configItem("password", &password, string)); + _add(new configItem("plugin", &plugin, string)); + _add(new configItem("plugin_opts", &plugin_opts, string)); + _add(new configItem("uot", &uot, itemType::boolean)); + _add(new configItem("mux", dynamic_cast(mux.get()), jsonStore)); + } + }; +} diff --git a/include/configs/outbounds/socks.h b/include/configs/outbounds/socks.h new file mode 100644 index 000000000..85d248e1a --- /dev/null +++ b/include/configs/outbounds/socks.h @@ -0,0 +1,23 @@ +#pragma once +#include "include/configs/baseConfig.h" +#include "include/configs/common/Outbound.h" + +namespace Configs +{ + class socks : public baseConfig + { + public: + std::shared_ptr commons = std::make_shared(); + QString username; + QString password; + bool uot = false; + + socks() + { + _add(new configItem("commons", dynamic_cast(commons.get()), jsonStore)); + _add(new configItem("username", &username, string)); + _add(new configItem("password", &password, string)); + _add(new configItem("uot", &uot, boolean)); + } + }; +} diff --git a/include/configs/outbounds/vmess.h b/include/configs/outbounds/vmess.h new file mode 100644 index 000000000..6d4a33624 --- /dev/null +++ b/include/configs/outbounds/vmess.h @@ -0,0 +1,42 @@ +#pragma once +#include "include/configs/baseConfig.h" +#include "include/configs/common/multiplex.h" +#include "include/configs/common/Outbound.h" +#include "include/configs/common/TLS.h" +#include "include/configs/common/transport.h" + +namespace Configs +{ + + inline QStringList vmessSecurity = {"auto", "none", "zero", "aes-128-gcm", "chacha20-poly1305"}; + inline QStringList vPacketEncoding = {"", "packetaddr", "xudp"}; + + class vmess : public baseConfig + { + public: + std::shared_ptr commons = std::make_shared(); + QString uuid; + QString security = "auto"; + int alter_id = 0; + bool global_padding = false; + bool authenticated_length = false; + std::shared_ptr tls = std::make_shared(); + QString packet_encoding; + std::shared_ptr transport = std::make_shared(); + std::shared_ptr mux = std::make_shared(); + + vmess() + { + _add(new configItem("commons", dynamic_cast(commons.get()), jsonStore)); + _add(new configItem("uuid", &uuid, string)); + _add(new configItem("security", &security, string)); + _add(new configItem("alter-id", &alter_id, integer)); + _add(new configItem("global-padding", &global_padding, boolean)); + _add(new configItem("authenticated_length", &authenticated_length, boolean)); + _add(new configItem("tls", dynamic_cast(tls.get()), jsonStore)); + _add(new configItem("packet_encoding", &packet_encoding, string)); + _add(new configItem("transport", dynamic_cast(transport.get()), jsonStore)); + _add(new configItem("mux", dynamic_cast(mux.get()), jsonStore)); + } + }; +} diff --git a/res/translations/zh_CN.ts b/res/translations/zh_CN.ts index ef4ec7d4b..2705508dc 100644 --- a/res/translations/zh_CN.ts +++ b/res/translations/zh_CN.ts @@ -176,7 +176,7 @@ <html><head/><body><p>Settings for the sing-box's built-in NTP client</p></body></html> - <html><head/><body><p>用于 sing-box 的内置 NTP 客户端的设置</p></body></html> + <html><head/><body><p>适用于 sing-box 的内置 NTP 客户端的设置</p></body></html> @@ -287,7 +287,7 @@ Only Country - + 仅国别 @@ -846,35 +846,35 @@ For more information, see the document "Configuration/DNS". GitHub - + jsDelivr(Cloudflare) - + jsDelivr(Gcore) - + jsDelivr(Quantil) - + jsDelivr(Fastly) - + jsDelivr(CDN) - + <html><head/><body><p>Local DNS can not be used in some configurations, you will have to set an ip here to be used as local dns in such situations</p></body></html> - + <html><head/><body><p>在某些配置中无法使用本地 DNS,在这种情况下您必须在这里设置一个IP 作为本地 DNS 使用</p></body></html> Local Override - + 本地覆盖 @@ -1254,11 +1254,11 @@ https://matsuridayo.github.io/n-configuration/#vpn-tun Form - 表单 + 表单 Ephemeral - + Ephemeral (短暂) @@ -2257,15 +2257,15 @@ Release note: Local DNS and Tun mode do not work together, please set an IP to be used as the Local DNS server in the Routing Settings -> Local override - + 本地 NDS 和 Tun 模式不能同时使用,请在「路由设置 → 本地覆盖」中设置一个 IP 用作本地 DNS 服务器 Core exited, cleaning up... - + 核心已退出,正在清理... Restarting the core ... - + 正在重新启动核心...