Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
23 changes: 8 additions & 15 deletions rabl/rabl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@
a small number of reports from many different sources.
"""

from __future__ import absolute_import

import os
import logging

try:
import configparser
except ImportError:
import ConfigParser as configparser

import ipaddr
import ipaddress
import configparser

try:
import MySQLdb
Expand Down Expand Up @@ -88,23 +81,23 @@ 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.
address, is_spam, claimed_reporter = packet.strip().split(",")
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:
Expand Down
14 changes: 4 additions & 10 deletions rabl/write_to_rbldnsd.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
#! /usr/bin/env python
#! /usr/bin/env python3

"""Reactive Autonomous Blackhole List Server

General a zone file suitable for use with rbldnsd from the
data collected by the RABL server.
"""

from __future__ import absolute_import

import os
import shutil
import hashlib
import logging
import datetime
import tempfile

try:
import configparser
except ImportError:
import ConfigParser as configparser
import configparser

import MySQLdb

Expand Down Expand Up @@ -50,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).
Expand Down Expand Up @@ -126,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:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dnspython==1.16.0
idna==2.8
ipaddr==2.2.0
mysqlclient==1.4.2.post1
sentry-sdk==0.10.2
spoon==1.0.6
Expand Down
26 changes: 3 additions & 23 deletions salt/states/rabl.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,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"],
Expand All @@ -36,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,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_rabl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

"""RABL unit tests."""

Expand Down