Feature: Add "Ban IP" to log message context menu in main dialog
- Add "Ban IP" menu item to the log message list (m_CList_Message) right-click context menu, allowing users to extract IPv4 addresses from selected log entries and add them directly to the IP blacklist - Reuses ExtractFirstIPFromMessage() from the previous commit for dependency-free IPv4 parsing with per-segment 0-255 validation - Checks against whitelist before banning (whitelisted IPs cannot be banned) and skips IPs already in blacklist with clear feedback - Immediately persists via THIS_CFG.SetStr to the config ini file; IPBlacklist singleton takes effect instantly — subsequent connections from banned IPs are rejected in IOCPServer::OnAccept() which already calls IsIPBlacklisted() on every new connection - Menu item is grayed out when no log entry is selected - Sync en_US / zh_TW language files with new translation strings Co-Authored-By: DeepSeek V4 Pro
This commit is contained in:
@@ -943,6 +943,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
|||||||
ON_COMMAND(ID_MSGLOG_CLEAR, &CMy2015RemoteDlg::OnMsglogClear)
|
ON_COMMAND(ID_MSGLOG_CLEAR, &CMy2015RemoteDlg::OnMsglogClear)
|
||||||
ON_COMMAND(ID_MSGLOG_SEARCH, &CMy2015RemoteDlg::OnMsglogSearch)
|
ON_COMMAND(ID_MSGLOG_SEARCH, &CMy2015RemoteDlg::OnMsglogSearch)
|
||||||
ON_COMMAND(ID_MSGLOG_LOGIN_NOTIFY, &CMy2015RemoteDlg::OnMsglogLoginNotify)
|
ON_COMMAND(ID_MSGLOG_LOGIN_NOTIFY, &CMy2015RemoteDlg::OnMsglogLoginNotify)
|
||||||
|
ON_COMMAND(ID_MSGLOG_BAN_IP, &CMy2015RemoteDlg::OnMsglogBanIP)
|
||||||
ON_COMMAND(ID_ONLINE_ADD_WATCH, &CMy2015RemoteDlg::OnOnlineAddWatch)
|
ON_COMMAND(ID_ONLINE_ADD_WATCH, &CMy2015RemoteDlg::OnOnlineAddWatch)
|
||||||
ON_COMMAND(ID_ONLINE_LOGIN_NOTIFY, &CMy2015RemoteDlg::OnOnlineLoginNotify)
|
ON_COMMAND(ID_ONLINE_LOGIN_NOTIFY, &CMy2015RemoteDlg::OnOnlineLoginNotify)
|
||||||
ON_NOTIFY(NM_CUSTOMDRAW, IDC_ONLINE, &CMy2015RemoteDlg::OnNMCustomdrawOnline)
|
ON_NOTIFY(NM_CUSTOMDRAW, IDC_ONLINE, &CMy2015RemoteDlg::OnNMCustomdrawOnline)
|
||||||
@@ -9306,12 +9307,14 @@ void CMy2015RemoteDlg::OnRClickMessage(NMHDR* pNMHDR, LRESULT* pResult)
|
|||||||
m_bLogSearchVisible ? _TR("隐藏搜索") : _TR("搜索日志"));
|
m_bLogSearchVisible ? _TR("隐藏搜索") : _TR("搜索日志"));
|
||||||
menu.AppendMenu(MF_SEPARATOR);
|
menu.AppendMenu(MF_SEPARATOR);
|
||||||
menu.AppendMenu(MF_STRING, ID_MSGLOG_LOGIN_NOTIFY, _TR("上线提醒"));
|
menu.AppendMenu(MF_STRING, ID_MSGLOG_LOGIN_NOTIFY, _TR("上线提醒"));
|
||||||
|
menu.AppendMenu(MF_STRING, ID_MSGLOG_BAN_IP, _TR("封禁IP"));
|
||||||
|
|
||||||
// 没有选中项时禁用"删除选中"和"上线提醒"
|
// 没有选中项时禁用"删除选中"、"复制选中"、"上线提醒"和"封禁IP"
|
||||||
if (m_CList_Message.GetSelectedCount() == 0) {
|
if (m_CList_Message.GetSelectedCount() == 0) {
|
||||||
menu.EnableMenuItem(ID_MSGLOG_DELETE, MF_GRAYED);
|
menu.EnableMenuItem(ID_MSGLOG_DELETE, MF_GRAYED);
|
||||||
menu.EnableMenuItem(ID_MSGLOG_COPY, MF_GRAYED);
|
menu.EnableMenuItem(ID_MSGLOG_COPY, MF_GRAYED);
|
||||||
menu.EnableMenuItem(ID_MSGLOG_LOGIN_NOTIFY, MF_GRAYED);
|
menu.EnableMenuItem(ID_MSGLOG_LOGIN_NOTIFY, MF_GRAYED);
|
||||||
|
menu.EnableMenuItem(ID_MSGLOG_BAN_IP, MF_GRAYED);
|
||||||
}
|
}
|
||||||
// PowerShell不可用时禁用"上线提醒"
|
// PowerShell不可用时禁用"上线提醒"
|
||||||
if (!GetNotifyManager().IsPowerShellAvailable()) {
|
if (!GetNotifyManager().IsPowerShellAvailable()) {
|
||||||
@@ -9549,6 +9552,77 @@ void CMy2015RemoteDlg::OnMsglogLoginNotify()
|
|||||||
MessageBoxL(msg, _TR("上线提醒"), MB_ICONINFORMATION);
|
MessageBoxL(msg, _TR("上线提醒"), MB_ICONINFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMy2015RemoteDlg::OnMsglogBanIP()
|
||||||
|
{
|
||||||
|
// Get selected log messages and extract IP addresses from them
|
||||||
|
std::vector<std::string> ipsToAdd;
|
||||||
|
|
||||||
|
POSITION pos = m_CList_Message.GetFirstSelectedItemPosition();
|
||||||
|
while (pos) {
|
||||||
|
int row = m_CList_Message.GetNextSelectedItem(pos);
|
||||||
|
// Column 2 is the message content ("信息内容")
|
||||||
|
CString msgText = m_CList_Message.GetItemText(row, 2);
|
||||||
|
|
||||||
|
CString extractedIP;
|
||||||
|
if (ExtractFirstIPFromMessage(msgText, extractedIP)) {
|
||||||
|
std::string ipUtf8 = CT2A(extractedIP, CP_UTF8);
|
||||||
|
ipsToAdd.push_back(ipUtf8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ipsToAdd.empty()) {
|
||||||
|
MessageBoxL("所选日志消息中未检测到有效的 IP 地址", "提示", MB_ICONINFORMATION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process each extracted IP
|
||||||
|
int bannedCount = 0;
|
||||||
|
int alreadyCount = 0;
|
||||||
|
int whitelistCount = 0;
|
||||||
|
|
||||||
|
for (const auto& ip : ipsToAdd) {
|
||||||
|
// Cannot ban whitelisted IPs
|
||||||
|
if (IPWhitelist::getInstance().IsWhitelisted(ip)) {
|
||||||
|
whitelistCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Already in blacklist
|
||||||
|
if (IPBlacklist::getInstance().IsBlacklisted(ip)) {
|
||||||
|
alreadyCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPBlacklist::getInstance().AddIP(ip);
|
||||||
|
bannedCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Persist to config
|
||||||
|
if (bannedCount > 0) {
|
||||||
|
std::string blacklistStr = IPBlacklist::getInstance().Export();
|
||||||
|
THIS_CFG.SetStr("settings", "IPBlacklist", blacklistStr.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build result message
|
||||||
|
CString details;
|
||||||
|
if (bannedCount > 0) {
|
||||||
|
details.AppendFormat(_TR("已封禁 %d 个 IP"), bannedCount);
|
||||||
|
}
|
||||||
|
if (alreadyCount > 0) {
|
||||||
|
if (!details.IsEmpty()) details += _T("\n");
|
||||||
|
details.AppendFormat(_TR("%d 个 IP 已在黑名单中"), alreadyCount);
|
||||||
|
}
|
||||||
|
if (whitelistCount > 0) {
|
||||||
|
if (!details.IsEmpty()) details += _T("\n");
|
||||||
|
details.AppendFormat(_TR("%d 个 IP 在白名单中,已跳过"), whitelistCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.IsEmpty()) {
|
||||||
|
details = _TR("未执行任何操作");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBoxL(details, _TR("封禁IP"), MB_ICONINFORMATION);
|
||||||
|
}
|
||||||
|
|
||||||
void CMy2015RemoteDlg::OnOnlineAddWatch()
|
void CMy2015RemoteDlg::OnOnlineAddWatch()
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&m_cs);
|
EnterCriticalSection(&m_cs);
|
||||||
|
|||||||
@@ -565,6 +565,7 @@ public:
|
|||||||
afx_msg void OnMsglogClear();
|
afx_msg void OnMsglogClear();
|
||||||
afx_msg void OnMsglogSearch();
|
afx_msg void OnMsglogSearch();
|
||||||
afx_msg void OnMsglogLoginNotify();
|
afx_msg void OnMsglogLoginNotify();
|
||||||
|
afx_msg void OnMsglogBanIP();
|
||||||
afx_msg void OnOnlineAddWatch();
|
afx_msg void OnOnlineAddWatch();
|
||||||
afx_msg void OnNMCustomdrawOnline(NMHDR* pNMHDR, LRESULT* pResult);
|
afx_msg void OnNMCustomdrawOnline(NMHDR* pNMHDR, LRESULT* pResult);
|
||||||
afx_msg void OnOnlineRunAsAdmin();
|
afx_msg void OnOnlineRunAsAdmin();
|
||||||
|
|||||||
@@ -1968,3 +1968,8 @@ FRPC Զ
|
|||||||
所选日志消息中未检测到有效的 IP 地址=No valid IP address detected in the selected log messages
|
所选日志消息中未检测到有效的 IP 地址=No valid IP address detected in the selected log messages
|
||||||
所有解析出的 IP 已在上线提醒列表中=All extracted IPs are already in the login notify list
|
所有解析出的 IP 已在上线提醒列表中=All extracted IPs are already in the login notify list
|
||||||
已添加 %d 个 IP 到上线提醒列表=Added %d IP(s) to login notify list
|
已添加 %d 个 IP 到上线提醒列表=Added %d IP(s) to login notify list
|
||||||
|
封禁IP=Ban IP
|
||||||
|
已封禁 %d 个 IP=Banned %d IP(s)
|
||||||
|
%d 个 IP 已在黑名单中=%d IP(s) already in blacklist
|
||||||
|
%d 个 IP 在白名单中,已跳过=%d IP(s) in whitelist, skipped
|
||||||
|
未执行任何操作=No action taken
|
||||||
|
|||||||
@@ -1959,3 +1959,8 @@ FRPC Զ
|
|||||||
所有解析出的 IP 已在上线提醒列表中=所有解析出的 IP 已在上線提醒列表中
|
所有解析出的 IP 已在上线提醒列表中=所有解析出的 IP 已在上線提醒列表中
|
||||||
已添加 %d 个 IP 到上线提醒列表=已新增 %d 個 IP 到上線提醒列表
|
已添加 %d 个 IP 到上线提醒列表=已新增 %d 個 IP 到上線提醒列表
|
||||||
所选日志消息中未检测到有效的 IP 地址=所選日誌消息中未檢測到有效的 IP 位址
|
所选日志消息中未检测到有效的 IP 地址=所選日誌消息中未檢測到有效的 IP 位址
|
||||||
|
封禁IP=封禁IP
|
||||||
|
已封禁 %d 个 IP=已封禁 %d 個 IP
|
||||||
|
%d 个 IP 已在黑名单中=%d 個 IP 已在黑名單中
|
||||||
|
%d 个 IP 在白名单中,已跳过=%d 個 IP 在白名單中,已跳過
|
||||||
|
未执行任何操作=未執行任何操作
|
||||||
|
|||||||
@@ -992,6 +992,7 @@
|
|||||||
#define ID_MSGLOG_COPY 33043
|
#define ID_MSGLOG_COPY 33043
|
||||||
#define ID_MSGLOG_SEARCH 33078
|
#define ID_MSGLOG_SEARCH 33078
|
||||||
#define ID_MSGLOG_LOGIN_NOTIFY 33079
|
#define ID_MSGLOG_LOGIN_NOTIFY 33079
|
||||||
|
#define ID_MSGLOG_BAN_IP 33080
|
||||||
#define ID_WEB_REMOTE_CONTROL 33044
|
#define ID_WEB_REMOTE_CONTROL 33044
|
||||||
#define ID_TOOL_PLUGIN_SETTINGS 33045
|
#define ID_TOOL_PLUGIN_SETTINGS 33045
|
||||||
#define ID_33046 33046
|
#define ID_33046 33046
|
||||||
@@ -1033,7 +1034,7 @@
|
|||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 398
|
#define _APS_NEXT_RESOURCE_VALUE 398
|
||||||
#define _APS_NEXT_COMMAND_VALUE 33080
|
#define _APS_NEXT_COMMAND_VALUE 33081
|
||||||
#define _APS_NEXT_CONTROL_VALUE 2542
|
#define _APS_NEXT_CONTROL_VALUE 2542
|
||||||
#define _APS_NEXT_SYMED_VALUE 105
|
#define _APS_NEXT_SYMED_VALUE 105
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user