spfcheck : first use bugs corrections
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5963 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
47
spfcheck.php
47
spfcheck.php
@@ -38,7 +38,9 @@ class spfcheck
|
||||
/** Store all the DNS requests done
|
||||
*/
|
||||
private $dnsRequests = array ();
|
||||
|
||||
/** Store the number of DNS requests
|
||||
*/
|
||||
private $dnsCounter = 0;
|
||||
/** Set the DNS maximum number of requests
|
||||
*/
|
||||
const dnsRequestsMax = 30;
|
||||
@@ -58,11 +60,12 @@ class spfcheck
|
||||
// {{{
|
||||
{
|
||||
$this->errors = array ();
|
||||
$this->dnsCounter = 0;
|
||||
$this->dnsRequests = array ();
|
||||
$this->catchAll = "";
|
||||
$this->ipRecords = $this->getRecordsRecurse ($domain);
|
||||
if ($this->catchAll === "")
|
||||
$this->errors[$domain] = dgettext ("domframework",
|
||||
$this->errors[$domain][] = dgettext ("domframework",
|
||||
"No catch all defined for the domain");
|
||||
return $this->ipRecords;
|
||||
}
|
||||
@@ -125,6 +128,11 @@ class spfcheck
|
||||
$this->matchRule = "$this->catchAllDomain/$this->catchAll";
|
||||
return "SOFTFAIL";
|
||||
}
|
||||
if ($this->catchAll === "?all")
|
||||
{
|
||||
$this->matchRule = "$this->catchAllDomain/$this->catchAll";
|
||||
return "NEUTRAL";
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
@@ -185,6 +193,18 @@ class spfcheck
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Get the DNS values set for the provided $domain/$part(/$entity)
|
||||
* @param string $search The search entity
|
||||
* @return array The array of result from DNS
|
||||
* @return false if not exists
|
||||
*/
|
||||
public function getDNSEntries ($search)
|
||||
{
|
||||
if (! key_exists ($search, $this->dnsRequests))
|
||||
return false;
|
||||
return $this->dnsRequests[$search];
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// PRIVATE METHODS //
|
||||
/////////////////////////
|
||||
@@ -268,10 +288,11 @@ class spfcheck
|
||||
"Invalid mx set form domain '%s' : empty"), $domain);
|
||||
continue;
|
||||
}
|
||||
foreach ($this->dns_get_record ($ext, DNS_MX, $domain) as $record)
|
||||
foreach ($this->dns_get_record ($ext, DNS_MX, "$domain/$part") as
|
||||
$record)
|
||||
{
|
||||
foreach ($this->dns_get_record ($record, DNS_A | DNS_AAAA, $domain)
|
||||
as $ip)
|
||||
foreach ($this->dns_get_record ($record, DNS_A | DNS_AAAA,
|
||||
"$domain/$part/$record") as $ip)
|
||||
{
|
||||
$ips[$domain][$part][] = $ip;
|
||||
}
|
||||
@@ -331,7 +352,7 @@ class spfcheck
|
||||
{
|
||||
$this->errors[$domain][$part] = sprintf (dgettext ("domframework",
|
||||
"Invalid ptr set for domain '%s' : PTR must not be used anymore ".
|
||||
"(see RFC7208)"), $domain, $part);
|
||||
"(see RFC7208) : Skip it"), $domain, $part);
|
||||
continue;
|
||||
}
|
||||
// }}}
|
||||
@@ -349,8 +370,8 @@ class spfcheck
|
||||
"Invalid A set form domain '%s' : empty"), $domain);
|
||||
continue;
|
||||
}
|
||||
foreach ($this->dns_get_record ($ext, DNS_A | DNS_AAAA, $domain) as
|
||||
$record)
|
||||
foreach ($this->dns_get_record ($ext, DNS_A | DNS_AAAA,
|
||||
"$domain/$part") as $record)
|
||||
{
|
||||
$ips[$domain][$part][] = $record;
|
||||
}
|
||||
@@ -360,6 +381,7 @@ class spfcheck
|
||||
// "-all" / "~all" / "+all" part
|
||||
elseif (strtolower ($part) === "-all" ||
|
||||
strtolower ($part) === "~all" ||
|
||||
strtolower ($part) === "?all" ||
|
||||
strtolower ($part) === "+all")
|
||||
// {{{
|
||||
{
|
||||
@@ -410,11 +432,11 @@ class spfcheck
|
||||
default: throw new \Exception (dgettext ("domframework",
|
||||
"SPFCheck : Invalid type for DNS get record"), 500);
|
||||
}
|
||||
if (count ($this->dnsRequests) >= self::dnsRequestsMax)
|
||||
if ($this->dnsCounter >= self::dnsRequestsMax)
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"SPFCheck : Too much DNS requests (%d >= %d)"),
|
||||
count ($this->dnsRequests), self::dnsRequestsMax), 500);
|
||||
$this->dnsRequests[] = "$hostname, $typeStr";
|
||||
$this->dnsCounter, self::dnsRequestsMax), 500);
|
||||
$this->dnsCounter++;
|
||||
$res = array ();
|
||||
if ($type === DNS_TXT)
|
||||
{
|
||||
@@ -422,7 +444,7 @@ class spfcheck
|
||||
{
|
||||
if (! isset ($record["txt"]))
|
||||
{
|
||||
$this->errors[$somain][] = sprintf (dgettext ("domframework",
|
||||
$this->errors[$domain][] = sprintf (dgettext ("domframework",
|
||||
"No TXT record for domain '%s'"), $domain);
|
||||
continue;
|
||||
}
|
||||
@@ -465,6 +487,7 @@ class spfcheck
|
||||
}
|
||||
else
|
||||
throw new \Exception ("Can not get unknown type : $type");
|
||||
$this->dnsRequests[$domain] = $res;
|
||||
return $res;
|
||||
}
|
||||
// }}}
|
||||
|
||||
Reference in New Issue
Block a user