-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail_delivery.php
95 lines (83 loc) · 2.7 KB
/
email_delivery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
$log_file = '/var/log/maillog';
$domain_to_track = $_SESSION['general']["domain"];;
$email_data = [];
// Read log file content using shell_exec
$log_content = shell_exec("cat $log_file");
if ($log_content === null) {
echo "Error: Unable to read log file.";
exit(1);
}
// Process log file line by line
$lines = explode("\n", $log_content);
$lines=array_reverse($lines);
foreach ($lines as $line) {
if (strpos($line, $domain_to_track) === false) {
preg_match('/([A-Fa-f0-9]{10,12}):/', $line, $queue_id_matches);
if (!empty($queue_id_matches)){
if(empty($email_data[$queue_id_matches[1]])) {
continue;
}
}
}
$changes=0;
// Extract the email queue ID
preg_match('/([A-Fa-f0-9]{10,12}):/', $line, $queue_id_matches);
if (!empty($queue_id_matches)) {
$queue_id = $queue_id_matches[1];
} else {
continue;
}
// Extract the email status
preg_match('/status=(\w+)/', $line, $status_matches);
if (!empty($status_matches)) {
$status = $status_matches[1];
$changes++;
}
// Extract the recipient email address
preg_match('/to=<([^>]+)>/', $line, $recipient_matches);
if (!empty($recipient_matches)) {
$recipient = $recipient_matches[1];
$changes++;
}
preg_match('/from=<([^>]+)>/', $line, $sender_matches);
if (!empty($sender_matches)) {
$sender = $sender_matches[1];
$changes++;
}else{
//$sender=$line;
}
if($changes==0){
continue;
}
// Extract the timestamp
preg_match('/^\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}/', $line, $timestamp_matches);
if (!empty($timestamp_matches)) {
$timestamp = $timestamp_matches[0];
}
if (isset($status) && isset($recipient) ) {
$email_data[$queue_id] = [
'timestamp' => $timestamp,
'recipient' => $recipient,
'sender' => $sender,
'status' => $status
];
}
}
ob_start();
echo "<table class='dataTable table table-responsive table-bordered'>";
echo "<thead><tr><th>Queue ID</th><th>Timestamp</th><th>Sender</th><th>Recipient</th><th>Status</th></tr></thead><tbody>";
foreach ($email_data as $queue_id => $email) {
//foreach ($emails as $email) {
echo "<tr>";
echo "<td>" . htmlspecialchars($queue_id) . "</td>";
echo "<td>" . htmlspecialchars($email['timestamp']) . "</td>";
echo "<td>" . htmlspecialchars($email['sender']) . "</td>";
echo "<td>" . htmlspecialchars($email['recipient']) . "</td>";
echo "<td>" . htmlspecialchars($email['status']) . "</td>";
echo "</tr>";
//}
}
echo "</tbody></table>";
$mod["content"]=ob_get_clean();
?>