]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
750e9833 FV |
2 | """ |
3 | This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check | |
4 | if we are not 'age_limit' tagging some porn site | |
a45ea170 FV |
5 | |
6 | A second approach implemented relies on a list of porn domains, to activate it | |
7 | pass the list filename as the only argument | |
750e9833 FV |
8 | """ |
9 | ||
10 | # Allow direct execution | |
11 | import os | |
12 | import sys | |
f8271158 | 13 | |
750e9833 FV |
14 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
15 | ||
f8271158 | 16 | |
14f25df2 | 17 | import urllib.parse |
ac668111 | 18 | import urllib.request |
19 | ||
20 | from test.helper import gettestcases | |
750e9833 | 21 | |
a45ea170 FV |
22 | if len(sys.argv) > 1: |
23 | METHOD = 'LIST' | |
24 | LIST = open(sys.argv[1]).read().decode('utf8').strip() | |
25 | else: | |
26 | METHOD = 'EURISTIC' | |
27 | ||
8a1a60d1 | 28 | for test in gettestcases(): |
a45ea170 FV |
29 | if METHOD == 'EURISTIC': |
30 | try: | |
ac668111 | 31 | webpage = urllib.request.urlopen(test['url'], timeout=10).read() |
70a1165b | 32 | except Exception: |
86e5f3ed | 33 | print('\nFail: {}'.format(test['name'])) |
a45ea170 FV |
34 | continue |
35 | ||
36 | webpage = webpage.decode('utf8', 'replace') | |
37 | ||
38 | RESULT = 'porn' in webpage.lower() | |
39 | ||
40 | elif METHOD == 'LIST': | |
14f25df2 | 41 | domain = urllib.parse.urlparse(test['url']).netloc |
a45ea170 | 42 | if not domain: |
86e5f3ed | 43 | print('\nFail: {}'.format(test['name'])) |
a45ea170 FV |
44 | continue |
45 | domain = '.'.join(domain.split('.')[-2:]) | |
750e9833 | 46 | |
a45ea170 | 47 | RESULT = ('.' + domain + '\n' in LIST or '\n' + domain + '\n' in LIST) |
750e9833 | 48 | |
3089bc74 S |
49 | if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict'] |
50 | or test['info_dict']['age_limit'] != 18): | |
86e5f3ed | 51 | print('\nPotential missing age_limit check: {}'.format(test['name'])) |
750e9833 | 52 | |
3089bc74 S |
53 | elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict'] |
54 | and test['info_dict']['age_limit'] == 18): | |
86e5f3ed | 55 | print('\nPotential false negative: {}'.format(test['name'])) |
750e9833 FV |
56 | |
57 | else: | |
58 | sys.stdout.write('.') | |
59 | sys.stdout.flush() | |
60 | ||
61 | print() |