Commit 9d424a89 authored by 132ikl's avatar 132ikl
Browse files

Add WSGI components and README

parent c570200b
# liteshort
liteshort is a simple, configurable link shortener.
![liteshort screenshot](https://fs.ikl.sh/selif/4cgndb6e.png)
README coming soon.
# Username to make admin API requests # String: Username to make admin API requests
# Default: 'admin' # Default: 'admin'
admin_username: 'admin' admin_username: 'admin'
# Plaintext password to make admin API requests # String: Plaintext password to make admin API requests
# Safe to remove if admin_hashed_password is set # Safe to remove if admin_hashed_password is set
# Default: unset # Default: unset
#admin_password: #admin_password:
# Hashed password (bcrypt) to make admin API requests - Preferred over plaintext, use securepass.sh to generate # String: Hashed password (bcrypt) to make admin API requests - Preferred over plaintext, use securepass.sh to generate
# Please note that authentication takes noticeably longer than using plaintext password # Please note that authentication takes noticeably longer than using plaintext password
# Don't include the <username>: segment, just the hash # Don't include the <username>: segment, just the hash
# Default: unset (required to start application) # Default: unset (required to start application)
admin_hashed_password: '$2y$15$Dhll3IY42R.JNOYazarlG.8IndwMjxmHLpFsebJzcGTJd.gbsAwna' admin_hashed_password:
# Boolean: Disables API. If set to true, admin_password/admin_hashed_password do not need to be set.
# Default: false
disable_api: false
# String: Secret key used for cookies (used for storage of messages) # String: Secret key used for cookies (used for storage of messages)
# This should be a 12-16 character randomized string with letters, numbers, and symbols # This should be a 12-16 character randomized string with letters, numbers, and symbols
# Default: unset (required to start application) # Default: unset (required to start application)
secret_key: 'S$JI8L*&xua%gBoL' secret_key:
# String: Filename of the URL database without extension # String: Filename of the URL database without extension
# Default: 'urls' # Default: 'urls'
...@@ -45,4 +49,4 @@ site_url: ...@@ -45,4 +49,4 @@ site_url:
# Boolean: Show link to project repository on GitHub at bottom right corner of page # Boolean: Show link to project repository on GitHub at bottom right corner of page
# Default: true # Default: true
show_github_link: false show_github_link: true
\ No newline at end of file
[uwsgi]
module = wsgi:app
master = true
processes = 2
socket = liteshort.sock
chmod-socket = 660
vacuum = true
die-on-term = true
...@@ -21,12 +21,14 @@ def load_config(): ...@@ -21,12 +21,14 @@ def load_config():
req_options = {'admin_username': 'admin', 'database_name': "urls", 'random_length': 4, req_options = {'admin_username': 'admin', 'database_name': "urls", 'random_length': 4,
'allowed_chars': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', 'allowed_chars': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
'random_gen_timeout': 5, 'site_name': 'liteshort', 'site_url': None, 'show_github_link': True, 'random_gen_timeout': 5, 'site_name': 'liteshort', 'site_url': None, 'show_github_link': True,
'secret_key': None 'secret_key': None, 'disable_api': False
} }
config_types = {'admin_username': str, 'database_name': str, 'random_length': int, config_types = {'admin_username': str, 'database_name': str, 'random_length': int,
'allowed_chars': str, 'random_gen_timeout': int, 'site_name': str, 'allowed_chars': str, 'random_gen_timeout': int, 'site_name': str,
'site_url': (str, type(None)), 'show_github_link': bool, 'secret_key': str} 'site_url': (str, type(None)), 'show_github_link': bool, 'secret_key': str,
'disable_api': bool
}
for option in req_options.keys(): for option in req_options.keys():
if option not in new_config.keys(): # Make sure everything in req_options is set in config if option not in new_config.keys(): # Make sure everything in req_options is set in config
...@@ -42,7 +44,7 @@ def load_config(): ...@@ -42,7 +44,7 @@ def load_config():
matches = True matches = True
if not matches: if not matches:
raise TypeError(option + " is incorrect type") 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(): # Sets config value to see if bcrypt is required to check password
new_config['password_hashed'] = True new_config['password_hashed'] = True
elif 'admin_password' in new_config.keys(): elif 'admin_password' in new_config.keys():
...@@ -234,6 +236,8 @@ def main_post(): ...@@ -234,6 +236,8 @@ def main_post():
return response(request, (current_app.config['site_url'] or request.base_url) + short, return response(request, (current_app.config['site_url'] or request.base_url) + short,
'Error: Failed to generate') 'Error: Failed to generate')
elif 'api' in request.form: elif 'api' in request.form:
if current_app.config['disable_api']:
return response(request, None, "API is disabled.")
# All API calls require authentication # All API calls require authentication
if not request.authorization \ if not request.authorization \
or not authenticate(request.authorization['username'], request.authorization['password']): or not authenticate(request.authorization['username'], request.authorization['password']):
......
[Unit]
Description=uWSGI instance to serve liteshort
After=network.target
[Service]
User=
Group=www-data
WorkingDirectory=/path/to/install
Environment="PATH=/path/to/install/virtualenv/bin"
ExecStart=/path/to/install/virtualenv/bin/uwsgi --ini liteshort.ini
[Install]
WantedBy=multi-user.target
...@@ -9,6 +9,7 @@ A copy of the MIT license can be obtained at https://mit-license.org/ ...@@ -9,6 +9,7 @@ A copy of the MIT license can be obtained at https://mit-license.org/
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{ config.site_name }}</title> <title>{{ config.site_name }}</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css"> <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
......
from liteshort import app
if __name__ == "__main__":
app.run()
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