fix: 安全更新,备份数据库插件仅限管理员运行

v2^2
xiaojunnuo 2025-07-22 11:51:27 +08:00
parent 9d9cd8a362
commit 13dfca1749
8 changed files with 25 additions and 6 deletions

View File

@ -59,6 +59,7 @@ export type PluginDefine = Registrable & {
form: any;
};
};
onlyAdmin?: boolean;
needPlus?: boolean;
showRunStrategy?: boolean;
pluginType?: string; //类型
@ -162,6 +163,14 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
this.registerSecret(cert.key);
this.registerSecret(cert.one);
}
debugger
// @ts-ignore
if (this.ctx.step.onlyAdmin) {
if (!this.isAdmin()) {
throw new Error("只有管理员才能运行此任务");
}
}
}
async getAccess<T = any>(accessId: string | number, isCommon = false) {

View File

@ -30,4 +30,5 @@ export const pluginGroups = {
qiniu: new PluginGroup("qiniu", "七牛云", 5, "svg:icon-qiniuyun"),
aws: new PluginGroup("aws", "亚马逊云", 6, "svg:icon-aws"),
other: new PluginGroup("other", "其他", 10, "clarity:plugin-line"),
admin: new PluginGroup("admin", "管理", 11, "ion:settings-outline"),
};

View File

@ -30,3 +30,4 @@ export * from './plugin-github/index.js'
export * from './plugin-namesilo/index.js'
export * from './plugin-proxmox/index.js'
export * from './plugin-wangsu/index.js'
export * from './plugin-admin/index.js'

View File

@ -0,0 +1,3 @@
export * from './plugin-restart.js';
export * from './plugin-script.js';
export * from './plugin-db-backup.js';

View File

@ -14,14 +14,15 @@ const defaultFilePrefix = 'db_backup';
name: 'DBBackupPlugin',
title: '数据库备份',
icon: 'lucide:database-backup',
desc: '仅支持备份SQLite数据库',
group: pluginGroups.other.key,
desc: '【仅管理员可用】仅支持备份SQLite数据库',
group: pluginGroups.admin.key,
showRunStrategy: true,
default: {
strategy: {
runStrategy: RunStrategy.AlwaysRun,
},
},
onlyAdmin:true,
needPlus: true,
})
export class DBBackupPlugin extends AbstractPlusTaskPlugin {
@ -157,6 +158,11 @@ export class DBBackupPlugin extends AbstractPlusTaskPlugin {
}
async execute(): Promise<void> {
if (!this.isAdmin()) {
throw new Error('只有管理员才能运行此任务');
}
this.logger.info('开始备份数据库');
let dbPath = process.env.certd_typeorm_dataSource_default_database;

View File

@ -1,5 +1,5 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy } from '@certd/pipeline';
import { httpsServer } from '../../../modules/auto/https/server.js';
import { httpsServer } from '../../modules/auto/https/server.js';
@IsTaskPlugin({
name: 'RestartCertd',
@ -7,6 +7,7 @@ import { httpsServer } from '../../../modules/auto/https/server.js';
icon: 'mdi:restart',
desc: '【仅管理员可用】 重启 certd的https服务用于更新 Certd 的 ssl 证书',
group: pluginGroups.other.key,
onlyAdmin:true,
default: {
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,

View File

@ -13,6 +13,7 @@ export type CustomScriptContext = {
desc: '【仅管理员】运行自定义js脚本执行',
group: pluginGroups.other.key,
showRunStrategy: true,
onlyAdmin: true,
default: {
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,

View File

@ -1,5 +1,2 @@
export * from './plugin-restart.js';
export * from './plugin-script.js';
export * from './plugin-wait.js';
export * from './plugin-db-backup.js';
export * from './plugin-deploy-to-mail.js';