1
0

DomainService.php 735 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Cache;
  4. use Illuminate\Support\Facades\Redis;
  5. class DomainService
  6. {
  7. const CACHE_KEY = 'pf:services:domains:';
  8. public static function hasValidDns($domain)
  9. {
  10. if(!$domain || !strlen($domain) || strpos($domain, '.') == -1) {
  11. return false;
  12. }
  13. if(config('security.url.trusted_domains')) {
  14. if(in_array($domain, explode(',', config('security.url.trusted_domains')))) {
  15. return true;
  16. }
  17. }
  18. return Cache::remember(self::CACHE_KEY . 'valid-dns:' . $domain, 14400, function() use($domain) {
  19. return count(dns_get_record($domain, DNS_A | DNS_AAAA)) > 0;
  20. });
  21. }
  22. }