| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-present eyeo GmbH | 2 # Copyright (C) 2006-present 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 |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 15 | 15 |
| 16 import re | 16 import re |
| 17 import random | 17 import random |
| 18 from sitescripts.utils import get_config, get_template, encode_email_address | 18 from sitescripts.utils import get_config, get_template |
| 19 from sitescripts.web import url_handler, form_handler, send_simple_response | 19 from sitescripts.web import url_handler, form_handler |
| 20 from sitescripts.reports.utils import (calculateReportSecret, | 20 from sitescripts.reports.utils import (calculateReportSecret, |
| 21 calculateReportSecret_compat, getReport, | 21 calculateReportSecret_compat, getReport, |
| 22 saveReport, sendUpdateNotification, | 22 saveReport, sendUpdateNotification, |
| 23 getUserId, updateUserUsefulness) | 23 getUserId, updateUserUsefulness) |
| 24 | 24 |
| 25 GUID_REGEX = r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$' | |
| 26 | |
| 25 | 27 |
| 26 @url_handler('/updateReport') | 28 @url_handler('/updateReport') |
| 27 @form_handler | 29 @form_handler |
| 28 def handleRequest(environ, start_response, data): | 30 def handleRequest(environ, start_response, params): |
| 29 params = {name: data.get(name, '').strip() for name in ['name', 'email', | |
|
Vasily Kuznetsov
2019/02/07 20:19:16
These checks were not there before, right? If this
rhowell
2019/02/08 01:34:51
Actually, it seems that most of these params are n
| |
| 30 'subject', 'message', 'guid', 'secret', 'status', 'usefulness', | |
|
Vasily Kuznetsov
2019/02/07 20:19:16
What do you think about putting this list of field
rhowell
2019/02/08 01:34:52
Turns out, we don't need this list for anything!
Vasily Kuznetsov
2019/02/08 19:06:07
Acknowledged.
| |
| 31 'notify']} | |
| 32 missing = [k for k, v in params.iteritems() if not v] | |
| 33 if missing: | |
| 34 text = 'Missing fields: ' + ', '.join(missing) | |
| 35 return send_simple_response(start_response, 400, text) | |
| 36 | |
| 37 try: | |
| 38 params['email'] = encode_email_address(params['email']) | |
| 39 except ValueError: | |
| 40 return send_simple_response(start_response, 400, | |
| 41 'Invalid email address') | |
| 42 | |
| 43 guid = params.get('guid', '').lower() | 31 guid = params.get('guid', '').lower() |
| 44 guid_regex = r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$' | 32 if not re.match(GUID_REGEX, guid): |
|
Vasily Kuznetsov
2019/02/07 20:19:16
This could also be a constant at the top of the mo
rhowell
2019/02/08 01:34:52
Done.
| |
| 45 if not re.match(guid_regex, guid): | |
| 46 return showError('Invalid or missing report GUID', start_response) | 33 return showError('Invalid or missing report GUID', start_response) |
| 47 | 34 |
| 48 reportData = getReport(guid) | 35 reportData = getReport(guid) |
| 49 | 36 |
| 50 if reportData is None: | 37 if reportData is None: |
| 51 return showError('Report does not exist', start_response) | 38 return showError('Report does not exist', start_response) |
| 52 | 39 |
| 53 secret = calculateReportSecret(guid) | 40 secret = calculateReportSecret(guid) |
| 54 if (params.get('secret', '') != secret and | 41 if (params.get('secret', '') != secret and |
| 55 params.get('secret', '') != calculateReportSecret_compat(guid)): | 42 params.get('secret', '') != calculateReportSecret_compat(guid)): |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 84 newURL += '#secret=' + secret | 71 newURL += '#secret=' + secret |
| 85 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 72 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) |
| 86 return [] | 73 return [] |
| 87 | 74 |
| 88 | 75 |
| 89 def showError(message, start_response): | 76 def showError(message, start_response): |
| 90 template = get_template(get_config().get('reports', 'errorTemplate')) | 77 template = get_template(get_config().get('reports', 'errorTemplate')) |
| 91 start_response('400 Processing Error', | 78 start_response('400 Processing Error', |
| 92 [('Content-Type', 'application/xhtml+xml; charset=utf-8')]) | 79 [('Content-Type', 'application/xhtml+xml; charset=utf-8')]) |
| 93 return [template.render({'message': message}).encode('utf-8')] | 80 return [template.render({'message': message}).encode('utf-8')] |
| LEFT | RIGHT |