pi hole
This commit is contained in:
@@ -91,8 +91,8 @@ $httpRequest = function (string $method, string $url, array $headers, ?string $b
|
||||
};
|
||||
|
||||
$v5Request = function (array $instance, array $params) use ($normalizeApiPath, $httpRequest): array {
|
||||
if (!empty($instance['token']) && !isset($params['auth'])) {
|
||||
$params['auth'] = $instance['token'];
|
||||
if (!empty($instance['password']) && !isset($params['auth'])) {
|
||||
$params['auth'] = $instance['password'];
|
||||
}
|
||||
|
||||
$url = $normalizeApiPath((string)$instance['url'], (string)$instance['api_path']);
|
||||
@@ -116,7 +116,7 @@ $v6Auth = function (array $instance) use ($httpRequest): array {
|
||||
$timeout = 8;
|
||||
}
|
||||
$verify = !empty($instance['verify_tls']);
|
||||
$payload = ['password' => (string)($instance['token'] ?? '')];
|
||||
$payload = ['password' => (string)($instance['password'] ?? '')];
|
||||
$body = json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
$res = $httpRequest('POST', $url, ['Accept: application/json', 'Content-Type: application/json'], $body, $verify, $timeout);
|
||||
if (!$res['ok']) {
|
||||
@@ -159,7 +159,7 @@ $v6Request = function (array $instance, string $path, string $method, array $pay
|
||||
$detectApi = function (array $instance) use ($v6Auth, $v6Request, $v5Request): array {
|
||||
$sid = '';
|
||||
$authRes = null;
|
||||
if (!empty($instance['token'])) {
|
||||
if (!empty($instance['password'])) {
|
||||
$authRes = $v6Auth($instance);
|
||||
if (($authRes['ok'] ?? false) && !empty($authRes['sid'])) {
|
||||
$sid = (string)$authRes['sid'];
|
||||
@@ -621,7 +621,7 @@ if ($action === 'test') {
|
||||
$message = 'Host nicht erreichbar oder kein HTTP-Response.';
|
||||
} elseif ($httpCode === 401 || $httpCode === 403) {
|
||||
$status = 'auth';
|
||||
$message = 'API Passwort falsch oder nicht berechtigt.';
|
||||
$message = 'Passwort oder App-Passwort falsch oder nicht berechtigt.';
|
||||
} elseif ($error === 'invalid_json') {
|
||||
$status = 'invalid';
|
||||
$message = 'API antwortet nicht mit JSON. URL pruefen.';
|
||||
@@ -659,7 +659,7 @@ if ($action === 'test') {
|
||||
$message = 'Host nicht erreichbar oder kein HTTP-Response.';
|
||||
} elseif ($httpCode === 401 || $httpCode === 403) {
|
||||
$status = 'auth';
|
||||
$message = 'API Token/Passwort falsch oder nicht berechtigt.';
|
||||
$message = 'Passwort oder Legacy-API-Token falsch oder nicht berechtigt.';
|
||||
} elseif ($error === 'invalid_json') {
|
||||
$status = 'invalid';
|
||||
$message = 'API antwortet nicht mit JSON. URL oder API-Pfad pruefen.';
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user