From dc5a5fa5431ce36bd1441ff277db238ac945646c Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 22 Apr 2025 07:26:11 +0800 Subject: [PATCH] chore: --- .../src/plugins/plugin-51dns/client.test.mjs | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 packages/ui/certd-server/src/plugins/plugin-51dns/client.test.mjs diff --git a/packages/ui/certd-server/src/plugins/plugin-51dns/client.test.mjs b/packages/ui/certd-server/src/plugins/plugin-51dns/client.test.mjs new file mode 100644 index 00000000..e068ff6e --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-51dns/client.test.mjs @@ -0,0 +1,136 @@ +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) + // // 提取 182****43522
+ // console.log(res2.data.match(/(.*?)<\/span>/)[1]) + // const success1 = res2.data.includes('DNS解析') + // 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('DNS解析') + console.log("success", success2) + + + /** + * certd.top + + */ + //上面文本中间有换行,需要提取 193341603 部分,必须有certd.top,使用 new Regexp, .号要能匹配换行符,非贪婪模式 + const regExp = new RegExp(']*>certd\\.top<\\/a>',"i"); + + const domainId = res3.data.match(regExp)[1] + + + console.log("domainId", domainId) +} + +login()