Conditionally set env vars from whoogle.env

This allows the user to enable their preferred settings in a variety of
ways, depending on their deployment preference. Values added to
whoogle.env can be enabled using WHOOGLE_DOTENV=1, in which case all
values in the env var file will overwrite defaults or user provided
settings.
This commit is contained in:
Ben Busby 2021-03-28 13:23:42 -04:00
parent d6f579dee6
commit 6280728ee5
No known key found for this signature in database
GPG Key ID: 3B08611DF6E62ED2
9 changed files with 41 additions and 44 deletions

12
.env
View File

@ -1,12 +0,0 @@
# This is the only file you have to change for configuring your installation
# Work done ------------------------
# Setting up social media sites
# Change the domain as per your requirements. Don't forget to rebuild your Docker or restart the app.
twitter=nitter.net
youtube=invidious.snopyta.org
instagram=bibliogram.art/u
reddit=libredd.it
# Plan
# For setting dark, Language, enable Replace Social Media Links etc

View File

@ -37,6 +37,9 @@ ENV WHOOGLE_PROXY_TYPE=$proxytype
ARG proxyloc=''
ENV WHOOGLE_PROXY_LOC=$proxyloc
ARG whoogle_dotenv=''
ENV WHOOGLE_DOTENV=$whoogle_dotenv
ARG use_https=''
ENV HTTPS_ONLY=$use_https
@ -59,6 +62,7 @@ COPY misc/tor/torrc /etc/tor/torrc
COPY misc/tor/start-tor.sh misc/tor/start-tor.sh
COPY app/ app/
COPY run .
COPY whoogle.env .
EXPOSE $EXPOSE_PORT

View File

@ -138,6 +138,8 @@ Description=Whoogle
#Environment=WHOOGLE_ALT_YT=invidious.snopyta.org
#Environment=WHOOGLE_ALT_IG=bibliogram.art/u
#Environment=WHOOGLE_ALT_RD=libredd.it
# Load values from dotenv only
#Environment=WHOOGLE_DOTENV=1
Type=simple
User=root
WorkingDirectory=<whoogle_directory>
@ -233,10 +235,11 @@ Depending on your preferences, you can also deploy the app yourself on your own
- A bit more experience or willingness to work through issues
## Environment Variables
There are a few optional environment variables available for customizing a Whoogle instance:
There are a few optional environment variables available for customizing a Whoogle instance. These can be set manually, or copied into `whoogle.env` and enabled by setting `WHOOGLE_DOTENV=1`.
| Variable | Description |
| ------------------ | -------------------------------------------------------------- |
| WHOOGLE_DOTENV | Load environment variables in `whoogle.env` |
| WHOOGLE_USER | The username for basic auth. WHOOGLE_PASS must also be set if used. |
| WHOOGLE_PASS | The password for basic auth. WHOOGLE_USER must also be set if used. |
| WHOOGLE_PROXY_USER | The username of the proxy server. |

View File

@ -6,9 +6,17 @@ from flask_session import Session
import json
import os
from stem import Signal
from dotenv import load_dotenv
app = Flask(__name__, static_folder=os.path.dirname(
os.path.abspath(__file__)) + '/static')
# Load .env file if enabled
if os.getenv("WHOOGLE_DOTENV", ''):
dotenv_path = '../whoogle.env'
load_dotenv(os.path.join(os.path.dirname(os.path.abspath(__file__)),
dotenv_path))
app.user_elements = {}
app.default_key_set = generate_user_keys()
app.no_cookie_ips = []

View File

@ -3,9 +3,6 @@ import os
import urllib.parse as urlparse
from urllib.parse import parse_qs
# For .env reading
from dotenv import load_dotenv
load_dotenv(os.path.join(os.path.abspath(os.getcwd()), '.env'))
SKIP_ARGS = ['ref_src', 'utm']
SKIP_PREFIX = ['//www.', '//mobile.', '//m.']
@ -25,32 +22,13 @@ BLACKLIST = [
'Reklāma', 'Reklaam', 'Διαφήμιση', 'מודעה', 'Hirdetés', 'Anúncio'
]
# Setting up ALTs site Links
SITE_ALTS = {}
def get_alt_links():
print("Setting up alternative social media site..")
tw,yt,ig,rd = os.getenv("twitter"),os.getenv("youtube"),os.getenv("instagram"),os.getenv("reddit")
if tw != None and tw != "":
SITE_ALTS['twitter.com']=tw
else:
SITE_ALTS['twitter.com']=os.getenv('WHOOGLE_ALT_TW', 'nitter.net')
SITE_ALTS = {
'twitter.com': os.getenv('WHOOGLE_ALT_TW', 'nitter.net'),
'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),
'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it')
}
if yt != None and yt != "":
SITE_ALTS['youtube.com']=yt
else:
SITE_ALTS['youtube.com']=os.getenv('WHOOGLE_ALT_YT', 'invalid.com')
if ig != None and ig != "":
SITE_ALTS['instagram.com']=os.getenv("instagram")
else:
SITE_ALTS['instagram.com']=os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u')
if rd != None and rd != "":
SITE_ALTS['reddit.com']=os.getenv("reddit")
else:
SITE_ALTS['reddit.com']=os.getenv('WHOOGLE_ALT_RD', 'libredd.it')
get_alt_links()
def has_ad_content(element: str) -> bool:
"""Inspects an HTML element for ad related content
@ -94,7 +72,7 @@ def get_site_alt(link: str) -> str:
str: An updated (or ignored) result link
"""
for site_key in SITE_ALTS.keys():
if site_key not in link:
continue

View File

@ -37,6 +37,8 @@ services:
#- WHOOGLE_ALT_YT=invidious.snopyta.org
#- WHOOGLE_ALT_IG=bibliogram.art/u
#- WHOOGLE_ALT_RD=libredd.it
# Load environment variables from whoogle.env
#- WHOOGLE_DOTENV=1
ports:
- 5000:5000
restart: unless-stopped

View File

@ -31,4 +31,4 @@ urllib3==1.25.9
waitress==1.4.3
wcwidth==0.1.9
Werkzeug==0.16.0
python-dotenv
python-dotenv==0.16.0

2
run
View File

@ -22,5 +22,5 @@ else
mkdir -p "$STATIC_FOLDER"
python3 -um app \
--host "${ADDRESS:-0.0.0.0}" \
--port "${PORT:-"${EXPOSE_PORT:-5000}"}"
--port "${PORT:-"${EXPOSE_PORT:-5000}"}" --debug
fi

14
whoogle.env Normal file
View File

@ -0,0 +1,14 @@
# You can set Whoogle environment variables here, but must set
# WHOOGLE_DOTENV=1 in your deployment to enable these values
#WHOOGLE_ALT_TW=nitter.net
#WHOOGLE_ALT_YT=invidious.snopyta.org
#WHOOGLE_ALT_IG=bibliogram.art/u
#WHOOGLE_ALT_RD=libredd.it
#WHOOGLE_USER=""
#WHOOGLE_PASS=""
#WHOOGLE_PROXY_USER=""
#WHOOGLE_PROXY_PASS=""
#WHOOGLE_PROXY_TYPE=""
#WHOOGLE_PROXY_LOC=""
#HTTPS_ONLY=1