MaxMind IP database & region approvals
This commit is contained in:
46
approval.js
Normal file
46
approval.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import {countryForIP} from "./maxmind.js";
|
||||
|
||||
|
||||
const bannedCountries = [
|
||||
'US', // FFS
|
||||
'PR', // FFS (different country?!)
|
||||
|
||||
// OFAC country bans
|
||||
'CU', // Cuba
|
||||
'IR', // Iran
|
||||
'KP', // North Korea
|
||||
'SY', // Syria
|
||||
'RU', // Russia
|
||||
'BY', // Belarus
|
||||
]
|
||||
|
||||
|
||||
export function approveWallet(walletAddress) {
|
||||
// todo OFAC lookup
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
function approveIP(ipAddress) {
|
||||
try {
|
||||
const country = countryForIP(ipAddress)
|
||||
if (!country) return false
|
||||
const approved = !bannedCountries.includes(country)
|
||||
if (!approved)
|
||||
// todo log ban & report
|
||||
console.warn(`IP ${ipAddress} from ${country} is banned`)
|
||||
return approved
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`IP lookup failed for ${ipAddress}: ${e.message}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function approveRegion(socket, bypass) {
|
||||
const ipAddress = socket.handshake.address
|
||||
const approved = bypass === '6ehWWH98diqv39gWZcPo' || approveIP(ipAddress)
|
||||
socket.emit('approvedRegion', approved)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user