|
@@ -3,12 +3,12 @@
|
|
#include "CApp.h"
|
|
#include "CApp.h"
|
|
#include "comm.h"
|
|
#include "comm.h"
|
|
#include "FileOperate.h"
|
|
#include "FileOperate.h"
|
|
|
|
+#include "SysProxy.h"
|
|
|
|
|
|
-
|
|
|
|
-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)
|
|
|
|
|
|
+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)
|
|
{
|
|
{
|
|
SNotifyCenter::getSingleton().addEvent(EVENTID(EventClashPreOceeQut));
|
|
SNotifyCenter::getSingleton().addEvent(EVENTID(EventClashPreOceeQut));
|
|
- _hEvent = nullptr;
|
|
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -19,11 +19,7 @@ CLashConfig::~CLashConfig(void)
|
|
delete m_process;
|
|
delete m_process;
|
|
m_process = nullptr;
|
|
m_process = nullptr;
|
|
}
|
|
}
|
|
- if (m_log)
|
|
|
|
- {
|
|
|
|
- delete m_log;
|
|
|
|
- m_log = nullptr;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
BOOL CLashConfig::MakeClash()
|
|
BOOL CLashConfig::MakeClash()
|
|
@@ -61,18 +57,18 @@ BOOL CLashConfig::MakeClash()
|
|
|
|
|
|
//CList_node::getSingletonPtr()->listnode;
|
|
//CList_node::getSingletonPtr()->listnode;
|
|
YAML::Node proxies;
|
|
YAML::Node proxies;
|
|
- //for each (LISTNODE node in CList_node::getSingletonPtr()->listnode)
|
|
|
|
- //{
|
|
|
|
- // if (node.type == "shadowsocks") {
|
|
|
|
- // proxies.push_back(buildShadowsocks(&node));
|
|
|
|
- // }
|
|
|
|
- // else if (node.type == "trojan") {
|
|
|
|
- // proxies.push_back(buildtrojan(&node));
|
|
|
|
- // }
|
|
|
|
- // else if (node.type == "v2ray") {
|
|
|
|
- // proxies.push_back(buildv2ray(&node));
|
|
|
|
- // }
|
|
|
|
- //}
|
|
|
|
|
|
+ for each (auto node in CApp::getSingletonPtr()->GetServerList()->vectlistmode)
|
|
|
|
+ {
|
|
|
|
+ if (node.type == "shadowsocks") {
|
|
|
|
+ proxies.push_back(buildShadowsocks(&node));
|
|
|
|
+ }
|
|
|
|
+ else if (node.type == "trojan") {
|
|
|
|
+ proxies.push_back(buildtrojan(&node));
|
|
|
|
+ }
|
|
|
|
+ else if (node.type == "v2ray") {
|
|
|
|
+ proxies.push_back(buildv2ray(&node));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
root["proxies"] = proxies;
|
|
root["proxies"] = proxies;
|
|
@@ -130,16 +126,25 @@ BOOL CLashConfig::MakeClash()
|
|
}
|
|
}
|
|
|
|
|
|
root["rules"] = m_rules;
|
|
root["rules"] = m_rules;
|
|
- auto name_file = "config.yaml";
|
|
|
|
|
|
+ auto name_file = DSPROXY_CONFIG_ClASH_NAME;
|
|
|
|
|
|
if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode) {
|
|
if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode) {
|
|
- name_file = "tun_config.yaml";
|
|
|
|
|
|
+ name_file = DSPROXY_CONFIG_TUN_ClASH_NAME;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ m_run_config = CApp::getSingletonPtr()->GetConfigPath() / name_file;
|
|
|
|
+ std::ofstream ofstream(CApp::getSingletonPtr()->GetConfigPath() / name_file);
|
|
|
|
+ ofstream << root;
|
|
|
|
+ ofstream.close();
|
|
|
|
+ }
|
|
|
|
+ catch (const std::exception& e) {
|
|
|
|
+ LOG_CAUGHT_EXCEPTION();
|
|
|
|
+ return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
- //std::ofstream ofstream(path + "\\config\\" + name_file);
|
|
|
|
- //// ÉèÖÃÅäÖÃÎļþnodeÊý
|
|
|
|
- //ofstream << root << std::endl;
|
|
|
|
- //ofstream.close();
|
|
|
|
|
|
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
@@ -150,23 +155,12 @@ BOOL CLashConfig::InitClash()
|
|
{
|
|
{
|
|
m_process = new CProcess();
|
|
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_http_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9300,9500);
|
|
m_socks_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9600,9800);
|
|
m_socks_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9600,9800);
|
|
m_c_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9900);
|
|
m_c_port = CTool::getSingletonPtr()->FindAvailableTcpPort(9900);
|
|
|
|
|
|
- ;
|
|
|
|
-
|
|
|
|
- /*std::string dir = CLASHCONFIGDIR;
|
|
|
|
-
|
|
|
|
- auto name_file = dir + "\\" + CLASHCONFIINIT;
|
|
|
|
-
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
auto name_file = DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
auto name_file = DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
|
|
|
|
if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode) {
|
|
if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::tun_mode) {
|
|
@@ -182,14 +176,16 @@ BOOL CLashConfig::InitClash()
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- auto config_path = CApp::getSingletonPtr()->GetConfigPath().wstring() + L"\\" + name_file;
|
|
|
|
- std::ofstream ofstream(config_path);
|
|
|
|
|
|
+
|
|
|
|
+ std::ofstream ofstream(CApp::getSingletonPtr()->GetConfigPath() / name_file);
|
|
ofstream << root << std::endl;
|
|
ofstream << root << std::endl;
|
|
ofstream.close();
|
|
ofstream.close();
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
- catch (const std::exception&)
|
|
|
|
|
|
+ catch (const std::exception& e)
|
|
{
|
|
{
|
|
|
|
+ Logger::getSingletonPtr()->INFO(e.what());
|
|
|
|
+ LOG_CAUGHT_EXCEPTION();
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -199,20 +195,6 @@ BOOL CLashConfig::InitClash()
|
|
|
|
|
|
BOOL CLashConfig::StartClash()
|
|
BOOL CLashConfig::StartClash()
|
|
{
|
|
{
|
|
- /*wil::unique_handle hEvent(CreateEventW(nullptr, FALSE, FALSE, nullptr));
|
|
|
|
- THROW_LAST_ERROR_IF_NULL(hEvent);*/
|
|
|
|
- //std::wstring config = path + L"\\" + WCLASHCONFIGDIR;
|
|
|
|
- ////args.push_back("-d");
|
|
|
|
- //////args.push_back(std::filesystem::current_path().string() + "\\route");
|
|
|
|
- ////args.push_back(path + "\\config");
|
|
|
|
- ////args.push_back("-f");
|
|
|
|
- ////args.push_back(path + "\\config\\configinit.yaml");
|
|
|
|
- //std::wstring run_config = config + L"\\" + S_CA2W(CLASHCONFIINIT).GetBuffer(0);
|
|
|
|
- //SStringW path_config;
|
|
|
|
- //path_config.Format(L"%s\\%s -d %s -f %s", config.c_str(),CLASHEXE,config.c_str(), run_config.c_str());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
auto assetsDir = std::filesystem::current_path() / CLASH_ASSETS_DIR_NAME;
|
|
auto assetsDir = std::filesystem::current_path() / CLASH_ASSETS_DIR_NAME;
|
|
auto confg_path = CApp::getSingletonPtr()->GetConfigPath() / DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
auto confg_path = CApp::getSingletonPtr()->GetConfigPath() / DSPROXY_CONFIG_INIT_ClASH_NAME;
|
|
CProcessManager::getSingletonPtr()->SetArgs(assetsDir / DSPROXY_EXE_NAME, assetsDir, std::move(confg_path));
|
|
CProcessManager::getSingletonPtr()->SetArgs(assetsDir / DSPROXY_EXE_NAME, assetsDir, std::move(confg_path));
|
|
@@ -251,29 +233,112 @@ BOOL CLashConfig::StopClash()
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-YAML::Node CLashConfig::buildShadowsocks()
|
|
|
|
|
|
+int CLashConfig::GetHttpPort()
|
|
{
|
|
{
|
|
- return YAML::Node();
|
|
|
|
|
|
+ return m_http_port;
|
|
}
|
|
}
|
|
|
|
|
|
-YAML::Node CLashConfig::buildtrojan()
|
|
|
|
|
|
+int CLashConfig::GetSocketPort()
|
|
{
|
|
{
|
|
|
|
+ return m_socks_port;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int CLashConfig::GetClasApiPort()
|
|
|
|
+{
|
|
|
|
+ return m_c_port;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::filesystem::path CLashConfig::GetRunConfig()
|
|
|
|
+{
|
|
|
|
+ return m_run_config;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+YAML::Node CLashConfig::buildShadowsocks(CServerListMode* node)
|
|
|
|
+{
|
|
|
|
+ YAML::Node t_map;
|
|
|
|
+
|
|
|
|
+ if (!node)
|
|
|
|
+ {
|
|
|
|
+ return t_map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ t_map["name"] = node->name;
|
|
|
|
+ t_map["type"] = std::string("ss");
|
|
|
|
+ t_map["server"] = node->host;
|
|
|
|
+ t_map["port"] = std::to_string(node->port);
|
|
|
|
+ t_map["cipher"] = node->method;
|
|
|
|
+ t_map["password"] = node->passwd;
|
|
|
|
+ t_map["udp"] = true;
|
|
|
|
+
|
|
|
|
+ return t_map;
|
|
|
|
+
|
|
return YAML::Node();
|
|
return YAML::Node();
|
|
}
|
|
}
|
|
|
|
|
|
-YAML::Node CLashConfig::buildv2ray()
|
|
|
|
|
|
+YAML::Node CLashConfig::buildtrojan(CServerListMode* node)
|
|
{
|
|
{
|
|
|
|
+ YAML::Node t_map;
|
|
|
|
+
|
|
|
|
+ if (!node)
|
|
|
|
+ {
|
|
|
|
+ return t_map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ t_map["name"] = node->name;
|
|
|
|
+ t_map["type"] = std::string("trojan");
|
|
|
|
+ t_map["server"] = node->host;
|
|
|
|
+ t_map["port"] = std::to_string(node->port);
|
|
|
|
+ t_map["password"] = node->passwd;
|
|
|
|
+ if (!node->sni.empty()) {
|
|
|
|
+ t_map["sni"] = node->sni;
|
|
|
|
+ }
|
|
|
|
+ t_map["udp"] = true;
|
|
|
|
+
|
|
|
|
+ return t_map;
|
|
return YAML::Node();
|
|
return YAML::Node();
|
|
}
|
|
}
|
|
|
|
|
|
-std::vector<YAML::Node> CLashConfig::buildv2rayHost()
|
|
|
|
|
|
+YAML::Node CLashConfig::buildv2ray(CServerListMode* node)
|
|
{
|
|
{
|
|
|
|
+ YAML::Node t_map;
|
|
|
|
+ if (!node)
|
|
|
|
+ {
|
|
|
|
+ return t_map;
|
|
|
|
+ }
|
|
|
|
+
|
|
std::vector<YAML::Node> p;
|
|
std::vector<YAML::Node> p;
|
|
- /*if (node) {
|
|
|
|
|
|
+ t_map["name"] = node->name;
|
|
|
|
+ t_map["type"] = std::string("vmess");
|
|
|
|
+ t_map["server"] = node->host;
|
|
|
|
+ t_map["port"] = std::to_string(node->port);
|
|
|
|
+ t_map["uuid"] = node->uuid;
|
|
|
|
+ t_map["cipher"] = node->method;
|
|
|
|
+ t_map["alterId"] = node->v2_alter_id;
|
|
|
|
+ t_map["udp"] = node->udp;
|
|
|
|
+
|
|
|
|
+ if (node->v2_tls == "tls") {
|
|
|
|
+ t_map["tls"] = node->v2_tls;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (node->v2_net == "tcp") {
|
|
|
|
+ t_map["network"] = node->v2_net;
|
|
|
|
+ }
|
|
|
|
+ else if (node->v2_net == "ws") {
|
|
|
|
+ t_map["network"] = node->v2_net;
|
|
|
|
+ t_map["ws-path"] = node->v2_path;
|
|
|
|
+ t_map["ws-headers"] = buildv2rayHost(node);
|
|
|
|
+ }
|
|
|
|
+ return t_map;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::vector<YAML::Node> CLashConfig::buildv2rayHost(CServerListMode* node)
|
|
|
|
+{
|
|
|
|
+ std::vector<YAML::Node> p;
|
|
|
|
+ if (node) {
|
|
YAML::Node t_map;
|
|
YAML::Node t_map;
|
|
t_map["host"] = node->v2_host;
|
|
t_map["host"] = node->v2_host;
|
|
p.push_back(t_map);
|
|
p.push_back(t_map);
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
return p;
|
|
return p;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -321,11 +386,10 @@ std::vector<YAML::Node> CLashConfig::buildProxyGroups()
|
|
std::vector<YAML::Node> dns_arr;
|
|
std::vector<YAML::Node> dns_arr;
|
|
std::vector<std::string> proxy;
|
|
std::vector<std::string> proxy;
|
|
YAML::Node proxies;
|
|
YAML::Node proxies;
|
|
- /*for each (LISTNODE node in CList_node::getSingletonPtr()->listnode)
|
|
|
|
|
|
+ for each (auto node in CApp::getSingletonPtr()->GetServerList()->vectlistmode)
|
|
{
|
|
{
|
|
proxy.push_back(node.name.c_str());
|
|
proxy.push_back(node.name.c_str());
|
|
-
|
|
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
YAML::Node li;
|
|
YAML::Node li;
|
|
li["name"] = "Proxy";
|
|
li["name"] = "Proxy";
|
|
li["type"] = "select";
|
|
li["type"] = "select";
|
|
@@ -431,16 +495,7 @@ std::vector<YAML::Node> CLashConfig::buildruleproviders()
|
|
|
|
|
|
void CLashConfig::ThreadFun_process_Config(LPARAM lParam)
|
|
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)
|
|
void CLashConfig::ThreadFun_ProcessMonitor_Config(LPARAM lParam)
|
|
@@ -496,6 +551,15 @@ void CLashConfig::ThreadFun_ProcessMonitor_Config(LPARAM lParam)
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void CLashConfig::SetProxy()
|
|
|
|
+{
|
|
|
|
+ if (CApp::getSingletonPtr()->GetSysMode() == PROXY_MODE::sys_mode)
|
|
|
|
+ {
|
|
|
|
+ auto proxy = "127.0.0.1:" + std::to_string(m_http_port);
|
|
|
|
+ SetSystemProxy(S_CA2W(proxy.c_str()), NULL, L"localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;172.32.*;192.168.*");
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
//winrt::fire_and_forget CLashConfig::_StartClash()
|
|
//winrt::fire_and_forget CLashConfig::_StartClash()
|
|
//{
|
|
//{
|
|
// if (CProcessManager::getSingletonPtr()->Start())
|
|
// if (CProcessManager::getSingletonPtr()->Start())
|