second commit

This commit is contained in:
deepend 2024-01-23 15:52:00 +00:00
parent 288acd25d9
commit a1f221d020
3 changed files with 206 additions and 0 deletions

101
css/style.css Normal file
View File

@ -0,0 +1,101 @@
/* General Body Styling */
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
color: #333;
}
/* Form Styling */
form {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 500px;
margin: 30px auto;
}
input[type="file"] {
border: 1px solid #ddd;
padding: 10px;
border-radius: 4px;
width: calc(100% - 22px);
}
input[type="submit"] {
background-color: #007bff;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
/* Output Styling */
h2, h3 {
color: #007bff;
}
p {
background: #fff;
padding: 10px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 10px;
}
strong {
color: #333;
}
/* Responsive Design */
@media (max-width: 600px) {
form {
width: 100%;
padding: 15px;
}
input[type="file"], input[type="submit"] {
width: calc(100% - 20px);
}
}
/* Table Styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
text-align: left;
padding: 8px;
}
th {
background-color: #f4f4f4;
}
/* Error Message Styling */
.error {
color: red;
margin-top: 20px;
}
/* Responsive Table */
@media (max-width: 600px) {
table {
display: block;
overflow-x: auto;
}
}

16
index.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>DMARC Report Viewer</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="form-container">
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="dmarcReport">Select DMARC XML Report:</label>
<input type="file" name="dmarcReport" id="dmarcReport">
<input type="submit" value="Upload Report" name="submit">
</form>
</div>
</body>
</html>

89
upload.php Normal file
View File

@ -0,0 +1,89 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["dmarcReport"])) {
$file = $_FILES["dmarcReport"]["tmp_name"];
$fileType = strtolower(pathinfo($_FILES["dmarcReport"]["name"], PATHINFO_EXTENSION));
$fileError = $_FILES["dmarcReport"]["error"];
// Start of HTML output
echo '<!DOCTYPE html><html><head><title>DMARC Report Output</title>';
echo '<link rel="stylesheet" href="css/style.css"></head><body>';
// Check for file upload errors
if ($fileError !== UPLOAD_ERR_OK) {
echo "<p class='error'>Error in file upload: " . $fileError . "</p>";
exit;
}
// Validate file type (XML)
if ($fileType != "xml") {
echo "<p class='error'>Only XML files are allowed.</p>";
exit;
}
// Load XML file
libxml_use_internal_errors(true);
$xml = simplexml_load_file($file);
$errors = libxml_get_errors();
libxml_clear_errors();
// Check if it's a valid DMARC XML
if ($xml === false || !empty($errors)) {
echo "<p class='error'>Failed to parse the XML file. Ensure it's a valid DMARC report.</p>";
foreach ($errors as $error) {
echo "<p class='error-detail'>Error: " . htmlspecialchars($error->message) . "</p>";
}
exit;
}
// Verify XML structure
if (!isset($xml->report_metadata, $xml->policy_published, $xml->record)) {
echo "<p class='error'>Invalid DMARC report structure.</p>";
exit;
}
// Extract and display data
echo "<h2>DMARC Report Summary</h2>";
$orgName = $xml->report_metadata->org_name;
echo "<p>Organization: $orgName</p>";
$domain = $xml->policy_published->domain;
$policy = $xml->policy_published->p;
echo "<p>Domain: $domain</p>";
echo "<p>Policy: $policy</p>";
// Process record data
echo "<h3>Details of Email Activity</h3>";
echo "<table><thead><tr><th>Source IP</th><th>Email Count</th><th>SPF Result</th><th>DKIM Result</th><th>Explanation</th></tr></thead><tbody>";
foreach ($xml->record as $record) {
$sourceIp = $record->row->source_ip;
$count = $record->row->count;
$evaluatedPolicy = $record->row->policy_evaluated;
$spfResult = $evaluatedPolicy->spf;
$dkimResult = $evaluatedPolicy->dkim;
echo "<tr>";
echo "<td>$sourceIp</td>";
echo "<td>$count</td>";
echo "<td>$spfResult</td>";
echo "<td>$dkimResult</td>";
// Plain English Explanation
$explanation = getExplanation($spfResult, $dkimResult);
echo "<td>$explanation</td>";
echo "</tr>";
}
echo "</tbody></table>";
echo '</body></html>';
}
function getExplanation($spfResult, $dkimResult) {
if ($spfResult == "pass" && $dkimResult == "pass") {
return "Both SPF and DKIM checks passed. Emails are likely legitimate.";
} elseif ($spfResult == "fail" && $dkimResult == "fail") {
return "Both SPF and DKIM checks failed. Emails could be fraudulent.";
} else {
return "Mixed results. Further investigation needed.";
}
}
?>