diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index f98417a..8c491b3 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -17,19 +17,18 @@ import shutil import socketserver import http.server +import base64 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 from .cache import CACHE -from .utils import error, warning, okgreen +from .utils import error, warning, okgreen, makeform, encrypt DEFAULTS = { @@ -448,8 +447,6 @@ def create_cover(gallery_name, gallery_settings, gallery_path): 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) @@ -480,16 +477,8 @@ 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") or settings.get("password"): - form = base64.b64encode(from_template.render(gallery=gallery_settings, settings=settings).encode("Utf-8")) password = gallery_settings.get("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 = encrypted_template.render( - settings=settings, - gallery=gallery_settings, - form=str(form, 'utf-8'), - ciphertext=str(encrypted, 'utf-8'), - ).encode("Utf-8") + html = encrypt(password, template, gallery_path, settings, gallery_settings) open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) @@ -529,26 +518,14 @@ 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") 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, settings=settings).encode("Utf-8")) - template_to_render = encrypted_template - 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") - + html = encrypt(password, light_templates, gallery_light_path, settings, gallery_settings) + open(Path("build").joinpath(gallery_light_path, "index.html"), "wb").write(html) def build_index(settings, galleries_cover, templates, gallery_path='', sub_index=False, gallery_settings={}): index_template = templates.get_template("index.html") - form_template = templates.get_template("form.html") reverse = gallery_settings.get('reverse', settings["settings"].get('reverse', False)) if reverse: @@ -574,17 +551,9 @@ 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"): - form = base64.b64encode(form_template.render(settings=settings).encode("Utf-8")) - index_template_to_render = templates.get_template("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, - form=str(form, 'utf-8'), - ciphertext=str(encrypted, 'utf-8') - ).encode("Utf-8") - + html = encrypt(password, templates, gallery_path, settings, None) + open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) diff --git a/prosopopee/themes/light/templates/encrypted.html b/prosopopee/themes/light/templates/encrypted.html index c230124..e2307c0 100644 --- a/prosopopee/themes/light/templates/encrypted.html +++ b/prosopopee/themes/light/templates/encrypted.html @@ -18,6 +18,7 @@ +