Merge pull request #160 from Ars2014/dev-2.x

Fix #135
This commit is contained in:
Alex Root Junior 2019-07-14 01:18:24 +03:00 committed by GitHub
commit 66849ec770
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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