2018-02-05 10:22:36 +08:00
#!/usr/bin/env python
""" Verify the integrity of the domain blacklist
"""
2018-02-05 11:09:52 +08:00
import io
2018-02-05 10:22:36 +08:00
import sys
from publicsuffixlist import PublicSuffixList
2018-02-05 12:55:37 +08:00
from requests import get
2018-02-05 10:22:36 +08:00
def main ( arguments ) :
2018-02-05 11:09:52 +08:00
suffix_detected = False
2018-02-05 12:55:37 +08:00
psl = None
download_suffixes ( )
with open ( " public_suffix_list.dat " , " r " ) as latest :
psl = PublicSuffixList ( latest )
2018-02-05 11:09:52 +08:00
with io . open ( ' disposable_email_blacklist.conf ' , ' r ' ) as deb :
for i , line in enumerate ( deb ) :
current_line = line . strip ( )
public_suffix = psl . publicsuffix ( current_line )
if public_suffix == current_line :
print ( f ' The line number { i + 1 } contains just a public suffix: { current_line } ' )
suffix_detected = True
if suffix_detected :
print ( ' At least one valid public suffix found in the blacklist, please remove it. See https://publicsuffix.org for details on why this shouldn \' t be blacklisted. ' )
sys . exit ( 1 )
2018-02-05 10:22:36 +08:00
2018-02-05 12:55:37 +08:00
def download_suffixes ( ) :
with open ( ' public_suffix_list.dat ' , " wb " ) as file :
response = get ( ' https://publicsuffix.org/list/public_suffix_list.dat ' )
file . write ( response . content )
2018-02-05 10:22:36 +08:00
if __name__ == " __main__ " :
main ( sys . argv )