-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (49 loc) · 1.49 KB
/
app.py
File metadata and controls
61 lines (49 loc) · 1.49 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import tempfile
import shutil
import subprocess
from flask import Flask, request, redirect, url_for
from werkzeug.utils import secure_filename
import constants
MAIN_TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form name="form" action="/upload" method="POST" enctype="multipart/form-data">
<span>Crash dump file: </span><input type="file" name="file"/>
<input type="submit" value="Upload" name="submit">
</form>
</body>
</html>
"""
CRASHDUMP_EXTENSION = '.dmp'
CRASHDUMP_HEADER = 'MDMP'
app = Flask(__name__)
# Limit uploads to 1M
app.config['MAX_CONTENT_LENGTH'] = 1 * 1024 * 1024
@app.route('/', methods=['GET'])
def main():
return MAIN_TEMPLATE
@app.route('/upload', methods=['POST'])
def upload():
if not 'file' in request.files or not request.files['file'].filename:
return 'Missing crash dump.', 400
file = request.files['file']
if not file.filename.endswith(CRASHDUMP_EXTENSION):
return 'Must upload a crash dump .dmp file.', 400
with tempfile.NamedTemporaryFile() as f:
shutil.copyfileobj(file.stream, f)
f.flush()
f.seek(0)
try:
if f.read(len(CRASHDUMP_HEADER)).decode('ascii') != CRASHDUMP_HEADER:
return 'Invalid dump file.', 400
except:
return 'Invalid dump file.', 400
try:
out = subprocess.check_output([constants.MINIDUMP_STACKWALK, f.name, constants.SYMBOL_PATH])
return '<pre>%s</pre>' % out.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output, 400
return 'ok'