From f28b501c7c14fe53e9373a2e16b8c50836aaaee3 Mon Sep 17 00:00:00 2001 From: ymage Date: Mon, 5 Nov 2018 01:17:16 +0100 Subject: [PATCH 1/4] Add missing Remember Me input name --- app/templates/login.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/login.html b/app/templates/login.html index 46ae8c0..1536092 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -72,7 +72,7 @@
From be96921864432921284cf3b88befe1dd0f544e93 Mon Sep 17 00:00:00 2001 From: Balint Csergo Date: Tue, 6 Nov 2018 14:56:55 +0100 Subject: [PATCH 2/4] support arbitrary db port, pdns_proto and pdns_port --- .env | 1 + config_template.py | 3 ++- configs/development.py | 4 ++-- docker-compose.yml | 1 + docker/PowerDNS-Admin/entrypoint.sh | 19 +++++++++++++------ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.env b/.env index 47a6291..fd12ecf 100644 --- a/.env +++ b/.env @@ -4,6 +4,7 @@ PDA_DB_HOST=powerdns-admin-mysql PDA_DB_NAME=powerdns_admin PDA_DB_USER=powerdns_admin PDA_DB_PASSWORD=changeme +PDA_DB_PORT=3306 PDNS_DB_HOST=pdns-mysql PDNS_DB_NAME=pdns diff --git a/config_template.py b/config_template.py index 2c34193..9d44b7b 100644 --- a/config_template.py +++ b/config_template.py @@ -22,11 +22,12 @@ UPLOAD_DIR = os.path.join(basedir, 'upload') SQLA_DB_USER = 'pda' SQLA_DB_PASSWORD = 'changeme' SQLA_DB_HOST = '127.0.0.1' +SQLA_DB_PORT = 3306 SQLA_DB_NAME = 'pda' SQLALCHEMY_TRACK_MODIFICATIONS = True # DATABASE - MySQL -SQLALCHEMY_DATABASE_URI = 'mysql://'+SQLA_DB_USER+':'+SQLA_DB_PASSWORD+'@'+SQLA_DB_HOST+'/'+SQLA_DB_NAME +SQLALCHEMY_DATABASE_URI = 'mysql://'+SQLA_DB_USER+':'+SQLA_DB_PASSWORD+'@'+SQLA_DB_HOST+':'+str(SQLA_DB_PORT)+'/'+SQLA_DB_NAME # DATABASE - SQLite # SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'pdns.db') diff --git a/configs/development.py b/configs/development.py index 48a3884..fd5d4d6 100644 --- a/configs/development.py +++ b/configs/development.py @@ -15,12 +15,12 @@ UPLOAD_DIR = os.path.join(basedir, 'upload') # DATABASE CONFIG FOR MYSQL DB_HOST = os.environ.get('PDA_DB_HOST') +DB_PORT = os.environ.get('PDA_DB_PORT', 3306 ) DB_NAME = os.environ.get('PDA_DB_NAME') DB_USER = os.environ.get('PDA_DB_USER') DB_PASSWORD = os.environ.get('PDA_DB_PASSWORD') - #MySQL -SQLALCHEMY_DATABASE_URI = 'mysql://'+DB_USER+':'+DB_PASSWORD+'@'+DB_HOST+'/'+DB_NAME +SQLALCHEMY_DATABASE_URI = 'mysql://'+DB_USER+':'+DB_PASSWORD+'@'+DB_HOST+':'+ str(DB_PORT) + '/'+DB_NAME SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository') SQLALCHEMY_TRACK_MODIFICATIONS = True diff --git a/docker-compose.yml b/docker-compose.yml index acb3822..25e4e10 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: - PDA_DB_NAME=${PDA_DB_NAME} - PDA_DB_USER=${PDA_DB_USER} - PDA_DB_PASSWORD=${PDA_DB_PASSWORD} + - PDA_DB_PORT=${PDA_DB_PORT} - PDNS_HOST=${PDNS_HOST} - PDNS_API_KEY=${PDNS_API_KEY} - FLASK_APP=/powerdns-admin/app/__init__.py diff --git a/docker/PowerDNS-Admin/entrypoint.sh b/docker/PowerDNS-Admin/entrypoint.sh index 098cdf7..228c463 100755 --- a/docker/PowerDNS-Admin/entrypoint.sh +++ b/docker/PowerDNS-Admin/entrypoint.sh @@ -1,6 +1,5 @@ #!/bin/bash -set -o nounset set -o errexit set -o pipefail @@ -8,13 +7,21 @@ set -o pipefail # == Vars # DB_MIGRATION_DIR='/powerdns-admin/migrations' +if [[ -z ${PDNS_PROTO} ]]; + then PDNS_PROTO="http" +fi + +if [[ -z ${PDNS_PORT} ]]; + then PDNS_PORT=8081 +fi + # Wait for us to be able to connect to MySQL before proceeding echo "===> Waiting for $PDA_DB_HOST MySQL service" until nc -zv \ $PDA_DB_HOST \ - 3306; + $PDA_DB_PORT; do echo "MySQL ($PDA_DB_HOST) is unavailable - sleeping" sleep 1 @@ -42,12 +49,12 @@ fi echo "===> Update PDNS API connection info" # initial setting if not available in the DB -mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} ${PDA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_url', 'http://${PDNS_HOST}:8081') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_url') LIMIT 1;" -mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} ${PDA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_key', '${PDNS_API_KEY}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_key') LIMIT 1;" +mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} -P${PDA_DB_PORT} ${PDA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_url', '${PDNS_PROTO}://${PDNS_HOST}:${PDNS_PORT}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_url') LIMIT 1;" +mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} -P${PDA_DB_PORT} ${PDA_DB_NAME} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_key', '${PDNS_API_KEY}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_key') LIMIT 1;" # update pdns api setting if .env is changed. -mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} ${PDA_DB_NAME} -e "UPDATE setting SET value='http://${PDNS_HOST}:8081' WHERE name='pdns_api_url';" -mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} ${PDA_DB_NAME} -e "UPDATE setting SET value='${PDNS_API_KEY}' WHERE name='pdns_api_key';" +mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} -P${PDA_DB_PORT} ${PDA_DB_NAME} -e "UPDATE setting SET value='${PDNS_PROTO}://${PDNS_HOST}:${PDNS_PORT}' WHERE name='pdns_api_url';" +mysql -h${PDA_DB_HOST} -u${PDA_DB_USER} -p${PDA_DB_PASSWORD} -P${PDA_DB_PORT} ${PDA_DB_NAME} -e "UPDATE setting SET value='${PDNS_API_KEY}' WHERE name='pdns_api_key';" echo "===> Assets management" echo "---> Running Yarn" From 6395d81916983b7e453676f9579b318049514d71 Mon Sep 17 00:00:00 2001 From: Robert Kerr Date: Mon, 12 Nov 2018 20:25:56 +0000 Subject: [PATCH 3/4] Fix typo Use -> User --- app/templates/admin_edituser.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/admin_edituser.html b/app/templates/admin_edituser.html index d374d22..114a592 100644 --- a/app/templates/admin_edituser.html +++ b/app/templates/admin_edituser.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% set active_page = "admin_users" %} -{% block title %}Edit Use - {{ SITE_NAME }}{% endblock %} +{% block title %}Edit User - {{ SITE_NAME }}{% endblock %} {% block dashboard_stat %} From c7d43ce5cc885aaeaed87797293cd769c8047c1f Mon Sep 17 00:00:00 2001 From: Robert Kerr Date: Sun, 18 Nov 2018 10:23:47 +0000 Subject: [PATCH 4/4] Fix for when TOTP starts with 0 PyOTP wants the token as a string, by passing it as an int leading 0s get stripped and verification fails --- app/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 8b2babc..7e87d08 100644 --- a/app/models.py +++ b/app/models.py @@ -90,7 +90,7 @@ class User(db.Model): def verify_totp(self, token): totp = pyotp.TOTP(self.otp_secret) - return totp.verify(int(token)) + return totp.verify(token) def get_hashed_password(self, plain_text_password=None): # Hash a password for the first time