Repository: freedomofpress/securedrop

Issue:
Remove CUSTOM_HEADER_IMAGE legacy code
I encountered a couple of old logo versions in `securedrop/static/i`: `securedrop.png` and `securedrop_small.png`. The latter file is in fact still in use in the journalist and source UI templates, but only if `CUSTOM_HEADER_IMAGE` is set. What's `CUSTOM_HEADER_IMAGE` you ask? It's neither configurable via `sdconfig` nor found in `config.py`. 

Turns out this is an old "theming option" in early versions of SecureDrop. It looks like any explanation of what it is intended to do was dropped in 5aa8a4432949201893afbac0f506c60d93fa7483 and it's now just being quietly passed into the template. This looks to me like legacy code that can be safely removed.


Discussion:
I also don't see any way this legacy functionality could possibly work in current `develop`, since references to the `header_image` variable itself were removed from the template in #3057. It looks like this was the first iteration of "custom logo" functionality, and it'd dump a "Powered by SecureDrop" below the custom logo *iff* it was configured.
I am seeing reference to the old custom header image logic in https://github.com/freedomofpress/securedrop/blob/develop/install_files/ansible-base/roles/backup/files/0.3_collect.py which looks like an older version of `backup.py` (not called or accessed from anywhere) that can be safely removed now, so doing so as part of the same PR.

Resolving patch:
diff --git a/install_files/ansible-base/roles/backup/files/0.3_collect.py b/install_files/ansible-base/roles/backup/files/0.3_collect.py
deleted file mode 100755
--- a/install_files/ansible-base/roles/backup/files/0.3_collect.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/opt/venvs/securedrop-app-code/bin/python
-"""
-
-This script should be copied to the App server and ran by the anisble
-plabook. When run (as root), it collects all of the necessary information
-to backup the 0.3 system and stores it in /tmp/sd-backup-0.3-TIME_STAMP.zip.gpg
-
-"""
-
-import sys
-import os
-import io
-import zipfile
-from datetime import datetime
-# Import the application config.py file
-sys.path.append("/var/www/securedrop")
-import config  # noqa: F403
-import gnupg  # noqa: F403
-
-TOR_SERVICES = "/var/lib/tor/services"
-TOR_CONFIG = "/etc/tor/torrc"
-
-
-def collect_config_file(zf):
-    config_file_path = os.path.join(config.SECUREDROP_ROOT, "config.py")
-    zf.write(config_file_path)
-
-
-def collect_securedrop_data_root(zf):
-    # The store and key dirs are shared between both interfaces
-    for root, dirs, files in os.walk(config.SECUREDROP_DATA_ROOT):
-        for name in files:
-            zf.write(os.path.join(root, name))
-
-
-def collect_custom_header_image(zf):
-    # The custom header image is copied over the deafult `static/i/logo.png`.
-    zf.write(os.path.join(config.SECUREDROP_ROOT, "static/i/logo.png"))
-
-
-def collect_tor_files(zf):
-    # All of the tor Onion Service private keys are stored in the THS specific
-    # subdirectory `/var/lib/tor/services` backing up this directory will back
-    # up all of the THS and ATHS required keys needed to restore all the hidden
-    # services on that system.
-    for root, dirs, files in os.walk(TOR_SERVICES):
-        for name in files:
-            zf.write(os.path.join(root, name))
-
-    # The tor config file has the ATHS client names required to restore
-    # the ATHS info. These names are also in the the specific client_key file
-    # but backing up this file makes it easier than parsing the files during a
-    # restore.
-    zf.write(TOR_CONFIG)
-
-
-def encrypt_zip_file(zf_fn):
-    # Encrypt the backup zip file with the application's gpg public key
-    gpg = gnupg.GPG(binary='gpg2', homedir=config.GPG_KEY_DIR)
-    e_fn = '{}.gpg'.format(zf_fn)
-
-    stream = io.open(zf_fn, "rb")
-    gpg.encrypt_file(stream, config.JOURNALIST_KEY, always_trust='True',
-                     output=e_fn)
-
-
-def main():
-    # name append a timestamp to the sd-backup zip filename
-    dt = str(datetime.utcnow().strftime("%Y-%m-%d--%H-%M-%S"))
-    zf_fn = 'sd-backup-{}.zip'.format(dt)
-    with zipfile.ZipFile(zf_fn, 'w') as zf:
-        collect_config_file(zf)
-        collect_securedrop_data_root(zf)
-        collect_custom_header_image(zf)
-        collect_tor_files(zf)
-    encrypt_zip_file(zf_fn)
-    print(zf_fn)
-
-
-if __name__ == "__main__":
-    main()
diff --git a/securedrop/journalist_app/__init__.py b/securedrop/journalist_app/__init__.py
--- a/securedrop/journalist_app/__init__.py
+++ b/securedrop/journalist_app/__init__.py
@@ -111,14 +111,6 @@ def _handle_http_exception(
     app.jinja_env.trim_blocks = True
     app.jinja_env.lstrip_blocks = True
     app.jinja_env.globals['version'] = version.__version__
-    if hasattr(config, 'CUSTOM_HEADER_IMAGE'):
-        app.jinja_env.globals['header_image'] = \
-            config.CUSTOM_HEADER_IMAGE  # type: ignore
-        app.jinja_env.globals['use_custom_header_image'] = True
-    else:
-        app.jinja_env.globals['header_image'] = 'logo.png'
-        app.jinja_env.globals['use_custom_header_image'] = False
-
     app.jinja_env.filters['rel_datetime_format'] = \
         template_filters.rel_datetime_format
     app.jinja_env.filters['filesizeformat'] = template_filters.filesizeformat
diff --git a/securedrop/source_app/__init__.py b/securedrop/source_app/__init__.py
--- a/securedrop/source_app/__init__.py
+++ b/securedrop/source_app/__init__.py
@@ -91,14 +91,6 @@ def handle_csrf_error(e):
     app.jinja_env.globals['version'] = version.__version__
     # Exported to source templates for being included in instructions
     app.jinja_env.globals['submission_key_fpr'] = config.JOURNALIST_KEY
-    if getattr(config, 'CUSTOM_HEADER_IMAGE', None):
-        app.jinja_env.globals['header_image'] = \
-            config.CUSTOM_HEADER_IMAGE  # type: ignore
-        app.jinja_env.globals['use_custom_header_image'] = True
-    else:
-        app.jinja_env.globals['header_image'] = 'logo.png'
-        app.jinja_env.globals['use_custom_header_image'] = False
-
     app.jinja_env.filters['rel_datetime_format'] = \
         template_filters.rel_datetime_format
     app.jinja_env.filters['nl2br'] = evalcontextfilter(template_filters.nl2br)


Test patch: