Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
efd9bbb77a | |||
b463aea274 | |||
c8cf590a5a | |||
42f679ef61 | |||
0cb882bb7d | |||
66f817cdf8 | |||
5925c882c8 | |||
6f09a82eee | |||
e23579709a | |||
929e4152d3 | |||
d0527affc2 | |||
f2ebaf74d9 | |||
b6d8c36f3e | |||
587600d571 | |||
17f293ca4e |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
pages/
|
||||
public/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,127 +18,102 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
audit:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- 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:
|
||||
- docker
|
||||
- priv
|
||||
- docker
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -146,5 +121,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,6 +1,14 @@
|
||||
{
|
||||
"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": {
|
||||
"npmGlobalTools": [],
|
||||
|
11382
package-lock.json
generated
11382
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdns",
|
||||
"version": "3.0.5",
|
||||
"version": "4.0.4",
|
||||
"private": false,
|
||||
"description": "smart dns methods written in TypeScript",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,15 +25,32 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartpromise": "^2.0.5"
|
||||
"@pushrocks/smartdelay": "^2.0.10",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartrequest": "^1.1.47",
|
||||
"@tsclass/tsclass": "^3.0.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.27",
|
||||
"tslint": "^6.1.3",
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
62
readme.md
62
readme.md
@ -1,43 +1,53 @@
|
||||
# @pushrocks/smartdns
|
||||
|
||||
smart dns methods written in TypeScript
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||
[](https://GitLab.com/pushrocks/smartdns)
|
||||
[](https://github.com/pushrocks/smartdns)
|
||||
[](https://pushrocks.gitlab.io/smartdns/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdns)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartdns)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdns/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||
[](https://david-dm.org/pushrocks/smartdns)
|
||||
[](https://www.bithound.io/github/pushrocks/smartdns/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartdns)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```typescript
|
||||
let myDnsly = new dnsly.Dnsly('google'); // uses Google DNS Servers e.g 8.8.8.8
|
||||
myDnsly
|
||||
.getRecord('example.com', 'AAAA') // returns promise
|
||||
.then((record: dnsly.I_AAAA) => {
|
||||
// AAAA record for google.com, the I_AAAA will give you proper typings for the record return type
|
||||
// do something
|
||||
});
|
||||
const mySmartDns = new smartdns.SmartDns(); // uses Google DNS Https API
|
||||
const demoRecord = await mySmartDns.getRecord('example.com', 'AAAA'); // returns promise
|
||||
/*
|
||||
demoRecord looks like this:
|
||||
{
|
||||
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)
|
||||
> | 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)
|
||||
|
||||
[](https://push.rocks)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
24
test/test.ts
24
test/test.ts
@ -5,7 +5,7 @@ import * as smartdns from '../ts/index';
|
||||
let testDnsly: smartdns.Smartdns;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
@ -14,8 +14,9 @@ tap.test('should get an A DNS Record', async () => {
|
||||
{
|
||||
name: 'dnsly_a.bleu.de',
|
||||
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',
|
||||
value: '::1',
|
||||
type: 'AAAA'
|
||||
}
|
||||
dnsSecEnabled: false,
|
||||
type: 'AAAA',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
tap.test('should get a txt record', async () => {
|
||||
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
|
||||
{
|
||||
chunked: ['sometext_txt'],
|
||||
name: 'dnsly_txt.bleu.de',
|
||||
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);
|
||||
});
|
||||
|
||||
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();
|
||||
|
@ -1,5 +1,15 @@
|
||||
// node native scope
|
||||
import * as dns from 'dns';
|
||||
|
||||
export { dns };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { dns, smartdelay, smartpromise };
|
||||
export { smartdelay, smartpromise, smartrequest };
|
||||
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export { tsclass };
|
||||
|
190
ts/index.ts
190
ts/index.ts
@ -1,37 +1,41 @@
|
||||
import * as plugins from './dnsly.plugins';
|
||||
|
||||
export type TDnsProvider = 'google';
|
||||
export type TDnsRecordType =
|
||||
| 'A'
|
||||
| 'AAAA'
|
||||
| 'CNAME'
|
||||
| 'PTR'
|
||||
| 'MX'
|
||||
| 'NAPTR'
|
||||
| 'NS'
|
||||
| 'SOA'
|
||||
| 'SRV'
|
||||
| 'TXT';
|
||||
export type TDnsProvider = 'google' | 'cloudflare';
|
||||
|
||||
export interface IDnsRecord {
|
||||
chunked?: string[];
|
||||
name: string;
|
||||
type: TDnsRecordType;
|
||||
value: string;
|
||||
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
|
||||
*/
|
||||
export class Smartdns {
|
||||
dnsServerIp: string;
|
||||
dnsServerPort: number;
|
||||
public dnsServerIp: string;
|
||||
public dnsServerPort: number;
|
||||
|
||||
public dnsTypeMap: { [key: string]: number } = {
|
||||
A: 1,
|
||||
AAAA: 28,
|
||||
CNAME: 5,
|
||||
MX: 15,
|
||||
TXT: 16,
|
||||
};
|
||||
|
||||
/**
|
||||
* constructor for class dnsly
|
||||
*/
|
||||
constructor(dnsProviderArg: TDnsProvider = 'google') {
|
||||
this._setDnsProvider(dnsProviderArg);
|
||||
}
|
||||
constructor(optionsArg: ISmartDnsConstructorOptions) {}
|
||||
|
||||
/**
|
||||
* check a dns record until it has propagated to Google DNS
|
||||
@ -40,30 +44,37 @@ export class Smartdns {
|
||||
* @param recordTypeArg
|
||||
* @param expectedValue
|
||||
*/
|
||||
async checkUntilAvailable(
|
||||
public async checkUntilAvailable(
|
||||
recordNameArg: string,
|
||||
recordTypeArg: TDnsRecordType,
|
||||
expectedValue: string
|
||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
expectedValue: string,
|
||||
cyclesArg: number = 50,
|
||||
intervalArg: number = 500
|
||||
) {
|
||||
let cycleArg = 0;
|
||||
let doCheck = async () => {
|
||||
if (cycleArg < 30) {
|
||||
cycleArg++;
|
||||
let runCycles = 0;
|
||||
const doCheck = async () => {
|
||||
if (runCycles < cyclesArg) {
|
||||
runCycles++;
|
||||
try {
|
||||
let myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
|
||||
let myRecord = myRecordArray[0].value[0];
|
||||
const myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
||||
const myRecord = myRecordArray[0].value;
|
||||
if (myRecord === expectedValue) {
|
||||
console.log(
|
||||
`smartdns: .checkUntilAvailable() verified that wanted >>>${recordTypeArg}<<< record exists for >>>${recordNameArg}<<< with value >>>${expectedValue}<<<`
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
await plugins.smartdelay.delayFor(2000);
|
||||
await plugins.smartdelay.delayFor(intervalArg);
|
||||
return await doCheck();
|
||||
}
|
||||
} catch (err) {
|
||||
await plugins.smartdelay.delayFor(2000);
|
||||
await plugins.smartdelay.delayFor(intervalArg);
|
||||
return await doCheck();
|
||||
}
|
||||
} else {
|
||||
console.log('failed permanently...');
|
||||
console.log(
|
||||
`smartdns: .checkUntilAvailable() failed permanently for ${recordNameArg} with value ${recordTypeArg} - ${expectedValue}...`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -73,67 +84,85 @@ export class Smartdns {
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* get AAAA Record
|
||||
*/
|
||||
async getRecordAAAA(recordNameArg: string) {
|
||||
public async getRecordAAAA(recordNameArg: string) {
|
||||
return await this.getRecord(recordNameArg, 'AAAA');
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a txt record
|
||||
*/
|
||||
getRecordTxt(recordNameArg: string): Promise<IDnsRecord[]> {
|
||||
let done = plugins.smartpromise.defer<IDnsRecord[]>();
|
||||
plugins.dns.resolveTxt(recordNameArg, (err, recordsArg) => {
|
||||
if (err) {
|
||||
done.reject(err);
|
||||
return;
|
||||
}
|
||||
let responseArray: IDnsRecord[] = [];
|
||||
for (let record of recordsArg) {
|
||||
let recordAny: any = record; // fix wrong typings
|
||||
responseArray.push({
|
||||
chunked: recordAny,
|
||||
name: recordNameArg,
|
||||
value: recordAny.join(' '),
|
||||
type: 'TXT'
|
||||
});
|
||||
}
|
||||
done.resolve(responseArray);
|
||||
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
return await this.getRecord(recordNameArg, 'TXT');
|
||||
}
|
||||
|
||||
public async getRecord(
|
||||
recordNameArg: string,
|
||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
||||
const response = await plugins.smartrequest.request(requestUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
accept: 'application/dns-json',
|
||||
},
|
||||
});
|
||||
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[]> {
|
||||
let done = plugins.smartpromise.defer<IDnsRecord[]>();
|
||||
public async getRecordWithNodeDNS(
|
||||
recordNameArg: string,
|
||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
this.setNodeDnsProvider('cloudflare');
|
||||
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
||||
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
||||
if (err) {
|
||||
done.reject(err);
|
||||
return;
|
||||
}
|
||||
let responseArray: IDnsRecord[] = [];
|
||||
for (let recordKey in recordsArg) {
|
||||
responseArray.push({
|
||||
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
||||
for (const recordKey in recordsArg) {
|
||||
returnArray.push({
|
||||
name: recordNameArg,
|
||||
value: recordsArg[recordKey],
|
||||
type: recordTypeArg
|
||||
value: recordsArg[recordKey][0],
|
||||
type: recordTypeArg,
|
||||
dnsSecEnabled: false,
|
||||
});
|
||||
}
|
||||
done.resolve(responseArray);
|
||||
done.resolve(returnArray);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
getNameServer(domainNameArg: string) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
public async getNameServer(domainNameArg: string): Promise<string[]> {
|
||||
const done = plugins.smartpromise.defer<string[]>();
|
||||
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
||||
if (!err) {
|
||||
done.resolve(result);
|
||||
@ -142,18 +171,43 @@ export class Smartdns {
|
||||
done.reject(err);
|
||||
}
|
||||
});
|
||||
return await done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the DNS provider
|
||||
*/
|
||||
private _setDnsProvider(dnsProvider: TDnsProvider) {
|
||||
if (dnsProvider === 'google') {
|
||||
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 {
|
||||
return this.dnsTypeMap[dnsTypeNameArg];
|
||||
}
|
||||
|
||||
public convertDnsTypeNumberToTypeName(
|
||||
dnsTypeNumberArg: number
|
||||
): plugins.tsclass.network.TDnsRecordType {
|
||||
for (const key in this.dnsTypeMap) {
|
||||
if (this.dnsTypeMap[key] === dnsTypeNumberArg) {
|
||||
return key as plugins.tsclass.network.TDnsRecordType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user