diff --git a/README.md b/README.md index def6909..ee42c56 100644 --- a/README.md +++ b/README.md @@ -115,4 +115,15 @@ Enable the free mode by setting the following environment variable. This will allow you to create a wordpress site without using a licence key using the /createsite command. ``` FREE_MODE: true -``` \ No newline at end of file +``` + + +## Hip2 +HIP2 allows sending HNS to a domain. +To enable HIP2 on your wordpress site you should + +1. Download the [HIP2 plugin](https://git.woodburn.au/nathanwoodburn/hnshosting-wp/raw/branch/main/assets/hns-wallet-plugin.zip) +2. Upload the plugin to your wordpress site +3. Activate the plugin +4. Go to the settings page and enter your HNS wallet address +5. Ensure it works by settings the permalink to post name and saving \ No newline at end of file diff --git a/assets/hns-wallet-plugin.zip b/assets/hns-wallet-plugin.zip new file mode 100644 index 0000000..fab70cb Binary files /dev/null and b/assets/hns-wallet-plugin.zip differ diff --git a/discord-bot/bot.py b/discord-bot/bot.py index cf7fa15..6293b17 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -71,6 +71,14 @@ async def license(ctx): @tree.command(name="createsite", description="Create a new WordPress site") async def createsite(ctx, domain: str, licence: str = None): + # Verify domain is valid + if domain == None: + await ctx.response.send_message("You must specify a domain",ephemeral=True) + return + if "http://" in domain or "https://" in domain: + await ctx.response.send_message("You must specify a domain without http:// or https://",ephemeral=True) + return + if FREE_LICENCE == True: # If free licences are enabled then auto generate a licence r = requests.post(f"http://{Master_IP}:{Master_Port}/add-licence",headers={"key":os.getenv('LICENCE_KEY')}) if r.status_code == 200: @@ -80,12 +88,12 @@ async def createsite(ctx, domain: str, licence: str = None): else: await ctx.response.send_message(f"Error getting license\n" + json['error']) return - + r = requests.post(f"http://{Master_IP}:{Master_Port}/new-site?domain={domain}",headers={"key":licence}) if r.status_code == 200: 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") + await ctx.response.send_message(f"Site https://{domain} creating...\nI'll send you a message when it's ready") ready = False while ready == False: @@ -96,7 +104,7 @@ async def createsite(ctx, domain: str, licence: str = None): 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}`") + await ctx.user.send(f"Site https://{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']) diff --git a/master/main.py b/master/main.py index 96575b9..c695878 100644 --- a/master/main.py +++ b/master/main.py @@ -233,37 +233,6 @@ def site_status(): else: return jsonify({'success': 'false', 'domain': domain, 'ip': publicIP, 'tlsa': 'none','error': 'No TLSA record found'}) - -@app.route('/info') -def site_status_human(): - domain = request.args.get('domain') - domain = domain.lower() - if domain == None: - return "

Invalid domain

" - - # Check if domain exists - if not site_exists(domain): - return "

Domain does not exist

" - - # Get worker - worker = site_worker(domain) - if worker == None: - return "

Domain does not exist

" - - # Get worker ip - ip = workerIP_PRIV(worker) - - # Get TLSA record - resp=requests.get("http://"+ip + ":5000/tlsa?domain=" + domain,timeout=2) - json = resp.json() - publicIP = workerIP(worker) - - if "tlsa" in json: - tlsa = json['tlsa'] - return "

Domain: " + domain + "


IP: " + publicIP + "


TLSA: " + tlsa + "


Make sure to add the TLSA record to `_443._tcp." + domain + "` or `*." + domain + "`

" - else: - return "

Domain: " + domain + "


IP: " + publicIP + "


TLSA: none


No TLSA record found

" - @app.route('/tlsa', methods=['GET']) def tlsa(): domain = request.args.get('domain') @@ -531,19 +500,20 @@ def register_post(): return redirect('/success?domain=' + domain + '&status=creating') @app.route('/success') +@app.route('/info') def success(): if 'domain' not in request.args: return redirect('/') domain = request.args.get('domain') domain = domain.lower() if not site_exists(domain): - return render_template('success.html', message="Error: Domain does not exist\nPlease contact support") + return render_template('success.html', title="Your site is installing.
Please wait...",message="") if 'status' not in request.args: # Get worker worker = site_worker(domain) if worker == None: - return render_template('success.html', message="Error: Domain does not exist\nPlease contact support") + return render_template('success.html', title="Your site is installing.
Please wait...",message="Error: Domain does not exist
Please contact support") # Get worker ip ip = workerIP_PRIV(worker) @@ -554,14 +524,14 @@ def success(): if "tlsa" in json: tlsa = json['tlsa'] - return render_template('success.html', message="Success\nDomain: " + domain + "\nIP: " + publicIP + "\nTLSA: " + tlsa + "\nMake sure to add the TLSA record to `_443._tcp." + domain + "` or `*." + domain + "`") + return render_template('success.html', title="Your site is ready!",message="Success
Domain: " + domain + "
IP: " + publicIP + "
TLSA: " + tlsa + "
Make sure to add the TLSA record to _443._tcp." + domain + " or *." + domain + "") else: - return render_template('success.html', message="Success\nDomain: " + domain + "\nIP: " + publicIP + "\nTLSA: Pending\nNo TLSA record found") + return render_template('success.html', title="Your site is installing.
Please wait...",message="Domain: " + domain + "
IP: " + publicIP + "
TLSA: Pending
No TLSA record found") elif request.args.get('status') == 'creating': return render_template('success.html') - - + + @app.route('/site-count') def site_count_route(): return str(get_sites_count()) diff --git a/master/templates/assets/js/status_update.js b/master/templates/assets/js/status_update.js index 0738dca..9f6509a 100644 --- a/master/templates/assets/js/status_update.js +++ b/master/templates/assets/js/status_update.js @@ -1,10 +1,12 @@ -// Refresh page without status arg - -// Wait 10 seconds +// Wait for 10 seconds setTimeout(function() { - // Refresh page - // Get domain from param + // Get the 'domain' parameter from the current URL + var urlParams = new URLSearchParams(window.location.search); var domain = urlParams.get('domain'); - window.location = "https://hnshosting.au/success?domain=" + domain; -}, 10000); \ No newline at end of file + // Construct the new URL with the 'domain' parameter + var newURL = "https://hnshosting.au/info?domain=" + domain; + + // Redirect to the new URL + window.location.href = newURL; +}, 10000); diff --git a/master/templates/success.html b/master/templates/success.html index f2cb7f3..0c1d19d 100644 --- a/master/templates/success.html +++ b/master/templates/success.html @@ -35,9 +35,9 @@

Success

-

Your site is installing.
Please wait...

+

{{title| safe}}

-

{{message}}

+

{{message | safe}}

diff --git a/worker/main.py b/worker/main.py index cdb9c62..f9c1140 100644 --- a/worker/main.py +++ b/worker/main.py @@ -44,8 +44,8 @@ def tlsa(): tlsa_file = open('wordpress-'+domain+'/tlsa.txt', 'r') tlsa = tlsa_file.readlines() tlsa_file.close() - except FileNotFoundError: - return jsonify({'error': 'TLSA record not found', 'success': 'false'}) + except FileNotFoundError as e: + return jsonify({'error': 'TLSA record not found', 'success': 'false', 'ex': str(e)}) # Remove newlines tlsa = tlsa[0].strip('\n') diff --git a/worker/wp.sh b/worker/wp.sh index 04855d5..2a3e7b3 100644 --- a/worker/wp.sh +++ b/worker/wp.sh @@ -43,6 +43,8 @@ services: MYSQL_DATABASE: WordPressDatabase MYSQL_USER: WordPressUser MYSQL_PASSWORD: $MYSQL_PASSWORD + volumes: + - mysql:/var/lib/mysql wordpress: depends_on: - ${DOMAIN}db @@ -87,6 +89,12 @@ printf "server { sub_filter_once on; } + location = /.well-known/wallets/HNS { + proxy_pass $URL; + proxy_set_header Host \$http_host; + rewrite ^(.*)$ \$1/ break; + } + listen 443 ssl; ssl_certificate /etc/ssl/$DOMAIN.crt;