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:
parent
c570200b2f
commit
9d424a8959
6
README.md
Normal file
6
README.md
Normal 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.
|
16
config.yml
16
config.yml
@ -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
12
liteshort.ini
Normal 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
|
||||||
|
|
10
liteshort.py
10
liteshort.py
@ -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():
|
|||||||
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():
|
|||||||
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
13
liteshort.service
Normal 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
BIN
static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -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') }}">
|
||||||
|
Loading…
Reference in New Issue
Block a user