Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobaidadada committed Nov 22, 2024
2 parents b771b9b + 946cd01 commit de961b7
Show file tree
Hide file tree
Showing 21 changed files with 2,142 additions and 76 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filecat",
"version": "1.0.8",
"version": "1.0.9",
"description": "filecat 文件管理器",
"author": "xiaobaidadada",
"scripts": {
Expand Down Expand Up @@ -118,7 +118,6 @@
"style-loader": "^3.3.4",
"systeminformation": "^5.22.11",
"tar": "^7.4.3",
"tencentcloud-sdk-nodejs": "^4.0.858",
"tldts": "^6.1.20",
"ts-node": "^10.9.2",
"typedi": "^0.10.0",
Expand Down
1 change: 0 additions & 1 deletion src/common/frame/ws.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {CmdType, protocolIsProto2, WsConnectType, WsData} from "./WsData";
import * as parser from "socket.io-parser"
import {Decoder, Encoder, Packet, PacketType} from "socket.io-parser"
import {settingService} from "../../main/domain/setting/setting.service";
import {wss} from "tencentcloud-sdk-nodejs";

const url = require('url');

Expand Down
1 change: 1 addition & 0 deletions src/common/req/sys.pojo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface staticSysPojo {
cpu_core_num:number,
cpu_phy_core_num:number
cpu_speed_hz:number
pid_ppid:string;
}

// 物理信息
Expand Down
4 changes: 3 additions & 1 deletion src/main/domain/ddns/ddns.dnspod.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ export class DnsPodService extends DdnsPre implements updateDns{
async_have = true;
DataUtil.set(ddns_dnspod_key, data);
}
} else {
return false;
}
} finally {

}

return true;
}

async update(data: DdnsConnection,domain:IResult,ip:string,type:string) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/domain/ddns/ddns.pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ export abstract class DdnsPre implements updateDns{
this.async_have = true;
DataUtil.set(this.getDdnsKey(), data);
}
} else {
return false;
}
}catch (e) {
console.log(e)
}

return true;
}

abstract update(data: DdnsConnection, domain: IResult, ip: string, type: string);
Expand Down
145 changes: 80 additions & 65 deletions src/main/domain/ddns/ddns.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,41 @@ import {ddns_dnspod_key, dnspodService} from "./ddns.dnspod.service";
import {DdnsPre} from "./ddns.pre";
import {IResult} from "tldts-core";
import {ddns_tx_key, tengxunService} from "./ddns.tengxun.service";
import {aliService, ddns_ali_key, generateAliSignature,alidnsEndpoint} from "./ddns.ali.server";
const tencentcloud = require("tencentcloud-sdk-nodejs")
const txClient = tencentcloud.dnspod.v20210323.Client;
import {aliService, ddns_ali_key, generateAliSignature, alidnsEndpoint} from "./ddns.ali.server";
// const tencentcloud = require("tencentcloud-sdk-nodejs")
// const txClient = tencentcloud.dnspod.v20210323.Client;
import {Client as txClient} from "./tx/dnspod_client"

const dnspodTest = "https://dnsapi.cn/User.Detail";


export class DdnsService extends DdnsPre {

export class DdnsService extends DdnsPre{


public ddnsTask() {
setInterval(async ()=>{
const netList = await this.updateAndGetIps();
await dnspodService.Run(netList)
await tengxunService.Run(netList);
await aliService.Run(netList);
public ddnsTask() {
const ok = setInterval(() => {
(async () => {
const netList = await this.updateAndGetIps();
let handle_num = 0;
if (await dnspodService.Run(netList)) {
handle_num++;
}
if (await tengxunService.Run(netList)) {
handle_num++;
}
if (handle_num == 0) {
clearInterval(ok);
}
})().catch(e => {
// todo 日志功能暂时不加
console.log(e)
})
// 五分钟分钟检测一次
},1000*60*10);
}, 1000*60*10);
}

async getIps(type:string) {
const list:DdnsIPPojo[] = await this.getNowIps();
async getIps(type: string) {
const list: DdnsIPPojo[] = await this.getNowIps();
let key = "";
switch (type) {
case "dnspod":
Expand All @@ -46,11 +58,11 @@ export class DdnsService extends DdnsPre{
}
const result = new DdnsConnection();
const data = await DataUtil.get<DdnsConnection>(key);
result.ips=list;
if (!!data && !!data.ips && data.ips.length>0) {
const map = getMapByList(data.ips,(v)=>v.ifaceOrWww+v.isIPv4);
result.ips = list;
if (!!data && !!data.ips && data.ips.length > 0) {
const map = getMapByList(data.ips, (v) => v.ifaceOrWww + v.isIPv4);
for (const ip of result.ips) {
const item = map.get(ip.ifaceOrWww+ip.isIPv4);
const item = map.get(ip.ifaceOrWww + ip.isIPv4);
if (item) {
ip.ddnsHost = item.ddnsHost;
}
Expand All @@ -63,7 +75,7 @@ export class DdnsService extends DdnsPre{
return Sucess(result);
}

async save(data:DdnsConnection) {
async save(data: DdnsConnection) {
let key = "";
switch (data.ddnsType) {
case DdnsType.dnspod:
Expand All @@ -77,57 +89,59 @@ export class DdnsService extends DdnsPre{
break;
}
if (data.isOpen) {
if (data.ddnsType===DdnsType.dnspod) {
key = ddns_dnspod_key;
try {
const r = await HttpRequest.post(dnspodTest,{
format:"json",
"login_token":`${(data.account as DnsPod).id},${(data.account as DnsPod).token}`
},true)
if (r.status.code+"" !== "1") {
return Sucess("身份验证失败",RCode.DdnsAuthFail);
}
} catch (e) {
return Sucess("身份验证失败",RCode.DdnsAuthFail);
if (data.ddnsType === DdnsType.dnspod) {
key = ddns_dnspod_key;
try {
const r = await HttpRequest.post(dnspodTest, {
format: "json",
"login_token": `${(data.account as DnsPod).id},${(data.account as DnsPod).token}`
}, true)
if (r.status.code + "" !== "1") {
return Sucess("身份验证失败", RCode.DdnsAuthFail);
}
} catch (e) {
return Sucess("身份验证失败", RCode.DdnsAuthFail);
}

} else if (data.ddnsType===DdnsType.tengxun) {
key = ddns_tx_key;
try {
const client = new txClient({
credential: {
secretId: (data.account as Tengxun).secretid,
secretKey: (data.account as Tengxun).secretkey
},
});
await client.DescribeUserDetail();
} catch (e) {
return Sucess("身份验证失败",RCode.DdnsAuthFail);
}
} else if (data.ddnsType===DdnsType.ali) {
key = ddns_ali_key;
try {
const params = {
Action: 'DescribeTags',
AccessKeyId: (data.account as Ali).accesskey_id,
SignatureMethod: 'HMAC-SHA1',
SignatureNonce: Math.random().toString(),
Timestamp: new Date().toISOString(),
Format: 'JSON',
SignatureVersion: '1.0',
Version: '2015-01-09',
ResourceType:"DOMAIN"
};
params['Signature'] = generateAliSignature(params, (data.account as Ali).accesskey_secret);
const req = await HttpRequest.get(alidnsEndpoint,params);
} catch (e) {
return Sucess("身份验证失败",RCode.DdnsAuthFail);
}
} else if (data.ddnsType === DdnsType.tengxun) {
key = ddns_tx_key;
try {
const client = new txClient({
credential: {
secretId: (data.account as Tengxun).secretid,
secretKey: (data.account as Tengxun).secretkey
},
});
await client.DescribeUserDetail();
} catch (e) {
return Sucess("身份验证失败", RCode.DdnsAuthFail);
}
} else if (data.ddnsType === DdnsType.ali) {
// todo 目前不用
key = ddns_ali_key;
try {
const params = {
Action: 'DescribeTags',
AccessKeyId: (data.account as Ali).accesskey_id,
SignatureMethod: 'HMAC-SHA1',
SignatureNonce: Math.random().toString(),
Timestamp: new Date().toISOString(),
Format: 'JSON',
SignatureVersion: '1.0',
Version: '2015-01-09',
ResourceType: "DOMAIN"
};
params['Signature'] = generateAliSignature(params, (data.account as Ali).accesskey_secret);
const req = await HttpRequest.get(alidnsEndpoint, params);
} catch (e) {
return Sucess("身份验证失败", RCode.DdnsAuthFail);
}
await DataUtil.set(key,data);
}
ddnsService.ddnsTask();
await DataUtil.set(key, data);
return Sucess("身份信息正确");
}
await DataUtil.set(key,data);
await DataUtil.set(key, data);
return Sucess("保存成功");
}

Expand All @@ -137,5 +151,6 @@ export class DdnsService extends DdnsPre{
update(data: DdnsConnection, domain: IResult, ip: string, type: string) {
}
}

export const ddnsService = new DdnsService();
ddnsService.ddnsTask();
9 changes: 6 additions & 3 deletions src/main/domain/ddns/ddns.tengxun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {DdnsConnection, DnsPod, Tengxun} from "../../../common/req/ddns.pojo";
import {DdnsPre} from "./ddns.pre";
import {IResult} from "tldts-core";

const tencentcloud = require("tencentcloud-sdk-nodejs")
const txClient = tencentcloud.dnspod.v20210323.Client;
// const tencentcloud = require("tencentcloud-sdk-nodejs")
// const txClient = tencentcloud.dnspod.v20210323.Client;
import {Client as txClient} from "./tx/dnspod_client"

export const ddns_tx_key = "tengxun_ddns_key"

export class TengxunService extends DdnsPre {
Expand All @@ -27,11 +29,12 @@ export class TengxunService extends DdnsPre {
// 更新
// const record = req.RecordList[0];
await client.ModifyRecord({
RecordId:req.RecordList[0].RecordId,
"RecordType": type,
"SubDomain": domain.subdomain,
"Domain": domain.domain,
"Value": ip,
"RecordLine": "默认",
"RecordLine": "默认"
});
} else {
//添加
Expand Down
Loading

0 comments on commit de961b7

Please sign in to comment.