Add warn in validate_ip

Refer to issue #135
This commit is contained in:
Arslan 'Ars2014' Sakhapov 2019-07-14 02:43:15 +05:00
parent ca68d3d177
commit 6cd63cb7bc

View file

@ -5,6 +5,7 @@ import functools
import ipaddress
import itertools
import typing
import logging
from typing import Dict, List, Optional, Union
from aiohttp import web
@ -35,6 +36,8 @@ TELEGRAM_SUBNET_2 = ipaddress.IPv4Network('91.108.4.0/22')
allowed_ips = set()
log = logging.getLogger(__name__)
def _check_ip(ip: str) -> bool:
"""
@ -258,7 +261,9 @@ class WebhookRequestHandler(web.View):
if self.request.app.get('_check_ip', False):
ip_address, accept = self.check_ip()
if not accept:
log.warning(f"Blocking request from a unauthorized IP: {ip_address}")
raise web.HTTPUnauthorized()
# context.set_value('TELEGRAM_IP', ip_address)