chore: 完善审计日志

This commit is contained in:
xiaojunnuo
2026-07-19 00:49:38 +08:00
parent eee22154e3
commit ce4839bd80
14 changed files with 43 additions and 29 deletions
+1
View File
@@ -229,5 +229,6 @@ Certd 是可私有化部署的 SSL/TLS 证书自动化管理平台,提供 Web
- 审计日志是 Plus 版功能,非 Plus 版不会写入。 - 审计日志是 Plus 版功能,非 Plus 版不会写入。
- Controller 继承 `BaseController`,通过 `this.auditLog({ content: "xxx" })` 记录日志。 - Controller 继承 `BaseController`,通过 `this.auditLog({ content: "xxx" })` 记录日志。
- Controller 中的 `@Post("/add", { summary: "xxxx" })`, 这个summary是必须要的,他是日志action字段的来源
- `getAuditType()` 返回类型常量,中间件自动从 ctx.path 判定 scope`/api/sys/` → system,其他 → user)。 - `getAuditType()` 返回类型常量,中间件自动从 ctx.path 判定 scope`/api/sys/` → system,其他 → user)。
- 操作日志有系统级(scope=system)和用户级(scope=user)区分。 - 操作日志有系统级(scope=system)和用户级(scope=user)区分。
@@ -37,12 +37,12 @@ export class SysAccessController extends AccessController {
return await super.list(body); return await super.list(body);
} }
@Post("/add", { description: "sys:settings:edit" }) @Post("/add", { description: "sys:settings:edit", summary: "添加系统授权配置" })
async add(@Body(ALL) bean: any) { async add(@Body(ALL) bean: any) {
return await super.add(bean); return await super.add(bean);
} }
@Post("/update", { description: "sys:settings:edit" }) @Post("/update", { description: "sys:settings:edit", summary: "更新系统授权配置" })
async update(@Body(ALL) bean: any) { async update(@Body(ALL) bean: any) {
return await super.update(bean); return await super.update(bean);
} }
@@ -51,7 +51,7 @@ export class SysAccessController extends AccessController {
return await super.info(id); return await super.info(id);
} }
@Post("/delete", { description: "sys:settings:edit" }) @Post("/delete", { description: "sys:settings:edit", summary: "删除系统授权配置" })
async delete(@Query("id") id: number) { async delete(@Query("id") id: number) {
return await super.delete(id); return await super.delete(id);
} }
@@ -29,7 +29,6 @@ export class BasicController extends BaseController {
throw new Error("用户ID不能为空"); throw new Error("用户ID不能为空");
} }
await this.plusService.userPreBind(body.userId); await this.plusService.userPreBind(body.userId);
await this.auditLog({ content: `预绑定了用户(ID:${body.userId})` });
return this.ok({}); return this.ok({});
} }
@@ -41,7 +40,7 @@ export class BasicController extends BaseController {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo); const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
installInfo.bindUserId = body.userId; installInfo.bindUserId = body.userId;
await this.sysSettingsService.saveSetting(installInfo); await this.sysSettingsService.saveSetting(installInfo);
await this.auditLog({ content: `绑定了用户(ID:${body.userId})` }); await this.auditLog({ content: `绑定了袖手科技用户(ID:${body.userId})` });
return this.ok({}); return this.ok({});
} }
@@ -50,14 +49,13 @@ export class BasicController extends BaseController {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo); const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
installInfo.bindUserId = null; installInfo.bindUserId = null;
await this.sysSettingsService.saveSetting(installInfo); await this.sysSettingsService.saveSetting(installInfo);
await this.auditLog({ content: "解绑了用户" }); await this.auditLog({ content: "解绑了袖手科技用户" });
return this.ok({}); return this.ok({});
} }
@Post("/updateLicense", { description: "sys:settings:edit", summary: "更新许可证" }) @Post("/updateLicense", { description: "sys:settings:edit", summary: "更新许可证" })
public async updateLicense(@Body(ALL) body: { license: string }) { public async updateLicense(@Body(ALL) body: { license: string }) {
await this.plusService.updateLicense(body.license); await this.plusService.updateLicense(body.license);
await this.auditLog({ content: "更新了许可证" });
return this.ok(true); return this.ok(true);
} }
} }
@@ -36,10 +36,10 @@ export class SysSettingsController extends BaseController {
/** /**
* 立即隐藏 * 立即隐藏
*/ */
@Post("/hidden", { description: "sys:settings:edit", summary: "立刻隐藏系统" }) @Post("/hidden", { description: "sys:settings:edit", summary: "隐藏系统" })
async hiddenImmediate() { async hiddenImmediate() {
await this.safeService.hiddenImmediately(); await this.safeService.hiddenImmediately();
await this.auditLog({ content: "立刻隐藏了系统" }); await this.auditLog({ content: "隐藏了系统" });
return this.ok({}); return this.ok({});
} }
} }
@@ -68,7 +68,7 @@ export class UserProjectController extends BaseController {
async applyJoin(@Body(ALL) body: any) { async applyJoin(@Body(ALL) body: any) {
const userId = this.getUserId(); const userId = this.getUserId();
const res = await this.service.applyJoin({ userId, projectId: body.projectId }); const res = await this.service.applyJoin({ userId, projectId: body.projectId });
this.auditLog({ content: "申请了加入项目" }); this.auditLog({ content: `申请了加入项目 项目ID:${body.projectId}` });
return this.ok(res); return this.ok(res);
} }
@@ -90,7 +90,7 @@ export class UserProjectController extends BaseController {
status, status,
permission, permission,
}); });
this.auditLog({ content: "更新了项目成员" }); this.auditLog({ content: `更新了项目成员 「项目ID:${projectId} 用户ID:${userId}` });
return this.ok(res); return this.ok(res);
} }
@@ -99,7 +99,7 @@ export class UserProjectController extends BaseController {
const { projectId } = await this.getProjectUserIdAdmin(); const { projectId } = await this.getProjectUserIdAdmin();
const { status, permission, userId } = body; const { status, permission, userId } = body;
const res = await this.service.approveJoin({ userId, projectId: projectId, status, permission }); const res = await this.service.approveJoin({ userId, projectId: projectId, status, permission });
this.auditLog({ content: "审批了加入项目申请" }); this.auditLog({ content: `审批了加入项目申请 「项目ID:${projectId} 用户ID:${userId}` });
return this.ok(res); return this.ok(res);
} }
@@ -110,7 +110,7 @@ export class UserProjectController extends BaseController {
projectId, projectId,
userId: body.userId, userId: body.userId,
}); });
this.auditLog({ content: "删除了项目成员" }); this.auditLog({ content: `删除了项目成员 「项目ID:${projectId} 用户ID:${body.userId}` });
return this.ok(); return this.ok();
} }
@@ -122,7 +122,7 @@ export class UserProjectController extends BaseController {
projectId, projectId,
userId, userId,
}); });
this.auditLog({ content: "离开了项目" }); this.auditLog({ content: `离开了项目 「项目ID:${projectId} 用户ID:${userId}` });
return this.ok(); return this.ok();
} }
} }
@@ -43,7 +43,7 @@ export class TransferController extends BaseController {
const { projectId } = await this.getProjectUserIdRead(); const { projectId } = await this.getProjectUserIdRead();
const userId = this.getUserId(); const userId = this.getUserId();
await this.service.transferAll(userId, projectId); await this.service.transferAll(userId, projectId);
this.auditLog({ content: "迁移了项目资源" }); this.auditLog({ content: `迁移了项目资源 「用户ID:${userId} -> 项目ID:${projectId}` });
return this.ok(); return this.ok();
} }
} }
@@ -22,7 +22,7 @@ export class EmailController extends BaseController {
public async test(@Body("receiver") receiver) { public async test(@Body("receiver") receiver) {
const userId = super.getUserId(); const userId = super.getUserId();
await this.emailService.test(userId, receiver); await this.emailService.test(userId, receiver);
this.auditLog({ content: "测试邮件发送" }); this.auditLog({ content: "测试邮件发送" });
return this.ok({}); return this.ok({});
} }
@@ -37,7 +37,7 @@ export class EmailController extends BaseController {
public async add(@Body("email") email) { public async add(@Body("email") email) {
const userId = super.getUserId(); const userId = super.getUserId();
await this.emailService.add(userId, email); await this.emailService.add(userId, email);
this.auditLog({ content: "添加了邮件" }); this.auditLog({ content: `添加了邮箱地址 「${email}` });
return this.ok({}); return this.ok({});
} }
@@ -45,7 +45,7 @@ export class EmailController extends BaseController {
public async delete(@Body("email") email) { public async delete(@Body("email") email) {
const userId = super.getUserId(); const userId = super.getUserId();
await this.emailService.delete(userId, email); await this.emailService.delete(userId, email);
this.auditLog({ content: "删除了邮件" }); this.auditLog({ content: `删除了邮箱地址 「${email}` });
return this.ok({}); return this.ok({});
} }
} }
@@ -101,7 +101,7 @@ export class MineController extends BaseController {
avatar: body.avatar, avatar: body.avatar,
nickName: body.nickName, nickName: body.nickName,
}); });
this.auditLog({ content: "更新了个人资料" }); this.auditLog({ content: `更新了个人资料` });
return this.ok({}); return this.ok({});
} }
@@ -140,10 +140,16 @@ export class MineController extends BaseController {
phoneCode: body.phoneCode, phoneCode: body.phoneCode,
mobile: body.mobile, mobile: body.mobile,
}); });
this.auditLog({ content: "修改了手机号" }); //手机号脱敏处理
const mobile = this.maskPhone(body.mobile);
this.auditLog({ content: `修改了手机号 「${mobile}` });
return this.ok({}); return this.ok({});
} }
private maskPhone(phone: string) {
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
}
@Post("/contact/email", { description: Constants.per.authOnly, summary: "绑定或修改邮箱" }) @Post("/contact/email", { description: Constants.per.authOnly, summary: "绑定或修改邮箱" })
public async updateEmail(@Body(ALL) body: { email: string; validateCode: string; identityValidationCode: string }) { public async updateEmail(@Body(ALL) body: { email: string; validateCode: string; identityValidationCode: string }) {
const userId = this.getUserId(); const userId = this.getUserId();
@@ -157,7 +163,7 @@ export class MineController extends BaseController {
await this.userService.updateEmail(userId, { await this.userService.updateEmail(userId, {
email: body.email, email: body.email,
}); });
this.auditLog({ content: "修改了邮箱" }); this.auditLog({ content: `修改了邮箱地址 「${body.email}` });
return this.ok({}); return this.ok({});
} }
@@ -67,7 +67,7 @@ export class MinePasskeyController extends BaseController {
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx); const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
this.auditLog({ content: "注册了Passkey" }); this.auditLog({ content: `注册了Passkey ${deviceName}` });
return this.ok(result); return this.ok(result);
} }
@@ -96,7 +96,7 @@ export class MinePasskeyController extends BaseController {
} }
await this.passkeyService.delete([passkey.id]); await this.passkeyService.delete([passkey.id]);
this.auditLog({ content: "解绑了Passkey" }); this.auditLog({ content: `解绑了Passkey ${passkey.deviceName}` });
return this.ok({}); return this.ok({});
} }
} }
@@ -47,7 +47,7 @@ export class UserTwoFactorSettingController extends BaseController {
} }
await this.service.saveSetting(userId, null, setting); await this.service.saveSetting(userId, null, setting);
this.auditLog({ content: "保存了双因子认证设置" }); this.auditLog({ content: `保存了双因子认证设置 ${setting.authenticator.enabled ? "启用" : "禁用"}` });
return this.ok({}); return this.ok({});
} }
@@ -68,7 +68,7 @@ export class UserTwoFactorSettingController extends BaseController {
userId, userId,
verifyCode: bean.verifyCode, verifyCode: bean.verifyCode,
}); });
this.auditLog({ content: "保存了验证器设置" }); this.auditLog({ content: `保存了验证器设置` });
return this.ok(); return this.ok();
} }
@@ -94,7 +94,7 @@ export class UserSettingsController extends CrudController<UserSettingsService>
merge(setting, bean); merge(setting, bean);
await this.service.saveSetting(userId, null, setting); await this.service.saveSetting(userId, null, setting);
this.auditLog({ content: "保存了授权设置" }); this.auditLog({ content: `保存了授权设置${setting.allowAdminViewCerts ? "允许管理员查看证书" : "禁止管理员查看证书"}` });
return this.ok({}); return this.ok({});
} }
} }
@@ -111,7 +111,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
await this.checkOwner(this.service, id, "write"); await this.checkOwner(this.service, id, "write");
const res = await super.delete(id); const res = await super.delete(id);
this.auditLog({ this.auditLog({
content: `删除了站点监控(ID:${id})`, content: `删除了站点监控ID:${id}`,
}); });
return res; return res;
} }
@@ -150,7 +150,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
userId, userId,
projectId, projectId,
}); });
this.auditLog({ content: "导入了站点监控" }); this.auditLog({ content: `导入了站点监控${body.text}` });
return this.ok(); return this.ok();
} }
@@ -222,6 +222,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
id: bean.id, id: bean.id,
disabled: bean.disabled, disabled: bean.disabled,
}); });
this.auditLog({ content: `${bean.disabled ? "禁用" : "启用"}` });
return this.ok(); return this.ok();
} }
@@ -239,6 +240,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
merge(setting, bean); merge(setting, bean);
await this.service.saveSetting(userId, projectId, setting); await this.service.saveSetting(userId, projectId, setting);
this.auditLog({});
return this.ok({}); return this.ok({});
} }
} }
@@ -132,7 +132,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
siteId: body.siteId, siteId: body.siteId,
projectId, projectId,
}); });
this.auditLog({ content: "导入了站点IP" }); this.auditLog({ content: `导入了站点IP${body.text}` });
return this.ok(); return this.ok();
} }
} }
@@ -25,6 +25,13 @@ export const AuditType = {
jobHistory: { value: "jobHistory", label: "监控历史", color: "default" }, jobHistory: { value: "jobHistory", label: "监控历史", color: "default" },
account: { value: "account", label: "账号管理", color: "geekblue" }, account: { value: "account", label: "账号管理", color: "geekblue" },
plus: { value: "plus", label: "Plus许可", color: "volcano" }, plus: { value: "plus", label: "Plus许可", color: "volcano" },
site: { value: "site", label: "站点设置", color: "blue" },
wallet: { value: "wallet", label: "钱包管理", color: "gold" },
invite: { value: "invite", label: "邀请管理", color: "cyan" },
trade: { value: "trade", label: "交易订单", color: "volcano" },
product: { value: "product", label: "产品管理", color: "purple" },
activationCode: { value: "activationCode", label: "激活码管理", color: "orange" },
userSuite: { value: "userSuite", label: "用户套餐", color: "geekblue" },
} as const; } as const;
export const AuditAction = { export const AuditAction = {