index.php aktualisiert

This commit is contained in:
pw
2025-06-26 21:00:28 +02:00
parent e89bf9253e
commit cbd9ea850b

505
index.php
View File

@ -3,32 +3,29 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>E-Mail Analyse</title> <title>E-Mail Phishing Analyse</title>
<style> <style>
/* CSS aus der Mehrwertsteuerrechner-Datei */
body { body {
font-family: Arial, sans-serif; /* Arial als Standardschriftart */ font-family: Arial, sans-serif;
background-color: #fff; /* Weißer Hintergrund */ background-color: #f4f4f4;
color: #333; color: #333;
line-height: 1.6; line-height: 1.6;
margin: 0; margin: 0;
padding: 20px; padding: 20px;
} }
.container { .container {
max-width: 900px; /* Angepasst für E-Mail-Analyse */ max-width: 900px;
margin: 30px auto; margin: 30px auto;
background: #fff; background: #fff;
padding: 30px; padding: 30px;
border-radius: 8px; border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
border: 1px solid #a81212; /* Akzentfarbe für den Rand */ border: 1px solid #a81212;
} }
h1, h2, h3 { h1 {
text-align: center; text-align: center;
color: #a81212; /* Akzentfarbe für Überschrift */ color: #a81212;
margin-bottom: 30px; margin-bottom: 30px;
border-bottom: 1px solid #eee; /* Beibehalten für Struktur */
padding-bottom: 10px;
} }
.form-group { .form-group {
margin-bottom: 20px; margin-bottom: 20px;
@ -38,101 +35,105 @@
margin-bottom: 8px; margin-bottom: 8px;
font-weight: bold; font-weight: bold;
} }
input[type="file"] { /* Angepasst für Dateiupload */ input[type="file"] {
width: calc(100% - 22px); width: calc(100% - 22px);
padding: 10px; padding: 10px;
border: 1px solid #a81212; margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px; border-radius: 4px;
box-sizing: border-box; box-sizing: border-box;
font-size: 16px; display: none; /* Versteckt das Standard-Input-Feld */
display: block; /* Sicherstellen, dass es wie ein Block-Element behandelt wird */
margin-bottom: 15px; /* Abstand nach unten */
} }
button[type="submit"], .back-button { /* Angepasst von input[type="submit"] */ input[type="submit"] {
background-color: #a81212; background-color: #a81212;
color: white; color: white;
padding: 12px 20px;
border: none; border: none;
border-radius: 4px;
cursor: pointer; cursor: pointer;
font-size: 16px; font-size: 16px;
width: 100%; font-weight: bold;
transition: background-color 0.3s ease; transition: background-color 0.3s ease;
text-decoration: none; /* Für den Button-Link */ width: 100%;
display: block; /* Für den Button-Link */ padding: 10px; /* Einheitlicher Abstand */
text-align: center; /* Für den Button-Link */ border-radius: 4px; /* Einheitlicher Radius */
box-sizing: border-box; /* Für den Button-Link */
} }
button[type="submit"]:hover, .back-button:hover { input[type="submit"]:hover {
background-color: #8f0e0e; background-color: #8c0f0f;
}
.result-section { /* Container für die Ergebnisse */
background-color: #ffe5e5;
border: 1px solid #a81212;
color: #a81212;
padding: 15px;
border-radius: 5px;
margin-top: 20px;
font-size: 1.1em;
text-align: left; /* Textausrichtung angepasst */
} }
.error { .error {
background-color: #f8d7da; background-color: #ffe0e0;
border: 1px solid #f5c6cb; color: #cc0000;
color: #721c24; border: 1px solid #cc0000;
padding: 15px; padding: 15px;
border-radius: 5px; border-radius: 5px;
margin-top: 20px; margin-bottom: 20px;
font-size: 1.1em;
text-align: center;
}
.header-section p, .phishing-section p {
background-color: #f9f9f9; /* Leichterer Hintergrund für Header-Einträge */
border-left: 5px solid #a81212; /* Akzentfarbe für Header-Balken */
padding: 10px;
margin-bottom: 10px;
word-wrap: break-word;
color: #333; /* Standardtextfarbe */
} }
.warning { .warning {
background-color: #fff3cd; /* Gelb für Warnungen */ background-color: #fff3cd;
color: #856404; color: #664d03;
border-color: #ffeeba; border: 1px solid #ffc107;
font-weight: bold;
}
.phishing-tendency {
padding: 15px; padding: 15px;
border-radius: 5px;
margin-bottom: 20px; margin-bottom: 20px;
border-radius: 8px;
font-size: 1.4em;
font-weight: bold;
text-align: center;
color: white;
text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
} }
.phishing-tendency.red { .result {
background-color: #dc3545; /* Rot für Phishing */ background-color: #e0ffe0;
border: 1px solid #c82333; color: #008000;
} border: 1px solid #008000;
.phishing-tendency.green {
background-color: #28a745; /* Grün für keine Phishing-Tendenz */
border: 1px solid #218838;
}
.full-email-preview {
background-color: #f0f0f0;
border: 1px solid #ccc;
padding: 15px; padding: 15px;
max-height: 400px; border-radius: 5px;
overflow-y: auto; margin-bottom: 20px;
white-space: pre-wrap; }
.result h2 {
color: #008000;
margin-top: 0;
}
.phishing-high {
background-color: #ffe0e0;
color: #cc0000;
border: 1px solid #cc0000;
}
.phishing-low {
background-color: #e6ffe6;
color: #008000;
border: 1px solid #008000;
}
.result-section {
margin-top: 30px;
border-top: 1px solid #eee;
padding-top: 20px;
}
.result-section h3 {
color: #a81212;
margin-bottom: 15px;
}
.header-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.header-table th, .header-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
word-break: break-all; word-break: break-all;
color: #333; }
.header-table th {
background-color: #f2f2f2;
width: 150px;
}
pre {
background-color: #eee;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
} }
footer { footer {
text-align: center; text-align: center;
margin-top: 40px; margin-top: 40px;
font-size: 0.9em;
color: #777; color: #777;
font-size: 0.9em;
} }
footer a { footer a {
color: #a81212; color: #a81212;
@ -142,38 +143,28 @@
text-decoration: underline; text-decoration: underline;
} }
/* Drag & Drop Feld CSS */ /* Drag and Drop Styles */
.drop-area { .drop-zone {
border: 3px dashed #a81212; border: 2px dashed #a81212;
border-radius: 8px; border-radius: 8px;
padding: 40px 20px; padding: 40px;
text-align: center; text-align: center;
font-size: 1.2em;
color: #777;
cursor: pointer; cursor: pointer;
transition: background-color 0.3s ease, border-color 0.3s ease; transition: background-color 0.3s ease, border-color 0.3s ease;
margin-bottom: 20px; margin-bottom: 20px;
background-color: #fff;
} }
.drop-area.highlight { .drop-zone.highlight {
background-color: #fff0f0; background-color: #f0f8ff;
border-color: #dc3545; border-color: #007bff;
} }
.drop-area p { .drop-zone p {
margin: 0; margin: 0;
color: #555;
} }
.drop-area input[type="file"] { .drop-zone input {
display: none; /* Verstecke das ursprüngliche Dateiauswahlfeld */ display: none;
} }
.file-name-display { .file-name-display {
margin-top: 10px;
font-size: 1em;
color: #333;
font-weight: bold;
}
/* Optional: Dateiname direkt unter dem Drag&Drop Feld */
#selectedFileName {
text-align: center;
margin-top: 10px; margin-top: 10px;
font-weight: bold; font-weight: bold;
color: #a81212; color: #a81212;
@ -182,173 +173,195 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>E-Mail Analyse-Tool</h1> <h1>E-Mail Phishing Analyse</h1>
<form action="process_email.php" method="post" enctype="multipart/form-data" id="uploadForm">
<div class="form-group">
<label for="email_file">E-Mail (.eml oder .txt) hochladen:</label>
<div id="drop_zone" class="drop-zone">
<input type="file" name="email_file" id="email_file" accept=".eml,.txt">
<p>E-Mail-Datei hierher ziehen oder klicken zum Auswählen</p>
<div id="file_name_display" class="file-name-display"></div>
</div>
</div>
<input type="submit" value="E-Mail analysieren">
</form>
<?php <?php
$errors = []; // Initialisiere $errors am Anfang, um es immer verfügbar zu haben // PHP-Fehler anzeigen (nur für Entwicklung, im Produktivsystem deaktivieren)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (isset($_GET['result'])) { // --- Eigene Log-Funktion für index.php ---
$result = json_decode(base64_decode($_GET['result']), true); function log_index_message($message) {
$log_file = __DIR__ . '/index_analysis.log';
$timestamp = date('Y-m-d H:i:s');
file_put_contents($log_file, "$timestamp: $message\n", FILE_APPEND | LOCK_EX);
}
if ($result) { log_index_message("index.php loaded.");
// Zurück-Button ganz oben vor den Ergebnissen
echo '<div class="form-group" style="margin-bottom: 20px;">'; $tempDir = __DIR__ . '/temp_results/'; // Muss mit process_email.php übereinstimmen
echo '<a href="index.php" class="back-button">Neue Analyse starten</a>';
if (isset($_GET['error'])) {
$errorMessage = htmlspecialchars($_GET['error']);
echo '<div class="error"><p>Fehler: ' . $errorMessage . '</p></div>';
log_index_message("Error displayed: " . $errorMessage);
} elseif (isset($_GET['result_id'])) {
$resultId = basename($_GET['result_id']); // basename zur Sicherheit
$tempFilePath = $tempDir . $resultId;
log_index_message("Attempting to read result from: " . $tempFilePath);
if (file_exists($tempFilePath) && is_readable($tempFilePath)) {
$jsonResult = file_get_contents($tempFilePath);
// Temporäre Datei löschen (optional, aber empfohlen für Aufräumen)
unlink($tempFilePath); // Jetzt aktiviert für das Aufräumen
log_index_message("Temp file read. Deletion status: " . (file_exists($tempFilePath) ? "NOT DELETED" : "DELETED"));
if ($jsonResult === false) {
log_index_message("ERROR: Failed to read content from temp file: " . $tempFilePath);
echo '<div class="error"><p>Fehler: Analyseergebnisse konnten nicht gelesen werden.</p></div>';
} else {
$result = json_decode($jsonResult, true);
if (json_last_error() !== JSON_ERROR_NONE) {
log_index_message("ERROR: JSON decoding failed: " . json_last_error_msg());
echo '<div class="error"><p>Fehler: Analyseergebnisse konnten nicht dekodiert werden. (' . json_last_error_msg() . ')</p></div>';
} elseif (is_array($result)) {
log_index_message("Analysis results successfully loaded and decoded.");
$headers = $result['headers'] ?? [];
$phishingWarnings = $result['phishing_check'] ?? [];
$isPhishingTendency = $result['is_phishing_tendency'] ?? false;
$fullEmailPreview = $result['full_email_preview'] ?? 'Keine Vorschau verfügbar.';
$phishingClass = $isPhishingTendency ? 'phishing-high' : 'phishing-low';
$phishingText = $isPhishingTendency ? 'Hohe Phishing-Tendenz erkannt!' : 'Geringe Phishing-Tendenz erkannt.';
echo '<div class="result ' . $phishingClass . '">';
echo '<h2>Analyse Ergebnis:</h2>';
echo '<p><strong>' . $phishingText . '</strong></p>';
echo '</div>';
if (!empty($phishingWarnings)) {
echo '<div class="warning">';
echo '<h3>Phishing Warnungen:</h3>';
echo '<ul>';
foreach ($phishingWarnings as $warning) {
echo '<li>' . htmlspecialchars($warning) . '</li>';
}
echo '</ul>';
echo '</div>';
}
echo '<div class="result-section">';
echo '<h3>Gefundene E-Mail-Header:</h3>';
if (!empty($headers)) {
echo '<table class="header-table">';
echo '<thead><tr><th>Header</th><th>Wert</th></tr></thead>';
echo '<tbody>';
foreach ($headers as $name => $value) {
echo '<tr>';
echo '<td>' . htmlspecialchars($name) . '</td>';
echo '<td>' . htmlspecialchars($value) . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} else {
echo '<p>Keine Header gefunden oder verarbeitet.</p>';
}
echo '</div>'; echo '</div>';
echo '<div class="result-section">'; echo '<div class="result-section">';
echo '<h3>E-Mail-Vorschau (erste 2000 Zeichen):</h3>';
// Phishing Tendenz Anzeige echo '<pre>' . htmlspecialchars($fullEmailPreview) . '</pre>';
$tendencyClass = $result['is_phishing_tendency'] ? 'red' : 'green';
$tendencyText = $result['is_phishing_tendency'] ? 'Phishing-Tendenz: HOCH' : 'Phishing-Tendenz: GERING';
echo '<div class="phishing-tendency ' . $tendencyClass . '">' . $tendencyText . '</div>';
echo '<h2>Analyse-Ergebnisse:</h2>';
echo '<h3>Phishing-Prüfung (Details):</h3>';
echo '<div class="phishing-section">';
if (!empty($result['phishing_check'])) {
foreach ($result['phishing_check'] as $warning) {
echo '<p class="warning">' . htmlspecialchars($warning) . '</p>';
}
} else {
echo '<p>Keine offensichtlichen Phishing-Merkmale erkannt (Basierend auf einfacher Prüfung).</p>';
}
echo '</div>'; echo '</div>';
echo '<h3>Header-Daten:</h3>';
if (!empty($result['headers'])) {
echo '<div class="header-section">';
foreach ($result['headers'] as $name => $value) {
echo '<p><strong>' . htmlspecialchars($name) . ':</strong> ' . nl2br(htmlspecialchars($value)) . '</p>';
}
echo '</div>';
} else { } else {
echo '<p>Keine Header-Daten gefunden oder Fehler beim Parsen.</p>'; log_index_message("ERROR: Decoded result is not an array.");
echo '<div class="error"><p>Fehler: Ungültiges Analyseergebnisformat.</p></div>';
} }
echo '<h3>Vollständige E-Mail (Vorschau):</h3>';
if (isset($result['full_email_preview'])) {
echo '<pre class="full-email-preview">' . htmlspecialchars($result['full_email_preview']) . '</pre>';
} else {
echo '<p>Vorschau nicht verfügbar.</p>';
}
echo '</div>'; // Ende result-section
} else {
echo '<div class="error"><p>Fehler beim Laden der Analyse-Ergebnisse.</p></div>';
// Auch hier den Zurück-Button anzeigen, falls ein Fehler auftritt
echo '<div class="form-group" style="margin-top: 30px;">';
echo '<a href="index.php" class="back-button">Zurück zum Upload</a>';
echo '</div>';
}
} elseif (isset($_GET['error'])) {
echo '<div class="error"><p>' . htmlspecialchars($_GET['error']) . '</p></div>';
// Auch hier den Zurück-Button anzeigen, falls ein Fehler auftritt
echo '<div class="form-group" style="margin-top: 30px;">';
echo '<a href="index.php" class="back-button">Zurück zum Upload</a>';
echo '</div>';
} else {
// Zeige das Drag & Drop Feld, wenn keine Ergebnisse oder Fehler vorliegen
?>
<form id="uploadForm" action="process_email.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="email_file">Wählen Sie eine E-Mail-Datei zum Hochladen aus (.eml oder .txt) oder ziehen Sie sie hierher:</label>
<div id="drop-area" class="drop-area">
<input type="file" id="email_file" name="email_file" accept=".eml,.txt" required>
<p>Ziehen Sie Ihre E-Mail-Datei hierher oder klicken Sie, um sie auszuwählen.</p>
<div id="selectedFileName" class="file-name-display"></div>
</div>
</div>
<div class="form-group">
<button type="submit" id="submitButton" disabled>E-Mail analysieren</button>
</div>
</form>
<script>
const dropArea = document.getElementById('drop-area');
const fileInput = document.getElementById('email_file');
const submitButton = document.getElementById('submitButton');
const selectedFileNameDisplay = document.getElementById('selectedFileName');
const uploadForm = document.getElementById('uploadForm');
// Verhindere Standard-Drag-Verhalten
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false); // Für den gesamten Body
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
// Highlight Drop Area, wenn Datei darüber gezogen wird
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropArea.classList.add('highlight');
}
function unhighlight() {
dropArea.classList.remove('highlight');
}
// Handle Dropped Files
dropArea.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length > 0) {
fileInput.files = files; // Weise die gedroppten Dateien dem Input-Feld zu
updateFileNameDisplay();
}
}
// Handle File Selection via Klick
fileInput.addEventListener('change', updateFileNameDisplay);
function updateFileNameDisplay() {
if (fileInput.files.length > 0) {
const fileName = fileInput.files[0].name;
const fileExtension = fileName.split('.').pop().toLowerCase();
const allowedExtensions = ['eml', 'txt'];
if (allowedExtensions.includes(fileExtension)) {
selectedFileNameDisplay.textContent = `Ausgewählte Datei: ${fileName}`;
submitButton.disabled = false; // Aktiviere den Submit-Button
// Optional: Füge hier eine visuelle Bestätigung hinzu
} else {
selectedFileNameDisplay.textContent = `Ungültiger Dateityp: ${fileName}. Bitte .eml oder .txt wählen.`;
submitButton.disabled = true; // Deaktiviere den Submit-Button
alert('Ungültiger Dateityp. Bitte laden Sie eine .eml- oder .txt-Datei hoch.');
fileInput.value = ''; // Setze das Feld zurück
} }
} else { } else {
selectedFileNameDisplay.textContent = ''; log_index_message("ERROR: Temp file not found or not readable: " . $tempFilePath);
submitButton.disabled = true; // Deaktiviere den Submit-Button echo '<div class="error"><p>Fehler: Analyseergebnisse nicht gefunden oder nicht zugänglich.</p></div>';
} }
} }
// Initialer Zustand: Button deaktiviert
updateFileNameDisplay(); // Überprüft, ob beim Laden bereits eine Datei ausgewählt ist (unwahrscheinlich)
</script>
<?php
}
?> ?>
</div> </div>
<footer> <footer>
&copy; <?php echo date("Y"); ?> <a href="https://wachtel-it.de" target="_blank">Philipp Wachtel</a> &copy; <?php echo date("Y"); ?> <a href="https://wachtel-it.de" target="_blank">Philipp Wachtel</a>
</footer> </footer>
<script>
const dropZone = document.getElementById('drop_zone');
const fileInput = document.getElementById('email_file');
const fileNameDisplay = document.getElementById('file_name_display');
const uploadForm = document.getElementById('uploadForm');
// Verhindere Standard-Browser-Verhalten für Drag & Drop
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('highlight');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('highlight');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('highlight');
const files = e.dataTransfer.files;
if (files.length > 0) {
const file = files[0];
handleFile(file);
}
});
// Dateiauswahl über Klick
dropZone.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
handleFile(file);
});
function handleFile(file) {
if (file) {
const allowedExtensions = ['eml', 'txt'];
const fileExtension = file.name.split('.').pop().toLowerCase();
if (allowedExtensions.includes(fileExtension)) {
// Weisen Sie die Datei dem Input-Feld zu
const dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
fileInput.files = dataTransfer.files;
fileNameDisplay.textContent = 'Ausgewählte Datei: ' + file.name;
fileNameDisplay.style.color = '#008000'; // Grüne Farbe für ausgewählte Datei
} else {
fileNameDisplay.textContent = 'Ungültiger Dateityp. Bitte .eml oder .txt hochladen.';
fileNameDisplay.style.color = '#cc0000'; // Rote Farbe für Fehler
fileInput.value = ''; // Input leeren
}
}
}
// Formular-Validierung vor dem Absenden (optional, aber empfohlen)
uploadForm.addEventListener('submit', (e) => {
if (!fileInput.files || fileInput.files.length === 0) {
alert('Bitte wählen Sie eine E-Mail-Datei aus, bevor Sie analysieren.');
e.preventDefault(); // Formular nicht absenden
}
});
</script>
</body> </body>
</html> </html>