**Änderungen:** - ✅ check_printer_ips.py und check_printers.py: Entfernt nicht mehr benötigte Skripte zur Überprüfung von Drucker-IP-Adressen. - ✅ DRUCKER_STATUS_REQUIREMENTS.md: Veraltete Anforderungen entfernt. - ✅ setup_standard_printers.py: Anpassungen zur Vereinheitlichung der Drucker-IP. - ✅ app.py: Logik zur Filterung offline/unreachable Drucker aktualisiert. **Ergebnis:** - Bereinigung des Codes durch Entfernen nicht mehr benötigter Dateien. - Optimierte Logik zur Handhabung von Druckerstatus in der Anwendung. 🤖 Generated with [Claude Code](https://claude.ai/code)
222 lines
9.6 KiB
HTML
222 lines
9.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>CSRF-Token Test - MYP Platform</title>
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
|
|
.container { max-width: 800px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
|
.test-section { margin: 20px 0; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
|
|
.success { background: #d4edda; border-color: #c3e6cb; color: #155724; }
|
|
.error { background: #f8d7da; border-color: #f5c6cb; color: #721c24; }
|
|
.info { background: #d1ecf1; border-color: #bee5eb; color: #0c5460; }
|
|
button { padding: 10px 20px; margin: 5px; border: none; border-radius: 5px; cursor: pointer; }
|
|
.btn-primary { background: #007bff; color: white; }
|
|
.btn-danger { background: #dc3545; color: white; }
|
|
.btn-success { background: #28a745; color: white; }
|
|
pre { background: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; }
|
|
.token-display { font-family: monospace; background: #f8f9fa; padding: 10px; border-radius: 5px; word-break: break-all; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🔒 CSRF-Token Diagnose & Test</h1>
|
|
<p>Diese Seite hilft bei der Diagnose und Behebung von CSRF-Token-Problemen.</p>
|
|
|
|
<!-- Token-Anzeige -->
|
|
<div class="test-section info">
|
|
<h3>📋 Aktuelle Token-Informationen</h3>
|
|
<p><strong>Meta-Tag Token:</strong></p>
|
|
<div class="token-display" id="meta-token">{{ csrf_token() }}</div>
|
|
|
|
<p><strong>Session Token:</strong></p>
|
|
<div class="token-display" id="session-token">{{ session.get('_csrf_token', 'Nicht verfügbar') }}</div>
|
|
|
|
<p><strong>JavaScript Token:</strong></p>
|
|
<div class="token-display" id="js-token">Wird geladen...</div>
|
|
</div>
|
|
|
|
<!-- Test-Formular -->
|
|
<div class="test-section">
|
|
<h3>📝 CSRF-Test-Formular</h3>
|
|
<form id="test-form" method="POST" action="/api/csrf-test">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
|
<p>
|
|
<label for="test-data">Test-Daten:</label><br>
|
|
<input type="text" id="test-data" name="test_data" value="CSRF-Test-Daten" style="width: 300px; padding: 5px;">
|
|
</p>
|
|
<button type="submit" class="btn-primary">📤 Formular senden (mit Token)</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- AJAX-Tests -->
|
|
<div class="test-section">
|
|
<h3>🌐 AJAX-Tests</h3>
|
|
<button onclick="testAjaxWithToken()" class="btn-success">✅ AJAX mit Token</button>
|
|
<button onclick="testAjaxWithoutToken()" class="btn-danger">❌ AJAX ohne Token</button>
|
|
<button onclick="testFetchWithToken()" class="btn-success">✅ Fetch mit Token</button>
|
|
<button onclick="testFetchWithoutToken()" class="btn-danger">❌ Fetch ohne Token</button>
|
|
</div>
|
|
|
|
<!-- Ergebnisse -->
|
|
<div class="test-section">
|
|
<h3>📊 Test-Ergebnisse</h3>
|
|
<div id="results"></div>
|
|
</div>
|
|
|
|
<!-- Debug-Informationen -->
|
|
<div class="test-section">
|
|
<h3>🔍 Debug-Informationen</h3>
|
|
<button onclick="showDebugInfo()" class="btn-primary">Debug-Info anzeigen</button>
|
|
<pre id="debug-info" style="display: none;"></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- CSRF-Fix Script -->
|
|
<script src="{{ url_for('static', filename='js/csrf-fix.js') }}"></script>
|
|
|
|
<script>
|
|
// Token-Anzeige aktualisieren
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const jsToken = window.getCSRFToken ? window.getCSRFToken() : 'CSRF-Fix nicht geladen';
|
|
document.getElementById('js-token').textContent = jsToken;
|
|
});
|
|
|
|
// Ergebnis anzeigen
|
|
function showResult(message, isSuccess = true) {
|
|
const results = document.getElementById('results');
|
|
const div = document.createElement('div');
|
|
div.className = isSuccess ? 'success' : 'error';
|
|
div.innerHTML = `<strong>${new Date().toLocaleTimeString()}:</strong> ${message}`;
|
|
results.appendChild(div);
|
|
results.scrollTop = results.scrollHeight;
|
|
}
|
|
|
|
// AJAX mit Token
|
|
function testAjaxWithToken() {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/csrf-test');
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
xhr.setRequestHeader('X-CSRFToken', window.getCSRFToken());
|
|
|
|
xhr.onload = function() {
|
|
if (xhr.status === 200) {
|
|
showResult('✅ AJAX mit Token erfolgreich', true);
|
|
} else {
|
|
showResult(`❌ AJAX mit Token fehlgeschlagen: ${xhr.status} ${xhr.statusText}`, false);
|
|
}
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
showResult('❌ AJAX mit Token - Netzwerkfehler', false);
|
|
};
|
|
|
|
xhr.send(JSON.stringify({test_data: 'AJAX-Test mit Token'}));
|
|
}
|
|
|
|
// AJAX ohne Token
|
|
function testAjaxWithoutToken() {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/csrf-test');
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
xhr.onload = function() {
|
|
if (xhr.status === 400) {
|
|
showResult('✅ AJAX ohne Token korrekt abgelehnt (400)', true);
|
|
} else {
|
|
showResult(`⚠️ AJAX ohne Token unerwartete Antwort: ${xhr.status}`, false);
|
|
}
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
showResult('❌ AJAX ohne Token - Netzwerkfehler', false);
|
|
};
|
|
|
|
xhr.send(JSON.stringify({test_data: 'AJAX-Test ohne Token'}));
|
|
}
|
|
|
|
// Fetch mit Token
|
|
async function testFetchWithToken() {
|
|
try {
|
|
const response = await fetch('/api/csrf-test', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': window.getCSRFToken()
|
|
},
|
|
body: JSON.stringify({test_data: 'Fetch-Test mit Token'})
|
|
});
|
|
|
|
if (response.ok) {
|
|
showResult('✅ Fetch mit Token erfolgreich', true);
|
|
} else {
|
|
showResult(`❌ Fetch mit Token fehlgeschlagen: ${response.status} ${response.statusText}`, false);
|
|
}
|
|
} catch (error) {
|
|
showResult(`❌ Fetch mit Token Fehler: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Fetch ohne Token
|
|
async function testFetchWithoutToken() {
|
|
try {
|
|
const response = await fetch('/api/csrf-test', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({test_data: 'Fetch-Test ohne Token'})
|
|
});
|
|
|
|
if (response.status === 400) {
|
|
showResult('✅ Fetch ohne Token korrekt abgelehnt (400)', true);
|
|
} else {
|
|
showResult(`⚠️ Fetch ohne Token unerwartete Antwort: ${response.status}`, false);
|
|
}
|
|
} catch (error) {
|
|
showResult(`❌ Fetch ohne Token Fehler: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Debug-Informationen
|
|
function showDebugInfo() {
|
|
const debugInfo = {
|
|
'Meta-Tag Token': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'),
|
|
'Hidden Input Token': document.querySelector('input[name="csrf_token"]')?.value,
|
|
'JavaScript Token': window.getCSRFToken ? window.getCSRFToken() : 'Nicht verfügbar',
|
|
'Cookies': document.cookie,
|
|
'User Agent': navigator.userAgent,
|
|
'URL': window.location.href,
|
|
'Timestamp': new Date().toISOString()
|
|
};
|
|
|
|
document.getElementById('debug-info').textContent = JSON.stringify(debugInfo, null, 2);
|
|
document.getElementById('debug-info').style.display = 'block';
|
|
}
|
|
|
|
// Formular-Handler
|
|
document.getElementById('test-form').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('/api/csrf-test', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
showResult('✅ Formular erfolgreich gesendet', true);
|
|
} else {
|
|
showResult(`❌ Formular fehlgeschlagen: ${response.status} ${response.statusText}`, false);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
showResult(`❌ Formular Fehler: ${error.message}`, false);
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |