mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +08:00
perf: 群晖支持刷新登录有效期
This commit is contained in:
@@ -124,6 +124,23 @@ export class SynologyAccess extends BaseAccess {
|
|||||||
})
|
})
|
||||||
timeout = 120;
|
timeout = 120;
|
||||||
|
|
||||||
|
@AccessInput({
|
||||||
|
title: "测试",
|
||||||
|
component: {
|
||||||
|
name: "api-test",
|
||||||
|
action: "onTestRequest",
|
||||||
|
},
|
||||||
|
helper: "点击测试接口看是否正常",
|
||||||
|
})
|
||||||
|
testRequest = true;
|
||||||
|
|
||||||
|
async onTestRequest() {
|
||||||
|
const client = new SynologyClient(this as any, this.ctx.http, this.ctx.logger, this.skipSslVerify);
|
||||||
|
await client.doLogin();
|
||||||
|
await client.getCertList();
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
onLoginWithOPTCode(data: { otpCode: string }) {
|
onLoginWithOPTCode(data: { otpCode: string }) {
|
||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
const client = new SynologyClient(this as any, ctx.http, ctx.logger, this.skipSslVerify);
|
const client = new SynologyClient(this as any, ctx.http, ctx.logger, this.skipSslVerify);
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./plugin-deploy-to-panel.js";
|
export * from "./plugin-deploy-to-panel.js";
|
||||||
|
export * from "./plugin-keep-alive.js";
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ export class SynologyDeployToPanel extends AbstractPlusTaskPlugin {
|
|||||||
//授权选择框
|
//授权选择框
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: "群晖授权",
|
title: "群晖授权",
|
||||||
helper: "群晖登录授权,请确保账户是管理员用户组",
|
helper: "群晖登录授权,请确保账户是管理员用户组\n群晖OTP授权有效期只有30天,您还需要添加“群晖-刷新OTP登录有效期”任务做登录有效期保活",
|
||||||
component: {
|
component: {
|
||||||
name: "access-selector",
|
name: "access-selector",
|
||||||
type: "synology",
|
type: "synology",
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
|
||||||
|
import { AbstractPlusTaskPlugin } from "@certd/plugin-plus";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
@IsTaskPlugin({
|
||||||
|
name: "SynologyKeepAlive",
|
||||||
|
title: "群晖-刷新OTP登录有效期",
|
||||||
|
icon: "simple-icons:synology",
|
||||||
|
group: pluginGroups.panel.key,
|
||||||
|
desc: "群晖登录状态可能30天失效,需要在失效之前登录一次,刷新有效期,您可以将其放在“部署到群晖面板”任务之后",
|
||||||
|
showRunStrategy: false,
|
||||||
|
default: {
|
||||||
|
strategy: {
|
||||||
|
runStrategy: RunStrategy.AlwaysRun,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
needPlus: true,
|
||||||
|
})
|
||||||
|
export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
|
||||||
|
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: "群晖授权",
|
||||||
|
helper: "群晖登录授权,请确保账户是管理员用户组",
|
||||||
|
component: {
|
||||||
|
name: "access-selector",
|
||||||
|
type: "synology",
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
accessId!: string;
|
||||||
|
|
||||||
|
|
||||||
|
//授权选择框
|
||||||
|
@TaskInput({
|
||||||
|
title: "间隔天数",
|
||||||
|
helper: "多少天刷新一次,建议15天以内",
|
||||||
|
component: {
|
||||||
|
name: "number-input",
|
||||||
|
type: "number",
|
||||||
|
min: 1,
|
||||||
|
max: 30,
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
intervalDays!: number;
|
||||||
|
|
||||||
|
@TaskOutput({
|
||||||
|
title: "上次刷新时间",
|
||||||
|
type :"SynologyLastRefreshTime"
|
||||||
|
})
|
||||||
|
lastRefreshTime!: number;
|
||||||
|
|
||||||
|
async onInstance() {}
|
||||||
|
async execute(): Promise<void> {
|
||||||
|
this.logger.info("开始刷新群晖登录有效期");
|
||||||
|
const now = dayjs()
|
||||||
|
const status = this.getLastStatus();
|
||||||
|
if (status) {
|
||||||
|
let lastRefreshTime = this.getLastOutput("lastRefreshTime");
|
||||||
|
lastRefreshTime = lastRefreshTime || 0;
|
||||||
|
this.lastRefreshTime = lastRefreshTime;
|
||||||
|
const lastTime = dayjs(lastRefreshTime);
|
||||||
|
const diffDays = now.diff(lastTime, "day");
|
||||||
|
if (diffDays < this.intervalDays) {
|
||||||
|
this.logger.info(`距离上次刷新有效期${diffDays.toFixed(0)}天(${this.intervalDays}天),无需刷新`);
|
||||||
|
this.logger.info(`下一次刷新时间${lastTime.add(this.intervalDays, "day").format("YYYY-MM-DD")}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// const access: SynologyAccess = await this.getAccess<SynologyAccess>(this.accessId);
|
||||||
|
// const client = new SynologyClient(access as any, this.ctx.http, this.ctx.logger, access.skipSslVerify);
|
||||||
|
// await client.doLogin();
|
||||||
|
// await client.getCertList();
|
||||||
|
this.lastRefreshTime = now.unix();
|
||||||
|
this.logger.info("刷新群晖登录有效期成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
new SynologyKeepAlivePlugin();
|
||||||
Reference in New Issue
Block a user