Commit 756ebdeb authored by 132ikl's avatar 132ikl
Browse files

Add redir_url config option and enforce admin password to start

parent e8a56524
......@@ -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
# 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
# Boolean: Show link to project repository on GitHub at bottom right corner of page
# Default: true
show_github_link: true
......@@ -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
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'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment