feat(rdp): 新增 RDP 远程桌面/SMB/账单同步能力 + 清理编译产物
主要变更: - RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、 backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API - Windows SMB 文件传输:backend/pkg/winsmb - 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情 - Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs - 服务器导入助手:server_import_helpers、ImportCredentialSettings - 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块) - 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-* - .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
777d9e4e71
commit
76ec9387f0
202 files changed
+16555
-2543
No files matched your search
@@ -14,7 +14,7 @@ import { Loader2, Maximize2, Minimize2, Monitor, X } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { attachTerminalResize, mountXterm } from '@/lib/xterm-utils';
|
||||
import { useUserStore } from '@/store';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TerminalLoadingOverlay } from '@/components/common/TerminalLoadingOverlay';
|
||||
|
||||
interface SessionInfo {
|
||||
session_id: number;
|
||||
@@ -33,7 +33,6 @@ interface LiveMonitorProps {
|
||||
}
|
||||
|
||||
export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }: LiveMonitorProps) {
|
||||
const { t } = useTranslation();
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const termRef = useRef<XTerm | null>(null);
|
||||
const fitRef = useRef<FitAddon | null>(null);
|
||||
@@ -126,11 +125,11 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = () => setConnectError(t('aiops.wsConnectFailed'));
|
||||
ws.onerror = () => setConnectError('WebSocket 连接失败');
|
||||
|
||||
ws.onclose = (e) => {
|
||||
if (!didOpen) {
|
||||
setConnectError(`连接失败 (code=${e.code}): ${e.reason || t('aiops.authOrNetwork')}`);
|
||||
setConnectError(`连接失败 (code=${e.code}): ${e.reason || '认证失败或网络问题'}`);
|
||||
}
|
||||
setConnected(false);
|
||||
term.writeln('\r\n\x1b[33m[审计监控] 连接已断开\x1b[0m');
|
||||
@@ -138,7 +137,7 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
if (!didOpen) {
|
||||
setConnectError(t('aiops.connectTimeoutActive'));
|
||||
setConnectError('连接超时 — 请确认已登录且有活跃会话');
|
||||
ws.close();
|
||||
}
|
||||
}, 5000);
|
||||
@@ -196,14 +195,14 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
: { maxWidth: '960px', width: '92vw' }
|
||||
}
|
||||
>
|
||||
<DialogTitle className="sr-only">{t('system.terminalLiveMonitor')}</DialogTitle>
|
||||
<DialogDescription className="sr-only">{t('system.auditWebssh')}</DialogDescription>
|
||||
<DialogTitle className="sr-only">终端实时监控</DialogTitle>
|
||||
<DialogDescription className="sr-only">审计在线 WebSSH 会话</DialogDescription>
|
||||
|
||||
{/* 工具栏 — 与 TerminalDialog 一致 // Logan.Li */}
|
||||
<div className="flex items-center justify-between px-4 py-2 border-b border-[var(--dg-border)]">
|
||||
<div className="flex items-center gap-2 text-sm min-w-0 flex-wrap">
|
||||
<Monitor className="h-4 w-4 dg-text-green shrink-0" />
|
||||
<span className="text-[var(--dg-text-primary)] font-medium">{t('system.terminalLiveMonitor')}</span>
|
||||
<span className="text-[var(--dg-text-primary)] font-medium">终端实时监控</span>
|
||||
{meta && (
|
||||
<span className="text-[var(--dg-text-muted)] truncate">
|
||||
{meta.username} · {meta.server_name} ({meta.server_ip}) · {formatTime(meta.start_time)}
|
||||
@@ -217,12 +216,12 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
{!connected && !connectError && (
|
||||
<Badge variant="outline" className="border-yellow-500/30 dg-text-yellow bg-yellow-500/10 text-xs">
|
||||
<Loader2 className="h-3 w-3 animate-spin mr-1" />
|
||||
{t('common.connecting')}
|
||||
连接中
|
||||
</Badge>
|
||||
)}
|
||||
{connectError && (
|
||||
<Badge variant="outline" className="border-red-500/30 dg-text-red bg-red-500/10 text-xs">
|
||||
{t('system.ldapTestFailed')}
|
||||
连接失败
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@@ -231,7 +230,7 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
type="button"
|
||||
onClick={() => setFullscreen(!fullscreen)}
|
||||
className="p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]"
|
||||
title={fullscreen ? t('common.exitFullscreen') : t('common.fullscreen')}
|
||||
title={fullscreen ? '退出全屏' : '全屏'}
|
||||
>
|
||||
{fullscreen ? <Minimize2 className="h-4 w-4" /> : <Maximize2 className="h-4 w-4" />}
|
||||
</button>
|
||||
@@ -249,12 +248,11 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo }
|
||||
<p className="text-sm dg-text-red px-4 py-2 border-b border-[var(--dg-border)]">{connectError}</p>
|
||||
)}
|
||||
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="xterm-terminal-host"
|
||||
style={{ height: fullscreen ? 'calc(100vh - 49px)' : '520px' }}
|
||||
/>
|
||||
<div className="relative bg-[#0a0e14]" style={{ height: fullscreen ? 'calc(100vh - 49px)' : '520px' }}>
|
||||
<div ref={containerRef} className="xterm-terminal-host h-full" />
|
||||
<TerminalLoadingOverlay show={!connected && !connectError} label="正在连接监控..." />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
// RDP 审计查看器:在线实时查看 + 历史录屏回放共用 Canvas 播放器 // Logan.Li
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { getAuthToken, getWsBase } from '@/utils/request';
|
||||
import { rdpSessionApi } from '@/api';
|
||||
import { Loader2, Maximize2, Minimize2, Pause, Play, RotateCcw, X } from 'lucide-react';
|
||||
|
||||
interface RdpAuditViewerProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
sessionId: number | null;
|
||||
mode: 'live' | 'replay';
|
||||
}
|
||||
|
||||
interface RdpFrame {
|
||||
type: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
image?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
interface RdpRecord {
|
||||
version?: number;
|
||||
frames?: RdpFrame[];
|
||||
}
|
||||
|
||||
interface RawFrame {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
rgba: Uint8ClampedArray;
|
||||
}
|
||||
|
||||
const BINARY_HEADER = 20;
|
||||
const FRAME_MS = 500;
|
||||
|
||||
async function parseRawFrame(data: Blob | ArrayBuffer): Promise<RawFrame | null> {
|
||||
const buffer = data instanceof Blob ? await data.arrayBuffer() : data;
|
||||
if (buffer.byteLength < BINARY_HEADER) return null;
|
||||
const view = new DataView(buffer);
|
||||
const magic = String.fromCharCode(view.getUint8(0), view.getUint8(1), view.getUint8(2), view.getUint8(3));
|
||||
if (magic !== 'RDPR') return null;
|
||||
const x = view.getUint32(4, true);
|
||||
const y = view.getUint32(8, true);
|
||||
const width = view.getUint32(12, true);
|
||||
const height = view.getUint32(16, true);
|
||||
const bytes = width * height * 4;
|
||||
if (width <= 0 || height <= 0 || buffer.byteLength < BINARY_HEADER + bytes) return null;
|
||||
return { x, y, width, height, rgba: new Uint8ClampedArray(buffer, BINARY_HEADER, bytes) };
|
||||
}
|
||||
|
||||
async function drawImageFrame(ctx: CanvasRenderingContext2D, frame: RdpFrame) {
|
||||
if (!frame.image) return;
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
ctx.drawImage(img, frame.x || 0, frame.y || 0, frame.width || img.width, frame.height || img.height);
|
||||
resolve();
|
||||
};
|
||||
img.onerror = () => reject(new Error('RDP 录屏帧解码失败'));
|
||||
img.src = frame.image || '';
|
||||
});
|
||||
}
|
||||
|
||||
export function RdpAuditViewer({ open, onOpenChange, sessionId, mode }: RdpAuditViewerProps) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const timerRef = useRef<number | null>(null);
|
||||
const [fullscreen, setFullscreen] = useState(false);
|
||||
const [status, setStatus] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [canvasSize, setCanvasSize] = useState({ width: 1024, height: 800 });
|
||||
const [frames, setFrames] = useState<RdpFrame[]>([]);
|
||||
const [index, setIndex] = useState(0);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
|
||||
const playableFrames = useMemo(() => frames.filter((f) => f.type === 'bitmap' && f.image), [frames]);
|
||||
|
||||
const drawRaw = async (data: Blob | ArrayBuffer) => {
|
||||
const frame = await parseRawFrame(data);
|
||||
if (!frame) return;
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas?.getContext('2d');
|
||||
if (!canvas || !ctx) return;
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
const pixels = new Uint8ClampedArray(frame.rgba.length);
|
||||
pixels.set(frame.rgba);
|
||||
ctx.putImageData(new ImageData(pixels, frame.width, frame.height), frame.x, frame.y);
|
||||
};
|
||||
|
||||
const drawReplay = async (nextIndex: number) => {
|
||||
const frame = playableFrames[nextIndex];
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas?.getContext('2d');
|
||||
if (!frame || !canvas || !ctx) return;
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
await drawImageFrame(ctx, frame);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !sessionId) return;
|
||||
setStatus(mode === 'live' ? '正在连接 RDP 实时审计...' : '正在加载 RDP 录屏...');
|
||||
setLoading(true);
|
||||
setFrames([]);
|
||||
setIndex(0);
|
||||
setPlaying(false);
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas?.getContext('2d');
|
||||
if (canvas && ctx) {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
if (mode === 'live') {
|
||||
const token = getAuthToken();
|
||||
const ws = new WebSocket(`${getWsBase()}/ws/rdp-audit/${sessionId}?token=${encodeURIComponent(token)}`);
|
||||
ws.binaryType = 'arraybuffer';
|
||||
wsRef.current = ws;
|
||||
ws.onopen = () => { setLoading(false); setStatus(''); };
|
||||
ws.onmessage = (event) => {
|
||||
if (typeof event.data !== 'string') {
|
||||
void drawRaw(event.data as Blob | ArrayBuffer);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const frame = JSON.parse(event.data) as RdpFrame;
|
||||
if (frame.type === 'session' && frame.width && frame.height) {
|
||||
setCanvasSize({ width: frame.width, height: frame.height });
|
||||
} else if (frame.type === 'status' || frame.type === 'error') {
|
||||
setStatus(frame.message || '');
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
};
|
||||
ws.onerror = () => { setLoading(false); setStatus('RDP 实时审计连接失败'); };
|
||||
ws.onclose = () => setStatus((prev) => prev || 'RDP 实时审计已断开');
|
||||
return () => {
|
||||
ws.close();
|
||||
wsRef.current = null;
|
||||
};
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
rdpSessionApi.getRecord(sessionId)
|
||||
.then((raw) => {
|
||||
if (cancelled) return;
|
||||
const text = typeof raw === 'string' ? raw : String(raw || '');
|
||||
const record = JSON.parse(text || '{}') as RdpRecord;
|
||||
const list = (record.frames || []).filter((f) => f.type === 'bitmap' && f.image);
|
||||
setFrames(list);
|
||||
setStatus(list.length ? '' : '该 RDP 会话没有可播放画面帧');
|
||||
setPlaying(list.length > 0);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) {
|
||||
setStatus('RDP 录屏加载失败');
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
rdpSessionApi.logReplayView(sessionId).catch(() => {});
|
||||
return () => { cancelled = true; };
|
||||
}, [open, sessionId, mode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!playing || mode !== 'replay') return;
|
||||
timerRef.current = window.setInterval(() => {
|
||||
setIndex((current) => {
|
||||
const next = current + 1;
|
||||
if (next >= playableFrames.length) {
|
||||
setPlaying(false);
|
||||
return current;
|
||||
}
|
||||
void drawReplay(next);
|
||||
return next;
|
||||
});
|
||||
}, FRAME_MS);
|
||||
return () => {
|
||||
if (timerRef.current !== null) window.clearInterval(timerRef.current);
|
||||
timerRef.current = null;
|
||||
};
|
||||
}, [playing, mode, playableFrames.length]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'replay' && playableFrames.length > 0) void drawReplay(index);
|
||||
}, [index, playableFrames.length, mode]);
|
||||
|
||||
const displayHeight = fullscreen ? 'calc(100vh - 88px)' : '560px';
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent
|
||||
showCloseButton={false}
|
||||
className={cn(
|
||||
'bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] p-0 gap-0 overflow-hidden',
|
||||
fullscreen ? '!max-w-none !w-screen !h-screen !rounded-none !translate-x-0 !translate-y-0 !left-0 !top-0' : '',
|
||||
)}
|
||||
style={fullscreen ? { maxWidth: '100vw', width: '100vw', height: '100vh' } : { maxWidth: '1120px', width: '94vw' }}
|
||||
>
|
||||
<DialogTitle className="sr-only">{mode === 'live' ? 'RDP 实时审计' : 'RDP 历史回放'}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Windows RDP 图形会话审计查看</DialogDescription>
|
||||
<div className="flex items-center justify-between px-4 py-2 border-b border-[var(--dg-border)]">
|
||||
<div className="text-sm font-medium text-[var(--dg-text-primary)]">
|
||||
{mode === 'live' ? 'RDP 实时审计' : `RDP 历史回放 #${sessionId || ''}`}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<button type="button" onClick={() => setFullscreen(!fullscreen)} className="p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]">
|
||||
{fullscreen ? <Minimize2 className="h-4 w-4" /> : <Maximize2 className="h-4 w-4" />}
|
||||
</button>
|
||||
<button type="button" onClick={() => onOpenChange(false)} className="p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]">
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative bg-black flex items-center justify-center" style={{ height: displayHeight }}>
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
width={canvasSize.width}
|
||||
height={canvasSize.height}
|
||||
className="max-w-full max-h-full outline-none"
|
||||
style={{ aspectRatio: `${canvasSize.width} / ${canvasSize.height}` }}
|
||||
/>
|
||||
{loading && <Loader2 className="absolute h-7 w-7 animate-spin text-white/80" />}
|
||||
{status && <div className="absolute left-4 bottom-4 max-w-[70%] rounded bg-black/70 px-3 py-2 text-xs text-white">{status}</div>}
|
||||
</div>
|
||||
{mode === 'replay' && (
|
||||
<div className="flex items-center gap-3 px-4 py-3 border-t border-[var(--dg-border)]">
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" disabled={playableFrames.length === 0} onClick={() => setPlaying((v) => !v)}>
|
||||
{playing ? <Pause className="h-4 w-4" /> : <Play className="h-4 w-4" />}
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" disabled={playableFrames.length === 0} onClick={() => { setIndex(0); setPlaying(false); }}>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
</Button>
|
||||
<Slider
|
||||
value={[index]}
|
||||
min={0}
|
||||
max={Math.max(playableFrames.length - 1, 0)}
|
||||
step={1}
|
||||
onValueChange={(v) => { setPlaying(false); setIndex(v[0] || 0); }}
|
||||
className="flex-1"
|
||||
/>
|
||||
<span className="text-xs dg-text-muted tabular-nums">{playableFrames.length ? index + 1 : 0} / {playableFrames.length}</span>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { exportAuditReportCsv, exportAuditReportJson } from './replay/export-audit';
|
||||
import { terminalSessionApi, sessionCommandApi } from '@/api';
|
||||
import { unwrapList } from '@/hooks/api/unwrap';
|
||||
import { attachTerminalResize, mountXterm } from '@/lib/xterm-utils';
|
||||
import { formatSize } from '@/pages/audit/terminal-audit/helpers';
|
||||
import { ReplayEngine, type SpeedOption } from './replay/replay-engine';
|
||||
import {
|
||||
@@ -39,6 +40,7 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
const { t } = useTranslation();
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const termRef = useRef<XTerm | null>(null);
|
||||
const fitRef = useRef<FitAddon | null>(null);
|
||||
const engineRef = useRef<ReplayEngine | null>(null);
|
||||
const rowsRef = useRef<AsciicastRow[]>([]);
|
||||
|
||||
@@ -97,6 +99,7 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
const fit = new FitAddon();
|
||||
term.loadAddon(fit);
|
||||
termRef.current = term;
|
||||
fitRef.current = fit;
|
||||
|
||||
const engine = new ReplayEngine({
|
||||
onTimeUpdate: (time) => {
|
||||
@@ -147,10 +150,7 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
const rows = parseAsciicast(data);
|
||||
rowsRef.current = rows;
|
||||
|
||||
if (containerRef.current) {
|
||||
term.open(containerRef.current);
|
||||
try { fit.fit(); } catch { /* noop */ }
|
||||
}
|
||||
mountXterm(term, fit, () => containerRef.current);
|
||||
|
||||
if (rows.length === 0) {
|
||||
term.write(data);
|
||||
@@ -168,6 +168,8 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
const seek = initialSeekSec != null && initialSeekSec > 0 ? initialSeekSec : 0;
|
||||
engine.seekTo(seek, false);
|
||||
setCurrentTime(seek);
|
||||
engine.play();
|
||||
setPlaying(true);
|
||||
|
||||
// 二次审计:记录回放查看 // Logan.Li
|
||||
terminalSessionApi.logReplayView(sessionId).catch(() => {});
|
||||
@@ -187,9 +189,29 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
engineRef.current = null;
|
||||
try { term.dispose(); } catch { /* noop */ }
|
||||
termRef.current = null;
|
||||
fitRef.current = null;
|
||||
};
|
||||
}, [open, sessionId, initialSeekSec, t]);
|
||||
|
||||
// 回放终端也跟随 Dialog 尺寸变化重新 fit,避免缩放后内容区留边。 // Logan.Li
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
let cleanup: (() => void) | undefined;
|
||||
let retry = 0;
|
||||
const attach = () => {
|
||||
const container = containerRef.current;
|
||||
const fit = fitRef.current;
|
||||
const term = termRef.current;
|
||||
if (!container || !fit || !term) {
|
||||
if (retry++ < 30) requestAnimationFrame(attach);
|
||||
return;
|
||||
}
|
||||
cleanup = attachTerminalResize(container, fit, term);
|
||||
};
|
||||
attach();
|
||||
return () => cleanup?.();
|
||||
}, [open, sessionId]);
|
||||
|
||||
// 倍速变更 // Logan.Li
|
||||
useEffect(() => {
|
||||
engineRef.current?.setSpeed(speed);
|
||||
@@ -264,7 +286,7 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
<p className="dg-text-red text-sm">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
<div ref={containerRef} className="flex-1 min-h-0 p-1" />
|
||||
<div ref={containerRef} className="xterm-terminal-host flex-1 min-h-0" />
|
||||
|
||||
{!legacyMode && totalTime > 0 && (
|
||||
<div className="shrink-0 border-t border-[var(--dg-border)] bg-[var(--dg-bg-secondary)]/95 px-3 py-2.5 space-y-2">
|
||||
@@ -361,4 +383,4 @@ export function ReplayDialog({ open, onOpenChange, sessionId, initialSeekSec }:
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { Key, Loader2 } from 'lucide-react';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { userApi } from '@/api';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getErrorMessage } from '@/lib/utils';
|
||||
|
||||
interface ResetPasswordDialogProps {
|
||||
user: { id: number | string; username?: string; nickname?: string; authSource?: string } | null;
|
||||
@@ -17,7 +17,6 @@ interface ResetPasswordDialogProps {
|
||||
}
|
||||
|
||||
export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirm, setConfirm] = useState('');
|
||||
@@ -31,12 +30,12 @@ export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps)
|
||||
setSaving(true);
|
||||
try {
|
||||
await userApi.resetUserPassword(user.id, password);
|
||||
toast({ title: t('system.passwordReset'), description: `用户 ${user.nickname || user.username} 的新密码已生效` });
|
||||
toast({ title: '密码已重置', description: `用户 ${user.nickname || user.username} 的新密码已生效` });
|
||||
setPassword('');
|
||||
setConfirm('');
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
toast({ title: t('system.resetFailed'), description: e?.message || String(e), variant: 'destructive' });
|
||||
} catch (e: unknown) {
|
||||
toast({ title: '重置失败', description: getErrorMessage(e), variant: 'destructive' });
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
@@ -48,7 +47,7 @@ export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps)
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-[var(--dg-text-primary)] flex items-center gap-2">
|
||||
<Key className="h-5 w-5 text-[var(--dg-blue)]" />
|
||||
{t('system.resetPassword')}
|
||||
重置密码
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-[var(--dg-text-muted)]">
|
||||
{user ? `为「${user.nickname || user.username}」设置新密码` : ''}
|
||||
@@ -56,26 +55,26 @@ export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps)
|
||||
</DialogHeader>
|
||||
|
||||
{isLdap ? (
|
||||
<p className="text-sm dg-text-yellow/90 py-2">{t('system.ldapResetHint')}</p>
|
||||
<p className="text-sm dg-text-yellow/90 py-2">LDAP 用户请在 LDAP 目录中管理密码,不支持本地重置。</p>
|
||||
) : (
|
||||
<div className="space-y-3 py-1">
|
||||
<div>
|
||||
<Label className="text-xs text-[var(--dg-text-muted)]">{t('system.newPassword')}</Label>
|
||||
<Label className="text-xs text-[var(--dg-text-muted)]">新密码</Label>
|
||||
<Input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
placeholder={t('system.passwordMinLen')}
|
||||
placeholder="至少 6 位"
|
||||
className="mt-1 h-9 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-[var(--dg-text-muted)]">{t('system.userConfirmPassword')}</Label>
|
||||
<Label className="text-xs text-[var(--dg-text-muted)]">确认密码</Label>
|
||||
<Input
|
||||
type="password"
|
||||
value={confirm}
|
||||
onChange={e => setConfirm(e.target.value)}
|
||||
placeholder={t('system.confirmNewPassword')}
|
||||
placeholder="再次输入新密码"
|
||||
className="mt-1 h-9 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]"
|
||||
/>
|
||||
</div>
|
||||
@@ -83,7 +82,7 @@ export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps)
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" className="border-[var(--dg-border)]" onClick={onClose}>{t('common.cancel')}</Button>
|
||||
<Button variant="outline" className="border-[var(--dg-border)]" onClick={onClose}>取消</Button>
|
||||
{!isLdap && (
|
||||
<Button onClick={handleReset} disabled={!canSubmit || saving} className="bg-[var(--dg-blue)] hover:opacity-90">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin mr-1" /> : null}
|
||||
@@ -94,4 +93,4 @@ export function ResetPasswordDialog({ user, onClose }: ResetPasswordDialogProps)
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,11 @@ export function RoleFormDialog({
|
||||
const togglePermission = (id: number, checked: boolean) => {
|
||||
setForm((prev) => {
|
||||
const set = new Set(prev.permission_ids);
|
||||
checked ? set.add(id) : set.delete(id);
|
||||
if (checked) {
|
||||
set.add(id);
|
||||
} else {
|
||||
set.delete(id);
|
||||
}
|
||||
return { ...prev, permission_ids: Array.from(set) };
|
||||
});
|
||||
};
|
||||
@@ -84,7 +88,13 @@ export function RoleFormDialog({
|
||||
const toggleGroup = (items: PermissionOption[], checked: boolean) => {
|
||||
setForm((prev) => {
|
||||
const set = new Set(prev.permission_ids);
|
||||
items.forEach(p => checked ? set.add(p.id) : set.delete(p.id));
|
||||
items.forEach((p) => {
|
||||
if (checked) {
|
||||
set.add(p.id);
|
||||
} else {
|
||||
set.delete(p.id);
|
||||
}
|
||||
});
|
||||
return { ...prev, permission_ids: Array.from(set) };
|
||||
});
|
||||
};
|
||||
|
||||
@@ -6,6 +6,11 @@ export interface AsciicastRow {
|
||||
data: string;
|
||||
}
|
||||
|
||||
export interface AsciicastParseResult {
|
||||
rows: AsciicastRow[];
|
||||
inputRecorded: boolean;
|
||||
}
|
||||
|
||||
export interface CommandBookmark {
|
||||
id: number;
|
||||
command: string;
|
||||
@@ -39,13 +44,52 @@ const HIGH_RISK_PATTERNS = [
|
||||
/\bkill\s+-9\b/i,
|
||||
];
|
||||
|
||||
// parseAsciicast 解析 asciicast v2 录制数据 // Logan.Li
|
||||
export function parseAsciicast(raw: string): AsciicastRow[] {
|
||||
function isPrintableInput(data: string): boolean {
|
||||
if (!data || data.length > 128) return false;
|
||||
if (data.includes('\x1b')) return false;
|
||||
return /^[\x08\x09\x0a\x0d\x20-\x7e]+$/.test(data);
|
||||
}
|
||||
|
||||
function compactPrintable(data: string): string {
|
||||
return data.replace(/[\r\n]/g, '');
|
||||
}
|
||||
|
||||
// dedupeLegacyInputRows 兼容旧录像:去掉“客户端输入 + 远端 PTY 回显”造成的重复字符。 // Logan.Li
|
||||
export function dedupeLegacyInputRows(rows: AsciicastRow[]): AsciicastRow[] {
|
||||
const result: AsciicastRow[] = [];
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
const current = compactPrintable(row.data);
|
||||
if (!current || !isPrintableInput(row.data)) {
|
||||
result.push(row);
|
||||
continue;
|
||||
}
|
||||
|
||||
let echo = '';
|
||||
for (let j = i + 1; j < rows.length && rows[j].time - row.time <= 1; j++) {
|
||||
if (!isPrintableInput(rows[j].data)) break;
|
||||
echo += compactPrintable(rows[j].data);
|
||||
if (echo.length >= current.length) break;
|
||||
}
|
||||
if (echo.startsWith(current)) continue;
|
||||
result.push(row);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// parseAsciicastDetailed 解析 asciicast v2,并识别 AIOps 新旧录制格式。 // Logan.Li
|
||||
export function parseAsciicastDetailed(raw: string): AsciicastParseResult {
|
||||
const lines = raw.split('\n').filter((l) => l.trim());
|
||||
const rows: AsciicastRow[] = [];
|
||||
for (const line of lines) {
|
||||
let inputRecorded = true;
|
||||
for (let idx = 0; idx < lines.length; idx++) {
|
||||
const line = lines[idx];
|
||||
try {
|
||||
const parsed = JSON.parse(line) as unknown;
|
||||
if (idx === 0 && parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
const header = parsed as { aiops_input_recorded?: boolean };
|
||||
inputRecorded = header.aiops_input_recorded !== false;
|
||||
}
|
||||
if (Array.isArray(parsed) && parsed.length >= 3) {
|
||||
rows.push({
|
||||
time: Number(parsed[0]) || 0,
|
||||
@@ -57,7 +101,13 @@ export function parseAsciicast(raw: string): AsciicastRow[] {
|
||||
// 跳过无法解析的行
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
return { rows: inputRecorded ? dedupeLegacyInputRows(rows) : rows, inputRecorded };
|
||||
}
|
||||
|
||||
// parseAsciicast 解析 asciicast v2 录制数据 // Logan.Li
|
||||
export function parseAsciicast(raw: string): AsciicastRow[] {
|
||||
const parsed = parseAsciicastDetailed(raw);
|
||||
return parsed.rows;
|
||||
}
|
||||
|
||||
// formatReplayTime 格式化回放时间 mm:ss 或 hh:mm:ss // Logan.Li
|
||||
@@ -113,4 +163,4 @@ export function findRowIndexAt(rows: AsciicastRow[], time: number): number {
|
||||
if (rows[idx].time > time) break;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user