From 937620e86ca2f5e4d1ca632d61a1bd4b5315d796 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:13:24 +1000 Subject: [PATCH 01/19] main: Initial stripe test --- master/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/master/main.py b/master/main.py index edbca2b..8072c5b 100644 --- a/master/main.py +++ b/master/main.py @@ -232,6 +232,26 @@ def tlsa(): return resp.json() + +@app.route('stripe', methods=['POST']) +def stripe(): + # Get API header + api_key = request.headers.get('key') + if api_key == None: + return jsonify({'error': 'Invalid API key', 'success': 'false'}) + if api_key != os.getenv('STRIPE_KEY'): + return jsonify({'error': 'Invalid API key', 'success': 'false'}) + + # Log all requests + print(request.json) + # Log for docker + print(request.json, flush=True) + + return jsonify({'success': 'true'}) + + + + def get_sites_count(): # If file doesn't exist, create it try: From 5f56c1d0c2d499e475213a2715535e0f0d5af395 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:17:27 +1000 Subject: [PATCH 02/19] main: Initial stripe test fix path --- master/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/master/main.py b/master/main.py index 8072c5b..9451555 100644 --- a/master/main.py +++ b/master/main.py @@ -233,7 +233,7 @@ def tlsa(): return resp.json() -@app.route('stripe', methods=['POST']) +@app.route('/stripe', methods=['POST']) def stripe(): # Get API header api_key = request.headers.get('key') From d4fd4705644c4afc37be57e5dbe1f0637d0ab24d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:25:55 +1000 Subject: [PATCH 03/19] main: Stripe log all requests --- master/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/master/main.py b/master/main.py index 9451555..4ae4b03 100644 --- a/master/main.py +++ b/master/main.py @@ -235,6 +235,10 @@ def tlsa(): @app.route('/stripe', methods=['POST']) def stripe(): + # Log all requests + print(request.json) + # Log for docker + print(request.json, flush=True) # Get API header api_key = request.headers.get('key') if api_key == None: @@ -242,10 +246,7 @@ def stripe(): if api_key != os.getenv('STRIPE_KEY'): return jsonify({'error': 'Invalid API key', 'success': 'false'}) - # Log all requests - print(request.json) - # Log for docker - print(request.json, flush=True) + return jsonify({'success': 'true'}) From 230dc2a12a9758844ab636e7bca17b0ecae9ad97 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:41:38 +1000 Subject: [PATCH 04/19] main: Added test stripe verification --- master/main.py | 38 ++++++++++++++++++++++++++------------ master/requirements.txt | 3 ++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/master/main.py b/master/main.py index 4ae4b03..355063e 100644 --- a/master/main.py +++ b/master/main.py @@ -234,20 +234,34 @@ def tlsa(): @app.route('/stripe', methods=['POST']) -def stripe(): - # Log all requests - print(request.json) - # Log for docker +def stripeapi(): print(request.json, flush=True) - # Get API header - api_key = request.headers.get('key') - if api_key == None: - return jsonify({'error': 'Invalid API key', 'success': 'false'}) - if api_key != os.getenv('STRIPE_KEY'): - return jsonify({'error': 'Invalid API key', 'success': 'false'}) - - + print(request.headers, flush=True) + payload = request.data + stripe.api_key = os.getenv('STRIPE_SECRET') + endpoint_secret = os.getenv('STRIPE_ENDPOINT_SECRET') + sig_header = request.headers.get('HTTP_STRIPE_SIGNATURE') + events = None + try: + event = stripe.Webhook.construct_event( + payload, sig_header, endpoint_secret + ) + except ValueError as e: + # Invalid payload + return jsonify({'success': 'false'}) + except stripe.error.SignatureVerificationError as e: + return jsonify({'success': 'false'}) + # Handle the event + if event.type == 'payment_intent.succeeded': + payment_intent = event.data.object # contains a stripe.PaymentIntent + print('PaymentIntent was successful!', flush=True) + elif event.type == 'payment_method.attached': + payment_method = event.data.object # contains a stripe.PaymentMethod + print('PaymentMethod was attached to a Customer!', flush=True) + # ... handle other event types + else: + print('Unhandled event type {}'.format(event.type)) return jsonify({'success': 'true'}) diff --git a/master/requirements.txt b/master/requirements.txt index 01ad091..9a8f17f 100644 --- a/master/requirements.txt +++ b/master/requirements.txt @@ -1,4 +1,5 @@ python-dotenv requests flask -jsonify \ No newline at end of file +jsonify +stripe \ No newline at end of file From 969e5e17a54cac2d9284288d84d8cbb3530c8917 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:44:17 +1000 Subject: [PATCH 05/19] main: Import stripe python module --- master/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/master/main.py b/master/main.py index 355063e..8a5cad0 100644 --- a/master/main.py +++ b/master/main.py @@ -2,6 +2,7 @@ from flask import Flask, request, jsonify import dotenv import os import requests +import stripe dotenv.load_dotenv() @@ -240,7 +241,7 @@ def stripeapi(): payload = request.data stripe.api_key = os.getenv('STRIPE_SECRET') endpoint_secret = os.getenv('STRIPE_ENDPOINT_SECRET') - sig_header = request.headers.get('HTTP_STRIPE_SIGNATURE') + sig_header = request.headers.get('Stripe-Signature') events = None try: event = stripe.Webhook.construct_event( From eb137b85d32465b15f43fe442bc4ade91c2f5323 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:53:39 +1000 Subject: [PATCH 06/19] main: Added email test for stripe --- README.md | 13 +++++++++++++ master/main.py | 35 +++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e00aad3..a3364ac 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,19 @@ Then to start the master api server screen -dmS hnshosting-master python3 main.py ``` +## Stripe webhook +Create a new webhook endpoint on stripe and set the url to https://master-server-domain:5000/stripe-webhook (note: you need to add a https proxy to your master server if you want to use stripe) +Add these environment variables to your master server +```yaml +STRIPE_SECRET: your-stripe-secret-key +STRIPE_ENDPOINT_SECRET: your-stripe-endpoint-secret +SMTP_HOST: smtp-server +SMTP_PORT: smtp-port +SMTP_USER: smtp-user +SMTP_PASS: smtp-pass +SMTP_FROM: smtp-from +``` + ## Worker server install diff --git a/master/main.py b/master/main.py index 8a5cad0..f314b0b 100644 --- a/master/main.py +++ b/master/main.py @@ -2,7 +2,8 @@ from flask import Flask, request, jsonify import dotenv import os import requests -import stripe +import stripe # For stripe payments +import smtplib, ssl # For sending emails dotenv.load_dotenv() @@ -236,8 +237,6 @@ def tlsa(): @app.route('/stripe', methods=['POST']) def stripeapi(): - print(request.json, flush=True) - print(request.headers, flush=True) payload = request.data stripe.api_key = os.getenv('STRIPE_SECRET') endpoint_secret = os.getenv('STRIPE_ENDPOINT_SECRET') @@ -255,12 +254,32 @@ def stripeapi(): # Handle the event if event.type == 'payment_intent.succeeded': - payment_intent = event.data.object # contains a stripe.PaymentIntent + payment_intent = event.data.object + # Get email + email = payment_intent['receipt_email'] + # Create licence key + licence_key = os.urandom(16).hex() + # Add licence key to file + key_file = open('/data/licence_key.txt', 'a') + key_file.write(licence_key + '\n') + key_file.close() + # Send email + host = os.getenv('SMTP_HOST') + port = os.getenv('SMTP_PORT') + user = os.getenv('SMTP_USER') + password = os.getenv('SMTP_PASS') + from_email = os.getenv('SMTP_FROM') + if from_email == None: + from_email = user + + context = ssl.create_default_context() + with smtplib.SMTP_SSL(host, port, context=context) as server: + server.login(user, password) + server.sendmail(from_email, email, "Your licence key is: " + licence_key) + + + print('PaymentIntent was successful!', flush=True) - elif event.type == 'payment_method.attached': - payment_method = event.data.object # contains a stripe.PaymentMethod - print('PaymentMethod was attached to a Customer!', flush=True) - # ... handle other event types else: print('Unhandled event type {}'.format(event.type)) return jsonify({'success': 'true'}) From 93333eed26cffcf2d7f52d8e0cc1b9091a9f1843 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 16:57:05 +1000 Subject: [PATCH 07/19] main: Cleaned up email --- master/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/master/main.py b/master/main.py index f314b0b..833ec47 100644 --- a/master/main.py +++ b/master/main.py @@ -275,7 +275,12 @@ def stripeapi(): context = ssl.create_default_context() with smtplib.SMTP_SSL(host, port, context=context) as server: server.login(user, password) - server.sendmail(from_email, email, "Your licence key is: " + licence_key) + message = """\ + Subject: Your Licence key + + Your licence key is: """ + licence_key + + server.sendmail(from_email, email, message) From cb849004b7923e64579d90461a59b8964f2dc359 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:05:01 +1000 Subject: [PATCH 08/19] main: Added info to email --- master/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/master/main.py b/master/main.py index 833ec47..b3feea6 100644 --- a/master/main.py +++ b/master/main.py @@ -275,10 +275,20 @@ def stripeapi(): context = ssl.create_default_context() with smtplib.SMTP_SSL(host, port, context=context) as server: server.login(user, password) - message = """\ + message = """From: Hosting <""" + from_email + """> + To: """ + email + """ Subject: Your Licence key - Your licence key is: """ + licence_key + Hello, + This email contains your licence key for your new wordpress site. + You can redeem this key via the discord bot or api. + + Your licence key is: """ + licence_key + """ + + Thanks, + HNSHosting + + """ server.sendmail(from_email, email, message) From 2209e03158461c6ff2cc27da4e59cc1eea9c13f3 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:11:42 +1000 Subject: [PATCH 09/19] main: Email test 3 --- master/main.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/master/main.py b/master/main.py index b3feea6..9384027 100644 --- a/master/main.py +++ b/master/main.py @@ -275,20 +275,11 @@ def stripeapi(): context = ssl.create_default_context() with smtplib.SMTP_SSL(host, port, context=context) as server: server.login(user, password) - message = """From: Hosting <""" + from_email + """> - To: """ + email + """ - Subject: Your Licence key - - Hello, - This email contains your licence key for your new wordpress site. - You can redeem this key via the discord bot or api. - - Your licence key is: """ + licence_key + """ - - Thanks, - HNSHosting - - """ + message = "From: Hosting <" + from_email + ">\nTo: " + email + \ + "\nSubject: Your Licence key\n\nHello,\n\n"\ + +"This email contains your licence key for your new wordpress site.\n" \ + +"You can redeem this key via the discord bot or api.\n\n"\ + +"Your licence key is: " + licence_key +"\nThanks,\nHNSHosting" server.sendmail(from_email, email, message) From fc8a0c3193a6b721546fc37f9335cda2ef80c7ff Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:18:24 +1000 Subject: [PATCH 10/19] main: Cleaned up code --- README.md | 2 +- master/main.py | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a3364ac..1217cb8 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ SMTP_HOST: smtp-server SMTP_PORT: smtp-port SMTP_USER: smtp-user SMTP_PASS: smtp-pass -SMTP_FROM: smtp-from +SMTP_FROM: smtp-from (eg. HNSHosting ) This is optional ``` diff --git a/master/main.py b/master/main.py index 9384027..b5effa2 100644 --- a/master/main.py +++ b/master/main.py @@ -251,8 +251,7 @@ def stripeapi(): return jsonify({'success': 'false'}) except stripe.error.SignatureVerificationError as e: return jsonify({'success': 'false'}) - - # Handle the event + if event.type == 'payment_intent.succeeded': payment_intent = event.data.object # Get email @@ -270,12 +269,12 @@ def stripeapi(): password = os.getenv('SMTP_PASS') from_email = os.getenv('SMTP_FROM') if from_email == None: - from_email = user + from_email = "Hosting <"+user + ">" context = ssl.create_default_context() with smtplib.SMTP_SSL(host, port, context=context) as server: server.login(user, password) - message = "From: Hosting <" + from_email + ">\nTo: " + email + \ + message = "From: " + from_email + "\nTo: " + email + \ "\nSubject: Your Licence key\n\nHello,\n\n"\ +"This email contains your licence key for your new wordpress site.\n" \ +"You can redeem this key via the discord bot or api.\n\n"\ @@ -283,16 +282,12 @@ def stripeapi(): server.sendmail(from_email, email, message) - - - print('PaymentIntent was successful!', flush=True) + print('Licence sent via email for stripe payment', flush=True) else: print('Unhandled event type {}'.format(event.type)) return jsonify({'success': 'true'}) - - def get_sites_count(): # If file doesn't exist, create it try: From aa11014ab955457aeb20a06cc5375048c301bd87 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:20:35 +1000 Subject: [PATCH 11/19] actions: Start adding a dev build --- .gitea/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 7620559..c754326 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -22,6 +22,8 @@ jobs: cd master echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + docker build -t hnshosting-master:$tag_num . docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num @@ -47,6 +49,7 @@ jobs: cd discord-bot echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" docker build -t hnshosting-bot:$tag_num . docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num From bc3f813b290bf326de4d5a28a4e61c473fa00ed2 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:23:23 +1000 Subject: [PATCH 12/19] actions: Added dev build --- .gitea/workflows/build.yml | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index c754326..09779e0 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -23,12 +23,21 @@ jobs: echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + if [ "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" = "master" ]; then + docker build -t hnshosting-master:$tag_num . + docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num + docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest + else + docker build -t hnshosting-master-dev:$tag_num . + docker tag hnshosting-master-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master-dev:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-master-dev:$tag_num + docker tag hnshosting-master-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master-dev:latest + docker push git.woodburn.au/nathanwoodburn/hnshosting-master-dev:latest + fi - docker build -t hnshosting-master:$tag_num . - docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num - docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest + Build Bot: runs-on: ubuntu-latest @@ -50,8 +59,16 @@ jobs: echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - docker build -t hnshosting-bot:$tag_num . - docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num - docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:latest \ No newline at end of file + if [ "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" = "master" ]; then + docker build -t hnshosting-bot:$tag_num . + docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num + docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:latest + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:latest + else + docker build -t hnshosting-bot-dev:$tag_num . + docker tag hnshosting-bot-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:$tag_num + docker tag hnshosting-bot-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:latest + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:latest + fi \ No newline at end of file From 166e2234291fe4cc29f56ed2354976f392bda1e7 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:31:40 +1000 Subject: [PATCH 13/19] actions: Fixed tags --- .gitea/workflows/build.yml | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 09779e0..50b76f4 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -23,20 +23,21 @@ jobs: echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - if [ "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" = "master" ]; then - docker build -t hnshosting-master:$tag_num . - docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num - docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest + tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + if [ tag = "main" ]; then + $tag = "latest" else - docker build -t hnshosting-master-dev:$tag_num . - docker tag hnshosting-master-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master-dev:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-master-dev:$tag_num - docker tag hnshosting-master-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master-dev:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-master-dev:latest + $tag_num = $tag +"-"+ $tag_num fi + docker build -t hnshosting-master:$tag_num . + docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num + docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag + + + Build Bot: @@ -59,16 +60,16 @@ jobs: echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - if [ "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" = "master" ]; then - docker build -t hnshosting-bot:$tag_num . - docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num - docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:latest + tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + if [ tag = "main" ]; then + $tag = "latest" else - docker build -t hnshosting-bot-dev:$tag_num . - docker tag hnshosting-bot-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:$tag_num - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:$tag_num - docker tag hnshosting-bot-dev:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:latest - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot-dev:latest - fi \ No newline at end of file + $tag_num = $tag +"-"+ $tag_num + fi + + docker build -t hnshosting-bot:$tag_num . + docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num + docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag + \ No newline at end of file From 46096f0e84dded673606e1e1b3f72a65ba61edf6 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:33:58 +1000 Subject: [PATCH 14/19] actions: Fixed typo --- .gitea/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 50b76f4..71251ad 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -25,9 +25,9 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} if [ tag = "main" ]; then - $tag = "latest" + tag = "latest" else - $tag_num = $tag +"-"+ $tag_num + tag_num = $tag +"-"+ $tag_num fi docker build -t hnshosting-master:$tag_num . @@ -62,9 +62,9 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} if [ tag = "main" ]; then - $tag = "latest" + tag = "latest" else - $tag_num = $tag +"-"+ $tag_num + tag_num = $tag +"-"+ $tag_num fi docker build -t hnshosting-bot:$tag_num . From b0ab46562f14ad1c645e513f18c35caeb14c7459 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:35:18 +1000 Subject: [PATCH 15/19] actions: Syntax error fix --- .gitea/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 71251ad..49260a7 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -25,9 +25,9 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} if [ tag = "main" ]; then - tag = "latest" + tag="latest" else - tag_num = $tag +"-"+ $tag_num + tag_num=$tag + "-" + $tag_num fi docker build -t hnshosting-master:$tag_num . @@ -62,9 +62,9 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} if [ tag = "main" ]; then - tag = "latest" + tag="latest" else - tag_num = $tag +"-"+ $tag_num + tag_num=$tag + "-" + $tag_num fi docker build -t hnshosting-bot:$tag_num . From 62770ff0ecbb903b1beed6a8d599edf5599dc264 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:38:29 +1000 Subject: [PATCH 16/19] actions: syntax error try 3 --- .gitea/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 49260a7..69a1568 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -27,7 +27,7 @@ jobs: if [ tag = "main" ]; then tag="latest" else - tag_num=$tag + "-" + $tag_num + tag_num="${tag}-${tag_num}" fi docker build -t hnshosting-master:$tag_num . From b2f731ce8d3a54655ce437a4dbd7ab6c4d7cf3b6 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:39:44 +1000 Subject: [PATCH 17/19] actions: Apply fix to bot --- .gitea/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 69a1568..26492ab 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -64,7 +64,7 @@ jobs: if [ tag = "main" ]; then tag="latest" else - tag_num=$tag + "-" + $tag_num + tag_num="${tag}-${tag_num}" fi docker build -t hnshosting-bot:$tag_num . From d005c5796e15e69d096381e86dcfc82108e34d89 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 17:43:02 +1000 Subject: [PATCH 18/19] actions: Fix errors from feature branches --- .gitea/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 26492ab..60922c2 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -24,11 +24,13 @@ jobs: tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + tag=${tag//\//-} if [ tag = "main" ]; then tag="latest" else tag_num="${tag}-${tag_num}" fi + docker build -t hnshosting-master:$tag_num . docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num @@ -61,6 +63,7 @@ jobs: tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + tag=${tag//\//-} if [ tag = "main" ]; then tag="latest" else From bc1b27a504bc0db821424d33f168c3d7787ced9c Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 18:15:01 +1000 Subject: [PATCH 19/19] worker: Fixed ports --- worker/main.py | 6 +++--- worker/wp.sh | 23 +++++++++-------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/worker/main.py b/worker/main.py index f24852a..82e4a18 100644 --- a/worker/main.py +++ b/worker/main.py @@ -26,7 +26,7 @@ def new_site(): sites_file.close() # New site in background - thread = threading.Thread(target=new_site, args=(domain, 5000 + count)) + thread = threading.Thread(target=new_site, args=(domain)) thread.start() @@ -93,8 +93,8 @@ def site_exists(domain): else: return False -def new_site(domain,port): - script = 'bash wp.sh ' + domain + ' '+ str(port) +def new_site(domain): + script = 'bash wp.sh ' + domain os.system(script) # Start the server diff --git a/worker/wp.sh b/worker/wp.sh index 6563699..227ddae 100644 --- a/worker/wp.sh +++ b/worker/wp.sh @@ -4,10 +4,8 @@ # Then it will create an NGINX reverse proxy to the container. # USAGE: -# ./wp.sh [domain] [port offset] +# ./wp.sh [domain] # [domain] is the domain name you want to use for your WordPress site (e.g. docker.freeconcept) -# [port offset] is the offset you want to use for the port numbers. -# This is used if you want to run multiple instances of WordPress on the same server. (e.g. 0, 1, 2, 3, etc.) # Variables # Set the domain name @@ -21,15 +19,6 @@ fi DOMAIN="$1" echo "Setting up on domain name: $DOMAIN" -# Set port offset -# This is used to offset the port numbers so you can run multiple instances of WordPress on the same server. -if [ -z "$2" ] -then - PORT_OFFSET=0 -else - PORT_OFFSET="$2" -fi - mkdir wordpress-$DOMAIN cd wordpress-$DOMAIN @@ -38,6 +27,8 @@ MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32) MYSQL_PASSWORD=$(openssl rand -base64 32) # Create port numbers +# Offset is the number of files in nginx/sites-enabled +PORT_OFFSET=$(ls -1 /etc/nginx/sites-enabled | wc -l) WORDPRESS_PORT=$((8000 + $PORT_OFFSET)) # Create the docker config file @@ -82,14 +73,18 @@ printf "server { server_name $DOMAIN *.$DOMAIN; proxy_ssl_server_name on; location / { + proxy_set_header Accept-Encoding ""; proxy_set_header X-Real-IP \$remote_addr; proxy_set_header Host \$http_host; proxy_set_header X-Forwarded-Host \$http_host; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto \$scheme; - proxy_pass $URL; - } + + sub_filter '' ''; + sub_filter_once on; + + } listen 443 ssl; ssl_certificate /etc/ssl/$DOMAIN.crt;