Compare commits

...

4 Commits

Author SHA1 Message Date
97c57b2865 4.0.8 2021-01-22 23:24:03 +00:00
e04485231d fix(core): update 2021-01-22 23:24:02 +00:00
228bc88d60 4.0.7 2021-01-22 22:40:17 +00:00
811041b036 fix(core): update 2021-01-22 22:40:16 +00:00
5 changed files with 43 additions and 31 deletions

View File

@ -26,16 +26,28 @@ mirror:
- docker - docker
- notpriv - notpriv
audit: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high - npmci command npm audit --audit-level=high --only=dev
tags: tags:
- docker - docker
allow_failure: true
# ==================== # ====================
# test stage # test stage

7
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdns", "name": "@pushrocks/smartdns",
"version": "4.0.6", "version": "4.0.8",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -4495,6 +4495,11 @@
"dns-packet": "^5.1.2" "dns-packet": "^5.1.2"
} }
}, },
"dns2": {
"version": "1.4.2",
"resolved": "https://verdaccio.lossless.one/dns2/-/dns2-1.4.2.tgz",
"integrity": "sha512-cRapXqyLsCW5HMBQg2pTkDnSe3KXjysWnU756epw554HJZRrqo4cD3xghCOFmZIgVzxhotiGsLGEH8QCq5cKnw=="
},
"dom-serializer": { "dom-serializer": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://verdaccio.lossless.one/dom-serializer/-/dom-serializer-0.2.2.tgz", "resolved": "https://verdaccio.lossless.one/dom-serializer/-/dom-serializer-0.2.2.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdns", "name": "@pushrocks/smartdns",
"version": "4.0.6", "version": "4.0.8",
"private": false, "private": false,
"description": "smart dns methods written in TypeScript", "description": "smart dns methods written in TypeScript",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -26,9 +26,11 @@
"homepage": "https://gitlab.com/pushrocks/dnsly#README", "homepage": "https://gitlab.com/pushrocks/dnsly#README",
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.10", "@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartenv": "^4.0.16",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47", "@pushrocks/smartrequest": "^1.1.47",
"@tsclass/tsclass": "^3.0.21" "@tsclass/tsclass": "^3.0.21",
"dns2": "^1.4.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.24",

View File

@ -1,5 +1,8 @@
import * as smartenv from '@pushrocks/smartenv';
const smartenvInstance = new smartenv.Smartenv();
// node native scope // node native scope
import * as dns from 'dns'; import type dnsType from 'dns';
const dns: typeof dnsType = smartenvInstance.getSafeNodeModule('dns');
export { dns }; export { dns };
@ -8,9 +11,16 @@ import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
export { smartdelay, smartpromise, smartrequest }; export { smartdelay, smartenv, smartpromise, smartrequest };
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
export { tsclass }; export { tsclass };
// third party scope
const dns2 = smartenvInstance.getSafeNodeModule('dns2');
export {
dns2
}

View File

@ -56,7 +56,12 @@ export class Smartdns {
if (runCycles < cyclesArg) { if (runCycles < cyclesArg) {
runCycles++; runCycles++;
try { try {
const myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg); let myRecordArray: plugins.tsclass.network.IDnsRecord[];
if (runCycles % 2 === 0 || !plugins.dns) {
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
} else {
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
}
const myRecord = myRecordArray[0].value; const myRecord = myRecordArray[0].value;
if (myRecord === expectedValue) { if (myRecord === expectedValue) {
console.log( console.log(
@ -68,6 +73,7 @@ export class Smartdns {
return await doCheck(); return await doCheck();
} }
} catch (err) { } catch (err) {
// console.log(err);
await plugins.smartdelay.delayFor(intervalArg); await plugins.smartdelay.delayFor(intervalArg);
return await doCheck(); return await doCheck();
} }
@ -140,7 +146,6 @@ export class Smartdns {
recordNameArg: string, recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType recordTypeArg: plugins.tsclass.network.TDnsRecordType
): Promise<plugins.tsclass.network.IDnsRecord[]> { ): Promise<plugins.tsclass.network.IDnsRecord[]> {
this.setNodeDnsProvider('cloudflare');
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>(); const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => { plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
if (err) { if (err) {
@ -174,28 +179,6 @@ export class Smartdns {
return await done.promise; return await done.promise;
} }
/**
* set the DNS provider
*/
public setNodeDnsProvider(dnsProvider: TDnsProvider) {
if (!this.dnsServerIp) {
console.log(
`Warning: Setting the nodejs dns authority to ${dnsProvider}. Only do this if you know what you are doing.`
);
}
if (dnsProvider === 'google' && this.dnsServerIp !== '8.8.8.8') {
this.dnsServerIp = '8.8.8.8';
this.dnsServerPort = 53;
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
} else if (dnsProvider === 'cloudflare' && this.dnsServerIp !== '1.1.1.1') {
this.dnsServerIp = '1.1.1.1';
this.dnsServerPort = 53;
plugins.dns.setServers(['1.1.1.1', '1.0.0.1']);
} else {
throw new Error('unknown dns provider');
}
}
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number { public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
return this.dnsTypeMap[dnsTypeNameArg]; return this.dnsTypeMap[dnsTypeNameArg];
} }