| 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 | 19 from sitescripts.utils import get_config, get_template | 
| 20 from sitescripts.utils import get_config, get_template, setupStderr | 20 from sitescripts.web import url_handler, form_handler | 
| 21 from sitescripts.web import url_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 | 
| 26   setupStderr(environ['wsgi.errors']) | 25 def handleRequest(environ, start_response, params): | 
| 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() | 26   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): | 27   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) | 28     return showError('Invalid or missing report GUID', start_response) | 
| 44 | 29 | 
| 45   reportData = getReport(guid) | 30   reportData = getReport(guid) | 
| 46 | 31 | 
| 47   if reportData == None: | 32   if reportData == None: | 
| 48     return showError('Report does not exist', start_response) | 33     return showError('Report does not exist', start_response) | 
| 49 | 34 | 
| 50   secret = calculateReportSecret(guid) | 35   secret = calculateReportSecret(guid) | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 76   newURL = get_config().get('reports', 'urlRoot') + guid | 61   newURL = get_config().get('reports', 'urlRoot') + guid | 
| 77   newURL += '?updated=' + str(int(random.uniform(0, 10000))) | 62   newURL += '?updated=' + str(int(random.uniform(0, 10000))) | 
| 78   newURL += '#secret=' + secret | 63   newURL += '#secret=' + secret | 
| 79   start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 64   start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 
| 80   return [] | 65   return [] | 
| 81 | 66 | 
| 82 def showError(message, start_response): | 67 def showError(message, start_response): | 
| 83   template = get_template(get_config().get('reports', 'errorTemplate')) | 68   template = get_template(get_config().get('reports', 'errorTemplate')) | 
| 84   start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
    l; charset=utf-8')]) | 69   start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
    l; charset=utf-8')]) | 
| 85   return [template.render({'message': message}).encode('utf-8')] | 70   return [template.render({'message': message}).encode('utf-8')] | 
| OLD | NEW | 
|---|