47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
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)
|
|
}
|
|
|