1
0
Fork 0
mirror of synced 2024-07-01 04:30:59 +12:00
appwrite/src/Appwrite/Network/Validator/CNAME.php

58 lines
1 KiB
PHP
Raw Normal View History

2020-02-21 11:15:53 +13:00
<?php
2020-06-12 07:36:10 +12:00
namespace Appwrite\Network\Validator;
2020-02-21 11:15:53 +13:00
use Utopia\Validator;
class CNAME extends Validator
{
/**
* @var string
2020-02-21 11:15:53 +13:00
*/
protected $target;
/**
* @param string $target
*/
public function __construct($target)
{
$this->target = $target;
}
/**
* @return string
*/
2020-02-21 11:15:53 +13:00
public function getDescription()
{
return 'Invalid CNAME record';
2020-02-21 11:15:53 +13:00
}
/**
* Check if CNAME record target value matches selected target
2020-06-25 09:05:16 +12:00
*
* @param mixed $domain
2020-02-21 11:15:53 +13:00
*
* @return bool
*/
public function isValid($domain)
{
2020-10-28 08:44:15 +13:00
if (!is_string($domain)) {
2020-02-21 11:15:53 +13:00
return false;
}
try {
$records = \dns_get_record($domain, DNS_CNAME);
} catch (\Throwable $th) {
2020-02-21 11:15:53 +13:00
return false;
}
2020-06-25 09:02:27 +12:00
foreach ($records as $record) {
if (isset($record['target']) && $record['target'] === $this->target) {
2020-02-21 11:15:53 +13:00
return true;
}
}
return false;
}
}