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
Commit
[Web] Improve SPF checks
b6933fdb
data/web/inc/ajax/dns_diagnostics.php | 2 +-
data/web/inc/spf.inc.php | 14 +++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
Diff
diff --git a/data/web/inc/ajax/dns_diagnostics.php b/data/web/inc/ajax/dns_diagnostics.php
index 841b86f2..1b4c6ea7 100644
--- a/data/web/inc/ajax/dns_diagnostics.php
+++ b/data/web/inc/ajax/dns_diagnostics.php
@@ -368,7 +368,7 @@ foreach ($records as $record) {
$record[2] == $spf_link) {
$state = state_nomatch;
$rslt = get_spf_allowed_hosts($record[0]);
- if(in_array($ip, $rslt) && in_array($ip6, $rslt)){
+ if(in_array($ip, $rslt) && in_array(expand_ipv6($ip6), $rslt)){
$state = state_good;
}
$state .= '<br />' . $current[$data_field[$current['type']]].state_optional;
diff --git a/data/web/inc/spf.inc.php b/data/web/inc/spf.inc.php
index ddb9d48c..5e63b38b 100644
--- a/data/web/inc/spf.inc.php
+++ b/data/web/inc/spf.inc.php
@@ -1,6 +1,12 @@
<?php
error_reporting(0);
+function expand_ipv6($ip) {
+ $hex = unpack("H*hex", inet_pton($ip));
+ $ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
+ return $ip;
+}
+
function get_spf_allowed_hosts($check_domain)
{
$hosts = array();
@@ -33,6 +39,8 @@ function get_spf_allowed_hosts($check_domain)
else
{
unset($cidr);
+ // reset domain to check_domain
+ $domain = $check_domain;
if (strpos($mech, ':') !== FALSE) // handle a domain specification
{
$split = explode(':', $mech);
@@ -77,7 +85,11 @@ function get_spf_allowed_hosts($check_domain)
}
}
}
-
+ foreach ($hosts as &$host) {
+ if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
+ $host = expand_ipv6($host);
+ }
+ }
return $hosts;
}