2021-06-03 09:43:42 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-10-28 05:50:17 +00:00
|
|
|
"""
|
|
|
|
This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
|
|
|
|
if we are not 'age_limit' tagging some porn site
|
2014-01-14 21:01:00 +00:00
|
|
|
|
|
|
|
A second approach implemented relies on a list of porn domains, to activate it
|
|
|
|
pass the list filename as the only argument
|
2013-10-28 05:50:17 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Allow direct execution
|
|
|
|
import os
|
|
|
|
import sys
|
2022-04-11 22:32:57 +00:00
|
|
|
|
2013-10-28 05:50:17 +00:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2022-04-11 22:32:57 +00:00
|
|
|
|
2022-06-24 10:54:43 +00:00
|
|
|
import urllib.parse
|
2022-06-24 08:10:17 +00:00
|
|
|
import urllib.request
|
|
|
|
|
|
|
|
from test.helper import gettestcases
|
2013-10-28 05:50:17 +00:00
|
|
|
|
2014-01-14 21:01:00 +00:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
METHOD = 'LIST'
|
|
|
|
LIST = open(sys.argv[1]).read().decode('utf8').strip()
|
|
|
|
else:
|
|
|
|
METHOD = 'EURISTIC'
|
|
|
|
|
2017-09-19 15:51:20 +00:00
|
|
|
for test in gettestcases():
|
2014-01-14 21:01:00 +00:00
|
|
|
if METHOD == 'EURISTIC':
|
|
|
|
try:
|
2022-06-24 08:10:17 +00:00
|
|
|
webpage = urllib.request.urlopen(test['url'], timeout=10).read()
|
2015-03-27 12:02:20 +00:00
|
|
|
except Exception:
|
2022-04-11 15:10:28 +00:00
|
|
|
print('\nFail: {}'.format(test['name']))
|
2014-01-14 21:01:00 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
webpage = webpage.decode('utf8', 'replace')
|
|
|
|
|
|
|
|
RESULT = 'porn' in webpage.lower()
|
|
|
|
|
|
|
|
elif METHOD == 'LIST':
|
2022-06-24 10:54:43 +00:00
|
|
|
domain = urllib.parse.urlparse(test['url']).netloc
|
2014-01-14 21:01:00 +00:00
|
|
|
if not domain:
|
2022-04-11 15:10:28 +00:00
|
|
|
print('\nFail: {}'.format(test['name']))
|
2014-01-14 21:01:00 +00:00
|
|
|
continue
|
|
|
|
domain = '.'.join(domain.split('.')[-2:])
|
2013-10-28 05:50:17 +00:00
|
|
|
|
2014-01-14 21:01:00 +00:00
|
|
|
RESULT = ('.' + domain + '\n' in LIST or '\n' + domain + '\n' in LIST)
|
2013-10-28 05:50:17 +00:00
|
|
|
|
2019-05-10 20:56:22 +00:00
|
|
|
if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict']
|
|
|
|
or test['info_dict']['age_limit'] != 18):
|
2022-04-11 15:10:28 +00:00
|
|
|
print('\nPotential missing age_limit check: {}'.format(test['name']))
|
2013-10-28 05:50:17 +00:00
|
|
|
|
2019-05-10 20:56:22 +00:00
|
|
|
elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict']
|
|
|
|
and test['info_dict']['age_limit'] == 18):
|
2022-04-11 15:10:28 +00:00
|
|
|
print('\nPotential false negative: {}'.format(test['name']))
|
2013-10-28 05:50:17 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
print()
|