From afd5b9aa835e7f4d1e0e3cbd01bcaf3ccdf02af1 Mon Sep 17 00:00:00 2001 From: Ben Busby <33362396+benbusby@users.noreply.github.com> Date: Fri, 15 May 2020 14:17:16 -0600 Subject: [PATCH 1/4] Minor fix to dark mode on img results --- app/filter.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/filter.py b/app/filter.py index a77116c..006cbac 100644 --- a/app/filter.py +++ b/app/filter.py @@ -78,7 +78,7 @@ class Filter: # Special rebranding for image search results if img_src.startswith(LOGO_URL): img['src'] = '/static/img/logo.png' - img['height'] = 40 + img['style'] = 'height:40px;width:162px' else: img['src'] = BLANK_B64 @@ -114,9 +114,15 @@ class Filter: # Set up dark mode if active if self.dark: - soup.find('html')['style'] = 'scrollbar-color: #333 #111;' + soup.find('html')['style'] = 'scrollbar-color: #333 #111;color:#fff !important;background:#000 !important' for input_element in soup.findAll('input'): - input_element['style'] = 'color:#fff;' + input_element['style'] = 'color:#fff;background:#000;' + + for span_element in soup.findAll('span'): + span_element['style'] = 'color: white;' + + for href_element in soup.findAll('a'): + href_element['style'] = 'color: white' if href_element['href'].startswith('/search') else '' def update_links(self, soup): # Replace hrefs with only the intended destination (no "utm" type tags) From 1ed6178e9a50d961ddff4aa13f772937d07c4981 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 15 May 2020 15:44:50 -0600 Subject: [PATCH 2/4] Feature: https only -- adds option to enforce https on running instances (#48) * Adding HTTPS enforcement Command line runs of Whoogle Search through pip/pipx/etc will need the `--https-only` flag appended to the run command. Docker runs require the `use_https` build arg applied. * Update README.md Moved https-only note to top of docker run command, updated pip runner help output * Dockerfile: removed HTTPS enforcement, updated PORT setting Dockerfile no longer enforces an HTTPS connection, but still allows for setting via a build arg. The Flask server port is now configurable as a build arg as well, by setting a port number to "whoogle_port" * Fixed incorrect port assignment --- Dockerfile | 8 +++++++- README.md | 6 ++++-- app/routes.py | 10 ++++++++++ whoogle-search | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3438aa..18551cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,14 @@ RUN mkdir $config_dir VOLUME $config_dir ENV CONFIG_VOLUME=$config_dir +ARG use_https='' +ENV HTTPS_ONLY=$use_https + +ARG whoogle_port=5000 +ENV EXPOSE_PORT=$whoogle_port + COPY . . -EXPOSE 5000 +EXPOSE $EXPOSE_PORT CMD ["./whoogle-search"] diff --git a/README.md b/README.md index d22d1d7..95de42c 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Sandboxed temporary instance: ```bash $ whoogle-search --help usage: whoogle-search [-h] [--port ] [--host ] [--debug] + [--https-only] Whoogle Search console runner @@ -79,7 +80,8 @@ optional arguments: -h, --help show this help message and exit --port Specifies a port to run on (default 5000) --host Specifies the host address to use (default 127.0.0.1) - --debug Activates debug mode for the Flask server (default False) + --debug Activates debug mode for the server (default False) + --https-only Enforces HTTPS redirects for all requests (default False) ``` ### D) Manual @@ -124,7 +126,7 @@ docker build --tag whoogle-search:1.0 . docker run --publish 5000:5000 --detach --name whoogle-search whoogle-search:1.0 ``` -And kill with: `docker rm --force whooglesearch` +And kill with: `docker rm --force whoogle-search` #### Using [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) ```bash diff --git a/app/routes.py b/app/routes.py index 4fa3c93..94a10c3 100644 --- a/app/routes.py +++ b/app/routes.py @@ -20,6 +20,12 @@ CONFIG_PATH = os.getenv('CONFIG_VOLUME', app.config['STATIC_FOLDER']) + '/config @app.before_request def before_request_func(): + # Always redirect to https if HTTPS_ONLY is set + if os.getenv('HTTPS_ONLY', False) and request.url.startswith('http://'): + url = request.url.replace('http://', 'https://', 1) + code = 301 + return redirect(url, code=code) + json_config = json.load(open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else {'url': request.url_root} g.user_config = Config(**json_config) @@ -162,7 +168,11 @@ def run_app(): help='Specifies the host address to use (default 127.0.0.1)') parser.add_argument('--debug', default=False, action='store_true', help='Activates debug mode for the server (default False)') + parser.add_argument('--https-only', default=False, action='store_true', + help='Enforces HTTPS redirects for all requests') args = parser.parse_args() + os.environ['HTTPS_ONLY'] = '1' if args.https_only else '' + if args.debug: app.run(host=args.host, port=args.port, debug=args.debug) else: diff --git a/whoogle-search b/whoogle-search index b4f229c..f87c61a 100755 --- a/whoogle-search +++ b/whoogle-search @@ -7,7 +7,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" # Set default port if unavailable if [[ -z "${PORT}" ]]; then - PORT=5000 + PORT="${EXPOSE_PORT:-5000}" fi # Set directory to serve static content from From 0e9bbc737d3197ff9043e49545dc105e9e785c7c Mon Sep 17 00:00:00 2001 From: Paul Rothrock Date: Fri, 15 May 2020 18:01:26 -0400 Subject: [PATCH 3/4] Add Alfred Instructions (#52) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 95de42c..67219fd 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,13 @@ Update browser settings: - Click the 3 dot menu in the top right - Navigate to the settings menu and select the "search" sub-menu - Select Whoogle and press "Set as default" + - [Alfred](https://www.alfredapp.com/) (Mac OS X) + 1. Go to `Alfred Preferences` > `Features` > `Web Search` and click `Add Custom Search`. Then configure these settings + - Search URL: `https://\/search?q={query} + - Title: `Whoogle for '{query}'` (or whatever you want) + - Keyword: `whoogle` + + 2. Go to `Default Results` and click the `Setup fallback results` button. Click `+` and add Whoogle, then drag it to the top. - Others (TODO) ### Customizing and Configuration From 31237895841f699234e9d19716d028b93dd584af Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 15 May 2020 16:10:31 -0600 Subject: [PATCH 4/4] Added config option for opening links in new tab (#49) --- app/filter.py | 3 +++ app/models/config.py | 1 + app/static/js/controller.js | 2 ++ app/templates/index.html | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/app/filter.py b/app/filter.py index 006cbac..0cda5d3 100644 --- a/app/filter.py +++ b/app/filter.py @@ -22,6 +22,7 @@ class Filter: self.near = config['near'] if 'near' in config else '' self.dark = config['dark'] if 'dark' in config else False self.nojs = config['nojs'] if 'nojs' in config else False + self.new_tab = config['new_tab'] if 'new_tab' in config else False self.mobile = mobile self.secret_key = secret_key @@ -131,6 +132,8 @@ class Filter: if '/advanced_search' in href: a.decompose() continue + elif self.new_tab: + a['target'] = '_blank' result_link = urlparse.urlparse(href) query_link = parse_qs(result_link.query)['q'][0] if '?q=' in href else '' diff --git a/app/models/config.py b/app/models/config.py index 1c866d7..1a53049 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -57,6 +57,7 @@ class Config: self.dark = False self.nojs = False self.near = '' + self.new_tab = False self.get_only = False for key, value in kwargs.items(): diff --git a/app/static/js/controller.js b/app/static/js/controller.js index e950eb5..02ecdb5 100644 --- a/app/static/js/controller.js +++ b/app/static/js/controller.js @@ -21,6 +21,7 @@ const fillConfigValues = () => { const noJS = document.getElementById("config-nojs"); const dark = document.getElementById("config-dark"); const url = document.getElementById("config-url"); + const newTab = document.getElementById("config-new-tab"); const getOnly = document.getElementById("config-get-only"); // Request existing config info @@ -39,6 +40,7 @@ const fillConfigValues = () => { noJS.checked = !!configSettings["nojs"]; dark.checked = !!configSettings["dark"]; getOnly.checked = !!configSettings["get_only"]; + newTab.checked = !!configSettings["new_tab"]; // Addresses the issue of incorrect URL being used behind reverse proxy url.value = configSettings["url"] ? configSettings["url"] : ""; diff --git a/app/templates/index.html b/app/templates/index.html index 222fa17..33f2153 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -66,6 +66,10 @@ +
+ + +