Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
1536475306 | |||
5c06ae1edb | |||
2cfecab96f | |||
7eb8a46c7c | |||
c56e732d6d | |||
aff5f2e7d9 | |||
6c38ff36d7 | |||
b45cda5084 | |||
dedd3a3f82 | |||
f2dffb6e88 | |||
2a1fbeb183 | |||
a6a47d2e96 | |||
84ad6bbcd6 | |||
4102c3a692 | |||
6281ab0c80 | |||
622c65291e | |||
dd8c97b99a | |||
9c56dc51e3 | |||
45cbd3a953 | |||
d3e2655212 | |||
e02b2253f5 | |||
862577745d | |||
ca72206ab4 | |||
0221c3207e | |||
f2b8fa57af | |||
e5b072d99b | |||
97c57b2865 | |||
e04485231d | |||
228bc88d60 | |||
811041b036 | |||
a1203366d7 | |||
0deb77cda8 |
125
.gitlab-ci.yml
125
.gitlab-ci.yml
@ -1,125 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
audit:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g tslint typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
95
changelog.md
Normal file
95
changelog.md
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-09-18 - 6.1.0 - feat(smartdns)
|
||||||
|
Add DNS Server and DNSSEC tools with comprehensive unit tests
|
||||||
|
|
||||||
|
- Updated package dependencies to the latest versions
|
||||||
|
- Introduced DnsServer class for handling DNS requests over both HTTPS and UDP with support for custom handlers
|
||||||
|
- Added DnsSec class for generating and managing DNSSEC keys and DS records
|
||||||
|
- Implemented unit tests for DnsServer and Smartdns classes
|
||||||
|
|
||||||
|
## 2024-06-02 - 6.0.0 - server/client
|
||||||
|
Main description here
|
||||||
|
|
||||||
|
- **Breaking Change:** Move from client only to server + client exports.
|
||||||
|
|
||||||
|
## 2024-03-30 - 5.0.4 - maintenance
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Switch to new org scheme
|
||||||
|
|
||||||
|
## 2023-04-08 - 5.0.4 - core
|
||||||
|
Main description here
|
||||||
|
|
||||||
|
- Core update
|
||||||
|
- Fixes applied to the system
|
||||||
|
|
||||||
|
## 2022-07-27 - 5.0.0 - core
|
||||||
|
Update contains relevant changes
|
||||||
|
|
||||||
|
- **Breaking Change:** Major update and core changes
|
||||||
|
- Fixes and updates applied
|
||||||
|
|
||||||
|
## 2022-07-27 - 4.0.11 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- **Breaking Change:** Core update and changes applied
|
||||||
|
|
||||||
|
## 2021-08-24 - 4.0.10 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Fixes applied to the core functionalities
|
||||||
|
|
||||||
|
## 2021-01-23 - 4.0.8 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Updates and fixes to the core components
|
||||||
|
|
||||||
|
## 2020-08-05 - 4.0.4 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Multiple core fixes applied
|
||||||
|
|
||||||
|
## 2020-02-15 - 4.0.0 - core
|
||||||
|
Main description here
|
||||||
|
|
||||||
|
- Core updates
|
||||||
|
- Fixes applied across the system
|
||||||
|
|
||||||
|
## 2020-02-15 - 3.0.8 - core
|
||||||
|
Core updates with major changes
|
||||||
|
|
||||||
|
- **Breaking Change:** Now uses Google DNS HTTPS API and handles DNSSEC validation
|
||||||
|
|
||||||
|
## 2019-01-07 - 3.0.6 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Fixes and updates applied to the core
|
||||||
|
|
||||||
|
## 2018-05-13 - 3.0.4 - core
|
||||||
|
Range contains relevant changes
|
||||||
|
|
||||||
|
- Fixes applied, including `fix .checkUntilAvailable` error
|
||||||
|
|
||||||
|
## 2018-05-13 - 3.0.0 - ci
|
||||||
|
Main description here
|
||||||
|
|
||||||
|
- CI changes and updates to the access level and global packages
|
||||||
|
|
||||||
|
## 2017-07-31 - 2.0.10 - package
|
||||||
|
Update to new package name and improved record retrieval
|
||||||
|
|
||||||
|
- **Breaking Change:** Package name update and record retrieval improvements
|
||||||
|
|
||||||
|
## 2017-01-27 - 2.0.1 - maintenance
|
||||||
|
Multiple fixes and merges
|
||||||
|
|
||||||
|
## 2017-01-27 - 2.0.0 - core
|
||||||
|
Fix typings and update to better API
|
||||||
|
|
||||||
|
## 2016-11-15 - 1.0.7 - initial
|
||||||
|
Initial setup and improvements
|
||||||
|
|
||||||
|
- Initial deployment
|
||||||
|
- README improvements
|
||||||
|
|
@ -2,17 +2,30 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartdns",
|
"gitrepo": "smartdns",
|
||||||
"shortDescription": "smart dns methods written in TypeScript",
|
"description": "A TypeScript library for smart DNS methods, supporting various DNS records and providers.",
|
||||||
"npmPackagename": "@pushrocks/smartdns",
|
"npmPackagename": "@push.rocks/smartdns",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"DNS",
|
||||||
|
"TypeScript",
|
||||||
|
"Node.js",
|
||||||
|
"Google DNS",
|
||||||
|
"Cloudflare",
|
||||||
|
"DNS records",
|
||||||
|
"DNS resolution",
|
||||||
|
"DNSSEC"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public",
|
"npmAccessLevel": "public",
|
||||||
"npmRegistryUrl": "registry.npmjs.org"
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
11006
package-lock.json
generated
11006
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
60
package.json
60
package.json
@ -1,43 +1,56 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdns",
|
"name": "@push.rocks/smartdns",
|
||||||
"version": "4.0.5",
|
"version": "6.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "smart dns methods written in TypeScript",
|
"description": "A TypeScript library for smart DNS methods, supporting various DNS records and providers.",
|
||||||
"main": "dist_ts/index.js",
|
"exports": {
|
||||||
"typings": "dist_ts/index.d.ts",
|
".": "./dist_ts_server/index.js",
|
||||||
|
"./server": "./dist_ts_server/index.js",
|
||||||
|
"./client": "./dist_ts_client/index.js"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild tsfolders --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/dnsly.git"
|
"url": "https://code.foss.global/push.rocks/smartdns.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"dns",
|
"DNS",
|
||||||
"google dns",
|
"TypeScript",
|
||||||
"dns record"
|
"Node.js",
|
||||||
|
"Google DNS",
|
||||||
|
"Cloudflare",
|
||||||
|
"DNS records",
|
||||||
|
"DNS resolution",
|
||||||
|
"DNSSEC"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/dnsly/issues"
|
"url": "https://gitlab.com/pushrocks/dnsly/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
"homepage": "https://code.foss.global/push.rocks/smartdns",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@push.rocks/smartdelay": "^3.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@push.rocks/smartenv": "^5.0.5",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@tsclass/tsclass": "^3.0.21",
|
"@push.rocks/smartrequest": "^2.0.15",
|
||||||
"dns2": "^1.4.2"
|
"@tsclass/tsclass": "^4.1.2",
|
||||||
|
"@types/dns-packet": "^5.6.5",
|
||||||
|
"@types/elliptic": "^6.4.18",
|
||||||
|
"dns-packet": "^5.6.1",
|
||||||
|
"elliptic": "^6.5.7",
|
||||||
|
"minimatch": "^10.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@git.zone/tsbuild": "^2.1.84",
|
||||||
"@gitzone/tstest": "^1.0.43",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@types/node": "^14.0.27",
|
"@push.rocks/tapbundle": "^5.2.0",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^22.5.5"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -53,5 +66,6 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
6987
pnpm-lock.yaml
generated
Normal file
6987
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
147
readme.md
147
readme.md
@ -1,53 +1,124 @@
|
|||||||
# @pushrocks/smartdns
|
# @push.rocks/smartdns
|
||||||
|
|
||||||
smart dns methods written in TypeScript
|
smart dns methods written in TypeScript
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [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
|
To install `@push.rocks/smartdns`, use the following command with npm:
|
||||||
|
|
||||||
Status Category | Status Badge
|
```bash
|
||||||
-- | --
|
npm install @push.rocks/smartdns --save
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
```
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
Or with `yarn`:
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
```bash
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
yarn add @push.rocks/smartdns
|
||||||
Code Style | [](https://lossless.cloud)
|
```
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
Make sure you have a TypeScript environment setup to utilize the library effectively.
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
`@push.rocks/smartdns` is a comprehensive library aimed at facilitating smart DNS operations, leveraging TypeScript for enhanced development experience. This section aims to cover several real-world scenarios demonstrating the library's capabilities, from basic DNS lookups to more advanced DNS management tasks.
|
||||||
|
|
||||||
|
### Getting Started
|
||||||
|
|
||||||
|
First, ensure you import the module into your TypeScript project:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const mySmartDns = new smartdns.SmartDns(); // uses Google DNS Https API
|
import { Smartdns } from '@push.rocks/smartdns';
|
||||||
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'
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribution
|
### Basic DNS Record Lookup
|
||||||
|
|
||||||
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). :)
|
Often, the need arises to fetch various DNS records for a domain. `@push.rocks/smartdns` simplifies this by providing intuitive methods.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
#### Fetching A Records
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
To fetch an "A" record for a domain:
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
```typescript
|
||||||
|
const dnsManager = new Smartdns({});
|
||||||
|
const aRecords = await dnsManager.getRecordsA('example.com');
|
||||||
|
console.log(aRecords);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Fetching AAAA Records
|
||||||
|
|
||||||
|
Similarly, for "AAAA" records:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const aaaaRecords = await dnsManager.getRecordsAAAA('example.com');
|
||||||
|
console.log(aaaaRecords);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced DNS Management
|
||||||
|
|
||||||
|
Beyond simple queries, `@push.rocks/smartdns` offers functionalities suitable for more complex DNS management scenarios.
|
||||||
|
|
||||||
|
#### Checking DNS Propagation
|
||||||
|
|
||||||
|
When changing DNS records, ensuring that the new records have propagated fully is crucial. `@push.rocks/smartdns` facilitates this with a method to check a DNS record until it is available globally.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const recordType = 'TXT'; // Record type: A, AAAA, CNAME, TXT etc.
|
||||||
|
const expectedValue = 'your_expected_value';
|
||||||
|
const isAvailable = await dnsManager.checkUntilAvailable('example.com', recordType, expectedValue);
|
||||||
|
|
||||||
|
if (isAvailable) {
|
||||||
|
console.log('Record propagated successfully.');
|
||||||
|
} else {
|
||||||
|
console.log('Record propagation failed or timed out.');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Leveraging DNS for Application Logic
|
||||||
|
|
||||||
|
DNS records can serve beyond mere domain-to-IP resolution; they can be instrumental in application logic, such as feature flagging or environment-specific configurations.
|
||||||
|
|
||||||
|
#### Example: Feature Flagging via TXT Records
|
||||||
|
|
||||||
|
Consider leveraging TXT records for enabling/disabling features dynamically without deploying new code.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const txtRecords = await dnsManager.getRecordsTxt('features.example.com');
|
||||||
|
const featureFlags = txtRecords.reduce((acc, record) => {
|
||||||
|
const [flag, isEnabled] = record.value.split('=');
|
||||||
|
acc[flag] = isEnabled === 'true';
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
if (featureFlags['NewFeature']) {
|
||||||
|
// Logic to enable the new feature
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
`@push.rocks/smartdns` offers a versatile set of tools for DNS querying and management, tailored for applications at any scale. The examples provided illustrate the library's potential use cases, highlighting its applicability in various scenarios from basic lookups to facilitating complex application features through DNS.
|
||||||
|
|
||||||
|
For the full spectrum of functionalities, including detailed method documentation and additional use cases, consult the module's [TypeDoc documentation](https://pushrocks.gitlab.io/smartdns/). This will serve as a comprehensive guide to leveraging `@push.rocks/smartdns` effectively in your projects.
|
||||||
|
|
||||||
|
Remember, DNS changes might take time to propagate worldwide, and the utility methods provided by `@push.rocks/smartdns` for checking record availability will be invaluable in managing these changes seamlessly.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
import * as smartdns from '../ts/index';
|
import * as smartdns from '../ts_client/index.js';
|
||||||
|
|
||||||
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({});
|
testDnsly = new smartdns.Smartdns({});
|
||||||
expect(testDnsly).to.be.instanceOf(smartdns.Smartdns);
|
expect(testDnsly).toBeInstanceOf(smartdns.Smartdns);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get an A DNS Record', async () => {
|
tap.test('should get an A DNS Record', async () => {
|
||||||
return expect(testDnsly.getRecordA('dnsly_a.bleu.de')).to.eventually.deep.equal([
|
return expect(await testDnsly.getRecordsA('dnsly_a.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_a.bleu.de',
|
name: 'dnsly_a.bleu.de',
|
||||||
value: '127.0.0.1',
|
value: '127.0.0.1',
|
||||||
@ -21,7 +21,7 @@ tap.test('should get an A DNS Record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get an AAAA Record', async () => {
|
tap.test('should get an AAAA Record', async () => {
|
||||||
return expect(testDnsly.getRecordAAAA('dnsly_aaaa.bleu.de')).to.eventually.deep.equal([
|
return expect(await testDnsly.getRecordsAAAA('dnsly_aaaa.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_aaaa.bleu.de',
|
name: 'dnsly_aaaa.bleu.de',
|
||||||
value: '::1',
|
value: '::1',
|
||||||
@ -32,7 +32,7 @@ tap.test('should get an AAAA Record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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(await testDnsly.getRecordsTxt('dnsly_txt.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_txt.bleu.de',
|
name: 'dnsly_txt.bleu.de',
|
||||||
value: 'sometext_txt',
|
value: 'sometext_txt',
|
||||||
@ -43,34 +43,37 @@ tap.test('should get a txt record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should, get a mx record for a domain', async () => {
|
tap.test('should, get a mx record for a domain', async () => {
|
||||||
const res = await testDnsly.getRecord('bleu.de', 'MX');
|
const res = await testDnsly.getRecords('bleu.de', 'MX');
|
||||||
console.log(res);
|
console.log(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available', async () => {
|
tap.test('should check until DNS is available', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')).to
|
return expect(
|
||||||
.eventually.be.true;
|
await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')
|
||||||
|
).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')).to
|
return expect(
|
||||||
.eventually.be.false;
|
await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')
|
||||||
|
).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2'))
|
return expect(
|
||||||
.to.eventually.be.false;
|
await testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2')
|
||||||
|
).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get name server for hostname', async () => {
|
tap.test('should get name server for hostname', async () => {
|
||||||
let result = await testDnsly.getNameServer('bleu.de');
|
let result = await testDnsly.getNameServers('bleu.de');
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should detect dns sec', async () => {
|
tap.test('should detect dns sec', async () => {
|
||||||
const result = await testDnsly.getRecordA('lossless.com');
|
const result = await testDnsly.getRecordsA('lossless.com');
|
||||||
console.log(result[0]);
|
console.log(result[0]);
|
||||||
expect(result[0].dnsSecEnabled).to.be.true;
|
expect(result[0].dnsSecEnabled).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
163
test/test.server.ts
Normal file
163
test/test.server.ts
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
import { tapNodeTools } from '@push.rocks/tapbundle/node';
|
||||||
|
|
||||||
|
import * as dnsPacket from 'dns-packet';
|
||||||
|
import * as https from 'https';
|
||||||
|
import * as dgram from 'dgram';
|
||||||
|
|
||||||
|
import * as smartdns from '../ts_server/index.js';
|
||||||
|
|
||||||
|
let dnsServer: smartdns.DnsServer;
|
||||||
|
|
||||||
|
tap.test('should create an instance of DnsServer', async () => {
|
||||||
|
// Use valid options
|
||||||
|
const httpsData = await tapNodeTools.createHttpsCert();
|
||||||
|
dnsServer = new smartdns.DnsServer({
|
||||||
|
httpsKey: httpsData.key,
|
||||||
|
httpsCert: httpsData.cert,
|
||||||
|
httpsPort: 8080,
|
||||||
|
udpPort: 8081,
|
||||||
|
});
|
||||||
|
expect(dnsServer).toBeInstanceOf(smartdns.DnsServer);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should start the server', async () => {
|
||||||
|
await dnsServer.start();
|
||||||
|
// @ts-ignore
|
||||||
|
expect(dnsServer.httpsServer).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('lets add a handler', async () => {
|
||||||
|
dnsServer.registerHandler('*.bleu.de', ['A'], (question) => {
|
||||||
|
return {
|
||||||
|
name: question.name,
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
ttl: 300,
|
||||||
|
data: '127.0.0.1',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const response = dnsServer.processDnsRequest({
|
||||||
|
type: 'query',
|
||||||
|
id: 1,
|
||||||
|
flags: 0,
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
answers: [],
|
||||||
|
});
|
||||||
|
expect(response.answers[0]).toEqual({
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
ttl: 300,
|
||||||
|
data: '127.0.0.1',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('lets query over https', async () => {
|
||||||
|
const query = dnsPacket.encode({
|
||||||
|
type: 'query',
|
||||||
|
id: 2,
|
||||||
|
flags: dnsPacket.RECURSION_DESIRED,
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await fetch('https://localhost:8080/dns-query', {
|
||||||
|
method: 'POST',
|
||||||
|
body: query,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/dns-message',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200);
|
||||||
|
|
||||||
|
const responseData = await response.arrayBuffer();
|
||||||
|
const dnsResponse = dnsPacket.decode(Buffer.from(responseData));
|
||||||
|
|
||||||
|
console.log(dnsResponse.answers[0]);
|
||||||
|
|
||||||
|
expect(dnsResponse.answers[0]).toEqual({
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
ttl: 300,
|
||||||
|
flush: false,
|
||||||
|
data: '127.0.0.1',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('lets query over udp', async () => {
|
||||||
|
const client = dgram.createSocket('udp4');
|
||||||
|
|
||||||
|
const query = dnsPacket.encode({
|
||||||
|
type: 'query',
|
||||||
|
id: 3,
|
||||||
|
flags: dnsPacket.RECURSION_DESIRED,
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const responsePromise = new Promise<dnsPacket.Packet>((resolve, reject) => {
|
||||||
|
client.on('message', (msg) => {
|
||||||
|
const dnsResponse = dnsPacket.decode(msg);
|
||||||
|
resolve(dnsResponse);
|
||||||
|
client.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
client.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.send(query, 8081, 'localhost', (err) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const dnsResponse = await responsePromise;
|
||||||
|
|
||||||
|
console.log(dnsResponse.answers[0]);
|
||||||
|
|
||||||
|
expect(dnsResponse.answers[0]).toEqual({
|
||||||
|
name: 'dnsly_a.bleu.de',
|
||||||
|
type: 'A',
|
||||||
|
class: 'IN',
|
||||||
|
ttl: 300,
|
||||||
|
flush: false,
|
||||||
|
data: '127.0.0.1',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should run for a while', async (toolsArg) => {
|
||||||
|
await toolsArg.delayFor(1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should stop the server', async () => {
|
||||||
|
await dnsServer.stop();
|
||||||
|
// @ts-ignore
|
||||||
|
expect(dnsServer.httpsServer).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
await tap.start();
|
@ -1,22 +0,0 @@
|
|||||||
// 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 { smartdelay, smartpromise, smartrequest };
|
|
||||||
|
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
|
||||||
|
|
||||||
export { tsclass };
|
|
||||||
|
|
||||||
// third party scope
|
|
||||||
import dns2 from 'dns2';
|
|
||||||
|
|
||||||
export {
|
|
||||||
dns2
|
|
||||||
}
|
|
8
ts_client/00_commitinfo_data.ts
Normal file
8
ts_client/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartdns',
|
||||||
|
version: '5.0.4',
|
||||||
|
description: 'smart dns methods written in TypeScript'
|
||||||
|
}
|
@ -1,10 +1,30 @@
|
|||||||
import * as plugins from './dnsly.plugins';
|
import * as plugins from './dnsly.plugins.js';
|
||||||
|
|
||||||
export type TDnsProvider = 'google' | 'cloudflare';
|
export type TDnsProvider = 'google' | 'cloudflare';
|
||||||
|
|
||||||
|
export const makeNodeProcessUseDnsProvider = (providerArg: TDnsProvider) => {
|
||||||
|
switch (providerArg) {
|
||||||
|
case 'cloudflare':
|
||||||
|
plugins.dns.setServers([
|
||||||
|
'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 ISmartDnsConstructorOptions {}
|
||||||
|
|
||||||
export interface IGoogleDNSHTTPSResponse {
|
export interface IDnsJsonResponse {
|
||||||
Status: number;
|
Status: number;
|
||||||
TC: boolean;
|
TC: boolean;
|
||||||
RD: boolean;
|
RD: boolean;
|
||||||
@ -24,8 +44,6 @@ export class Smartdns {
|
|||||||
public dnsServerIp: string;
|
public dnsServerIp: string;
|
||||||
public dnsServerPort: number;
|
public dnsServerPort: number;
|
||||||
|
|
||||||
public dns2 = new plugins.dns2();
|
|
||||||
|
|
||||||
public dnsTypeMap: { [key: string]: number } = {
|
public dnsTypeMap: { [key: string]: number } = {
|
||||||
A: 1,
|
A: 1,
|
||||||
AAAA: 28,
|
AAAA: 28,
|
||||||
@ -58,7 +76,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.getRecords(recordNameArg, recordTypeArg, 0);
|
||||||
|
} 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(
|
||||||
@ -67,11 +90,10 @@ export class Smartdns {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
await plugins.smartdelay.delayFor(intervalArg);
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
// lets try backup strategy
|
|
||||||
const backupResult = this.dns2[`resolve${recordTypeArg}`]('google.com')
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -88,37 +110,50 @@ export class Smartdns {
|
|||||||
/**
|
/**
|
||||||
* get A Dns Record
|
* get A Dns Record
|
||||||
*/
|
*/
|
||||||
public async getRecordA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
public async getRecordsA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
return await this.getRecord(recordNameArg, 'A');
|
return await this.getRecords(recordNameArg, 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get AAAA Record
|
* get AAAA Record
|
||||||
*/
|
*/
|
||||||
public async getRecordAAAA(recordNameArg: string) {
|
public async getRecordsAAAA(recordNameArg: string) {
|
||||||
return await this.getRecord(recordNameArg, 'AAAA');
|
return await this.getRecords(recordNameArg, 'AAAA');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets a txt record
|
* gets a txt record
|
||||||
*/
|
*/
|
||||||
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
public async getRecordsTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
return await this.getRecord(recordNameArg, 'TXT');
|
return await this.getRecords(recordNameArg, 'TXT');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getRecord(
|
public async getRecords(
|
||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
|
retriesCounterArg = 20
|
||||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
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',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
||||||
const responseBody: IGoogleDNSHTTPSResponse = response.body;
|
const getResponseBody = async (counterArg = 0): Promise<IDnsJsonResponse> => {
|
||||||
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
accept: 'application/dns-json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responseBody: IDnsJsonResponse = response.body;
|
||||||
|
if (responseBody?.Status !== 0 && counterArg < retriesCounterArg) {
|
||||||
|
await plugins.smartdelay.delayFor(500);
|
||||||
|
return getResponseBody(counterArg++);
|
||||||
|
} else {
|
||||||
|
return responseBody;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const responseBody = await getResponseBody();
|
||||||
|
if (!responseBody.Answer || !typeof responseBody.Answer[Symbol.iterator]) {
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
for (const dnsEntry of responseBody.Answer) {
|
for (const dnsEntry of responseBody.Answer) {
|
||||||
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
||||||
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
||||||
@ -144,7 +179,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) {
|
||||||
@ -165,7 +199,7 @@ export class Smartdns {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getNameServer(domainNameArg: string): Promise<string[]> {
|
public async getNameServers(domainNameArg: string): Promise<string[]> {
|
||||||
const done = plugins.smartpromise.defer<string[]>();
|
const done = plugins.smartpromise.defer<string[]>();
|
||||||
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@ -178,28 +212,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];
|
||||||
}
|
}
|
18
ts_client/dnsly.plugins.ts
Normal file
18
ts_client/dnsly.plugins.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import * as smartenv from '@push.rocks/smartenv';
|
||||||
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
|
// node native scope
|
||||||
|
import type dnsType from 'dns';
|
||||||
|
const dns: typeof dnsType = await smartenvInstance.getSafeNodeModule('dns');
|
||||||
|
|
||||||
|
export { dns };
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import * as smartrequest from '@push.rocks/smartrequest';
|
||||||
|
|
||||||
|
export { smartdelay, smartenv, smartpromise, smartrequest };
|
||||||
|
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export { tsclass };
|
1
ts_client/index.ts
Normal file
1
ts_client/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './classes.dnsclient.js';
|
147
ts_server/classes.dnsserver.ts
Normal file
147
ts_server/classes.dnsserver.ts
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
|
interface IDnsServerOptions {
|
||||||
|
httpsKey: string;
|
||||||
|
httpsCert: string;
|
||||||
|
httpsPort: number;
|
||||||
|
udpPort: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IDnsHandler {
|
||||||
|
domainPattern: string;
|
||||||
|
recordTypes: string[];
|
||||||
|
handler: (question: plugins.dnsPacket.Question) => plugins.dnsPacket.Answer | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DnsServer {
|
||||||
|
private udpServer: plugins.dgram.Socket;
|
||||||
|
private httpsServer: plugins.https.Server;
|
||||||
|
private handlers: IDnsHandler[] = [];
|
||||||
|
|
||||||
|
constructor(private options: IDnsServerOptions) {}
|
||||||
|
|
||||||
|
public registerHandler(
|
||||||
|
domainPattern: string,
|
||||||
|
recordTypes: string[],
|
||||||
|
handler: (question: plugins.dnsPacket.Question) => plugins.dnsPacket.Answer | null
|
||||||
|
): void {
|
||||||
|
this.handlers.push({ domainPattern, recordTypes, handler });
|
||||||
|
}
|
||||||
|
|
||||||
|
private processDnsRequest(request: plugins.dnsPacket.Packet): plugins.dnsPacket.Packet {
|
||||||
|
const response: plugins.dnsPacket.Packet = {
|
||||||
|
type: 'response',
|
||||||
|
id: request.id,
|
||||||
|
flags: plugins.dnsPacket.RECURSION_DESIRED | plugins.dnsPacket.RECURSION_AVAILABLE,
|
||||||
|
questions: request.questions,
|
||||||
|
answers: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const question of request.questions) {
|
||||||
|
console.log(`Query for ${question.name} of type ${question.type}`);
|
||||||
|
|
||||||
|
let answered = false;
|
||||||
|
|
||||||
|
for (const handlerEntry of this.handlers) {
|
||||||
|
if (
|
||||||
|
plugins.minimatch.minimatch(question.name, handlerEntry.domainPattern) &&
|
||||||
|
handlerEntry.recordTypes.includes(question.type)
|
||||||
|
) {
|
||||||
|
const answer = handlerEntry.handler(question);
|
||||||
|
if (answer) {
|
||||||
|
response.answers.push(answer);
|
||||||
|
answered = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!answered) {
|
||||||
|
console.log(`No handler found for ${question.name} of type ${question.type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleHttpsRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): void {
|
||||||
|
if (req.method === 'POST' && req.url === '/dns-query') {
|
||||||
|
let body: Buffer[] = [];
|
||||||
|
|
||||||
|
req.on('data', chunk => {
|
||||||
|
body.push(chunk);
|
||||||
|
}).on('end', () => {
|
||||||
|
const msg = Buffer.concat(body);
|
||||||
|
const request = plugins.dnsPacket.decode(msg);
|
||||||
|
const response = this.processDnsRequest(request);
|
||||||
|
const responseData = plugins.dnsPacket.encode(response);
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/dns-message' });
|
||||||
|
res.end(responseData);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.writeHead(404);
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start(): Promise<void> {
|
||||||
|
this.httpsServer = plugins.https.createServer(
|
||||||
|
{
|
||||||
|
key: this.options.httpsKey,
|
||||||
|
cert: this.options.httpsCert,
|
||||||
|
},
|
||||||
|
this.handleHttpsRequest.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.udpServer = plugins.dgram.createSocket('udp4');
|
||||||
|
this.udpServer.on('message', (msg, rinfo) => {
|
||||||
|
const request = plugins.dnsPacket.decode(msg);
|
||||||
|
const response = this.processDnsRequest(request);
|
||||||
|
const responseData = plugins.dnsPacket.encode(response);
|
||||||
|
this.udpServer.send(responseData, rinfo.port, rinfo.address);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.udpServer.on('error', (err) => {
|
||||||
|
console.error(`UDP Server error:\n${err.stack}`);
|
||||||
|
this.udpServer.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
const udpListeningDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
const httpsListeningDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
try {
|
||||||
|
this.udpServer.bind(this.options.udpPort, '0.0.0.0', () => {
|
||||||
|
console.log(`UDP DNS server running on port ${this.options.udpPort}`);
|
||||||
|
udpListeningDeferred.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.httpsServer.listen(this.options.httpsPort, () => {
|
||||||
|
console.log(`HTTPS DNS server running on port ${this.options.httpsPort}`);
|
||||||
|
httpsListeningDeferred.resolve();
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error starting DNS server:', err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
await Promise.all([udpListeningDeferred.promise, httpsListeningDeferred.promise]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop(): Promise<void> {
|
||||||
|
const doneUdp = plugins.smartpromise.defer<void>();
|
||||||
|
const doneHttps = plugins.smartpromise.defer<void>();
|
||||||
|
this.udpServer.close(() => {
|
||||||
|
console.log('UDP DNS server stopped');
|
||||||
|
this.udpServer.unref();
|
||||||
|
this.udpServer = null;
|
||||||
|
doneUdp.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.httpsServer.close(() => {
|
||||||
|
console.log('HTTPS DNS server stopped');
|
||||||
|
this.httpsServer.unref();
|
||||||
|
this.httpsServer = null;
|
||||||
|
doneHttps.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([doneUdp.promise, doneHttps.promise]);
|
||||||
|
}
|
||||||
|
}
|
83
ts_server/classes.dnstools.ts
Normal file
83
ts_server/classes.dnstools.ts
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
|
interface DnssecZone {
|
||||||
|
zone: string;
|
||||||
|
algorithm: string;
|
||||||
|
keySize: number;
|
||||||
|
days: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DnssecKeyPair {
|
||||||
|
private: string;
|
||||||
|
public: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DnsSec {
|
||||||
|
private zone: DnssecZone;
|
||||||
|
private keyPair: DnssecKeyPair;
|
||||||
|
private ec: any; // declare the ec instance
|
||||||
|
|
||||||
|
constructor(zone: DnssecZone) {
|
||||||
|
this.zone = zone;
|
||||||
|
this.ec = new plugins.elliptic.ec('secp256k1'); // Create an instance of the secp256k1 curve
|
||||||
|
this.keyPair = this.generateKeyPair();
|
||||||
|
}
|
||||||
|
|
||||||
|
private generateKeyPair(): DnssecKeyPair {
|
||||||
|
const key = this.ec.genKeyPair();
|
||||||
|
const privatePem = key.getPrivate().toString('hex'); // get private key in hex format
|
||||||
|
// @ts-ignore
|
||||||
|
const publicPem = key.getPublic().toString('hex'); // get public key in hex format
|
||||||
|
|
||||||
|
return {
|
||||||
|
private: privatePem,
|
||||||
|
public: publicPem
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private formatPEM(pem: string, type: string): string {
|
||||||
|
const start = `-----BEGIN ${type}-----`;
|
||||||
|
const end = `-----END ${type}-----`;
|
||||||
|
|
||||||
|
const formatted = [start];
|
||||||
|
for (let i = 0; i < pem.length; i += 64) {
|
||||||
|
formatted.push(pem.slice(i, i + 64));
|
||||||
|
}
|
||||||
|
formatted.push(end);
|
||||||
|
return formatted.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDSRecord(): string {
|
||||||
|
const publicPem = this.keyPair.public;
|
||||||
|
const publicKey = this.ec.keyFromPublic(publicPem); // Create a public key from the publicPEM
|
||||||
|
|
||||||
|
const digest = publicKey.getPublic(); // get public point
|
||||||
|
return `DS {id} 8 {algorithm} {digest} {hash-algorithm}\n`
|
||||||
|
.replace('{id}', '256') // zone hash
|
||||||
|
.replace('{algorithm}', this.getAlgorithm())
|
||||||
|
.replace('{digest}', `0x${digest.getX()}${digest.getY()}`)
|
||||||
|
.replace('{hash-algorithm}', '2');
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAlgorithm(): string {
|
||||||
|
switch (this.zone.algorithm) {
|
||||||
|
case 'ECDSA':
|
||||||
|
return '8';
|
||||||
|
case 'ED25519':
|
||||||
|
return '15';
|
||||||
|
case 'RSA':
|
||||||
|
return '1';
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported algorithm: ${this.zone.algorithm}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getKeyPair(): DnssecKeyPair {
|
||||||
|
return this.keyPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDsAndKeyPair(): [DnssecKeyPair, string] {
|
||||||
|
const dsRecord = this.getDSRecord();
|
||||||
|
return [this.keyPair, dsRecord];
|
||||||
|
}
|
||||||
|
}
|
1
ts_server/index.ts
Normal file
1
ts_server/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './classes.dnsserver.js';
|
30
ts_server/plugins.ts
Normal file
30
ts_server/plugins.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// node native
|
||||||
|
import fs from 'fs';
|
||||||
|
import http from 'http';
|
||||||
|
import https from 'https';
|
||||||
|
import dgram from 'dgram';
|
||||||
|
|
||||||
|
export {
|
||||||
|
fs,
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
dgram,
|
||||||
|
}
|
||||||
|
|
||||||
|
// @push.rocks scope
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartpromise,
|
||||||
|
}
|
||||||
|
|
||||||
|
// third party
|
||||||
|
import * as elliptic from 'elliptic';
|
||||||
|
import * as dnsPacket from 'dns-packet';
|
||||||
|
import * as minimatch from 'minimatch';
|
||||||
|
|
||||||
|
export {
|
||||||
|
dnsPacket,
|
||||||
|
elliptic,
|
||||||
|
minimatch,
|
||||||
|
}
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user