Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2cfecab96f | |||
7eb8a46c7c | |||
c56e732d6d | |||
aff5f2e7d9 | |||
6c38ff36d7 | |||
b45cda5084 | |||
dedd3a3f82 | |||
f2dffb6e88 | |||
2a1fbeb183 | |||
a6a47d2e96 |
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,128 +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
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm 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 typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
@ -2,17 +2,30 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartdns",
|
||||
"description": "smart dns methods written in TypeScript",
|
||||
"npmPackagename": "@pushrocks/smartdns",
|
||||
"license": "MIT"
|
||||
"description": "A TypeScript library for smart DNS methods, supporting various DNS records and providers.",
|
||||
"npmPackagename": "@push.rocks/smartdns",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"DNS",
|
||||
"TypeScript",
|
||||
"Node.js",
|
||||
"Google DNS",
|
||||
"Cloudflare",
|
||||
"DNS records",
|
||||
"DNS resolution",
|
||||
"DNSSEC"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public",
|
||||
"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"
|
||||
}
|
||||
}
|
53
package.json
53
package.json
@ -1,44 +1,53 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdns",
|
||||
"version": "5.0.3",
|
||||
"name": "@push.rocks/smartdns",
|
||||
"version": "6.0.0",
|
||||
"private": false,
|
||||
"description": "smart dns methods written in TypeScript",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"description": "A TypeScript library for smart DNS methods, supporting various DNS records and providers.",
|
||||
"exports": {
|
||||
".": "./dist_ts_server/index.js",
|
||||
"./server": "./dist_ts_server/index.js",
|
||||
"./client": "./dist_ts_client/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"build": "(tsbuild tsfolders --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/dnsly.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartdns.git"
|
||||
},
|
||||
"keywords": [
|
||||
"dns",
|
||||
"google dns",
|
||||
"dns record"
|
||||
"DNS",
|
||||
"TypeScript",
|
||||
"Node.js",
|
||||
"Google DNS",
|
||||
"Cloudflare",
|
||||
"DNS records",
|
||||
"DNS resolution",
|
||||
"DNSSEC"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/dnsly/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartdns",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartenv": "^5.0.2",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^2.0.11",
|
||||
"@tsclass/tsclass": "^4.0.17",
|
||||
"dns2": "^2.0.5"
|
||||
"@push.rocks/smartdelay": "^3.0.1",
|
||||
"@push.rocks/smartenv": "^5.0.5",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartrequest": "^2.0.15",
|
||||
"@tsclass/tsclass": "^4.0.54",
|
||||
"@types/dns-packet": "^5.6.5",
|
||||
"dns-packet": "^5.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.1"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.13.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
8340
pnpm-lock.yaml
generated
8340
pnpm-lock.yaml
generated
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,51 +1,124 @@
|
||||
# @pushrocks/smartdns
|
||||
# @push.rocks/smartdns
|
||||
|
||||
smart dns methods written in TypeScript
|
||||
|
||||
## 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/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
To install `@push.rocks/smartdns`, use the following command with npm:
|
||||
|
||||
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)
|
||||
```bash
|
||||
npm install @push.rocks/smartdns --save
|
||||
```
|
||||
|
||||
Or with `yarn`:
|
||||
|
||||
```bash
|
||||
yarn add @push.rocks/smartdns
|
||||
```
|
||||
|
||||
Make sure you have a TypeScript environment setup to utilize the library effectively.
|
||||
|
||||
## 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
|
||||
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'
|
||||
}
|
||||
*/
|
||||
import { Smartdns } from '@push.rocks/smartdns';
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
To fetch an "A" record for a domain:
|
||||
|
||||
```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,6 +1,6 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as smartdns from '../ts/index.js';
|
||||
import * as smartdns from '../ts_client/index.js';
|
||||
|
||||
let testDnsly: smartdns.Smartdns;
|
||||
|
||||
@ -10,7 +10,7 @@ tap.test('should create an instance of Dnsly', async () => {
|
||||
});
|
||||
|
||||
tap.test('should get an A DNS Record', async () => {
|
||||
return expect(await testDnsly.getRecordA('dnsly_a.bleu.de')).toEqual([
|
||||
return expect(await testDnsly.getRecordsA('dnsly_a.bleu.de')).toEqual([
|
||||
{
|
||||
name: 'dnsly_a.bleu.de',
|
||||
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 () => {
|
||||
return expect(await testDnsly.getRecordAAAA('dnsly_aaaa.bleu.de')).toEqual([
|
||||
return expect(await testDnsly.getRecordsAAAA('dnsly_aaaa.bleu.de')).toEqual([
|
||||
{
|
||||
name: 'dnsly_aaaa.bleu.de',
|
||||
value: '::1',
|
||||
@ -32,7 +32,7 @@ tap.test('should get an AAAA Record', async () => {
|
||||
});
|
||||
|
||||
tap.test('should get a txt record', async () => {
|
||||
return expect(await testDnsly.getRecordTxt('dnsly_txt.bleu.de')).toEqual([
|
||||
return expect(await testDnsly.getRecordsTxt('dnsly_txt.bleu.de')).toEqual([
|
||||
{
|
||||
name: 'dnsly_txt.bleu.de',
|
||||
value: 'sometext_txt',
|
||||
@ -43,7 +43,7 @@ tap.test('should get a txt record', 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);
|
||||
});
|
||||
|
||||
@ -66,12 +66,12 @@ tap.test('should check until DNS is available an return false if it fails', asyn
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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]);
|
||||
expect(result[0].dnsSecEnabled).toBeTrue();
|
||||
});
|
0
test/test.server.ts
Normal file
0
test/test.server.ts
Normal file
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartdns',
|
||||
version: '5.0.3',
|
||||
description: 'smart dns methods written in TypeScript'
|
||||
}
|
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'
|
||||
}
|
@ -78,7 +78,7 @@ export class Smartdns {
|
||||
try {
|
||||
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
||||
if (runCycles % 2 === 0 || !plugins.dns) {
|
||||
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg, 0);
|
||||
myRecordArray = await this.getRecords(recordNameArg, recordTypeArg, 0);
|
||||
} else {
|
||||
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
||||
}
|
||||
@ -110,25 +110,25 @@ export class Smartdns {
|
||||
/**
|
||||
* get A Dns Record
|
||||
*/
|
||||
public async getRecordA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
return await this.getRecord(recordNameArg, 'A');
|
||||
public async getRecordsA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
return await this.getRecords(recordNameArg, 'A');
|
||||
}
|
||||
|
||||
/**
|
||||
* get AAAA Record
|
||||
*/
|
||||
public async getRecordAAAA(recordNameArg: string) {
|
||||
return await this.getRecord(recordNameArg, 'AAAA');
|
||||
public async getRecordsAAAA(recordNameArg: string) {
|
||||
return await this.getRecords(recordNameArg, 'AAAA');
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a txt record
|
||||
*/
|
||||
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
return await this.getRecord(recordNameArg, 'TXT');
|
||||
public async getRecordsTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||
return await this.getRecords(recordNameArg, 'TXT');
|
||||
}
|
||||
|
||||
public async getRecord(
|
||||
public async getRecords(
|
||||
recordNameArg: string,
|
||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
retriesCounterArg = 20
|
||||
@ -151,6 +151,9 @@ export class Smartdns {
|
||||
}
|
||||
};
|
||||
const responseBody = await getResponseBody();
|
||||
if (!responseBody.Answer || !typeof responseBody.Answer[Symbol.iterator]) {
|
||||
return returnArray;
|
||||
}
|
||||
for (const dnsEntry of responseBody.Answer) {
|
||||
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
||||
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
||||
@ -196,7 +199,7 @@ export class Smartdns {
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
public async getNameServer(domainNameArg: string): Promise<string[]> {
|
||||
public async getNameServers(domainNameArg: string): Promise<string[]> {
|
||||
const done = plugins.smartpromise.defer<string[]>();
|
||||
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
||||
if (!err) {
|
@ -1,4 +1,4 @@
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
import * as smartenv from '@push.rocks/smartenv';
|
||||
const smartenvInstance = new smartenv.Smartenv();
|
||||
// node native scope
|
||||
import type dnsType from 'dns';
|
||||
@ -7,9 +7,9 @@ const dns: typeof dnsType = await smartenvInstance.getSafeNodeModule('dns');
|
||||
export { dns };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
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 };
|
||||
|
1
ts_client/index.ts
Normal file
1
ts_client/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './classes.dnsclient.js';
|
120
ts_server/classes.dnsserver.ts
Normal file
120
ts_server/classes.dnsserver.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
interface IDnsServerOptions {
|
||||
httpsKey: string;
|
||||
httpsCert: string;
|
||||
httpsPort: number;
|
||||
udpPort: number;
|
||||
}
|
||||
|
||||
class DnsServer {
|
||||
private udpServer: plugins.dgram.Socket;
|
||||
private httpsServer: plugins.https.Server;
|
||||
|
||||
constructor(private options: IDnsServerOptions) {
|
||||
this.udpServer = plugins.dgram.createSocket('udp4');
|
||||
this.setupUdpServer();
|
||||
|
||||
this.httpsServer = plugins.https.createServer(
|
||||
{
|
||||
key: plugins.fs.readFileSync(options.httpsKey),
|
||||
cert: plugins.fs.readFileSync(options.httpsCert)
|
||||
},
|
||||
this.handleHttpsRequest.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
private setupUdpServer(): void {
|
||||
this.udpServer.on('message', (msg, rinfo) => {
|
||||
const request = plugins.dnsPacket.decode(msg);
|
||||
const response = {
|
||||
type: 'response' as const,
|
||||
id: request.id,
|
||||
flags: plugins.dnsPacket.RECURSION_DESIRED | plugins.dnsPacket.RECURSION_AVAILABLE,
|
||||
questions: request.questions,
|
||||
answers: [] as plugins.dnsPacket.Answer[]
|
||||
};
|
||||
|
||||
const question = request.questions[0];
|
||||
console.log(`UDP query for ${question.name} of type ${question.type}`);
|
||||
|
||||
if (question.type === 'A') {
|
||||
response.answers.push({
|
||||
name: question.name,
|
||||
type: 'A',
|
||||
class: 'IN',
|
||||
ttl: 300,
|
||||
data: '127.0.0.1'
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
this.udpServer.bind(this.options.udpPort, '0.0.0.0', () => {
|
||||
console.log(`UDP DNS server running on port ${this.options.udpPort}`);
|
||||
});
|
||||
}
|
||||
|
||||
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 = {
|
||||
type: 'response' as const,
|
||||
id: request.id,
|
||||
flags: plugins.dnsPacket.RECURSION_DESIRED | plugins.dnsPacket.RECURSION_AVAILABLE,
|
||||
questions: request.questions,
|
||||
answers: [] as plugins.dnsPacket.Answer[]
|
||||
};
|
||||
|
||||
const question = request.questions[0];
|
||||
console.log(`DoH query for ${question.name} of type ${question.type}`);
|
||||
|
||||
if (question.type === 'A') {
|
||||
response.answers.push({
|
||||
name: question.name,
|
||||
type: 'A',
|
||||
class: 'IN',
|
||||
ttl: 300,
|
||||
data: '127.0.0.1'
|
||||
});
|
||||
}
|
||||
|
||||
const responseData = plugins.dnsPacket.encode(response);
|
||||
res.writeHead(200, { 'Content-Type': 'application/dns-message' });
|
||||
res.end(responseData);
|
||||
});
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
this.httpsServer.listen(this.options.httpsPort, () => {
|
||||
console.log(`DoH server running on port ${this.options.httpsPort}`);
|
||||
});
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
this.udpServer.close(() => {
|
||||
console.log('UDP DNS server stopped');
|
||||
});
|
||||
|
||||
this.httpsServer.close(() => {
|
||||
console.log('HTTPS DNS server stopped');
|
||||
});
|
||||
}
|
||||
}
|
0
ts_server/index.ts
Normal file
0
ts_server/index.ts
Normal file
17
ts_server/plugins.ts
Normal file
17
ts_server/plugins.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import fs from 'fs';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import dgram from 'dgram';
|
||||
|
||||
export {
|
||||
fs,
|
||||
http,
|
||||
https,
|
||||
dgram,
|
||||
}
|
||||
|
||||
import * as dnsPacket from 'dns-packet';
|
||||
|
||||
export {
|
||||
dnsPacket
|
||||
}
|
@ -3,8 +3,12 @@
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user