mirror of
https://github.com/certd/certd.git
synced 2026-04-15 05:00:52 +08:00
perf: 数据库备份支持oss
This commit is contained in:
@@ -1,136 +0,0 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
function aes(val) {
|
||||
var k = CryptoJS.enc.Utf8.parse('1234567890abcDEF');
|
||||
var iv = CryptoJS.enc.Utf8.parse('1234567890abcDEF');
|
||||
const enc = CryptoJS.AES.encrypt(val, k, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.ZeroPadding
|
||||
}).toString();
|
||||
return enc;
|
||||
}
|
||||
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: 'https://www.51dns.com',
|
||||
timeout: 5000,
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})
|
||||
|
||||
async function login() {
|
||||
|
||||
const res = await instance.request({
|
||||
url: 'https://www.51dns.com/login.html',
|
||||
method: 'get',
|
||||
headers: {
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com',
|
||||
}
|
||||
})
|
||||
|
||||
//提取 var csrfToken = "ieOfM21eDd9nWJv3OZtMJF6ogDsnPKQHJ17dlMck";
|
||||
const _token = res.data.match(/var csrfToken = "(.*?)"/)[1]
|
||||
console.log(_token)
|
||||
console.log(res.headers)
|
||||
|
||||
|
||||
const setCookie = res.headers['set-cookie']
|
||||
const cookie = setCookie.map(item => {
|
||||
return item.split(';')[0]
|
||||
}).join(';')
|
||||
|
||||
|
||||
var obj = {
|
||||
'email_or_phone': aes(""),
|
||||
'password': aes(""),
|
||||
'type': aes('account'),
|
||||
'redirectTo': 'https://www.51dns.com/domain',
|
||||
'_token': _token
|
||||
}
|
||||
console.log(JSON.stringify(obj, null, 2))
|
||||
const res2 = await instance.request({
|
||||
url: 'https://www.51dns.com/login',
|
||||
method: 'post',
|
||||
data: {
|
||||
...obj
|
||||
},
|
||||
headers: {
|
||||
/**
|
||||
* Origin:
|
||||
* https://www.51dns.com
|
||||
* Referer:
|
||||
* https://www.51dns.com/login.html
|
||||
* User-Agent:
|
||||
* Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36
|
||||
// __root_domain_v=.51dns.com;
|
||||
*/
|
||||
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com/login.html',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Cookie': cookie,
|
||||
//X-Requested-With:
|
||||
// XMLHttpRequest
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
|
||||
console.log(res2.headers)
|
||||
if (res2.data.code == 0) {
|
||||
console.log("登录成功")
|
||||
}
|
||||
|
||||
const setCookie2 = res2.headers['set-cookie']
|
||||
const cookie2 = setCookie2.map(item => {
|
||||
return item.split(';')[0]
|
||||
}).join(';')
|
||||
|
||||
//
|
||||
// // console.log(res2.data)
|
||||
// // 提取 <span class="user_email">182****43522</span><br>
|
||||
// console.log(res2.data.match(/<span class="user_email">(.*?)<\/span>/)[1])
|
||||
// const success1 = res2.data.includes('<span class="nav-title">DNS解析</span>')
|
||||
// console.log("success", success1)
|
||||
|
||||
|
||||
const res3 = await instance.request({
|
||||
url: 'https://www.51dns.com/domain',
|
||||
method: 'get',
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
|
||||
'Origin': 'https://www.51dns.com',
|
||||
'Referer': 'https://www.51dns.com/login.html',
|
||||
'Cookie': cookie2,
|
||||
}
|
||||
})
|
||||
|
||||
console.log(res3.statusText)
|
||||
console.log(res3.headers)
|
||||
const success2 = res3.data.includes('<span class="nav-title">DNS解析</span>')
|
||||
console.log("success", success2)
|
||||
|
||||
|
||||
/**
|
||||
* <a target="_blank" href="https://www.51dns.com/domain/record/193341603"
|
||||
* class="color47">certd.top</a>
|
||||
|
||||
*/
|
||||
//上面文本中间有换行,需要提取 193341603 部分,必须有certd.top,使用 new Regexp, .号要能匹配换行符,非贪婪模式
|
||||
const regExp = new RegExp('<a target="_blank" href="https://www.51dns.com/domain/record/(\\d+)"[^>]*>certd\\.top<\\/a>',"i");
|
||||
|
||||
const domainId = res3.data.match(regExp)[1]
|
||||
|
||||
|
||||
console.log("domainId", domainId)
|
||||
}
|
||||
|
||||
login()
|
||||
@@ -1,11 +1,11 @@
|
||||
import {IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import dayjs from 'dayjs';
|
||||
import {AbstractPlusTaskPlugin} from '@certd/plugin-plus';
|
||||
import JSZip from 'jszip';
|
||||
import * as os from 'node:os';
|
||||
import {SshAccess, SshClient} from '@certd/plugin-lib';
|
||||
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import dayjs from "dayjs";
|
||||
import { AbstractPlusTaskPlugin } from "@certd/plugin-plus";
|
||||
import JSZip from "jszip";
|
||||
import * as os from "node:os";
|
||||
import { OssClientContext, ossClientFactory, OssClientRemoveByOpts, SshAccess, SshClient } from "@certd/plugin-lib";
|
||||
|
||||
const defaultBackupDir = 'certd_backup';
|
||||
const defaultFilePrefix = 'db-backup';
|
||||
@@ -63,12 +63,14 @@ export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
||||
@TaskInput({
|
||||
title: 'OSS类型',
|
||||
component: {
|
||||
name: 'a-input',
|
||||
name: 'a-select',
|
||||
options: [
|
||||
{value: "aliyun", label: "阿里云OSS"},
|
||||
{value: "alioss", label: "阿里云OSS"},
|
||||
{value: "s3", label: "MinIO/S3"},
|
||||
{value: "qiniu", label: "七牛云"},
|
||||
{value: "tencent", label: "腾讯云COS"}
|
||||
{value: "qiniuoss", label: "七牛云"},
|
||||
{value: "tencentcos", label: "腾讯云COS"},
|
||||
{value: "ftp", label: "Ftp"},
|
||||
{value: "sftp", label: "Sftp"},
|
||||
]
|
||||
},
|
||||
mergeScript: `
|
||||
@@ -90,7 +92,7 @@ export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
||||
mergeScript: `
|
||||
return {
|
||||
show:ctx.compute(({form})=>{
|
||||
return form.backupMode === 'ssh';
|
||||
return form.backupMode === 'oss';
|
||||
}),
|
||||
component:{
|
||||
type: ctx.compute(({form})=>{
|
||||
@@ -270,7 +272,38 @@ export class DBBackupPlugin extends AbstractPlusTaskPlugin {
|
||||
}
|
||||
|
||||
private async ossBackup(dbPath: string, backupDir: string, backupPath: string) {
|
||||
// TODO
|
||||
if (!this.ossAccessId) {
|
||||
throw new Error('未配置ossAccessId');
|
||||
}
|
||||
const access = await this.getAccess(this.ossAccessId);
|
||||
const ossType = this.ossType
|
||||
|
||||
const ctx: OssClientContext = {
|
||||
logger: this.logger,
|
||||
utils: this.ctx.utils,
|
||||
accessService:this.accessService
|
||||
}
|
||||
|
||||
this.logger.info(`开始备份文件到:${ossType}`);
|
||||
const client = await ossClientFactory.createOssClientByType(ossType, {
|
||||
access,
|
||||
ctx,
|
||||
})
|
||||
|
||||
await client.upload(backupPath, dbPath);
|
||||
|
||||
if (this.retainDays > 0) {
|
||||
// 删除过期备份
|
||||
this.logger.info('开始删除过期备份文件');
|
||||
const removeByOpts: OssClientRemoveByOpts = {
|
||||
dir: backupDir,
|
||||
beforeDays: this.retainDays,
|
||||
};
|
||||
await client.removeBy(removeByOpts);
|
||||
this.logger.info('删除过期备份文件完成');
|
||||
}else{
|
||||
this.logger.info('已禁止删除过期文件');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user