增加威胁域名审计
This commit is contained in:
+52
-5
@@ -838,12 +838,16 @@ function populateThreatList(filteredThreats = null) {
|
||||
<span class="px-2 py-1 rounded-full text-xs ${statusInfo.class}">${statusInfo.text}</span>
|
||||
</td>
|
||||
<td class="py-2 sm:py-3 px-2 sm:px-4 text-sm">
|
||||
${!threat.resolved ? `
|
||||
${threat.status === 'blocked' ? `
|
||||
<button class="alert-action-btn block px-2 py-1 bg-blue-500 text-white text-xs rounded hover:bg-blue-600" data-alert-id="${threat.id}" data-action="allowed" data-domain="${threat.domain}">放行</button>
|
||||
` : threat.status === 'allowed' ? `
|
||||
<button class="alert-action-btn block px-2 py-1 bg-red-500 text-white text-xs rounded hover:bg-red-600" data-alert-id="${threat.id}" data-action="blocked" data-domain="${threat.domain}">屏蔽</button>
|
||||
` : `
|
||||
<div class="flex space-x-2">
|
||||
<button class="alert-action-btn block px-2 py-1 bg-red-500 text-white text-xs rounded hover:bg-red-600" data-alert-id="${threat.id}" data-action="blocked">屏蔽</button>
|
||||
<button class="alert-action-btn block px-2 py-1 bg-blue-500 text-white text-xs rounded hover:bg-blue-600" data-alert-id="${threat.id}" data-action="allowed">放行</button>
|
||||
<button class="alert-action-btn block px-2 py-1 bg-red-500 text-white text-xs rounded hover:bg-red-600" data-alert-id="${threat.id}" data-action="blocked" data-domain="${threat.domain}">屏蔽</button>
|
||||
<button class="alert-action-btn block px-2 py-1 bg-blue-500 text-white text-xs rounded hover:bg-blue-600" data-alert-id="${threat.id}" data-action="allowed" data-domain="${threat.domain}">放行</button>
|
||||
</div>
|
||||
` : '<span class="text-gray-500 text-xs">已处理</span>'}
|
||||
`}
|
||||
</td>
|
||||
`;
|
||||
|
||||
@@ -1058,8 +1062,9 @@ function bindAlertActionEvents() {
|
||||
button.addEventListener('click', async function() {
|
||||
const alertId = this.getAttribute('data-alert-id');
|
||||
const action = this.getAttribute('data-action');
|
||||
const domain = this.getAttribute('data-domain');
|
||||
|
||||
console.log(`处理告警 ${alertId},动作: ${action}`);
|
||||
console.log(`处理告警 ${alertId},动作: ${action},域名: ${domain}`);
|
||||
|
||||
// 显示加载状态
|
||||
const originalText = this.textContent;
|
||||
@@ -1082,6 +1087,15 @@ function bindAlertActionEvents() {
|
||||
console.log('告警解决 API 返回:', response);
|
||||
|
||||
if (response.status === 'success') {
|
||||
// 将规则加入到屏蔽管理的自定义规则列表
|
||||
if (action === 'blocked') {
|
||||
// 添加到屏蔽规则
|
||||
await addToCustomRules(domain, 'block');
|
||||
} else if (action === 'allowed') {
|
||||
// 添加到允许规则
|
||||
await addToCustomRules(domain, 'allow');
|
||||
}
|
||||
|
||||
// 刷新威胁告警数据
|
||||
await refreshThreatData();
|
||||
console.log('告警处理成功');
|
||||
@@ -1099,6 +1113,39 @@ function bindAlertActionEvents() {
|
||||
});
|
||||
}
|
||||
|
||||
// 添加到自定义规则列表
|
||||
async function addToCustomRules(domain, action) {
|
||||
try {
|
||||
console.log(`添加 ${action} 规则: ${domain}`);
|
||||
|
||||
// 根据操作类型选择 HTTP 方法
|
||||
const method = action === 'block' ? 'POST' : 'DELETE';
|
||||
|
||||
// 发送请求到屏蔽规则 API
|
||||
const response = await fetch('/api/shield', {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
rule: domain
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('添加规则 API 返回:', result);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || '添加规则失败');
|
||||
}
|
||||
|
||||
console.log('规则添加成功');
|
||||
} catch (error) {
|
||||
console.error('添加规则失败:', error);
|
||||
// 即使添加规则失败,也继续处理告警
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新威胁告警数据
|
||||
async function refreshThreatData() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user