1
0
Fork 0
mirror of https://github.com/fernwerker/ownDynDNS.git synced 2025-07-10 14:15:14 +02:00

added optional anonymous login for clients

This commit is contained in:
Nils Blume 2023-08-31 09:22:07 +02:00
parent 662884d405
commit fdb3c4aa49
4 changed files with 42 additions and 12 deletions

View file

@ -33,6 +33,7 @@ Parameter | Example | Explanation
`allowCreate` | true/`false` | allows creation of entries if parameter `create=true` in URL `allowCreate` | true/`false` | allows creation of entries if parameter `create=true` in URL
`restrictDomain` | true / `false` | allows admin to restrict the domain to update to a given value `domain` and/or `host`. See URL parameters for host parameter explanation `restrictDomain` | true / `false` | allows admin to restrict the domain to update to a given value `domain` and/or `host`. See URL parameters for host parameter explanation
`allowNetcupCreds` | true / `false` | allows the user to pass netcup credentials directly via the URL. URL creds will be preferred if any still exist in .env file `allowNetcupCreds` | true / `false` | allows the user to pass netcup credentials directly via the URL. URL creds will be preferred if any still exist in .env file
`allowAnonymous` | true / `false` | allows anonymous login, recommended only if you do not store any credentials and disable logging
* alternatively you can use .configure.sh to create your .env file for you (if you are on a *NIX system) * alternatively you can use .configure.sh to create your .env file for you (if you are on a *NIX system)
@ -49,7 +50,7 @@ You can now set `allowCreate=true` in .env and pass `create=true` as URL paramet
Parameter | Example | Explanation Parameter | Example | Explanation
---: | :--- | :--- ---: | :--- | :---
user | dnsupdater | username to authenticate against this script as defined in .env file user | dnsupdater | username to authenticate against this script as defined in .env file. If anonymous login is allowed in .env: `anonymous`
password | secretpleasechange |password for that user as defined in .env file password | secretpleasechange |password for that user as defined in .env file
domain | home.example.com | `case A)` If `host` is not specified: the FQDN for your host domain | home.example.com | `case A)` If `host` is not specified: the FQDN for your host
domain | example.com | `case B)` If you want to update the @ or * record domain | example.com | `case B)` If you want to update the @ or * record

View file

@ -60,6 +60,11 @@ final class Config
*/ */
private $allowNetcupCreds = false; private $allowNetcupCreds = false;
/**
* @var bool
*/
private $allowAnonymous = false;
/** /**
* @var bool * @var bool
*/ */
@ -91,8 +96,13 @@ final class Config
public function isValid() public function isValid()
{ {
return return
!empty($this->username) && (
!empty($this->password) && !empty($this->username) &&
!empty($this->password)
) ||
(
$this->isAllowAnonymous()
) &&
( (
( (
!empty($this->apiKey) && !empty($this->apiKey) &&
@ -202,6 +212,14 @@ final class Config
return $this->allowNetcupCreds; return $this->allowNetcupCreds;
} }
/**
* @return bool
*/
public function isAllowAnonymous()
{
return $this->allowAnonymous;
}
/** /**
* @return string * @return string
*/ */

View file

@ -58,14 +58,22 @@ final class Handler
} }
} }
if ( if ($this->config->isAllowAnonymous()) {
$this->config->getUsername() !== $this->payload->getUser() || if ($this->payload->getUser() == 'anonymous') {
$this->config->getPassword() !== $this->payload->getPassword() if ($this->config->isDebug()) {
) { $this->doLog('anonymous login by client');
if ($this->config->isDebug()) { }
throw new RuntimeException('credentials invalid'); }
} else { } else {
exit("credentials invalid\n"); if (
$this->config->getUsername() !== $this->payload->getUser() ||
$this->config->getPassword() !== $this->payload->getPassword()
) {
if ($this->config->isDebug()) {
throw new RuntimeException('credentials invalid');
} else {
exit("credentials invalid\n");
}
} }
} }

View file

@ -85,7 +85,10 @@ final class Payload
{ {
return return
!empty($this->user) && !empty($this->user) &&
!empty($this->password) && (
$this->user == 'anonymous' ||
!empty($this->password)
) &&
!empty($this->domain) && !empty($this->domain) &&
( (
( (