diff options
| author | Jan Friedli | 2020-08-30 14:44:41 +0200 |
|---|---|---|
| committer | jfriedli | 2020-09-06 08:29:17 -0700 |
| commit | 58709ebca01940b57527664adf6ad0309d6dd980 (patch) | |
| tree | 62775e7d18255522925f728c7c97be13761b9899 /matweb/utils.py | |
| parent | 7a252eaa907a71dfdc5c8b408659be3352a52c20 (diff) | |
added more logging for the helpers and the frontend
Diffstat (limited to 'matweb/utils.py')
| -rw-r--r-- | matweb/utils.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/matweb/utils.py b/matweb/utils.py index 915d735..ea84f4f 100644 --- a/matweb/utils.py +++ b/matweb/utils.py | |||
| @@ -3,7 +3,7 @@ import os | |||
| 3 | import hashlib | 3 | import hashlib |
| 4 | import mimetypes as mtype | 4 | import mimetypes as mtype |
| 5 | 5 | ||
| 6 | from flask_restful import abort | 6 | from flask_restful import abort, current_app |
| 7 | from libmat2 import parser_factory | 7 | from libmat2 import parser_factory |
| 8 | from werkzeug.utils import secure_filename | 8 | from werkzeug.utils import secure_filename |
| 9 | 9 | ||
| @@ -31,6 +31,7 @@ def hash_file(filepath: str, secret: str) -> str: | |||
| 31 | 31 | ||
| 32 | def check_upload_folder(upload_folder): | 32 | def check_upload_folder(upload_folder): |
| 33 | if not os.path.exists(upload_folder): | 33 | if not os.path.exists(upload_folder): |
| 34 | current_app.logger.info('Upload folder does not exist - creating it') | ||
| 34 | os.mkdir(upload_folder) | 35 | os.mkdir(upload_folder) |
| 35 | 36 | ||
| 36 | 37 | ||
| @@ -98,14 +99,17 @@ def get_file_paths(filename, upload_folder): | |||
| 98 | 99 | ||
| 99 | def is_valid_api_download_file(filename: str, key: str, secret: str, upload_folder: str) -> [str, str]: | 100 | def is_valid_api_download_file(filename: str, key: str, secret: str, upload_folder: str) -> [str, str]: |
| 100 | if filename != secure_filename(filename): | 101 | if filename != secure_filename(filename): |
| 102 | current_app.logger.error('Insecure filename %', filename) | ||
| 101 | abort(400, message='Insecure filename') | 103 | abort(400, message='Insecure filename') |
| 102 | 104 | ||
| 103 | complete_path, filepath = get_file_paths(filename, upload_folder) | 105 | complete_path, filepath = get_file_paths(filename, upload_folder) |
| 104 | 106 | ||
| 105 | if not os.path.exists(complete_path): | 107 | if not os.path.exists(complete_path): |
| 108 | current_app.logger.error('File not found') | ||
| 106 | abort(404, message='File not found') | 109 | abort(404, message='File not found') |
| 107 | 110 | ||
| 108 | if hmac.compare_digest(hash_file(complete_path, secret), key) is False: | 111 | if hmac.compare_digest(hash_file(complete_path, secret), key) is False: |
| 112 | current_app.logger.error('The file hash does not match') | ||
| 109 | abort(400, message='The file hash does not match') | 113 | abort(400, message='The file hash does not match') |
| 110 | return complete_path, filepath | 114 | return complete_path, filepath |
| 111 | 115 | ||
