| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 1 | <?php |
| 2 | require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php'; |
| 3 | |
| 4 | if (!isset($_SERVER['HTTP_HOST']) || strpos($_SERVER['HTTP_HOST'], 'mta-sts.') !== 0) { |
| 5 | http_response_code(404); |
| 6 | exit; |
| 7 | } |
| 8 | |
| 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); |
| 11 | |
| 12 | // Validate domain or return 404 on error |
| 13 | if ($domain === false || empty($domain)) { |
| 14 | http_response_code(404); |
| 15 | exit; |
| 16 | } |
| 17 | |
| 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); |
| 23 | |
| 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 | } |
| 33 | |
| 34 | $mta_sts = mailbox('get', 'mta_sts', $domain); |
| 35 | |
| 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 | } |
| 45 | |
| 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 | } |
| 53 | |
| 54 | ?> |