From 447a415e168c0221bf190578434b4d12f1b99c13 Mon Sep 17 00:00:00 2001 From: notangelmario Date: Thu, 22 Apr 2021 10:37:48 +0300 Subject: [PATCH] Add option to disable changing of configuration --- app.json | 6 ++ app/routes.py | 62 +++++++------ app/templates/index.html | 192 ++++++++++++++++++++------------------- whoogle.env | 1 + 4 files changed, 136 insertions(+), 125 deletions(-) diff --git a/app.json b/app.json index eb80f95..e359d3c 100644 --- a/app.json +++ b/app.json @@ -75,6 +75,12 @@ "value": "", "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": { "description": "[CONFIG] Enable dark mode (set to 1 or leave blank)", "value": "", diff --git a/app/routes.py b/app/routes.py index ff915ca..13c3554 100644 --- a/app/routes.py +++ b/app/routes.py @@ -129,6 +129,7 @@ def index(): logo=render_template( 'logo.html', dark=g.user_config.dark), + config_disabled=os.getenv('WHOOGLE_CONFIG_DISABLE_CHANGE', ''), config=g.user_config, tor_available=int(os.environ.get('TOR_AVAILABLE')), version_number=app.config['VERSION_NUMBER']) @@ -237,39 +238,40 @@ def search(): @app.route('/config', methods=['GET', 'POST', 'PUT']) @auth_required def config(): - if request.method == 'GET': - return json.dumps(g.user_config.__dict__) - elif request.method == 'PUT': - if 'name' in request.args: - config_pkl = os.path.join( - app.config['CONFIG_PATH'], - 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( + if os.getenv('WHOOGLE_CONFIG_DISABLE_CHANGE', '') != '': + if request.method == 'GET': + return json.dumps(g.user_config.__dict__) + elif request.method == 'PUT': + if 'name' in request.args: + config_pkl = os.path.join( 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 - if g.cookies_disabled: - open(app.config['DEFAULT_CONFIG'], 'w').write( - json.dumps(config_data, indent=4)) + # 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'], + request.args.get('name')), 'wb')) - session['config'] = config_data - return redirect(config_data['url']) + # Overwrite default config if user has cookies disabled + 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']) diff --git a/app/templates/index.html b/app/templates/index.html index 336b159..4984544 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -47,101 +47,103 @@ -
- -
-
-
-
- - -
— Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
— Replaces Twitter/YouTube/Instagram/Reddit links - with Nitter/Invidious/Bibliogram/Libreddit links.
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-   -   - -
-
-
-
+ {% if config_disabled == '' %} +
+ +
+
+
+
+ + +
— Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
— Replaces Twitter/YouTube/Instagram/Reddit links + with Nitter/Invidious/Bibliogram/Libreddit links.
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+   +   + +
+
+
+
+ {% endif %}