| OLD | NEW |
| 1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
| 2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 cookies = Cookie.SimpleCookie(environ.get('HTTP_COOKIE', '')) | 49 cookies = Cookie.SimpleCookie(environ.get('HTTP_COOKIE', '')) |
| 50 secret = cookies[id].value | 50 secret = cookies[id].value |
| 51 except (Cookie.CookieError, KeyError): | 51 except (Cookie.CookieError, KeyError): |
| 52 return showError('No digest secret', start_response) | 52 return showError('No digest secret', start_response) |
| 53 | 53 |
| 54 if secret != thisweek and secret != prevweek and secret != thisweek_compat a
nd secret != prevweek_compat: | 54 if secret != thisweek and secret != prevweek and secret != thisweek_compat a
nd secret != prevweek_compat: |
| 55 return showError('Wrong secret', start_response) | 55 return showError('Wrong secret', start_response) |
| 56 | 56 |
| 57 path = os.path.join(get_config().get('reports', 'digestPath'), id + '.html') | 57 path = os.path.join(get_config().get('reports', 'digestPath'), id + '.html') |
| 58 if not os.path.exists(path): | 58 if not os.path.exists(path): |
| 59 return showError('Digest doesn\'t exist', start_response) | 59 return showError("Digest doesn't exist", start_response) |
| 60 | 60 |
| 61 cookies = Cookie.SimpleCookie() | 61 cookies = Cookie.SimpleCookie() |
| 62 cookies[id] = secret | 62 cookies[id] = secret |
| 63 cookies[id]['path'] = '/' | 63 cookies[id]['path'] = '/' |
| 64 cookies[id]['secure'] = True | 64 cookies[id]['secure'] = True |
| 65 cookies[id]['httponly'] = True | 65 cookies[id]['httponly'] = True |
| 66 expiration = datetime.utcnow() + timedelta(weeks=2) | 66 expiration = datetime.utcnow() + timedelta(weeks=2) |
| 67 cookies[id]['expires'] = expiration.strftime('%a, %d-%b-%Y %H:%M:%S GMT') | 67 cookies[id]['expires'] = expiration.strftime('%a, %d-%b-%Y %H:%M:%S GMT') |
| 68 if redirect: | 68 if redirect: |
| 69 start_response('302 Found', [('Location', '/digest?id=' + id), ('Set-Coo
kie', cookies[id].OutputString())]) | 69 start_response('302 Found', [('Location', '/digest?id=' + id), ('Set-Coo
kie', cookies[id].OutputString())]) |
| 70 return [] | 70 return [] |
| 71 else: | 71 else: |
| 72 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8'),
('Set-Cookie', cookies[id].OutputString())]) | 72 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8'),
('Set-Cookie', cookies[id].OutputString())]) |
| 73 blockSize = 4096 | 73 blockSize = 4096 |
| 74 f = open(path) | 74 f = open(path) |
| 75 if 'wsgi.file_wrapper' in environ: | 75 if 'wsgi.file_wrapper' in environ: |
| 76 return environ['wsgi.file_wrapper'](f, blockSize) | 76 return environ['wsgi.file_wrapper'](f, blockSize) |
| 77 else: | 77 else: |
| 78 return iter(lambda: f.read(blockSize), '') | 78 return iter(lambda: f.read(blockSize), '') |
| 79 | 79 |
| 80 | 80 |
| 81 def showError(message, start_response): | 81 def showError(message, start_response): |
| 82 template = get_template(get_config().get('reports', 'errorTemplate')) | 82 template = get_template(get_config().get('reports', 'errorTemplate')) |
| 83 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+
xml; charset=utf-8')]) | 83 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+
xml; charset=utf-8')]) |
| 84 return [template.render({'message': message}).encode('utf-8')] | 84 return [template.render({'message': message}).encode('utf-8')] |
| OLD | NEW |