Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 1 addition & 61 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
'use strict';

const checker = module.exports;

checker.checkIP(ip, ips = [], iprs = []) {
// check if single ips includes ip
if ( ips.includes(ip) ) return true
if (iprs.some(ipr => {
const _range = ipr.split('-')
const _rangeLowerBound = _range[0].split('.').map(e => Number(e))
const _rangeUpperBound = _range[1].split('.').map(e => Number(e))

const _originIp4Arr = ip.split('.').map(e => Number(e))

return false
}))
}


function(origin_ip, allowed_ips = []) {
if (allowed_ips.length > 0) {
const ips = allowed_ips.filter(e => !e.includes('-'))
const iprs = allowed_ips.filter(e => e.includes('-'))
// check if any single ip matches the incoming req ip
if ( ips.includes(origin_ip)) {
return {success: true, ips: allowed_ips}
} else {
const _rangeResults = []
for (let i = 0; i < iprs.length; i++) {

const _range = iprs[i].split('-')
const _noip = origin_ip.split('.').map(e => Number(e))

const _rangeLowerBound = _range[0].split('.').map(e => Number(e))
const _rangeUpperBound = _range[1].split('.').map(e => Number(e))

for (let k0 = 0; k0 < _rangeLowerBound.length; k0++) {
if (_noip[k0] < _rangeLowerBound[k0]) {
_rangeResults.push(false)
}
}

for (let k1 = 0; k1 < _rangeUpperBound.length; k1++) {
if (_noip[k1] > _rangeUpperBound[k1]) {
_rangeResults.push(false)
}
}

_rangeResults.push(true)

}
if (_rangeResults.some(e => e === true)) {
return {success: true, ips: allowed_ips}
} else {
return {success: false, ips: allowed_ips, message: 'You have no access with your current IP'}
}
}
} else {
return {success: true, ips: []}
}
}
'use strict';
141 changes: 0 additions & 141 deletions ip.js

This file was deleted.

12 changes: 0 additions & 12 deletions ip.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
const IP = require('./ip'),
IP4 = IP.IP4,
IP6 = IP.IP6;

test('', () => {
console.log(IP);
const ip4 = new IP4(1, 1, 1, 1)
console.log(ip4);
const ip6 = new IP6('2001','0db8','85a3','08d3','1319','8a2e','0370','7344')
console.log(ip6);
//expect(getOrElse()).toBe(undefined);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Lucas Recknagel <lucas91@me.com>",
"license": "THE UNLICENSE",
"devDependencies": {
"jest": "^20.0.4"
"jest": "^23.6.0"
},
"scripts": {
"test": "jest"
Expand Down
15 changes: 0 additions & 15 deletions t.js

This file was deleted.

Loading