OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code is subject to the terms of the Mozilla Public License | 3 # This Source Code is subject to the terms of the Mozilla Public License |
4 # version 2.0 (the "License"). You can obtain a copy of the License at | 4 # version 2.0 (the "License"). You can obtain a copy of the License at |
5 # http://mozilla.org/MPL/2.0/. | 5 # http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import re, os, sys, random | 7 import re, os, sys, random |
8 from urlparse import parse_qsl | 8 from urlparse import parse_qsl |
9 from sitescripts.utils import get_config, get_template, setupStderr | 9 from sitescripts.utils import get_config, get_template, setupStderr |
10 from sitescripts.web import url_handler | 10 from sitescripts.web import url_handler |
(...skipping 26 matching lines...) Expand all Loading... |
37 return showError('Report does not exist', start_response) | 37 return showError('Report does not exist', start_response) |
38 | 38 |
39 secret = calculateReportSecret(guid) | 39 secret = calculateReportSecret(guid) |
40 if params.get('secret', '') != secret and params.get('secret', '') != calculat
eReportSecret_compat(guid): | 40 if params.get('secret', '') != secret and params.get('secret', '') != calculat
eReportSecret_compat(guid): |
41 return showError('Wrong secret value', start_response) | 41 return showError('Wrong secret value', start_response) |
42 | 42 |
43 reportData['status'] = params.get('status', '') | 43 reportData['status'] = params.get('status', '') |
44 if len(reportData['status']) > 1024: | 44 if len(reportData['status']) > 1024: |
45 reportData['status'] = reportData['status'][:1024] | 45 reportData['status'] = reportData['status'][:1024] |
46 | 46 |
| 47 reportData['utility'] = params.get('utility', 0) |
| 48 |
47 saveReport(guid, reportData) | 49 saveReport(guid, reportData) |
48 | 50 |
49 if params.get('notify', '') and 'email' in reportData: | 51 if params.get('notify', '') and 'email' in reportData: |
50 email = reportData['email'] | 52 email = reportData['email'] |
51 email = re.sub(r' at ', r'@', email) | 53 email = re.sub(r' at ', r'@', email) |
52 email = re.sub(r' dot ', r'.', email) | 54 email = re.sub(r' dot ', r'.', email) |
53 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email): | 55 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email): |
54 sendUpdateNotification({ | 56 sendUpdateNotification({ |
55 'email': email, | 57 'email': email, |
56 'url': get_config().get('reports', 'urlRoot') + guid, | 58 'url': get_config().get('reports', 'urlRoot') + guid, |
57 'status': reportData['status'], | 59 'status': reportData['status'], |
58 }) | 60 }) |
59 | 61 |
60 newURL = get_config().get('reports', 'urlRoot') + guid | 62 newURL = get_config().get('reports', 'urlRoot') + guid |
61 newURL += '?updated=' + str(int(random.uniform(0, 10000))) | 63 newURL += '?updated=' + str(int(random.uniform(0, 10000))) |
62 newURL += '#secret=' + secret | 64 newURL += '#secret=' + secret |
63 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 65 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) |
64 return [] | 66 return [] |
65 | 67 |
66 def showError(message, start_response): | 68 def showError(message, start_response): |
67 template = get_template(get_config().get('reports', 'errorTemplate')) | 69 template = get_template(get_config().get('reports', 'errorTemplate')) |
68 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
l; charset=utf-8')]) | 70 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm
l; charset=utf-8')]) |
69 return [template.render({'message': message}).encode('utf-8')] | 71 return [template.render({'message': message}).encode('utf-8')] |
OLD | NEW |