From 756ebdebd3b40c1f003d245a21252faf174383d6 Mon Sep 17 00:00:00 2001 From: 132ikl <132@ikl.sh> Date: Sun, 24 Feb 2019 21:14:51 -0500 Subject: [PATCH] Add redir_url config option and enforce admin password to start --- config.yml | 7 +++++++ liteshort.py | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index e295885..044ef58 100644 --- a/config.yml +++ b/config.yml @@ -44,9 +44,16 @@ site_name: 'liteshort' # String: URL shown when finished generating shortlinks. Include the / at the end. # If not set, it is automatically taken from the URL the shorten request is sent to. +# If you don't know, leave unset # Default: unset site_url: +# String: URL to redirect to when link not found. Useful if using a reverse proxy with a subdomain for liteshort +# If not set, it is automatically taken from the base URL +# If you don't know, leave unset +# Default: unset +redir_url: + # Boolean: Show link to project repository on GitHub at bottom right corner of page # Default: true show_github_link: true diff --git a/liteshort.py b/liteshort.py index 4c233e5..23fa89f 100644 --- a/liteshort.py +++ b/liteshort.py @@ -21,13 +21,13 @@ def load_config(): req_options = {'admin_username': 'admin', 'database_name': "urls", 'random_length': 4, 'allowed_chars': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', 'random_gen_timeout': 5, 'site_name': 'liteshort', 'site_url': None, 'show_github_link': True, - 'secret_key': None, 'disable_api': False + 'secret_key': None, 'disable_api': False, 'redir_url': None } config_types = {'admin_username': str, 'database_name': str, 'random_length': int, 'allowed_chars': str, 'random_gen_timeout': int, 'site_name': str, 'site_url': (str, type(None)), 'show_github_link': bool, 'secret_key': str, - 'disable_api': bool + 'disable_api': bool, 'redir_url': (str, type(None)) } for option in req_options.keys(): @@ -45,9 +45,9 @@ def load_config(): if not matches: raise TypeError(option + " is incorrect type") if not new_config['disable_api']: - if 'admin_hashed_password' in new_config.keys(): # Sets config value to see if bcrypt is required to check password + if 'admin_hashed_password' in new_config.keys() and new_config['admin_hashed_password']: new_config['password_hashed'] = True - elif 'admin_password' in new_config.keys(): + elif 'admin_password' in new_config.keys() and new_config['admin_password']: new_config['password_hashed'] = False else: raise TypeError('admin_password or admin_hashed_password must be set in config.yml') @@ -203,7 +203,8 @@ def main_redir(url): if long: return redirect(long, 301) flash('Short URL "' + url + '" doesn\'t exist', 'error') - return redirect(url_for('main')) + redirect_site = (current_app.config['redir_url'] or url_for('main')) + return redirect(redirect_site) @app.route('/', methods=['POST'])