From 8a409334b64003beca3741716c62d44fa9be9fe5 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 9 Nov 2023 12:13:59 +1100 Subject: [PATCH] feat: Add HIP02 addresses --- README.md | 11 +++++++- db.py | 68 +++++++++++++++++++++++++++++++++++++++++---- main.py | 15 +++++++--- proposal.md | 23 +++++++++++++++ sites/db.py | 22 ++++++++++++++- sites/slds.py | 10 +++++++ templates/edit.html | 2 +- 7 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 proposal.md diff --git a/README.md b/README.md index 42b4dc6..4f75f23 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ -# shakecities +# ShakeCities +A joint project between Nathan.Woodburn/ and crymzyn/ +ShakeCities is a geocities clone with an emphasis on Handshake domains. +Create a free site on yourname.shakecities/. You control that site and can add whatever you want to it. +Every domain comes enabled with HTTPS via DANE. We have support HIP02 aliases, so you can send HNS to yourname.shakecities/ + + + + +### Deployment ``` version: '3' services: diff --git a/db.py b/db.py index a89e787..4a90191 100644 --- a/db.py +++ b/db.py @@ -129,13 +129,71 @@ def get_website_data(domain): return parsed -def update_website_data(domain,data): +def get_website_data_raw(domain): connection = mysql.connector.connect(**dbargs) cursor = connection.cursor() - # Create json object - data = { - "data": data - } + cursor.execute(""" + SELECT * FROM site WHERE domain = %s + """, (domain,)) + data = cursor.fetchall() + cursor.close() + connection.close() + + if data == []: + # Create new entry + connection = mysql.connector.connect(**dbargs) + cursor = connection.cursor() + data = { + "data": "" + } + insert_query = "INSERT INTO site (data,domain) VALUES (%s,%s)" + cursor.execute(insert_query, (json.dumps(data), domain)) + connection.commit() + cursor.close() + connection.close() + return "" + + parsed = data[0][2] + parsed = json.loads(parsed) + + return parsed + +def update_website_data(domain,data): + data = get_website_data_raw(domain) + + connection = mysql.connector.connect(**dbargs) + cursor = connection.cursor() + # Update json object + data['data'] = data + + update_query = "UPDATE site SET data = %s WHERE domain = %s" + cursor.execute(update_query, (json.dumps(data), domain)) + + connection.commit() + cursor.close() + connection.close() + +def update_website_data_raw(domain,data): + connection = mysql.connector.connect(**dbargs) + cursor = connection.cursor() + # Update json object + data = json.loads(data) + + update_query = "UPDATE site SET data = %s WHERE domain = %s" + cursor.execute(update_query, (json.dumps(data), domain)) + + connection.commit() + cursor.close() + connection.close() + +def update_website_wallet(domain,token,address): + data = get_website_data_raw(domain) + + connection = mysql.connector.connect(**dbargs) + cursor = connection.cursor() + # Update json object + data[token] = address + update_query = "UPDATE site SET data = %s WHERE domain = %s" cursor.execute(update_query, (json.dumps(data), domain)) diff --git a/main.py b/main.py index 4cd6482..277a4b5 100644 --- a/main.py +++ b/main.py @@ -88,8 +88,10 @@ def edit(): resp.set_cookie('token', '', expires=0) return resp - data = db.get_website_data(user['domain']) - return render_template('edit.html',account=user['email'],account_link="account",data=data) + data = db.get_website_data_raw(user['domain']) + + + return render_template('edit.html',account=user['email'],account_link="account",data=data['data'],hns=data['HNS'],btc=data['BTC'],eth=data['ETH']) @app.route('/edit', methods=['POST']) @@ -105,8 +107,13 @@ def send_edit(): resp.set_cookie('token', '', expires=0) return resp - data = request.form['data'] - db.update_website_data(user['domain'],data) + data = {} + data['data'] = request.form['data'] + data['HNS'] = request.form['hns'] + data['BTC'] = request.form['btc'] + data['ETH'] = request.form['eth'] + + db.update_website_data_raw(user['domain'],data) return redirect('/edit') diff --git a/proposal.md b/proposal.md new file mode 100644 index 0000000..c3c889b --- /dev/null +++ b/proposal.md @@ -0,0 +1,23 @@ +This project is a joint collaboration with [Nathan.Woodburn/](https://github.com/nathanwoodburn/) and [crymzyn/](https://github.com/crymzyn) + + +What have you built previously? +- [HNSHosting WP](https://hnshosting.au) +- [Woodburn Faucet](https://faucet.woodburn.au) + + +What will you be building? Why is that a valuable open source contribution to Handshake? +ShakeCities is a geocities clone with an emphasis on Handshake domains. +Create a free site on yourname.shakecities/. You control that site and can add whatever you want to it. +Every domain comes enabled with HTTPS via DANE. We have support HIP02 aliases, so you can send HNS to yourname.shakecities/ + +This will be a valuable resource to the Handshake community as it will allow new users to deploy a website in minutes. +In addition it will include information on how to create a site to the users own domains to encourage them to move towards decentralisation. + + + +What are completion criteria? +Fully working project site with user pages actively served over HTTPS. + +What is your contact information? +`github@nathan.woodburn.au` diff --git a/sites/db.py b/sites/db.py index f6debc1..1aee3fe 100644 --- a/sites/db.py +++ b/sites/db.py @@ -32,4 +32,24 @@ def get_website_data(domain): # Decoding parsed = parsed.encode('utf-8').decode('unicode-escape') - return parsed \ No newline at end of file + return parsed + +def get_website_wallet(domain,token): + connection = mysql.connector.connect(**dbargs) + cursor = connection.cursor() + cursor.execute(""" + SELECT * FROM site WHERE domain = %s + """, (domain,)) + data = cursor.fetchall() + cursor.close() + connection.close() + + if data == []: + return "" + + parsed = data[0][2] + parsed = json.loads(parsed) + if token in parsed: + parsed = parsed[token] + + return "" \ No newline at end of file diff --git a/sites/slds.py b/sites/slds.py index 931b4e3..e74ce88 100644 --- a/sites/slds.py +++ b/sites/slds.py @@ -35,6 +35,16 @@ def index(): return website.render(data) +@app.route('/.well-known/wallets/') +def wallet(token): + address = db.get_website_wallet(request.host.split('.')[0],token) + if address == "": + return redirect('/') + # Plain text + response = make_response(address) + response.mimetype = "text/plain" + return response + @app.route('/') def catch_all(path): return redirect('/') # 404 catch all diff --git a/templates/edit.html b/templates/edit.html index 5115a10..475dd1e 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -29,7 +29,7 @@

Edit your page

-
+