diff options
| author | jvoisin | 2019-03-04 14:21:34 -0800 |
|---|---|---|
| committer | jvoisin | 2019-03-04 14:21:34 -0800 |
| commit | 475d7d9bc70f2f35031ccfea8e18cdc8006882d2 (patch) | |
| tree | 4d6b3bccbe909ebb45e05d4b7bd829e51424d0f8 | |
| parent | 15a1139577809b64a9f5e8048e52b643525a79a9 (diff) | |
| parent | c52b4178403b641c4383bafc41be44ae4e669394 (diff) | |
Merge branch 'custom_templates' into 'master'
Add support to override default templates with custom ones (Fixes: #14)
Closes #14
See merge request jvoisin/mat2-web!4
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | main.py | 7 |
3 files changed, 14 insertions, 0 deletions
| @@ -1 +1,2 @@ | |||
| 1 | __pycache__ | 1 | __pycache__ |
| 2 | custom_templates | ||
| @@ -79,6 +79,12 @@ collector cronjob to remove leftover files . Besides, it can create a | |||
| 79 | the uploads folder, to ensure that the uploaded files won't be recoverable | 79 | the uploads folder, to ensure that the uploaded files won't be recoverable |
| 80 | between reboots. | 80 | between reboots. |
| 81 | 81 | ||
| 82 | # Custom templates | ||
| 83 | |||
| 84 | You can override the default templates from `templates/` by putting replacements | ||
| 85 | into the directory path that's configured in `app.config['CUSTOM_TEMPLATES_DIR']` | ||
| 86 | (default `custom_templates/`). | ||
| 87 | |||
| 82 | # Threat model | 88 | # Threat model |
| 83 | 89 | ||
| 84 | - An attacker in possession of the very same file that a user wants to clean, | 90 | - An attacker in possession of the very same file that a user wants to clean, |
| @@ -6,6 +6,7 @@ from libmat2 import parser_factory | |||
| 6 | 6 | ||
| 7 | from flask import Flask, flash, request, redirect, url_for, render_template | 7 | from flask import Flask, flash, request, redirect, url_for, render_template |
| 8 | from flask import send_from_directory, after_this_request | 8 | from flask import send_from_directory, after_this_request |
| 9 | import jinja2 | ||
| 9 | 10 | ||
| 10 | from werkzeug.utils import secure_filename | 11 | from werkzeug.utils import secure_filename |
| 11 | 12 | ||
| @@ -14,6 +15,12 @@ app = Flask(__name__) | |||
| 14 | app.config['SECRET_KEY'] = os.urandom(32) | 15 | app.config['SECRET_KEY'] = os.urandom(32) |
| 15 | app.config['UPLOAD_FOLDER'] = './uploads/' | 16 | app.config['UPLOAD_FOLDER'] = './uploads/' |
| 16 | app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB | 17 | app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB |
| 18 | app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates' | ||
| 19 | |||
| 20 | app.jinja_loader = jinja2.ChoiceLoader([ # type: ignore | ||
| 21 | jinja2.FileSystemLoader(app.config['CUSTOM_TEMPLATES_DIR']), | ||
| 22 | app.jinja_loader, | ||
| 23 | ]) | ||
| 17 | 24 | ||
| 18 | def __hash_file(filepath: str) -> str: | 25 | def __hash_file(filepath: str) -> str: |
| 19 | sha256 = hashlib.sha256() | 26 | sha256 = hashlib.sha256() |
