better logging

This commit is contained in:
HF 2020-01-04 14:08:56 +01:00
parent b484ff17b6
commit 1e76ced03a
4 changed files with 14 additions and 14 deletions

View File

@ -19,7 +19,7 @@ import logger from './logger';
async function getIPIntel(ip: string): Promise<boolean> {
const email = `${Math.random().toString(36).substring(8)}-${Math.random().toString(36).substring(4)}@gmail.com`;
const url = `http://check.getipintel.net/check.php?ip=${ip}&contact=${email}&flags=m`;
logger.info('fetching getipintel', url);
logger.info(`PROXYCHECK fetching getipintel ${url}`);
const response = await fetch(url, {
headers: {
Accept: '*/*',
@ -29,13 +29,13 @@ async function getIPIntel(ip: string): Promise<boolean> {
},
});
// TODO log response code
logger.debug('getipintel?', ip);
logger.debug('PROXYCHECK getipintel? %s', ip);
if (!response.ok) {
const text = await response.text();
throw new Error(`getipintel not ok ${response.status}/${text}`);
throw new Error(`PROXYCHECK getipintel not ok ${response.status}/${text}`);
}
const body = await response.text();
logger.info('fetch getipintel is proxy?', ip, body);
logger.info('PROXYCHECK fetch getipintel is proxy? %s : %s', ip, body);
// returns tru iff we found 1 in the response and was ok (http code = 200)
const value = parseFloat(body);
return value > 0.995;
@ -49,7 +49,7 @@ async function getIPIntel(ip: string): Promise<boolean> {
*/
async function getProxyCheck(ip: string): Promise<boolean> {
const url = `http://proxycheck.io/v2/${ip}?risk=1&vpn=1&asn=1`;
logger.info('fetching proxycheck', url);
logger.info('PROXYCHECK fetching proxycheck %s', url);
const response = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
@ -60,7 +60,7 @@ async function getProxyCheck(ip: string): Promise<boolean> {
throw new Error(`proxycheck not ok ${response.status}/${text}`);
}
const data = await response.json();
logger.info('proxycheck is proxy?', ip, data);
logger.info('PROXYCHECK proxycheck is proxy?', data);
return data.status == 'ok' && data[ip].proxy === 'yes';
}
@ -72,7 +72,7 @@ async function getProxyCheck(ip: string): Promise<boolean> {
* @return true if proxy, false if not
*/
async function getShroomey(ip: string): Promise<boolean> {
logger.info('fetching shroomey', ip);
logger.info('PROXYCHECK fetching shroomey %s', ip);
const response = await fetch(`http://www.shroomery.org/ythan/proxycheck.php?ip=${ip}`, {
headers: {
Accept: '*/*',
@ -83,7 +83,7 @@ async function getShroomey(ip: string): Promise<boolean> {
});
if (!response.ok) throw new Error('shroomery.org not ok');
const body = await response.text();
logger.info('fetch shroomey is proxy?', ip, body);
logger.info('PROXYCHECK fetch shroomey is proxy? %s %s', ip, body);
return body === 'Y';
}
@ -168,10 +168,10 @@ async function withCache(f, ip) {
const cache = await redis.getAsync(key);
if (cache) {
const str = cache.toString('utf8');
logger.debug('fetch isproxy from cache', key, cache, typeof cache, str, typeof str);
logger.debug('PROXYCHECK fetch isproxy from cache %s %s %s %s %s', key, cache, typeof cache, str, typeof str);
return str === 'y';
}
logger.debug('fetch isproxy not from cache', key);
logger.debug('PROXYCHECK fetch isproxy not from cache %s', key);
// else make asynchronous ipcheck and assume no proxy in the meantime
// use lock to just check three at a time
@ -188,7 +188,7 @@ async function withCache(f, ip) {
lock += 1;
})
.catch((error) => {
logger.error('withCache', error.message || error);
logger.error('PROXYCHECK withCache %s', error.message || error);
const pos = checking.indexOf(ip);
if (~pos) checking.splice(pos, 1);
lock += 1;

View File

@ -7,10 +7,10 @@
import { createLogger, format, transports } from 'winston';
const logger = createLogger({
level: 'info',
format: format.combine(
format.splat(),
format.simple(),
),
transports: [

View File

@ -35,7 +35,7 @@ async function verifyClient(info, done) {
// Limiting socket connections per ip
const ip = await getIPFromRequest(req);
logger.info('Got ws request from', ip);
logger.info(`Got ws request from ${ip}`);
if (ipCounter.get(ip) > 50) {
logger.info(`Client ${ip} has more than 50 connections open.`);
return done(false);

View File

@ -13,7 +13,7 @@ import logger from '../core/logger';
function randomProxyURL() {
const rand = proxylist[Math.floor(Math.random() * proxylist.length)];
logger.info('choosesn fetch proxy', rand);
logger.info(`choosesn fetch proxy ${rand}`);
return rand;
}