-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproblem_report.py
More file actions
39 lines (25 loc) · 1.16 KB
/
problem_report.py
File metadata and controls
39 lines (25 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
#
# Copyright (c) 2020 Gareth Palmer <gareth.palmer3@gmail.com>
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2.
import re
from datetime import datetime
from flask import Blueprint, Response, request
import config
blueprint = Blueprint('problem_report', __name__)
@blueprint.route('/problem-report', methods = ['POST'])
def problem_report():
# Newer firmware now puts a leading newline for multipart/form-data variables
device_name = request.form.get('devicename', '').strip()
if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name):
return Response('Invalid device', mimetype = 'text/plain'), 403
prt_file = request.files.get('prt_file')
if prt_file is None:
return Response('Missing problem report', mimetype = 'text/plain'), 500
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
prt_file.save(f'{config.reports_dir}/prt-{device_name}-{timestamp}.tar.gz')
return Response('Log saved', mimetype = 'text/plain'), 200
@blueprint.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500