From ee9e73da66dc0d008a4aa8c5a8901edf2ff05251 Mon Sep 17 00:00:00 2001
From: Thomas Hassenstein <2021544@stud.hs-mannheim.de>
Date: Mon, 12 Jun 2023 07:26:18 +0200
Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9EREST?=
=?UTF-8?q?=E2=80=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Aktualisierung der Oberfläche
Auslagerung des Javaskript Codes
Anpassung CSS (Ergänzung von Disabled Styles)
REST Antworten vereinheitlichen
---
REST/app.py | 47 ++++++---
REST/index.html | 152 ++++-----------------------
REST/script.js | 236 ++++++++++++++++++++++++++++++++++++++++++
REST/style.css | 267 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 551 insertions(+), 151 deletions(-)
create mode 100644 REST/script.js
create mode 100644 REST/style.css
diff --git a/REST/app.py b/REST/app.py
index a830295..afbcbd9 100644
--- a/REST/app.py
+++ b/REST/app.py
@@ -10,54 +10,67 @@ CORS(app)
initialized = False
+def create_response(status_code, description):
+ return jsonify({
+ 'status': status_code,
+ 'description': description
+ })
+
@app.route('/trng/randomNum/init', methods=['GET'])
def initialize_generator():
- global initialized # Zugriff auf die globale Variable
+ global initialized
- #parameter 1 und 2 sind default values für Tests
result = analyze_data(int(1), int(1), startup=True)
if result is True:
initialized = True
- return jsonify({'message': 'successful operation; random number generator is ready and random numbers can be requested'}), 200
+ return create_response(200, 'Successful operation; random number generator is ready and random numbers can be requested')
+ if random_numbers == 400:
+ return create_response(500, 'Tests failed, try again')
+ if random_numbers is False:
+ return create_response(500, 'Unable to generate random numbers. Restart/Reset System')
else:
- return jsonify({'error': 'Unable to initialize the random number generator within a timeout of 60 seconds.'}), 555
+ return create_response(555, 'Unable to initialize the random number generator within a timeout of 60 seconds')
@app.route('/trng/randomNum/getRandom', methods=['GET'])
def get_random_numbers():
- global initialized # Zugriff auf die globale Variable
+ global initialized
quantity = request.args.get('quantity')
bits = request.args.get('numBits')
if not quantity.isdigit() or not bits.isdigit():
- return jsonify({'error': 'Invalid input. Quantity and bits must be numeric.'}), 400
+ return create_response(400, 'Invalid input. Quantity and bits must be numeric.')
if int(quantity) <= 0 or int(bits) <= 0:
- return jsonify({'error': 'Invalid input. Quantity and bits must be positive integers.'}), 400
+ return create_response(400, 'Invalid input. Quantity and bits must be positive integers.')
- # Überprüfe den Initialisierungsstatus
if not initialized:
- return jsonify({'error': 'system not ready; try init'}), 432
+ return create_response(432, 'System not ready; try init')
random_numbers = analyze_data(int(quantity), int(bits), startup=False)
+ if random_numbers == 400:
+ return create_response(500, 'Tests failed, try again')
if random_numbers is False:
- return jsonify({'error': 'Unable to generate random numbers.'}), 500
+ return create_response(500, 'Unable to generate random numbers. Restart/Reset System')
if random_numbers:
- data = {'randomNumbers': random_numbers} # Erstellen des Datenobjekts mit dem JSON-String
- return jsonify(data), 200
+ data = {
+ 'status': 200,
+ 'description': 'Successful operation; HEX-encoded bit arrays (with leading zeros if required)',
+ 'randomNumbers': random_numbers
+ }
+ return jsonify(data)
else:
- return jsonify({'error': 'Unable to generate random numbers.'}), 500
+ return create_response(500, 'Unable to generate random numbers.')
@app.route('/trng/randomNum/shutdown', methods=['GET'])
def shutdown_generator():
- global initialized # Zugriff auf die globale Variable
+ global initialized
- initialized = False # Setze den Initialisierungsstatus zurück
+ initialized = False
- # Beispielantwort
- return jsonify({'message': "successful operation; random number generator has been set to 'standby mode'"}), 200
+ return create_response(200, "Successful operation; random number generator has been set to 'standby mode'")
if __name__ == '__main__':
diff --git a/REST/index.html b/REST/index.html
index f97e053..ddbda3c 100644
--- a/REST/index.html
+++ b/REST/index.html
@@ -1,6 +1,7 @@
+
GMTROM - True Random Number Generator
@@ -11,144 +12,27 @@
+
+
+
+