Fix: keep the local FRP address and align the MCP read-only preset

A subordinate that already runs its own FRP proxy must keep advertising
its own master address: the upstream auto FRP is only a fallback entry
and should not overwrite the address baked into generated clients and
kernel payloads. GetEffectiveMasterAddress now returns the local address
when [frp] UseFrp is on and a master address is configured; otherwise the
upstream address is used exactly as before. The startup banner, the hot
switch tips and the settings dialog follow the same rule, and the dialog
now explains under the field when the address is supplied by the
upstream FRP.

The MCP settings dialog's read-only preset now unchecks every other tool
switch (file transfer, host management, chat, keylog), matching the smart
preset and the first-open state; previously Smart followed by Read-only
left those four checked.

The FRP auto-proxy messages now go through _TRF and the three language
files carry the new local-FRP variants and the upstream-address hint.

Verified: build.cmd server passes; the default (no local FRP) path is
unchanged.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-28 10:27:20 +01:00
1 parent a6c417a061
commit b0e172bf91
7 files changed
+57 -7

No files matched your search

+29 -3
View File
@@ -3086,6 +3086,18 @@ static bool IsFrpSupported(const char* logPrefix = nullptr)
return true; return true;
} }
// 本地是否已启用自有 FRP(主菜单设置:UseFrp + 主控地址)。
// 本地 FRP 只在 64 位主控上启动;32 位恒为未启用。
bool CMy2015RemoteDlg::IsLocalFrpEnabled()
{
#ifdef _WIN64
if (THIS_CFG.GetInt("frp", "UseFrp", 0) == 0) return false;
return !THIS_CFG.GetStr("settings", "master", "").empty();
#else
return false;
#endif
}
void CMy2015RemoteDlg::InitFrpClients() void CMy2015RemoteDlg::InitFrpClients()
{ {
// 显示初始化消息 // 显示初始化消息
@@ -3103,7 +3115,7 @@ void CMy2015RemoteDlg::InitFrpClients()
std::string ip = THIS_CFG.GetStr("settings", "master", ""); std::string ip = THIS_CFG.GetStr("settings", "master", "");
CString tip; CString tip;
if (hasUpperFrp) { if (hasUpperFrp && !IsLocalFrpEnabled()) {
// 使用上级配置的 FRP,无需关心公网 IP // 使用上级配置的 FRP,无需关心公网 IP
tip = _L("使用上级配置的FRP代理"); tip = _L("使用上级配置的FRP代理");
} else { } else {
@@ -3432,6 +3444,11 @@ bool CMy2015RemoteDlg::GetEffectiveMasterAddress(std::string& outIP, int& outPor
if (!frpConfigStr.empty()) { if (!frpConfigStr.empty()) {
FrpAutoConfig frpCfg = ParseFrpAutoConfig(frpConfigStr, heartbeat); FrpAutoConfig frpCfg = ParseFrpAutoConfig(frpConfigStr, heartbeat);
if (frpCfg.enabled && frpCfg.remotePort > 0) { if (frpCfg.enabled && frpCfg.remotePort > 0) {
// 本地已启用自有 FRP 时保持本地地址:上级自动 FRP 只是备用入口,
// 不再覆盖生成客户端/内核载荷里的主控地址。
if (IsLocalFrpEnabled()) {
return false;
}
outIP = frpCfg.serverAddr; outIP = frpCfg.serverAddr;
outPort = frpCfg.remotePort; outPort = frpCfg.remotePort;
return true; // 使用了 FRP 地址 return true; // 使用了 FRP 地址
@@ -3729,7 +3746,11 @@ void CMy2015RemoteDlg::CheckUpperFrpConfigChange()
// 首次:从无到有 → 启动 // 首次:从无到有 → 启动
if (newCfg.enabled) { if (newCfg.enabled) {
StartFrpcAuto(newCfg); StartFrpcAuto(newCfg);
tip.FormatL("[FRP] 已启用上级 FRP 反向代理(远程端口 %d),已生效", newPort); if (IsLocalFrpEnabled()) {
tip.Format(_TRF("[FRP] 已启用上级 FRP 反向代理(远程端口 %d);本地 FRP 已启用,主控地址保持不变"), newPort);
} else {
tip.Format(_TRF("[FRP] 已启用上级 FRP 反向代理(远程端口 %d),已生效"), newPort);
}
} else { } else {
// 新配置无效,但 cur 非空 —— 提示但不启动;同时确保 [frp_auto] 不残留旧值 // 新配置无效,但 cur 非空 —— 提示但不启动;同时确保 [frp_auto] 不残留旧值
ClearFrpAutoSection(); ClearFrpAutoSection();
@@ -3745,8 +3766,13 @@ void CMy2015RemoteDlg::CheckUpperFrpConfigChange()
StopFrpcAuto(); StopFrpcAuto();
if (newCfg.enabled) { if (newCfg.enabled) {
StartFrpcAuto(newCfg); // 内部会用新值覆盖 [frp_auto] StartFrpcAuto(newCfg); // 内部会用新值覆盖 [frp_auto]
tip.FormatL("[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d),已生效", if (IsLocalFrpEnabled()) {
tip.Format(_TRF("[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d);本地 FRP 已启用,主控地址保持不变"),
oldPort, newPort); oldPort, newPort);
} else {
tip.Format(_TRF("[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d),已生效"),
oldPort, newPort);
}
} else { } else {
// 新配置无效(解析失败等),旧的 FRPC 已停,[frp_auto] 必须一并清空 // 新配置无效(解析失败等),旧的 FRPC 已停,[frp_auto] 必须一并清空
ClearFrpAutoSection(); ClearFrpAutoSection();
+2
View File
@@ -573,6 +573,8 @@ public:
// 获取有效的主控地址(优先使用上级FRP配置) // 获取有效的主控地址(优先使用上级FRP配置)
// 返回值:是否使用了FRP地址 // 返回值:是否使用了FRP地址
static bool GetEffectiveMasterAddress(std::string& outIP, int& outPort, bool heartbeat=false); static bool GetEffectiveMasterAddress(std::string& outIP, int& outPort, bool heartbeat=false);
// 本地是否已启用自有 FRP(UseFrp + 主控地址;仅 64 位主控)
static bool IsLocalFrpEnabled();
void StartFrpcAuto(const FrpAutoConfig& cfg); void StartFrpcAuto(const FrpAutoConfig& cfg);
void StopFrpcAuto(); void StopFrpcAuto();
void InitFrpcAuto(); // 启动时自动恢复 void InitFrpcAuto(); // 启动时自动恢复
+6 -2
View File
@@ -314,17 +314,21 @@ void CMcpSettingsDlg::OnHttpsToggle()
// 「只读模式」预设:一键切到只读安全的工具组合。 // 「只读模式」预设:一键切到只读安全的工具组合。
// 顺带打开「启用 MCP」(未开则开),勾选「只读模式(禁命令执行)」, // 顺带打开「启用 MCP」(未开则开),勾选「只读模式(禁命令执行)」,
// 并关闭所有「要求只读关闭」才生效的开关,避免保存后这些功能处于 // 并关闭其余所有工具开关——与「智能模式」互相切换后状态才一致。
// 「已勾选但实际无效」的状态。 // (此前漏关 fileTransfer/machine/chat/keylog,Smart→ReadOnly 会残留勾选。)
void CMcpSettingsDlg::OnPresetReadonly() void CMcpSettingsDlg::OnPresetReadonly()
{ {
m_btnEnable.SetCheck(BST_CHECKED); m_btnEnable.SetCheck(BST_CHECKED);
m_btnReadonly.SetCheck(BST_CHECKED); m_btnReadonly.SetCheck(BST_CHECKED);
m_btnTerminal.SetCheck(BST_UNCHECKED); m_btnTerminal.SetCheck(BST_UNCHECKED);
m_btnRemoteControl.SetCheck(BST_UNCHECKED); m_btnRemoteControl.SetCheck(BST_UNCHECKED);
m_btnFileTransfer.SetCheck(BST_UNCHECKED);
m_btnFileWrite.SetCheck(BST_UNCHECKED); m_btnFileWrite.SetCheck(BST_UNCHECKED);
m_btnManage.SetCheck(BST_UNCHECKED); m_btnManage.SetCheck(BST_UNCHECKED);
m_btnMachine.SetCheck(BST_UNCHECKED);
m_btnMachineDangerous.SetCheck(BST_UNCHECKED); m_btnMachineDangerous.SetCheck(BST_UNCHECKED);
m_btnChat.SetCheck(BST_UNCHECKED);
m_btnKeylog.SetCheck(BST_UNCHECKED);
m_btnBuild.SetCheck(BST_UNCHECKED); m_btnBuild.SetCheck(BST_UNCHECKED);
} }
+5 -2
View File
@@ -130,11 +130,14 @@ BOOL CSettingDlg::OnInitDialog()
SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:")); SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:"));
m_sPublicIP = savedMaster.empty() ? localPublicIP.c_str() : savedMaster.c_str(); m_sPublicIP = savedMaster.empty() ? localPublicIP.c_str() : savedMaster.c_str();
SetDlgItemText(IDC_STATIC_SET_IP_HINT, _T("")); SetDlgItemText(IDC_STATIC_SET_IP_HINT, _T(""));
} else if (!frpAutoServer.empty()) { } else if (!frpAutoServer.empty() && !(frpEnabled && !savedMaster.empty())) {
// 场景 2: 上级配置了 FRP // 场景 2: 上级配置了 FRP
// 本地已启用自有 FRP(UseFrp + 已配置主控地址)时不走这里:
// 此时主控地址以本地 FRP 为准,与 GetEffectiveMasterAddress 的规则一致。
SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:")); SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:"));
m_sPublicIP = frpAutoServer.c_str(); m_sPublicIP = frpAutoServer.c_str();
SetDlgItemText(IDC_STATIC_SET_IP_HINT, _T("")); SetDlgItemText(IDC_STATIC_SET_IP_HINT,
_TR("该地址由上级自动 FRP 提供(端口由上级分配),无需修改"));
} else if (frpEnabled) { } else if (frpEnabled) {
// 场景 3: 启用了本地 FRP(FRP服务器应有公网IP) // 场景 3: 启用了本地 FRP(FRP服务器应有公网IP)
SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:")); SetDlgItemText(IDC_STATIC_SET_PUBLIC_IP, _TR("公网地址:"));
+5
View File
@@ -2269,3 +2269,8 @@ APK
; MCP settings preset buttons ; MCP settings preset buttons
只读模式=Nur-Lese-Modus 只读模式=Nur-Lese-Modus
智能模式=Intelligenter Modus 智能模式=Intelligenter Modus
; FRP auto proxy messages (local FRP precedence)
[FRP] 已启用上级 FRP 反向代理(远程端口 %d);本地 FRP 已启用,主控地址保持不变=[FRP] Vorgelagerter FRP-Reverse-Proxy aktiviert (Remote-Port %d); lokales FRP ist aktiv, Master-Adresse unveraendert
[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d);本地 FRP 已启用,主控地址保持不变=[FRP] Vorgelagerter FRP-Reverse-Proxy gewechselt (Remote-Port %d -> %d); lokales FRP ist aktiv, Master-Adresse unveraendert
; FRP address hint (upstream-provided)
该地址由上级自动 FRP 提供(端口由上级分配),无需修改=Vom FRP des vorgelagerten Servers (Port dort vergeben); keine Aenderung noetig
+5
View File
@@ -2280,3 +2280,8 @@ APK
; MCP settings preset buttons ; MCP settings preset buttons
只读模式=Read-only mode 只读模式=Read-only mode
智能模式=Smart mode 智能模式=Smart mode
; FRP auto proxy messages (local FRP precedence)
[FRP] 已启用上级 FRP 反向代理(远程端口 %d);本地 FRP 已启用,主控地址保持不变=[FRP] Upstream FRP reverse proxy enabled (remote port %d); local FRP is enabled, master address unchanged
[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d);本地 FRP 已启用,主控地址保持不变=[FRP] Upstream FRP reverse proxy switched (remote port %d → %d); local FRP is enabled, master address unchanged
; FRP address hint (upstream-provided)
该地址由上级自动 FRP 提供(端口由上级分配),无需修改=Provided by the upstream FRP (port assigned there); no change needed
+5
View File
@@ -2273,3 +2273,8 @@ APK
; MCP settings preset buttons ; MCP settings preset buttons
只读模式=唯讀模式 只读模式=唯讀模式
智能模式=智慧模式 智能模式=智慧模式
; FRP auto proxy messages (local FRP precedence)
[FRP] 已启用上级 FRP 反向代理(远程端口 %d);本地 FRP 已启用,主控地址保持不变=[FRP] 已啟用上級 FRP 反向代理(遠端連接埠 %d);本機 FRP 已啟用,主控位址保持不變
[FRP] 上级 FRP 反向代理配置已切换(远程端口 %d → %d);本地 FRP 已启用,主控地址保持不变=[FRP] 上級 FRP 反向代理設定已切換(遠端連接埠 %d → %d);本機 FRP 已啟用,主控位址保持不變
; FRP address hint (upstream-provided)
该地址由上级自动 FRP 提供(端口由上级分配),无需修改=此位址由上級自動 FRP 提供(連接埠由上級分配),無需修改