Allow defining initial config state w/ env vars

This introduces a set of environment variables that can be used for
defining initial config state, to expedite the process of
destroying/relaunching instances quickly with the same settings every
time.

Closes #228

Closes #195
main
Ben Busby 2021-03-28 14:24:57 -04:00 committed by Ben Busby
parent c944f3cb06
commit 7b9ee37beb
4 changed files with 56 additions and 28 deletions

View File

@ -238,7 +238,7 @@ Depending on your preferences, you can also deploy the app yourself on your own
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. |
@ -253,6 +253,22 @@ There are a few optional environment variables available for customizing a Whoog
| WHOOGLE_ALT_IG | The instagram.com alternative to use when site alternatives are enabled in the config. |
| WHOOGLE_ALT_RD | The reddit.com alternative to use when site alternatives are enabled in the config. |
### Config Environment Variables
These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time.
| Variable | Description |
| ----------------------- | --------------------------------------------------------------- |
| WHOOGLE_CONFIG_COUNTRY | Filter results by hosting country |
| WHOOGLE_CONFIG_LANGUAGE | Set interface and search result language |
| WHOOGLE_CONFIG_DARK | Enable dark theme |
| WHOOGLE_CONFIG_SAFE | Enable safe searches |
| WHOOGLE_CONFIG_ALTS | Use social media site alternatives (nitter, invidious, etc) |
| WHOOGLE_CONFIG_TOR | Use Tor routing (if available) |
| WHOOGLE_CONFIG_NEW_TAB | Always open results in new tab |
| WHOOGLE_CONFIG_GET_ONLY | Search using GET requests only |
| WHOOGLE_CONFIG_URL | The root url of the instance (`https://<your url>/`) |
| WHOOGLE_CONFIG_STYLE | The custom CSS to use for styling (must be single line) |
## Usage
Same as most search engines, with the exception of filtering by time range.

View File

@ -5,20 +5,20 @@ import os
class Config:
def __init__(self, **kwargs):
app_config = current_app.config
self.url = ''
self.lang_search = ''
self.lang_interface = ''
self.url = os.getenv('WHOOGLE_CONFIG_URL', '')
self.lang_search = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '')
self.lang_interface = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '')
self.style = open(os.path.join(app_config['STATIC_FOLDER'],
'css/variables.css')).read()
self.ctry = ''
self.safe = False
self.dark = False
self.nojs = False
self.tor = False
self.near = ''
self.alts = False
self.new_tab = False
self.get_only = False
self.ctry = os.getenv('WHOOGLE_CONFIG_COUNTRY', '')
self.safe = bool(os.getenv('WHOOGLE_CONFIG_SAFE', False))
self.dark = bool(os.getenv('WHOOGLE_CONFIG_DARK', False))
self.alts = bool(os.getenv('WHOOGLE_CONFIG_ALTS', False))
self.nojs = bool(os.getenv('WHOOGLE_CONFIG_NOJS', False))
self.tor = bool(os.getenv('WHOOGLE_CONFIG_TOR', False))
self.near = os.getenv('WHOOGLE_CONFIG_NEAR', '')
self.new_tab = bool(os.getenv('WHOOGLE_CONFIG_NEW_TAB', False))
self.get_only = bool(os.getenv('WHOOGLE_CONFIG_GET_ONLY', False))
self.safe_keys = [
'lang_search',
'lang_interface',
@ -27,6 +27,8 @@ class Config:
]
for key, value in kwargs.items():
if not value:
continue
setattr(self, key, value)
def __getitem__(self, name):

View File

@ -54,8 +54,7 @@ def before_request_func():
# Generate session values for user if unavailable
if not valid_user_session(session):
session['config'] = json.load(open(app.config['DEFAULT_CONFIG'])) \
if os.path.exists(app.config['DEFAULT_CONFIG']) else {
'url': request.url_root}
if os.path.exists(app.config['DEFAULT_CONFIG']) else {}
session['uuid'] = str(uuid.uuid4())
session['fernet_keys'] = generate_user_keys(True)

View File

@ -12,3 +12,14 @@
#WHOOGLE_PROXY_TYPE=""
#WHOOGLE_PROXY_LOC=""
#HTTPS_ONLY=1
#WHOOGLE_CONFIG_COUNTRY=countryUK # See app/static/settings/countries.json for values
#WHOOGLE_CONFIG_LANGUAGE=lang_en # See app/static/settings/languages.json for values
#WHOOGLE_CONFIG_DARK=1 # Dark mode
#WHOOGLE_CONFIG_SAFE=1 # Safe searches
#WHOOGLE_CONFIG_ALTS=1 # Use social media site alternatives
#WHOOGLE_CONFIG_TOR=1 # Use Tor if available
#WHOOGLE_CONFIG_NEW_TAB=1 # Open results in new tab
#WHOOGLE_CONFIG_GET_ONLY=1 # Search using GET requests only
#WHOOGLE_CONFIG_URL=https://<whoogle url>/
#WHOOGLE_CONFIG_STYLE=":root { /* LIGHT THEME COLORS */ --whoogle-background: #d8dee9; --whoogle-accent: #2e3440; --whoogle-text: #3B4252; --whoogle-contrast-text: #eceff4; --whoogle-secondary-text: #70757a; --whoogle-result-bg: #fff; --whoogle-result-title: #4c566a; --whoogle-result-url: #81a1c1; --whoogle-result-visited: #a3be8c; /* DARK THEME COLORS */ --whoogle-dark-background: #222; --whoogle-dark-accent: #685e79; --whoogle-dark-text: #fff; --whoogle-dark-contrast-text: #000; --whoogle-dark-secondary-text: #bbb; --whoogle-dark-result-bg: #000; --whoogle-dark-result-title: #1967d2; --whoogle-dark-result-url: #4b11a8; --whoogle-dark-result-visited: #bbbbff; }"