Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
/** | |||||
* The eloquent definition of a Domain. | |||||
* | |||||
* @property string $namespace | |||||
*/ | |||||
class Domain extends Model | class Domain extends Model | ||||
{ | { | ||||
// we've simply never heard of this domain | // we've simply never heard of this domain | ||||
public const STATUS_NEW = 1 << 0; | public const STATUS_NEW = 1 << 0; | ||||
// it's been activated | // it's been activated | ||||
public const STATUS_ACTIVE = 1 << 1; | public const STATUS_ACTIVE = 1 << 1; | ||||
// domain has been suspended. | // domain has been suspended. | ||||
public const STATUS_SUSPENDED = 1 << 2; | public const STATUS_SUSPENDED = 1 << 2; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | // public const STATUS_VERIFIED = 1 << 5; | ||||
/** | /** | ||||
* Returns whether this domain is active. | * Returns whether this domain is active. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isActive(): bool | public function isActive(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_ACTIVE; | return ($this->status & self::STATUS_ACTIVE) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is confirmed the ownership of. | * Returns whether this domain is confirmed the ownership of. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isConfirmed(): bool | public function isConfirmed(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_CONFIRMED; | return ($this->status & self::STATUS_CONFIRMED) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is deleted. | * Returns whether this domain is deleted. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isDeleted(): bool | public function isDeleted(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_DELETED; | return ($this->status & self::STATUS_DELETED) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is registered with us. | * Returns whether this domain is registered with us. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isExternal(): bool | public function isExternal(): bool | ||||
{ | { | ||||
return $this->type & self::TYPE_EXTERNAL; | return ($this->type & self::TYPE_EXTERNAL) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is hosted with us. | * Returns whether this domain is hosted with us. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isHosted(): bool | public function isHosted(): bool | ||||
{ | { | ||||
return $this->type & self::TYPE_HOSTED; | return ($this->type & self::TYPE_HOSTED) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is new. | * Returns whether this domain is new. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isNew(): bool | public function isNew(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_NEW; | return ($this->status & self::STATUS_NEW) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is public. | * Returns whether this domain is public. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isPublic(): bool | public function isPublic(): bool | ||||
{ | { | ||||
return $this->type & self::TYPE_PUBLIC; | return ($this->type & self::TYPE_PUBLIC) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is registered in LDAP. | * Returns whether this domain is registered in LDAP. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isLdapReady(): bool | public function isLdapReady(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_LDAP_READY; | return ($this->status & self::STATUS_LDAP_READY) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is suspended. | * Returns whether this domain is suspended. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isSuspended(): bool | public function isSuspended(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_SUSPENDED; | return ($this->status & self::STATUS_SUSPENDED) == true; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this (external) domain has been verified | * Returns whether this (external) domain has been verified | ||||
* to exist in DNS. | * to exist in DNS. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | public function confirm(): bool | ||||
// Get DNS records and find a matching TXT entry | // Get DNS records and find a matching TXT entry | ||||
$records = \dns_get_record($this->namespace, DNS_TXT); | $records = \dns_get_record($this->namespace, DNS_TXT); | ||||
if ($records === 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}"); | ||||
} | } | ||||
foreach ($records as $record) { | foreach ($records as $record) { | ||||
if ($record['txt'] === $hash) { | if ($record['txt'] === $hash) { | ||||
machniak: This debug line is redundant. | |||||
$confirmed = true; | $confirmed = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Get DNS records and find a matching CNAME entry | // Get DNS records and find a matching CNAME entry | ||||
// Note: some servers resolve every non-existing name | // Note: some servers resolve every non-existing name | ||||
// so we need to define left and right side of the CNAME record | // so we need to define left and right side of the CNAME record | ||||
// i.e.: kolab-verify IN CNAME <hash>.domain.tld. | // i.e.: kolab-verify IN CNAME <hash>.domain.tld. | ||||
if (!$confirmed) { | if (!$confirmed) { | ||||
$cname = $this->hash(self::HASH_CODE) . '.' . $this->namespace; | $cname = $this->hash(self::HASH_CODE) . '.' . $this->namespace; | ||||
$records = \dns_get_record('kolab-verify.' . $this->namespace, DNS_CNAME); | $records = \dns_get_record('kolab-verify.' . $this->namespace, DNS_CNAME); | ||||
if ($records === false) { | if ($records === false) { | ||||
throw new \Exception("Failed to get DNS record for $domain"); | throw new \Exception("Failed to get DNS record for {$this->namespace}"); | ||||
} | } | ||||
foreach ($records as $records) { | foreach ($records as $records) { | ||||
if ($records['target'] === $cname) { | if ($records['target'] === $cname) { | ||||
$confirmed = true; | $confirmed = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
This debug line is redundant.