summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordoobry2019-02-26 12:40:11 +0100
committerdoobry2019-03-04 14:55:53 +0100
commitc52b4178403b641c4383bafc41be44ae4e669394 (patch)
tree4d6b3bccbe909ebb45e05d4b7bd829e51424d0f8
parent15a1139577809b64a9f5e8048e52b643525a79a9 (diff)
Add support to override default templates with custom ones (Fixes: #14)
-rw-r--r--.gitignore1
-rw-r--r--README.md6
-rw-r--r--main.py7
3 files changed, 14 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index bee8a64..e42d897 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
1__pycache__ 1__pycache__
2custom_templates
diff --git a/README.md b/README.md
index b12e1ea..5f00d86 100644
--- a/README.md
+++ b/README.md
@@ -79,6 +79,12 @@ collector cronjob to remove leftover files . Besides, it can create a
79the uploads folder, to ensure that the uploaded files won't be recoverable 79the uploads folder, to ensure that the uploaded files won't be recoverable
80between reboots. 80between reboots.
81 81
82# Custom templates
83
84You can override the default templates from `templates/` by putting replacements
85into 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,
diff --git a/main.py b/main.py
index 59c3791..033d8b6 100644
--- a/main.py
+++ b/main.py
@@ -6,6 +6,7 @@ from libmat2 import parser_factory
6 6
7from flask import Flask, flash, request, redirect, url_for, render_template 7from flask import Flask, flash, request, redirect, url_for, render_template
8from flask import send_from_directory, after_this_request 8from flask import send_from_directory, after_this_request
9import jinja2
9 10
10from werkzeug.utils import secure_filename 11from werkzeug.utils import secure_filename
11 12
@@ -14,6 +15,12 @@ app = Flask(__name__)
14app.config['SECRET_KEY'] = os.urandom(32) 15app.config['SECRET_KEY'] = os.urandom(32)
15app.config['UPLOAD_FOLDER'] = './uploads/' 16app.config['UPLOAD_FOLDER'] = './uploads/'
16app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB 17app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
18app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates'
19
20app.jinja_loader = jinja2.ChoiceLoader([ # type: ignore
21 jinja2.FileSystemLoader(app.config['CUSTOM_TEMPLATES_DIR']),
22 app.jinja_loader,
23 ])
17 24
18def __hash_file(filepath: str) -> str: 25def __hash_file(filepath: str) -> str:
19 sha256 = hashlib.sha256() 26 sha256 = hashlib.sha256()