From c4164c66e29f3ec799f98108a344806ca61e94ff Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 25 Oct 2024 22:49:05 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=96=87=E4=BB=B6=E5=90=8D=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6=E9=99=90=E5=88=B6=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../validator/__tests__/validator.spec.ts | 33 ++++++++++++++++++- .../src/plugin/validator/index.ts | 13 ++++++++ .../plugin-host/plugin/copy-to-local/index.ts | 15 ++++++--- .../plugin/upload-to-host/index.ts | 15 ++++++--- 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/packages/ui/certd-client/src/plugin/validator/__tests__/validator.spec.ts b/packages/ui/certd-client/src/plugin/validator/__tests__/validator.spec.ts index 133030c1..8331158c 100644 --- a/packages/ui/certd-client/src/plugin/validator/__tests__/validator.spec.ts +++ b/packages/ui/certd-client/src/plugin/validator/__tests__/validator.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { isDomain } from "/@/plugin/validator"; +import { isDomain, isFilePath } from "/@/plugin/validator"; describe("domain_validator", () => { it("ok", () => { @@ -41,4 +41,35 @@ describe("domain_validator", () => { value = [".cc.com"]; expect(test).to.throw(Error, "域名有误:.cc.com,请输入正确的域名"); }); + + it("isFilePath", () => { + let value = "/a/$/bc"; + + function test() { + return isFilePath({}, value); + } + + expect(test()).to.be.true; + + value = "/a/&/bc"; + expect(test()).to.be.true; + + //*?“<>|等特殊字符 + + value = "/a/&/b>c.txt"; + const errorMessage = '文件名不能包含*?"<>|等特殊字符'; + expect(test).to.throw(Error, errorMessage); + + value = "/a/&/b|等特殊符号 + if (!/^[^*?"<>|]*$/.test(value)) { + throw new Error(`文件名不能包含*?"<>|等特殊字符`); + } + return true; +} +Validator.register("filepath", isFilePath); diff --git a/packages/ui/certd-server/src/plugins/plugin-host/plugin/copy-to-local/index.ts b/packages/ui/certd-server/src/plugins/plugin-host/plugin/copy-to-local/index.ts index faa156cc..b7ac227e 100644 --- a/packages/ui/certd-server/src/plugins/plugin-host/plugin/copy-to-local/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-host/plugin/copy-to-local/index.ts @@ -19,46 +19,51 @@ import path from 'path'; export class CopyCertToLocalPlugin extends AbstractTaskPlugin { @TaskInput({ title: '证书保存路径', - helper: '全链证书,路径要包含文件名,文件名不能用*?!等特殊符号' + '\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pem', + helper: '全链证书,路径要包含文件名' + '\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pem', component: { placeholder: './tmp/full_chain.pem', }, + rules: [{ type: 'filepath' }], }) crtPath!: string; @TaskInput({ title: '私钥保存路径', - helper: '路径要包含文件名,文件名不能用*?!等特殊符号\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.key', + helper: '路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.key', component: { placeholder: './tmp/cert.key', }, + rules: [{ type: 'filepath' }], }) keyPath!: string; @TaskInput({ title: '中间证书保存路径', - helper: '一般情况传上面两个文件就行了,极少数情况需要这个中间证书', + helper: '路径要包含文件名,一般情况传上面两个文件就行了,极少数情况需要这个中间证书', component: { placeholder: '/root/deploy/nginx/intermediate.pem', }, + rules: [{ type: 'filepath' }], }) icPath!: string; @TaskInput({ title: 'PFX证书保存路径', - helper: '用于IIS证书部署,路径要包含文件名,文件名不能用*?!等特殊符号\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pfx', + helper: '用于IIS证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pfx', component: { placeholder: './tmp/cert.pfx', }, + rules: [{ type: 'filepath' }], }) pfxPath!: string; @TaskInput({ title: 'DER证书保存路径', helper: - '用户Apache证书部署,路径要包含文件名,文件名不能用*?!等特殊符号\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可', + '用于Apache证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可', component: { placeholder: './tmp/cert.der 或 ./tmp/cert.cer', }, + rules: [{ type: 'filepath' }], }) derPath!: string; diff --git a/packages/ui/certd-server/src/plugins/plugin-host/plugin/upload-to-host/index.ts b/packages/ui/certd-server/src/plugins/plugin-host/plugin/upload-to-host/index.ts index 62dc9fa4..7d49917a 100644 --- a/packages/ui/certd-server/src/plugins/plugin-host/plugin/upload-to-host/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-host/plugin/upload-to-host/index.ts @@ -20,45 +20,50 @@ import dayjs from 'dayjs'; export class UploadCertToHostPlugin extends AbstractTaskPlugin { @TaskInput({ title: '证书保存路径', - helper: '全链证书,需要有写入权限,路径要包含证书文件名,文件名不能用*?!等特殊符号,例如:/tmp/cert.pem', + helper: '全链证书,需要有写入权限,路径要包含证书文件名,例如:/tmp/cert.pem', component: { placeholder: '/root/deploy/nginx/full_chain.pem', }, + rules: [{ type: 'filepath' }], }) crtPath!: string; @TaskInput({ title: '私钥保存路径', - helper: '需要有写入权限,路径要包含私钥文件名,文件名不能用*?!等特殊符号,例如:/tmp/cert.key', + helper: '需要有写入权限,路径要包含私钥文件名,例如:/tmp/cert.key', component: { placeholder: '/root/deploy/nginx/cert.key', }, + rules: [{ type: 'filepath' }], }) keyPath!: string; @TaskInput({ title: '中间证书保存路径', - helper: '一般情况传上面两个文件即可,极少数情况需要这个中间证书', + helper: '路径要包含文件名,一般情况传上面两个文件即可,极少数情况需要这个中间证书', component: { placeholder: '/root/deploy/nginx/intermediate.pem', }, + rules: [{ type: 'filepath' }], }) icPath!: string; @TaskInput({ title: 'PFX证书保存路径', - helper: '用于IIS证书部署,需要有写入权限,路径要包含私钥文件名,文件名不能用*?!等特殊符号,例如:/tmp/cert.pfx', + helper: '用于IIS证书部署,需要有写入权限,路径要包含证书文件名,例如:/tmp/cert.pfx', component: { placeholder: '/root/deploy/nginx/cert.pfx', }, + rules: [{ type: 'filepath' }], }) pfxPath!: string; @TaskInput({ title: 'DER证书保存路径', - helper: '用于Apache证书部署,需要有写入权限,路径要包含私钥文件名,文件名不能用*?!等特殊符号,例如:/tmp/cert.der', + helper: '用于Apache证书部署,需要有写入权限,路径要包含证书文件名,例如:/tmp/cert.der', component: { placeholder: '/root/deploy/nginx/cert.der', }, + rules: [{ type: 'filepath' }], }) derPath!: string;