@certd/plugin-plus 1.38.2 → 1.38.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.38.4](https://github.com/certd/certd/compare/v1.38.3...v1.38.4) (2026-01-31)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @certd/plugin-plus
|
|
9
|
+
|
|
10
|
+
## [1.38.3](https://github.com/certd/certd/compare/v1.38.2...v1.38.3) (2026-01-28)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @certd/plugin-plus
|
|
13
|
+
|
|
6
14
|
## [1.38.2](https://github.com/certd/certd/compare/v1.38.1...v1.38.2) (2026-01-22)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @certd/plugin-plus
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"querystring";import{CertReader as t}from"@certd/plugin-lib";import o from"fs";import i from"form-data";import s from"crypto-js";import{utils as n,http as r}from"@certd/basic";import{Pager as a,AbstractTaskPlugin as c}from"@certd/pipeline";import{isPlus as d}from"@certd/plus-core";const h="certd";class p{access;http;logger;skipSslVerify;token;constructor(e,t,o,i){this.access=e,this.http=t,this.logger=o,this.skipSslVerify=i}async doLogin(){const e=this.access;if(e.otp&&null!=e.deviceId)return this.logger.info("OTP登录"),await this.doLoginWithDeviceId(e.deviceId);this.logger.info("使用普通登录");const t=this.getLoginUrl(),o=await this.http.request({url:t,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:e.username,passwd:e.password,session:"Certd",format:"sid",enable_syno_token:"yes"},skipSslVerify:this.skipSslVerify??!0,timeout:1e3*this.access.timeout||12e4});if(!o.success)throw new Error("登录失败: ",o.error);return this.logger.info("登录成功"),this.token=o.data,this.token}async doLoginWithOTPCode(e){const t=this.getLoginUrl(),o=this.access,i=await this.http.request({url:t,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:o.username,passwd:o.password,otp_code:e,enable_device_token:"yes",device_name:h},timeout:1e3*this.access.timeout||3e4,skipSslVerify:this.skipSslVerify??!0});if(!i.success)throw new Error("登录失败: ",i.error);return this.logger.info("登录成功"),this.token=i.data,this.token}getLoginUrl(){const e=this.access,t="6"===e.version?"auth.cgi":"entry.cgi";return`${e.baseUrl}/webapi/${t}`}async doLoginWithDeviceId(e){const t=this.access,o=this.getLoginUrl(),i=await this.http.request({url:o,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:t.username,passwd:t.password,device_name:h,device_id:e,session:"Certd",format:"sid",enable_syno_token:"yes"},timeout:1e3*this.access.timeout||3e4,skipSslVerify:this.skipSslVerify??!0});if(!i.success)throw new Error("登录失败: ",i.error);return this.logger.info("登录成功"),this.token=i.data,this.token}async doRequest(t){const o=this.token.sid,i=t.method||"POST",s={...t.apiParams,_sid:o,...t.params,SynoToken:this.token.synotoken},n=await this.http.request({url:`${this.access.baseUrl}/webapi/entry.cgi?${e.stringify(s)}`,method:i,data:t.data,headers:t.headers,skipSslVerify:this.skipSslVerify??!0,timeout:1e3*this.access.timeout||3e4});if(!n.success)throw new Error(`API 调用失败: ${JSON.stringify(n.error)}`);return n.data}async getCertList(){return this.logger.info("获取证书列表"),await this.doRequest({method:"GET",apiParams:{api:"SYNO.Core.Certificate.CRT",version:1,method:"list"}})}async getInfo(){return this.logger.info("获取信息"),await this.doRequest({method:"GET",apiParams:{api:"SYNO.API.Info",version:1,method:"query"}})}async updateCertToPanel(e,s){this.logger.info(`更新证书:${e.id}`);const n=new t(s);return n.readCertFile({logger:this.logger,handle:async t=>{const s=new i,{tmpCrtPath:r,tmpKeyPath:a,tmpIcPath:c}=t;return this.logger.info(`上传证书:${r},${a}`),s.append("key",o.createReadStream(a)),s.append("cert",o.createReadStream(r)),n.cert.ic&&(this.logger.info(`包含中间证书:${c}`),s.append("inter_cert",o.createReadStream(c))),s.append("id",e.id),s.append("desc",e.desc),console.log(JSON.stringify(s.getHeaders())),await this.doRequest({method:"POST",apiParams:{api:"SYNO.Core.Certificate",version:1,method:"import"},data:s,headers:{...s.getHeaders()}})}})}}class l{access=null;http=null;logger=null;xTickets=null;loginCookies=null;domainTokenCookie=null;userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0";constructor(e){this.access=e.access,this.http=e.http,this.logger=e.logger}async doRedirectRequest(e){let t=null;try{t=await this.http.request(e)}catch(e){if(t=e.response,this.logger.info(t.headers),!t)throw new Error("请求失败:",e)}return t}getCookie(e){const t=e.headers["set-cookie"];if(!t||0===t.length)throw new Error("未获取到cookie",e);return t.map((e=>e.split(";")[0])).join(";")}async getToken(){const e=await this.http.request({url:"https://login.xinnet.com/queryUOne",method:"get"});this.logger.info("queryUOne",e.data);const{uOne:t,uTwo:o}=e.data,i=await this.doRedirectRequest({url:"https://login.xinnet.com/newlogin",method:"get",headers:{Host:"login.xinnet.com",Origin:"https://login.xinnet.com",Referer:"https://login.xinnet.com/separatePage/?service=https://www.xinnet.com/"},maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),n=this.getCookie(i);this.logger.info("firstCookie",n);const r={username:this.access.username,password:(a=this.access.password,c=o,s.AES.encrypt(a,c).toString()),uOne:t,randStr:"",ticket:"",service:"",isRemoteLogin:!1};var a,c;const d=new FormData;for(const e in r)d.append(e,r[e]);const h=await this.http.request({url:"https://login.xinnet.com/newlogin",method:"post",headers:{Origin:"https://login.xinnet.com",Referer:"https://login.xinnet.com/separatePage/?service=https://www.xinnet.com/","Content-Type":"multipart/form-data",Cookie:n},data:d,withCredentials:!0,returnOriginRes:!0}),p=this.getCookie(h);this.logger.info("登录成功,loginCookie:",p);const l=h.data.data.xTickets;this.logger.info("tickets:",l),this.xTickets=l,this.loginCookies=p;const m=`https://domain.xinnet.com/domainsso/getXtoken?xticket=${this.xTickets.split("###")[3]}&callback=${"jsonp_"+(Math.floor(1e5*Math.random())*Date.now()).toString(16)}`;console.log("getxtoken-------",m);const u=await this.doRedirectRequest({url:m,method:"get",headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0",cookie:p},maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),g=this.getCookie(u);this.logger.info("获取domainXtoken成功:",g),this.domainTokenCookie=g}async getDomainList(e){this.domainTokenCookie||await this.getToken();const t=new a(e);return await this.doDomainRequest({url:"https://domain.xinnet.com/domainManage/domainList",method:"post",data:{pageNo:t.pageNo,pageSize:t.pageSize,domainName:e.searchKey??""}})}async doDomainRequest(e){this.domainTokenCookie||await this.getToken();return await this.http.request({url:e.url,method:e.method??"post",headers:{Host:"domain.xinnet.com",Origin:"https://domain.xinnet.com",Referer:"https://domain.xinnet.com/","User-Agent":this.userAgent,cookie:this.domainTokenCookie},data:e.data,withCredentials:!0})}async getDcpCookie(e){this.domainTokenCookie||await this.getToken();const t=this.domainTokenCookie,o="https://domain.xinnet.com/dcp?serviceCode="+e.serviceCode+"&type=analytic",i=(await this.doRedirectRequest({url:o,method:"get",headers:{cookie:t},maxRedirects:0,withCredentials:!0,returnOriginRes:!0})).headers.location;console.log("跳转到dcp:",i);const s=await this.doRedirectRequest({url:i,method:"get",maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),n=this.getCookie(s);return this.logger.info("dcpCookie",n),n}async getDomainDnsList(e){const t=await this.http.request({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/list",method:"post",headers:{"Content-Type":"application/json; charset=UTF-8",Host:"dcp.xinnet.com",Origin:"https://dcp.xinnet.com",Referer:"https://dcp.xinnet.com/dcpProduct.html",cookie:e.dcpCookie},data:{type:"ALL",content:e.recordValue||"",skip:1,limit:10},withCredentials:!0});if(0!=t.code)throw this.logger.error("获取DNS列表失败",JSON.stringify(t)),new Error("获取DNS列表失败");return t.data?.list}async addDomainDnsRecord(e,t){const o=await this.doDcpRequest({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/add",method:"post",data:{recordName:e.recordName,type:e.type,content:e.recordValue,ttl:600,phoneCode:1}},t);this.logger.info(o),await n.sleep(3e3);const i=await this.getDomainDnsList({serviceCode:t.serviceCode,recordValue:e.recordValue,dcpCookie:t.dcpCookie});if(!i||0===i.length)throw new Error("未找到添加的DNS记录");const s=i[0];return{recordId:s.id,recordFullName:s.name,recordValue:s.content,type:s.type}}async deleteDomainDnsRecord(e,t){const o=await this.doDcpRequest({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/delete",method:"post",data:{recordId:e.recordId,recordName:e.recordFullName,content:e.recordValue,type:e.type,isBatch:0,phoneCode:1}},t);return console.log(o.data),o}async doDcpRequest(e,t){return await this.http.request({url:e.url,method:e.method??"post",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",Host:"dcp.xinnet.com",Origin:"https://dcp.xinnet.com",Referer:"https://dcp.xinnet.com/dcpProduct.html",cookie:t.dcpCookie},withCredentials:!0,data:e.data})}}class m{opts;deviceId;xToken;token;cookie;constructor(e){this.opts=e,this.deviceId=(new Date).getTime()+Math.floor(1e6*Math.random())+""}async sign(e,t){const o=(await import("crypto-js")).default;let i="";return Object.keys(e).sort().forEach((function(t){e[t]&&(i=i+"&"+t+"="+e[t])})),i=i.slice(1),o.HmacMD5(i,t).toString()}async doRequest(e){const t=(await r.request({...e,logRes:!1,returnOriginRes:!0})).data;if(null!=t.ret){if(0!==t.ret)throw new Error(JSON.stringify(t));return t.data}if(!t.success)throw new Error(JSON.stringify(t.error));if(t.data?.errCode)throw new Error(JSON.stringify(t.data));return t.data}async login(){if(this.xToken)return this.xToken;const e=this.deviceId,t=this.opts.access.email;var o;const i={method:"serverless.function.runtime.invoke",params:`{"functionTarget":"uni-id-co","functionArgs":{"method":"login","params":[{"password":"${this.opts.access.password}","captcha":"","resetAppId":"__UNI__unicloud_console","resetUniPlatform":"web","isReturnToken":false,"email":"${t}"}],"clientInfo":${`{"PLATFORM":"web","OS":"windows","APPID":"${o="__UNI__uniid_server"}","DEVICEID":"${e}","scene":1001,"appId":"${o}","appLanguage":"zh-Hans","appName":"账号中心","appVersion":"1.0.0","appVersionCode":"100","browserName":"chrome","browserVersion":"122.0.6261.95","deviceId":"174585375190823882061","deviceModel":"PC","deviceType":"pc","hostName":"chrome","hostVersion":"122.0.6261.95","osName":"windows","osVersion":"10 x64","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36","uniCompilerVersion":"4.45","uniPlatform":"web","uniRuntimeVersion":"4.45","locale":"zh-Hans","LOCALE":"zh-Hans"}`}}}`,spaceId:"uni-id-server",timestamp:(new Date).getTime()},s=await this.sign(i,"ba461799-fde8-429f-8cc4-4b6d306e2339"),n=(await this.doRequest({url:"https://account.dcloud.net.cn/client",method:"POST",data:i,headers:{"X-Serverless-Sign":s,Origin:"https://account.dcloud.net.cn",Referer:"https://account.dcloud.net.cn"}})).newToken.token;return this.xToken=n,this.opts.logger.info("登录成功:",n),n}async getToken(){if(this.token)return{token:this.token,cookie:this.cookie};const e=await this.login(),t=this.deviceId,o=`{"PLATFORM":"web","OS":"windows","APPID":"__UNI__unicloud_console","DEVICEID":"${t}","scene":1001,"appId":"__UNI__unicloud_console","appLanguage":"zh-Hans","appName":"uniCloud控制台","appVersion":"1.0.0","appVersionCode":"100","browserName":"chrome","browserVersion":"122.0.6261.95","deviceId":"${t}","deviceModel":"PC","deviceType":"pc","hostName":"chrome","hostVersion":"122.0.6261.95","osName":"windows","osVersion":"10 x64","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36","uniCompilerVersion":"4.57","uniPlatform":"web","uniRuntimeVersion":"4.57","locale":"zh-Hans","LOCALE":"zh-Hans"}`,i={method:"serverless.function.runtime.invoke",params:`{"functionTarget":"uni-cloud-kernel","functionArgs":{"action":"user/getUserToken","data":{"isLogin":true},"clientInfo":${o},"uniIdToken":"${e}"}}`,spaceId:"dc-6nfabcn6ada8d3dd",timestamp:(new Date).getTime()},s=await this.sign(i,"4c1f7fbf-c732-42b0-ab10-4634a8bbe834"),n=await this.doRequest({url:"https://unicloud.dcloud.net.cn/client",method:"POST",data:i,headers:{"X-Client-Info":encodeURIComponent(o),"X-Serverless-Sign":s,"X-Client-Token":e,Origin:"https://unicloud.dcloud.net.cn",Referer:"https://unicloud.dcloud.net.cn"}}),r=n.data.data.token,a=n.headers["set-cookie"];let c="";for(let e=0;e<a.length;e++){c+=a[e].substring(0,a[e].indexOf(";"))+";"}return this.token=r,this.opts.logger.info("获取token成功:",r),this.cookie=c,{token:r,cookie:c}}async createCert(e){await this.getToken();const{spaceId:t,domain:o,cert:i,provider:s}=e;this.opts.logger.info(`开始部署证书, provider:${s},spaceId:${t},domain:${o}`);const n={appid:"",provider:s,spaceId:t,domain:o,cert:encodeURIComponent(i.crt),key:encodeURIComponent(i.key)},r=await this.doRequest({url:"https://unicloud-api.dcloud.net.cn/unicloud/api/host/create-domain-with-cert",method:"POST",data:n,headers:{Token:this.token,Cookie:this.cookie}});this.opts.logger.info("证书部署成功:",JSON.stringify(r))}}function u(){if(!d())throw new Error("此插件仅供专业版中使用")}class g extends c{setCtx(e){super.setCtx(e),u()}}class w{privateKeyPem="";http;logger;access;token;constructor(e){this.logger=e.logger,this.http=e.http,this.access=e.access,this.privateKeyPem="\n-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAt83xKlUSU0i09/pwwQ0MQQ0v71IULdVGJ3AFo+anwLX1TRCp\nxmY5i+xmT9tshHqiPG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qK23XUGDnuCRhzbiqGPGkQovN8Z0RUOiev1m\n3bgUHoAKWvECYrjURS1AxkAmuy8wPsYvyTLHOBpxOD5bLkjMGyVHe7AL59gTDktv\nh2oPEZibIamo6MJyhCxbYC0CgYAIZhnYL7MsO3phgRqR3oTyiDwJEq/RLIQWSFG4\nzNhk8BhPDxRvL7XIEQXQKndNwEyrpKJOri/euIDnlet9z7s1GRmX2/OxmS0LsFoN\nif/K7djUDn2L7RWwAQI0hsC1pNZTw7raoE5I/JB3FSifIFA4/3U5/GdqhvCOS+k9\ni7rUGQKBgQDPspapfGj2ozgWChJ2xMTGBhJhynM81w3j9w7MLvO/7/U43zYzKzyc\n7YJzApQOSwX/nLdquzi+UIbvuCB3npZVZl52S4f7BBcgLNQpdmcfWrAbDv5lySfn\n/KTN22Wxmhh20QgiNSxj+o+KIgdAgZCgWt7NrkZ5UX7Lo+ZfYU1xbg==\n-----END RSA PRIVATE KEY-----"}async sign(e){const{KJUR:t,KEYUTIL:o,hextob64:i}=await import("jsrsasign"),s=o.getKey(this.privateKeyPem),n=new t.crypto.Signature({alg:"SHA256withRSA"});n.init(s),n.updateString(e);return i(n.sign())}async doRequest(e){const t=Date.now();let o="";if("get"===e.method.toLowerCase()){let i=[];for(const t in e.params)i.push(`${t}=${e.params[t]}`);i.push(`nonce=${t}`),i.push(`timestamp=${t}`),i=i.sort(),o=i.join("&")}else o=`body=${JSON.stringify(e.data||{})}&nonce=${t}×tamp=${t}`;const i={sign:await this.sign(o),timestamp:t,nonce:t};this.token&&(i.Token=this.token);const s=await this.http.request({...e,headers:i,baseURL:"https://testaa.5678.jp"});if(!s.success&&200!==s.code)throw new Error(`请求失败:${s.msg}`);return s.data}async login(){const e={email:this.access.username,password:this.access.password,accountType:1},t=await this.doRequest({url:"/api/vcloud/v1/userApi/noAuth/login",method:"post",data:e,logRes:!1,logParams:!1}),{token:o}=t;this.logger.info("登录成功"),this.token=o}}export{g as AbstractPlusTaskPlugin,w as MaoyunClient,p as SynologyClient,m as UniCloudClient,l as XinnetClient,u as mustPlus};
|
|
1
|
+
import e from"querystring";import{CertReader as t}from"@certd/plugin-lib";import o from"fs";import i from"form-data";import s from"crypto-js";import{utils as n,http as r}from"@certd/basic";import{Pager as a,AbstractTaskPlugin as c}from"@certd/pipeline";import{isPlus as d}from"@certd/plus-core";const h="certd";class p{access;http;logger;skipSslVerify;token;constructor(e,t,o,i){this.access=e,this.http=t,this.logger=o,this.skipSslVerify=i}async doLogin(){const e=this.access;if(e.otp&&null!=e.deviceId)return this.logger.info("OTP登录"),await this.doLoginWithDeviceId(e.deviceId);this.logger.info("使用普通登录");const t=this.getLoginUrl(),o=await this.http.request({url:t,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:e.username,passwd:e.password,session:"Certd",format:"sid",enable_syno_token:"yes"},skipSslVerify:this.skipSslVerify??!0,timeout:1e3*this.access.timeout||12e4});if(!o.success)throw new Error("登录失败: ",o.error);return this.logger.info("登录成功"),this.token=o.data,this.token}async doLoginWithOTPCode(e){const t=this.getLoginUrl(),o=this.access,i=await this.http.request({url:t,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:o.username,passwd:o.password,otp_code:e,enable_device_token:"yes",device_name:h},timeout:1e3*this.access.timeout||3e4,skipSslVerify:this.skipSslVerify??!0});if(!i.success)throw new Error("登录失败: ",i.error);return this.logger.info("登录成功"),this.token=i.data,this.token}getLoginUrl(){const e=this.access,t="6"===e.version?"auth.cgi":"entry.cgi";return`${e.baseUrl}/webapi/${t}`}async doLoginWithDeviceId(e){const t=this.access,o=this.getLoginUrl(),i=await this.http.request({url:o,method:"GET",params:{api:"SYNO.API.Auth",version:6,method:"login",account:t.username,passwd:t.password,device_name:h,device_id:e,session:"Certd",format:"sid",enable_syno_token:"yes"},timeout:1e3*this.access.timeout||3e4,skipSslVerify:this.skipSslVerify??!0});if(!i.success)throw new Error("登录失败: ",i.error);return this.logger.info("登录成功"),this.token=i.data,this.token}async doRequest(t){const o=this.token.sid,i=t.method||"POST",s={...t.apiParams,_sid:o,...t.params,SynoToken:this.token.synotoken},n=await this.http.request({url:`${this.access.baseUrl}/webapi/entry.cgi?${e.stringify(s)}`,method:i,data:t.data,headers:t.headers,skipSslVerify:this.skipSslVerify??!0,timeout:1e3*this.access.timeout||3e4});if(!n.success)throw new Error(`API 调用失败: ${JSON.stringify(n.error)}`);return n.data}async getCertList(){return this.logger.info("获取证书列表"),await this.doRequest({method:"GET",apiParams:{api:"SYNO.Core.Certificate.CRT",version:1,method:"list"}})}async getInfo(){return this.logger.info("获取信息"),await this.doRequest({method:"GET",apiParams:{api:"SYNO.API.Info",version:1,method:"query"}})}async updateCertToPanel(e,s){this.logger.info(`更新证书:${e.id}`);const n=new t(s);return n.readCertFile({logger:this.logger,handle:async t=>{const s=new i,{tmpCrtPath:r,tmpKeyPath:a,tmpIcPath:c}=t;return this.logger.info(`上传证书:${r},${a}`),s.append("key",o.createReadStream(a)),s.append("cert",o.createReadStream(r)),n.cert.ic&&(this.logger.info(`包含中间证书:${c}`),s.append("inter_cert",o.createReadStream(c))),s.append("id",e.id),s.append("desc",e.desc),console.log(JSON.stringify(s.getHeaders())),await this.doRequest({method:"POST",apiParams:{api:"SYNO.Core.Certificate",version:1,method:"import"},data:s,headers:{...s.getHeaders()}})}})}}class l{access=null;http=null;logger=null;xTickets=null;loginCookies=null;domainTokenCookie=null;userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0";constructor(e){this.access=e.access,this.http=e.http,this.logger=e.logger}async doRedirectRequest(e){let t=null;try{t=await this.http.request(e)}catch(e){if(t=e.response,this.logger.info(t.headers),!t)throw new Error("请求失败:",e)}return t}getCookie(e){const t=e.headers["set-cookie"];if(!t||0===t.length)throw new Error("未获取到cookie",e);return t.map((e=>e.split(";")[0])).join(";")}async getToken(){const e=await this.http.request({url:"https://login.xinnet.com/queryUOne",method:"get"});this.logger.info("queryUOne",e.data);const{uOne:t,uTwo:o}=e.data,i=await this.doRedirectRequest({url:"https://login.xinnet.com/newlogin",method:"get",headers:{Host:"login.xinnet.com",Origin:"https://login.xinnet.com",Referer:"https://login.xinnet.com/separatePage/?service=https://www.xinnet.com/"},maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),n=this.getCookie(i);this.logger.info("firstCookie",n);const r={username:this.access.username,password:(a=this.access.password,c=o,s.AES.encrypt(a,c).toString()),uOne:t,randStr:"",ticket:"",service:"",isRemoteLogin:!1};var a,c;const d=new FormData;for(const e in r)d.append(e,r[e]);const h=await this.http.request({url:"https://login.xinnet.com/newlogin",method:"post",headers:{Origin:"https://login.xinnet.com",Referer:"https://login.xinnet.com/separatePage/?service=https://www.xinnet.com/","Content-Type":"multipart/form-data",Cookie:n},data:d,withCredentials:!0,returnOriginRes:!0}),p=this.getCookie(h);this.logger.info("登录成功,loginCookie:",p);const l=h.data?.data?.xTickets;if(this.logger.info("tickets:",l),!l)throw this.logger.error("未获取到tickets"),this.logger.warn("请检查是否触发了异地登录保护,https://console.xinnet.com/hy/index.html#/recentlogin ,将ip设置为白名单"),this.logger.warn("或者检查是否开启了动态口令验证,您需要关闭它"),new Error("未获取到tickets"+(h.data||h));this.xTickets=l,this.loginCookies=p;const m=`https://domain.xinnet.com/domainsso/getXtoken?xticket=${this.xTickets.split("###")[3]}&callback=${"jsonp_"+(Math.floor(1e5*Math.random())*Date.now()).toString(16)}`,u=await this.doRedirectRequest({url:m,method:"get",headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0",cookie:p},maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),g=this.getCookie(u);this.logger.info("获取domainXtoken成功:",g),this.domainTokenCookie=g}async getDomainList(e){this.domainTokenCookie||await this.getToken();const t=new a(e);return await this.doDomainRequest({url:"https://domain.xinnet.com/domainManage/domainList",method:"post",data:{pageNo:t.pageNo,pageSize:t.pageSize,domainName:e.searchKey??""}})}async doDomainRequest(e){this.domainTokenCookie||await this.getToken();return await this.http.request({url:e.url,method:e.method??"post",headers:{Host:"domain.xinnet.com",Origin:"https://domain.xinnet.com",Referer:"https://domain.xinnet.com/","User-Agent":this.userAgent,cookie:this.domainTokenCookie},data:e.data,withCredentials:!0})}async getDcpCookie(e){this.domainTokenCookie||await this.getToken();const t=this.domainTokenCookie,o="https://domain.xinnet.com/dcp?serviceCode="+e.serviceCode+"&type=analytic",i=(await this.doRedirectRequest({url:o,method:"get",headers:{cookie:t},maxRedirects:0,withCredentials:!0,returnOriginRes:!0})).headers.location;console.log("跳转到dcp:",i);const s=await this.doRedirectRequest({url:i,method:"get",maxRedirects:0,withCredentials:!0,returnOriginRes:!0}),n=this.getCookie(s);return this.logger.info("dcpCookie",n),n}async getDomainDnsList(e){const t=await this.http.request({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/list",method:"post",headers:{"Content-Type":"application/json; charset=UTF-8",Host:"dcp.xinnet.com",Origin:"https://dcp.xinnet.com",Referer:"https://dcp.xinnet.com/dcpProduct.html",cookie:e.dcpCookie},data:{type:"ALL",content:e.recordValue||"",skip:1,limit:10},withCredentials:!0});if(0!=t.code)throw this.logger.error("获取DNS列表失败",JSON.stringify(t)),new Error("获取DNS列表失败");return t.data?.list}async addDomainDnsRecord(e,t){const o=await this.doDcpRequest({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/add",method:"post",data:{recordName:e.recordName,type:e.type,content:e.recordValue,ttl:600,phoneCode:1}},t);this.logger.info(o),await n.sleep(3e3);const i=await this.getDomainDnsList({serviceCode:t.serviceCode,recordValue:e.recordValue,dcpCookie:t.dcpCookie});if(!i||0===i.length)throw new Error("未找到添加的DNS记录");const s=i[0];return{recordId:s.id,recordFullName:s.name,recordValue:s.content,type:s.type}}async deleteDomainDnsRecord(e,t){const o=await this.doDcpRequest({url:"https://dcp.xinnet.com/dcp/domaincloudanalytic/delete",method:"post",data:{recordId:e.recordId,recordName:e.recordFullName,content:e.recordValue,type:e.type,isBatch:0,phoneCode:1}},t);return console.log(o.data),o}async doDcpRequest(e,t){return await this.http.request({url:e.url,method:e.method??"post",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",Host:"dcp.xinnet.com",Origin:"https://dcp.xinnet.com",Referer:"https://dcp.xinnet.com/dcpProduct.html",cookie:t.dcpCookie},withCredentials:!0,data:e.data})}}class m{opts;deviceId;xToken;token;cookie;constructor(e){this.opts=e,this.deviceId=(new Date).getTime()+Math.floor(1e6*Math.random())+""}async sign(e,t){const o=(await import("crypto-js")).default;let i="";return Object.keys(e).sort().forEach((function(t){e[t]&&(i=i+"&"+t+"="+e[t])})),i=i.slice(1),o.HmacMD5(i,t).toString()}async doRequest(e){const t=(await r.request({...e,logRes:!1,returnOriginRes:!0})).data;if(null!=t.ret){if(0!==t.ret)throw new Error(JSON.stringify(t));return t.data}if(!t.success)throw new Error(JSON.stringify(t.error));if(t.data?.errCode)throw new Error(JSON.stringify(t.data));return t.data}async login(){if(this.xToken)return this.xToken;const e=this.deviceId,t=this.opts.access.email;var o;const i={method:"serverless.function.runtime.invoke",params:`{"functionTarget":"uni-id-co","functionArgs":{"method":"login","params":[{"password":"${this.opts.access.password}","captcha":"","resetAppId":"__UNI__unicloud_console","resetUniPlatform":"web","isReturnToken":false,"email":"${t}"}],"clientInfo":${`{"PLATFORM":"web","OS":"windows","APPID":"${o="__UNI__uniid_server"}","DEVICEID":"${e}","scene":1001,"appId":"${o}","appLanguage":"zh-Hans","appName":"账号中心","appVersion":"1.0.0","appVersionCode":"100","browserName":"chrome","browserVersion":"122.0.6261.95","deviceId":"174585375190823882061","deviceModel":"PC","deviceType":"pc","hostName":"chrome","hostVersion":"122.0.6261.95","osName":"windows","osVersion":"10 x64","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36","uniCompilerVersion":"4.45","uniPlatform":"web","uniRuntimeVersion":"4.45","locale":"zh-Hans","LOCALE":"zh-Hans"}`}}}`,spaceId:"uni-id-server",timestamp:(new Date).getTime()},s=await this.sign(i,"ba461799-fde8-429f-8cc4-4b6d306e2339"),n=(await this.doRequest({url:"https://account.dcloud.net.cn/client",method:"POST",data:i,headers:{"X-Serverless-Sign":s,Origin:"https://account.dcloud.net.cn",Referer:"https://account.dcloud.net.cn"}})).newToken.token;return this.xToken=n,this.opts.logger.info("登录成功:",n),n}async getToken(){if(this.token)return{token:this.token,cookie:this.cookie};const e=await this.login(),t=this.deviceId,o=`{"PLATFORM":"web","OS":"windows","APPID":"__UNI__unicloud_console","DEVICEID":"${t}","scene":1001,"appId":"__UNI__unicloud_console","appLanguage":"zh-Hans","appName":"uniCloud控制台","appVersion":"1.0.0","appVersionCode":"100","browserName":"chrome","browserVersion":"122.0.6261.95","deviceId":"${t}","deviceModel":"PC","deviceType":"pc","hostName":"chrome","hostVersion":"122.0.6261.95","osName":"windows","osVersion":"10 x64","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36","uniCompilerVersion":"4.57","uniPlatform":"web","uniRuntimeVersion":"4.57","locale":"zh-Hans","LOCALE":"zh-Hans"}`,i={method:"serverless.function.runtime.invoke",params:`{"functionTarget":"uni-cloud-kernel","functionArgs":{"action":"user/getUserToken","data":{"isLogin":true},"clientInfo":${o},"uniIdToken":"${e}"}}`,spaceId:"dc-6nfabcn6ada8d3dd",timestamp:(new Date).getTime()},s=await this.sign(i,"4c1f7fbf-c732-42b0-ab10-4634a8bbe834"),n=await this.doRequest({url:"https://unicloud.dcloud.net.cn/client",method:"POST",data:i,headers:{"X-Client-Info":encodeURIComponent(o),"X-Serverless-Sign":s,"X-Client-Token":e,Origin:"https://unicloud.dcloud.net.cn",Referer:"https://unicloud.dcloud.net.cn"}}),r=n.data.data.token,a=n.headers["set-cookie"];let c="";for(let e=0;e<a.length;e++){c+=a[e].substring(0,a[e].indexOf(";"))+";"}return this.token=r,this.opts.logger.info("获取token成功:",r),this.cookie=c,{token:r,cookie:c}}async createCert(e){await this.getToken();const{spaceId:t,domain:o,cert:i,provider:s}=e;this.opts.logger.info(`开始部署证书, provider:${s},spaceId:${t},domain:${o}`);const n={appid:"",provider:s,spaceId:t,domain:o,cert:encodeURIComponent(i.crt),key:encodeURIComponent(i.key)},r=await this.doRequest({url:"https://unicloud-api.dcloud.net.cn/unicloud/api/host/create-domain-with-cert",method:"POST",data:n,headers:{Token:this.token,Cookie:this.cookie}});this.opts.logger.info("证书部署成功:",JSON.stringify(r))}}function u(){if(!d())throw new Error("此插件仅供专业版中使用")}class g extends c{setCtx(e){super.setCtx(e),u()}}class w{privateKeyPem="";http;logger;access;token;constructor(e){this.logger=e.logger,this.http=e.http,this.access=e.access,this.privateKeyPem="\n-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAt83xKlUSU0i09/pwwQ0MQQ0v71IULdVGJ3AFo+anwLX1TRCp\nxmY5i+xmT9tshHqiPGN8qeg+lDaqA+iwmS6zqi+KlNmmKJc3kUx/h24MI3nff0xy\nz605ZfDgJhwBkJpTI6Sk4+OLX+lZxOiET0nOT7jrhKiFCKX8+0ZXjTJ1cmdifKaj\nqXmjD+XYZzBwA2fCr1kPq2xKvU097Ksu6QvM+La5X/tt+FJOuedmuqZmsb6YQ+6O\n6mJ0bcY0kFDGNkoeY6dEyeJAkIDJbda3n0I71KwRR2J0CSN3TF+w1hSQa7Hp1rXw\n+zQvR6p7O2VY8zQeZZKRKGl7OGdKW5F79iz2fQIDAQABAoIBAEN0BaRGciI0VY2H\n0CdY1X1uDIBke9lSIpvIhZlfxYJ4hFxS2CtiSo4qJGX8HbgElVNaI17rR0P3R6+F\njoG43OCA7/euZEcTL6ZYD5kw7q16RWYfNSc36A+cNXZm4sAhko9LFeQ4FmcNaQ9V\nUXEToe4p6+zUN3Y0DEJez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o+ZfYU1xbg==\n-----END RSA PRIVATE KEY-----"}async sign(e){const{KJUR:t,KEYUTIL:o,hextob64:i}=await import("jsrsasign"),s=o.getKey(this.privateKeyPem),n=new t.crypto.Signature({alg:"SHA256withRSA"});n.init(s),n.updateString(e);return i(n.sign())}async doRequest(e){const t=Date.now();let o="";if("get"===e.method.toLowerCase()){let i=[];for(const t in e.params)i.push(`${t}=${e.params[t]}`);i.push(`nonce=${t}`),i.push(`timestamp=${t}`),i=i.sort(),o=i.join("&")}else o=`body=${JSON.stringify(e.data||{})}&nonce=${t}×tamp=${t}`;const i={sign:await this.sign(o),timestamp:t,nonce:t};this.token&&(i.Token=this.token);const s=await this.http.request({...e,headers:i,baseURL:"https://testaa.5678.jp"});if(!s.success&&200!==s.code)throw new Error(`请求失败:${s.msg}`);return s.data}async login(){const e={email:this.access.username,password:this.access.password,accountType:1},t=await this.doRequest({url:"/api/vcloud/v1/userApi/noAuth/login",method:"post",data:e,logRes:!1,logParams:!1}),{token:o}=t;this.logger.info("登录成功"),this.token=o}}export{g as AbstractPlusTaskPlugin,w as MaoyunClient,p as SynologyClient,m as UniCloudClient,l as XinnetClient,u as mustPlus};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/plugin-plus",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.38.
|
|
4
|
+
"version": "1.38.4",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/d/index.d.ts",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"compile": "tsc --skipLibCheck --watch"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@certd/basic": "^1.38.
|
|
20
|
-
"@certd/pipeline": "^1.38.
|
|
21
|
-
"@certd/plugin-lib": "^1.38.
|
|
22
|
-
"@certd/plus-core": "^1.38.
|
|
19
|
+
"@certd/basic": "^1.38.4",
|
|
20
|
+
"@certd/pipeline": "^1.38.4",
|
|
21
|
+
"@certd/plugin-lib": "^1.38.4",
|
|
22
|
+
"@certd/plus-core": "^1.38.4",
|
|
23
23
|
"crypto-js": "^4.2.0",
|
|
24
24
|
"dayjs": "^1.11.7",
|
|
25
25
|
"form-data": "^4.0.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"tslib": "^2.8.1",
|
|
47
47
|
"typescript": "^5.4.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "84291482732687cc8162c6505666ba2b29b02918"
|
|
50
50
|
}
|