From 657ee72ecbfffabbfb7527a623922f25f7b7ff01 Mon Sep 17 00:00:00 2001 From: 132ikl <132@ikl.sh> Date: Thu, 21 Feb 2019 15:59:21 -0500 Subject: [PATCH] Add basic Flask/Jinja setup and basic YAML config --- .gitignore | 3 +++ config.yml | 9 +++++++++ liteshort.py | 28 ++++++++++++++++++++++++++++ securepass.sh | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 config.yml create mode 100644 liteshort.py create mode 100755 securepass.sh diff --git a/.gitignore b/.gitignore index 894a44c..376f22a 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +# PyCharm +.idea diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..e17e371 --- /dev/null +++ b/config.yml @@ -0,0 +1,9 @@ +# Username to make admin API requests +admin_username: 'admin' + +# Plaintext password to make admin API requests +# Safe to remove if admin_hashed_password is set +#admin_password: 'password' + +# Hashed password (bcrypt) to make admin API requests - Preferred over plaintext, use securepass.sh to generate +admin_hashed_password: 'test' diff --git a/liteshort.py b/liteshort.py new file mode 100644 index 0000000..fdda238 --- /dev/null +++ b/liteshort.py @@ -0,0 +1,28 @@ +from flask import Flask +import yaml + + +def load_config(): + new_config = yaml.load(open("config.yml")) + if "admin_hashed_password" in new_config.keys(): + new_config["password"] = new_config["admin_hashed_password"] + elif "admin_password" in new_config.keys(): + new_config["password"] = new_config["admin_password"] + else: + raise Exception("admin_password or admin_hashed_password must be set in config.yml") + return new_config + + +config = load_config() +print(config["password"]) + +app = Flask(__name__) + + +@app.route('/') +def hello_world(): + return 'Hello World!' + + +if __name__ == '__main__': + app.run() diff --git a/securepass.sh b/securepass.sh new file mode 100755 index 0000000..bb6be66 --- /dev/null +++ b/securepass.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +## bcrypt passwd generator ## +############################# +CMD=$(which htpasswd 2>/dev/null) +OPTS="-nBC 15" + +read -p "Username: " USERNAME + +check_config() { + if [ -z $CMD ]; then + printf "Exiting: htpasswd is missing.\n" + exit 1 + fi + + if [ -z "$USERNAME" ]; then + usage + fi +} + +check_config $USERNAME +printf "Generating Bcrypt hash for username: $USERNAME\n\n" +$CMD $OPTS $USERNAME +exit $?