pi hole
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-27 00:41:37 +02:00
parent e7a1878c72
commit 463b2cf5e1
6 changed files with 40 additions and 22 deletions

View File

@@ -11,6 +11,15 @@ $notice = null;
$error = null;
$loadInstances = function (array $settings): array {
$normalizeSecret = static function (array $row): string {
$password = trim((string)($row['password'] ?? ''));
if ($password !== '') {
return $password;
}
return trim((string)($row['token'] ?? ''));
};
$instances = [];
$rawJson = trim((string)($settings['instances_json'] ?? ''));
if ($rawJson !== '') {
@@ -29,7 +38,7 @@ $loadInstances = function (array $settings): array {
'id' => $id,
'name' => trim((string)($row['name'] ?? '')) ?: $id,
'url' => $url,
'token' => trim((string)($row['token'] ?? '')),
'password' => $normalizeSecret($row),
'is_primary' => !empty($row['is_primary']),
];
}
@@ -46,7 +55,7 @@ $loadInstances = function (array $settings): array {
'id' => $key,
'name' => trim((string)($settings[$key . '_name'] ?? '')) ?: ($key === 'primary' ? 'Primaer' : 'Sekundaer'),
'url' => $url,
'token' => trim((string)($settings[$key . '_token'] ?? '')),
'password' => trim((string)($settings[$key . '_token'] ?? '')),
'is_primary' => $key === 'primary',
];
}
@@ -74,7 +83,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$instanceId = trim((string)($_POST['instance_id'] ?? ''));
$name = trim((string)($_POST['name'] ?? ''));
$url = trim((string)($_POST['url'] ?? ''));
$token = trim((string)($_POST['token'] ?? ''));
$password = trim((string)($_POST['password'] ?? ''));
$isPrimary = isset($_POST['is_primary']);
if ($deleteId !== '') {
@@ -87,11 +96,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($instanceId === '' || $url === '') {
$error = 'Bitte ID und URL angeben.';
} else {
$existingToken = '';
$existingPassword = '';
if ($currentId !== '' && isset($instances[$currentId])) {
$existingToken = (string)($instances[$currentId]['token'] ?? '');
$existingPassword = (string)($instances[$currentId]['password'] ?? '');
}
$tokenToStore = $token !== '' ? $token : $existingToken;
$passwordToStore = $password !== '' ? $password : $existingPassword;
if ($currentId !== '' && $currentId !== $instanceId) {
unset($instances[$currentId]);
}
@@ -99,7 +108,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'id' => $instanceId,
'name' => $name !== '' ? $name : $instanceId,
'url' => $url,
'token' => $tokenToStore,
'password' => $passwordToStore,
'is_primary' => $isPrimary,
];
@@ -215,8 +224,8 @@ if ($primaryId === '') {
<input type="text" name="url" placeholder="http://pi-hole.local" required>
</label>
<label class="form-field">
<span class="muted">API Token / Web-Passwort (v6) (leer lassen = unveraendert)</span>
<input type="password" name="token" placeholder="Token" autocomplete="new-password">
<span class="muted">Passwort / App-Passwort (leer lassen = unveraendert)</span>
<input type="password" name="password" placeholder="Pi-hole Passwort oder App-Passwort" autocomplete="new-password">
</label>
<label class="form-field" style="align-items:center;">
<span class="muted">Als Primaer verwenden</span>