mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-14 02:24:31 +00:00
34 lines
848 B
PHP
34 lines
848 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class DomainService
|
|
{
|
|
const CACHE_KEY = 'pf:services:domains:';
|
|
|
|
public static function hasValidDns($domain)
|
|
{
|
|
if (! $domain || ! strlen($domain) || strpos($domain, '.') == -1) {
|
|
return false;
|
|
}
|
|
|
|
if (config('security.url.trusted_domains')) {
|
|
if (in_array($domain, explode(',', config('security.url.trusted_domains')))) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$valid = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
|
|
|
if (! $valid) {
|
|
return false;
|
|
}
|
|
|
|
return Cache::remember(self::CACHE_KEY.'valid-dns:'.$domain, 1800, function () use ($domain) {
|
|
return count(dns_get_record($domain, DNS_A | DNS_AAAA)) > 0;
|
|
});
|
|
}
|
|
}
|