57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
import {countryForIP} from "./maxmind.js";
|
|
import {clientIP} from "./misc.js";
|
|
import {sql} from "./db.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 async function approveTOS(socket, time, version, callback) {
|
|
const ipAddress = clientIP(socket)
|
|
await sql('insert into tosacceptance (ipaddr, time, version) values ($1,$2,$3)', ipAddress, time, version)
|
|
callback(true)
|
|
}
|
|
|
|
|
|
export function approveWallet(walletAddress) {
|
|
// todo OFAC lookup
|
|
return true
|
|
}
|
|
|
|
|
|
function approveIP(ipAddress) {
|
|
let country
|
|
try {
|
|
country = countryForIP(ipAddress)
|
|
}
|
|
catch (e) {
|
|
console.warn(`IP lookup failed for ${ipAddress}: ${e.message}`)
|
|
return false
|
|
}
|
|
if (!country) return false
|
|
const approved = !bannedCountries.includes(country)
|
|
console.debug(`IP ${ipAddress} from ${country} is ${approved ? 'approved' : 'rejected'}`)
|
|
return approved
|
|
}
|
|
|
|
|
|
export function approveRegion(socket, bypass) {
|
|
const ipAddress = clientIP(socket)
|
|
const debug = bypass === process.env.DEXORDER_REGION_APPROVAL;
|
|
const approved = debug || approveIP(ipAddress)
|
|
socket.emit('approvedRegion', approved)
|
|
if(debug)
|
|
console.info(`approved admin at ${ipAddress}`)
|
|
}
|