From 3c924afbca69e81e201d72cd457934687ec429b8 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 14 Aug 2017 21:05:01 -0400 Subject: [PATCH] configurable port plus support for SSL --- .gitignore | 4 +++- config-sample.ini | 9 +++++++-- generate-cert.sh | 16 ++++++++++++++++ run-debug.sh | 6 ++++++ run.sh | 2 +- src/app.py | 8 ++++++-- src/templates/login.html | 4 ++-- 7 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 generate-cert.sh create mode 100644 run-debug.sh diff --git a/.gitignore b/.gitignore index 837cfc101..e9f840267 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ npm-debug.log yarn-error.log app.pyc demo.ncdb -config.ini \ No newline at end of file +config.ini +cert.key +cert.crt \ No newline at end of file diff --git a/config-sample.ini b/config-sample.ini index 5648cafe6..bf2c544c5 100644 --- a/config-sample.ini +++ b/config-sample.ini @@ -1,8 +1,13 @@ +[Network] +port=5000 +certPath=cert.crt +certKeyPath=cert.key + [Login] # Enter below credentials with with which you want to authenticate to Notecase web app -username=adam +username=your_username # This is bcrypt password hash. You can use generate-password.py (in this directory) to hash your password -password-hash=$2b$12$4Ia5lYbbpOv3pxxdoDgjUeAJ9z4FhqyEhhX52ra78FH03wPGx8zGu +password-hash=$2b$12$FHT8keXp3BGTfzAV/VnrkuLpkwN8Vpj5iIh4RwCbHTNWYSBI9hGAK [Sync] sync-server-url=https://localhost:57201 diff --git a/generate-cert.sh b/generate-cert.sh new file mode 100644 index 000000000..770357edc --- /dev/null +++ b/generate-cert.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +openssl genrsa -des3 -out cert.key 2048 + +openssl req -new -key cert.key -out cert.csr + +# Remove passphrase from key +cp cert.key cert.key.org + +openssl rsa -in cert.key.org -out cert.key + +# Generate self signed certificate +openssl x509 -req -days 730 -in cert.csr -signkey cert.key -out cert.crt + +rm cert.key.org +rm cert.csr \ No newline at end of file diff --git a/run-debug.sh b/run-debug.sh new file mode 100644 index 000000000..1cf658d8e --- /dev/null +++ b/run-debug.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +export FLASK_DEBUG=0 +export FLASK_APP=src/app.py + +flask run \ No newline at end of file diff --git a/run.sh b/run.sh index 7a6afb26b..1cf658d8e 100644 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/bin/sh -export FLASK_DEBUG=1 +export FLASK_DEBUG=0 export FLASK_APP=src/app.py flask run \ No newline at end of file diff --git a/src/app.py b/src/app.py index a43ea78f5..f2c7e81f3 100644 --- a/src/app.py +++ b/src/app.py @@ -42,6 +42,10 @@ config.read('config.ini') user = User() user.id = config['Login']['username'] +port = config['Network']['port'] +certPath = config['Network']['certPath'] +certKeyPath = config['Network']['certKeyPath'] + hashedPassword = config['Login']['password-hash'].encode('utf-8') @app.route('/login', methods=['POST']) @@ -85,5 +89,5 @@ def load_user(user_id): api.add_resource(Notes, '/notes/') -if __name__ == '__main__': - app.run(host='0.0.0.0') \ No newline at end of file +if __name__ == "__main__": + app.run(host='0.0.0.0', port=port, ssl_context = (certPath, certKeyPath)) \ No newline at end of file diff --git a/src/templates/login.html b/src/templates/login.html index 724eab9d7..f5c8c8ab1 100644 --- a/src/templates/login.html +++ b/src/templates/login.html @@ -44,7 +44,7 @@ - - + + \ No newline at end of file