diff --git a/.gitignore b/.gitignore index b783f8b..fde1ef4 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ venv.bak/ # Databases *.db + +# Configuration files +config.yml diff --git a/LICENSE b/LICENSE index 46908db..77ba444 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2019 Steven Spangler +Copyright 2019 Steven Spangler, Kevin Alberts, I.C.T.S.V. Inter-Actief Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/config.default.yml b/config.default.yml new file mode 100644 index 0000000..c2acbff --- /dev/null +++ b/config.default.yml @@ -0,0 +1,69 @@ +# String: Username to make admin API requests +# Default: 'admin' +admin_username: 'admin' + +# String: Plaintext password to make admin API requests +# Safe to remove if admin_hashed_password is set +# Default: unset +#admin_password: + +# 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 +# Don't include the : segment, just the hash +# Default: unset (required to start application) +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) +# This should be a 12-16 character randomized string with letters, numbers, and symbols +# Default: unset (required to start application) +secret_key: '' + +# String: Filename of the URL database without extension +# Default: 'urls' +database_name: 'urls' + +# Integer: Length of random short URLs by default +# Default: 4 +random_length: 5 + +# String: Allowed URL characters +# Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ +allowed_chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_©®‍‼⁉⃣™ℹ↔↕↖↗↘↙↩↪⌚⌛⌨⏏⏩⏪⏫⏬⏭⏮⏯⏰⏱⏲⏳⏸⏹⏺Ⓜ▪▫▶◀◻◼◽◾☀☁☂☃☄☎☑☔☕☘☝☠☢☣☦☪☮☯☸☹☺♀♂♈♉♊♋♌♍♎♏♐♑♒♓♟♠♣♥♦♨♻♾♿⚒⚓⚔⚕⚖⚗⚙⚛⚜⚠⚡⚪⚫⚰⚱⚽⚾⛄⛅⛈⛎⛏⛑⛓⛔⛩⛪⛰⛱⛲⛳⛴⛵⛷⛸⛹⛺⛽✂✅✈✉✊✋✌✍✏✒✔✖✝✡✨✳✴❄❇❌❎❓❔❕❗❣❤➕➖➗➡➰➿⤴⤵⬅⬆⬇⬛⬜⭐⭕〰〽㊗㊙️🀄🃏🅰🅱🅾🅿🆎🆑🆒🆓🆔🆕🆖🆗🆘🆙🆚🇦🇧🇨🇩🇪🇫🇬🇭🇮🇯🇰🇱🇲🇳🇴🇵🇶🇷🇸🇹🇺🇻🇼🇽🇾🇿🈁🈂🈚🈯🈲🈳🈴🈵🈶🈷🈸🈹🈺🉐🉑🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟🌠🌡🌤🌥🌦🌧🌨🌩🌪🌫🌬🌭🌮🌯🌰🌱🌲🌳🌴🌵🌶🌷🌸🌹🌺🌻🌼🌽🌾🌿🍀🍁🍂🍃🍄🍅🍆🍇🍈🍉🍊🍋🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕🍖🍗🍘🍙🍚🍛🍜🍝🍞🍟🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯🍰🍱🍲🍳🍴🍵🍶🍷🍸🍹🍺🍻🍼🍽🍾🍿🎀🎁🎂🎄🎅🎆🎇🎈🎉🎊🎋🎌🎍🎎🎏🎐🎑🎒🎓🎖🎗🎙🎚🎛🎞🎟🎠🎡🎢🎣🎤🎥🎦🎧🎨🎩🎪🎫🎬🎭🎮🎯🎰🎱🎲🎳🎴🎵🎶🎷🎸🎹🎺🎻🎼🎽🎾🎿🏀🏁🏂🏃🏄🏅🏆🏇🏈🏉🏊🏋🏌🏍🏎🏏🏐🏑🏒🏓🏔🏕🏖🏗🏘🏙🏚🏛🏜🏝🏞🏟🏠🏡🏢🏣🏤🏥🏦🏧🏨🏩🏪🏫🏬🏭🏮🏯🏰🏳🏴🏵🏷🏸🏹🏺🏻🏼🏽🏾🏿🐀🐁🐂🐃🐄🐅🐆🐇🐈🐉🐊🐋🐌🐍🐎🐏🐐🐑🐒🐓🐔🐕🐖🐗🐘🐙🐚🐛🐜🐝🐞🐟🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐪🐫🐬🐭🐮🐯🐰🐱🐲🐳🐴🐵🐶🐷🐸🐹🐺🐻🐼🐽🐾🐿👀👁👂👃👄👅👆👇👈👉👊👋👌👍👎👏👐👑👒👓👔👕👖👗👘👙👚👛👜👝👞👟👠👡👢👣👤👥👦👧👨👩👪👫👬👭👮👯👰👱👲👳👴👵👶👷👸👹👺👻👼👽👿💀💁💂💃💄💅💆💇💈💉💊💋💌💍💎💏💐💑💒💓💔💕💖💗💘💙💚💛💜💝💞💟💠💡💢💣💤💥💦💧💨💩💪💫💬💭💮💯💰💱💲💳💴💵💶💷💸💹💺💻💼💽💾💿📀📁📂📃📄📅📆📇📈📉📊📋📌📍📎📏📐📑📒📓📔📕📖📗📘📙📚📛📜📝📞📟📠📡📢📣📤📥📦📧📨📩📪📫📬📭📮📯📰📱📲📳📴📵📶📷📸📹📺📻📼📽📿🔀🔁🔂🔃🔄🔅🔆🔇🔈🔉🔊🔋🔌🔍🔎🔏🔐🔑🔒🔓🔔🔕🔖🔗🔘🔙🔚🔛🔜🔝🔞🔟🔠🔡🔢🔣🔤🔥🔦🔧🔨🔩🔪🔫🔬🔭🔮🔯🔰🔱🔲🔳🔴🔵🔶🔷🔸🔹🔺🔻🔼🔽🕉🕊🕋🕌🕍🕎🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧🕯🕰🕳🕴🕵🕶🕷🕸🕹🕺🖇🖊🖋🖌🖍🖐🖕🖖🖤🖥🖨🖱🖲🖼🗂🗃🗄🗑🗒🗓🗜🗝🗞🗡🗣🗨🗯🗳🗺🗻🗼🗽🗾🗿😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿🙀🙁🙂🙃🙄🙅🙆🙇🙈🙉🙊🙋🙌🙍🙎🙏🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟🚠🚡🚢🚣🚤🚥🚦🚧🚨🚩🚪🚫🚬🚭🚮🚯🚰🚱🚲🚳🚴🚵🚶🚷🚸🚹🚺🚻🚼🚽🚾🚿🛀🛁🛂🛃🛄🛅🛋🛌🛍🛎🛏🛐🛑🛒🛠🛡🛢🛣🛤🛥🛩🛫🛬🛰🛳🛴🛵🛶🛷🛸🛹🤐🤑🤒🤓🤔🤕🤖🤗🤘🤙🤚🤛🤜🤝🤞🤟🤠🤡🤢🤣🤤🤥🤦🤧🤨🤩🤪🤫🤬🤭🤮🤯🤰🤱🤲🤳🤴🤵🤶🤷🤸🤹🤺🤼🤽🤾🥀🥁🥂🥃🥄🥅🥇🥈🥉🥊🥋🥌🥍🥎🥏🥐🥑🥒🥓🥔🥕🥖🥗🥘🥙🥚🥛🥜🥝🥞🥟🥠🥡🥢🥣🥤🥥🥦🥧🥨🥩🥪🥫🥬🥭🥮🥯🥰🥳🥴🥵🥶🥺🥼🥽🥾🥿🦀🦁🦂🦃🦄🦅🦆🦇🦈🦉🦊🦋🦌🦍🦎🦏🦐🦑🦒🦓🦔🦕🦖🦗🦘🦙🦚🦛🦜🦝🦞🦟🦠🦡🦢🦰🦱🦲🦳🦴🦵🦶🦷🦸🦹🧀🧁🧂🧐🧑🧒🧓🧔🧕🧖🧗🧘🧙🧚🧛🧜🧝🧞🧟🧠🧡🧢🧣🧤🧥🧦🧧🧨🧩🧪🧫🧬🧭🧮🧯🧰🧱🧲🧳🧴🧵🧶🧷🧸🧹🧺🧻🧼🧽🧾🧿󠁢󠁣󠁥󠁧󠁬󠁮󠁳󠁴󠁷󠁿' + + +# Amount of time in seconds to spend generating random short URLs until timeout +# Default: 5 +random_gen_timeout: 5 + +# String: Name shown on tab while on site and on page header +# Default: 'liteshort' +site_name: 'I.C.T.S.V. Inter-/Actief/ URL Shortener' + +# String: Domain where the shortlinks will be served from. Useful if using the web interface on a subdomain. +# 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_domain: + +# String: Subdomain to host the web interface on. +# Useful if you want the shorturls on the short domain but the web interface on a subdomain. +# If you don't know, leave unset +# Default: unset +subdomain: + +# String: URL which takes you to the most recent short URL's destination +# Short URLs cannot be created with this string if set +# Default: l +latest: 'l' + +# Boolean: Show link to project repository on GitHub at bottom right corner of page +# Default: true +show_github_link: false + +# Integer: How many items to show per page in the admin interface +# Default: 20 +admin_links_per_page: 20 diff --git a/config.yml b/config.yml deleted file mode 100644 index 4abcb47..0000000 --- a/config.yml +++ /dev/null @@ -1,59 +0,0 @@ -# String: Username to make admin API requests -# Default: 'admin' -admin_username: 'admin' - -# String: Plaintext password to make admin API requests -# Safe to remove if admin_hashed_password is set -# Default: unset -#admin_password: - -# 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 -# Don't include the : segment, just the hash -# Default: unset (required to start application) -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) -# This should be a 12-16 character randomized string with letters, numbers, and symbols -# Default: unset (required to start application) -secret_key: - -# String: Filename of the URL database without extension -# Default: 'urls' -database_name: 'urls' - -# Integer: Length of random short URLs by default -# Default: 4 -random_length: 4 - -# String: Allowed URL characters -# Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ -allowed_chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_' - -# Amount of time in seconds to spend generating random short URLs until timeout -# Default: 5 -random_gen_timeout: 5 - -# String: Name shown on tab while on site and on page header -# Default: 'liteshort' -site_name: 'liteshort' - -# String: Domain where the shortlinks will be served from. Useful if using the web interface on a subdomain. -# 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_domain: - -# String: Subdomain to host the web interface on. -# Useful if you want the shorturls on the short domain but the web interface on a subdomain. -# If you don't know, leave unset -# Default: unset -subdomain: - -# 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 865da3a..833350d 100644 --- a/liteshort.py +++ b/liteshort.py @@ -1,9 +1,10 @@ -# Copyright (c) 2019 Steven Spangler <132@ikl.sh> +# Copyright (c) 2019 Steven Spangler <132@ikl.sh>, Kevin Alberts # This file is part of liteshort by 132ikl # This software is license under the MIT license. It should be included in your copy of this software. # A copy of the MIT license can be obtained at https://mit-license.org/ -from flask import Flask, current_app, flash, g, jsonify, redirect, render_template, request, send_from_directory, url_for +from flask import Flask, current_app, flash, g, jsonify, make_response, redirect, render_template, request, \ + send_from_directory, url_for, session import bcrypt import os import random @@ -22,13 +23,14 @@ 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_domain': None, 'show_github_link': True, - 'secret_key': None, 'disable_api': False, 'subdomain': '' + 'secret_key': None, 'disable_api': False, 'subdomain': '', 'latest': 'l', 'admin_links_per_page': 20 } config_types = {'admin_username': str, 'database_name': str, 'random_length': int, 'allowed_chars': str, 'random_gen_timeout': int, 'site_name': str, 'site_domain': (str, type(None)), 'show_github_link': bool, 'secret_key': str, - 'disable_api': bool, 'subdomain': (str, type(None)) + 'disable_api': bool, 'subdomain': (str, type(None)), 'latest': (str, type(None)), + 'admin_links_per_page': int } for option in req_options.keys(): @@ -62,7 +64,7 @@ def authenticate(username, password): def check_long_exist(long): query = query_db('SELECT short FROM urls WHERE long = ?', (long,)) for i in query: - if i and (len(i['short']) <= current_app.config["random_length"]): # Checks if query if pre-existing URL is same as random length URL + if i and (len(i['short']) <= current_app.config["random_length"]) and i['short'] != current_app.config['latest']: # Checks if query if pre-existing URL is same as random length URL return i['short'] return False @@ -103,7 +105,7 @@ def generate_short(rq): return response(rq, None, 'Timeout while generating random short URL') short = ''.join(random.choice(current_app.config['allowed_chars']) for i in range(current_app.config['random_length'])) - if not check_short_exist(short): + if not check_short_exist(short) and short != app.config['latest']: return short @@ -114,16 +116,44 @@ def get_long(short): return None +def get_baseUrl(): + if current_app.config['site_domain']: + # TODO: un-hack-ify adding the protocol here + return 'https://' + current_app.config['site_domain'] + '/' + else: + return request.base_url + + def list_shortlinks(): result = query_db('SELECT * FROM urls', (), False, None) result = nested_list_to_dict(result) return result +def list_shortlinks_page(page, limit=50): + assert page >= 1 + assert type(page) == int + assert type(limit) == int + start_index = (page - 1) * limit + result = query_db('SELECT * FROM urls ORDER BY short LIMIT ? OFFSET ?', (limit, start_index), False, None) + result = nested_list_to_dict(result) + return result + + +def get_num_pages(limit=50): + assert type(limit) == int + result = query_db('SELECT COUNT(*) FROM urls', (), False, None) + items = result[0][0] + page_count = result[0][0] // limit + if page_count * limit < items: + page_count += 1 + return page_count, items + + def nested_list_to_dict(l): d = {} for nl in l: - d[nl[0]] = nl[1] + d[nl[0]] = nl[1] return d @@ -143,14 +173,25 @@ def response(rq, result, error_msg="Error: Unknown error"): else: if result and result is not True: flash(result, 'success') - return render_template("main.html") elif not result: flash(error_msg, 'error') - return render_template("main.html") return render_template("main.html") +def set_latest(long): + if app.config['latest']: + if query_db('SELECT short FROM urls WHERE short = ?', (current_app.config['latest'],)): + get_db().cursor().execute("UPDATE urls SET long = ? WHERE short = ?", + (long, current_app.config['latest'])) + else: + get_db().cursor().execute("INSERT INTO urls (long,short) VALUES (?, ?)", + (long, current_app.config['latest'])) + + def validate_short(short): + if short == app.config['latest']: + return response(request, None, + 'Short URL cannot be the same as a special URL ({})'.format(short)) for char in short: if char not in current_app.config['allowed_chars']: return response(request, None, @@ -209,10 +250,12 @@ def main(): def main_redir(url): long = get_long(url) if long: - return redirect(long, 301) - flash('Short URL "' + url + '" doesn\'t exist', 'error') - redirect_site = url_for('main') - return redirect(redirect_site) + resp = make_response(redirect(long, 301)) + else: + flash('Short URL "' + url + '" doesn\'t exist', 'error') + resp = make_response(redirect(url_for('main'))) + resp.headers.set('Cache-Control', 'no-store, must-revalidate') + return resp @app.route('/', methods=['POST'], subdomain=app.config['subdomain']) @@ -228,7 +271,7 @@ def main_post(): else: return result if get_long(short) == request.form['long']: - return response(request, (('https://' + app.config['site_domain'] + '/') or request.base_url) + short, + return response(request, get_baseUrl() + short, 'Error: Failed to return pre-existing non-random shortlink') else: short = generate_short(request) @@ -237,12 +280,15 @@ def main_post(): 'Short URL already taken') long_exists = check_long_exist(request.form['long']) if long_exists and not request.form.get('short'): - # TODO: un-hack-ify adding the protocol here - return response(request, (('https://' + app.config['site_domain'] + '/') or request.base_url) + long_exists, + set_latest(request.form['long']) + get_db().commit() + return response(request, get_baseUrl() + long_exists, 'Error: Failed to return pre-existing random shortlink') get_db().cursor().execute('INSERT INTO urls (long,short) VALUES (?,?)', (request.form['long'], short)) + set_latest(request.form['long']) get_db().commit() - return response(request, (('https://' + app.config['site_domain'] + '/') or request.base_url) + short, + + return response(request, get_baseUrl() + short, 'Error: Failed to generate') elif request.form.get('api'): if current_app.config['disable_api']: @@ -276,5 +322,58 @@ def main_post(): return response(request, None, 'Long URL required') +@app.route('/login', methods=['POST']) +def login(): + if 'admin_hashed_password' not in app.config or app.config['admin_hashed_password'] is None: + raise AssertionError("Login is disabled.") + + if authenticate(request.form['username'], request.form['password']): + session['logged_in'] = True + else: + flash('Wrong password!', 'error') + return make_response(redirect(url_for('admin'))) + + +@app.route('/logout') +def logout(): + if 'logged_in' in session and session['logged_in']: + session['logged_in'] = False + return make_response(redirect(url_for('admin'))) + + +@app.route('/delete/') +def delete(short): + if 'logged_in' in session and session['logged_in']: + success = delete_url(short) + if success: + flash("Link '/{}' deleted.".format(short), "success") + else: + flash("Failed to delete URL.".format(short), "error") + page = request.args.get('page', '1') + return make_response(redirect(url_for('admin')+"?page="+page)) + else: + return make_response(redirect(url_for('admin'))) + + +@app.route('/admin') +def admin(): + if 'logged_in' in session and session['logged_in']: + page_count, num_items = get_num_pages(app.config['admin_links_per_page']) + page = request.args.get('page', '1') + try: + page = int(page) + if page > page_count: + return make_response(redirect(url_for('admin')+"?page="+str(page_count))) + if page < 1: + return make_response(redirect(url_for('admin')+"?page=1")) + except ValueError: + page = 1 + + urls = list_shortlinks_page(page, app.config['admin_links_per_page']) + return render_template('admin.html', urls=urls, page=page, page_count=page_count, num_items=num_items) + else: + return render_template('login.html') + + if __name__ == '__main__': app.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..51d54a8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +bcrypt +flask +pyyaml diff --git a/static/admin.css b/static/admin.css new file mode 100644 index 0000000..7330810 --- /dev/null +++ b/static/admin.css @@ -0,0 +1,74 @@ +/* +Copyright (c) 2019 Kevin Alberts +This software is license under the MIT license. It should be included in your copy of this software. +A copy of the MIT license can be obtained at https://mit-license.org/ +*/ +.paginator-link { + display: inline-block; + padding: 8px; + margin: 2px; + background: #1D428A; + border: 1px solid #1D428A; + color: white; +} + +.paginator-link { + text-decoration: none; +} + +.paginator-link:hover { + border: 1px solid #1D428A; + color: white; + background: #2450A8; +} + +.paginator-current { + display: inline-block; + padding: 8px; + margin: 2px; + border: 1px solid #1D428A; + background: white; + color: #1D428A; +} + +#box-title .small { + font-size: 2rem +} + +#content_admin { + width: 1200px; +} + +#link-table { + border-collapse: separate; + border-spacing: 0; + margin-top: 1rem; + margin-bottom: 2rem; +} + +#link-table .link-table-header { + background-color: #1D428A; + color: white; +} + +#link-table .link-table-center { + text-align: center; +} + +#link-table tr:hover { + background-color: rgba(0, 0, 0, 0.1); +} +#link-table tr.link-table-header:hover { + background-color: #1D428A; + color: white; +} + +#link-table .link-table-header th { + text-align: left; + font-size: 1.1rem; + padding: 0.5rem 1rem; +} + +#link-table th, #link-table td { + padding: 0.2rem 1rem; +} diff --git a/static/favicon.ico b/static/favicon.ico index 4d8381c..d1f8f7f 100644 Binary files a/static/favicon.ico and b/static/favicon.ico differ diff --git a/static/ia-logo.svg b/static/ia-logo.svg new file mode 100644 index 0000000..f3d2274 --- /dev/null +++ b/static/ia-logo.svg @@ -0,0 +1,3 @@ + + +image/svg+xml \ No newline at end of file diff --git a/static/ia.css b/static/ia.css new file mode 100644 index 0000000..188e5ef --- /dev/null +++ b/static/ia.css @@ -0,0 +1,231 @@ +/* +Copyright (c) 2019 Kevin Alberts +This software is license under the MIT license. It should be included in your copy of this software. +A copy of the MIT license can be obtained at https://mit-license.org/ +*/ +body{ + margin: 0 0 2rem; + background-color: #f4f4f4; + font-family: Open Sans, Arial, sans-serif; +} + +#top{ + background-color: #1D428A; + width: 100%; + display: flex; + justify-content: center; +} + +#header { + height: 6rem; + display: flex; + align-items: center; +} + +#logo img { + height: 3rem; +} + +#logo { + margin-right: 1rem; + align-items: center; +} + +#title { + color: white; + text-decoration: none; + font-family: "Humanst521 BT", "Open Sans", sans-serif; + font-size: 2.75rem; + line-height: 2.75rem; +} + +#title a { + color: white; + text-decoration: none; +} + +#middle { + width: 100%; + display: flex; + justify-content: center; +} + +#content { + min-height: 100px; + min-width: 200px; + margin: 1rem; + width: 600px; +} + +#box { + padding: 1rem; +} + +#box .form { + margin-bottom: 1rem; +} + +#box-title { + margin: 0 0 0.5rem 0; + font-family: "Humanst521 BT", "Open Sans", sans-serif; + font-size: 2.5rem; + font-weight: normal; +} + +.drop-shadow { + filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.5)); +} + +#long-url-box{ + display: flex; + align-items: stretch; +} + +#long-url-box .prepend { + background-color: #1D428A; + color: white; + font-family: "Humanst521 BT", "Open Sans", sans-serif; + font-size: 2rem; + font-weight: bold; + display: block; + padding: 0.5rem; + text-align: center; + z-index: 1; + + margin-top: 1rem; + margin-bottom: 1rem; +} + +#long-url { + width: 1%; + min-width: 40px; + flex: 1 1 auto; + font-size: 1.75rem; + color: black; + position: relative; + border: none; + padding: 0.5rem; + + margin-top: 1rem; + margin-bottom: 1rem; + + border-top: 1px solid rgba(0, 0, 0, 0.5); + border-bottom: 1px solid rgba(0, 0, 0, 0.5); +} + +#username, #password { + /*width: 1%;*/ + min-width: 40px; + flex: 1 1 auto; + font-size: 1.75rem; + color: black; + position: relative; + padding: 0.5rem; + + margin-top: 1rem; + margin-bottom: 1rem; + + border: 1px solid rgba(0, 0, 0, 0.5); +} + +#submit { + background-color: #077821; + color: white; + border: none; + font-size: 2rem; + cursor: pointer; + font-weight: normal; + padding: 0.5rem; + font-family: "Humanst521 BT", "Open Sans", sans-serif; + + margin-top: 1rem; + margin-bottom: 1rem; +} + +#submit:hover { + background-color: #099A2B; +} + +#custom-link-box .optional { + font-size: 1.25rem; + margin-top: 0.5em; + margin-bottom: 0.5rem; +} + +#custom-label { + display: flex; + align-items: stretch; +} + +#custom-label .url { + float: left; + background-color: #1D428A; + color: white; + + + font-family: "Humanst521 BT", "Open Sans", sans-serif; + font-size: 1.5rem; + font-weight: normal; + display: block; + padding: 0.5rem; + text-align: center; + z-index: 1; +} + +#custom-link { + width: 1%; + min-width: 40px; + flex: 1 1 auto; + font-size: 1.5rem; + color: black; + position: relative; + border: none; + padding: 0.5rem; + + border-top: 1px solid rgba(0, 0, 0, 0.5); + border-bottom: 1px solid rgba(0, 0, 0, 0.5); + border-right: 1px solid rgba(0, 0, 0, 0.5); +} + +.success { + color: #077821; + font-size: 1.25rem; +} + +.error { + color: #B8231F; + font-size: 1.25rem; +} + +.success span { + display: block; +} + +.success a { + color: #153065; + text-decoration: none; + font-family: monospace; + font-size: 1.25rem; + display: block; + + margin-top: 0.25rem; + padding: 0.25rem; + border: 1px solid rgba(0, 0, 0, 0.5); + background-color: white; + text-align: center; +} + +.success a:hover { + color: #2450A8; + text-decoration: underline; +} + +#copyright { + margin-top: 2rem; + font-size: 0.9rem; +} + +#copyright span { + text-align: center; + display: block; +} diff --git a/static/ictsv-logo-white.svg b/static/ictsv-logo-white.svg new file mode 100644 index 0000000..a4c1db7 --- /dev/null +++ b/static/ictsv-logo-white.svg @@ -0,0 +1,192 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/static/ictsv-logo.svg b/static/ictsv-logo.svg new file mode 100644 index 0000000..d1447bb --- /dev/null +++ b/static/ictsv-logo.svg @@ -0,0 +1,189 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/static/styles.css b/static/styles.css index 25ebdef..498bfe2 100644 --- a/static/styles.css +++ b/static/styles.css @@ -1,5 +1,5 @@ /* -Copyright (c) 2019 Steven Spangler <132@ikl.sh> +Copyright (c) 2019 Steven Spangler <132@ikl.sh>, Kevin Alberts This file is part of liteshort by 132ikl This software is license under the MIT license. It should be included in your copy of this software. A copy of the MIT license can be obtained at https://mit-license.org/ @@ -67,4 +67,4 @@ div.github { div.github:hover { opacity: 1; -} \ No newline at end of file +} diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..b223f97 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,100 @@ + + + + + + URL Admin - {{ config.site_name }} + + + + + + + +
+
+
+
+

URL Admin (Logout)

+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} + {% if category == 'success' %} +
+ ✓ {{ message }} +
+ {% elif category == 'error' %} +
+ ✖ {{ message }} +
+ {% endif %} + {% endfor %} + {% endif %} + {% endwith %} + +

There are {{ num_items }} links in the database.

+ +
+ {% for i in range(1, page_count + 1) %} + {% if i == page %} + {{ i }} + {% else %} + {{ i }} + {% endif %} + {% endfor %} +
+ + + + + + + + {% for long, short in urls.items() %} + + + + + + {% else %} + + + + {% endfor %} + + +
+ {% for i in range(1, page_count + 1) %} + {% if i == page %} + {{ i }} + {% else %} + {{ i }} + {% endif %} + {% endfor %} +
+
+
+
+ + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..ef75138 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,67 @@ + + + + + + Admin Login - {{ config.site_name }} + + + + + + +
+
+
+
+
+

Admin Login

+
+
+ +
+
+ +
+ +
+
+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} + {% if category == 'success' %} +
+ ✓ {{ message }} +
+ {% elif category == 'error' %} +
+ ✖ {{ message }} +
+ {% endif %} + {% endfor %} + {% endif %} + {% endwith %} +
+
+
+ + diff --git a/templates/main.html b/templates/main.html index 5ae9901..210ccce 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,5 +1,5 @@