public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/web/mta-sts.php
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
<?php
2
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
4
if (!isset($_SERVER['HTTP_HOST']) || strpos($_SERVER['HTTP_HOST'], 'mta-sts.') !== 0) {
5
http_response_code(404);
6
exit;
7
}
9
$host = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']);
10
$domain = idn_to_ascii(strtolower(str_replace('mta-sts.', '', $host)), 0, INTL_IDNA_VARIANT_UTS46);
12
// Validate domain or return 404 on error
13
if ($domain === false || empty($domain)) {
14
http_response_code(404);
15
exit;
16
}
18
// Check if domain is an alias domain and resolve to target domain
19
try {
20
$stmt = $pdo->prepare("SELECT `target_domain` FROM `alias_domain` WHERE `alias_domain` = :domain");
21
$stmt->execute(array(':domain' => $domain));
22
$alias_row = $stmt->fetch(PDO::FETCH_ASSOC);
24
if ($alias_row !== false && !empty($alias_row['target_domain'])) {
25
// This is an alias domain, use the target domain for MTA-STS lookup
26
$domain = $alias_row['target_domain'];
27
}
28
} catch (PDOException $e) {
29
// On database error, return 404
30
http_response_code(404);
31
exit;
32
}
34
$mta_sts = mailbox('get', 'mta_sts', $domain);
36
if (count($mta_sts) == 0 ||
37
!isset($mta_sts['version']) ||
38
!isset($mta_sts['mode']) ||
39
!isset($mta_sts['max_age']) ||
40
!isset($mta_sts['mx']) ||
41
$mta_sts['active'] != 1) {
42
http_response_code(404);
43
exit;
44
}
46
header('Content-Type: text/plain; charset=utf-8');
47
echo "version: {$mta_sts['version']}\n";
48
echo "mode: {$mta_sts['mode']}\n";
49
echo "max_age: {$mta_sts['max_age']}\n";
50
foreach ($mta_sts['mx'] as $mx) {
51
echo "mx: {$mx}\n";
52
}
54
?>