Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions client/src/components/AddDecisionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState, type FormEvent } from 'react';
import { AlertCircle, ShieldCheck } from 'lucide-react';
import { DEFAULT_MANUAL_DECISION_SCENARIO } from '../../../shared/contracts';
import { MANAGED_BAN_DURATION, MANAGED_BAN_REASON } from '../lib/permanentBans';
import { addDecision, addDecisions, checkAllowlist } from '../lib/api';
import { useI18n } from '../lib/i18n';
import type {
Expand Down Expand Up @@ -29,6 +30,8 @@ type SkippedBatch = BulkTarget & { entries: BulkAddDecisionResponse['allowlisted
interface AddDecisionModalProps {
/** In bulk mode (`values` set), `ip` is ignored. */
initialDecision: AddDecisionRequest;
/** Restrict this form to long-lived removable IP bans, not temporary decisions. */
managedBan?: boolean;
/** Adds the same decision for each of these values instead of the single `ip`. */
values?: string[];
instances: InstanceSummary[];
Expand Down Expand Up @@ -75,6 +78,7 @@ interface ErrorInfo {

export function AddDecisionModal({
initialDecision,
managedBan = false,
values,
instances,
multipleInstances,
Expand Down Expand Up @@ -239,6 +243,7 @@ export function AddDecisionModal({
const payload: AddDecisionRequest = {
...decision,
scenario: selectedScenario,
...(managedBan ? { type: 'ban' as const, duration: MANAGED_BAN_DURATION, reason: MANAGED_BAN_REASON } : {}),
...(bypassAllowlist ? { bypass_allowlist: true } : {}),
};
if (bulk) {
Expand Down Expand Up @@ -302,8 +307,9 @@ export function AddDecisionModal({
};

return (
<Modal isOpen onClose={close} title={t(bulk ? 'pages.decisions.addManualDecisions' : 'pages.decisions.addManualDecision')} maxWidth="max-w-md">
<Modal isOpen onClose={close} title={managedBan ? 'Ban IP — Banned IPs list' : t(bulk ? 'pages.decisions.addManualDecisions' : 'pages.decisions.addManualDecision')} maxWidth="max-w-md">
<form onSubmit={submit} className="space-y-4">
{managedBan && <p className="text-sm text-gray-600 dark:text-gray-300">This adds a long-term ban to the Banned IPs list. It can be removed using Unban. CrowdSec requires an expiration, so the ban is set for 10 years.</p>}
{bulk ? (
<div>
<p className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('pages.decisions.bulkValues', { count: bulkValues.length })}</p>
Expand All @@ -329,7 +335,7 @@ export function AddDecisionModal({
/>
</div>
)}
<div>
{!managedBan && <div>
<label htmlFor="add-decision-type" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('tableColumns.type')}</label>
<select
id="add-decision-type"
Expand All @@ -342,8 +348,8 @@ export function AddDecisionModal({
<option key={option.value} value={option.value}>{t(option.labelKey)}</option>
))}
</select>
</div>
<div>
</div>}
{!managedBan && <div>
<label htmlFor="add-decision-duration" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('pages.decisions.duration')}</label>
<input
id="add-decision-duration"
Expand All @@ -355,8 +361,8 @@ export function AddDecisionModal({
onChange={(event) => updateDecision({ duration: event.target.value })}
/>
<p className="text-xs text-gray-500 mt-1">{t('pages.decisions.durationHint')}</p>
</div>
{scenarioOptions.length > 1 && (
</div>}
{!managedBan && scenarioOptions.length > 1 && (
<div>
<label htmlFor="add-decision-scenario" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('tableColumns.scenario')}</label>
<select
Expand All @@ -372,7 +378,7 @@ export function AddDecisionModal({
</select>
</div>
)}
<div>
{!managedBan && <div>
<label htmlFor="add-decision-reason" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('pages.decisions.reason')}</label>
<input
id="add-decision-reason"
Expand All @@ -383,7 +389,7 @@ export function AddDecisionModal({
value={decision.reason}
onChange={(event) => updateDecision({ reason: event.target.value })}
/>
</div>
</div>}
{multipleInstances && (
<div className="space-y-1">
<label className="flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300">
Expand Down Expand Up @@ -489,7 +495,7 @@ export function AddDecisionModal({
{t('common.cancel')}
</button>
<button type="submit" disabled={inProgress || blockedByAllowlist} className="px-4 py-2 text-sm font-medium text-white bg-primary-600 border border-transparent rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:cursor-not-allowed disabled:opacity-50">
{inProgress ? t('pages.decisions.adding') : retrying ? 'Retry failed instances' : bulk ? t('pages.decisions.addDecisionsCount', { count: bulkValues.length }) : t('pages.decisions.addDecision')}
{inProgress ? t('pages.decisions.adding') : retrying ? 'Retry failed instances' : managedBan ? 'Add to Banned IPs' : bulk ? t('pages.decisions.addDecisionsCount', { count: bulkValues.length }) : t('pages.decisions.addDecision')}
</button>
</div>
</form>
Expand Down
7 changes: 7 additions & 0 deletions client/src/lib/permanentBans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** A removable, long-lived CrowdSec ban distinct from automated temporary decisions.
* CrowdSec requires an expiry; ten years is deliberately long, not infinite.
* The reason marker is used by the Banned IPs page and its dashboard count.
*/
export const MANAGED_BAN_REASON = 'permanent-ban';
export const MANAGED_BAN_DURATION = '87600h'; // ~10 years
export const MANAGED_BAN_QUERY = 'type:ban AND status:active AND origin:cscli AND scenario:permanent-ban';
1 change: 1 addition & 0 deletions client/src/pages/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,7 @@ export function Alerts() {

{showToolbarBanIp && (
<AddDecisionModal
managedBan
initialDecision={{ ip: '', type: 'ban', duration: '4h', reason: 'manual' }}
instances={instances}
multipleInstances={multipleInstances}
Expand Down
12 changes: 7 additions & 5 deletions client/src/pages/BannedIPs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/Card'
import { Modal } from '../components/ui/Modal';
import { AddDecisionModal } from '../components/AddDecisionModal';
import type { DecisionListItem, InstanceSummary } from '../types';
import { MANAGED_BAN_QUERY } from '../lib/permanentBans';

const PAGE_SIZE = 50;
const ACTIVE_BAN_QUERY = 'type:ban AND status:active AND origin:cscli';
const ACTIVE_BAN_QUERY = MANAGED_BAN_QUERY;

export function BannedIPs() {
const [instances, setInstances] = useState<InstanceSummary[]>([]);
Expand Down Expand Up @@ -76,7 +77,7 @@ export function BannedIPs() {
<ShieldBan className="h-7 w-7 text-red-600" aria-hidden="true"/>
<div>
<h1 className="text-2xl font-semibold text-gray-900 dark:text-white">Banned IPs</h1>
<p className="text-sm text-gray-500">Manually imposed IP bans. Automatic temporary bans remain on Decisions.</p>
<p className="text-sm text-gray-500">Long-term manually managed bans. Use Unban to remove an IP at any time.</p>
</div>
</div>
<div className="flex gap-2">
Expand All @@ -91,7 +92,7 @@ export function BannedIPs() {
</div>
</div>
<Card>
<CardHeader><CardTitle>Manual bans ({total})</CardTitle></CardHeader>
<CardHeader><CardTitle>Banned IPs ({total})</CardTitle></CardHeader>
<CardContent>
<div className="mb-4 flex flex-wrap gap-3">
<label className="flex min-w-0 flex-1 flex-col gap-1 text-sm">
Expand Down Expand Up @@ -133,7 +134,7 @@ export function BannedIPs() {
</td>}
</tr>)}
{loading && <tr><td colSpan={canManage?5:4} className="px-3 py-8 text-center text-gray-500">Loading active IP bans…</td></tr>}
{!loading && visible.length===0 && <tr><td colSpan={canManage?5:4} className="px-3 py-8 text-center text-gray-500">No manual bans match this view.</td></tr>}
{!loading && visible.length===0 && <tr><td colSpan={canManage?5:4} className="px-3 py-8 text-center text-gray-500">No IPs in the managed ban list match this view.</td></tr>}
</tbody>
</table>
</div>
Expand Down Expand Up @@ -166,7 +167,8 @@ export function BannedIPs() {
</div>
</Modal>
{showAdd && <AddDecisionModal
initialDecision={{ip:'',type:'ban',duration:'4h',reason:'manual'}}
managedBan
initialDecision={{ip:'',type:'ban',duration:'87600h',reason:'permanent-ban'}}
instances={instances}
multipleInstances={instances.length>1}
currentInstanceId={scope!=='all'?scope:undefined}
Expand Down
5 changes: 3 additions & 2 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ShieldBan
} from "lucide-react";
import { DASHBOARD_COLORS } from "../lib/dashboardColors";
import { MANAGED_BAN_QUERY } from "../lib/permanentBans";
import { getCountryCodesMatchingName, getCountryName } from "../lib/utils";
import type {
ConfigResponse,
Expand Down Expand Up @@ -679,7 +680,7 @@ export function Dashboard() {
useEffect(() => {
let cancelled=false;
// Count manually imposed bans shown in Banned IPs; automated decisions remain on Decisions.
void fetchDecisionsPaginated(1,1,{q:'type:ban AND status:active AND origin:cscli'})
void fetchDecisionsPaginated(1,1,{q:MANAGED_BAN_QUERY})
.then(result=>{if(!cancelled)setActiveBanDecisions(result.pagination.total);})
.catch(()=>{if(!cancelled)setActiveBanDecisions(null);});
return ()=>{cancelled=true;};
Expand Down Expand Up @@ -1624,7 +1625,7 @@ export function Dashboard() {
<p className="text-[11px] font-medium leading-tight text-gray-500 dark:text-gray-400 sm:text-sm">Total banned IPs</p>
</div>
<h3 className="text-lg font-bold text-gray-900 dark:text-white sm:text-2xl">{activeBanDecisions===null?'—':activeBanDecisions.toLocaleString()}</h3>
<p className="text-xs text-gray-500">Manually imposed IP bans</p>
<p className="text-xs text-gray-500">Long-term managed IP bans</p>
</div>
</CardContent>
</Card>
Expand Down
Loading