60 lines
1.5 KiB
JavaScript
60 lines
1.5 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)
|
|
const query = `insert into tosacceptance (ipaddr, time, version) values ('${ipAddress}', '${time}', '${version}')`;
|
|
console.log('query:', query)
|
|
await sql(query)
|
|
console.log('approved TOS')
|
|
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}`)
|
|
}
|