From a7ab1d7e6ee6098c8a69fff71ea3a1a4c98ef108 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 10 Feb 2018 12:50:23 -0800 Subject: [PATCH] Add onionshare favicon to all HTML pages --- install/onionshare.nsi | 2 ++ onionshare/web.py | 20 +++++++++++++++++--- share/html/404.html | 1 + share/html/denied.html | 3 ++- share/html/index.html | 3 +-- share/images/favicon.ico | Bin 0 -> 4286 bytes 6 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 share/images/favicon.ico diff --git a/install/onionshare.nsi b/install/onionshare.nsi index 151d36d4..0380cfb2 100644 --- a/install/onionshare.nsi +++ b/install/onionshare.nsi @@ -201,6 +201,7 @@ Section "install" File "${BINPATH}\share\html\index.html" SetOutPath "$INSTDIR\share\images" + File "${BINPATH}\share\images\favicon.ico" File "${BINPATH}\share\images\file_delete.png" File "${BINPATH}\share\images\logo.png" File "${BINPATH}\share\images\logo_transparent.png" @@ -379,6 +380,7 @@ FunctionEnd Delete "$INSTDIR\share\html\404.html" Delete "$INSTDIR\share\html\denied.html" Delete "$INSTDIR\share\html\index.html" + Delete "$INSTDIR\share\images\favicon.ico" Delete "$INSTDIR\share\images\file_delete.png" Delete "$INSTDIR\share\images\logo.png" Delete "$INSTDIR\share\images\logo_transparent.png" diff --git a/onionshare/web.py b/onionshare/web.py index 3eef67c7..6ade1b47 100644 --- a/onionshare/web.py +++ b/onionshare/web.py @@ -26,6 +26,7 @@ import queue import socket import sys import tempfile +import base64 from distutils.version import LooseVersion as Version from urllib.request import urlopen @@ -125,6 +126,9 @@ def add_request(request_type, path, data=None): }) +# Load favicon.ico and base64 encode it, to pass into templates +favicon_b64 = base64.b64encode(open(common.get_resource_path('images/favicon.ico'), 'rb').read()).decode() + slug = None @@ -206,7 +210,10 @@ def index(slug_candidate): global stay_open, download_in_progress deny_download = not stay_open and download_in_progress if deny_download: - r = make_response(render_template_string(open(common.get_resource_path('html/denied.html')).read())) + r = make_response(render_template_string( + open(common.get_resource_path('html/denied.html')).read(), + favicon_b64=favicon_b64 + )) for header, value in security_headers: r.headers.set(header, value) return r @@ -215,6 +222,7 @@ def index(slug_candidate): r = make_response(render_template_string( open(common.get_resource_path('html/index.html')).read(), + favicon_b64=favicon_b64, slug=slug, file_info=file_info, filename=os.path.basename(zip_filename), @@ -243,7 +251,10 @@ def download(slug_candidate): global stay_open, download_in_progress, done deny_download = not stay_open and download_in_progress if deny_download: - r = make_response(render_template_string(open(common.get_resource_path('html/denied.html')).read())) + r = make_response(render_template_string( + open(common.get_resource_path('html/denied.html')).read(), + favicon_b64=favicon_b64 + )) for header,value in security_headers: r.headers.set(header, value) return r @@ -355,7 +366,10 @@ def page_not_found(e): force_shutdown() print(strings._('error_rate_limit')) - r = make_response(render_template_string(open(common.get_resource_path('html/404.html')).read()), 404) + r = make_response(render_template_string( + open(common.get_resource_path('html/404.html')).read(), + favicon_b64=favicon_b64 + ), 404) for header, value in security_headers: r.headers.set(header, value) return r diff --git a/share/html/404.html b/share/html/404.html index 2e2b06f0..09d0fc3c 100644 --- a/share/html/404.html +++ b/share/html/404.html @@ -2,6 +2,7 @@ Error 404 +