diff --git a/README.en.md b/README.en.md index 2acd5d0650354e172cda410ae77be4bcd8abcc45..8b1a79528892a9601e059de390ee15df226d44f4 100644 --- a/README.en.md +++ b/README.en.md @@ -13,7 +13,7 @@ This software is a standard proxy server that supports Socks5 and HTTP tunnel pr this software support following features 1. SOCKS5 proxy 2. Tunnel proxy -3. support Permission Validation(planning) +3. support Permission Validation 4. operator log 5. encrypt Communication(planning) 6. load balanc(planning) @@ -23,7 +23,7 @@ this software support following features #### Requirements support system above windows 7sp1 and linux(ubuntu20.04,centos8) -XEngine need V7.23 or above +XEngine need V7.27 or above vcpkg need 2021.05.11 or above #### Windows diff --git a/README.md b/README.md index 99c1bc73e3c6fa138e9d207302dafcec2587cf78..4e4545816111e20322fba136ef94335f6af0ad64 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service 此软件支持以下特性 1. SOCKS5代理 2. Tunnel代理 -3. 权限验证(planning) +3. 权限验证 4. 操作日志 5. 加密通信(planning) 6. 负载均衡(planning) @@ -23,7 +23,7 @@ c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service #### 版本需求 支持WINDOWS 7SP1和LINUX(UBUNT20.04,CENTOS8)以上系统 -XEngine版本需要V7.26或者以上版本 +XEngine版本需要V7.27或者以上版本 vcpkg 需要2021.05.11以上版本 #### Windows diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp index 802580ec0902785f8b5c85787d58a95d4ab3c48c..c77b0a57f02377023b6af328e1925316aa307f02 100644 --- a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp @@ -62,9 +62,8 @@ int main(int argc, char** argv) ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH enServerAuth; ProxyProtocol_SocksClient_AuthParse(tszMsgBuffer, &enServerAuth); printf("接受服务器返回数据,内容:%d\n", enServerAuth); - //////////////////////////////////////////////////////////////////////////登录 匿名登录不需要 - /* - ProxyProtocol_SocksClient_LoginPacket(tszMsgBuffer, &nMsgLen); + //////////////////////////////////////////////////////////////////////////登录 匿名登录注释下面的代码 + ProxyProtocol_SocksClient_LoginPacket(tszMsgBuffer, &nMsgLen, "123123aa", "123123"); if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) { printf("发送投递失败!\n"); @@ -85,7 +84,7 @@ int main(int argc, char** argv) else { printf("login failed\n"); - }*/ + } //////////////////////////////////////////////////////////////////////////连接 ProxyProtocol_SocksClient_ConnectPacket(tszMsgBuffer, &nMsgLen, "www.xyry.org", 80, ENUM_RFCCOMPONENTS_PROXYSOCKS_COMMAND_CONNECT, ENUM_RFCCOMPONENTS_PROXYSOCKS_IPADDR_DOMAIN); if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp index 1ad7b34ed95f320185b3480dba89dd8ced5eae11..9584d4b9fb22fb605ae5a2586bb101ed641b32bb 100644 --- a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) WSAStartup(MAKEWORD(2, 2), &st_WSAData); #endif SOCKET m_Socket; - LPCTSTR lpszServiceAddr = _T("192.168.1.12"); + LPCTSTR lpszServiceAddr = _T("127.0.0.1"); if (!XClient_TCPSelect_Create(&m_Socket, lpszServiceAddr, 5401)) { printf("连接失败!错误:%lX\n", XClient_GetLastError()); @@ -41,7 +41,7 @@ int main(int argc, char** argv) TCHAR tszMsgBuffer[2048]; memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); - ProxyProtocol_TunnelClient_Packet(tszMsgBuffer, &nMsgLen, "www.xyry.org:80"); + ProxyProtocol_TunnelClient_Packet(tszMsgBuffer, &nMsgLen, "www.xyry.org:80", "MTIzMTIzYWE6MTIzMTIz"); if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) { printf("发送投递失败!\n"); diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx new file mode 100644 index 0000000000000000000000000000000000000000..9057e20ccdf617387f5c849e8b2fc4840a8d9910 Binary files /dev/null and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx new file mode 100644 index 0000000000000000000000000000000000000000..172dc1ac01f57ed89026119852df0b9b3bcdb905 Binary files /dev/null and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/UserList.txt b/XEngine_Release/XEngine_Config/UserList.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc05bbb93ea00858cc22c4cbb1803f44cadce2c5 --- /dev/null +++ b/XEngine_Release/XEngine_Config/UserList.txt @@ -0,0 +1,2 @@ +123123aa 123123 +aaadddaa 123123 \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index e327e5b29e2026e21aefe93f730571cf64423790..ac11f937de68f236490faf8e7f5b3ea80e1a30f5 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -6,19 +6,25 @@ "XMax":{ "nMaxClient":10000, "nMaxQueue":10000, - "nIOThread":2 + "nIOThread":1 }, "XTime":{ "nTimeCheck":3, - "nSocksTimeOut":5, - "nTunnelTimeOut":5 + "nSocksTimeOut":0, + "nTunnelTimeOut":0 }, "XLog":{ "MaxSize":1024000, "MaxCount":10, - "LogLeave":32 + "LogLeave":32, + "tszLogFile":"./XEngine_Log/XEngine_ServiceApp.log" }, - "XSocks":{ - "nAuthType":0 - } + "XAuth":{ + "bAuth":0, + "tszAuthFile":"./XEngine_Config/UserList.txt" + }, + "XVer":[ + "1.1.0.1001 Build20211231", + "1.0.0.1001 Build20211211" + ] } \ No newline at end of file diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index 1f2ecd63c3974ba621c2b38c0c1be0edc515909f..310220a5e9eec2e1d900b7cf6f61bf92b482b55b 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -4,15 +4,18 @@ UNICODE = 0 FLAGS = RELEASE=$(RELEASE) #要编译的模块 MODULE_CONFIGURE_PATH = ./XEngine_ModuleConfigure +MODULE_AUTHORIZE_PATH = ./XEngine_ModuleAuthorize APP_SERVICE_PATH = ./XEngine_ServiceApp -XENGINE_MODULES = libXEngine_ModuleConfigure.so XEngine_ServiceApp.exe +XENGINE_MODULES = libXEngine_ModuleConfigure.so libXEngine_ModuleAuthorize.so XEngine_ServiceApp.exe .PHONY:MakeAll MakeAll:$(XENGINE_MODULES) libXEngine_ModuleConfigure.so: make -C $(MODULE_CONFIGURE_PATH) $(FLAGS) +libXEngine_ModuleAuthorize.so: + make -C $(MODULE_AUTHORIZE_PATH) $(FLAGS) XEngine_ServiceApp.exe: make -C $(APP_SERVICE_PATH) $(FLAGS) diff --git a/XEngine_Source/VSCopy-Debug.bat b/XEngine_Source/VSCopy-Debug.bat index 7ed9466b63c5a6265cd9a22f82e290ad2ce20523..9187c7c2f22b3daecbe3bc9b1a1784d6e076b055 100644 --- a/XEngine_Source/VSCopy-Debug.bat +++ b/XEngine_Source/VSCopy-Debug.bat @@ -1,6 +1,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_BaseLib.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_Algorithm.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_Core.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_OPenSsl.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_ManagePool.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_NetXApi.dll" "./" diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy-x86.bat index 91b52bbb0b2527c7142600cd56424c296960871d..2465b0d306900fea097373c03fa2aaaed7c0d5d9 100644 --- a/XEngine_Source/VSCopy-x86.bat +++ b/XEngine_Source/VSCopy-x86.bat @@ -1,6 +1,7 @@ copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_BaseLib.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_Algorithm.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_Core.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_OPenSsl.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_ManagePool.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_NetXApi.dll" "./" diff --git a/XEngine_Source/XEngine.sln b/XEngine_Source/XEngine.sln index 8d39a11235d82e4cb452ef197431cdf6bd6b4abc..fce9a93262f81059ac4a2f44061294057179169b 100644 --- a/XEngine_Source/XEngine.sln +++ b/XEngine_Source/XEngine.sln @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XEngine_UserHdr", "XEngine_ XEngine_UserProtocol.h = XEngine_UserProtocol.h EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ModuleAuthorize", "XEngine_ModuleAuthorize\XEngine_ModuleAuthorize.vcxproj", "{58026DC2-5383-490C-9BB4-BF3152192F0C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -36,6 +38,14 @@ Global {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x64.Build.0 = Release|x64 {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x86.ActiveCfg = Release|Win32 {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x86.Build.0 = Release|Win32 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Debug|x64.ActiveCfg = Debug|x64 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Debug|x64.Build.0 = Debug|x64 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Debug|x86.ActiveCfg = Debug|Win32 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Debug|x86.Build.0 = Debug|Win32 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Release|x64.ActiveCfg = Release|x64 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Release|x64.Build.0 = Release|x64 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Release|x86.ActiveCfg = Release|Win32 + {58026DC2-5383-490C-9BB4-BF3152192F0C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Source/XEngine_ModuleAuthorize/Makefile b/XEngine_Source/XEngine_ModuleAuthorize/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a00f37f1c25ffa69fd4f382fca14f96302e265b7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/Makefile @@ -0,0 +1,45 @@ +CC = g++ -Wall -std=c++17 -fPIC +RELEASE = 0 +UNICODE = 0 +INCLUDE = -I ./ +LOADBIN = +LIB = -ljsoncpp +LIBEX = -static-libgcc -lrt -ldl -lpthread +LOADSO = -Wl,-rpath= +LIBINCLUDE = ModuleAuthorize_User.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c -O2 +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + + +all:$(LIBINCLUDE) + $(CC) $(DEBUG) $(LIBINCLUDE) -o libXEngine_ModuleAuthorize.so -shared -fPIC $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) + +ModuleAuthorize_User.o:./ModuleAuthorize_User/ModuleAuthorize_User.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./ModuleAuthorize_User/ModuleAuthorize_User.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libXEngine_ModuleAuthorize.so + cp ./libXEngine_ModuleAuthorize.so ../../XEngine_Release/libXEngine_ModuleAuthorize.so + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.so diff --git a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Define.h b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Define.h new file mode 100644 index 0000000000000000000000000000000000000000..156fa80aee4624108f318b0fdee5319b283408f9 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Define.h @@ -0,0 +1,61 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/29 10:30:04 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuth_Define.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize +// File Base: ModuleAuth_Define +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleAuthorize_GetLastError(int* pInt_SysError = NULL); +/************************************************************************/ +/* ֤ */ +/************************************************************************/ +/******************************************************************** +ƣModuleAuthorize_User_Init +ܣʼȨỰ + .һlpszAuthFile + In/OutIn + ַָͣ + ɿգN + ˼Ȩļַ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +extern "C" BOOL ModuleAuthorize_User_Init(LPCTSTR lpszAuthFile); +/************************************************************************ +ƣModuleAuthorize_User_Destory +ܣȨ +ֵ + ͣ߼ + ˼Ƿٳɹ +ע +************************************************************************/ +extern "C" BOOL ModuleAuthorize_User_Destory(); +/******************************************************************** +ƣModuleAuthorize_User_Exist +ܣǷ֤ͨ + .һlpszUser + In/OutIn + ַָͣ + ɿգN + ˼û + .lpszPass + In/OutIn + ַָͣ + ɿգN + ˼ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +extern "C" BOOL ModuleAuthorize_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h new file mode 100644 index 0000000000000000000000000000000000000000..dbcf052875e3e56be05c1c7decb024fd643bed9a --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h @@ -0,0 +1,16 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/29 10:29:54 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuth_Error.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize +// File Base: ModuleAuth_Error +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: +// History: +*********************************************************************/ +#define ERROR_MODULE_AUTHORIZE_USER_PARAMENT 0xA0001 // +#define ERROR_MODULE_AUTHORIZE_USER_OPENFILE 0xA0002 //ļʧ +#define ERROR_MODULE_AUTHORIZE_USER_NOTFOUND 0xA0003 //ûҵ +#define ERROR_MODULE_AUTHORIZE_USER_PASSWORD 0xA0004 // \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.cpp b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a562eea4cb25d9c9dcb65440bb4a83ff8c33f0a1 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.cpp @@ -0,0 +1,140 @@ +#include "pch.h" +#include "ModuleAuthorize_User.h" +/******************************************************************** +// Created: 2021/12/29 10:24:25 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuthorize_User\ModuleAuthorize_User.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuthorize_User +// File Base: ModuleAuthorize_User +// File Ext: cpp +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: û֤ +// History: +*********************************************************************/ +CModuleAuthorize_User::CModuleAuthorize_User() +{ + +} +CModuleAuthorize_User::~CModuleAuthorize_User() +{ + +} +////////////////////////////////////////////////////////////////////////// +// ú +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣModuleAuthorize_User_Init +ܣʼȨỰ + .һlpszAuthFile + In/OutIn + ַָͣ + ɿգN + ˼Ȩļַ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CModuleAuthorize_User::ModuleAuthorize_User_Init(LPCTSTR lpszAuthFile) +{ + Authorize_IsErrorOccur = FALSE; + + FILE* pSt_File = _tfopen(lpszAuthFile, _T("rb")); + if (NULL == pSt_File) + { + Authorize_IsErrorOccur = TRUE; + Authorize_dwErrorCode = ERROR_MODULE_AUTHORIZE_USER_OPENFILE; + return FALSE; + } + int nCount = 0; + TCHAR tszMsgBuffer[4096]; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + while (TRUE) + { + int nRet = fread(tszMsgBuffer + nCount, 1, 1024, pSt_File); + if (nRet <= 0) + { + break; + } + nCount += nRet; + } + fclose(pSt_File); + + LPCTSTR lpszLineStr = _T("\r\n"); + TCHAR* ptszTokStr = _tcstok(tszMsgBuffer, lpszLineStr); + while (1) + { + if (NULL == ptszTokStr) + { + break; + } + XENGINE_USERAUTH st_UserInfo; + memset(&st_UserInfo, '\0', sizeof(XENGINE_USERAUTH)); + + _stscanf(ptszTokStr, _T("%s %s"), st_UserInfo.tszUserName, st_UserInfo.tszUserPass); + stl_MapSession.insert(make_pair(st_UserInfo.tszUserName, st_UserInfo)); + + ptszTokStr = _tcstok(NULL, lpszLineStr); + } + return TRUE; +} +/************************************************************************ +ƣModuleAuthorize_User_Destory +ܣȨ +ֵ + ͣ߼ + ˼Ƿٳɹ +ע +************************************************************************/ +BOOL CModuleAuthorize_User::ModuleAuthorize_User_Destory() +{ + Authorize_IsErrorOccur = FALSE; + + stl_MapSession.clear(); + return TRUE; +} +/******************************************************************** +ƣModuleAuthorize_User_Exist +ܣǷ֤ͨ + .һlpszUser + In/OutIn + ַָͣ + ɿգN + ˼û + .lpszPass + In/OutIn + ַָͣ + ɿգN + ˼ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CModuleAuthorize_User::ModuleAuthorize_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass) +{ + Authorize_IsErrorOccur = FALSE; + + unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszUser); + if (stl_MapIterator == stl_MapSession.end()) + { + Authorize_IsErrorOccur = TRUE; + Authorize_dwErrorCode = ERROR_MODULE_AUTHORIZE_USER_NOTFOUND; + return FALSE; + } + + if (_tcslen(lpszPass) != _tcslen(stl_MapIterator->second.tszUserPass)) + { + Authorize_IsErrorOccur = TRUE; + Authorize_dwErrorCode = ERROR_MODULE_AUTHORIZE_USER_PASSWORD; + return FALSE; + } + if (0 != _tcsncmp(lpszPass, stl_MapIterator->second.tszUserPass, _tcslen(lpszPass))) + { + Authorize_IsErrorOccur = TRUE; + Authorize_dwErrorCode = ERROR_MODULE_AUTHORIZE_USER_PASSWORD; + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.h b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.h new file mode 100644 index 0000000000000000000000000000000000000000..50b4e56b11e71d9dbf92dd74469e8c3f14e15e0c --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuthorize_User/ModuleAuthorize_User.h @@ -0,0 +1,31 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/29 10:23:14 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuthorize_User\ModuleAuthorize_User.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuthorize_User +// File Base: ModuleAuthorize_User +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: û֤ +// History: +*********************************************************************/ + +typedef struct +{ + TCHAR tszUserName[64]; + TCHAR tszUserPass[64]; +}XENGINE_USERAUTH, * LPXENGINE_USERAUTH; + +class CModuleAuthorize_User +{ +public: + CModuleAuthorize_User(); + ~CModuleAuthorize_User(); +public: + BOOL ModuleAuthorize_User_Init(LPCTSTR lpszAuthFile); + BOOL ModuleAuthorize_User_Destory(); + BOOL ModuleAuthorize_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass); +private: + unordered_map stl_MapSession; +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.def b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.def new file mode 100644 index 0000000000000000000000000000000000000000..a55b73f98f5ccef190295337daf8f44978b21e90 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.def @@ -0,0 +1,8 @@ +LIBRARY + +EXPORTS + ModuleAuthorize_GetLastError + + ModuleAuthorize_User_Init + ModuleAuthorize_User_Destory + ModuleAuthorize_User_Exist \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..53b7b33faa6129d2c9e20cb5642e2831769a0c60 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj @@ -0,0 +1,187 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {58026dc2-5383-490c-9bb4-bf3152192f0c} + XEngineModuleAuthorize + 10.0 + + + + DynamicLibrary + true + v142 + MultiByte + + + DynamicLibrary + false + v142 + true + MultiByte + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Library);$(LibraryPath) + + + false + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + true + + + false + $(XEngine_Include);$(IncludePath) + + + + Level3 + true + WIN32;_DEBUG;XENGINEMODULEAUTHORIZE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleAuthorize.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;XENGINEMODULEAUTHORIZE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + MultiThreaded + + + Windows + true + true + true + false + XEngine_ModuleAuthorize.def + + + + + Level3 + true + _DEBUG;XENGINEMODULEAUTHORIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleAuthorize.def + + + + + Level3 + true + true + true + NDEBUG;XENGINEMODULEAUTHORIZE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + MultiThreaded + + + Windows + true + true + true + false + XEngine_ModuleAuthorize.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.filters b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..b2af778f814ebf81f7cd01d93afafa47ec456a39 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {81c98be9-e677-45f9-804f-633fa68fd231} + + + {0db39aac-745e-45fc-9ee9-91c0a0d28ccd} + + + + + 头文件 + + + 头文件 + + + 头文件\ModuleAuthorize_User + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件\ModuleAuthorize_User + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.user b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/XEngine_ModuleAuthorize.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/dllmain.cpp b/XEngine_Source/XEngine_ModuleAuthorize/dllmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daed8c8f7ac50ca1466016a0529648d18125a7e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/XEngine_ModuleAuthorize/framework.h b/XEngine_Source/XEngine_ModuleAuthorize/framework.h new file mode 100644 index 0000000000000000000000000000000000000000..80cbbc9b06a9b0141f92ee19eceaed71328caff4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/XEngine_ModuleAuthorize/pch.cpp b/XEngine_Source/XEngine_ModuleAuthorize/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08ac653e60513275798d9b00751fb4e957256704 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/pch.cpp @@ -0,0 +1,43 @@ +#include "pch.h" +#include "ModuleAuthorize_User/ModuleAuthorize_User.h" +/******************************************************************** +// Created: 2021/12/29 10:35:16 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\pch.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +BOOL Authorize_IsErrorOccur = FALSE; +DWORD Authorize_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CModuleAuthorize_User m_User; +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleAuthorize_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return Authorize_dwErrorCode; +} +/************************************************************************/ +/* 验证导出函数 */ +/************************************************************************/ +extern "C" BOOL ModuleAuthorize_User_Init(LPCTSTR lpszAuthFile) +{ + return m_User.ModuleAuthorize_User_Init(lpszAuthFile); +} +extern "C" BOOL ModuleAuthorize_User_Destory() +{ + return m_User.ModuleAuthorize_User_Destory(); +} +extern "C" BOOL ModuleAuthorize_User_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass) +{ + return m_User.ModuleAuthorize_User_Exist(lpszUser, lpszPass); +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleAuthorize/pch.h b/XEngine_Source/XEngine_ModuleAuthorize/pch.h new file mode 100644 index 0000000000000000000000000000000000000000..6f920b9dd259d8833eda7ca0732f1ea06e3b7661 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleAuthorize/pch.h @@ -0,0 +1,44 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _WINDOWS +// 添加要在此处预编译的标头 +#include "framework.h" +#include +#else + +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include "ModuleAuth_Define.h" +#include "ModuleAuth_Error.h" +using namespace std; +#ifdef _UNICODE +typedef std::wstring tstring; +#else +typedef std::string tstring; +#endif +/******************************************************************** +// Created: 2021/12/29 10:27:12 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\pch.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern BOOL Authorize_IsErrorOccur; +extern DWORD Authorize_dwErrorCode; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index e5be8e337a35615f9de3296f6837d33d92cdf247..f9f13b388b9d0d8fa4f81e165103eee80341f389 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -33,14 +33,20 @@ typedef struct tag_XEngine_ServiceConfig }st_XTime; //*ʱ=ʱ struct { + TCHAR tszLogFile[MAX_PATH]; //־· int nMaxSize; //־С int nMaxCount; //־ int nLogLeave; //־ȼ }st_XLog; struct { - int nAuthType; - }st_XSocks; + int bAuth; //Ƿ֤,0 + TCHAR tszAuthFile[MAX_PATH]; //ַ֤ + }st_XAuth; + struct + { + list* pStl_ListVer; + }st_XVer; }XENGINE_SERVICECONFIG; ////////////////////////////////////////////////////////////////////////// // diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h index 60bdb829257f8f4f4433795bee824dd4fb157734..00bf513bedcffea88b4090324cbd41910da6fcad 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h @@ -16,4 +16,5 @@ #define ERROR_MODULE_CONFIGURE_JSON_XMAX 0xA0004 //ȡXMAXʧ #define ERROR_MODULE_CONFIGURE_JSON_XTIME 0xA0005 //ȡXTIMEʧ #define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //ȡXLOGʧ -#define ERROR_MODULE_CONFIGURE_JSON_XSOCK 0xA0007 \ No newline at end of file +#define ERROR_MODULE_CONFIGURE_JSON_XAUTH 0xA0007 //û֤ +#define ERROR_MODULE_CONFIGURE_JSON_XVER 0xA0008 //ûа汾 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index 7c5ba4fadc461499a0c0f80bf1a6a4cbb977f45b..3735aa8ac8888217db651c10bbe6f5a67afebd91 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -108,7 +108,7 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XE pSt_ServerConfig->st_XTime.nSocksTimeOut = st_JsonXTime["nSocksTimeOut"].asInt(); pSt_ServerConfig->st_XTime.nTunnelTimeOut = st_JsonXTime["nTunnelTimeOut"].asInt(); - if (st_JsonRoot["XLog"].empty() || (3 != st_JsonRoot["XLog"].size())) + if (st_JsonRoot["XLog"].empty() || (4 != st_JsonRoot["XLog"].size())) { Config_IsErrorOccur = TRUE; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XLOG; @@ -118,14 +118,29 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XE pSt_ServerConfig->st_XLog.nMaxSize = st_JsonXLog["MaxSize"].asInt(); pSt_ServerConfig->st_XLog.nMaxCount = st_JsonXLog["MaxCount"].asInt(); pSt_ServerConfig->st_XLog.nLogLeave = st_JsonXLog["LogLeave"].asInt(); + _tcscpy(pSt_ServerConfig->st_XLog.tszLogFile, st_JsonXLog["tszLogFile"].asCString()); - if (st_JsonRoot["XSocks"].empty() || (1 != st_JsonRoot["XSocks"].size())) + if (st_JsonRoot["XAuth"].empty() || (2 != st_JsonRoot["XAuth"].size())) { Config_IsErrorOccur = TRUE; - Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XSOCK; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XAUTH; return FALSE; } - Json::Value st_JsonXSocks = st_JsonRoot["XSocks"]; - pSt_ServerConfig->st_XSocks.nAuthType = st_JsonXSocks["nAuthType"].asInt(); + Json::Value st_JsonXAuth = st_JsonRoot["XAuth"]; + pSt_ServerConfig->st_XAuth.bAuth = st_JsonXAuth["bAuth"].asInt(); + _tcscpy(pSt_ServerConfig->st_XAuth.tszAuthFile, st_JsonXAuth["tszAuthFile"].asCString()); + + if (st_JsonRoot["XVer"].empty() || (2 != st_JsonRoot["XVer"].size())) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XVER; + return FALSE; + } + pSt_ServerConfig->st_XVer.pStl_ListVer = new list; + Json::Value st_JsonXVer = st_JsonRoot["XVer"]; + for (unsigned int i = 0; i < st_JsonXVer.size(); i++) + { + pSt_ServerConfig->st_XVer.pStl_ListVer->push_back(st_JsonXVer[i].asCString()); + } return TRUE; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/pch.h b/XEngine_Source/XEngine_ModuleConfigure/pch.h index 5bbbd53ab543de33b930aa28bcffe4d059846f73..e24f672848f073fca3936ef516997318d35a462f 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/pch.h +++ b/XEngine_Source/XEngine_ModuleConfigure/pch.h @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; #include #include diff --git a/XEngine_Source/XEngine_ServiceApp/Makefile b/XEngine_Source/XEngine_ServiceApp/Makefile index de8ea8a76e7452153ff12f40a033c605efad231b..d655e027012c4e8e98e9a929f609ef9c55b1bfbc 100644 --- a/XEngine_Source/XEngine_ServiceApp/Makefile +++ b/XEngine_Source/XEngine_ServiceApp/Makefile @@ -1,8 +1,8 @@ CC = g++ -Wall RELEASE = 0 UNICODE = 0 -LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../XEngine_ModuleConfigure -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_NetXApi -lHelpComponents_XLog -lRfcComponents_ProxyProtocol -lXClient_Socket -lNetHelp_APIHelp -lXEngine_ModuleConfigure +LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../XEngine_ModuleConfigure -L ../XEngine_ModuleAuthorize +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_OPenSsl -lXEngine_ManagePool -lXEngine_NetXApi -lHelpComponents_XLog -lRfcComponents_ProxyProtocol -lXClient_Socket -lNetHelp_APIHelp -lXEngine_ModuleConfigure -lXEngine_ModuleAuthorize LIBEX = -static-libgcc -ldl -lrt -lpthread LOADSO = -Wl,-rpath=./,--disable-new-dtags LIBINCLUDE = XEngine_Configure.o XEngine_Network.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ServiceApp.o diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp index 4a3036663e4a33a48a0e87b2493289a19fb5de66..2b3a81c22e563ee3e03b25737e07c439b9ee8067 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp @@ -39,6 +39,11 @@ BOOL XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS { pSt_Configure->bDeamon = _ttoi(argv[i + 1]); } + else if (0 == _tcscmp("-v", argv[i])) + { + printf("XEngine版本:%s,服务版本;%s", XENGINE_VERSION_STR, st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str()); + return FALSE; + } } return TRUE; diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index 429d4b477ca476c19e285ed6206e5e8bc378d029..c17ddb20065ac8432ee435077a9fbfaa727f5470 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include #ifdef _WINDOWS #include #include @@ -26,6 +28,8 @@ using namespace std; #include #include #include +#include +#include #include #include #include @@ -40,6 +44,8 @@ using namespace std; #include "../XEngine_UserProtocol.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Define.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Error.h" +#include "../XEngine_ModuleAuthorize/ModuleAuth_Define.h" +#include "../XEngine_ModuleAuthorize/ModuleAuth_Error.h" //加载自己的头文件 #include "XEngine_Configure.h" #include "XEngine_Network.h" @@ -79,15 +85,19 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #ifdef _WINDOWS #ifdef _WIN64 #pragma comment(lib,"../x64/Release/XEngine_ModuleConfigure.lib") +#pragma comment(lib,"../x64/Release/XEngine_ModuleAuthorize.lib") #else #ifdef _DEBUG #pragma comment(lib,"../Debug/XEngine_ModuleConfigure.lib") +#pragma comment(lib,"../Debug/XEngine_ModuleAuthorize.lib") #else #pragma comment(lib,"../Release/XEngine_ModuleConfigure.lib") +#pragma comment(lib,"../Release/XEngine_ModuleAuthorize.lib") #endif #endif #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") +#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl.lib") #pragma comment(lib,"XEngine_Core/XEngine_NetXApi.lib") #pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index 3b345ff34734b8b43453d0a3a28e0d8719ae543e..d4af7cae0e336d22446769468c5370f69096feeb 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -124,7 +124,7 @@ BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMs if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) { //发送数据给指定客户端 - if (!NetCore_TCPXCore_SendEx(xhSocksSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) + if (!NetCore_TCPXCore_SendEx(xhSocksSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen, 1, 1)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); return FALSE; @@ -134,7 +134,7 @@ BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMs } else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) { - if (!NetCore_TCPXCore_SendEx(xhTunnelSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) + if (!NetCore_TCPXCore_SendEx(xhTunnelSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen, 1, 1)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); return FALSE; diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp index f47659ad5eb6d7ca9731c31cdadd01731cb3c0d3..a89f16b572da4da13603c065a537d11ba1aeedc7 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -25,6 +25,7 @@ void ServiceApp_Stop(int signo) SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); + ModuleAuthorize_User_Destory(); } #ifdef _WINDOWS WSACleanup(); @@ -68,8 +69,13 @@ int main(int argc, char** argv) WSADATA st_WSAData; WSAStartup(MAKEWORD(2, 2), &st_WSAData); #endif + +#if XENGINE_VERSION_BIT < 7260001001 + printf("版本号过低,无法继续,按任意键退出!\n"); + getchar(); + return 0; +#endif bIsRun = TRUE; - LPCTSTR lpszLogFile = _T("./XEngine_Log/XEngine_MQServiceApp.Log"); HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig; memset(&st_XLogConfig, '\0', sizeof(HELPCOMPONENTS_XLOG_CONFIGURE)); @@ -77,7 +83,7 @@ int main(int argc, char** argv) st_XLogConfig.XLog_MaxBackupFile = 10; st_XLogConfig.XLog_MaxSize = 1024000; - _tcscpy(st_XLogConfig.tszFileName, lpszLogFile); + _tcscpy(st_XLogConfig.tszFileName, st_ServiceConfig.st_XLog.tszLogFile); signal(SIGINT, ServiceApp_Stop); signal(SIGTERM, ServiceApp_Stop); @@ -102,6 +108,20 @@ int main(int argc, char** argv) //设置日志打印级别 HelpComponents_XLog_SetLogPriority(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化日志系统成功")); + + if (st_ServiceConfig.st_XAuth.bAuth >0) + { + if (!ModuleAuthorize_User_Init(st_ServiceConfig.st_XAuth.tszAuthFile)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启用用户验证服务失败,错误:%lX"), ModuleAuthorize_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启用用户验证服务,用户列表地址:%s"), st_ServiceConfig.st_XAuth.tszAuthFile); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,没有启用用户验证服务")); + } //启动Socks服务相关代码 if (st_ServiceConfig.nSocksPort > 0) { @@ -166,7 +186,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Tunnel消息服务没有被启用")); } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中。。。")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中,XEngine版本:%s,服务版本;%s,发行次数:%d。。。"), XENGINE_VERSION_STR, st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str(), st_ServiceConfig.st_XVer.pStl_ListVer->size()); while (bIsRun) { std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -184,6 +204,7 @@ XENGINE_SERVICEAPP_EXIT: SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); + ModuleAuthorize_User_Destory(); } #ifdef _WINDOWS WSACleanup(); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp index de2a87c63ff49d0187eb40216171e3df6358dbd0..8e349d00b5e1f35a27611eb28fb8a656d580605c 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp @@ -48,7 +48,7 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int _tcscat(tszAuthBuffer, tszTmpBuffer); _tcscat(tszAuthBuffer, _T(" ")); //服务器是否支持 - if (st_ServiceConfig.st_XSocks.nAuthType == enListAuths[i]) + if (st_ServiceConfig.st_XAuth.bAuth == enListAuths[i]) { bFoundAuth = TRUE; } @@ -57,18 +57,18 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int { ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_NOAUTH); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,解析验证协议成功,但是验证类型不支持,客户端的支持验证:%s,服务器支持的验证:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XSocks.nAuthType); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,解析验证协议成功,但是验证类型不支持,客户端的支持验证:%s,服务器支持的验证:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XAuth.bAuth); return FALSE; } - ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, st_ServiceConfig.st_XSocks.nAuthType); + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, st_ServiceConfig.st_XAuth.bAuth); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); //如果是匿名,不会有ENUM_RFCCOMPONENTS_PROXY_STATUS_AUTH步骤 - if (ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_ANONYMOUS == st_ServiceConfig.st_XSocks.nAuthType) + if (ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_ANONYMOUS == st_ServiceConfig.st_XAuth.bAuth) { //跳过 ProxyProtocol_SocksCore_SetStatus(lpszClientAddr, ENUM_RFCCOMPONENTS_PROXY_STATUS_USER); } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,解析验证协议成功,支持的验证类型:%s,使用的验证类型:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XSocks.nAuthType); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,解析验证协议成功,支持的验证类型:%s,使用的验证类型:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XAuth.bAuth); } else if (ENUM_RFCCOMPONENTS_PROXY_STATUS_AUTH == enSocksStatus) { @@ -86,16 +86,23 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户登录验证失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); return FALSE; } - if (enProxyAuth != st_ServiceConfig.st_XSocks.nAuthType) + if (enProxyAuth != st_ServiceConfig.st_XAuth.bAuth) { ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_FAILED); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户登录验证失败,客户端发送的验证类型不支持"), lpszClientAddr); return FALSE; } + if (!ModuleAuthorize_User_Exist(tszUserName, tszUserPass)) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_FAILED); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户登录验证失败,用户名:%s,或者密码:%s 不正确"), lpszClientAddr, tszUserPass, tszUserPass); + return FALSE; + } ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_SUCCESS); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,用户登录验证成功,使用的验证类型:%d"), lpszClientAddr, enProxyAuth); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,用户登录验证成功,使用的验证类型:%d,用户名:%s"), lpszClientAddr, enProxyAuth, tszUserName); } else if (ENUM_RFCCOMPONENTS_PROXY_STATUS_USER == enSocksStatus) { @@ -137,7 +144,14 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int APIHelp_Domain_GetInfo(tszClientAddr, &st_APIUrl, &enDomainType); memset(tszClientAddr, '\0', sizeof(tszClientAddr)); - _stprintf(tszClientAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + if (_tcslen(st_APIUrl.tszSubDomain) > 0) + { + _stprintf(tszClientAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + } + else + { + _stprintf(tszClientAddr, _T("%s"), st_APIUrl.tszMainDomain); + } if (!NetXApi_Socket_DomainToAddr(tszClientAddr, &ppszListAddr, &nListCount)) { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index 56fff2e2d269a0f280918a2ff91bcc40031a91c0..ee948a8f0c7f40a9374d14b910117ae2cc3e9b03 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -38,6 +38,28 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in } TCHAR tszConnectAddr[128]; memset(tszConnectAddr, '\0', sizeof(tszConnectAddr)); + if (st_ServiceConfig.st_XAuth.bAuth > 0) + { + TCHAR tszUser[128]; + TCHAR tszPass[128]; + + memset(tszUser, '\0', sizeof(tszUser)); + memset(tszPass, '\0', sizeof(tszPass)); + if (!OPenSsl_Help_BasicDecoder(tszAuthInfo, tszUser, tszPass)) + { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 401); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,失败无法继续,错误:%lX"), lpszClientAddr, OPenSsl_GetLastError()); + return FALSE; + } + if (!ModuleAuthorize_User_Exist(tszUser, tszPass)) + { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 401); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,验证用户名:%s,密码:%s 失败,错误:%lX"), lpszClientAddr, tszUser, tszPass); + return FALSE; + } + } //是否为IP地址 if (BaseLib_OperatorIPAddr_IsIPV4Addr(tszIPAddr)) { @@ -54,13 +76,20 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in APIHelp_Domain_GetInfo(tszIPAddr, &st_APIUrl, &enDomainType); memset(tszIPAddr, '\0', sizeof(tszIPAddr)); - _stprintf(tszIPAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + if (_tcslen(st_APIUrl.tszSubDomain) > 0) + { + _stprintf(tszIPAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + } + else + { + _stprintf(tszIPAddr, _T("%s"), st_APIUrl.tszMainDomain); + } if (!NetXApi_Socket_DomainToAddr(tszIPAddr, &ppszListAddr, &nListCount)) { ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 500); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析域名失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析域名:%s,失败,错误:%lX"), lpszClientAddr, tszIPAddr, ProxyProtocol_GetLastError()); return FALSE; } _tcscpy(tszConnectAddr, ppszListAddr[0]); //随便选择一个IP地址 diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index 77907765b6745c3ce412313f2395f9092dec2ba3..9f319b49e0501dc7eda9e7bc9e9e3d91b24a6617 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -10,25 +10,12 @@ // Purpose: ûԶЭͷ // History: *********************************************************************/ -////////////////////////////////////////////////////////////////////////// -// Э鶨;unOperatorType -////////////////////////////////////////////////////////////////////////// -typedef enum -{ - //ûϢ - ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_MSG = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER + 1 -}ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_CUSTOM; -////////////////////////////////////////////////////////////////////////// -// Э鶨:unOperatorCode -////////////////////////////////////////////////////////////////////////// -#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MSG_TEXTREQ 0x0001 //Ϣ -#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MSG_TEXTREP 0x0002 //ظϢ /////////////////////////////////////////////////////////////////////////// // ݽṹ /////////////////////////////////////////////////////////////////////////// #pragma pack(push) #pragma pack(1) -typedef struct +typedef struct { TCHAR tszIPAddr[128]; ENUM_RFCCOMPONENTS_PROXY_STATUS enStatus;