From 468535eef71f92374d294a8d7b3b6155081395b9 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 19 Jul 2025 03:36:59 +0800 Subject: [PATCH] Improve: Support authorizing the online host quantity --- server/2015Remote/2015Remote.h | 3 +- server/2015Remote/2015Remote.rc | Bin 89304 -> 89564 bytes server/2015Remote/2015RemoteDlg.cpp | 104 ++++++++++++++-------------- server/2015Remote/2015RemoteDlg.h | 3 +- server/2015Remote/CPasswordDlg.cpp | 12 +++- server/2015Remote/CPasswordDlg.h | 2 + server/2015Remote/IOCPServer.cpp | 7 +- server/2015Remote/SettingDlg.cpp | 5 -- server/2015Remote/resource.h | Bin 44338 -> 44430 bytes server/2015Remote/stdafx.h | 1 + 10 files changed, 69 insertions(+), 68 deletions(-) diff --git a/server/2015Remote/2015Remote.h b/server/2015Remote/2015Remote.h index 53afd72..5e0e83a 100644 --- a/server/2015Remote/2015Remote.h +++ b/server/2015Remote/2015Remote.h @@ -78,7 +78,7 @@ public: // 启动多个服务端,成功返回0 // nPort示例: 6543;7543 - UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort) { + UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort, int maxConn) { bool succeed = false; auto list = StringToVector(uPort, ';'); for (int i=0; iUpdateMaxConnection(maxConn); succeed = true; m_iocpServer.push_back(svr); } diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 3f769669d52ecd12a2d62c3a74a0c2bf732358de..22bfdb4f0f09f08a1824d47487ac0aa0e5299597 100644 GIT binary patch delta 314 zcmcbyll9JS)(w}`C-*gJOwQ1h*?dnuEP&a9!F02E#Y09xQwC!O9R@=%X#}J#ChMyk zPQItEG`Xg#3o2{QUY5{(Tep3c>h>FcytC<;DjX;Vg@2xq> zYYa3}2WYq{kTjd@=ps7Vz*lMVsoH0}5RGUujCGSQ*2;2&tODt>V9=R-uu^#PgkB}y z3&{!$3Jg}2Rtzx=C6i<8&6z>;@_KhL&DdbcX$sb5#9%)8qPjlYzHau&g4D?uY858G ttCgGlK+Q+ delta 236 zcmcb!oAt&{)(w}`CntF7ZMM)b31Bv5Fx;G9@sN?W=38^AQz(4n89GOp{nHMJ|(@$F11xa6eb&JO9>h>n1Eel47J60vSOd{ ReadAllDllFilesWindows(const std::string& dirPath) { CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent) { + m_nMaxConnection = 0; m_hExit = CreateEvent(NULL, TRUE, FALSE, NULL); m_hIcon = THIS_APP->LoadIcon(IDR_MAINFRAME); @@ -350,7 +351,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx) ON_COMMAND(ID_ONLINE_MESSAGE, &CMy2015RemoteDlg::OnOnlineMessage) ON_COMMAND(ID_ONLINE_DELETE, &CMy2015RemoteDlg::OnOnlineDelete) ON_COMMAND(ID_ONLINE_UPDATE, &CMy2015RemoteDlg::OnOnlineUpdate) - ON_COMMAND(IDM_ONLINE_ABOUT,&CMy2015RemoteDlg::OnAbout) + ON_COMMAND(IDM_ONLINE_ABOUT, &CMy2015RemoteDlg::OnAbout) ON_COMMAND(IDM_ONLINE_CMD, &CMy2015RemoteDlg::OnOnlineCmdManager) ON_COMMAND(IDM_ONLINE_PROCESS, &CMy2015RemoteDlg::OnOnlineProcessManager) @@ -360,17 +361,17 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx) ON_COMMAND(IDM_ONLINE_AUDIO, &CMy2015RemoteDlg::OnOnlineAudioManager) ON_COMMAND(IDM_ONLINE_VIDEO, &CMy2015RemoteDlg::OnOnlineVideoManager) ON_COMMAND(IDM_ONLINE_SERVER, &CMy2015RemoteDlg::OnOnlineServerManager) - ON_COMMAND(IDM_ONLINE_REGISTER, &CMy2015RemoteDlg::OnOnlineRegisterManager) + ON_COMMAND(IDM_ONLINE_REGISTER, &CMy2015RemoteDlg::OnOnlineRegisterManager) ON_COMMAND(IDM_KEYBOARD, &CMy2015RemoteDlg::OnOnlineKeyboardManager) ON_COMMAND(IDM_ONLINE_BUILD, &CMy2015RemoteDlg::OnOnlineBuildClient) //鐢熸垚Client - ON_MESSAGE(UM_ICONNOTIFY, (LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM))OnIconNotify) + ON_MESSAGE(UM_ICONNOTIFY, (LRESULT(__thiscall CWnd::*)(WPARAM, LPARAM))OnIconNotify) ON_COMMAND(IDM_NOTIFY_SHOW, &CMy2015RemoteDlg::OnNotifyShow) ON_COMMAND(ID_NOTIFY_EXIT, &CMy2015RemoteDlg::OnNotifyExit) ON_COMMAND(ID_MAIN_SET, &CMy2015RemoteDlg::OnMainSet) ON_COMMAND(ID_MAIN_EXIT, &CMy2015RemoteDlg::OnMainExit) - ON_MESSAGE(WM_USERTOONLINELIST, OnUserToOnlineList) + ON_MESSAGE(WM_USERTOONLINELIST, OnUserToOnlineList) ON_MESSAGE(WM_USEROFFLINEMSG, OnUserOfflineMsg) - ON_MESSAGE(WM_OPENSCREENSPYDIALOG, OnOpenScreenSpyDialog) + ON_MESSAGE(WM_OPENSCREENSPYDIALOG, OnOpenScreenSpyDialog) ON_MESSAGE(WM_OPENFILEMANAGERDIALOG, OnOpenFileManagerDialog) ON_MESSAGE(WM_OPENTALKDIALOG, OnOpenTalkDialog) ON_MESSAGE(WM_OPENSHELLDIALOG, OnOpenShellDialog) @@ -389,6 +390,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx) ON_MESSAGE(WM_OPENFILEMGRDIALOG, OnOpenFileMgrDialog) ON_MESSAGE(WM_OPENDRAWINGBOARD, OnOpenDrawingBoard) ON_MESSAGE(WM_UPXTASKRESULT, UPXProcResult) + ON_MESSAGE(WM_PASSWORDCHECK, OnPasswordCheck) ON_WM_HELPINFO() ON_COMMAND(ID_ONLINE_SHARE, &CMy2015RemoteDlg::OnOnlineShare) ON_COMMAND(ID_TOOL_AUTH, &CMy2015RemoteDlg::OnToolAuth) @@ -914,7 +916,18 @@ BOOL CMy2015RemoteDlg::OnInitDialog() CreateSolidMenu(); - if (!ListenPort()) { + std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543"); + m_nMaxConnection = 1; + std::string pwd = THIS_CFG.GetStr("settings", "Password"); + auto arr = StringToVector(pwd, '-', 6); + if (arr.size() == 7) { + m_nMaxConnection = atoi(arr[2].c_str()); + } + else { + int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection"); + m_nMaxConnection = nMaxConnection <= 0 ? 10000 : nMaxConnection; + } + if (!Activate(nPort, m_nMaxConnection)){ OnCancel(); return FALSE; } @@ -1063,6 +1076,31 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy) } } +LRESULT CMy2015RemoteDlg::OnPasswordCheck(WPARAM wParam, LPARAM lParam) { + static bool isChecking = false; + if (isChecking) + return S_OK; + + isChecking = true; + if (!CheckValid(-1)) + { + KillTimer(TIMER_CHECK); + CInputDialog dlg(this); + dlg.m_str = m_superPass.c_str(); + dlg.Init("杈撳叆瀵嗙爜", "杈撳叆涓绘帶绋嬪簭鐨勫瘑鐮:"); + dlg.DoModal(); + if (hashSHA256(dlg.m_str.GetString()) != GetPwdHash()) { + THIS_APP->UpdateMaxConnection(1); + MessageBox("璇峰悜绠$悊鍛樼敵璇峰彛浠ゃ", "鎻愮ず", MB_ICONWARNING); + } + else { + m_superPass = dlg.m_str.GetString(); + MessageBox("璇峰強鏃跺褰撳墠涓绘帶绋嬪簭鎺堟潈: 鍦ㄥ伐鍏疯彍鍗曚腑鐢熸垚鍙d护!", "鎻愮ず", MB_ICONWARNING); + } + } + isChecking = false; + return S_OK; +} void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent) { @@ -1078,21 +1116,7 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent) } return; } - if (!CheckValid(-1)) - { - KillTimer(nIDEvent); - CInputDialog dlg(this); - dlg.m_str = m_superPass.c_str(); - dlg.Init("杈撳叆瀵嗙爜", "杈撳叆涓绘帶绋嬪簭鐨勫瘑鐮:"); - dlg.DoModal(); - if (hashSHA256(dlg.m_str.GetString()) != GetPwdHash()) { - MessageBox("璇烽氱煡绠$悊鍛樺欢闀挎巿鏉冩椂闂达紝鍐嶅叧闂鎻愮ず淇℃伅!!!" - "\n鍚﹀垯锛屽叧闂鎻愮ず淇℃伅灏嗛鍑虹▼搴忥紝鏃犳硶鎺堟潈鎴愬姛銆", "鎻愮ず", MB_ICONWARNING); - return OnMainExit(); - } - m_superPass = dlg.m_str.GetString(); - MessageBox("璇峰強鏃跺褰撳墠涓绘帶绋嬪簭鎺堟潈: 鍦ㄥ伐鍏疯彍鍗曚腑鐢熸垚鍙d护!", "鎻愮ず", MB_ICONWARNING); - } + PostMessageA(WM_PASSWORDCHECK); } if (nIDEvent == TIMER_CLOSEWND) { DeletePopupWindow(); @@ -1471,17 +1495,17 @@ bool CMy2015RemoteDlg::CheckValid(int trail) { return false; } - // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256 + // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256: HostNum auto v = splitString(dlg.m_sPassword.GetBuffer(), '-'); - if (v.size() != 6) + if (v.size() != 6 && v.size() != 7) { THIS_CFG.SetStr(settings, pwdKey, ""); MessageBox("鏍煎紡閿欒锛岃閲嶆柊鐢宠鍙d护!", "鎻愮ず", MB_ICONINFORMATION); KillTimer(TIMER_CHECK); return false; } - std::vector subvector(v.begin() + 2, v.end()); - std::string password = v[0] + " - " + v[1] + ": " + GetPwdHash(); + std::vector subvector(v.end() - 4, v.end()); + std::string password = v[0] + " - " + v[1] + ": " + GetPwdHash() + (v.size()==6?"":": "+v[2]); std::string finalKey = deriveKey(password, deviceID); std::string hash256 = joinString(subvector, '-'); std::string fixedKey = getFixedLengthID(finalKey); @@ -1512,14 +1536,6 @@ bool CMy2015RemoteDlg::CheckValid(int trail) { void CMy2015RemoteDlg::OnOnlineBuildClient() { - // 缁欐柊缂栬瘧鐨勭▼搴14澶╄瘯鐢ㄦ湡锛岃繃鏈熶箣鍚庣敓鎴愭湇鍔$闇瑕佺敵璇"鍙d护"锛 - // 濡傛灉瑕佸鍏朵粬鍔熻兘涔冭嚦鏁翠釜绋嬪簭鍚姩鎺堟潈閫昏緫锛屽皢涓嬭堪if璇彞娣诲姞鍒扮浉搴斿湴鏂瑰嵆鍙 - // 鍙d护鍖呭惈鎺堟潈鏃ユ湡鑼冨洿锛岀‘淇濅竴鏈轰竴鐮侊紱鎺堟潈閫昏緫浼氭娴嬭绠楁満鏃ユ湡鏈绡℃敼! - // 娉ㄩ噴涓嬮潰 if 璇彞鍙互灞忚斀璇ユ巿鏉冮昏緫. - // 2025/04/20 - if (!CheckValid(365)) - return; - // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 CBuildDlg Dlg; Dlg.m_strIP = THIS_CFG.GetStr("settings", "master", "").c_str(); @@ -1575,14 +1591,11 @@ void CMy2015RemoteDlg::OnNotifyExit() //鍥烘佽彍鍗 void CMy2015RemoteDlg::OnMainSet() { - int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection"); CSettingDlg Dlg; + Dlg.m_nMax_Connect = m_nMaxConnection; Dlg.DoModal(); //妯℃ 闃诲 - if (nMaxConnection != Dlg.m_nMax_Connect) - { - THIS_APP->UpdateMaxConnection(Dlg.m_nMax_Connect); - } + int m = atoi(THIS_CFG.GetStr("settings", "ReportInterval", "5").c_str()); int n = THIS_CFG.GetInt("settings", "SoftwareDetect"); if (m== m_settings.ReportInterval && n == m_settings.DetectSoftware) { @@ -1607,19 +1620,6 @@ void CMy2015RemoteDlg::OnMainExit() CDialogEx::OnOK(); // 鍏抽棴瀵硅瘽妗 } -BOOL CMy2015RemoteDlg::ListenPort() -{ - std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543"); - //璇诲彇ini 鏂囦欢涓殑鐩戝惉绔彛 - int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection"); - //璇诲彇鏈澶ц繛鎺ユ暟 - - if (nMaxConnection <= 0) - nMaxConnection = 10000; - return Activate(nPort,nMaxConnection); //寮濮嬬洃鍚 -} - - std::string exec(const std::string& cmd) { HANDLE hReadPipe, hWritePipe; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; @@ -1689,7 +1689,7 @@ std::vector splitByNewline(const std::string& input) { BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection) { UINT ret = 0; - if ( (ret = THIS_APP->StartServer(NotifyProc, OfflineProc, nPort)) !=0 ) + if ( (ret = THIS_APP->StartServer(NotifyProc, OfflineProc, nPort, nMaxConnection)) !=0 ) { Mprintf("======> StartServer Failed \n"); char cmd[200]; diff --git a/server/2015Remote/2015RemoteDlg.h b/server/2015Remote/2015RemoteDlg.h index 10ed504..1283c67 100644 --- a/server/2015Remote/2015RemoteDlg.h +++ b/server/2015Remote/2015RemoteDlg.h @@ -168,7 +168,7 @@ public: VOID CreateToolBar(); VOID CreateNotifyBar(); VOID CreateSolidMenu(); - BOOL ListenPort(); + int m_nMaxConnection; BOOL Activate(const std::string& nPort,int nMaxConnection); void UpdateActiveWindow(CONTEXT_OBJECT* ctx); void SendMasterSettings(CONTEXT_OBJECT* ctx); @@ -263,4 +263,5 @@ public: void OnListClick(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnOnlineUnauthorize(); afx_msg void OnToolRequestAuth(); + afx_msg LRESULT OnPasswordCheck(WPARAM wParam, LPARAM lParam); }; diff --git a/server/2015Remote/CPasswordDlg.cpp b/server/2015Remote/CPasswordDlg.cpp index 3ec1927..632d613 100644 --- a/server/2015Remote/CPasswordDlg.cpp +++ b/server/2015Remote/CPasswordDlg.cpp @@ -126,6 +126,7 @@ CPwdGenDlg::CPwdGenDlg(CWnd* pParent /*=nullptr*/) , m_sUserPwd(_T("")) , m_ExpireTm(COleDateTime::GetCurrentTime()) , m_StartTm(COleDateTime::GetCurrentTime()) + , m_nHostNum(1) { } @@ -150,6 +151,9 @@ void CPwdGenDlg::DoDataExchange(CDataExchange* pDX) DDX_DateTimeCtrl(pDX, IDC_EXPIRE_DATE, m_ExpireTm); DDX_Control(pDX, IDC_START_DATE, m_StartDate); DDX_DateTimeCtrl(pDX, IDC_START_DATE, m_StartTm); + DDX_Control(pDX, IDC_EDIT_HOSTNUM, m_EditHostNum); + DDX_Text(pDX, IDC_EDIT_HOSTNUM, m_nHostNum); + DDV_MinMaxInt(pDX, m_nHostNum, 1, 9999); } @@ -172,10 +176,12 @@ void CPwdGenDlg::OnBnClickedButtonGenkey() } CString strBeginDate = m_StartTm.Format("%Y%m%d"); CString strEndDate = m_ExpireTm.Format("%Y%m%d"); - // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256 - std::string password = std::string(strBeginDate.GetString()) + " - " + strEndDate.GetBuffer() + ": " + GetPwdHash(); + CString hostNum; + hostNum.Format("%04d", m_nHostNum); + // 瀵嗙爜褰㈠紡锛20250209 - 20350209: SHA256: HostNum + std::string password = std::string(strBeginDate.GetString()) + " - " + strEndDate.GetBuffer() + ": " + GetPwdHash() + ": " + hostNum.GetBuffer(); std::string finalKey = deriveKey(password, m_sDeviceID.GetString()); - std::string fixedKey = strBeginDate.GetString() + std::string("-") + strEndDate.GetBuffer() + std::string("-") + + std::string fixedKey = strBeginDate.GetString() + std::string("-") + strEndDate.GetBuffer() + std::string("-") + hostNum.GetString() + "-" + getFixedLengthID(finalKey); m_EditPassword.SetWindowTextA(fixedKey.c_str()); std::string hardwareID = getHardwareID(); diff --git a/server/2015Remote/CPasswordDlg.h b/server/2015Remote/CPasswordDlg.h index 239ac0b..61ff110 100644 --- a/server/2015Remote/CPasswordDlg.h +++ b/server/2015Remote/CPasswordDlg.h @@ -76,4 +76,6 @@ public: CDateTimeCtrl m_StartDate; COleDateTime m_StartTm; virtual BOOL OnInitDialog(); + CEdit m_EditHostNum; + int m_nHostNum; }; diff --git a/server/2015Remote/IOCPServer.cpp b/server/2015Remote/IOCPServer.cpp index 9f4ea15..7f2f9b4 100644 --- a/server/2015Remote/IOCPServer.cpp +++ b/server/2015Remote/IOCPServer.cpp @@ -43,12 +43,7 @@ IOCPServer::IOCPServer(void) m_hListenEvent = WSA_INVALID_EVENT; m_hListenThread = NULL; - m_ulMaxConnections = THIS_CFG.GetInt("settings", "MaxConnection"); - - if (m_ulMaxConnections<=0) - { - m_ulMaxConnections = 10000; - } + m_ulMaxConnections = 10000; InitializeCriticalSection(&m_cs); diff --git a/server/2015Remote/SettingDlg.cpp b/server/2015Remote/SettingDlg.cpp index 5d1ee3f..c05c5fb 100644 --- a/server/2015Remote/SettingDlg.cpp +++ b/server/2015Remote/SettingDlg.cpp @@ -70,15 +70,12 @@ BOOL CSettingDlg::OnInitDialog() m_sPublicIP = THIS_CFG.GetStr("settings", "master", "").c_str(); m_sPublicIP = m_sPublicIP.IsEmpty() ? cvt.getPublicIP().c_str() : m_sPublicIP; std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543"); - //读取ini 文件中的监听端口 - int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection"); int DXGI = THIS_CFG.GetInt("settings", "DXGI"); CString algo = THIS_CFG.GetStr("settings", "ScreenCompress", "").c_str(); m_nListenPort = nPort.c_str(); - m_nMax_Connect = nMaxConnection<=0 ? 10000 : nMaxConnection; int n = algo.IsEmpty() ? ALGORITHM_DIFF : atoi(algo.GetString()); switch (n) @@ -135,8 +132,6 @@ void CSettingDlg::OnBnClickedButtonSettingapply() UpdateData(TRUE); THIS_CFG.SetStr("settings", "master", m_sPublicIP.GetBuffer()); THIS_CFG.SetStr("settings", "ghost", m_nListenPort.GetString()); - //向ini文件中写入值 - THIS_CFG.SetInt("settings", "MaxConnection", m_nMax_Connect); int n = m_ComboScreenCapture.GetCurSel(); THIS_CFG.SetInt("settings", "DXGI", n); diff --git a/server/2015Remote/resource.h b/server/2015Remote/resource.h index 6a892f28d9111f1c863a586ec3527f9051cc762b..dc29ec02047c094f1b4cea4da5e33c7ecfca3087 100644 GIT binary patch delta 58 zcmV-A0LA~Z+5(Q-0lhC3Lv&@L* QBa=iq7LyLF6qDSnR*UKvF#rGn delta 30 ocmV+(0O9|R+XAxM0