diff --git a/master/main.py b/master/main.py index 4b5d6dd..e1cbc4e 100644 --- a/master/main.py +++ b/master/main.py @@ -430,7 +430,15 @@ def home(): pass # Create html page - html = "

Stats


" + html = "

Welcome


" + html += "

Create a site

" + html += "
" + html += "

Domain:

" + html += "

Licence key:

" + html += "" + html += "
" + + html += "

Stats


" html += "

Workers

" html += "

Number of workers: " + str(len(workers)) + "

" html += "

Workers:

" @@ -560,13 +568,38 @@ def admin(): @app.route('/add-site', methods=['POST']) def addsite(): - # Check cookie - login_key = request.cookies.get('login_key') - if login_key == None: - return redirect('/admin') - if login_key not in logins: - return redirect('/admin') - + # Check for licence key + if 'licence' not in request.form: + # Check cookie + login_key = request.cookies.get('login_key') + if login_key == None: + 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 domain = request.args.get('domain') if domain == None: @@ -614,7 +647,13 @@ def addsite(): # Send worker request requests.post("http://"+ worker.split(':')[1].strip('\n') + ":5000/new-site?domain=" + domain) - return redirect('/admin') + html = "

Site creating...


" + html += "

Domain: " + domain + "

" + html += "

Worker: " + worker.split(':')[0] + "

" + html += "

Worker IP: " + worker.split(':')[1].strip('\n') + "

" + html += "

Check status here

" + + return html @app.route('/licence')