Compare commits

...

27 Commits

Author SHA1 Message Date
ca72206ab4 4.0.10 2021-08-24 11:41:22 +02:00
0221c3207e fix(core): update 2021-08-24 11:41:22 +02:00
f2b8fa57af 4.0.9 2021-08-24 11:40:44 +02:00
e5b072d99b fix(core): update 2021-08-24 11:40:44 +02:00
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
a1203366d7 4.0.6 2021-01-22 22:20:40 +00:00
0deb77cda8 fix(core): update 2021-01-22 22:20:39 +00:00
ed8b7ec65a 4.0.5 2021-01-22 20:37:52 +00:00
6cfc12f83f fix(core): update 2021-01-22 20:37:51 +00:00
efd9bbb77a 4.0.4 2020-08-05 15:37:52 +00:00
b463aea274 fix(core): update 2020-08-05 15:37:51 +00:00
c8cf590a5a 4.0.3 2020-02-19 21:38:43 +00:00
42f679ef61 fix(core): update 2020-02-19 21:38:42 +00:00
0cb882bb7d 4.0.2 2020-02-15 16:46:46 +00:00
66f817cdf8 fix(core): update 2020-02-15 16:46:46 +00:00
5925c882c8 4.0.1 2020-02-15 16:46:04 +00:00
6f09a82eee fix(core): update 2020-02-15 16:46:04 +00:00
e23579709a 4.0.0 2020-02-15 16:41:38 +00:00
929e4152d3 BREAKING CHANGE(core): now uses Google DNS HTTPS API and handles DNSSEC validation 2020-02-15 16:41:37 +00:00
d0527affc2 3.0.8 2019-01-07 00:53:04 +01:00
f2ebaf74d9 fix(core): update 2019-01-07 00:53:04 +01:00
b6d8c36f3e 3.0.7 2019-01-07 00:28:27 +01:00
587600d571 3.0.6 2019-01-07 00:28:16 +01:00
17f293ca4e fix(core): update 2019-01-07 00:28:15 +01:00
11 changed files with 25686 additions and 1210 deletions

22
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/ .nogit/
pages/
public/ # artifacts
coverage/ coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,16 +1,16 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
# ==================== # ====================
# security stage # security stage
@ -18,127 +18,115 @@ stages:
mirror: mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
snyk: auditProductionDependencies:
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 -g snyk - npmci command npm install --production --ignore-scripts
- npmci command npm install --ignore-scripts - npmci command npm config set registry https://registry.npmjs.org
- npmci command snyk test - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
- notpriv
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true allow_failure: true
services:
- docker:stable-dind auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci command npm install --ignore-scripts
- npmci command npm run build - npmci command npm config set registry https://registry.npmjs.org
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm audit --audit-level=high --only=dev
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags: tags:
- docker - docker
- priv allow_failure: true
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testBuild:
testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# metadata stage # metadata stage
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services: only:
- docker:stable-dind - tags
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm prepare
--env SOURCE_CODE="$PWD" - npmci npm install
--volume "$PWD":/code - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags: tags:
- docker - lossless
- priv - docker
- priv
trigger: trigger:
stage: metadata stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:
@ -146,5 +134,5 @@ pages:
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,6 +1,14 @@
{ {
"gitzone": { "gitzone": {
"compliance": "standard" "projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartdns",
"shortDescription": "smart dns methods written in TypeScript",
"npmPackagename": "@pushrocks/smartdns",
"license": "MIT"
}
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],

26300
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{ {
"name": "@pushrocks/smartdns", "name": "@pushrocks/smartdns",
"version": "3.0.5", "version": "4.0.10",
"private": false, "private": false,
"description": "smart dns methods written in TypeScript", "description": "smart dns methods written in TypeScript",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)" "build": "(tsbuild --web)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -25,15 +25,34 @@
}, },
"homepage": "https://gitlab.com/pushrocks/dnsly#README", "homepage": "https://gitlab.com/pushrocks/dnsly#README",
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^2.0.5" "@pushrocks/smartenv": "^4.0.16",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@tsclass/tsclass": "^3.0.21",
"dns2": "^1.4.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.4", "@gitzone/tsbuild": "^2.1.24",
"@gitzone/tstest": "^1.0.18", "@gitzone/tstest": "^1.0.43",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^10.12.18", "@types/node": "^14.0.27",
"tslint": "^5.12.0", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.17.0" "tslint-config-prettier": "^1.18.0"
} },
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
} }

View File

@ -1,43 +1,53 @@
# @pushrocks/smartdns # @pushrocks/smartdns
smart dns methods written in TypeScript smart dns methods written in TypeScript
## Availabililty ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdns)
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@pushrocks/smartdns) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartdns)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdns) * [github.com (source mirror)](https://github.com/pushrocks/smartdns)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdns) * [docs (typedoc)](https://pushrocks.gitlab.io/smartdns/)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdns/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartdns/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdns/commits/master) Status Category | Status Badge
[![coverage report](https://GitLab.com/pushrocks/smartdns/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartdns/commits/master) -- | --
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartdns.svg)](https://www.npmjs.com/package/@pushrocks/smartdns) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdns/badges/master/pipeline.svg)](https://lossless.cloud)
[![Dependency Status](https://david-dm.org/pushrocks/smartdns.svg)](https://david-dm.org/pushrocks/smartdns) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdns/badges/master/coverage.svg)](https://lossless.cloud)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartdns/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartdns/master/dependencies/npm) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartdns)](https://lossless.cloud)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartdns/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartdns) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartdns)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartdns)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartdns)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartdns)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
```typescript ```typescript
let myDnsly = new dnsly.Dnsly('google'); // uses Google DNS Servers e.g 8.8.8.8 const mySmartDns = new smartdns.SmartDns(); // uses Google DNS Https API
myDnsly const demoRecord = await mySmartDns.getRecord('example.com', 'AAAA'); // returns promise
.getRecord('example.com', 'AAAA') // returns promise /*
.then((record: dnsly.I_AAAA) => { demoRecord looks like this:
// AAAA record for google.com, the I_AAAA will give you proper typings for the record return type {
// do something name: 'example.com',
}); type: 'A',
dnsSecEnabled: true,
value: '104.24.103.243'
}
*/
``` ```
For further information read the linked docs at the top of this README. ## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -5,7 +5,7 @@ import * as smartdns from '../ts/index';
let testDnsly: smartdns.Smartdns; let testDnsly: smartdns.Smartdns;
tap.test('should create an instance of Dnsly', async () => { tap.test('should create an instance of Dnsly', async () => {
testDnsly = new smartdns.Smartdns('google'); testDnsly = new smartdns.Smartdns({});
expect(testDnsly).to.be.instanceOf(smartdns.Smartdns); expect(testDnsly).to.be.instanceOf(smartdns.Smartdns);
}); });
@ -14,8 +14,9 @@ tap.test('should get an A DNS Record', async () => {
{ {
name: 'dnsly_a.bleu.de', name: 'dnsly_a.bleu.de',
value: '127.0.0.1', value: '127.0.0.1',
type: 'A' dnsSecEnabled: false,
} type: 'A',
},
]); ]);
}); });
@ -24,19 +25,20 @@ tap.test('should get an AAAA Record', async () => {
{ {
name: 'dnsly_aaaa.bleu.de', name: 'dnsly_aaaa.bleu.de',
value: '::1', value: '::1',
type: 'AAAA' dnsSecEnabled: false,
} type: 'AAAA',
},
]); ]);
}); });
tap.test('should get a txt record', async () => { tap.test('should get a txt record', async () => {
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([ return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
{ {
chunked: ['sometext_txt'],
name: 'dnsly_txt.bleu.de', name: 'dnsly_txt.bleu.de',
value: 'sometext_txt', value: 'sometext_txt',
type: 'TXT' type: 'TXT',
} dnsSecEnabled: false,
},
]); ]);
}); });
@ -65,4 +67,10 @@ tap.test('should get name server for hostname', async () => {
console.log(result); console.log(result);
}); });
tap.test('should detect dns sec', async () => {
const result = await testDnsly.getRecordA('lossless.com');
console.log(result[0]);
expect(result[0].dnsSecEnabled).to.be.true;
});
tap.start(); tap.start();

View File

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

View File

@ -1,37 +1,61 @@
import * as plugins from './dnsly.plugins'; import * as plugins from './dnsly.plugins';
export type TDnsProvider = 'google'; export type TDnsProvider = 'google' | 'cloudflare';
export type TDnsRecordType =
| 'A'
| 'AAAA'
| 'CNAME'
| 'PTR'
| 'MX'
| 'NAPTR'
| 'NS'
| 'SOA'
| 'SRV'
| 'TXT';
export interface IDnsRecord { export const makeNodeProcessUseDnsProvider = async (providerArg: TDnsProvider) => {
chunked?: string[]; switch (providerArg) {
name: string; case 'cloudflare':
type: TDnsRecordType; plugins.dns.setServers([
value: string; '1.1.1.1',
'1.0.0.1',
'[2606:4700:4700::1111]',
'[2606:4700:4700::1001]',
]);
break;
case 'google':
plugins.dns.setServers([
'8.8.8.8',
'8.8.4.4',
'[2001:4860:4860::8888]',
'[2606:4700:4700::1001]',
]);
}
};
export interface ISmartDnsConstructorOptions {}
export interface IGoogleDNSHTTPSResponse {
Status: number;
TC: boolean;
RD: boolean;
RA: boolean;
AD: boolean;
CD: boolean;
Question: Array<{ name: string; type: number }>;
Answer: Array<{ name: string; type: number; TTL: number; data: string }>;
Additional: [];
Comment: string;
} }
/** /**
* class dnsly offers methods for working with dns from a dns provider like Google DNS * class dnsly offers methods for working with dns from a dns provider like Google DNS
*/ */
export class Smartdns { export class Smartdns {
dnsServerIp: string; public dnsServerIp: string;
dnsServerPort: number; public dnsServerPort: number;
public dnsTypeMap: { [key: string]: number } = {
A: 1,
AAAA: 28,
CNAME: 5,
MX: 15,
TXT: 16,
};
/** /**
* constructor for class dnsly * constructor for class dnsly
*/ */
constructor(dnsProviderArg: TDnsProvider = 'google') { constructor(optionsArg: ISmartDnsConstructorOptions) {}
this._setDnsProvider(dnsProviderArg);
}
/** /**
* check a dns record until it has propagated to Google DNS * check a dns record until it has propagated to Google DNS
@ -40,30 +64,43 @@ export class Smartdns {
* @param recordTypeArg * @param recordTypeArg
* @param expectedValue * @param expectedValue
*/ */
async checkUntilAvailable( public async checkUntilAvailable(
recordNameArg: string, recordNameArg: string,
recordTypeArg: TDnsRecordType, recordTypeArg: plugins.tsclass.network.TDnsRecordType,
expectedValue: string expectedValue: string,
cyclesArg: number = 50,
intervalArg: number = 500
) { ) {
let cycleArg = 0; let runCycles = 0;
let doCheck = async () => { const doCheck = async () => {
if (cycleArg < 30) { if (runCycles < cyclesArg) {
cycleArg++; runCycles++;
try { try {
let myRecordArray = await this.getRecord(recordNameArg, recordTypeArg); let myRecordArray: plugins.tsclass.network.IDnsRecord[];
let myRecord = myRecordArray[0].value[0]; if (runCycles % 2 === 0 || !plugins.dns) {
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
} else {
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
}
const myRecord = myRecordArray[0].value;
if (myRecord === expectedValue) { if (myRecord === expectedValue) {
console.log(
`smartdns: .checkUntilAvailable() verified that wanted >>>${recordTypeArg}<<< record exists for >>>${recordNameArg}<<< with value >>>${expectedValue}<<<`
);
return true; return true;
} else { } else {
await plugins.smartdelay.delayFor(2000); await plugins.smartdelay.delayFor(intervalArg);
return await doCheck(); return await doCheck();
} }
} catch (err) { } catch (err) {
await plugins.smartdelay.delayFor(2000); // console.log(err);
await plugins.smartdelay.delayFor(intervalArg);
return await doCheck(); return await doCheck();
} }
} else { } else {
console.log('failed permanently...'); console.log(
`smartdns: .checkUntilAvailable() failed permanently for ${recordNameArg} with value ${recordTypeArg} - ${expectedValue}...`
);
return false; return false;
} }
}; };
@ -73,67 +110,84 @@ export class Smartdns {
/** /**
* get A Dns Record * get A Dns Record
*/ */
async getRecordA(recordNameArg: string): Promise<IDnsRecord[]> { public async getRecordA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
return await this.getRecord(recordNameArg, 'A'); return await this.getRecord(recordNameArg, 'A');
} }
/** /**
* get AAAA Record * get AAAA Record
*/ */
async getRecordAAAA(recordNameArg: string) { public async getRecordAAAA(recordNameArg: string) {
return await this.getRecord(recordNameArg, 'AAAA'); return await this.getRecord(recordNameArg, 'AAAA');
} }
/** /**
* gets a txt record * gets a txt record
*/ */
getRecordTxt(recordNameArg: string): Promise<IDnsRecord[]> { public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
let done = plugins.smartpromise.defer<IDnsRecord[]>(); return await this.getRecord(recordNameArg, 'TXT');
plugins.dns.resolveTxt(recordNameArg, (err, recordsArg) => { }
if (err) {
done.reject(err); public async getRecord(
return; recordNameArg: string,
} recordTypeArg: plugins.tsclass.network.TDnsRecordType
let responseArray: IDnsRecord[] = []; ): Promise<plugins.tsclass.network.IDnsRecord[]> {
for (let record of recordsArg) { const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
let recordAny: any = record; // fix wrong typings const response = await plugins.smartrequest.request(requestUrl, {
responseArray.push({ method: 'GET',
chunked: recordAny, headers: {
name: recordNameArg, accept: 'application/dns-json',
value: recordAny.join(' '), },
type: 'TXT'
});
}
done.resolve(responseArray);
}); });
return done.promise; const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
const responseBody: IGoogleDNSHTTPSResponse = response.body;
for (const dnsEntry of responseBody.Answer) {
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
}
if (dnsEntry.name.endsWith('.')) {
dnsEntry.name = dnsEntry.name.substring(0, dnsEntry.name.length - 1);
}
returnArray.push({
name: dnsEntry.name,
type: this.convertDnsTypeNumberToTypeName(dnsEntry.type),
dnsSecEnabled: responseBody.AD,
value: dnsEntry.data,
});
}
// console.log(responseBody);
return returnArray;
} }
/** /**
* get oridinary record * gets a record using nodejs dns resolver
*/ */
getRecord(recordNameArg: string, recordTypeArg: TDnsRecordType): Promise<IDnsRecord[]> { public async getRecordWithNodeDNS(
let done = plugins.smartpromise.defer<IDnsRecord[]>(); recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType
): Promise<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) {
done.reject(err); done.reject(err);
return; return;
} }
let responseArray: IDnsRecord[] = []; const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
for (let recordKey in recordsArg) { for (const recordKey in recordsArg) {
responseArray.push({ returnArray.push({
name: recordNameArg, name: recordNameArg,
value: recordsArg[recordKey], value: recordsArg[recordKey][0],
type: recordTypeArg type: recordTypeArg,
dnsSecEnabled: false,
}); });
} }
done.resolve(responseArray); done.resolve(returnArray);
}); });
return done.promise; return done.promise;
} }
getNameServer(domainNameArg: string) { public async getNameServer(domainNameArg: string): Promise<string[]> {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer<string[]>();
plugins.dns.resolveNs(domainNameArg, (err, result) => { plugins.dns.resolveNs(domainNameArg, (err, result) => {
if (!err) { if (!err) {
done.resolve(result); done.resolve(result);
@ -142,18 +196,21 @@ export class Smartdns {
done.reject(err); done.reject(err);
} }
}); });
return await done.promise;
} }
/** public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
* set the DNS provider return this.dnsTypeMap[dnsTypeNameArg];
*/ }
private _setDnsProvider(dnsProvider: TDnsProvider) {
if (dnsProvider === 'google') { public convertDnsTypeNumberToTypeName(
this.dnsServerIp = '8.8.8.8'; dnsTypeNumberArg: number
this.dnsServerPort = 53; ): plugins.tsclass.network.TDnsRecordType {
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']); for (const key in this.dnsTypeMap) {
} else { if (this.dnsTypeMap[key] === dnsTypeNumberArg) {
throw new Error('unknown dns provider'); return key as plugins.tsclass.network.TDnsRecordType;
}
} }
return null;
} }
} }