feat(demo): 按插件当前实现重写演示页

- 列表/筛选对齐真实 Console:八维筛选、语义动作中文描述、登录失败结果语义
- 详情抽屉展示字段级 diff(脱敏/截断/封顶)与 AuditLog Extension 原始 JSON
- 新增行内「历史」快捷、按筛选条件导出 UTF-8 BOM CSV
- 设置页覆盖审计开关/字段变更/系统变更/保留期与登录失败告警(含测试与模拟触发)
- 模拟器支持 HTTP 捕获管线与系统内部变更两条通道
- 核心纯函数重写并扩充至 56 个单元用例
This commit is contained in:
2026-11-23 00:05:12 +08:00
parent 602744debd
commit afda8d04fd
8 changed files with 3759 additions and 828 deletions
+817 -280
View File
File diff suppressed because it is too large Load Diff
+1064 -73
View File
File diff suppressed because it is too large Load Diff
+308 -79
View File
@@ -15,6 +15,8 @@
--warn-tint: rgba(217, 119, 6, 0.1);
--info: #2563eb;
--info-tint: rgba(37, 99, 235, 0.1);
--purple: #7c3aed;
--purple-tint: rgba(124, 58, 237, 0.1);
--gray-50: #f9fafb;
--gray-100: #f3f4f6;
--gray-200: #e5e7eb;
@@ -30,12 +32,16 @@
* { box-sizing: border-box; }
html, body { height: 100%; }
/* hidden 属性优先于组件的 display 声明(如 .alert-banner{display:flex}) */
[hidden] { display: none !important; }
html { height: 100%; }
body {
margin: 0;
min-height: 100vh;
display: flex;
min-width: 1080px;
min-width: 1100px;
font-size: 14px;
color: var(--gray-900);
background: var(--gray-100);
@@ -165,6 +171,8 @@ body {
.readonly-hint { color: var(--primary-dark); }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tabs {
display: flex;
gap: 4px;
@@ -207,6 +215,13 @@ body {
padding: 14px 18px 0;
}
.card-sub {
font-size: 12.5px;
color: var(--gray-500);
line-height: 1.6;
padding: 6px 18px 0;
}
.btn {
appearance: none;
border: none;
@@ -219,12 +234,17 @@ body {
align-items: center;
gap: 6px;
transition: filter 0.15s, background 0.15s;
white-space: nowrap;
}
.btn svg {
width: 13px;
height: 13px;
fill: currentColor;
width: 14px;
height: 14px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.btn-primary { background: var(--primary); color: #fff; }
@@ -237,6 +257,8 @@ body {
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-link {
appearance: none;
border: none;
@@ -244,10 +266,8 @@ body {
color: var(--primary-dark);
font-size: 13px;
cursor: pointer;
padding: 8px 4px;
align-self: flex-end;
padding: 6px 4px;
}
.btn-link:hover { text-decoration: underline; }
.icon-btn {
@@ -262,8 +282,8 @@ body {
cursor: pointer;
line-height: 1;
}
.icon-btn:hover { background: var(--gray-100); color: var(--gray-900); }
.icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.input {
border: 1px solid var(--gray-300);
@@ -277,12 +297,13 @@ body {
}
.input:focus,
select:focus {
select:focus,
textarea:focus {
border-color: var(--primary);
box-shadow: 0 0 0 2px var(--primary-tint);
}
select, .input { min-width: 0; }
select, .input, textarea { min-width: 0; }
select {
appearance: none;
@@ -296,8 +317,21 @@ select {
cursor: pointer;
}
textarea {
border: 1px solid var(--gray-300);
border-radius: 6px;
padding: 8px 10px;
font-family: ui-monospace, Consolas, monospace;
font-size: 12px;
line-height: 1.55;
resize: vertical;
width: 100%;
}
.hint { font-size: 12px; color: var(--gray-400); }
.muted { color: var(--gray-400); font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.break-all { word-break: break-all; }
/* ============ 横幅 ============ */
.banner {
@@ -305,31 +339,64 @@ select {
padding: 10px 14px;
font-size: 13px;
margin-bottom: 14px;
line-height: 1.55;
}
.banner-warn { background: var(--warn-tint); color: var(--warn); border: 1px solid rgba(217, 119, 6, 0.25); }
.banner-danger { background: var(--danger-tint); color: var(--danger); border: 1px solid rgba(215, 29, 29, 0.25); }
.alert-banner {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.alert-banner-body { flex: 1; }
.alert-banner-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.alert-banner-actions .btn-link { color: var(--danger); }
/* ============ 筛选栏 ============ */
.filter-bar {
display: flex;
align-items: flex-end;
gap: 12px;
.filter-card {
padding: 12px 16px;
margin-bottom: 14px;
flex-wrap: wrap;
}
.filter-item { display: flex; flex-direction: column; gap: 4px; }
.filter-item.grow { flex: 1; min-width: 180px; }
.filter-item label { font-size: 11px; color: var(--gray-500); font-weight: 600; }
.filter-item select, .filter-item .input { min-width: 120px; width: 100%; }
.filter-grid {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr)) auto;
gap: 10px 12px;
align-items: end;
}
/* ============ 表格 ============ */
.filter-item { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter-item > span { font-size: 11px; color: var(--gray-500); font-weight: 600; white-space: nowrap; }
.filter-item input,
.filter-item select { width: 100%; height: 32px; font-size: 12.5px; }
.filter-actions { display: flex; gap: 8px; }
.filter-note {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
padding-top: 10px;
border-top: 1px dashed var(--gray-200);
font-size: 12px;
color: var(--gray-500);
}
/* ============ 列表 ============ */
.table-card { overflow: hidden; }
.audit-list-wrap { overflow-x: auto; }
.audit-table {
width: 100%;
min-width: 900px;
border-collapse: collapse;
table-layout: fixed;
}
.audit-table th {
@@ -337,17 +404,18 @@ select {
font-size: 12px;
font-weight: 600;
color: var(--gray-500);
padding: 10px 16px;
padding: 10px 14px;
background: var(--gray-50);
border-bottom: 1px solid var(--gray-200);
white-space: nowrap;
}
.audit-table td {
padding: 10px 16px;
padding: 9px 14px;
border-bottom: 1px solid var(--gray-100);
font-size: 13px;
vertical-align: middle;
overflow: hidden;
}
.audit-table tbody tr {
@@ -356,20 +424,20 @@ select {
}
.audit-table tbody tr:hover { background: var(--gray-50); }
.audit-table tbody tr.selected td { background: var(--primary-tint); }
@keyframes rowFlash {
0% { background: var(--primary-tint); }
100% { background: transparent; }
}
tr.row-new td { animation: rowFlash 2.8s ease-out; }
tr.row-new td { animation: rowFlash 2.6s ease-out; }
.td-ip { color: var(--gray-500); font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-time { color: var(--gray-700); font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-ip { color: var(--gray-500); font-variant-numeric: tabular-nums; }
.cell-user { display: flex; align-items: center; gap: 8px; }
.cell-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-lines { min-width: 0; }
.u-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-time { font-size: 11.5px; color: var(--gray-400); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* 动作徽标 */
.method {
@@ -384,10 +452,17 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
.m-post { background: var(--info-tint); color: var(--info); }
.m-put { background: var(--warn-tint); color: var(--warn); }
.m-delete { background: var(--danger-tint); color: var(--danger); }
.m-patch { background: rgba(124, 58, 237, 0.1); color: #6d28d9; }
.m-patch { background: var(--purple-tint); color: var(--purple); }
.m-get { background: var(--gray-100); color: var(--gray-500); }
/* 资源列 */
.res-line {
display: flex;
align-items: center;
gap: 6px;
overflow: hidden;
white-space: nowrap;
}
.rt {
display: inline-block;
font-size: 11px;
@@ -396,29 +471,64 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
background: var(--gray-100);
border-radius: 4px;
padding: 2px 7px;
margin-right: 8px;
}
.rn { color: var(--gray-500); font-size: 12.5px; word-break: break-all; }
/* 结果徽标 */
.result {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12.5px;
font-weight: 500;
font-variant-numeric: tabular-nums;
}
.result i {
width: 7px;
height: 7px;
border-radius: 50%;
flex-shrink: 0;
}
.result.ok { color: #16a34a; }
.result.ok i { background: #16a34a; }
.result.fail { color: var(--danger); }
.result.fail i { background: var(--danger); }
.rn {
color: var(--gray-700);
font-size: 12.5px;
overflow: hidden;
text-overflow: ellipsis;
}
.history-link {
flex-shrink: 0;
font-size: 11.5px;
color: var(--primary-dark);
text-decoration: none;
cursor: pointer;
}
.history-link:hover { text-decoration: underline; }
.path-line {
margin-top: 2px;
font-family: ui-monospace, Consolas, monospace;
font-size: 11px;
color: var(--gray-400);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 描述列 */
.action-desc {
display: inline-block;
max-width: 100%;
font-size: 12.5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: middle;
}
.changes-hint {
display: inline-block;
margin-left: 4px;
padding: 1px 5px;
border-radius: 4px;
font-size: 10.5px;
color: var(--warn);
background: var(--warn-tint);
vertical-align: middle;
}
/* 结果徽标 */
.status-badge {
display: inline-block;
padding: 2px 7px;
border-radius: 4px;
font-size: 11.5px;
font-weight: 600;
font-family: ui-monospace, Consolas, monospace;
}
.status-ok { color: #0f766e; background: rgba(76, 203, 160, 0.15); }
.status-fail { color: var(--danger); background: rgba(215, 29, 29, 0.12); }
/* 空状态 */
.empty-state {
@@ -444,11 +554,11 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
.pg-right { display: flex; align-items: center; gap: 8px; }
.pg-right select { padding: 5px 24px 5px 8px; font-size: 12.5px; }
.icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.pg-page { font-size: 12.5px; color: var(--gray-500); font-variant-numeric: tabular-nums; }
/* ============ 设置页 ============ */
#panel-settings .settings-card { max-width: 780px; }
.settings-card { margin-bottom: 16px; padding-bottom: 6px; }
#panel-settings .settings-card { max-width: 820px; }
.settings-card { margin-bottom: 16px; padding-bottom: 4px; }
.setting-row {
display: flex;
@@ -459,11 +569,18 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
border-bottom: 1px solid var(--gray-100);
}
.setting-text { max-width: 640px; }
.setting-text { max-width: 620px; }
.s-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.s-desc { font-size: 12.5px; color: var(--gray-500); line-height: 1.5; }
.s-desc { font-size: 12.5px; color: var(--gray-500); line-height: 1.55; }
.s-desc code {
background: var(--gray-100);
border-radius: 4px;
padding: 1px 5px;
font-size: 11.5px;
}
.input.num { width: 90px; text-align: center; }
.input.num { width: 96px; text-align: center; flex-shrink: 0; }
.input.secret-input { width: 280px; flex-shrink: 0; }
.settings-actions {
display: flex;
@@ -480,7 +597,16 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
}
.clean-stats .num-warn { color: var(--danger); font-weight: 600; }
.settings-card .btn { margin: 0 18px 16px; }
.alert-preview {
margin: 0 18px 16px;
padding: 12px;
background: var(--secondary);
color: #d1fae5;
border-radius: 6px;
font-size: 11.5px;
line-height: 1.55;
overflow-x: auto;
}
/* 开关 */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
@@ -525,7 +651,7 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.c-a { background: #4ccba0; }
.c-b { background: #6366f1; }
@@ -545,8 +671,8 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
position: fixed;
top: 0;
right: 0;
width: 440px;
max-width: 92vw;
width: 480px;
max-width: 94vw;
height: 100vh;
background: #fff;
z-index: 50;
@@ -571,7 +697,13 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
}
.drawer-title { font-size: 16px; font-weight: 700; }
.drawer-sub { font-size: 12px; color: var(--gray-400); margin-top: 3px; font-family: ui-monospace, Consolas, monospace; }
.drawer-sub {
font-size: 11.5px;
color: var(--gray-400);
margin-top: 3px;
font-family: ui-monospace, Consolas, monospace;
word-break: break-all;
}
.readonly-banner {
background: var(--primary-tint);
@@ -586,24 +718,26 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
.detail-list { margin: 0; }
.detail-list .d-row {
padding: 9px 0;
display: flex;
gap: 12px;
padding: 8px 0;
border-bottom: 1px dashed var(--gray-200);
}
.detail-list dt {
font-size: 11.5px;
flex: 0 0 5.5rem;
font-size: 12px;
color: var(--gray-500);
font-weight: 600;
margin-bottom: 5px;
padding-top: 1px;
}
.detail-list dd {
flex: 1;
margin: 0;
font-size: 13px;
font-size: 12.5px;
word-break: break-all;
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.path-code {
@@ -617,9 +751,48 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
line-height: 1.6;
}
.ua { font-size: 12px; color: var(--gray-500); line-height: 1.6; }
.ua { font-size: 11.5px; color: var(--gray-500); line-height: 1.6; }
.raw-json { margin-top: 16px; }
.changes { margin-top: 18px; }
.changes-title {
font-size: 13px;
font-weight: 600;
color: var(--gray-900);
margin: 0 0 6px;
}
.change-row {
display: flex;
gap: 10px;
padding: 8px 0;
border-bottom: 1px dashed var(--gray-200);
}
.change-badge {
flex: 0 0 auto;
align-self: flex-start;
margin-top: 1px;
padding: 1px 6px;
border-radius: 4px;
font-size: 11px;
font-weight: 600;
}
.change-added { color: #0f766e; background: rgba(76, 203, 160, 0.15); }
.change-updated { color: var(--warn); background: var(--warn-tint); }
.change-removed { color: var(--danger); background: var(--danger-tint); }
.change-body { flex: 1; min-width: 0; }
.change-field { font-size: 12px; color: var(--gray-900); word-break: break-all; }
.change-values {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 5px;
margin-top: 2px;
font-size: 12px;
color: var(--gray-700);
}
.change-old { color: var(--danger); text-decoration: line-through; }
.change-arrow { color: var(--gray-400); flex-shrink: 0; }
.raw-json { margin-top: 18px; }
.raw-json summary {
font-size: 12.5px;
color: var(--gray-500);
@@ -631,11 +804,12 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
.raw-json pre {
background: var(--secondary);
color: #d1fae5;
font-size: 11.5px;
font-size: 11px;
border-radius: 6px;
padding: 12px;
overflow-x: auto;
line-height: 1.6;
max-height: 320px;
}
/* ============ 模拟操作弹窗 ============ */
@@ -644,8 +818,10 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 520px;
max-width: 92vw;
width: 680px;
max-width: 94vw;
max-height: 90vh;
overflow-y: auto;
background: #fff;
border-radius: 10px;
z-index: 50;
@@ -656,7 +832,7 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
.modal[hidden] { display: none; }
@keyframes popIn {
from { transform: translate(-50%, -50%) scale(0.96); opacity: 0; }
from { transform: translate(-50%, -50%) scale(0.97); opacity: 0; }
to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@@ -674,7 +850,7 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
font-size: 12.5px;
color: var(--gray-500);
line-height: 1.6;
margin: 8px 0 14px;
margin: 8px 0 12px;
}
.modal-sub code {
@@ -684,9 +860,35 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
font-size: 11.5px;
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; flex: 1; }
.seg-tabs {
display: inline-flex;
background: var(--gray-100);
border-radius: 7px;
padding: 3px;
margin-bottom: 14px;
}
.seg-tab {
appearance: none;
border: none;
background: none;
padding: 6px 14px;
font-size: 12.5px;
font-weight: 500;
color: var(--gray-500);
border-radius: 5px;
cursor: pointer;
}
.seg-tab.active {
background: #fff;
color: var(--gray-900);
font-weight: 600;
box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label { font-size: 12px; color: var(--gray-500); font-weight: 600; }
.field select, .field .input { width: 100%; }
.field textarea { width: 100%; }
.field-row { display: flex; gap: 12px; }
@@ -710,7 +912,13 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 6px;
/* 弹窗内容超高时操作按钮始终可见 */
position: sticky;
bottom: -20px;
margin: 6px -22px -20px;
padding: 12px 22px 20px;
border-top: 1px solid var(--gray-100);
background: #fff;
}
/* ============ Toast ============ */
@@ -729,9 +937,30 @@ tr.row-new td { animation: rowFlash 2.6s ease-out; }
pointer-events: none;
transition: opacity 0.25s, transform 0.25s;
z-index: 100;
max-width: 60vw;
max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--primary-dark); }
.toast.warn { background: #92400e; }
/* ============ 响应式(演示页以桌面为主,窄屏保证可用) ============ */
@media (max-width: 1400px) {
.filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 1180px) {
body { min-width: 900px; }
.page-header { flex-direction: column; }
.header-actions { align-self: flex-end; }
}
@media (max-width: 760px) {
body { min-width: 0; }
.sidebar { display: none; }
.main { padding: 16px 14px 32px; }
.filter-grid { grid-template-columns: minmax(0, 1fr); }
.field-row { flex-direction: column; gap: 0; }
.modal { width: 94vw; }
}
+592 -117
View File
@@ -1,9 +1,18 @@
/**
* 操作审计 · 模拟数据生成器(种子随机,确定性输出)
*
* 记录字段与产品设计 4.1 表格一一对应;resourceType/resourceName 通过
* AuditCore.resolveResource 从路径解析得出(模拟真实捕获管线)。
* 内置若干"故事线"数据:登录爆破、越权 403、服务端 500 等,便于验证筛选场景。
* 记录字段与插件 spec 一致:username / attemptedUsername / method / action /
* resourceType / resourceName / path / statusCode / remoteIp / userAgent / changes。
* 资源解析、语义动作、登录结果与字段 diff 全部经 AuditCore 按真实捕获管线推导,
* 便于在演示页复现「谁改了什么」而不仅是「谁点了什么」。
*
* 内置故事线(固定时间锚点,可直接按演示页提示复现):
* 1. 排查「hello-halo 这篇文章谁改过」(多用户多次编辑,含字段 diff)
* 2. 登录爆破回溯(同一 IP、无差别撞库,含失败回显页)
* 3. 忘记密码后登录成功(失败 → 成功清零)
* 4. 定时发布(系统内部变更,执行者「系统」、无 IP/UA)
* 5. 插件生命周期(升级 / 停用 / 卸载,含字段 diff)
* 6. 越权与异常(403 / 404 / 500)
*/
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
@@ -16,7 +25,7 @@
var DAY = 86400000;
var MIN = 60000;
var BASE_COUNT = 128; // 随机生成的基础记录条数
var BASE_COUNT = 116;
// ---------- 种子随机 ----------
function mulberry32(seed) {
@@ -38,10 +47,17 @@
function hex(r, n) {
var s = '';
var chars = '0123456789abcdef';
for (var i = 0; i < n; i++) s += chars[rint(r, 0, 15)];
for (var i = 0; i < n; i++) {
s += chars[rint(r, 0, 15)];
}
return s;
}
/** 演示用的一次性假口令(运行时生成,非真实凭据;仅用于验证敏感字段脱敏)。 */
function demoSecret(r) {
return 'demo-only-' + hex(r, 12);
}
// ---------- 基础素材 ----------
var UAS = {
chrome: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.2151.97 Safari/537.36',
@@ -52,156 +68,615 @@
};
var USERS = {
'guichumo': { ips: ['192.168.1.23', '116.24.65.187'], uas: ['chrome', 'edge'] },
guichumo: { ips: ['192.168.1.23', '116.24.65.187'], uas: ['chrome', 'edge'] },
'editor.zhang': { ips: ['116.24.65.201'], uas: ['edge', 'firefox'] },
'writer.li': { ips: ['120.79.10.45'], uas: ['safari', 'chrome'] }
};
var SLUGS = ['hello-halo', 'self-host-guide', 'weekly-2026-w46', 'reading-notes-11', 'plugin-dev-diary', 'spring-festival-2026'];
var PLUGINS = ['plugin-search-widget', 'plugin-comment-widget', 'plugin-sitemap', 'plugin-links'];
function postPath(r) { return '/apis/content.halo.run/v1alpha1/posts/' + pick(r, SLUGS); }
function publishPath(r) { return '/apis/api.content.halo.run/v1alpha1/posts/' + pick(r, SLUGS) + '/publish'; }
function commentPath(r) { return '/apis/content.halo.run/v1alpha1/comments/comment-' + hex(r, 6); }
function approvePath(r) { return '/apis/api.halo.run/v1alpha1/comments/comment-' + hex(r, 6) + '/approve'; }
function replyPath(r) { return '/apis/api.halo.run/v1alpha1/comments/comment-' + hex(r, 6) + '/reply'; }
function attachPath(r) { return '/apis/storage.halo.run/v1alpha1/attachments/attachment-' + hex(r, 6); }
// [权重, 操作者, 方法, 路径函数, 状态码]
var ACTIONS = [
[16, 'guichumo', 'PUT', postPath, 200],
[10, 'guichumo', 'POST', publishPath, 200],
[6, 'guichumo', 'POST', function () { return '/apis/content.halo.run/v1alpha1/posts'; }, 201],
[5, 'guichumo', 'PUT', function () { return '/apis/v1alpha1/configmaps/system'; }, 200],
[4, 'guichumo', 'PUT', function (r) { return '/apis/plugin.halo.run/v1alpha1/plugins/' + pick(r, PLUGINS); }, 200],
[4, 'guichumo', 'POST', function () { return '/apis/storage.halo.run/v1alpha1/attachments'; }, 201],
[4, 'guichumo', 'DELETE', attachPath, 204],
[3, 'guichumo', 'DELETE', commentPath, 204],
[3, 'guichumo', 'PUT', function () { return '/apis/v1alpha1/roles/role-template-editor'; }, 200],
[2, 'guichumo', 'POST', function () { return '/login'; }, 200],
[2, 'guichumo', 'POST', function () { return '/logout'; }, 200],
[12, 'editor.zhang', 'PUT', postPath, 200],
[6, 'editor.zhang', 'POST', function () { return '/apis/content.halo.run/v1alpha1/posts'; }, 201],
[2, 'editor.zhang', 'POST', function () { return '/login'; }, 200],
[2, 'editor.zhang', 'POST', function () { return '/apis/storage.halo.run/v1alpha1/attachments'; }, 201],
[8, 'writer.li', 'PUT', postPath, 200],
[6, 'writer.li', 'POST', approvePath, 200],
[3, 'writer.li', 'POST', replyPath, 200],
[2, 'writer.li', 'POST', function () { return '/login'; }, 200]
var POSTS = [
{ name: 'hello-halo', title: '你好,Halo', summary: '从零开始搭建自己的写作空间。' },
{ name: 'self-host-guide', title: '自托管指南', summary: '用 Docker 部署 Halo 的完整步骤。' },
{ name: 'reading-notes-11', title: '读书笔记 #11', summary: '本周读完的三本书。' },
{ name: 'plugin-dev-diary', title: '插件开发日志', summary: '从脚手架到上架。' },
{ name: 'weekly-2026-w46', title: '每周摘要 · 2026 W46', summary: '站点一周动态。' },
{ name: 'spring-festival-2026', title: '春节计划', summary: '假期更新安排。' }
];
var TOTAL_WEIGHT = ACTIONS.reduce(function (sum, a) { return sum + a[0]; }, 0);
var PLUGINS = [
{ name: 'plugin-search-widget', displayName: '搜索组件', version: { old: '1.2.0', next: '1.3.0' } },
{ name: 'plugin-comment-widget', displayName: '评论组件', version: { old: '1.5.0', next: '1.6.0' } },
{ name: 'plugin-sitemap', displayName: 'Sitemap', version: { old: '1.0.4', next: '1.0.5' } },
{ name: 'plugin-links', displayName: '友情链接', version: { old: '2.1.1', next: '2.2.0' } }
];
function userCtx(r, name) {
var u = USERS[name];
// ---------- 文档快照(diff 用,结构贴近 Halo 扩展模型)----------
function postDoc(entry, patch) {
var spec = {
title: entry.title,
slug: entry.name,
visible: 'PUBLIC',
publish: true,
pinned: false,
allowComment: true,
summary: entry.summary
};
Object.keys(patch || {}).forEach(function (key) {
spec[key] = patch[key];
});
return {
username: name,
remoteIp: pick(r, u.ips),
userAgent: UAS[pick(r, u.uas)]
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Post',
metadata: {
name: entry.name,
labels: { 'content.halo.run/pinned': 'false' },
annotations: { 'content.halo.run/permalink-pattern': '/archives/:slug' },
version: 128,
creationTimestamp: '2026-10-01T08:00:00Z'
},
spec: spec,
status: { phase: 'PUBLISHED', permalink: '/archives/' + entry.name }
};
}
function rec(timestamp, username, method, path, statusCode, remoteIp, userAgent) {
var res = AuditCore.resolveResource(path);
function commentDoc(name, approved) {
return {
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Comment',
metadata: { name: name, version: 7 },
spec: {
raw: '写得很好,收藏了。',
owner: { displayName: '访客' + name.slice(-4), kind: 'Email' },
approved: approved,
hidden: false,
allowNotification: true
}
};
}
function pluginDoc(plugin, enabled, version) {
return {
apiVersion: 'plugin.halo.run/v1alpha1',
kind: 'Plugin',
metadata: { name: plugin.name, labels: { 'plugin.halo.run/plugin-name': plugin.name } },
spec: {
displayName: plugin.displayName,
version: version,
enabled: enabled,
author: { name: 'halo-sigs' },
requires: '>=2.20.0'
},
status: { phase: enabled ? 'STARTED' : 'DISABLED' }
};
}
// ---------- 记录组装 ----------
function recCtx(r, username) {
var u = USERS[username] || USERS.guichumo;
return {
id: null,
timestamp: timestamp,
username: username,
method: AuditCore.normalizeMethod(method),
path: path,
resourceType: res.resourceType,
resourceName: res.resourceName,
statusCode: statusCode,
remoteIp: remoteIp,
userAgent: userAgent
remoteIp: pick(r, u.ips),
userAgent: UAS[pick(r, u.uas)],
authenticated: true
};
}
function make(overrides) {
return AuditCore.buildRecord(Object.assign({
statusCode: 200,
authenticated: true,
recordChanges: true
}, overrides));
}
function postPath(name) { return '/apis/content.halo.run/v1alpha1/posts/' + name; }
function postsPath() { return '/apis/content.halo.run/v1alpha1/posts'; }
function commentPath(name) { return '/apis/content.halo.run/v1alpha1/comments/' + name; }
function pluginPath(name) { return '/apis/plugin.halo.run/v1alpha1/plugins/' + name; }
/**
* 基础操作集:[权重, 构造函数(r) → 记录输入]
* 每次构造经过 buildRecord:资源解析、语义动作、登录结果、字段 diff 与插件一致。
*/
var ACTIONS = [
[16, function (r) {
var entry = pick(r, POSTS);
var ctx = recCtx(r, pick(r, ['guichumo', 'editor.zhang', 'writer.li']));
return Object.assign(ctx, {
method: 'PUT',
path: postPath(entry.name),
previous: postDoc(entry),
body: postDoc(entry, {
title: entry.title + '(修订)',
summary: entry.summary + ' 已补充示例。'
})
});
}],
[9, function (r) {
var entry = pick(r, POSTS);
var ctx = recCtx(r, pick(r, ['guichumo', 'editor.zhang']));
return Object.assign(ctx, {
method: 'POST',
path: postPath(entry.name) + '/publish'
});
}],
[7, function (r) {
var ctx = recCtx(r, 'guichumo');
var slug = 'draft-' + hex(r, 5);
return Object.assign(ctx, {
method: 'POST',
path: postsPath(),
statusCode: 201,
body: {
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Post',
metadata: { name: slug },
spec: { title: '草稿 · ' + slug, slug: slug, visible: 'PUBLIC', publish: false }
}
});
}],
[6, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/api.console.halo.run/v1alpha1/configmaps/system',
previous: {
apiVersion: 'v1alpha1',
kind: 'ConfigMap',
metadata: { name: 'system', version: 9 },
data: { theme: 'theme-earth', locale: 'zh-CN' }
},
body: {
apiVersion: 'v1alpha1',
kind: 'ConfigMap',
metadata: { name: 'system', version: 10 },
data: { theme: 'theme-earth', locale: 'zh-CN', 'site.title': '青竹小站' }
}
});
}],
[5, function (r) {
var plugin = pick(r, PLUGINS);
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: pluginPath(plugin.name) + '/activation',
previous: pluginDoc(plugin, false, plugin.version.old),
body: pluginDoc(plugin, true, plugin.version.old)
});
}],
[5, function (r) {
var ctx = recCtx(r, pick(r, ['editor.zhang', 'writer.li']));
var name = 'attachment-' + hex(r, 6);
return Object.assign(ctx, {
method: 'POST',
path: '/apis/storage.halo.run/v1alpha1/attachments',
statusCode: 201,
body: {
apiVersion: 'storage.halo.run/v1alpha1',
kind: 'Attachment',
metadata: { name: name },
spec: { displayName: 'cover-' + hex(r, 4) + '.png', mediaType: 'image/png', size: rint(r, 80, 640) * 1024 }
}
});
}],
[3, function (r) {
var ctx = recCtx(r, 'editor.zhang');
var name = 'attachment-' + hex(r, 6);
return Object.assign(ctx, {
method: 'DELETE',
path: '/apis/storage.halo.run/v1alpha1/attachments/' + name,
statusCode: 204,
previous: {
apiVersion: 'storage.halo.run/v1alpha1',
kind: 'Attachment',
metadata: { name: name },
spec: { displayName: 'old-cover.png', mediaType: 'image/png', size: 245760 }
}
});
}],
[4, function (r) {
var ctx = recCtx(r, 'writer.li');
return Object.assign(ctx, {
method: 'POST',
path: '/apis/api.halo.run/v1alpha1/comments/comment-' + hex(r, 6) + '/reply',
body: {
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Reply',
metadata: { name: 'reply-' + hex(r, 4) },
spec: { raw: '感谢支持,已更新示例。', quoteReply: 'comment-' + hex(r, 4) }
}
});
}],
[3, function (r) {
var ctx = recCtx(r, 'editor.zhang');
var name = 'comment-' + hex(r, 6);
return Object.assign(ctx, {
method: 'DELETE',
path: commentPath(name),
statusCode: 204,
previous: commentDoc(name, true)
});
}],
[3, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/api.console.halo.run/v1alpha1/roles/role-template-editor',
previous: {
apiVersion: 'v1alpha1',
kind: 'Role',
metadata: { name: 'role-template-editor', labels: { 'rbac.authorization.halo.run/display-name': '编辑' } },
rules: [{ apiGroups: ['content.halo.run'], resources: ['posts'], verbs: ['get', 'list', 'create', 'update'] }]
},
body: {
apiVersion: 'v1alpha1',
kind: 'Role',
metadata: { name: 'role-template-editor', labels: { 'rbac.authorization.halo.run/display-name': '编辑' } },
rules: [{ apiGroups: ['content.halo.run'], resources: ['posts'], verbs: ['get', 'list', 'create', 'update', 'delete'] }]
}
});
}],
[2, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'POST',
path: '/apis/api.console.halo.run/v1alpha1/users',
statusCode: 201,
body: {
apiVersion: 'v1alpha1',
kind: 'User',
metadata: { name: 'alice-' + hex(r, 4) },
spec: {
displayName: 'Alice',
email: 'alice-' + hex(r, 3) + '@example.com',
// 运行时生成的假口令:用于验证 spec.password 在 diff 中被脱敏
password: demoSecret(r),
roles: ['role-template-author']
}
}
});
}],
[2, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/api.console.halo.run/v1alpha1/users/guichumo/password',
previous: {
apiVersion: 'v1alpha1',
kind: 'User',
metadata: { name: 'guichumo' },
spec: { password: demoSecret(r) }
},
body: {
apiVersion: 'v1alpha1',
kind: 'User',
metadata: { name: 'guichumo' },
spec: { password: demoSecret(r) }
}
});
}],
[2, function (r) {
var ctx = recCtx(r, 'writer.li');
return Object.assign(ctx, {
method: 'POST',
path: '/apis/content.halo.run/v1alpha1/comments/comment-' + hex(r, 6) + '/approve'
});
}],
[2, function (r) {
var ctx = recCtx(r, 'editor.zhang');
return Object.assign(ctx, {
method: 'POST',
path: '/apis/api.console.halo.run/v1alpha1/categories',
statusCode: 201,
body: {
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Category',
metadata: { name: 'category-' + hex(r, 4) },
spec: { displayName: '技术随笔', slug: 'tech-notes', priority: 10 }
}
});
}],
[2, function (r) {
var ctx = recCtx(r, 'editor.zhang');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/theme.halo.run/v1alpha1/themes/theme-earth/activation'
});
}],
[1, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/api.halo.run/v1alpha1/settings/basic'
});
}],
[1, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'POST',
path: '/apis/api.halo.run/v1alpha1/tags',
statusCode: 201,
body: {
apiVersion: 'content.halo.run/v1alpha1',
kind: 'Tag',
metadata: { name: 'tag-' + hex(r, 4) },
spec: { displayName: 'Halo', slug: 'halo' }
}
});
}],
[1, function (r) {
var ctx = recCtx(r, 'guichumo');
return Object.assign(ctx, {
method: 'PUT',
path: '/apis/api.halo.run/v1alpha1/menus/menu-primary',
previous: {
apiVersion: 'v1alpha1',
kind: 'Menu',
metadata: { name: 'menu-primary' },
spec: { displayName: '主菜单', menuItems: ['/archives', '/categories'] }
},
body: {
apiVersion: 'v1alpha1',
kind: 'Menu',
metadata: { name: 'menu-primary' },
spec: { displayName: '主菜单', menuItems: ['/archives', '/categories', '/about'] }
}
});
}]
];
var TOTAL_WEIGHT = ACTIONS.reduce(function (sum, item) { return sum + item[0]; }, 0);
/**
* 生成模拟审计日志(按时间倒序,id 从旧到新递增)
* @param {number} [now] 当前时间戳(默认 Date.now()),测试传固定值保证确定性
* @returns {Array}
*/
function generateLogs(now) {
if (typeof now !== 'number') now = Date.now();
var r = mulberry32(20261121);
if (typeof now !== 'number') {
now = Date.now();
}
var r = mulberry32(20261122);
var logs = [];
// 基础记录:均匀散布在近 90 天
for (var i = 0; i < BASE_COUNT; i++) {
var roll = r() * TOTAL_WEIGHT;
var action = ACTIONS[0];
for (var j = 0; j < ACTIONS.length; j++) {
roll -= ACTIONS[j][0];
if (roll <= 0) { action = ACTIONS[j]; break; }
}
var ctx = userCtx(r, action[1]);
var time = now - rint(r, 5 * MIN, 90 * DAY);
logs.push(rec(
new Date(time).toISOString(), ctx.username,
action[2], action[3](r), action[4],
ctx.remoteIp, ctx.userAgent
));
function add(record) {
logs.push(record);
return record;
}
// ---- 故事线(固定时间锚点)----
// ---- 基础记录:均匀散布在近 90 天 ----
for (var i = 0; i < BASE_COUNT; i++) {
var roll = r() * TOTAL_WEIGHT;
var action = ACTIONS[0][1];
for (var j = 0; j < ACTIONS.length; j++) {
roll -= ACTIONS[j][0];
if (roll <= 0) {
action = ACTIONS[j][1];
break;
}
}
var input = action(r);
input.timestamp = new Date(now - rint(r, 5 * MIN, 90 * DAY)).toISOString();
add(make(input));
}
// 1. 攻击者爆破登录:20 天前,同一 IP 6 次失败,UA 为 python-requests
var burstBase = now - 20 * DAY - 3600 * 1000 * 3; // 约 20 天前的凌晨
[0, 41, 88, 135, 210, 400].forEach(function (off) {
logs.push(rec(
new Date(burstBase + off * 1000).toISOString(), '未知用户',
'POST', '/login', 401, '203.0.113.66', UAS.bot
));
// ---- 故事线 1:排查「hello-halo 这篇文章谁改过」 ----
var hello = POSTS[0];
add(make({
username: 'editor.zhang',
remoteIp: '116.24.65.201',
userAgent: UAS.edge,
method: 'PUT',
path: postPath(hello.name),
timestamp: new Date(now - 6 * DAY - 3 * 3600 * 1000).toISOString(),
previous: postDoc(hello),
body: postDoc(hello, { title: '你好,Halo(补充开箱截图)', summary: '从零开始搭建自己的写作空间,附开箱截图。' })
}));
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'PUT',
path: postPath(hello.name),
timestamp: new Date(now - 2 * DAY - 5 * 3600 * 1000).toISOString(),
previous: postDoc(hello, { title: '你好,Halo(补充开箱截图)' }),
body: postDoc(hello, { title: '你好,Halo', summary: '从零开始搭建自己的写作空间。', visible: 'PRIVATE' })
}));
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'PUT',
path: postPath(hello.name),
timestamp: new Date(now - 2 * DAY - 2 * 3600 * 1000).toISOString(),
previous: postDoc(hello, { visible: 'PRIVATE' }),
body: postDoc(hello, { visible: 'PUBLIC', pinned: true })
}));
// ---- 故事线 2:登录爆破回溯(同一 IP 无差别撞库 + 失败回显) ----
var burstBase = now - 20 * DAY - 3 * 3600 * 1000;
var attackAccounts = ['admin', 'root', 'oracle', 'test', 'admin', 'postgres'];
attackAccounts.forEach(function (account, idx) {
add(make({
method: 'POST',
path: '/login',
statusCode: 302,
location: '/login?error=invalid-credential&method=form',
attemptedUsername: account,
remoteIp: '203.0.113.66',
userAgent: UAS.bot,
timestamp: new Date(burstBase + [0, 41, 88, 135, 210, 400][idx] * 1000).toISOString()
}));
});
// 浏览器随后渲染失败回显页(GET,HTTP 200):审计标注 login-failure,红色「失败」
add(make({
method: 'GET',
path: '/login?error=invalid-credential&method=form',
statusCode: 200,
remoteIp: '203.0.113.66',
userAgent: UAS.bot,
timestamp: new Date(burstBase + 401 * 1000).toISOString()
}));
// 2. 站长忘记密码:12 天前输错两次后登录成功
var b2 = now - 12 * DAY - 3600 * 1000 * 10;
[[0, 401], [97, 401], [180, 200]].forEach(function (pair) {
var ctx = { remoteIp: '192.168.1.23', userAgent: UAS.chrome };
logs.push(rec(
new Date(b2 + pair[0] * 1000).toISOString(),
pair[1] === 200 ? 'guichumo' : '未知用户',
'POST', '/login', pair[1], ctx.remoteIp, ctx.userAgent
));
// ---- 故事线 3:忘记密码(失败两次后成功) ----
var retryBase = now - 12 * DAY - 10 * 3600 * 1000;
[
{ at: 0, account: 'guichumo', ok: false },
{ at: 97, account: 'guichumo', ok: false },
{ at: 180, account: 'guichumo', ok: true }
].forEach(function (step) {
add(make({
username: 'guichumo',
method: 'POST',
path: '/login',
statusCode: 302,
location: step.ok ? '/uc' : '/login?error=bad-credentials&method=form',
attemptedUsername: step.account,
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
timestamp: new Date(retryBase + step.at * 1000).toISOString()
}));
});
add(make({
username: 'guichumo',
method: 'POST',
path: '/login',
statusCode: 302,
location: '/challenges/two-factor/totp',
attemptedUsername: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
timestamp: new Date(now - 9 * DAY - 8 * 3600 * 1000).toISOString()
}));
add(make({
username: 'guichumo',
method: 'POST',
path: '/logout',
statusCode: 302,
location: '/login?logout',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
timestamp: new Date(now - 4 * DAY - 11 * 3600 * 1000).toISOString()
}));
// 3. 越权尝试:8 天前 editor.zhang 尝试修改系统设置被拒绝
logs.push(rec(
new Date(now - 8 * DAY - 3600 * 1000 * 14).toISOString(), 'editor.zhang',
'PUT', '/apis/v1alpha1/configmaps/system', 403, '116.24.65.201', UAS.edge
));
// ---- 故事线 4:定时发布(系统内部变更:无 IP/UA,执行者「系统」) ----
add(AuditCore.buildSystemRecord({
id: 'auditlog-system-0001',
timestamp: new Date(now - DAY - 5 * 3600 * 1000).toISOString(),
method: 'PUT',
resourceType: 'posts',
resourceName: 'weekly-2026-w46',
path: '/apis/content.halo.run/v1alpha1/posts/weekly-2026-w46',
changes: [
{ field: 'spec.publish', changeType: 'UPDATED', oldValue: 'false', newValue: 'true' },
{ field: 'spec.publishTime', changeType: 'ADDED', oldValue: null, newValue: '2026-11-21T02:00:00Z' }
]
}));
add(AuditCore.buildSystemRecord({
id: 'auditlog-system-0002',
timestamp: new Date(now - 3 * DAY - 4 * 3600 * 1000).toISOString(),
method: 'DELETE',
resourceType: 'posts',
resourceName: 'draft-night-notes',
path: '/apis/content.halo.run/v1alpha1/posts/draft-night-notes',
changes: [
{ field: 'spec.title', changeType: 'REMOVED', oldValue: '夜间随笔(未发布)', newValue: null },
{ field: 'metadata.name', changeType: 'REMOVED', oldValue: 'draft-night-notes', newValue: null }
]
}));
// 4. 权限不足:5 天前 writer.li 尝试删除评论被拒绝
logs.push(rec(
new Date(now - 5 * DAY - 3600 * 1000 * 9).toISOString(), 'writer.li',
'DELETE', '/apis/content.halo.run/v1alpha1/comments/comment-a3f802', 403, '120.79.10.45', UAS.safari
));
// ---- 故事线 5:插件生命周期(升级 / 停用 / 卸载) ----
var search = PLUGINS[0];
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'PUT',
path: pluginPath(search.name) + '/upgrade',
previous: pluginDoc(search, true, search.version.old),
body: pluginDoc(search, true, search.version.next),
timestamp: new Date(now - 7 * DAY - 6 * 3600 * 1000).toISOString()
}));
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'PUT',
path: pluginPath(search.name) + '/activation',
previous: pluginDoc(search, true, search.version.next),
body: pluginDoc(search, false, search.version.next),
timestamp: new Date(now - 6 * DAY - 9 * 3600 * 1000).toISOString()
}));
var links = PLUGINS[3];
add(make({
username: 'guichumo',
remoteIp: '116.24.65.187',
userAgent: UAS.edge,
method: 'DELETE',
path: pluginPath(links.name) + '/uninstall',
statusCode: 204,
previous: pluginDoc(links, true, links.version.next),
timestamp: new Date(now - 1 * DAY - 7 * 3600 * 1000).toISOString()
}));
// 5. 资源不存在:3 天前删除一个已不存在的附件
logs.push(rec(
new Date(now - 3 * DAY - 3600 * 1000 * 20).toISOString(), 'guichumo',
'DELETE', '/apis/storage.halo.run/v1alpha1/attachments/attachment-dead42', 404, '192.168.1.23', UAS.chrome
));
// ---- 故事线 6:越权与异常 ----
add(make({
username: 'editor.zhang',
remoteIp: '116.24.65.201',
userAgent: UAS.edge,
method: 'PUT',
path: '/apis/api.console.halo.run/v1alpha1/configmaps/system',
statusCode: 403,
timestamp: new Date(now - 8 * DAY - 14 * 3600 * 1000).toISOString()
}));
add(make({
username: 'writer.li',
remoteIp: '120.79.10.45',
userAgent: UAS.safari,
method: 'DELETE',
path: commentPath('comment-a3f802'),
statusCode: 403,
timestamp: new Date(now - 5 * DAY - 9 * 3600 * 1000).toISOString()
}));
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'DELETE',
path: '/apis/storage.halo.run/v1alpha1/attachments/attachment-dead42',
statusCode: 404,
timestamp: new Date(now - 3 * DAY - 20 * 3600 * 1000).toISOString()
}));
add(make({
username: 'writer.li',
remoteIp: '120.79.10.45',
userAgent: UAS.chrome,
method: 'POST',
path: '/apis/api.content.halo.run/v1alpha1/posts/self-host-guide/publish',
statusCode: 500,
timestamp: new Date(now - 2 * DAY - 6 * 3600 * 1000).toISOString()
}));
// 6. 服务端异常:2 天前发布文章返回 500
logs.push(rec(
new Date(now - 2 * DAY - 3600 * 1000 * 6).toISOString(), 'writer.li',
'POST', '/apis/api.content.halo.run/v1alpha1/posts/self-host-guide/publish', 500, '120.79.10.45', UAS.chrome
));
// ---- 故事线 7:误操作定位(删除文章,含字段 diff) ----
var deleted = { name: 'weekly-2026-w45', title: '每周摘要 · 2026 W45', summary: '站点一周动态。' };
add(make({
username: 'guichumo',
remoteIp: '192.168.1.23',
userAgent: UAS.chrome,
method: 'DELETE',
path: postPath(deleted.name),
statusCode: 204,
previous: postDoc(deleted),
timestamp: new Date(now - DAY - 2 * 3600 * 1000).toISOString()
}));
// 7. 误操作定位:1 天前删除了一篇文章
logs.push(rec(
new Date(now - DAY - 3600 * 1000 * 2).toISOString(), 'guichumo',
'DELETE', '/apis/content.halo.run/v1alpha1/posts/weekly-2026-w45', 204, '192.168.1.23', UAS.chrome
));
// 排序 + 分配 id(最新记录 id 数字最大)
// ---- 排序 + 分配记录标识(最新记录编号最大) ----
logs.sort(function (a, b) {
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
});
logs.forEach(function (l, idx) {
l.id = 'audit-' + String(logs.length - idx).padStart(4, '0');
logs.forEach(function (log, idx) {
if (!log.id || log.id.indexOf('auditlog-system-') !== 0) {
log.id = 'auditlog-' + String(logs.length - idx).padStart(4, '0');
}
});
return logs;
}