GMTROM/REST/index.html

154 lines
5.5 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>GMTROM - True Random Number Generator</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/png href="logomiddle.png">
</head>
<body>
<img src="logo.png" alt="Logo" class="logo">
<h1>GMTROM - True Random Number Generator</h1>
<form id="randomForm">
<input type="button" value="Initialize" id="initButton"><br><br>
<label for="quantity">Quantity of Random Numbers:</label>
<input type="number" id="quantity" name="quantity"><br><br>
<label for="bits">Number of Bits per Random Number:</label>
<input type="number" id="bits" name="bits"><br><br>
<input type="button" value="Generate" id="generateButton">
<input type="button" value="Shutdown" id="shutdownButton">
</form>
<div id="status"></div>
<div id="result"></div>
<script>
document.getElementById('initButton').addEventListener('click', function() {
fetch('https://172.16.78.57:5000/trng/randomNum/init')
.then(response => {
document.getElementById('status').innerText = 'Status: ' + response.status;
if (response.status === 200) {
document.getElementById('result').innerText = 'Successful operation; random number generator has been set to "standby mode".';
console.log('Initialisierung erfolgreich');
} else {
console.log('Fehler beim Initialisieren');
}
})
.catch(error => {
console.error('Fehler beim Initialisieren:', error);
});
});
document.getElementById('generateButton').addEventListener('click', function(event) {
var quantity = document.getElementById('quantity').value;
var bits = document.getElementById('bits').value;
var url = 'https://172.16.78.57:5000/trng/randomNum/getRandom';
if (quantity && bits) {
url += '?quantity=' + quantity + '&numBits=' + bits;
}
fetch(url)
.then(response => {
document.getElementById('status').innerText = 'Status: ' + response.status;
return response.json();
})
.then(data => {
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = ''; // Clear previous results
var table = document.createElement('table');
table.classList.add('table');
var thead = document.createElement('thead');
var tbody = document.createElement('tbody');
var trHead = document.createElement('tr');
var thNr = document.createElement('th');
var thCopy = document.createElement('th');
var thRandom = document.createElement('th');
var copyAllButton = document.createElement('button');
thNr.textContent = 'ID';
thCopy.textContent = ' ';
thRandom.textContent = 'Random Number';
trHead.appendChild(thNr);
trHead.appendChild(thCopy);
trHead.appendChild(thRandom);
thead.appendChild(trHead);
table.appendChild(thead);
var hexNumbers = JSON.parse(data.randomNumbers);
for (var i = 0; i < hexNumbers.length; i++) {
var tr = document.createElement('tr');
var tdNr = document.createElement('td');
var tdCopy = document.createElement('td');
var tdRandom = document.createElement('td');
var copyButton = document.createElement('button');
tdNr.textContent = (i + 1).toString();
tdRandom.textContent = hexNumbers[i];
copyButton.textContent = 'Copy';
copyButton.classList.add('copy-button');
copyButton.addEventListener('click', function() {
copyToClipboard(this.parentElement.nextElementSibling.textContent);
});
tdCopy.appendChild(copyButton);
tr.appendChild(tdNr);
tr.appendChild(tdCopy);
tr.appendChild(tdRandom);
tbody.appendChild(tr);
}
table.appendChild(tbody);
resultDiv.appendChild(table);
copyAllButton.textContent = 'Copy all';
copyAllButton.classList.add('copy-button');
copyAllButton.addEventListener('click', function() {
var allHexNumbers = hexNumbers.join(', ');
copyToClipboard(allHexNumbers);
});
resultDiv.insertBefore(copyAllButton, table);
})
.catch(error => {
console.error('Fehler beim Abrufen der Daten:', error);
});
});
function copyToClipboard(text) {
var textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
// Anzeigen eines Popups zur Bestätigung der Kopie
window.alert('Der Text wurde in die Zwischenablage kopiert!');
}
document.getElementById('shutdownButton').addEventListener('click', function() {
fetch('https://172.16.78.57:5000/trng/randomNum/shutdown')
.then(response => {
document.getElementById('status').innerText = 'Status: ' + response.status;
if (response.status === 200) {
document.getElementById('result').innerText = 'Successful operation; random number generator has been shut down.';
console.log('Shutdown erfolgreich');
//document.getElementById('quantity').value = ''; // Textfeld "Quantity" zurücksetzen
//document.getElementById('bits').value = ''; // Textfeld "Bits" zurücksetzen
//document.getElementById('status').innerText = ''; // Element "status" zurücksetzen
//document.getElementById('result').innerText = ''; // Element "result" zurücksetzen
} else {
console.log('Fehler beim Shutdown');
}
})
.catch(error => {
console.error('Fehler beim Shutdown:', error);
});
});
</script>
</body>
</html>