Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | public function hash($mod = null): string | ||||
} | } | ||||
$hash = \md5('hkccp-verify-' . $this->namespace); | $hash = \md5('hkccp-verify-' . $this->namespace); | ||||
return $mod === self::HASH_TEXT ? "$cname=$hash" : $hash; | return $mod === self::HASH_TEXT ? "$cname=$hash" : $hash; | ||||
} | } | ||||
/** | /** | ||||
* Suspend this domain. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function suspend(): void | |||||
{ | |||||
if ($this->isSuspended()) { | |||||
return; | |||||
} | |||||
$this->status |= Domain::STATUS_SUSPENDED; | |||||
$this->save(); | |||||
} | |||||
/** | |||||
* Unsuspend this domain. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function unsuspend(): void | |||||
{ | |||||
if (!$this->isSuspended()) { | |||||
return; | |||||
} | |||||
$this->status ^= Domain::STATUS_SUSPENDED; | |||||
$this->save(); | |||||
} | |||||
/** | |||||
* Verify if a domain exists in DNS | * Verify if a domain exists in DNS | ||||
* | * | ||||
* @return bool True if registered, False otherwise | * @return bool True if registered, False otherwise | ||||
* @throws \Exception Throws exception on DNS or DB errors | * @throws \Exception Throws exception on DNS or DB errors | ||||
*/ | */ | ||||
public function verify(): bool | public function verify(): bool | ||||
{ | { | ||||
if ($this->isVerified()) { | if ($this->isVerified()) { | ||||
return true; | return true; | ||||
} | } | ||||
$record = \dns_get_record($this->namespace, DNS_ANY); | $records = \dns_get_record($this->namespace, DNS_ANY); | ||||
if ($record === false) { | if ($records === false) { | ||||
throw new \Exception("Failed to get DNS record for {$this->namespace}"); | throw new \Exception("Failed to get DNS record for {$this->namespace}"); | ||||
} | } | ||||
if (!empty($record)) { | // It may happen that result contains other domains depending on the host DNS setup | ||||
// that's why in_array() and not just !empty() | |||||
if (in_array($this->namespace, array_column($records, 'host'))) { | |||||
$this->status |= Domain::STATUS_VERIFIED; | $this->status |= Domain::STATUS_VERIFIED; | ||||
$this->save(); | $this->save(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Returns the wallet by which the domain is controlled | * Returns the wallet by which the domain is controlled | ||||
* | * | ||||
* @return \App\Wallet A wallet object | * @return \App\Wallet A wallet object | ||||
*/ | */ | ||||
public function wallet(): Wallet | public function wallet(): ?Wallet | ||||
{ | { | ||||
return $this->entitlement()->first()->wallet; | // Note: Not all domains have a entitlement/wallet | ||||
$entitlement = $this->entitlement()->first(); | |||||
return $entitlement ? $entitlement->first()->wallet : null; | |||||
} | } | ||||
} | } |