From 3b914abf7a23d4221e4bb1bb46a7681df3a3a445 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:46:08 +1000 Subject: [PATCH 1/4] bot: Send a dm with the site info when the site is ready --- discord-bot/bot.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index b7969a9..ce9d578 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv import discord from discord import app_commands import requests +import asyncio load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') @@ -69,7 +70,24 @@ async def createsite(ctx, domain: str, licence: str): if r.status_code == 200: json = r.json() if json['success'] == "true": - await ctx.response.send_message(f"Site {domain} creating...\nPlease wait a few minutes and then send /siteinfo domain:{domain}") + await ctx.response.send_message(f"Site {domain} creating...\nI'll send you a message when it's ready") + # Set a timer to check if the site is ready + # Keep checking every 30 seconds until it is ready + + ready = False + while ready == False: + ready = await check_site_ready(domain,ctx.user.id) + if ready == False: + await asyncio.sleep(30) + + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + json = r.json() + if json['success'] == "true": + await ctx.user.send(f"Site {domain} is ready!\nHere is the site info for {json['domain']}\nA: `{json['ip']}`\nTLSA: `{json['tlsa']}`\nMake sure you put the TLSA in either `_443._tcp.{domain}` or `*.{domain}`") + else: + await ctx.user.send(f"Error getting site info\n" + json['error']) + + else: await ctx.response.send_message(f"Error creating site\n" + json['error']) else: @@ -88,6 +106,17 @@ async def siteinfo(ctx, domain: str): else: await ctx.response.send_message(f"Error getting site info\n" + r.text) +async def check_site_ready(domain): + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + if r.status_code == 200: + json = r.json() + if json['success'] == "true": + return True + else: + return False + else: + return False + # When the bot is ready @client.event async def on_ready(): From ce8827ed97a334c99974a8e379a2c870db068b0f Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:49:29 +1000 Subject: [PATCH 2/4] worker: Install missing update repo --- worker/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/worker/install.sh b/worker/install.sh index 7a1a95b..04ca556 100644 --- a/worker/install.sh +++ b/worker/install.sh @@ -11,6 +11,7 @@ KERNEL_VERSION=$(uname -r) sudo apt-mark hold linux-image-generic linux-headers-generic linux-generic linux-image-$KERNEL_VERSION linux-headers-$KERNEL_VERSION # Install Docker +sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common python3-pip nginx -y curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null From d217309e74e01cc2d015e3e062514abe34f5a2f5 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:51:58 +1000 Subject: [PATCH 3/4] bot: Fixed check if site ready function args --- discord-bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index ce9d578..3413083 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -76,7 +76,7 @@ async def createsite(ctx, domain: str, licence: str): ready = False while ready == False: - ready = await check_site_ready(domain,ctx.user.id) + ready = await check_site_ready(domain) if ready == False: await asyncio.sleep(30) From 908a4e0422a0c97da4efebc1c143cd546ee77735 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:54:31 +1000 Subject: [PATCH 4/4] bot: Check for install every 5 seconds --- discord-bot/bot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index 3413083..0450dbc 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -71,14 +71,12 @@ async def createsite(ctx, domain: str, licence: str): json = r.json() if json['success'] == "true": await ctx.response.send_message(f"Site {domain} creating...\nI'll send you a message when it's ready") - # Set a timer to check if the site is ready - # Keep checking every 30 seconds until it is ready ready = False while ready == False: ready = await check_site_ready(domain) if ready == False: - await asyncio.sleep(30) + await asyncio.sleep(5) r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") json = r.json()