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
|
|
|
|
{
|
|
|
|
/**
|
2020-10-27 13:08:29 +13:00
|
|
|
* @var string
|
2020-02-21 11:15:53 +13:00
|
|
|
*/
|
|
|
|
protected $target;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $target
|
|
|
|
*/
|
|
|
|
public function __construct($target)
|
|
|
|
{
|
|
|
|
$this->target = $target;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:08:29 +13:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-02-21 11:15:53 +13:00
|
|
|
public function getDescription()
|
|
|
|
{
|
2020-06-16 08:05:49 +12:00
|
|
|
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
|
|
|
*
|
2020-10-27 13:08:29 +13: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;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:08:29 +13:00
|
|
|
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;
|
|
|
|
}
|
2021-04-13 20:46:30 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is array
|
|
|
|
*
|
|
|
|
* Function will return true if object is array.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isArray(): bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Type
|
|
|
|
*
|
|
|
|
* Returns validator type.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
return self::TYPE_STRING;
|
|
|
|
}
|
2020-02-21 11:15:53 +13:00
|
|
|
}
|