Improve: Support authorizing the online host quantity

This commit is contained in:
yuanyuanxiang
2025-07-19 03:36:59 +08:00
parent 468918494e
commit 468535eef7
10 changed files with 69 additions and 68 deletions

View File

@@ -78,7 +78,7 @@ public:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0
// nPortʾ<74><CABE>: 6543;7543 // nPortʾ<74><CABE>: 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; bool succeed = false;
auto list = StringToVector(uPort, ';'); auto list = StringToVector(uPort, ';');
for (int i=0; i<list.size(); ++i) for (int i=0; i<list.size(); ++i)
@@ -90,6 +90,7 @@ public:
SAFE_DELETE(svr); SAFE_DELETE(svr);
continue; continue;
} }
svr->UpdateMaxConnection(maxConn);
succeed = true; succeed = true;
m_iocpServer.push_back(svr); m_iocpServer.push_back(svr);
} }

Binary file not shown.

View File

@@ -282,6 +282,7 @@ std::vector<DllInfo*> ReadAllDllFilesWindows(const std::string& dirPath) {
CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent) CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent)
{ {
m_nMaxConnection = 0;
m_hExit = CreateEvent(NULL, TRUE, FALSE, NULL); m_hExit = CreateEvent(NULL, TRUE, FALSE, NULL);
m_hIcon = THIS_APP->LoadIcon(IDR_MAINFRAME); m_hIcon = THIS_APP->LoadIcon(IDR_MAINFRAME);
@@ -389,6 +390,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
ON_MESSAGE(WM_OPENFILEMGRDIALOG, OnOpenFileMgrDialog) ON_MESSAGE(WM_OPENFILEMGRDIALOG, OnOpenFileMgrDialog)
ON_MESSAGE(WM_OPENDRAWINGBOARD, OnOpenDrawingBoard) ON_MESSAGE(WM_OPENDRAWINGBOARD, OnOpenDrawingBoard)
ON_MESSAGE(WM_UPXTASKRESULT, UPXProcResult) ON_MESSAGE(WM_UPXTASKRESULT, UPXProcResult)
ON_MESSAGE(WM_PASSWORDCHECK, OnPasswordCheck)
ON_WM_HELPINFO() ON_WM_HELPINFO()
ON_COMMAND(ID_ONLINE_SHARE, &CMy2015RemoteDlg::OnOnlineShare) ON_COMMAND(ID_ONLINE_SHARE, &CMy2015RemoteDlg::OnOnlineShare)
ON_COMMAND(ID_TOOL_AUTH, &CMy2015RemoteDlg::OnToolAuth) ON_COMMAND(ID_TOOL_AUTH, &CMy2015RemoteDlg::OnToolAuth)
@@ -914,7 +916,18 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
CreateSolidMenu(); 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(); OnCancel();
return FALSE; 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("请及时对当前主控程序授权: 在工具菜单中生成口令!", "提示", MB_ICONWARNING);
}
}
isChecking = false;
return S_OK;
}
void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent) void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
{ {
@@ -1078,21 +1116,7 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
} }
return; return;
} }
if (!CheckValid(-1)) PostMessageA(WM_PASSWORDCHECK);
{
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("请及时对当前主控程序授权: 在工具菜单中生成口令!", "提示", MB_ICONWARNING);
}
} }
if (nIDEvent == TIMER_CLOSEWND) { if (nIDEvent == TIMER_CLOSEWND) {
DeletePopupWindow(); DeletePopupWindow();
@@ -1471,17 +1495,17 @@ bool CMy2015RemoteDlg::CheckValid(int trail) {
return false; return false;
} }
// 密码形式20250209 - 20350209: SHA256 // 密码形式20250209 - 20350209: SHA256: HostNum
auto v = splitString(dlg.m_sPassword.GetBuffer(), '-'); auto v = splitString(dlg.m_sPassword.GetBuffer(), '-');
if (v.size() != 6) if (v.size() != 6 && v.size() != 7)
{ {
THIS_CFG.SetStr(settings, pwdKey, ""); THIS_CFG.SetStr(settings, pwdKey, "");
MessageBox("格式错误,请重新申请口令!", "提示", MB_ICONINFORMATION); MessageBox("格式错误,请重新申请口令!", "提示", MB_ICONINFORMATION);
KillTimer(TIMER_CHECK); KillTimer(TIMER_CHECK);
return false; return false;
} }
std::vector<std::string> subvector(v.begin() + 2, v.end()); std::vector<std::string> subvector(v.end() - 4, v.end());
std::string password = v[0] + " - " + v[1] + ": " + GetPwdHash(); std::string password = v[0] + " - " + v[1] + ": " + GetPwdHash() + (v.size()==6?"":": "+v[2]);
std::string finalKey = deriveKey(password, deviceID); std::string finalKey = deriveKey(password, deviceID);
std::string hash256 = joinString(subvector, '-'); std::string hash256 = joinString(subvector, '-');
std::string fixedKey = getFixedLengthID(finalKey); std::string fixedKey = getFixedLengthID(finalKey);
@@ -1512,14 +1536,6 @@ bool CMy2015RemoteDlg::CheckValid(int trail) {
void CMy2015RemoteDlg::OnOnlineBuildClient() void CMy2015RemoteDlg::OnOnlineBuildClient()
{ {
// 给新编译的程序14天试用期过期之后生成服务端需要申请"口令"
// 如果要对其他功能乃至整个程序启动授权逻辑将下述if语句添加到相应地方即可。
// 口令包含授权日期范围,确保一机一码;授权逻辑会检测计算机日期未被篡改!
// 注释下面 if 语句可以屏蔽该授权逻辑.
// 2025/04/20
if (!CheckValid(365))
return;
// TODO: 在此添加命令处理程序代码 // TODO: 在此添加命令处理程序代码
CBuildDlg Dlg; CBuildDlg Dlg;
Dlg.m_strIP = THIS_CFG.GetStr("settings", "master", "").c_str(); Dlg.m_strIP = THIS_CFG.GetStr("settings", "master", "").c_str();
@@ -1575,14 +1591,11 @@ void CMy2015RemoteDlg::OnNotifyExit()
//固态菜单 //固态菜单
void CMy2015RemoteDlg::OnMainSet() void CMy2015RemoteDlg::OnMainSet()
{ {
int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection");
CSettingDlg Dlg; CSettingDlg Dlg;
Dlg.m_nMax_Connect = m_nMaxConnection;
Dlg.DoModal(); //模态 阻塞 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 m = atoi(THIS_CFG.GetStr("settings", "ReportInterval", "5").c_str());
int n = THIS_CFG.GetInt("settings", "SoftwareDetect"); int n = THIS_CFG.GetInt("settings", "SoftwareDetect");
if (m== m_settings.ReportInterval && n == m_settings.DetectSoftware) { if (m== m_settings.ReportInterval && n == m_settings.DetectSoftware) {
@@ -1607,19 +1620,6 @@ void CMy2015RemoteDlg::OnMainExit()
CDialogEx::OnOK(); // 关闭对话框 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) { std::string exec(const std::string& cmd) {
HANDLE hReadPipe, hWritePipe; HANDLE hReadPipe, hWritePipe;
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
@@ -1689,7 +1689,7 @@ std::vector<std::string> splitByNewline(const std::string& input) {
BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection) BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection)
{ {
UINT ret = 0; 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"); Mprintf("======> StartServer Failed \n");
char cmd[200]; char cmd[200];

View File

@@ -168,7 +168,7 @@ public:
VOID CreateToolBar(); VOID CreateToolBar();
VOID CreateNotifyBar(); VOID CreateNotifyBar();
VOID CreateSolidMenu(); VOID CreateSolidMenu();
BOOL ListenPort(); int m_nMaxConnection;
BOOL Activate(const std::string& nPort,int nMaxConnection); BOOL Activate(const std::string& nPort,int nMaxConnection);
void UpdateActiveWindow(CONTEXT_OBJECT* ctx); void UpdateActiveWindow(CONTEXT_OBJECT* ctx);
void SendMasterSettings(CONTEXT_OBJECT* ctx); void SendMasterSettings(CONTEXT_OBJECT* ctx);
@@ -263,4 +263,5 @@ public:
void OnListClick(NMHDR* pNMHDR, LRESULT* pResult); void OnListClick(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnOnlineUnauthorize(); afx_msg void OnOnlineUnauthorize();
afx_msg void OnToolRequestAuth(); afx_msg void OnToolRequestAuth();
afx_msg LRESULT OnPasswordCheck(WPARAM wParam, LPARAM lParam);
}; };

View File

@@ -126,6 +126,7 @@ CPwdGenDlg::CPwdGenDlg(CWnd* pParent /*=nullptr*/)
, m_sUserPwd(_T("")) , m_sUserPwd(_T(""))
, m_ExpireTm(COleDateTime::GetCurrentTime()) , m_ExpireTm(COleDateTime::GetCurrentTime())
, m_StartTm(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_DateTimeCtrl(pDX, IDC_EXPIRE_DATE, m_ExpireTm);
DDX_Control(pDX, IDC_START_DATE, m_StartDate); DDX_Control(pDX, IDC_START_DATE, m_StartDate);
DDX_DateTimeCtrl(pDX, IDC_START_DATE, m_StartTm); 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 strBeginDate = m_StartTm.Format("%Y%m%d");
CString strEndDate = m_ExpireTm.Format("%Y%m%d"); CString strEndDate = m_ExpireTm.Format("%Y%m%d");
// 密码形式20250209 - 20350209: SHA256 CString hostNum;
std::string password = std::string(strBeginDate.GetString()) + " - " + strEndDate.GetBuffer() + ": " + GetPwdHash(); 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 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); getFixedLengthID(finalKey);
m_EditPassword.SetWindowTextA(fixedKey.c_str()); m_EditPassword.SetWindowTextA(fixedKey.c_str());
std::string hardwareID = getHardwareID(); std::string hardwareID = getHardwareID();

View File

@@ -76,4 +76,6 @@ public:
CDateTimeCtrl m_StartDate; CDateTimeCtrl m_StartDate;
COleDateTime m_StartTm; COleDateTime m_StartTm;
virtual BOOL OnInitDialog(); virtual BOOL OnInitDialog();
CEdit m_EditHostNum;
int m_nHostNum;
}; };

View File

@@ -43,12 +43,7 @@ IOCPServer::IOCPServer(void)
m_hListenEvent = WSA_INVALID_EVENT; m_hListenEvent = WSA_INVALID_EVENT;
m_hListenThread = NULL; m_hListenThread = NULL;
m_ulMaxConnections = THIS_CFG.GetInt("settings", "MaxConnection");
if (m_ulMaxConnections<=0)
{
m_ulMaxConnections = 10000; m_ulMaxConnections = 10000;
}
InitializeCriticalSection(&m_cs); InitializeCriticalSection(&m_cs);

View File

@@ -70,15 +70,12 @@ BOOL CSettingDlg::OnInitDialog()
m_sPublicIP = THIS_CFG.GetStr("settings", "master", "").c_str(); m_sPublicIP = THIS_CFG.GetStr("settings", "master", "").c_str();
m_sPublicIP = m_sPublicIP.IsEmpty() ? cvt.getPublicIP().c_str() : m_sPublicIP; m_sPublicIP = m_sPublicIP.IsEmpty() ? cvt.getPublicIP().c_str() : m_sPublicIP;
std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543"); std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543");
//<2F><>ȡini <20>ļ<EFBFBD><C4BC>еļ<D0B5><C4BC><EFBFBD><EFBFBD>˿<EFBFBD>
int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection");
int DXGI = THIS_CFG.GetInt("settings", "DXGI"); int DXGI = THIS_CFG.GetInt("settings", "DXGI");
CString algo = THIS_CFG.GetStr("settings", "ScreenCompress", "").c_str(); CString algo = THIS_CFG.GetStr("settings", "ScreenCompress", "").c_str();
m_nListenPort = nPort.c_str(); m_nListenPort = nPort.c_str();
m_nMax_Connect = nMaxConnection<=0 ? 10000 : nMaxConnection;
int n = algo.IsEmpty() ? ALGORITHM_DIFF : atoi(algo.GetString()); int n = algo.IsEmpty() ? ALGORITHM_DIFF : atoi(algo.GetString());
switch (n) switch (n)
@@ -135,8 +132,6 @@ void CSettingDlg::OnBnClickedButtonSettingapply()
UpdateData(TRUE); UpdateData(TRUE);
THIS_CFG.SetStr("settings", "master", m_sPublicIP.GetBuffer()); THIS_CFG.SetStr("settings", "master", m_sPublicIP.GetBuffer());
THIS_CFG.SetStr("settings", "ghost", m_nListenPort.GetString()); THIS_CFG.SetStr("settings", "ghost", m_nListenPort.GetString());
//<2F><>ini<6E>ļ<EFBFBD><C4BC><EFBFBD>д<EFBFBD><D0B4>ֵ
THIS_CFG.SetInt("settings", "MaxConnection", m_nMax_Connect);
int n = m_ComboScreenCapture.GetCurSel(); int n = m_ComboScreenCapture.GetCurSel();
THIS_CFG.SetInt("settings", "DXGI", n); THIS_CFG.SetInt("settings", "DXGI", n);

Binary file not shown.

View File

@@ -81,6 +81,7 @@
#define WM_OPENDECRYPTDIALOG WM_USER+3018 #define WM_OPENDECRYPTDIALOG WM_USER+3018
#define WM_OPENFILEMGRDIALOG WM_USER+3019 #define WM_OPENFILEMGRDIALOG WM_USER+3019
#define WM_OPENDRAWINGBOARD WM_USER+3020 #define WM_OPENDRAWINGBOARD WM_USER+3020
#define WM_PASSWORDCHECK WM_USER+3021
#ifdef _UNICODE #ifdef _UNICODE
#if defined _M_IX86 #if defined _M_IX86