mirror of https://github.com/certd/certd
perf: 支持windows文件上传
parent
37caef38ad
commit
7f61cab101
18
README.md
18
README.md
|
@ -49,9 +49,8 @@ https://certd.handsfree.work/
|
||||||
|
|
||||||
1.2 安装docker
|
1.2 安装docker
|
||||||
https://docs.docker.com/engine/install/
|
https://docs.docker.com/engine/install/
|
||||||
|
选择对应的操作系统,按照官方文档执行命令即可
|
||||||
|
|
||||||
1.3 安装docker-compose
|
|
||||||
https://docs.docker.com/compose/install/linux/
|
|
||||||
|
|
||||||
### 2. 下载docker-compose.yaml文件
|
### 2. 下载docker-compose.yaml文件
|
||||||
|
|
||||||
|
@ -82,12 +81,12 @@ https://github.com/certd/certd/releases
|
||||||
# 如果docker compose是插件化安装
|
# 如果docker compose是插件化安装
|
||||||
export CERTD_VERSION=latest
|
export CERTD_VERSION=latest
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
#如果docker compose是独立安装
|
|
||||||
export CERTD_VERSION=latest
|
|
||||||
docker-compose up -d
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
如果提示 没有compose命令,请安装docker-compose
|
||||||
|
https://docs.docker.com/compose/install/linux/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 4. 访问
|
### 4. 访问
|
||||||
|
|
||||||
http://your_server_ip:7001
|
http://your_server_ip:7001
|
||||||
|
@ -117,9 +116,12 @@ http://your_server_ip:7001
|
||||||
## 六、不同平台的设置说明
|
## 六、不同平台的设置说明
|
||||||
|
|
||||||
* [Cloudflare](./doc/cf/cf.md)
|
* [Cloudflare](./doc/cf/cf.md)
|
||||||
|
* [腾讯云](./doc/tencent/tencent.md)
|
||||||
|
* [windows主机](./doc/host/host.md)
|
||||||
|
|
||||||
|
|
||||||
## 七、问题处理
|
## 七、问题处理
|
||||||
### 6.1 忘记管理员密码
|
### 7.1 忘记管理员密码
|
||||||
解决方法如下:
|
解决方法如下:
|
||||||
1. 修改docker-compose.yaml文件,将环境变量`certd_system_resetAdminPassword`改为`true`
|
1. 修改docker-compose.yaml文件,将环境变量`certd_system_resetAdminPassword`改为`true`
|
||||||
```yaml
|
```yaml
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# 远程主机
|
||||||
|
|
||||||
|
远程主机基于ssh协议,通过ssh连接远程主机,执行命令。
|
||||||
|
|
||||||
|
## windows开启OpenSSH Server
|
||||||
|
1. 安装OpenSSH Server
|
||||||
|
请前往Microsoft官方文档查看如何开启openSSH
|
||||||
|
https://learn.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui#install-openssh-for-windows
|
||||||
|
|
||||||
|
2. 启动OpenSSH Server服务
|
||||||
|
```
|
||||||
|
win+R 弹出运行对话框,输入 services.msc 打开服务管理器
|
||||||
|
找到 OpenSSH SSH Server
|
||||||
|
启动ssh server服务,并且设置为自动启动
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 测试ssh登录
|
||||||
|
使用你常用的ssh客户端,连接你的windows主机,进行测试
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
# 如何确定你用户名
|
||||||
|
C:\Users\xiaoj>
|
||||||
|
↑↑↑↑---------这个就是windows ssh的登录用户名
|
||||||
|
```
|
|
@ -1,7 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="d2-page-cover">
|
<div class="d2-page-cover">
|
||||||
<div class="d2-page-cover__title" @click="$open('https://github.com/certd/certd')">
|
<div class="d2-page-cover__title" @click="$open('https://github.com/certd/certd')">
|
||||||
<div class="title-line">Certd v{{ version }}</div>
|
<div class="title-line">
|
||||||
|
<span>Certd v{{ version }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="d2-page-cover__sub-title">让你的证书永不过期</p>
|
<p class="d2-page-cover__sub-title">让你的证书永不过期</p>
|
||||||
<div class="warnning">
|
<div class="warnning">
|
||||||
|
@ -73,7 +75,7 @@ export default defineComponent({
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
width: 80%;
|
width: 70%;
|
||||||
.preview_img {
|
.preview_img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"glob": "^7.2.3",
|
"glob": "^7.2.3",
|
||||||
"https-proxy-agent": "^7.0.4",
|
"https-proxy-agent": "^7.0.4",
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"koa-send": "^5.0.1",
|
"koa-send": "^5.0.1",
|
||||||
|
|
|
@ -60,6 +60,32 @@ export class SshAccess implements IAccess, ConnectConfig {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
passphrase!: string;
|
passphrase!: string;
|
||||||
|
|
||||||
|
|
||||||
|
@AccessInput({
|
||||||
|
title: '是否Windows',
|
||||||
|
helper: '如果是Windows主机,请勾选此项',
|
||||||
|
component: {
|
||||||
|
name: 'a-switch',
|
||||||
|
vModel: 'checked',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
windows: boolean = false;
|
||||||
|
|
||||||
|
@AccessInput({
|
||||||
|
title: '命令编码',
|
||||||
|
helper: '如果是Windows主机,且出现乱码了,请尝试设置为GBK',
|
||||||
|
component: {
|
||||||
|
name: 'a-select',
|
||||||
|
vModel: 'value',
|
||||||
|
options:[
|
||||||
|
{value:"","label":"默认"},
|
||||||
|
{value:"GBK","label":"GBK"},
|
||||||
|
{value:"UTF8","label":"UTF-8"},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
encoding: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
new SshAccess();
|
new SshAccess();
|
||||||
|
|
|
@ -3,14 +3,26 @@ import ssh2, { ConnectConfig } from 'ssh2';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { ILogger } from '@certd/pipeline';
|
import { ILogger } from '@certd/pipeline';
|
||||||
|
import iconv from 'iconv-lite';
|
||||||
|
import {SshAccess} from "../access";
|
||||||
export class AsyncSsh2Client {
|
export class AsyncSsh2Client {
|
||||||
conn: ssh2.Client;
|
conn: ssh2.Client;
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
connConf: ssh2.ConnectConfig;
|
connConf: ssh2.ConnectConfig;
|
||||||
constructor(connConf: ssh2.ConnectConfig, logger: ILogger) {
|
windows:boolean = false;
|
||||||
|
encoding:string;
|
||||||
|
constructor(connConf: SshAccess, logger: ILogger) {
|
||||||
this.connConf = connConf;
|
this.connConf = connConf;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.windows = connConf.windows || false;
|
||||||
|
this.encoding = connConf.encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
convert(buffer: Buffer) {
|
||||||
|
if(this.encoding){
|
||||||
|
return iconv.decode(buffer, this.encoding);
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
|
@ -59,30 +71,29 @@ export class AsyncSsh2Client {
|
||||||
|
|
||||||
async exec(script: string) {
|
async exec(script: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.logger.info(`执行脚本:[${this.connConf.host}][exec]: ` + script);
|
this.logger.info(`执行命令:[${this.connConf.host}][exec]: ` + script);
|
||||||
this.conn.exec(script, (err: Error, stream: any) => {
|
this.conn.exec(script, (err: Error, stream: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data: any = null;
|
let data: string = null;
|
||||||
stream
|
stream
|
||||||
.on('close', (code: any, signal: any) => {
|
.on('close', (code: any, signal: any) => {
|
||||||
this.logger.info(`[${this.connConf.host}][close]:code:${code}`);
|
this.logger.info(`[${this.connConf.host}][close]:code:${code}`);
|
||||||
data = data ? data.toString() : null;
|
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(data));
|
reject(new Error(data));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('data', (ret: any) => {
|
.on('data', (ret: Buffer) => {
|
||||||
this.logger.info(`[${this.connConf.host}][info]: ` + ret);
|
data = this.convert(ret)
|
||||||
data = ret;
|
this.logger.info(`[${this.connConf.host}][info]: ` + data);
|
||||||
})
|
})
|
||||||
.stderr.on('data', (err: Error) => {
|
.stderr.on('data', (ret:Buffer) => {
|
||||||
this.logger.info(`[${this.connConf.host}][error]: ` + err);
|
data = this.convert(ret)
|
||||||
data = err;
|
this.logger.info(`[${this.connConf.host}][error]: ` + data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -104,10 +115,16 @@ export class AsyncSsh2Client {
|
||||||
this.logger.info('Stream :: close');
|
this.logger.info('Stream :: close');
|
||||||
resolve(output);
|
resolve(output);
|
||||||
})
|
})
|
||||||
.on('data', (data: any) => {
|
.on('data', (ret: Buffer) => {
|
||||||
|
const data = this.convert(ret)
|
||||||
this.logger.info('' + data);
|
this.logger.info('' + data);
|
||||||
output.push('' + data);
|
output.push(data);
|
||||||
});
|
})
|
||||||
|
.stderr.on('data', (ret:Buffer) => {
|
||||||
|
const data = this.convert(ret)
|
||||||
|
output.push(data);
|
||||||
|
this.logger.info(`[${this.connConf.host}][error]: ` + data);
|
||||||
|
});
|
||||||
stream.end(script + '\nexit\n');
|
stream.end(script + '\nexit\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -134,7 +151,7 @@ export class SshClient {
|
||||||
}
|
}
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
async uploadFiles(options: { connectConf: ConnectConfig; transports: any }) {
|
async uploadFiles(options: { connectConf: SshAccess; transports: any }) {
|
||||||
const { connectConf, transports } = options;
|
const { connectConf, transports } = options;
|
||||||
await this._call({
|
await this._call({
|
||||||
connectConf,
|
connectConf,
|
||||||
|
@ -142,7 +159,17 @@ export class SshClient {
|
||||||
const sftp = await conn.getSftp();
|
const sftp = await conn.getSftp();
|
||||||
this.logger.info('开始上传');
|
this.logger.info('开始上传');
|
||||||
for (const transport of transports) {
|
for (const transport of transports) {
|
||||||
await conn.exec(`mkdir -p ${path.dirname(transport.remotePath)} `);
|
let filePath = path.dirname(transport.remotePath);
|
||||||
|
let mkdirCmd = `mkdir -p ${filePath} `;
|
||||||
|
if(conn.windows){
|
||||||
|
if(filePath.indexOf("/") > -1){
|
||||||
|
this.logger.info("--------------------------")
|
||||||
|
this.logger.info("请注意:windows下,文件目录分隔应该写成\\而不是/")
|
||||||
|
this.logger.info("--------------------------")
|
||||||
|
}
|
||||||
|
mkdirCmd = `if not exist "${filePath}" mkdir ${filePath} `
|
||||||
|
}
|
||||||
|
await conn.exec(mkdirCmd);
|
||||||
await conn.fastPut({ sftp, ...transport });
|
await conn.fastPut({ sftp, ...transport });
|
||||||
}
|
}
|
||||||
this.logger.info('文件全部上传成功');
|
this.logger.info('文件全部上传成功');
|
||||||
|
@ -151,7 +178,7 @@ export class SshClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(options: {
|
async exec(options: {
|
||||||
connectConf: ConnectConfig;
|
connectConf: SshAccess;
|
||||||
script: string | Array<string>;
|
script: string | Array<string>;
|
||||||
}) {
|
}) {
|
||||||
let { script } = options;
|
let { script } = options;
|
||||||
|
@ -170,7 +197,7 @@ export class SshClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async shell(options: {
|
async shell(options: {
|
||||||
connectConf: ConnectConfig;
|
connectConf: SshAccess;
|
||||||
script: string;
|
script: string;
|
||||||
}): Promise<string[]> {
|
}): Promise<string[]> {
|
||||||
const { connectConf, script } = options;
|
const { connectConf, script } = options;
|
||||||
|
@ -183,7 +210,7 @@ export class SshClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _call(options: {
|
async _call(options: {
|
||||||
connectConf: ConnectConfig;
|
connectConf: SshAccess;
|
||||||
callable: any;
|
callable: any;
|
||||||
}): Promise<string[]> {
|
}): Promise<string[]> {
|
||||||
const { connectConf, callable } = options;
|
const { connectConf, callable } = options;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
import { SshClient } from '../../lib/ssh';
|
import { SshClient } from '../../lib/ssh';
|
||||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import {SshAccess} from "../../access";
|
||||||
|
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
name: 'uploadCertToHost',
|
name: 'uploadCertToHost',
|
||||||
|
@ -112,7 +113,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||||
throw new Error('主机登录授权配置不能为空');
|
throw new Error('主机登录授权配置不能为空');
|
||||||
}
|
}
|
||||||
this.logger.info('准备上传到服务器');
|
this.logger.info('准备上传到服务器');
|
||||||
const connectConf = await this.accessService.getById(accessId);
|
const connectConf:SshAccess = await this.accessService.getById(accessId);
|
||||||
const sshClient = new SshClient(this.logger);
|
const sshClient = new SshClient(this.logger);
|
||||||
await sshClient.uploadFiles({
|
await sshClient.uploadFiles({
|
||||||
connectConf,
|
connectConf,
|
||||||
|
|
Loading…
Reference in New Issue