db records TOS acceptance

This commit is contained in:
tim
2025-01-30 12:25:14 -04:00
parent 2f5a626e5c
commit 5af7422b9d
4 changed files with 28 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
import {countryForIP} from "./maxmind.js";
import {clientIP} from "./misc.js";
import {sql} from "./db.js";
const bannedCountries = [
@@ -15,6 +17,16 @@ const bannedCountries = [
]
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
@@ -22,25 +34,23 @@ export function approveWallet(walletAddress) {
function approveIP(ipAddress) {
let country
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`)
console.debug(`IP ${ipAddress} from ${country} is ${approved ? 'approved' : 'rejected'}`)
return approved
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 = socket.handshake.address
const ipAddress = clientIP(socket)
const debug = bypass === process.env.DEXORDER_REGION_APPROVAL;
const approved = debug || approveIP(ipAddress)
socket.emit('approvedRegion', approved)