OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import re, os, sys, random | 18 import re, os, sys, random |
19 from urlparse import parse_qsl | |
20 from sitescripts.utils import get_config, get_template, setupStderr | 19 from sitescripts.utils import get_config, get_template, setupStderr |
21 from sitescripts.web import url_handler | 20 from sitescripts.web import url_handler, form_handler |
22 from sitescripts.reports.utils import calculateReportSecret, calculateReportSecr
et_compat, getReport, saveReport, sendUpdateNotification, getUserId, updateUserU
sefulness | 21 from sitescripts.reports.utils import calculateReportSecret, calculateReportSecr
et_compat, getReport, saveReport, sendUpdateNotification, getUserId, updateUserU
sefulness |
23 | 22 |
24 @url_handler('/updateReport') | 23 @url_handler('/updateReport') |
25 def handleRequest(environ, start_response): | 24 @form_handler |
| 25 def handleRequest(environ, start_response, params): |
26 setupStderr(environ['wsgi.errors']) | 26 setupStderr(environ['wsgi.errors']) |
27 | 27 |
28 if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYP
E', '').startswith('application/x-www-form-urlencoded'): | |
29 return showError('Unsupported request method', start_response) | |
30 | |
31 try: | |
32 request_body_length = int(environ['CONTENT_LENGTH']) | |
33 except: | |
34 return showError('Invalid or missing Content-Length header', start_response) | |
35 | |
36 request_body = environ['wsgi.input'].read(request_body_length) | |
37 params = {} | |
38 for key, value in parse_qsl(request_body): | |
39 params[key] = value.decode('utf-8') | |
40 | |
41 guid = params.get('guid', '').lower() | 28 guid = params.get('guid', '').lower() |
42 if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$',
guid): | 29 if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$',
guid): |
43 return showError('Invalid or missing report GUID', start_response) | 30 return showError('Invalid or missing report GUID', start_response) |
44 | 31 |
45 reportData = getReport(guid) | 32 reportData = getReport(guid) |
46 | 33 |
47 if reportData == None: | 34 if reportData == None: |
48 return showError('Report does not exist', start_response) | 35 return showError('Report does not exist', start_response) |
49 | 36 |
50 secret = calculateReportSecret(guid) | 37 secret = calculateReportSecret(guid) |
(...skipping 25 matching lines...) Expand all Loading... |
76 newURL = get_config().get('reports', 'urlRoot') + guid | 63 newURL = get_config().get('reports', 'urlRoot') + guid |
77 newURL += '?updated=' + str(int(random.uniform(0, 10000))) | 64 newURL += '?updated=' + str(int(random.uniform(0, 10000))) |
78 newURL += '#secret=' + secret | 65 newURL += '#secret=' + secret |
79 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 66 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) |
80 return [] | 67 return [] |
81 | 68 |
82 def showError(message, start_response): | 69 def showError(message, start_response): |
83 template = get_template(get_config().get('reports', 'errorTemplate')) | 70 template = get_template(get_config().get('reports', 'errorTemplate')) |
84 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
l; charset=utf-8')]) | 71 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
l; charset=utf-8')]) |
85 return [template.render({'message': message}).encode('utf-8')] | 72 return [template.render({'message': message}).encode('utf-8')] |
OLD | NEW |