Add dashboard, and flask endpoint that executes a script and returns the result (currently a hardcoded script)

This commit is contained in:
Peter Stockings
2023-12-16 17:32:44 +11:00
parent f18c4628b7
commit bc38aa181c
2 changed files with 197 additions and 0 deletions

45
app.py
View File

@@ -60,6 +60,10 @@ def index():
def client():
return render_template("client.html")
@ app.route("/dashboard", methods=["GET"])
def dashboard():
return render_template("dashboard.html")
@app.route('/execute', methods=['POST'])
def execute_code():
@@ -89,6 +93,47 @@ def execute_code():
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/f/<function>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
def execute_http_function(function):
try:
# TODO: Get code from database based on function name
code = DEFAULT_SCRIPT
request_obj = {
'method': request.method,
'headers': dict(request.headers),
'url': request.url,
# Add other request properties as needed
}
# Add JSON data if it exists
if request.is_json:
request_obj['json'] = request.get_json()
# Add form data if it exists
if request.form:
request_obj['form'] = request.form.to_dict()
# Add query parameters if they exist
if request.args:
request_obj['query'] = request.args.to_dict()
# Add plain text data if it exists
if request.data and not request.is_json:
request_obj['text'] = request.data.decode('utf-8')
# Call the Node.js API
response = requests.post(API_URL, json={'code': code, 'request': request_obj})
response_data = response.json()
# Map the Node.js response to Flask response
flask_response = map_isolator_response_to_flask_response(response_data)
return flask_response
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':