From df13e247255bc50db808a31730f3efbcafeb97f9 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 06:55:55 +0200 Subject: [PATCH 01/11] Use ipaddress, not ipaddr. --- rabl/rabl.py | 13 ++++++------- requirements.txt | 1 - setup.py | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/rabl/rabl.py b/rabl/rabl.py index 5590eec..4d8d4d2 100644 --- a/rabl/rabl.py +++ b/rabl/rabl.py @@ -24,13 +24,12 @@ import os import logging +import ipaddress try: import configparser except ImportError: import ConfigParser as configparser -import ipaddr - try: import MySQLdb except ImportError: @@ -101,15 +100,15 @@ def _handle(self): is_spam = is_spam.lower() == "true" # We change reported IPv6 addresses to the /64 network. - address = ipaddr.IPAddress(address) - if isinstance(address, ipaddr.IPv6Address): - address = ipaddr.IPNetwork(str(address) + "/64").network - reporter = ipaddr.IPAddress(self.client_address[0]) + address = ipaddress.ip_address(address) + if isinstance(address, ipaddress.IPv6Address): + address = ipaddress.ip_network(str(address) + "/64").network + reporter = ipaddress.ip_address(self.client_address[0]) if reporter == CONF.get("rabl", "trusted_ip"): table_name = CONF.get("rabl", "trusted_table") # This IP is permitted to claim the report is from other IPs. - reporter = ipaddr.IPAddress(claimed_reporter) + reporter = ipaddress.ip_address(claimed_reporter) # If the report has a claimed reporter, then this has been # reported by a human, so may be able to be trusted more. elif claimed_reporter: diff --git a/requirements.txt b/requirements.txt index 8adc901..ae4458d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ dnspython==1.16.0 idna==2.8 -ipaddr==2.2.0 psutil==5.6.3 mysqlclient==1.4.2.post1 sentry-sdk==0.10.2 diff --git a/setup.py b/setup.py index c289aaa..940b956 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ "MySQL-python==1.2.5", "dnspython==1.16.0", "idna==2.8", - "ipaddr==2.2.0", "psutil==5.6.3", "sentry-sdk==0.10.2", "spoon==1.0.6", From e2e630a0f98dbcf24060b2f3de3387184b43c8b7 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 06:57:23 +0200 Subject: [PATCH 02/11] Use configparser, not ConfigParser. --- rabl/rabl.py | 5 +---- rabl/write_to_rbldnsd.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rabl/rabl.py b/rabl/rabl.py index 4d8d4d2..ac2b507 100644 --- a/rabl/rabl.py +++ b/rabl/rabl.py @@ -25,10 +25,7 @@ import os import logging import ipaddress -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser try: import MySQLdb diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index 5645fec..5ab98c3 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -15,10 +15,7 @@ import optparse import datetime import tempfile -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser import psutil From 6b7f0f861fba6d572dc691edb0675e22722b9242 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 06:58:15 +0200 Subject: [PATCH 03/11] Remove unnecessary future imports. --- rabl/rabl.py | 2 -- rabl/write_to_rbldnsd.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/rabl/rabl.py b/rabl/rabl.py index ac2b507..1b076f5 100644 --- a/rabl/rabl.py +++ b/rabl/rabl.py @@ -20,8 +20,6 @@ a small number of reports from many different sources. """ -from __future__ import absolute_import - import os import logging import ipaddress diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index 5ab98c3..40beb3c 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -6,8 +6,6 @@ data collected by the RABL server. """ -from __future__ import absolute_import - import os import shutil import hashlib From 1ac5d86463310d645652ec7ef97c52875ea0e22d Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:02:57 +0200 Subject: [PATCH 04/11] Prepare for new version, including updating classifiers. --- setup.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 720e288..638ebe8 100644 --- a/setup.py +++ b/setup.py @@ -21,11 +21,11 @@ setup( name="se-rabl", - version="1.0.1", + version="1.1.0", description="SpamExperts RABL", long_description=readme, - author="SpamExperts B.V.", - author_email="support@spamexperts.com", + author="SolarWinds", + author_email="mail-plg-engineering@solarwinds.com", url="https://github.com/spamexperts/se-rabl", packages=["rabl"], scripts=["rabl/write_to_rbldnsd.py"], @@ -35,15 +35,11 @@ zip_safe=False, keywords="rabl,spam,spamexperts", classifiers=[ - "Development Status :: 2 - Pre-Alpha", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.7", ], test_suite="tests", tests_require=test_requirements, From 6dbe171feeecdad3d890c208189728f6ced1f965 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:04:55 +0200 Subject: [PATCH 05/11] Prepare for new version. --- HISTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 11a2425..799412e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,10 @@ # History +## 1.1.0 (2019-xx-xx) + +* Drop support for Python 2. +* Add support for Python 3.7. + ## 1.0.1 (2019-xx-xx) * Add manifest file. From 23549684d56e39b9732ab897919e459eb1823a1d Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:07:27 +0200 Subject: [PATCH 06/11] Install Python 3, including pip. --- salt/states/rabl.sls | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/salt/states/rabl.sls b/salt/states/rabl.sls index 6a2e875..5d44561 100644 --- a/salt/states/rabl.sls +++ b/salt/states/rabl.sls @@ -15,31 +15,11 @@ basic-install: - binutils - libc6 - gcc - - python-dev + - python3-dev + - python3-pip + - python3-whl - wget -broken_python_modules: - pkg.purged: - - pkgs: - - python-pip - - python-pip-whl - -download get-pip: - cmd.run: - - name: wget -nv -N https://bootstrap.pypa.io/get-pip.py - - cwd: /var/cache/ - - creates: /var/cache/get-pip.py - -#install pip: -# cmd.run: -# - name: /usr/bin/python /var/cache/get-pip.py -# - unless: 'test -f /usr/bin/pip && fgrep -q /usr/bin/python /usr/bin/pip && /usr/bin/python -m pip' -# - require: -# - cmd: download get-pip -# pip.installed: -# - name: setuptools -# - upgrade: True - mariadb-server: pkg: - latest From 0babe971f7b9c7f72f38ba2fd9e1070ac624d3c0 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:08:25 +0200 Subject: [PATCH 07/11] Explicitly require Python 3. --- tests/unit/test_rabl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_rabl.py b/tests/unit/test_rabl.py index d7493b0..923ce5c 100644 --- a/tests/unit/test_rabl.py +++ b/tests/unit/test_rabl.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """RABL unit tests.""" From 5fd07c4e566cf530fd535ddc1639e673b0ada933 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:09:05 +0200 Subject: [PATCH 08/11] Explicitly require Python 3. --- rabl/write_to_rbldnsd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index 2083978..c90f722 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Reactive Autonomous Blackhole List Server From 005eebfc7775fbbd40205b8acf5bf8b5fd4d304f Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:22:06 +0200 Subject: [PATCH 09/11] Remove black space. --- rabl/write_to_rbldnsd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index ccb1b26..8817372 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -44,7 +44,7 @@ def load_configuration(): def get_temporary_location(filename): """Return an appropriate temporary location to store the file. - + We use a temp folder within the final destination so that the copy should be atomic and so that we're using the same disk (e.g. taking advantage of the same speed, etc). From bbf1f99700e134409dad35fb6ba900e418c04644 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:24:28 +0200 Subject: [PATCH 10/11] The hash file is a text file, don't open in binary mode. --- rabl/write_to_rbldnsd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index 8817372..b07dd6a 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -120,7 +120,7 @@ def write_zone(filename, table_name, life, minspread): def generate_checksum(filename): """Generate a SHA256 hash checksum for the file.""" - with open(filename + ".sha256", "wb") as sha_sig: + with open(filename + ".sha256", "w") as sha_sig: with open(filename, "rb") as file_content: sha256_hash = hashlib.sha256() while True: From 0ec98ab677205aa9d8ed4ea721b206694cf4fc75 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Sat, 3 Aug 2019 07:28:32 +0200 Subject: [PATCH 11/11] Convert the data from the socket to a string. --- rabl/rabl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rabl/rabl.py b/rabl/rabl.py index 64ef782..9a5be6e 100644 --- a/rabl/rabl.py +++ b/rabl/rabl.py @@ -81,7 +81,7 @@ def _handle(self): """Handle a single incoming connection.""" logger = logging.getLogger("rabl") logger.debug("Handling report from %s", self.client_address[0]) - packet = self.rfile.read(320000).strip() + packet = self.rfile.read(320000).decode("utf8").strip() # claimed_reporter is an IP address when from the trusted IP, or "" # otherwise.