diff --git a/.env b/.env deleted file mode 100644 index ae93496..0000000 --- a/.env +++ /dev/null @@ -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 diff --git a/Dockerfile b/Dockerfile index 6d0f2d3..3e3854c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 95a9450..ee2b3cc 100644 --- a/README.md +++ b/README.md @@ -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= @@ -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. | diff --git a/app/__init__.py b/app/__init__.py index 9d965b2..23422c3 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 = [] diff --git a/app/utils/results.py b/app/utils/results.py index e7e847c..7db53ed 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 3f48604..f2e8797 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/requirements.txt b/requirements.txt index 80282f4..0e4cdf0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/run b/run index 4ace594..f4eac50 100755 --- a/run +++ b/run @@ -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 diff --git a/whoogle.env b/whoogle.env new file mode 100644 index 0000000..a817360 --- /dev/null +++ b/whoogle.env @@ -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