From bbb032344b77d8e7e8ae2775d02c4d91ba717c38 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 26 Sep 2024 10:24:25 +0800 Subject: [PATCH] chore: --- README.md | 19 ++- plugin.md => doc/dev/development.md | 6 +- .../plugin-host/plugin/copy-to-local/index.ts | 22 ++- .../plugin/upload-to-host/index.ts | 136 ++++++++---------- start.sh | 23 +++ 5 files changed, 122 insertions(+), 84 deletions(-) rename plugin.md => doc/dev/development.md (93%) create mode 100644 start.sh diff --git a/README.md b/README.md index d2334ad3..7943366a 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,12 @@ https://certd.handsfree.work/ 3. 安装完成后在应用商店中找到`certd`,点击安装,配置域名等基本信息即可完成安装 -### 4.2 Docker部署 +### 4.2 Docker部署【推荐】 #### 1. 安装docker、docker-compose 1.1 准备一台云服务器 * 【阿里云】云服务器2核2G,新老用户同享,99元/年,续费同价!【 [立即购买](https://www.aliyun.com/benefit?scm=20140722.M_10244282._.V_1&source=5176.11533457&userCode=qya11txb )】 * 【腾讯云】云服务器2核2G,新老用户同享,99元/年,续费同价!【 [立即购买](https://cloud.tencent.com/act/cps/redirect?redirect=6094&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9&from=console)】 - 1.2 安装docker @@ -110,7 +109,7 @@ docker compose up -d > 如果提示 没有compose命令,请安装docker-compose > https://docs.docker.com/compose/install/linux/ -#### 镜像说明: +#### 3. 镜像说明: * 国内镜像地址: * `registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest` * `registry.cn-shenzhen.aliyuncs.com/handsfree/certd:armv7`、`[version]-armv7` @@ -124,13 +123,19 @@ docker compose up -d ![](./doc/images/action-build.jpg) -#### 3. 访问 +#### 4. 访问测试 http://your_server_ip:7001 默认账号密码:admin/123456 记得修改密码 - +### 4.3 源码部署 +```shell +# 克隆代码 +git clone https://github.com/certd/certd +cd certd +./start.sh +``` ## 五、 升级 @@ -223,11 +228,13 @@ https://afdian.com/a/greper ## 十一、贡献代码 -1. [贡献插件教程](./plugin.md) +1. 本地开发 [贡献插件教程](./dev/development.md) 2. 作为贡献者,代表您同意您贡献的代码如下许可: 1. 可以调整开源协议以使其更严格或更宽松。 2. 可以用于商业用途。 + + ## 十二、 开源许可 * 本项目遵循 GNU Affero General Public License(AGPL)开源协议。 * 允许个人和公司使用、复制、修改和分发本项目,禁止任何形式的商业用途 diff --git a/plugin.md b/doc/dev/development.md similarity index 93% rename from plugin.md rename to doc/dev/development.md index 232f15b1..dc6920e1 100644 --- a/plugin.md +++ b/doc/dev/development.md @@ -1,4 +1,5 @@ -# 贡献插件 +# 本地开发 +欢迎贡献插件 ## 1.本地调试运行 @@ -11,9 +12,6 @@ git clone https://github.com/certd/certd #进入项目目录 cd certd -# 切换到最新的版本tag,v2分支可能不稳定 -checkout tags/vx.x.x # x.x.x为最新的版本号 - # 安装依赖 npm install -g pnpm@8.15.7 pnpm install 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 d07f24da..964723b1 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 @@ -34,6 +34,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin { }) keyPath!: string; + @TaskInput({ + title: '中间证书保存路径', + helper: '需要有写入权限,路径要包含私钥文件名,文件名不能用*?!等特殊符号,例如:/tmp/intermediate.crt', + component: { + placeholder: '/root/deploy/nginx/intermediate.crt', + }, + }) + icPath!: string; + @TaskInput({ title: 'PFX证书保存路径', helper: '用于IIS证书部署,路径要包含文件名,文件名不能用*?!等特殊符号\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pfx', @@ -76,6 +85,12 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin { }) hostKeyPath!: string; + @TaskOutput({ + title: '中间证书保存路径', + type: 'HostKeyPath', + }) + hostIcPath!: string; + @TaskOutput({ title: 'PFX保存路径', type: 'HostPfxPath', @@ -99,7 +114,7 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin { fs.copyFileSync(srcFile, destFile); } async execute(): Promise { - let { crtPath, keyPath, pfxPath, derPath } = this; + let { crtPath, keyPath, icPath, pfxPath, derPath } = this; const certReader = new CertReader(this.cert); const handle = async ({ reader, tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath }) => { @@ -114,6 +129,11 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin { this.copyFile(tmpKeyPath, keyPath); this.hostKeyPath = keyPath; } + if (icPath) { + icPath = icPath.startsWith('/') ? icPath : path.join(Constants.dataDir, icPath); + this.copyFile(tmpPfxPath, icPath); + this.hostIcPath = icPath; + } if (pfxPath) { pfxPath = pfxPath.startsWith('/') ? pfxPath : path.join(Constants.dataDir, pfxPath); this.copyFile(tmpPfxPath, pfxPath); 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 ae30eee9..f263f412 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 @@ -79,7 +79,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin { name: 'pi-access-selector', type: 'ssh', }, - rules: [{ required: false, message: '' }], + required: true, }) accessId!: string; @@ -106,18 +106,6 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin { }) script!: string; - @TaskInput({ - title: '仅复制到当前主机', - helper: - '注意:本配置即将废弃\n' + - '开启后,将直接复制到当前主机某个目录,不上传到主机,由于是docker启动,实际上是复制到docker容器内的“证书保存路径”\n' + - '你需要事先在docker-compose.yaml中配置主机目录映射: volumes: /your_target_path:/your_target_path', - value: false, - component: { - name: 'a-switch', - vModel: 'checked', - }, - }) copyToThisHost!: boolean; @TaskOutput({ @@ -168,68 +156,70 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin { const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath } = opts; if (this.copyToThisHost) { this.logger.info('复制到目标路径'); - this.copyFile(tmpCrtPath, crtPath); - this.copyFile(tmpKeyPath, keyPath); - this.copyFile(tmpIcPath, this.icPath); - this.copyFile(tmpPfxPath, this.pfxPath); - this.copyFile(tmpDerPath, this.derPath); - } else { - if (!accessId) { - throw new Error('主机登录授权配置不能为空'); - } - this.logger.info('准备上传文件到服务器'); - - const transports: any = []; - if (crtPath) { - transports.push({ - localPath: tmpCrtPath, - remotePath: crtPath, - }); - this.logger.info(`上传证书到主机:${crtPath}`); - } - if (keyPath) { - transports.push({ - localPath: tmpKeyPath, - remotePath: keyPath, - }); - this.logger.info(`上传私钥到主机:${keyPath}`); - } - if (this.icPath) { - transports.push({ - localPath: tmpIcPath, - remotePath: this.icPath, - }); - this.logger.info(`上传中间证书到主机:${this.icPath}`); - } - if (this.pfxPath) { - transports.push({ - localPath: tmpPfxPath, - remotePath: this.pfxPath, - }); - this.logger.info(`上传PFX证书到主机:${this.pfxPath}`); - } - if (this.derPath) { - transports.push({ - localPath: tmpDerPath, - remotePath: this.derPath, - }); - this.logger.info(`上传DER证书到主机:${this.derPath}`); - } - this.logger.info('开始上传文件到服务器'); - await sshClient.uploadFiles({ - connectConf, - transports, - mkdirs: this.mkdirs, - }); - this.logger.info('上传文件到服务器成功'); - //输出 - this.hostCrtPath = crtPath; - this.hostKeyPath = keyPath; - this.hostIcPath = this.icPath; - this.hostPfxPath = this.pfxPath; - this.hostDerPath = this.derPath; + throw new Error('复制到当前主机功能已迁移到 “复制到本机”插件'); + // this.copyFile(tmpCrtPath, crtPath); + // this.copyFile(tmpKeyPath, keyPath); + // this.copyFile(tmpIcPath, this.icPath); + // this.copyFile(tmpPfxPath, this.pfxPath); + // this.copyFile(tmpDerPath, this.derPath); } + + if (!accessId) { + throw new Error('主机登录授权配置不能为空'); + } + this.logger.info('准备上传文件到服务器'); + + const transports: any = []; + if (crtPath) { + transports.push({ + localPath: tmpCrtPath, + remotePath: crtPath, + }); + this.logger.info(`上传证书到主机:${crtPath}`); + } + if (keyPath) { + transports.push({ + localPath: tmpKeyPath, + remotePath: keyPath, + }); + this.logger.info(`上传私钥到主机:${keyPath}`); + } + if (this.icPath) { + transports.push({ + localPath: tmpIcPath, + remotePath: this.icPath, + }); + this.logger.info(`上传中间证书到主机:${this.icPath}`); + } + if (this.pfxPath) { + transports.push({ + localPath: tmpPfxPath, + remotePath: this.pfxPath, + }); + this.logger.info(`上传PFX证书到主机:${this.pfxPath}`); + } + if (this.derPath) { + transports.push({ + localPath: tmpDerPath, + remotePath: this.derPath, + }); + this.logger.info(`上传DER证书到主机:${this.derPath}`); + } + this.logger.info('开始上传文件到服务器'); + await sshClient.uploadFiles({ + connectConf, + transports, + mkdirs: this.mkdirs, + }); + this.logger.info('上传文件到服务器成功'); + //输出 + this.hostCrtPath = crtPath; + this.hostKeyPath = keyPath; + this.hostIcPath = this.icPath; + this.hostPfxPath = this.pfxPath; + this.hostDerPath = this.derPath; }; + await certReader.readCertFile({ logger: this.logger, handle, diff --git a/start.sh b/start.sh new file mode 100644 index 00000000..a7fba814 --- /dev/null +++ b/start.sh @@ -0,0 +1,23 @@ + +echo "删除packages下除ui之外的其他目录" +rm -rf packages/!(ui) + +echo "安装pnpm 8.15.7, 前提是已经安装了nodejs" +npm install -g pnpm@8.15.7 +echo "安装依赖" +pnpm install + +echo "开始构建" +echo "构建certd-client" +cd packages/ui/certd-client +npm run build +cp -r dist ../certd-server + +echo "构建certd-server" +cd ../certd-server +npm run build +echo "构建完成" +echo "启动服务" +npm run start + +