mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 15:26:36 +08:00
feat(waf): 自动 IP 组 lookback 支持 60m/1h 时长写法
将 lookback_minutes 替换为 lookback,移除最小 5 分钟回看限制,并兼容旧字段。
This commit is contained in:
@@ -89,7 +89,7 @@ const defaultValues: IPGroupFormValues = {
|
||||
enabled: true,
|
||||
ip_list_text: '',
|
||||
auto_config_text: JSON.stringify(
|
||||
{ lookback_minutes: 60, ttl: -1, rules: [] },
|
||||
{ lookback: '1h', ttl: -1, rules: [] },
|
||||
null,
|
||||
2,
|
||||
),
|
||||
@@ -146,14 +146,20 @@ function appendAutomaticPresetRule(
|
||||
(item as { expr?: unknown }).expr === rule.expr,
|
||||
);
|
||||
const nextRules = exists ? rules : [...rules, rule];
|
||||
const lookback =
|
||||
typeof config.lookback === 'string' && config.lookback.trim()
|
||||
? config.lookback
|
||||
: typeof config.lookback_minutes === 'number'
|
||||
? `${config.lookback_minutes}m`
|
||||
: '1h';
|
||||
// strip legacy field so saved JSON only keeps lookback duration string
|
||||
const { lookback_minutes: _legacyLookbackMinutes, ...rest } = config;
|
||||
return JSON.stringify(
|
||||
{
|
||||
lookback_minutes:
|
||||
typeof config.lookback_minutes === 'number'
|
||||
? config.lookback_minutes
|
||||
: 60,
|
||||
ttl: typeof config.ttl === 'number' ? config.ttl : -1,
|
||||
...config,
|
||||
lookback,
|
||||
ttl: typeof rest.ttl === 'number' ? rest.ttl : -1,
|
||||
...rest,
|
||||
lookback,
|
||||
rules: nextRules,
|
||||
},
|
||||
null,
|
||||
@@ -384,8 +390,8 @@ export function IPGroupDialog({
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
定时从请求日志挖掘恶意 IP 的周期。最小 1 分钟,默认
|
||||
1440 分钟。
|
||||
定时从请求日志挖掘恶意 IP 的周期。最小 1 分钟,默认 1440
|
||||
分钟。
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -42,8 +42,8 @@ export function IPGroupTestDialog({
|
||||
<div className='space-y-4'>
|
||||
<div className='rounded-lg border border-dashed p-4 text-sm'>
|
||||
<p>
|
||||
回看 {result.lookback_minutes} 分钟 · 规则 {result.rule_count}{' '}
|
||||
条 · 命中 {result.matched_count} 个 IP
|
||||
回看 {result.lookback} · 规则 {result.rule_count} 条 · 命中{' '}
|
||||
{result.matched_count} 个 IP
|
||||
</p>
|
||||
<p className='text-xs text-muted-foreground mt-1'>
|
||||
测试时间:{new Date(result.tested_at).toLocaleString()}
|
||||
|
||||
@@ -1116,7 +1116,7 @@ export interface WAFIPGroupAutoTestPayload {
|
||||
export interface WAFIPGroupAutoTestResult {
|
||||
matched_ips: string[];
|
||||
matched_count: number;
|
||||
lookback_minutes: number;
|
||||
lookback: string;
|
||||
rule_count: number;
|
||||
tested_at: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user