Add option to disable changing of configuration

This commit is contained in:
notangelmario 2021-04-22 10:37:48 +03:00
parent d2fac809ca
commit 447a415e16
4 changed files with 136 additions and 125 deletions

View File

@ -75,6 +75,12 @@
"value": "", "value": "",
"required": false "required": false
}, },
"WHOOGLE_CONFIG_DISABLE_CHANGE": {
"description": "[CONFIG] Disable ability for client to change config (set to 1 or leave blank)",
"value": "",
"required": false
},
"WHOOGLE_CONFIG_DARK": { "WHOOGLE_CONFIG_DARK": {
"description": "[CONFIG] Enable dark mode (set to 1 or leave blank)", "description": "[CONFIG] Enable dark mode (set to 1 or leave blank)",
"value": "", "value": "",

View File

@ -129,6 +129,7 @@ def index():
logo=render_template( logo=render_template(
'logo.html', 'logo.html',
dark=g.user_config.dark), dark=g.user_config.dark),
config_disabled=os.getenv('WHOOGLE_CONFIG_DISABLE_CHANGE', ''),
config=g.user_config, config=g.user_config,
tor_available=int(os.environ.get('TOR_AVAILABLE')), tor_available=int(os.environ.get('TOR_AVAILABLE')),
version_number=app.config['VERSION_NUMBER']) version_number=app.config['VERSION_NUMBER'])
@ -237,39 +238,40 @@ def search():
@app.route('/config', methods=['GET', 'POST', 'PUT']) @app.route('/config', methods=['GET', 'POST', 'PUT'])
@auth_required @auth_required
def config(): def config():
if request.method == 'GET': if os.getenv('WHOOGLE_CONFIG_DISABLE_CHANGE', '') != '':
return json.dumps(g.user_config.__dict__) if request.method == 'GET':
elif request.method == 'PUT': return json.dumps(g.user_config.__dict__)
if 'name' in request.args: elif request.method == 'PUT':
config_pkl = os.path.join( if 'name' in request.args:
app.config['CONFIG_PATH'], config_pkl = os.path.join(
request.args.get('name'))
session['config'] = (pickle.load(open(config_pkl, 'rb'))
if os.path.exists(config_pkl)
else session['config'])
return json.dumps(session['config'])
else:
return json.dumps({})
else:
config_data = request.form.to_dict()
if 'url' not in config_data or not config_data['url']:
config_data['url'] = g.user_config.url
# Save config by name to allow a user to easily load later
if 'name' in request.args:
pickle.dump(
config_data,
open(os.path.join(
app.config['CONFIG_PATH'], app.config['CONFIG_PATH'],
request.args.get('name')), 'wb')) request.args.get('name'))
session['config'] = (pickle.load(open(config_pkl, 'rb'))
if os.path.exists(config_pkl)
else session['config'])
return json.dumps(session['config'])
else:
return json.dumps({})
else:
config_data = request.form.to_dict()
if 'url' not in config_data or not config_data['url']:
config_data['url'] = g.user_config.url
# Overwrite default config if user has cookies disabled # Save config by name to allow a user to easily load later
if g.cookies_disabled: if 'name' in request.args:
open(app.config['DEFAULT_CONFIG'], 'w').write( pickle.dump(
json.dumps(config_data, indent=4)) config_data,
open(os.path.join(
app.config['CONFIG_PATH'],
request.args.get('name')), 'wb'))
session['config'] = config_data # Overwrite default config if user has cookies disabled
return redirect(config_data['url']) if g.cookies_disabled:
open(app.config['DEFAULT_CONFIG'], 'w').write(
json.dumps(config_data, indent=4))
session['config'] = config_data
return redirect(config_data['url'])
@app.route('/url', methods=['GET']) @app.route('/url', methods=['GET'])

View File

@ -47,101 +47,103 @@
<input type="submit" id="search-submit" value="Search"> <input type="submit" id="search-submit" value="Search">
</div> </div>
</form> </form>
<br/> {% if config_disabled == '' %}
<button id="config-collapsible" class="collapsible">Configuration</button> <br/>
<div class="content"> <button id="config-collapsible" class="collapsible">Configuration</button>
<div class="config-fields"> <div class="content">
<form id="config-form" action="config" method="post"> <div class="config-fields">
<div class="config-div config-div-ctry"> <form id="config-form" action="config" method="post">
<label for="config-ctry">Filter Results by Country: </label> <div class="config-div config-div-ctry">
<select name="ctry" id="config-ctry"> <label for="config-ctry">Filter Results by Country: </label>
{% for ctry in countries %} <select name="ctry" id="config-ctry">
<option value="{{ ctry.value }}" {% for ctry in countries %}
{% if ctry.value in config.ctry %} <option value="{{ ctry.value }}"
selected {% if ctry.value in config.ctry %}
{% endif %}> selected
{{ ctry.name }} {% endif %}>
</option> {{ ctry.name }}
{% endfor %} </option>
</select> {% endfor %}
<div><span class="info-text"> — Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.</span></div> </select>
</div> <div><span class="info-text"> — Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.</span></div>
<div class="config-div config-div-lang"> </div>
<label for="config-lang-interface">Interface Language: </label> <div class="config-div config-div-lang">
<select name="lang_interface" id="config-lang-interface"> <label for="config-lang-interface">Interface Language: </label>
{% for lang in languages %} <select name="lang_interface" id="config-lang-interface">
<option value="{{ lang.value }}" {% for lang in languages %}
{% if lang.value in config.lang_interface %} <option value="{{ lang.value }}"
selected {% if lang.value in config.lang_interface %}
{% endif %}> selected
{{ lang.name }} {% endif %}>
</option> {{ lang.name }}
{% endfor %} </option>
</select> {% endfor %}
</div> </select>
<div class="config-div config-div-search-lang"> </div>
<label for="config-lang-search">Search Language: </label> <div class="config-div config-div-search-lang">
<select name="lang_search" id="config-lang-search"> <label for="config-lang-search">Search Language: </label>
{% for lang in languages %} <select name="lang_search" id="config-lang-search">
<option value="{{ lang.value }}" {% for lang in languages %}
{% if lang.value in config.lang_search %} <option value="{{ lang.value }}"
selected {% if lang.value in config.lang_search %}
{% endif %}> selected
{{ lang.name }} {% endif %}>
</option> {{ lang.name }}
{% endfor %} </option>
</select> {% endfor %}
</div> </select>
<div class="config-div config-div-near"> </div>
<label for="config-near">Near: </label> <div class="config-div config-div-near">
<input type="text" name="near" id="config-near" placeholder="City Name" value="{{ config.near }}"> <label for="config-near">Near: </label>
</div> <input type="text" name="near" id="config-near" placeholder="City Name" value="{{ config.near }}">
<div class="config-div config-div-nojs"> </div>
<label for="config-nojs">Show NoJS Links: </label> <div class="config-div config-div-nojs">
<input type="checkbox" name="nojs" id="config-nojs" {{ 'checked' if config.nojs else '' }}> <label for="config-nojs">Show NoJS Links: </label>
</div> <input type="checkbox" name="nojs" id="config-nojs" {{ 'checked' if config.nojs else '' }}>
<div class="config-div config-div-dark"> </div>
<label for="config-dark">Dark Mode: </label> <div class="config-div config-div-dark">
<input type="checkbox" name="dark" id="config-dark" {{ 'checked' if config.dark else '' }}> <label for="config-dark">Dark Mode: </label>
</div> <input type="checkbox" name="dark" id="config-dark" {{ 'checked' if config.dark else '' }}>
<div class="config-div config-div-safe"> </div>
<label for="config-safe">Safe Search: </label> <div class="config-div config-div-safe">
<input type="checkbox" name="safe" id="config-safe" {{ 'checked' if config.safe else '' }}> <label for="config-safe">Safe Search: </label>
</div> <input type="checkbox" name="safe" id="config-safe" {{ 'checked' if config.safe else '' }}>
<div class="config-div config-div-alts"> </div>
<label class="tooltip" for="config-alts">Replace Social Media Links: </label> <div class="config-div config-div-alts">
<input type="checkbox" name="alts" id="config-alts" {{ 'checked' if config.alts else '' }}> <label class="tooltip" for="config-alts">Replace Social Media Links: </label>
<div><span class="info-text"> — Replaces Twitter/YouTube/Instagram/Reddit links <input type="checkbox" name="alts" id="config-alts" {{ 'checked' if config.alts else '' }}>
with Nitter/Invidious/Bibliogram/Libreddit links.</span></div> <div><span class="info-text"> — Replaces Twitter/YouTube/Instagram/Reddit links
</div> with Nitter/Invidious/Bibliogram/Libreddit links.</span></div>
<div class="config-div config-div-new-tab"> </div>
<label for="config-new-tab">Open Links in New Tab: </label> <div class="config-div config-div-new-tab">
<input type="checkbox" name="new_tab" id="config-new-tab" {{ 'checked' if config.new_tab else '' }}> <label for="config-new-tab">Open Links in New Tab: </label>
</div> <input type="checkbox" name="new_tab" id="config-new-tab" {{ 'checked' if config.new_tab else '' }}>
<div class="config-div config-div-tor"> </div>
<label for="config-tor">Use Tor: {{ '' if tor_available else 'Unavailable' }}</label> <div class="config-div config-div-tor">
<input type="checkbox" name="tor" id="config-tor" {{ '' if tor_available else 'hidden' }} {{ 'checked' if config.tor else '' }}> <label for="config-tor">Use Tor: {{ '' if tor_available else 'Unavailable' }}</label>
</div> <input type="checkbox" name="tor" id="config-tor" {{ '' if tor_available else 'hidden' }} {{ 'checked' if config.tor else '' }}>
<div class="config-div config-div-get-only"> </div>
<label for="config-get-only">GET Requests Only: </label> <div class="config-div config-div-get-only">
<input type="checkbox" name="get_only" id="config-get-only" {{ 'checked' if config.get_only else '' }}> <label for="config-get-only">GET Requests Only: </label>
</div> <input type="checkbox" name="get_only" id="config-get-only" {{ 'checked' if config.get_only else '' }}>
<div class="config-div config-div-root-url"> </div>
<label for="config-url">Root URL: </label> <div class="config-div config-div-root-url">
<input type="text" name="url" id="config-url" value="{{ config.url }}"> <label for="config-url">Root URL: </label>
</div> <input type="text" name="url" id="config-url" value="{{ config.url }}">
<div class="config-div config-div-custom-css"> </div>
<label for="config-style">Custom CSS:</label> <div class="config-div config-div-custom-css">
<textarea name="style" id="config-style" value="">{{ config.style }}</textarea> <label for="config-style">Custom CSS:</label>
</div> <textarea name="style" id="config-style" value="">{{ config.style }}</textarea>
<div class="config-div"> </div>
<input type="submit" id="config-load" value="Load">&nbsp; <div class="config-div">
<input type="submit" id="config-submit" value="Apply">&nbsp; <input type="submit" id="config-load" value="Load">&nbsp;
<input type="submit" id="config-save" value="Save As..."> <input type="submit" id="config-submit" value="Apply">&nbsp;
</div> <input type="submit" id="config-save" value="Save As...">
</form> </div>
</div> </form>
</div> </div>
</div>
{% endif %}
</div> </div>
<footer> <footer>
<p style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};"> <p style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};">

View File

@ -15,6 +15,7 @@
#WHOOGLE_CONFIG_COUNTRY=countryUK # See app/static/settings/countries.json for values #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_LANGUAGE=lang_en # See app/static/settings/languages.json for values
#WHOOGLE_CONFIG_DISABLE_CHANGE=1 # Disables changing of config from client
#WHOOGLE_CONFIG_DARK=1 # Dark mode #WHOOGLE_CONFIG_DARK=1 # Dark mode
#WHOOGLE_CONFIG_SAFE=1 # Safe searches #WHOOGLE_CONFIG_SAFE=1 # Safe searches
#WHOOGLE_CONFIG_ALTS=1 # Use social media site alternatives #WHOOGLE_CONFIG_ALTS=1 # Use social media site alternatives