1
0
mirror of https://git.ikl.sh/132ikl/liteshort.git synced 2023-08-10 21:13:04 +03:00

Add WSGI components and README

This commit is contained in:
132ikl 2019-02-24 03:31:30 -05:00
parent c570200b2f
commit 9d424a8959
8 changed files with 60 additions and 15 deletions

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# liteshort
liteshort is a simple, configurable link shortener.
![liteshort screenshot](https://fs.ikl.sh/selif/4cgndb6e.png)
README coming soon.

View File

@ -1,22 +1,26 @@
# 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:
# 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

12
liteshort.ini Normal file
View File

@ -0,0 +1,12 @@
[uwsgi]
module = wsgi:app
master = true
processes = 2
socket = liteshort.sock
chmod-socket = 660
vacuum = true
die-on-term = true

View File

@ -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,13 +44,13 @@ 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():
new_config['password_hashed'] = False new_config['password_hashed'] = False
else: else:
raise TypeError('admin_password or admin_hashed_password must be set in config.yml') raise TypeError('admin_password or admin_hashed_password must be set in config.yml')
return new_config return new_config
@ -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']):

13
liteshort.service Normal file
View File

@ -0,0 +1,13 @@
[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

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -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') }}">

5
wsgi.py Normal file
View File

@ -0,0 +1,5 @@
from liteshort import app
if __name__ == "__main__":
app.run()