|
@@ -5,8 +5,11 @@
|
|
|
#include "FileOperate.h"
|
|
|
|
|
|
|
|
|
-CLashConfig::CLashConfig() : m_socks_port(9200), m_http_port(9300), m_c_port(9090), m_process(nullptr), m_Asyntask(1), m_is_qut(false), m_log(nullptr)
|
|
|
+CLashConfig::CLashConfig() : m_socks_port(9200), m_http_port(9300), m_c_port(9090), m_process(nullptr), m_Asyntask(1), m_AsyntaskProcessMonitor(1), m_is_qut(false), m_log(nullptr)
|
|
|
{
|
|
|
+
|
|
|
+ _hEvent = nullptr;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
CLashConfig::~CLashConfig(void)
|
|
@@ -25,7 +28,120 @@ CLashConfig::~CLashConfig(void)
|
|
|
|
|
|
BOOL CLashConfig::MakeClash()
|
|
|
{
|
|
|
- return 0;
|
|
|
+ buildRules();
|
|
|
+ YAML::Node root;
|
|
|
+ root["port"] = m_http_port;
|
|
|
+ root["socks-port"] = m_socks_port;
|
|
|
+ root["allow-lan"] = true;
|
|
|
+ root["external-controller"] = "127.0.0.1:" + std::to_string(m_c_port);
|
|
|
+ if (CApp::getSingletonPtr()->GetRouteMode() == ROUT_MODE::cn_mode)
|
|
|
+ {
|
|
|
+ root["mode"] = "rule";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ root["mode"] = "rule";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#ifdef _DEBUG
|
|
|
+ root["log-level"] = "debug";
|
|
|
+#else
|
|
|
+ root["log-level"] = "info";
|
|
|
+#endif
|
|
|
+
|
|
|
+ root["dns"] = buildDnsConfig();
|
|
|
+
|
|
|
+ if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode)
|
|
|
+ {
|
|
|
+ root["tun"] = builTunConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ YAML::Node proxies;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ root["proxies"] = proxies;
|
|
|
+ root["proxy-groups"] = buildProxyGroups();
|
|
|
+
|
|
|
+ YAML::Node reject;
|
|
|
+ YAML::Node google;
|
|
|
+ YAML::Node gfw;
|
|
|
+ YAML::Node proxy;
|
|
|
+ YAML::Node cncidr;
|
|
|
+
|
|
|
+
|
|
|
+ reject["type"] = "http";
|
|
|
+ reject["behavior"] = "domain";
|
|
|
+ reject["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt";
|
|
|
+ reject["path"] = "./ruleset/reject.yaml";
|
|
|
+ reject["interval"] = 86400;
|
|
|
+
|
|
|
+ google["type"] = "http";
|
|
|
+ google["behavior"] = "domain";
|
|
|
+ google["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt";
|
|
|
+ google["path"] = "./ruleset/google.yaml";
|
|
|
+ google["interval"] = 86400;
|
|
|
+
|
|
|
+
|
|
|
+ gfw["type"] = "http";
|
|
|
+ gfw["behavior"] = "domain";
|
|
|
+ gfw["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt";
|
|
|
+ gfw["path"] = "./ruleset/gfw.yaml";
|
|
|
+ gfw["interval"] = 86400;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ proxy["type"] = "http";
|
|
|
+ proxy["behavior"] = "domain";
|
|
|
+ proxy["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt";
|
|
|
+ proxy["path"] = "./ruleset/proxy.yaml";
|
|
|
+ proxy["interval"] = 86400;
|
|
|
+
|
|
|
+
|
|
|
+ cncidr["type"] = "http";
|
|
|
+ cncidr["behavior"] = "domain";
|
|
|
+ cncidr["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt";
|
|
|
+ cncidr["path"] = "./ruleset/cncidr.yaml";
|
|
|
+ cncidr["interval"] = 86400;
|
|
|
+
|
|
|
+ if (CApp::getSingletonPtr()->GetRouteMode() == ROUT_MODE::cn_mode)
|
|
|
+ {
|
|
|
+ root["rule-providers"]["reject"] = reject;
|
|
|
+ root["rule-providers"]["cncidr"] = cncidr;
|
|
|
+ root["rule-providers"]["proxy"] = proxy;
|
|
|
+ root["rule-providers"]["gfw"] = gfw;
|
|
|
+ root["rule-providers"]["google"] = google;
|
|
|
+ }
|
|
|
+
|
|
|
+ root["rules"] = m_rules;
|
|
|
+ auto name_file = "config.yaml";
|
|
|
+
|
|
|
+ if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode) {
|
|
|
+ name_file = "tun_config.yaml";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
}
|
|
|
|
|
|
BOOL CLashConfig::InitClash()
|
|
@@ -34,22 +150,22 @@ BOOL CLashConfig::InitClash()
|
|
|
{
|
|
|
m_process = new CProcess();
|
|
|
}
|
|
|
-
|
|
|
+ std::string logfile = std::filesystem::current_path().string() + "\\log\\log.log";
|
|
|
+ if (m_log == nullptr)
|
|
|
+ {
|
|
|
+ m_log = new Logger(Logger::file_and_terminal, Logger::info, logfile);
|
|
|
+ }
|
|
|
m_http_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9300,9500);
|
|
|
m_socks_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9600,9800);
|
|
|
m_c_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9900);
|
|
|
|
|
|
-
|
|
|
+ ;
|
|
|
|
|
|
|
|
|
|
|
|
auto name_file = dir + "\\" + CLASHCONFIINIT;
|
|
|
|
|
|
- std::string logfile = path + "\\config\\log.log";
|
|
|
- if (m_log == nullptr)
|
|
|
- {
|
|
|
- m_log = new Logger(Logger::file_and_terminal, Logger::info, logfile);
|
|
|
- }*/
|
|
|
+ */
|
|
|
|
|
|
auto name_file = DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
|
|
|
@@ -83,7 +199,8 @@ BOOL CLashConfig::InitClash()
|
|
|
|
|
|
BOOL CLashConfig::StartClash()
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+ THROW_LAST_ERROR_IF_NULL(hEvent);*/
|
|
|
|
|
|
|
|
|
|
|
@@ -93,19 +210,24 @@ BOOL CLashConfig::StartClash()
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
auto assetsDir = std::filesystem::current_path() / CLASH_ASSETS_DIR_NAME;
|
|
|
auto confg_path = CApp::getSingletonPtr()->GetConfigPath() / DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
|
CProcessManager::getSingletonPtr()->SetArgs(assetsDir / DSPROXY_EXE_NAME, assetsDir, std::move(confg_path));
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if (CProcessManager::getSingletonPtr()->Start())
|
|
|
{
|
|
|
CApp::getSingletonPtr()->SetCLashRuning(true);
|
|
|
- }
|
|
|
+ m_AsyntaskProcessMonitor.AddTask(&CLashConfig::ThreadFun_ProcessMonitor_Config, this, (LPARAM)CProcessManager::getSingletonPtr());
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
{
|
|
|
m_process->Create(CProcess::ASYNC);
|
|
@@ -122,7 +244,8 @@ BOOL CLashConfig::StartClash()
|
|
|
BOOL CLashConfig::StopClash()
|
|
|
{
|
|
|
m_is_qut = true;
|
|
|
- CProcessManager::getSingletonPtr()->Stop();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -147,72 +270,231 @@ YAML::Node CLashConfig::buildv2ray()
|
|
|
|
|
|
std::vector<YAML::Node> CLashConfig::buildv2rayHost()
|
|
|
{
|
|
|
- return std::vector<YAML::Node>();
|
|
|
+ std::vector<YAML::Node> p;
|
|
|
+
|
|
|
+ YAML::Node t_map;
|
|
|
+ t_map["host"] = node->v2_host;
|
|
|
+ p.push_back(t_map);
|
|
|
+ }*/
|
|
|
+ return p;
|
|
|
}
|
|
|
|
|
|
YAML::Node CLashConfig::builTunConfig()
|
|
|
{
|
|
|
- return YAML::Node();
|
|
|
+ std::vector<std::string> dns;
|
|
|
+ dns.push_back("198.18.0.2:53");
|
|
|
+ YAML::Node node;
|
|
|
+ node["enable"] = true;
|
|
|
+ node["stack"] = "gvisor";
|
|
|
+ node["dns-hijack"] = dns;
|
|
|
+ node["auto-route"] = true;
|
|
|
+ node["auto-detect-interface"] = true;
|
|
|
+ return node;
|
|
|
}
|
|
|
|
|
|
YAML::Node CLashConfig::buildDnsConfig()
|
|
|
{
|
|
|
- return YAML::Node();
|
|
|
+ YAML::Node dns;
|
|
|
+
|
|
|
+ std::vector<std::string> dns_arr;
|
|
|
+ dns_arr.push_back("114.114.114.114");
|
|
|
+ dns_arr.push_back("8.8.8.8");
|
|
|
+ dns_arr.push_back("tls://dns.rubyfish.cn:853");
|
|
|
+ dns_arr.push_back("https://1.1.1.1/dns-query");
|
|
|
+ dns["enable"] = true;
|
|
|
+ if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode)
|
|
|
+ {
|
|
|
+
|
|
|
+ dns["enhanced-mode"] = "redir-host";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ dns["nameserver"] = dns_arr;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return dns;
|
|
|
}
|
|
|
|
|
|
std::vector<YAML::Node> CLashConfig::buildProxyGroups()
|
|
|
{
|
|
|
- return std::vector<YAML::Node>();
|
|
|
+ std::vector<YAML::Node> dns_arr;
|
|
|
+ std::vector<std::string> proxy;
|
|
|
+ YAML::Node proxies;
|
|
|
+
|
|
|
+ {
|
|
|
+ proxy.push_back(node.name.c_str());
|
|
|
+
|
|
|
+ }*/
|
|
|
+ YAML::Node li;
|
|
|
+ li["name"] = "Proxy";
|
|
|
+ li["type"] = "select";
|
|
|
+ li["proxies"] = proxy;
|
|
|
+ dns_arr.push_back(li);
|
|
|
+
|
|
|
+ return dns_arr;
|
|
|
}
|
|
|
|
|
|
std::vector<YAML::Node> CLashConfig::buildRules()
|
|
|
{
|
|
|
- return std::vector<YAML::Node>();
|
|
|
-}
|
|
|
+ std::vector<YAML::Node> p;
|
|
|
|
|
|
-void CLashConfig::ThreadFun_process_Config(LPARAM lParam)
|
|
|
-{
|
|
|
+ m_rules.clear();
|
|
|
|
|
|
- if (CProcessManager::getSingletonPtr()->Start())
|
|
|
+ if (CApp::getSingletonPtr()->GetRouteMode() == ROUT_MODE::cn_mode)
|
|
|
{
|
|
|
- CApp::getSingletonPtr()->SetCLashRuning(true);
|
|
|
+ m_rules.push_back("RULE-SET,proxy,Proxy");
|
|
|
+ m_rules.push_back("RULE-SET,google,Proxy");
|
|
|
+ m_rules.push_back("RULE-SET,gfw,Proxy");
|
|
|
+ m_rules.push_back("RULE-SET,cncidr,DIRECT");
|
|
|
+
|
|
|
+ m_rules.push_back("GEOIP,CN,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,127.0.0.0/8,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,172.16.0.0/12,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,192.168.0.0/16,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,10.0.0.0/8,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,100.64.0.0/10,DIRECT");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ m_rules.push_back("GEOIP,CN,Proxy");
|
|
|
+ m_rules.push_back("IP-CIDR,127.0.0.0/8,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,172.16.0.0/12,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,192.168.0.0/16,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,10.0.0.0/8,DIRECT");
|
|
|
+ m_rules.push_back("IP-CIDR,100.64.0.0/10,DIRECT");
|
|
|
+ }
|
|
|
|
|
|
- HANDLE hClashProcess = CProcessManager::getSingletonPtr()->GetClashProcessInfo().hProcess;
|
|
|
+ m_rules.push_back("MATCH,Proxy");
|
|
|
|
|
|
- for (size_t i = 0; i < 5; ++i) {
|
|
|
+ return p;
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
+std::vector<YAML::Node> CLashConfig::buildruleproviders()
|
|
|
+{
|
|
|
+ std::vector<YAML::Node> pp;
|
|
|
+ YAML::Node node;
|
|
|
+ YAML::Node reject;
|
|
|
+ YAML::Node google;
|
|
|
+ YAML::Node gfw;
|
|
|
+ YAML::Node proxy;
|
|
|
+ YAML::Node cncidr;
|
|
|
+ reject["type"] = "http";
|
|
|
+ reject["behavior"] = "domain";
|
|
|
+ reject["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt";
|
|
|
+ reject["path"] = "./ruleset/reject.yaml";
|
|
|
+ reject["interval"] = 86400;
|
|
|
+ node["reject"] = reject;
|
|
|
+ pp.push_back(node);
|
|
|
+
|
|
|
+ google["type"] = "http";
|
|
|
+ google["behavior"] = "domain";
|
|
|
+ google["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt";
|
|
|
+ google["path"] = "./ruleset/google.yaml";
|
|
|
+ google["interval"] = 86400;
|
|
|
+ node["google"] = google;
|
|
|
+ pp.push_back(node);
|
|
|
+
|
|
|
+
|
|
|
+ gfw["type"] = "http";
|
|
|
+ gfw["behavior"] = "domain";
|
|
|
+ gfw["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt";
|
|
|
+ gfw["path"] = "./ruleset/gfw.yaml";
|
|
|
+ gfw["interval"] = 86400;
|
|
|
+ node["gfw"] = gfw;
|
|
|
+ pp.push_back(node);
|
|
|
+
|
|
|
+
|
|
|
+ proxy["type"] = "http";
|
|
|
+ proxy["behavior"] = "domain";
|
|
|
+ proxy["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt";
|
|
|
+ proxy["path"] = "./ruleset/proxy.yaml";
|
|
|
+ proxy["interval"] = 86400;
|
|
|
+ node["proxy"] = proxy;
|
|
|
+ pp.push_back(node);
|
|
|
+
|
|
|
+ cncidr["type"] = "http";
|
|
|
+ cncidr["behavior"] = "domain";
|
|
|
+ cncidr["url"] = "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt";
|
|
|
+ cncidr["path"] = "./ruleset/cncidr.yaml";
|
|
|
+ cncidr["interval"] = 86400;
|
|
|
+ node["cncidr"] = proxy;
|
|
|
+ pp.push_back(node);
|
|
|
+
|
|
|
+
|
|
|
+ return pp;
|
|
|
+}
|
|
|
+
|
|
|
+void CLashConfig::ThreadFun_process_Config(LPARAM lParam)
|
|
|
+{
|
|
|
+
|
|
|
+ CProcessManager* p = (CProcessManager*)lParam;
|
|
|
+
|
|
|
+ if (p->Start())
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ WaitForSingleObject(_hEvent.get(),INFINITE);
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+void CLashConfig::ThreadFun_ProcessMonitor_Config(LPARAM lParam)
|
|
|
+{
|
|
|
+ CProcessManager* p = (CProcessManager*)lParam;
|
|
|
+ if (p)
|
|
|
+ {
|
|
|
+ HANDLE hClashProcess = nullptr;
|
|
|
+ HANDLE hSubProcess = nullptr;
|
|
|
+
|
|
|
+ do
|
|
|
+ {
|
|
|
+ if (p->IsRunning() != State::Running)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (hClashProcess = p->GetClashProcessInfo().hProcess);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|