-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to standard
- Loading branch information
Showing
7 changed files
with
5,132 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [12.x, 14.x, 16.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,68 @@ | ||
'use strict'; | ||
|
||
const Assert = require('assert'); | ||
const Dns = require('dns'); | ||
const Http = require('http'); | ||
const Https = require('https'); | ||
const IPRangeCheck = require('ip-range-check'); | ||
'use strict' | ||
|
||
const Assert = require('assert') | ||
const Dns = require('dns') | ||
const Http = require('http') | ||
const Https = require('https') | ||
const IPRangeCheck = require('ip-range-check') | ||
|
||
const lookup = function (settings) { | ||
Assert(settings.type === 'whitelist' || settings.type === 'blacklist', 'type must be whitelist or blacklist') | ||
|
||
Assert(settings.type === 'whitelist' || settings.type === 'blacklist', 'type must be whitelist or blacklist'); | ||
|
||
const filter = function (hostname, options, callback) { | ||
|
||
if (arguments.length === 2) { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
Dns.lookup(hostname, options, (err, address, family) => { | ||
const filter = function (hostname, options, callback) { | ||
if (arguments.length === 2) { | ||
callback = options | ||
options = {} | ||
} | ||
|
||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
Dns.lookup(hostname, options, (err, address, family) => { | ||
if (err) { | ||
callback(err) | ||
return | ||
} | ||
|
||
const ip_test = IPRangeCheck(address, settings.iplist); | ||
const ipTest = IPRangeCheck(address, settings.iplist) | ||
|
||
if (ip_test && settings.type === 'whitelist') { //IP on whitelist, pass | ||
callback(err, address, family); | ||
return; | ||
} | ||
if (ipTest && settings.type === 'whitelist') { // IP on whitelist, pass | ||
callback(err, address, family) | ||
return | ||
} | ||
|
||
if (!ip_test && settings.type === 'blacklist') { //IP not on blacklist, pass | ||
callback(err, address, family); | ||
return; | ||
} | ||
//Fail | ||
if (!ipTest && settings.type === 'blacklist') { // IP not on blacklist, pass | ||
callback(err, address, family) | ||
return | ||
} | ||
// Fail | ||
|
||
callback(new Error(`Connection to IP ${address} not allowed`)); | ||
return; | ||
}); | ||
}; | ||
callback(new Error(`Connection to IP ${address} not allowed`)) | ||
}) | ||
} | ||
|
||
return filter; | ||
}; | ||
return filter | ||
} | ||
|
||
exports.http = function (settings) { | ||
const httpAgent = new Http.Agent(settings.agent) | ||
|
||
const httpAgent = new Http.Agent(settings.agent); | ||
httpAgent._oldCreateConnection_ = httpAgent.createConnection | ||
httpAgent.createConnection = function (options, ...args) { | ||
options.lookup = lookup(settings) | ||
|
||
httpAgent._oldCreateConnection_ = httpAgent.createConnection; | ||
httpAgent.createConnection = function (options, ...args) { | ||
return this._oldCreateConnection_(options, ...args) | ||
} | ||
|
||
options.lookup = lookup(settings); | ||
|
||
return this._oldCreateConnection_(options, ...args); | ||
}; | ||
|
||
return httpAgent; | ||
}; | ||
return httpAgent | ||
} | ||
|
||
exports.https = function (settings) { | ||
const httpsAgent = new Https.Agent(settings.agent) | ||
|
||
const httpsAgent = new Https.Agent(settings.agent); | ||
|
||
httpsAgent._oldCreateConnection_ = httpsAgent.createConnection; | ||
httpsAgent.createConnection = function (options, ...args) { | ||
|
||
options.lookup = lookup(settings); | ||
httpsAgent._oldCreateConnection_ = httpsAgent.createConnection | ||
httpsAgent.createConnection = function (options, ...args) { | ||
options.lookup = lookup(settings) | ||
|
||
return this._oldCreateConnection_(options, ...args); | ||
}; | ||
return this._oldCreateConnection_(options, ...args) | ||
} | ||
|
||
return httpsAgent; | ||
}; | ||
return httpsAgent | ||
} |
Oops, something went wrong.