mirror of
https://github.com/fernwerker/ownDynDNS.git
synced 2025-07-13 23:15:43 +02:00
added domain restriction capability
This commit is contained in:
parent
f2bfa9008f
commit
fac7616c25
5 changed files with 139 additions and 21 deletions
|
@ -55,6 +55,21 @@ final class Config
|
|||
*/
|
||||
private $allowCreate = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $restrictDomain = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $domain;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host;
|
||||
|
||||
|
||||
public function __construct(array $config)
|
||||
{
|
||||
|
@ -158,4 +173,58 @@ final class Config
|
|||
{
|
||||
return $this->allowCreate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRestrictDomain()
|
||||
{
|
||||
return $this->restrictDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
if (empty($this->host))
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->host . "." . $this->domain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
if (!empty($this->host))
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
else
|
||||
{
|
||||
$domainParts = explode('.', $this->domain);
|
||||
return $domainParts[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDomainName()
|
||||
{
|
||||
// hack if top level domain are used for dynDNS
|
||||
if (1 === substr_count($this->domain, '.')) {
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
$domainParts = explode('.', $this->domain);
|
||||
array_shift($domainParts); // remove sub domain
|
||||
return implode('.', $domainParts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,8 +124,21 @@ final class Handler
|
|||
$this->doLog(sprintf('api login failed, message: %s', $loginHandle->longmessage));
|
||||
}
|
||||
|
||||
// check if domain is restricted in config, force use of config values for domain and host
|
||||
if ($this->config->isRestrictDomain()) {
|
||||
$this->doLog('domain is restricted by .env file');
|
||||
$updateDomain = $this->config->getDomain();
|
||||
$updateDomainName = $this->config->getDomainName();
|
||||
$updateHost = $this->config->getHost();
|
||||
$this->doLog(sprintf('ignoring received domain, using configured domain: %s', $updateDomain));
|
||||
} else {
|
||||
$updateDomain = $this->payload->getDomain();
|
||||
$updateDomainName = $this->payload->getDomainName();
|
||||
$updateHost = $this->payload->getHost();
|
||||
}
|
||||
|
||||
$infoHandle = $dnsClient->infoDnsRecords(
|
||||
$this->payload->getDomainName(),
|
||||
$updateDomainName,
|
||||
$this->config->getCustomerId(),
|
||||
$this->config->getApiKey(),
|
||||
$loginHandle->responsedata->apisessionid,
|
||||
|
@ -138,10 +151,9 @@ final class Handler
|
|||
$txtchanges = false;
|
||||
|
||||
foreach ($infoHandle->responsedata->dnsrecords as $key => $record) {
|
||||
$recordHostnameReal = (!in_array($record->hostname, $this->payload->getMatcher())) ? $record->hostname . '.' . $this->payload->getDomainName() : $this->payload->getDomainName();
|
||||
$recordHostnameReal = (!in_array($record->hostname, $this->payload->getMatcher())) ? $record->hostname . '.' . $updateDomainName : $updateDomainName;
|
||||
|
||||
|
||||
if ($recordHostnameReal === $this->payload->getDomain()) {
|
||||
if ($recordHostnameReal === $updateDomain) {
|
||||
|
||||
// found matching entry, no need to create one
|
||||
$exists = true;
|
||||
|
@ -154,7 +166,7 @@ final class Handler
|
|||
)
|
||||
) {
|
||||
$record->destination = $this->payload->getIpv4();
|
||||
$this->doLog(sprintf('IPv4 for %s set to %s', $record->hostname . '.' . $this->payload->getDomainName(), $this->payload->getIpv4()));
|
||||
$this->doLog(sprintf('IPv4 for %s set to %s', $record->hostname . '.' . $updateDomainName, $this->payload->getIpv4()));
|
||||
$ipv4changes = true;
|
||||
}
|
||||
|
||||
|
@ -166,7 +178,7 @@ final class Handler
|
|||
)
|
||||
) {
|
||||
$record->destination = $this->payload->getIpv6();
|
||||
$this->doLog(sprintf('IPv6 for %s set to %s', $record->hostname . '.' . $this->payload->getDomainName(), $this->payload->getIpv6()));
|
||||
$this->doLog(sprintf('IPv6 for %s set to %s', $record->hostname . '.' . $updateDomainName, $this->payload->getIpv6()));
|
||||
$ipv6changes = true;
|
||||
}
|
||||
|
||||
|
@ -178,7 +190,7 @@ final class Handler
|
|||
)
|
||||
) {
|
||||
$record->destination = $this->payload->getTxt();
|
||||
$this->doLog(sprintf('TXT for %s set to %s', $record->hostname . '.' . $this->payload->getDomainName(), $this->payload->getTxt()));
|
||||
$this->doLog(sprintf('TXT for %s set to %s', $record->hostname . '.' . $updateDomainName, $this->payload->getTxt()));
|
||||
$txtchanges = true;
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +207,7 @@ final class Handler
|
|||
{
|
||||
$record = new Soap\Dnsrecord();
|
||||
|
||||
$record->hostname = $this->payload->getHost();
|
||||
$record->hostname = $updateHost;
|
||||
$record->type = $type;
|
||||
$record->priority = "0"; // only for MX, can possibly be removed
|
||||
|
||||
|
@ -218,7 +230,7 @@ final class Handler
|
|||
|
||||
|
||||
$dnsClient->updateDnsRecords(
|
||||
$this->payload->getDomainName(),
|
||||
$updateDomainName,
|
||||
$this->config->getCustomerId(),
|
||||
$this->config->getApiKey(),
|
||||
$loginHandle->responsedata->apisessionid,
|
||||
|
@ -235,7 +247,7 @@ final class Handler
|
|||
$recordSet->dnsrecords = $infoHandle->responsedata->dnsrecords;
|
||||
|
||||
$dnsClient->updateDnsRecords(
|
||||
$this->payload->getDomainName(),
|
||||
$updateDomainName,
|
||||
$this->config->getCustomerId(),
|
||||
$this->config->getApiKey(),
|
||||
$loginHandle->responsedata->apisessionid,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue