From afe573c97a2a1f8dade8b770d51ee2b7ce74f900 Mon Sep 17 00:00:00 2001 From: HF Date: Mon, 1 Aug 2022 22:06:21 +0200 Subject: [PATCH] log format change for proxycheck, asn validation --- src/core/isProxy.js | 12 ++++++------ src/data/sql/IPInfo.js | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/isProxy.js b/src/core/isProxy.js index 9ab0889..4d61e88 100644 --- a/src/core/isProxy.js +++ b/src/core/isProxy.js @@ -20,7 +20,7 @@ async function getIPIntel(ip) { const email = `${Math.random().toString(36).substring(8)}-${Math.random().toString(36).substring(4)}@gmail.com`; // eslint-disable-next-line max-len const url = `http://check.getipintel.net/check.php?ip=${ip}&contact=${email}&flags=m`; - logger.info(`PROXYCHECK fetching getipintel ${url}`); + logger.info(`fetching getipintel ${url}`); const response = await fetch(url, { headers: { Accept: '*/*', @@ -32,10 +32,10 @@ async function getIPIntel(ip) { }); if (!response.ok) { const text = await response.text(); - throw new Error(`PROXYCHECK getipintel not ok ${response.status}/${text}`); + throw new Error(`getipintel not ok ${response.status}/${text}`); } const body = await response.text(); - logger.info('PROXYCHECK fetch getipintel is proxy? %s : %s', ip, body); + logger.info('PROXYCHECK %s : %s', ip, body); // returns tru iff we found 1 in the response and was ok (http code = 200) const value = parseFloat(body); return [ @@ -52,7 +52,7 @@ async function getIPIntel(ip) { */ async function getProxyCheck(ip) { const url = `http://proxycheck.io/v2/${ip}?risk=1&vpn=1&asn=1`; - logger.info('PROXYCHECK fetching proxycheck %s', url); + logger.info('fetching proxycheck %s', url); const response = await fetch(url, { headers: { // eslint-disable-next-line max-len @@ -64,7 +64,7 @@ async function getProxyCheck(ip) { throw new Error(`proxycheck not ok ${response.status}/${text}`); } const data = await response.json(); - logger.info('PROXYCHECK proxycheck is proxy?', data); + logger.info('PROXYCHECK', data); if (!data.status) { return [ false, @@ -178,7 +178,7 @@ async function withCache(f, ip) { const pos = checking.indexOf(ipKey); if (~pos) checking.splice(pos, 1); } catch (error) { - logger.error('PROXYCHECK withCache %s', error.message || error); + logger.error('Error %s', error.message || error); const pos = checking.indexOf(ipKey); if (~pos) checking.splice(pos, 1); } finally { diff --git a/src/data/sql/IPInfo.js b/src/data/sql/IPInfo.js index f49b654..ef2d113 100644 --- a/src/data/sql/IPInfo.js +++ b/src/data/sql/IPInfo.js @@ -80,6 +80,10 @@ const IPInfo = sequelize.define('IPInfo', { pcheck(value) { this.setDataValue('pcheck', value.slice(0, 60)); }, + + country(value) { + this.setDataValue('country', value.slice(0, 2).toLowerCase()); + }, }, });