Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bastien Durel
mta-sts
Commits
88abf6ce
Commit
88abf6ce
authored
Aug 24, 2018
by
Bastien Durel
Browse files
generate mta-sts.txt on the fly from DNS data
parent
b19ae5bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
88abf6ce
/vendor/
/config.inc
config.inc.dist
0 → 100644
View file @
88abf6ce
<?php
// -*- php -*-
## set minimum TTL
# $ttl = 86400;
## set mode
# $mode = 'enforce';
## restrict domains
# $domains = ['example.com', 'example.met']
mta-sts.txt.php
0 → 100644
View file @
88abf6ce
<?php
$s
=
$_SERVER
[
'SERVER_NAME'
];
if
(
strpos
(
$s
,
'mta-sts.'
)
!==
0
)
throw
new
Exception
(
"Incorrect HTTP host"
);
$s
=
substr
(
$s
,
8
);
$mode
=
'enforce'
;
$ttl
=
0
;
# Here we may tweak mode/minimum TTL and restrict domains
if
(
file_exists
(
'config.inc'
))
include_once
(
'config.inc'
);
if
(
isset
(
$domains
))
{
if
(
!
in_array
(
$s
,
$domains
))
{
http_response_code
(
403
);
die
(
"Incorrect domain:
$s
"
);
}
}
# you use a DNSSEC-enabled resolver, don't you ?
$mx_rr
=
dns_get_record
(
$s
,
DNS_MX
);
$mx
=
[];
foreach
(
$mx_rr
as
$rr
)
{
$mx
[
$rr
[
'pri'
]]
=
$rr
[
'target'
];
$ttl
=
max
(
$ttl
,
$rr
[
'ttl'
]);
}
rsort
(
$mx
);
$mx
=
array_unique
(
$mx
);
header
(
'Content-Type: text/plain'
);
echo
"version: STSv1
\n
"
;
echo
"mode:
$mode
\n
"
;
echo
"max_age:
$ttl
\n
"
;
foreach
(
$mx
as
$addr
)
echo
"mx:
$addr
\n
"
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment