mirror of
https://github.com/certd/certd.git
synced 2026-07-15 02:07:38 +08:00
chore: format
This commit is contained in:
@@ -13,7 +13,7 @@ export class Bind9Access extends BaseAccess {
|
||||
component: {
|
||||
name: "access-selector",
|
||||
type: "ssh",
|
||||
vModel:"modelValue"
|
||||
vModel: "modelValue",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
@@ -37,7 +37,7 @@ export class Bind9Access extends BaseAccess {
|
||||
placeholder: "53",
|
||||
},
|
||||
})
|
||||
dnsPort: number = 53;
|
||||
dnsPort = 53;
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { Bind9Access } from './access.js';
|
||||
import { SshClient } from '../plugin-lib/ssh/index.js';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Bind9Access } from "./access.js";
|
||||
import { SshClient } from "../plugin-lib/ssh/index.js";
|
||||
|
||||
export type Bind9Record = {
|
||||
fullRecord: string;
|
||||
@@ -10,11 +10,11 @@ export type Bind9Record = {
|
||||
};
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'bind9',
|
||||
title: 'BIND9 DNS',
|
||||
desc: '通过 SSH 连接到 BIND9 服务器,使用 nsupdate 命令管理 DNS 记录',
|
||||
icon: 'clarity:host-line',
|
||||
accessType: 'bind9',
|
||||
name: "bind9",
|
||||
title: "BIND9 DNS",
|
||||
desc: "通过 SSH 连接到 BIND9 服务器,使用 nsupdate 命令管理 DNS 记录",
|
||||
icon: "clarity:host-line",
|
||||
accessType: "bind9",
|
||||
})
|
||||
export class Bind9DnsProvider extends AbstractDnsProvider<Bind9Record> {
|
||||
access!: Bind9Access;
|
||||
@@ -32,7 +32,7 @@ export class Bind9DnsProvider extends AbstractDnsProvider<Bind9Record> {
|
||||
// 从 accessService 获取 SSH 授权配置
|
||||
const sshAccess = await this.ctx.accessGetter.getById(this.access.sshAccessId);
|
||||
if (!sshAccess) {
|
||||
throw new Error('SSH 授权不存在');
|
||||
throw new Error("SSH 授权不存在");
|
||||
}
|
||||
return sshAccess;
|
||||
}
|
||||
@@ -42,12 +42,8 @@ export class Bind9DnsProvider extends AbstractDnsProvider<Bind9Record> {
|
||||
*/
|
||||
private buildNsupdateCommand(commands: string[]): string {
|
||||
const { dnsServer, dnsPort } = this.access;
|
||||
const nsupdateScript = [
|
||||
`server ${dnsServer} ${dnsPort}`,
|
||||
...commands,
|
||||
"send",
|
||||
].join("\n");
|
||||
|
||||
const nsupdateScript = [`server ${dnsServer} ${dnsPort}`, ...commands, "send"].join("\n");
|
||||
|
||||
// 使用 heredoc 方式执行 nsupdate
|
||||
return `nsupdate << 'EOF'
|
||||
${nsupdateScript}
|
||||
@@ -59,15 +55,15 @@ EOF`;
|
||||
*/
|
||||
async createRecord(options: CreateRecordOptions): Promise<Bind9Record> {
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
|
||||
|
||||
// 构建 nsupdate 命令
|
||||
// 格式: update add <name> <ttl> <type> <value>
|
||||
const updateCommand = `update add ${fullRecord} 60 ${type} "${value}"`;
|
||||
const nsupdateCmd = this.buildNsupdateCommand([updateCommand]);
|
||||
|
||||
this.logger.info('执行 nsupdate 命令添加记录');
|
||||
|
||||
this.logger.info("执行 nsupdate 命令添加记录");
|
||||
|
||||
try {
|
||||
const sshAccess = await this.getSshAccess();
|
||||
await this.sshClient.exec({
|
||||
@@ -75,10 +71,10 @@ EOF`;
|
||||
script: nsupdateCmd,
|
||||
throwOnStdErr: true,
|
||||
});
|
||||
|
||||
|
||||
this.logger.info(`添加域名解析成功: fullRecord=${fullRecord}, value=${value}`);
|
||||
} catch (error: any) {
|
||||
this.logger.error('添加域名解析失败:', error.message);
|
||||
this.logger.error("添加域名解析失败:", error.message);
|
||||
throw new Error(`添加 DNS 记录失败: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -89,7 +85,7 @@ EOF`;
|
||||
type,
|
||||
domain,
|
||||
};
|
||||
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -98,15 +94,15 @@ EOF`;
|
||||
*/
|
||||
async removeRecord(options: RemoveRecordOptions<Bind9Record>): Promise<void> {
|
||||
const { fullRecord, value, type, domain } = options.recordRes;
|
||||
this.logger.info('删除域名解析:', fullRecord, value, type, domain);
|
||||
this.logger.info("删除域名解析:", fullRecord, value, type, domain);
|
||||
|
||||
// 构建 nsupdate 命令
|
||||
// 格式: update delete <name> <type> <value>
|
||||
const updateCommand = `update delete ${fullRecord} ${type} "${value}"`;
|
||||
const nsupdateCmd = this.buildNsupdateCommand([updateCommand]);
|
||||
|
||||
this.logger.info('执行 nsupdate 命令删除记录');
|
||||
|
||||
this.logger.info("执行 nsupdate 命令删除记录");
|
||||
|
||||
try {
|
||||
const sshAccess = await this.getSshAccess();
|
||||
await this.sshClient.exec({
|
||||
@@ -114,11 +110,11 @@ EOF`;
|
||||
script: nsupdateCmd,
|
||||
throwOnStdErr: false, // 删除时忽略错误(记录可能已不存在)
|
||||
});
|
||||
|
||||
|
||||
this.logger.info(`删除域名解析成功: fullRecord=${fullRecord}, value=${value}`);
|
||||
} catch (error: any) {
|
||||
// 删除失败只记录警告,不抛出异常(清理操作不应影响主流程)
|
||||
this.logger.warn('删除域名解析时出现警告:', error.message);
|
||||
this.logger.warn("删除域名解析时出现警告:", error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './dns-provider.js';
|
||||
export * from './access.js';
|
||||
export * from "./dns-provider.js";
|
||||
export * from "./access.js";
|
||||
|
||||
Reference in New Issue
Block a user