mirror of https://github.com/certd/certd
fix: 安全更新,备份数据库插件仅限管理员运行
parent
9d9cd8a362
commit
13dfca1749
|
@ -59,6 +59,7 @@ export type PluginDefine = Registrable & {
|
||||||
form: any;
|
form: any;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
onlyAdmin?: boolean;
|
||||||
needPlus?: boolean;
|
needPlus?: boolean;
|
||||||
showRunStrategy?: boolean;
|
showRunStrategy?: boolean;
|
||||||
pluginType?: string; //类型
|
pluginType?: string; //类型
|
||||||
|
@ -162,6 +163,14 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
||||||
this.registerSecret(cert.key);
|
this.registerSecret(cert.key);
|
||||||
this.registerSecret(cert.one);
|
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) {
|
async getAccess<T = any>(accessId: string | number, isCommon = false) {
|
||||||
|
|
|
@ -30,4 +30,5 @@ export const pluginGroups = {
|
||||||
qiniu: new PluginGroup("qiniu", "七牛云", 5, "svg:icon-qiniuyun"),
|
qiniu: new PluginGroup("qiniu", "七牛云", 5, "svg:icon-qiniuyun"),
|
||||||
aws: new PluginGroup("aws", "亚马逊云", 6, "svg:icon-aws"),
|
aws: new PluginGroup("aws", "亚马逊云", 6, "svg:icon-aws"),
|
||||||
other: new PluginGroup("other", "其他", 10, "clarity:plugin-line"),
|
other: new PluginGroup("other", "其他", 10, "clarity:plugin-line"),
|
||||||
|
admin: new PluginGroup("admin", "管理", 11, "ion:settings-outline"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,3 +30,4 @@ export * from './plugin-github/index.js'
|
||||||
export * from './plugin-namesilo/index.js'
|
export * from './plugin-namesilo/index.js'
|
||||||
export * from './plugin-proxmox/index.js'
|
export * from './plugin-proxmox/index.js'
|
||||||
export * from './plugin-wangsu/index.js'
|
export * from './plugin-wangsu/index.js'
|
||||||
|
export * from './plugin-admin/index.js'
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './plugin-restart.js';
|
||||||
|
export * from './plugin-script.js';
|
||||||
|
export * from './plugin-db-backup.js';
|
|
@ -14,14 +14,15 @@ const defaultFilePrefix = 'db_backup';
|
||||||
name: 'DBBackupPlugin',
|
name: 'DBBackupPlugin',
|
||||||
title: '数据库备份',
|
title: '数据库备份',
|
||||||
icon: 'lucide:database-backup',
|
icon: 'lucide:database-backup',
|
||||||
desc: '仅支持备份SQLite数据库',
|
desc: '【仅管理员可用】仅支持备份SQLite数据库',
|
||||||
group: pluginGroups.other.key,
|
group: pluginGroups.admin.key,
|
||||||
showRunStrategy: true,
|
showRunStrategy: true,
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.AlwaysRun,
|
runStrategy: RunStrategy.AlwaysRun,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
onlyAdmin:true,
|
||||||
needPlus: true,
|
needPlus: true,
|
||||||
})
|
})
|
||||||
export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
||||||
|
@ -157,6 +158,11 @@ export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
|
|
||||||
|
if (!this.isAdmin()) {
|
||||||
|
throw new Error('只有管理员才能运行此任务');
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.info('开始备份数据库');
|
this.logger.info('开始备份数据库');
|
||||||
|
|
||||||
let dbPath = process.env.certd_typeorm_dataSource_default_database;
|
let dbPath = process.env.certd_typeorm_dataSource_default_database;
|
|
@ -1,5 +1,5 @@
|
||||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy } from '@certd/pipeline';
|
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({
|
@IsTaskPlugin({
|
||||||
name: 'RestartCertd',
|
name: 'RestartCertd',
|
||||||
|
@ -7,6 +7,7 @@ import { httpsServer } from '../../../modules/auto/https/server.js';
|
||||||
icon: 'mdi:restart',
|
icon: 'mdi:restart',
|
||||||
desc: '【仅管理员可用】 重启 certd的https服务,用于更新 Certd 的 ssl 证书',
|
desc: '【仅管理员可用】 重启 certd的https服务,用于更新 Certd 的 ssl 证书',
|
||||||
group: pluginGroups.other.key,
|
group: pluginGroups.other.key,
|
||||||
|
onlyAdmin:true,
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
|
@ -13,6 +13,7 @@ export type CustomScriptContext = {
|
||||||
desc: '【仅管理员】运行自定义js脚本执行',
|
desc: '【仅管理员】运行自定义js脚本执行',
|
||||||
group: pluginGroups.other.key,
|
group: pluginGroups.other.key,
|
||||||
showRunStrategy: true,
|
showRunStrategy: true,
|
||||||
|
onlyAdmin: true,
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
|
@ -1,5 +1,2 @@
|
||||||
export * from './plugin-restart.js';
|
|
||||||
export * from './plugin-script.js';
|
|
||||||
export * from './plugin-wait.js';
|
export * from './plugin-wait.js';
|
||||||
export * from './plugin-db-backup.js';
|
|
||||||
export * from './plugin-deploy-to-mail.js';
|
export * from './plugin-deploy-to-mail.js';
|
||||||
|
|
Loading…
Reference in New Issue