Files
Mailanalyse/index.php
2025-06-26 21:00:28 +02:00

367 lines
14 KiB
PHP

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>E-Mail Phishing Analyse</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
line-height: 1.6;
margin: 0;
padding: 20px;
}
.container {
max-width: 900px;
margin: 30px auto;
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
border: 1px solid #a81212;
}
h1 {
text-align: center;
color: #a81212;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}
input[type="file"] {
width: calc(100% - 22px);
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
display: none; /* Versteckt das Standard-Input-Feld */
}
input[type="submit"] {
background-color: #a81212;
color: white;
border: none;
cursor: pointer;
font-size: 16px;
font-weight: bold;
transition: background-color 0.3s ease;
width: 100%;
padding: 10px; /* Einheitlicher Abstand */
border-radius: 4px; /* Einheitlicher Radius */
}
input[type="submit"]:hover {
background-color: #8c0f0f;
}
.error {
background-color: #ffe0e0;
color: #cc0000;
border: 1px solid #cc0000;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.warning {
background-color: #fff3cd;
color: #664d03;
border: 1px solid #ffc107;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.result {
background-color: #e0ffe0;
color: #008000;
border: 1px solid #008000;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.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;
}
.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 {
text-align: center;
margin-top: 40px;
color: #777;
font-size: 0.9em;
}
footer a {
color: #a81212;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
/* Drag and Drop Styles */
.drop-zone {
border: 2px dashed #a81212;
border-radius: 8px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: background-color 0.3s ease, border-color 0.3s ease;
margin-bottom: 20px;
}
.drop-zone.highlight {
background-color: #f0f8ff;
border-color: #007bff;
}
.drop-zone p {
margin: 0;
color: #555;
}
.drop-zone input {
display: none;
}
.file-name-display {
margin-top: 10px;
font-weight: bold;
color: #a81212;
}
</style>
</head>
<body>
<div class="container">
<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-Fehler anzeigen (nur für Entwicklung, im Produktivsystem deaktivieren)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// --- Eigene Log-Funktion für index.php ---
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);
}
log_index_message("index.php loaded.");
$tempDir = __DIR__ . '/temp_results/'; // Muss mit process_email.php übereinstimmen
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 class="result-section">';
echo '<h3>E-Mail-Vorschau (erste 2000 Zeichen):</h3>';
echo '<pre>' . htmlspecialchars($fullEmailPreview) . '</pre>';
echo '</div>';
} else {
log_index_message("ERROR: Decoded result is not an array.");
echo '<div class="error"><p>Fehler: Ungültiges Analyseergebnisformat.</p></div>';
}
}
} else {
log_index_message("ERROR: Temp file not found or not readable: " . $tempFilePath);
echo '<div class="error"><p>Fehler: Analyseergebnisse nicht gefunden oder nicht zugänglich.</p></div>';
}
}
?>
</div>
<footer>
&copy; <?php echo date("Y"); ?> <a href="https://wachtel-it.de" target="_blank">Philipp Wachtel</a>
</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>
</html>