@svadmin/ui 0.130.0 → 0.131.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.css +301 -0
- package/dist/app.theme.css +301 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +44 -0
- package/package.json +5 -4
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { validateIpRuleValue as validatePattern } from './ip-access-rules.js';
|
|
3
|
+
import type { IpAccessMode, IpAccessRule as AccessRule, IpRuleAction as RuleAction, IpRuleType as RuleType } from './ip-access-rules.js';
|
|
4
|
+
export const validateIpRuleValue = validatePattern;
|
|
5
|
+
export type IpAccessRule = AccessRule;
|
|
6
|
+
export type IpRuleAction = RuleAction;
|
|
7
|
+
export type IpRuleType = RuleType;
|
|
8
|
+
|
|
9
|
+
export interface IpAccessRuleEditorProps {
|
|
10
|
+
rules?: IpAccessRule[];
|
|
11
|
+
mode?: IpAccessMode;
|
|
12
|
+
currentClientIp?: string;
|
|
13
|
+
resolveClientIp?: () => Promise<string>;
|
|
14
|
+
busy?: boolean;
|
|
15
|
+
class?: string;
|
|
16
|
+
onChange?: (rules: IpAccessRule[]) => void | Promise<void>;
|
|
17
|
+
onAddMyIp?: (ip: string) => void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { onMount } from 'svelte';
|
|
23
|
+
import ShieldCheck from '@lucide/svelte/icons/shield-check';
|
|
24
|
+
import Plus from '@lucide/svelte/icons/plus';
|
|
25
|
+
import MapPin from '@lucide/svelte/icons/map-pin';
|
|
26
|
+
import Pencil from '@lucide/svelte/icons/pencil';
|
|
27
|
+
import Trash2 from '@lucide/svelte/icons/trash-2';
|
|
28
|
+
import { Button } from './ui/button/index.js';
|
|
29
|
+
import { Input } from './ui/input/index.js';
|
|
30
|
+
import { Badge } from './ui/badge/index.js';
|
|
31
|
+
import { Sheet } from './ui/sheet/index.js';
|
|
32
|
+
import { ipRuleState, lockoutError, ruleTimingError } from './ip-access-rules.js';
|
|
33
|
+
|
|
34
|
+
let { rules = $bindable([]), mode = 'WHITELIST', currentClientIp = '', resolveClientIp,
|
|
35
|
+
busy: pending = $bindable(false), class: className = '', onChange, onAddMyIp }: IpAccessRuleEditorProps = $props();
|
|
36
|
+
const uid = $props.id();
|
|
37
|
+
let searchQuery = $state('');
|
|
38
|
+
let typeFilter = $state<'ALL' | IpRuleType>('ALL');
|
|
39
|
+
let actionFilter = $state<'ALL' | IpRuleAction>('ALL');
|
|
40
|
+
let modalOpen = $state(false);
|
|
41
|
+
let editId = $state<string | null>(null);
|
|
42
|
+
let editType = $state<IpRuleType>('SINGLE');
|
|
43
|
+
let editValue = $state('');
|
|
44
|
+
let editAction = $state<IpRuleAction>('ALLOW');
|
|
45
|
+
let editDescription = $state('');
|
|
46
|
+
let editExpiration = $state('PERMANENT');
|
|
47
|
+
let originalExpiration = $state<string | null>(null);
|
|
48
|
+
let editStartsAt = $state('');
|
|
49
|
+
let errorMessage = $state('');
|
|
50
|
+
let validationError = $state('');
|
|
51
|
+
let now = $state(Date.now());
|
|
52
|
+
let patternInput = $state<HTMLInputElement | null>(null);
|
|
53
|
+
let detectedIp = $state('');
|
|
54
|
+
let editSnapshot = $state('');
|
|
55
|
+
const clientIp = $derived(currentClientIp.trim() || detectedIp);
|
|
56
|
+
const currentIpValid = $derived(validateIpRuleValue('SINGLE', clientIp).valid);
|
|
57
|
+
const filteredRules = $derived(rules.filter(rule =>
|
|
58
|
+
(typeFilter === 'ALL' || rule.type === typeFilter) && (actionFilter === 'ALL' || rule.action === actionFilter)
|
|
59
|
+
&& `${rule.value} ${rule.description ?? ''}`.toLowerCase().includes(searchQuery.trim().toLowerCase())));
|
|
60
|
+
|
|
61
|
+
onMount(() => {
|
|
62
|
+
const timer = setInterval(() => { now = Date.now(); }, 1000);
|
|
63
|
+
return () => clearInterval(timer);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function localDate(iso?: string | null): string {
|
|
67
|
+
if (!iso || !Number.isFinite(Date.parse(iso))) return '';
|
|
68
|
+
const date = new Date(iso);
|
|
69
|
+
return new Date(date.getTime() - date.getTimezoneOffset() * 60_000).toISOString().slice(0, 23);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function openRule(rule?: IpAccessRule) {
|
|
73
|
+
editSnapshot = policySnapshot();
|
|
74
|
+
editId = rule?.id ?? null;
|
|
75
|
+
editType = rule?.type ?? 'SINGLE';
|
|
76
|
+
editValue = rule?.value ?? '';
|
|
77
|
+
editAction = rule?.action ?? (mode === 'WHITELIST' ? 'ALLOW' : 'DENY');
|
|
78
|
+
editDescription = rule?.description ?? '';
|
|
79
|
+
originalExpiration = rule?.expiresAt ?? null;
|
|
80
|
+
editExpiration = rule ? 'KEEP' : 'PERMANENT';
|
|
81
|
+
editStartsAt = localDate(rule?.startsAt);
|
|
82
|
+
validationError = '';
|
|
83
|
+
errorMessage = '';
|
|
84
|
+
modalOpen = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function policySnapshot(): string {
|
|
88
|
+
return JSON.stringify({ rules, mode, clientIp });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function commitRules(nextRules: IpAccessRule[]): Promise<boolean> {
|
|
92
|
+
if (pending) return false;
|
|
93
|
+
errorMessage = lockoutError(nextRules, mode, clientIp, Date.now()) ?? '';
|
|
94
|
+
if (errorMessage) return false;
|
|
95
|
+
pending = true;
|
|
96
|
+
const previousSnapshot = policySnapshot();
|
|
97
|
+
const submittedSnapshot = JSON.stringify({ rules: nextRules, mode, clientIp });
|
|
98
|
+
try {
|
|
99
|
+
await onChange?.(nextRules.map(rule => ({ ...rule })));
|
|
100
|
+
if (![previousSnapshot, submittedSnapshot].includes(policySnapshot())) {
|
|
101
|
+
errorMessage = 'Policy changed while saving. Reload the latest policy before continuing.';
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
rules = nextRules;
|
|
105
|
+
return true;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
errorMessage = error instanceof Error ? error.message : 'Unable to save rules. Try again.';
|
|
108
|
+
return false;
|
|
109
|
+
} finally { pending = false; }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function detectClientIp() {
|
|
113
|
+
if (!resolveClientIp || pending) return;
|
|
114
|
+
pending = true;
|
|
115
|
+
errorMessage = '';
|
|
116
|
+
try {
|
|
117
|
+
const resolved = (await resolveClientIp()).trim();
|
|
118
|
+
if (!validateIpRuleValue('SINGLE', resolved).valid) throw new Error('The server returned an invalid client IP.');
|
|
119
|
+
detectedIp = resolved;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
errorMessage = error instanceof Error ? error.message : 'Unable to detect client IP. Try again.';
|
|
122
|
+
} finally { pending = false; }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
onMount(() => { if (!currentClientIp && resolveClientIp) void detectClientIp(); });
|
|
126
|
+
|
|
127
|
+
async function trustCurrentIp() {
|
|
128
|
+
if (!currentIpValid || pending) return;
|
|
129
|
+
const existing = rules.find(rule => rule.type === 'SINGLE' && rule.value.trim() === clientIp && rule.action === 'ALLOW');
|
|
130
|
+
const trusted: IpAccessRule = { ...existing, id: existing?.id ?? crypto.randomUUID(), type: 'SINGLE',
|
|
131
|
+
value: clientIp, action: 'ALLOW', enabled: true, startsAt: null, expiresAt: null,
|
|
132
|
+
description: existing?.description ?? 'Current administrator IP' };
|
|
133
|
+
if (await commitRules([trusted, ...rules.filter(rule => rule.id !== trusted.id)])) {
|
|
134
|
+
try { await onAddMyIp?.(clientIp); }
|
|
135
|
+
catch (error) { errorMessage = error instanceof Error ? error.message : 'The IP was saved, but the notification callback failed.'; }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function expiration(): string | null {
|
|
140
|
+
if (editExpiration === 'KEEP') return originalExpiration;
|
|
141
|
+
const hours = { '2H': 2, '24H': 24, '7D': 168 }[editExpiration as '2H' | '24H' | '7D'];
|
|
142
|
+
const activation = editStartsAt ? Date.parse(editStartsAt) : Date.now();
|
|
143
|
+
return hours ? new Date(Math.max(Date.now(), activation) + hours * 3_600_000).toISOString() : null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function saveRule(event: SubmitEvent) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
if (editSnapshot !== policySnapshot()) {
|
|
149
|
+
errorMessage = 'Policy changed while editing. Close and reopen the editor before saving.';
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
validationError = validateIpRuleValue(editType, editValue).error ?? '';
|
|
153
|
+
if (editStartsAt && !Number.isFinite(Date.parse(editStartsAt))) validationError = 'Invalid activation date.';
|
|
154
|
+
if (validationError) { patternInput?.focus(); return; }
|
|
155
|
+
const existing = rules.find(rule => rule.id === editId);
|
|
156
|
+
const startsAt = editStartsAt === localDate(existing?.startsAt)
|
|
157
|
+
? existing?.startsAt ?? null : editStartsAt ? new Date(editStartsAt).toISOString() : null;
|
|
158
|
+
const next: IpAccessRule = { ...existing, id: editId ?? crypto.randomUUID(), type: editType,
|
|
159
|
+
value: editValue.trim(), action: editAction, description: editDescription.trim(),
|
|
160
|
+
enabled: existing?.enabled ?? true, startsAt,
|
|
161
|
+
expiresAt: expiration() };
|
|
162
|
+
validationError = ruleTimingError(next) ?? '';
|
|
163
|
+
if (validationError) return;
|
|
164
|
+
const updated = editId ? rules.map(rule => rule.id === editId ? next : { ...rule }) : [next, ...rules];
|
|
165
|
+
if (await commitRules(updated)) modalOpen = false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function toggleRule(rule: IpAccessRule) {
|
|
169
|
+
void commitRules(rules.map(current => ({ ...current, enabled: current.id === rule.id ? !current.enabled : current.enabled })));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function countdown(rule: IpAccessRule): string {
|
|
173
|
+
const state = ipRuleState(rule, now);
|
|
174
|
+
const deadline = state === 'Scheduled' ? rule.startsAt : rule.expiresAt;
|
|
175
|
+
if (state === 'Expired' || state === 'Invalid' || state === 'Disabled') return state;
|
|
176
|
+
if (!deadline) return 'Permanent';
|
|
177
|
+
const seconds = Math.max(0, Math.ceil((Date.parse(deadline) - now) / 1000));
|
|
178
|
+
return `${state === 'Scheduled' ? 'Starts in' : 'Expires in'} ${Math.floor(seconds / 3600)}h ${Math.floor(seconds / 60) % 60}m ${seconds % 60}s`;
|
|
179
|
+
}
|
|
180
|
+
</script>
|
|
181
|
+
|
|
182
|
+
<section class="ip-editor {className}" data-svadmin-component="IpAccessRuleEditor" aria-labelledby={`${uid}-title`} aria-busy={pending}>
|
|
183
|
+
<header class="ip-header">
|
|
184
|
+
<h2 id={`${uid}-title`}><ShieldCheck size={20} aria-hidden="true" /> IP Access Control Rules</h2>
|
|
185
|
+
<span class="ip-mode">{mode === 'WHITELIST' ? 'Whitelist Mode' : 'Blacklist Mode'}</span>
|
|
186
|
+
<Button size="sm" onclick={() => openRule()} disabled={pending}><Plus size={16} aria-hidden="true" />Add IP Rule</Button>
|
|
187
|
+
</header>
|
|
188
|
+
<div class="ip-client">
|
|
189
|
+
<span><MapPin size={16} aria-hidden="true" />Current IP: <strong>{clientIp || 'Unavailable'}</strong></span>
|
|
190
|
+
{#if resolveClientIp}<Button variant="outline" size="sm" disabled={pending} onclick={detectClientIp}>Detect IP</Button>{/if}
|
|
191
|
+
<Button variant="outline" size="sm" disabled={pending || !currentIpValid} onclick={trustCurrentIp}>Trust My IP</Button>
|
|
192
|
+
</div>
|
|
193
|
+
{#if errorMessage && !modalOpen}<p role="alert" class="ip-error">{errorMessage}</p>{/if}
|
|
194
|
+
<div class="ip-filters">
|
|
195
|
+
<Input aria-label="Search IP rules" placeholder="Filter by IP, CIDR or description..." bind:value={searchQuery} />
|
|
196
|
+
<select aria-label="Rule type filter" bind:value={typeFilter} class="svadmin-select">
|
|
197
|
+
<option value="ALL">All Types</option><option value="SINGLE">Single IP</option><option value="CIDR">CIDR Subnet</option><option value="RANGE">IP Range</option>
|
|
198
|
+
</select>
|
|
199
|
+
<select aria-label="Rule action filter" bind:value={actionFilter} class="svadmin-select">
|
|
200
|
+
<option value="ALL">All Actions</option><option value="ALLOW">ALLOW</option><option value="DENY">DENY</option>
|
|
201
|
+
</select>
|
|
202
|
+
</div>
|
|
203
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex (键盘用户需要滚动宽表格。) -->
|
|
204
|
+
<div class="ip-table-scroll" tabindex="0" role="region" aria-label="IP access rules">
|
|
205
|
+
<table>
|
|
206
|
+
<thead><tr><th scope="col">Status</th><th scope="col">IP / CIDR Pattern</th><th scope="col">Type</th><th scope="col">Action</th><th scope="col">Validity</th><th scope="col">Description</th><th scope="col">Operations</th></tr></thead>
|
|
207
|
+
<tbody>
|
|
208
|
+
{#each filteredRules as rule (rule.id)}
|
|
209
|
+
<tr>
|
|
210
|
+
<td><button type="button" role="switch" class="svadmin-switch" data-state={rule.enabled ? 'checked' : 'unchecked'}
|
|
211
|
+
aria-checked={rule.enabled} disabled={pending} aria-label={`Toggle ${rule.value}`} onclick={() => toggleRule(rule)}>
|
|
212
|
+
<span class="svadmin-switch-thumb"></span></button><span class="ip-state">{ipRuleState(rule, now)}</span></td>
|
|
213
|
+
<td class="ip-pattern">{rule.value}</td><td>{rule.type}</td>
|
|
214
|
+
<td><Badge variant={rule.action === 'ALLOW' ? 'subtle-success' : 'subtle-destructive'}>{rule.action}</Badge></td>
|
|
215
|
+
<td class="ip-validity"><span>{countdown(rule)}</span>{#if rule.expiresAt}<time datetime={rule.expiresAt}>{new Date(rule.expiresAt).toLocaleString()}</time>{/if}</td>
|
|
216
|
+
<td class="ip-description">{rule.description || '-'}</td>
|
|
217
|
+
<td><div class="ip-actions">
|
|
218
|
+
<Button variant="text" size="icon-sm" aria-label={`Edit ${rule.value}`} title="Edit rule" disabled={pending} onclick={() => openRule(rule)}><Pencil size={16} aria-hidden="true" /></Button>
|
|
219
|
+
<Button variant="text" size="icon-sm" aria-label={`Delete ${rule.value}`} title="Delete rule" disabled={pending} onclick={() => { void commitRules(rules.filter(current => current.id !== rule.id)); }}><Trash2 size={16} aria-hidden="true" /></Button>
|
|
220
|
+
</div></td>
|
|
221
|
+
</tr>
|
|
222
|
+
{:else}<tr><td colspan="7" class="ip-empty">No IP access rules found.</td></tr>{/each}
|
|
223
|
+
</tbody>
|
|
224
|
+
</table>
|
|
225
|
+
</div>
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<Sheet bind:open={modalOpen} class="svadmin-ip-rule-modal" role="dialog" aria-modal="true"
|
|
229
|
+
closeOnOverlayClick={false}
|
|
230
|
+
aria-labelledby={`${uid}-modal-title`} aria-describedby={`${uid}-modal-description`}
|
|
231
|
+
closeLabel="Close rule editor" onCloseRequest={close => { if (!pending) close(); }}>
|
|
232
|
+
<form onsubmit={saveRule}>
|
|
233
|
+
<header class="ip-modal-header"><h3 id={`${uid}-modal-title`}>{editId ? 'Edit IP Access Rule' : 'Add IP Access Rule'}</h3>
|
|
234
|
+
<p id={`${uid}-modal-description`}>IPv4 / IPv6</p></header>
|
|
235
|
+
<fieldset disabled={pending}>
|
|
236
|
+
<label for={`${uid}-type`}>Rule Type</label>
|
|
237
|
+
<select id={`${uid}-type`} bind:value={editType} class="svadmin-select"><option value="SINGLE">Single IP</option><option value="CIDR">CIDR Subnet</option><option value="RANGE">IP Range</option></select>
|
|
238
|
+
<label for={`${uid}-pattern`}>IP / Pattern Value</label>
|
|
239
|
+
<Input id={`${uid}-pattern`} bind:ref={patternInput} bind:value={editValue} aria-invalid={!!validationError} aria-describedby={validationError ? `${uid}-validation` : undefined} />
|
|
240
|
+
{#if validationError}<p id={`${uid}-validation`} class="ip-error" role="alert">{validationError}</p>{/if}
|
|
241
|
+
<label for={`${uid}-action`}>Action</label>
|
|
242
|
+
<select id={`${uid}-action`} bind:value={editAction} class="svadmin-select"><option value="ALLOW">ALLOW</option><option value="DENY">DENY</option></select>
|
|
243
|
+
<label for={`${uid}-activation`}>Activation Time</label>
|
|
244
|
+
<Input id={`${uid}-activation`} type="datetime-local" step="0.001" bind:value={editStartsAt} />
|
|
245
|
+
<label for={`${uid}-expiration`}>Expiration Period</label>
|
|
246
|
+
<select id={`${uid}-expiration`} bind:value={editExpiration} class="svadmin-select">
|
|
247
|
+
{#if editId}<option value="KEEP">Keep existing expiration</option>{/if}
|
|
248
|
+
<option value="PERMANENT">Permanent</option><option value="2H">2 Hours</option><option value="24H">24 Hours</option><option value="7D">7 Days</option>
|
|
249
|
+
</select>
|
|
250
|
+
<label for={`${uid}-description`}>Description</label><Input id={`${uid}-description`} bind:value={editDescription} />
|
|
251
|
+
</fieldset>
|
|
252
|
+
{#if errorMessage}<p role="alert" class="ip-error ip-save-error">{errorMessage}</p>{/if}
|
|
253
|
+
<footer><Button variant="outline" disabled={pending} onclick={() => { modalOpen = false; }}>Cancel</Button>
|
|
254
|
+
<Button type="submit" disabled={pending}>{pending ? 'Saving...' : 'Save Rule'}</Button></footer>
|
|
255
|
+
</form>
|
|
256
|
+
</Sheet>
|
|
257
|
+
|
|
258
|
+
<style>
|
|
259
|
+
.ip-editor { min-width: 0; color: var(--foreground); background: var(--card); font-size: var(--svadmin-text-body); }
|
|
260
|
+
.ip-header, .ip-client, .ip-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
261
|
+
.ip-header { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
|
|
262
|
+
h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--svadmin-text-section); font-weight: 500; }
|
|
263
|
+
.ip-mode { margin-right: auto; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
264
|
+
.ip-client { padding: 16px 0; }
|
|
265
|
+
.ip-client > span { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-right: auto; min-width: 0; }
|
|
266
|
+
strong { font-weight: 500; overflow-wrap: anywhere; }
|
|
267
|
+
.ip-filters { display: grid; grid-template-columns: minmax(160px, 1fr) repeat(2, minmax(120px, 160px)); gap: 12px; margin-bottom: 16px; }
|
|
268
|
+
.ip-table-scroll { max-width: 100%; overflow-x: auto; }
|
|
269
|
+
.ip-table-scroll:focus-visible { outline: var(--svadmin-focus-width) solid var(--ring); outline-offset: var(--svadmin-focus-offset); }
|
|
270
|
+
table { width: 100%; border-collapse: collapse; text-align: left; font-size: var(--svadmin-text-label); }
|
|
271
|
+
th { font-weight: 500; background: var(--muted); white-space: nowrap; }
|
|
272
|
+
th, td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
|
|
273
|
+
tr:hover td { background: var(--accent); }
|
|
274
|
+
.ip-pattern { font-family: monospace; letter-spacing: 0; overflow-wrap: anywhere; min-width: 140px; }
|
|
275
|
+
.ip-state, .ip-validity time { display: block; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); margin-top: 4px; }
|
|
276
|
+
.ip-validity { min-width: 170px; font-variant-numeric: tabular-nums; }
|
|
277
|
+
.ip-description { min-width: 120px; max-width: 240px; overflow-wrap: anywhere; }
|
|
278
|
+
.ip-actions { gap: 4px; flex-wrap: nowrap; }
|
|
279
|
+
.ip-error { color: var(--destructive); font-size: var(--svadmin-text-label); line-height: 1.5; overflow-wrap: anywhere; }
|
|
280
|
+
.ip-empty { padding: 40px 16px; color: var(--muted-foreground); text-align: center; }
|
|
281
|
+
:global(.svadmin-ip-rule-modal.svadmin-sheet-panel) { inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 32px)); max-width: calc(100vw - 32px); height: auto; max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; }
|
|
282
|
+
.ip-modal-header { padding: 20px 48px 16px 24px; border-bottom: 1px solid var(--border); }
|
|
283
|
+
h3 { margin: 0; font-size: var(--svadmin-text-section); font-weight: 500; }
|
|
284
|
+
.ip-modal-header p { margin: 8px 0 0; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
285
|
+
fieldset { display: grid; gap: 8px; margin: 0; padding: 20px 24px; border: 0; min-width: 0; }
|
|
286
|
+
label { margin-top: 4px; font-size: var(--svadmin-text-label); }
|
|
287
|
+
footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); }
|
|
288
|
+
.ip-save-error { margin: 0; padding: 0 24px 16px; }
|
|
289
|
+
@media (max-width: 600px) { .ip-filters { grid-template-columns: 1fr; } .ip-header { align-items: flex-start; } th, td { padding: 12px; } }
|
|
290
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { validateIpRuleValue as validatePattern } from './ip-access-rules.js';
|
|
2
|
+
import type { IpAccessMode, IpAccessRule as AccessRule, IpRuleAction as RuleAction, IpRuleType as RuleType } from './ip-access-rules.js';
|
|
3
|
+
export declare const validateIpRuleValue: typeof validatePattern;
|
|
4
|
+
export type IpAccessRule = AccessRule;
|
|
5
|
+
export type IpRuleAction = RuleAction;
|
|
6
|
+
export type IpRuleType = RuleType;
|
|
7
|
+
export interface IpAccessRuleEditorProps {
|
|
8
|
+
rules?: IpAccessRule[];
|
|
9
|
+
mode?: IpAccessMode;
|
|
10
|
+
currentClientIp?: string;
|
|
11
|
+
resolveClientIp?: () => Promise<string>;
|
|
12
|
+
busy?: boolean;
|
|
13
|
+
class?: string;
|
|
14
|
+
onChange?: (rules: IpAccessRule[]) => void | Promise<void>;
|
|
15
|
+
onAddMyIp?: (ip: string) => void | Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
declare const IpAccessRuleEditor: import("svelte").Component<IpAccessRuleEditorProps, {}, "rules" | "busy">;
|
|
18
|
+
type IpAccessRuleEditor = ReturnType<typeof IpAccessRuleEditor>;
|
|
19
|
+
export default IpAccessRuleEditor;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { IpAccessRuleEditorProps } from './IpAccessRuleEditor.svelte';
|
|
3
|
+
import type { IpAccessMode } from './ip-access-rules.js';
|
|
4
|
+
export interface IpWhitelistDrawerProps extends Omit<IpAccessRuleEditorProps, 'busy'> {
|
|
5
|
+
open?: boolean;
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
onModeChange?: (mode: IpAccessMode) => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { onMount } from 'svelte';
|
|
13
|
+
import { Sheet } from './ui/sheet/index.js';
|
|
14
|
+
import IpAccessRuleEditor from './IpAccessRuleEditor.svelte';
|
|
15
|
+
import { ipRuleState, lockoutError, validateIpRuleValue } from './ip-access-rules.js';
|
|
16
|
+
|
|
17
|
+
let { open = $bindable(false), rules = $bindable([]), mode = $bindable('WHITELIST'),
|
|
18
|
+
currentClientIp = '', resolveClientIp, class: className = '', onClose, onChange, onAddMyIp,
|
|
19
|
+
onModeChange }: IpWhitelistDrawerProps = $props();
|
|
20
|
+
const uid = $props.id();
|
|
21
|
+
let modeError = $state('');
|
|
22
|
+
let pending = $state(false);
|
|
23
|
+
let editorBusy = $state(false);
|
|
24
|
+
let detectedIp = $state('');
|
|
25
|
+
let now = $state(Date.now());
|
|
26
|
+
const clientIp = $derived(currentClientIp.trim() || detectedIp);
|
|
27
|
+
const activeCount = $derived(rules.filter(rule => ipRuleState(rule, now) === 'Active').length);
|
|
28
|
+
onMount(() => {
|
|
29
|
+
const timer = setInterval(() => { now = Date.now(); }, 1000);
|
|
30
|
+
return () => clearInterval(timer);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
async function resolveIp() {
|
|
34
|
+
if (!resolveClientIp) throw new Error('No client IP resolver is configured.');
|
|
35
|
+
const resolved = (await resolveClientIp()).trim();
|
|
36
|
+
if (!validateIpRuleValue('SINGLE', resolved).valid) throw new Error('The server returned an invalid client IP.');
|
|
37
|
+
detectedIp = resolved;
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function changeMode(event: Event) {
|
|
42
|
+
const control = event.currentTarget as HTMLSelectElement;
|
|
43
|
+
const next = control.value as IpAccessMode;
|
|
44
|
+
control.value = mode;
|
|
45
|
+
if (pending || editorBusy || next === mode) return;
|
|
46
|
+
modeError = lockoutError(rules, next, clientIp, Date.now()) ?? '';
|
|
47
|
+
if (modeError) return;
|
|
48
|
+
pending = true;
|
|
49
|
+
const previousSnapshot = JSON.stringify({ rules, mode, clientIp });
|
|
50
|
+
const submittedSnapshot = JSON.stringify({ rules, mode: next, clientIp });
|
|
51
|
+
try {
|
|
52
|
+
await onModeChange?.(next);
|
|
53
|
+
if (![previousSnapshot, submittedSnapshot].includes(JSON.stringify({ rules, mode, clientIp }))) {
|
|
54
|
+
modeError = 'Policy changed while switching mode. Reload the latest policy before continuing.';
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
mode = next;
|
|
58
|
+
}
|
|
59
|
+
catch (error) { modeError = error instanceof Error ? error.message : 'Unable to change enforcement mode. Try again.'; }
|
|
60
|
+
finally { pending = false; }
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<Sheet bind:open {...(onClose ? { onClose } : {})} closeLabel="Close IP whitelist drawer" class="svadmin-ip-drawer {className}"
|
|
65
|
+
onCloseRequest={close => { if (!pending && !editorBusy) close(); }}>
|
|
66
|
+
<div data-svadmin-component="IpWhitelistDrawer" role="dialog" aria-modal="true" aria-labelledby={`${uid}-title`}>
|
|
67
|
+
<header><h2 id={`${uid}-title`}>Network Security & IP Access Rules</h2></header>
|
|
68
|
+
<div class="ip-mode-bar">
|
|
69
|
+
<label for={`${uid}-mode`}>Enforcement Mode</label>
|
|
70
|
+
<select id={`${uid}-mode`} class="svadmin-select" value={mode} onchange={changeMode} disabled={pending || editorBusy}>
|
|
71
|
+
<option value="WHITELIST">Whitelist Only</option><option value="BLACKLIST">Blacklist Block</option>
|
|
72
|
+
</select>
|
|
73
|
+
<span>Active rules: {activeCount} / {rules.length}</span>
|
|
74
|
+
</div>
|
|
75
|
+
{#if modeError}<p class="ip-mode-error" role="alert">{modeError}</p>{/if}
|
|
76
|
+
<div class="ip-drawer-body" inert={pending}>
|
|
77
|
+
<IpAccessRuleEditor bind:rules bind:busy={editorBusy} {mode} currentClientIp={clientIp}
|
|
78
|
+
{...(resolveClientIp ? { resolveClientIp: resolveIp } : {})}
|
|
79
|
+
{...(onChange ? { onChange } : {})} {...(onAddMyIp ? { onAddMyIp } : {})} />
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</Sheet>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
:global(.svadmin-ip-drawer.svadmin-sheet-panel) { display: flex; flex-direction: column; width: min(1040px, 100vw); max-width: 100vw; padding: 0; }
|
|
86
|
+
header { padding: 20px 48px 20px 24px; border-bottom: 1px solid var(--border); }
|
|
87
|
+
h2 { margin: 0; color: var(--foreground); font-size: var(--svadmin-text-section); font-weight: 500; }
|
|
88
|
+
.ip-mode-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--border); font-size: var(--svadmin-text-label); }
|
|
89
|
+
.ip-mode-bar select { width: auto; max-width: 100%; }
|
|
90
|
+
.ip-mode-bar span { margin-left: auto; color: var(--muted-foreground); }
|
|
91
|
+
.ip-drawer-body { min-height: 0; overflow-y: auto; padding: 24px; }
|
|
92
|
+
.ip-mode-error { margin: 0; padding: 16px 24px; color: var(--destructive); font-size: var(--svadmin-text-label); }
|
|
93
|
+
@media (max-width: 600px) { .ip-drawer-body { padding: 16px; } .ip-mode-bar { padding: 16px; } }
|
|
94
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IpAccessRuleEditorProps } from './IpAccessRuleEditor.svelte';
|
|
2
|
+
import type { IpAccessMode } from './ip-access-rules.js';
|
|
3
|
+
export interface IpWhitelistDrawerProps extends Omit<IpAccessRuleEditorProps, 'busy'> {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
onModeChange?: (mode: IpAccessMode) => void | Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
declare const IpWhitelistDrawer: import("svelte").Component<IpWhitelistDrawerProps, {}, "mode" | "open" | "rules">;
|
|
9
|
+
type IpWhitelistDrawer = ReturnType<typeof IpWhitelistDrawer>;
|
|
10
|
+
export default IpWhitelistDrawer;
|