main: Added customer self service
All checks were successful
Build Docker / Build Bot (push) Successful in 22s
Build Docker / Build Master (push) Successful in 28s

This commit is contained in:
Nathan Woodburn 2023-08-25 17:57:51 +10:00
parent 20dbf6c0df
commit 3628e0a4ac
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -430,7 +430,15 @@ def home():
pass pass
# Create html page # Create html page
html = "<h1>Stats</h1><br>" html = "<h1>Welcome</h1><br>"
html += "<h2>Create a site</h2>"
html += "<form action='/add-site' method='POST'>"
html += "<p>Domain: <input type='text' name='domain'></p>"
html += "<p>Licence key: <input type='text' name='licence'></p>"
html += "<input type='submit' value='Create site'>"
html += "</form>"
html += "<br><h2>Stats</h2><br>"
html += "<h2>Workers</h2>" html += "<h2>Workers</h2>"
html += "<p>Number of workers: " + str(len(workers)) + "</p>" html += "<p>Number of workers: " + str(len(workers)) + "</p>"
html += "<p>Workers:</p>" html += "<p>Workers:</p>"
@ -560,13 +568,38 @@ def admin():
@app.route('/add-site', methods=['POST']) @app.route('/add-site', methods=['POST'])
def addsite(): def addsite():
# Check cookie # Check for licence key
login_key = request.cookies.get('login_key') if 'licence' not in request.form:
if login_key == None: # Check cookie
return redirect('/admin') login_key = request.cookies.get('login_key')
if login_key not in logins: if login_key == None:
return redirect('/admin') return redirect('/admin')
if login_key not in logins:
return redirect('/admin')
else:
# Use licence key
licence_key = request.form['licence']
# Check if licence key is valid
key_file = open('/data/licence_key.txt', 'r')
valid_key = False
for line in key_file.readlines():
if licence_key == line.strip('\n'):
valid_key = True
break
key_file.close()
if not valid_key:
return jsonify({'error': 'Invalid licence', 'success': 'false'})
# Delete licence key
key_file = open('/data/licence_key.txt', 'r')
lines = key_file.readlines()
key_file.close()
key_file = open('/data/licence_key.txt', 'w')
for line in lines:
if line.strip("\n") != licence_key:
key_file.write(line)
key_file.close()
# Get domain # Get domain
domain = request.args.get('domain') domain = request.args.get('domain')
if domain == None: if domain == None:
@ -614,7 +647,13 @@ def addsite():
# Send worker request # Send worker request
requests.post("http://"+ worker.split(':')[1].strip('\n') + ":5000/new-site?domain=" + domain) requests.post("http://"+ worker.split(':')[1].strip('\n') + ":5000/new-site?domain=" + domain)
return redirect('/admin') html = "<h1>Site creating...</h1><br>"
html += "<p>Domain: " + domain + "</p>"
html += "<p>Worker: " + worker.split(':')[0] + "</p>"
html += "<p>Worker IP: " + worker.split(':')[1].strip('\n') + "</p>"
html += "<p>Check status <a href='/site-info?domain=" + domain + "'>here</a></p>"
return html
@app.route('/licence') @app.route('/licence')