From baf9ec5387bdf9bec953d84b54982cc3a8877c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 21 Jul 2020 23:18:58 +0300 Subject: [PATCH] =?UTF-8?q?Blacklist=20=E2=86=92=20block(list)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- neomi.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/neomi.py b/neomi.py index 00c69ca..c79eb51 100644 --- a/neomi.py +++ b/neomi.py @@ -15,7 +15,7 @@ import urllib.parse class default_config: None -default_config.blacklist_file = pathlib.Path(os.environ['HOME']) / 'gopher_blacklist' +default_config.blocklist_file = pathlib.Path(os.environ['HOME']) / 'gopher_blocklist' default_config.charset = 'utf-8' default_config.fallback_mimetype = 'application/octet-stream' default_config.gopher_root = pathlib.Path(os.environ['HOME']) / 'gopher' @@ -799,18 +799,18 @@ class Threads_controller: class IPParseError(OneArgumentException): text = 'Error parsing IP: %s' -# read_blacklist(blacklist_file) → blacklist -# Reads the contents of the blacklist file into a form usable by ip_in_ranges() -def read_blacklist(blacklist_file): +# read_blocklist(blocklist_file) → blocklist +# Reads the contents of the blocklist file into a form usable by ip_in_ranges() +def read_blocklist(blocklist_file): try: - file = open(str(blacklist_file), 'r') + file = open(str(blocklist_file), 'r') except FileNotFoundError: return [] lines = file.read().split('\n') file.close() - blacklist = [] + blocklist = [] for line in lines: # Comment handling if '#' in line: @@ -828,9 +828,9 @@ def read_blacklist(blacklist_file): except ValueError as err: raise IPParseError('Invalid format: ' + line) from err - blacklist.append(ip_range) + blocklist.append(ip_range) - return blacklist + return blocklist # ip_in_ranges(ip, ip_ranges) → in_rages # Checks whether an ip address is in given ranges @@ -870,8 +870,8 @@ def listen(config): # Create a controller object for the worker threads threads_controller = Threads_controller() - # Read blacklist of addresses - blacklist = read_blacklist(config.blacklist_file) + # Read blocklist of addresses + blocklist = read_blocklist(config.blocklist_file) while True: # Wait for listening sockets to get activity @@ -883,11 +883,11 @@ def listen(config): # Accept and handle the connection conn, addr = s.accept() - # Check if connection is from a blacklisted IP address - if ip_in_ranges(addr[0], blacklist): + # Check if connection is from a blocked IP address + if ip_in_ranges(addr[0], blocklist): # It was, skip event conn.close() - log('Connection from blacklisted address %s' % addr[0]) + log('Connection from blocked address %s' % addr[0]) continue # Set timeout for socket