aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/signup.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-27 14:32:44 +0200
committerChocobozzz <me@florianbigard.com>2021-08-27 15:12:22 +0200
commit41fb13c330de629df2d23379209e79c7af0f2e9a (patch)
tree73bc5a90566406b3910f142beae2a879c1e4265d /server/lib/signup.ts
parent40e7ed0714f96c01e16de3ac971a4b28116294e1 (diff)
downloadPeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.gz
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.zst
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.zip
esModuleInterop to true
Diffstat (limited to 'server/lib/signup.ts')
-rw-r--r--server/lib/signup.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/lib/signup.ts b/server/lib/signup.ts
index 8fa81e601..3c1397a12 100644
--- a/server/lib/signup.ts
+++ b/server/lib/signup.ts
@@ -1,6 +1,6 @@
1import { UserModel } from '../models/user/user' 1import { IPv4, IPv6, parse, subnetMatch } from 'ipaddr.js'
2import * as ipaddr from 'ipaddr.js'
3import { CONFIG } from '../initializers/config' 2import { CONFIG } from '../initializers/config'
3import { UserModel } from '../models/user/user'
4 4
5const isCidr = require('is-cidr') 5const isCidr = require('is-cidr')
6 6
@@ -22,7 +22,7 @@ async function isSignupAllowed (): Promise<{ allowed: boolean, errorMessage?: st
22function isSignupAllowedForCurrentIP (ip: string) { 22function isSignupAllowedForCurrentIP (ip: string) {
23 if (!ip) return false 23 if (!ip) return false
24 24
25 const addr = ipaddr.parse(ip) 25 const addr = parse(ip)
26 const excludeList = [ 'blacklist' ] 26 const excludeList = [ 'blacklist' ]
27 let matched = '' 27 let matched = ''
28 28
@@ -32,23 +32,23 @@ function isSignupAllowedForCurrentIP (ip: string) {
32 } 32 }
33 33
34 if (addr.kind() === 'ipv4') { 34 if (addr.kind() === 'ipv4') {
35 const addrV4 = ipaddr.IPv4.parse(ip) 35 const addrV4 = IPv4.parse(ip)
36 const rangeList = { 36 const rangeList = {
37 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr)) 37 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr))
38 .map(cidr => ipaddr.IPv4.parseCIDR(cidr)), 38 .map(cidr => IPv4.parseCIDR(cidr)),
39 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr)) 39 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr))
40 .map(cidr => ipaddr.IPv4.parseCIDR(cidr)) 40 .map(cidr => IPv4.parseCIDR(cidr))
41 } 41 }
42 matched = ipaddr.subnetMatch(addrV4, rangeList, 'unknown') 42 matched = subnetMatch(addrV4, rangeList, 'unknown')
43 } else if (addr.kind() === 'ipv6') { 43 } else if (addr.kind() === 'ipv6') {
44 const addrV6 = ipaddr.IPv6.parse(ip) 44 const addrV6 = IPv6.parse(ip)
45 const rangeList = { 45 const rangeList = {
46 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr)) 46 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr))
47 .map(cidr => ipaddr.IPv6.parseCIDR(cidr)), 47 .map(cidr => IPv6.parseCIDR(cidr)),
48 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr)) 48 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr))
49 .map(cidr => ipaddr.IPv6.parseCIDR(cidr)) 49 .map(cidr => IPv6.parseCIDR(cidr))
50 } 50 }
51 matched = ipaddr.subnetMatch(addrV6, rangeList, 'unknown') 51 matched = subnetMatch(addrV6, rangeList, 'unknown')
52 } 52 }
53 53
54 return !excludeList.includes(matched) 54 return !excludeList.includes(matched)