From 53775d233bb7d226229bdf157fc37f8601b03a97 Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Mon, 2 Oct 2017 11:14:50 +0200 Subject: [PATCH] [enh] add global password --- prosopopee/prosopopee.py | 31 +++++++-- .../themes/exposure/templates/encrypted.html | 50 +++++--------- .../themes/exposure/templates/form.html | 22 ++++++ .../exposure/templates/index-encrypted.html | 66 ++++++++++++++++++ .../themes/material/templates/encrypted.html | 54 +++++---------- .../themes/material/templates/form.html | 30 ++++++++ .../material/templates/index-encrypted.html | 69 +++++++++++++++++++ 7 files changed, 248 insertions(+), 74 deletions(-) create mode 100644 prosopopee/themes/exposure/templates/form.html create mode 100644 prosopopee/themes/exposure/templates/index-encrypted.html create mode 100644 prosopopee/themes/material/templates/form.html create mode 100644 prosopopee/themes/material/templates/index-encrypted.html diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 52f3399..116820c 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -22,6 +22,8 @@ from subprocess import check_output import ruamel.yaml as yaml from docopt import docopt +import base64 + from path import Path from jinja2 import Environment, FileSystemLoader @@ -447,6 +449,7 @@ def build_gallery(settings, gallery_settings, gallery_path, template): gallery_index_template = template.get_template("gallery-index.html") page_template = template.get_template("page.html") encrypted_template = template.get_template("encrypted.html") + from_template = template.get_template("form.html") # this should probably be a factory Image.base_dir = Path(".").joinpath(gallery_path) @@ -476,14 +479,15 @@ def build_gallery(settings, gallery_settings, gallery_path, template): open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) - if gallery_settings.get("password"): - template_to_render = encrypted_template - password = gallery_settings.get("password") + if gallery_settings.get("password") or settings.get("password"): + password = gallery_settings.get("password", settings.get("password")) index_plain = Path("build").joinpath(gallery_path, "index.html") + form = base64.b64encode(from_template.render(gallery=gallery_settings).encode("Utf-8")) encrypted = check_output('cat %s | openssl enc -e -base64 -A -aes-256-cbc -pass pass:"%s"' % (index_plain, password), shell=True) - html = template_to_render.render( + html = encrypted_template.render( settings=settings, gallery=gallery_settings, + form=str(form, 'utf-8'), ciphertext=str(encrypted, 'utf-8'), ).encode("Utf-8") @@ -524,15 +528,18 @@ def build_gallery(settings, gallery_settings, gallery_path, template): open(Path("build").joinpath(gallery_light_path, "index.html"), "wb").write(html) - if gallery_settings.get("password"): + if gallery_settings.get("password") or settings.get("password"): light_template_to_render = light_templates.get_template("encrypted.html") + from_template = light_templates.get_template("form.html") + form = base64.b64encode(from_template.render(gallery=gallery_settings).encode("Utf-8")) template_to_render = encrypted_template - password = gallery_settings.get("password") + password = gallery_settings.get("password", settings.get("password")) index_plain = Path("build").joinpath(gallery_light_path, "index.html") encrypted = check_output('cat %s | openssl enc -e -base64 -A -aes-256-cbc -pass pass:"%s"' % (index_plain, password), shell=True) html = light_template_to_render.render( settings=settings, gallery=gallery_settings, + form=str(form, 'utf-8'), ciphertext=str(encrypted, 'utf-8'), ).encode("Utf-8") @@ -565,6 +572,18 @@ def build_index(settings, galleries_cover, templates, gallery_path='', sub_index open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) + if settings.get("password"): + index_template_to_render = templates.get_template("index-encrypted.html") + password = settings.get("password") + index_plain = Path("build").joinpath(gallery_path, "index.html") + encrypted = check_output('cat %s | openssl enc -e -base64 -A -aes-256-cbc -pass pass:"%s"' % (index_plain, password), shell=True) + html = index_template_to_render.render( + settings=settings, + ciphertext=str(encrypted, 'utf-8') + ).encode("Utf-8") + + open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) + def main(): arguments = docopt(__doc__, version='0.6') diff --git a/prosopopee/themes/exposure/templates/encrypted.html b/prosopopee/themes/exposure/templates/encrypted.html index 8dd4f6a..4293204 100644 --- a/prosopopee/themes/exposure/templates/encrypted.html +++ b/prosopopee/themes/exposure/templates/encrypted.html @@ -12,54 +12,40 @@ + + + - - + diff --git a/prosopopee/themes/exposure/templates/form.html b/prosopopee/themes/exposure/templates/form.html new file mode 100644 index 0000000..9f5dfaa --- /dev/null +++ b/prosopopee/themes/exposure/templates/form.html @@ -0,0 +1,22 @@ + +
\ +
+
+ +

{{ gallery.title }}

+
+
+
+
+ + +
+
+
+ diff --git a/prosopopee/themes/exposure/templates/index-encrypted.html b/prosopopee/themes/exposure/templates/index-encrypted.html new file mode 100644 index 0000000..bed3372 --- /dev/null +++ b/prosopopee/themes/exposure/templates/index-encrypted.html @@ -0,0 +1,66 @@ + + + + + {{ settings.title }} + + + + + + + + + + + + +
+
+
+ +

{{ settings.title }}

+
+ +
+ +
+
+ + + +
+
+ +
+ + + + + + diff --git a/prosopopee/themes/material/templates/encrypted.html b/prosopopee/themes/material/templates/encrypted.html index 1a6b118..b16be9d 100644 --- a/prosopopee/themes/material/templates/encrypted.html +++ b/prosopopee/themes/material/templates/encrypted.html @@ -14,56 +14,38 @@ + + - - + diff --git a/prosopopee/themes/material/templates/form.html b/prosopopee/themes/material/templates/form.html new file mode 100644 index 0000000..1bd9a48 --- /dev/null +++ b/prosopopee/themes/material/templates/form.html @@ -0,0 +1,30 @@ + +
+
+
+

{{ gallery.title }}

+
+ +
+ +
+
+ + +
+
+ +
+ + diff --git a/prosopopee/themes/material/templates/index-encrypted.html b/prosopopee/themes/material/templates/index-encrypted.html new file mode 100644 index 0000000..f6e33dc --- /dev/null +++ b/prosopopee/themes/material/templates/index-encrypted.html @@ -0,0 +1,69 @@ + + + + + {{ settings.title }} + + + + + + + + + + + + + +
+
+
+

{{ settings.title }}

+
+ +
+ +
+
+ + +
+
+ +
+ + + + +