adasd
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-27 01:09:12 +02:00
parent bd20634ad2
commit 0858d33f38
3 changed files with 78 additions and 13 deletions

View File

@@ -145,7 +145,8 @@
const code = err.http_code ? `HTTP ${err.http_code}` : 'HTTP ?'; const code = err.http_code ? `HTTP ${err.http_code}` : 'HTTP ?';
const scope = err.scope || 'request'; const scope = err.scope || 'request';
const msg = err.error || 'error'; const msg = err.error || 'error';
return `${scope}: ${msg} (${code})`; const hint = err.hint ? `, Hint: ${typeof err.hint === 'string' ? err.hint : JSON.stringify(err.hint)}` : '';
return `${scope}: ${msg} (${code}${hint})`;
}); });
errorEl.textContent = `API Fehler: ${lines.join(' | ')}`; errorEl.textContent = `API Fehler: ${lines.join(' | ')}`;
} else { } else {

View File

@@ -3,12 +3,10 @@
"title": "Pi-hole", "title": "Pi-hole",
"description": "Pi-hole Monitoring, Listen und Steuerung fuer mehrere Instanzen.", "description": "Pi-hole Monitoring, Listen und Steuerung fuer mehrere Instanzen.",
"actions": [ "actions": [
{ "label": "Zur Startseite", "href": "/", "variant": "ghost" }, { "label": "Zur Startseite", "href": "/", "variant": "ghost" }
{ "label": "Instanzen", "href": "/module/pihole/instances", "variant": "secondary" }
], ],
"tabs": [ "tabs": [
{ "label": "Dashboard", "href": "/module/pihole" }, { "label": "Dashboard", "href": "/module/pihole" },
{ "label": "Instanzen", "href": "/module/pihole/instances" },
{ "label": "Listen", "href": "/module/pihole/lists" }, { "label": "Listen", "href": "/module/pihole/lists" },
{ "label": "Queries", "href": "/module/pihole/queries" } { "label": "Queries", "href": "/module/pihole/queries" }
] ]

View File

@@ -87,6 +87,32 @@ $httpRequest = function (string $method, string $url, array $headers, ?string $b
return ['ok' => false, 'error' => 'invalid_json', 'http_code' => $httpCode, 'raw' => $raw, 'url' => $url]; return ['ok' => false, 'error' => 'invalid_json', 'http_code' => $httpCode, 'raw' => $raw, 'url' => $url];
} }
if ($httpCode >= 400) {
$apiError = is_array($data['error'] ?? null) ? $data['error'] : [];
return [
'ok' => false,
'error' => (string)($apiError['message'] ?? $apiError['key'] ?? ('HTTP ' . $httpCode)),
'error_key' => (string)($apiError['key'] ?? ''),
'hint' => $apiError['hint'] ?? null,
'http_code' => $httpCode,
'data' => $data,
'url' => $url,
];
}
if (isset($data['error'])) {
$apiError = is_array($data['error']) ? $data['error'] : [];
return [
'ok' => false,
'error' => (string)($apiError['message'] ?? $apiError['key'] ?? 'api_error'),
'error_key' => (string)($apiError['key'] ?? ''),
'hint' => $apiError['hint'] ?? null,
'http_code' => $httpCode,
'data' => $data,
'url' => $url,
];
}
return ['ok' => true, 'data' => $data, 'http_code' => $httpCode, 'url' => $url]; return ['ok' => true, 'data' => $data, 'http_code' => $httpCode, 'url' => $url];
}; };
@@ -156,7 +182,23 @@ $v6Request = function (array $instance, string $path, string $method, array $pay
return $httpRequest($method, $url, $headers, $body, $verify, $timeout); return $httpRequest($method, $url, $headers, $body, $verify, $timeout);
}; };
$detectApi = function (array $instance) use ($v6Auth, $v6Request, $v5Request): array { $v6RequestAny = function (array $instance, array $paths, string $method, array $payload, string $sid) use ($v6Request): array {
$last = ['ok' => false, 'error' => 'no_path', 'http_code' => 0, 'url' => ''];
foreach ($paths as $path) {
$result = $v6Request($instance, (string)$path, $method, $payload, $sid);
if (($result['ok'] ?? false) === true) {
return $result;
}
$last = $result;
$httpCode = (int)($result['http_code'] ?? 0);
if (!in_array($httpCode, [0, 400, 404], true)) {
return $result;
}
}
return $last;
};
$detectApi = function (array $instance) use ($v6Auth, $v6RequestAny, $v5Request): array {
$sid = ''; $sid = '';
$authRes = null; $authRes = null;
if (!empty($instance['password'])) { if (!empty($instance['password'])) {
@@ -166,7 +208,7 @@ $detectApi = function (array $instance) use ($v6Auth, $v6Request, $v5Request): a
} }
} }
$probe = $v6Request($instance, 'stats/summary', 'GET', [], $sid); $probe = $v6RequestAny($instance, ['stats/summary', 'summary'], 'GET', [], $sid);
if ($probe['ok'] || in_array((int)($probe['http_code'] ?? 0), [401, 403], true)) { if ($probe['ok'] || in_array((int)($probe['http_code'] ?? 0), [401, 403], true)) {
return ['version' => 6, 'sid' => $sid, 'probe' => $probe, 'auth' => $authRes]; return ['version' => 6, 'sid' => $sid, 'probe' => $probe, 'auth' => $authRes];
} }
@@ -306,6 +348,8 @@ if ($action === 'dashboard') {
return [ return [
'scope' => $scope, 'scope' => $scope,
'error' => $result['error'] ?? 'error', 'error' => $result['error'] ?? 'error',
'error_key' => $result['error_key'] ?? '',
'hint' => $result['hint'] ?? null,
'http_code' => $result['http_code'] ?? 0, 'http_code' => $result['http_code'] ?? 0,
'url' => $result['url'] ?? '', 'url' => $result['url'] ?? '',
]; ];
@@ -333,17 +377,22 @@ if ($action === 'dashboard') {
$errors[] = $makeError('summary', $summary); $errors[] = $makeError('summary', $summary);
} }
$blocking = $v6Request($instance, 'dns/blocking', 'GET', [], $sid); $blocking = $v6RequestAny($instance, ['dns/blocking'], 'GET', [], $sid);
if (!$blocking['ok']) { if (!$blocking['ok']) {
$errors[] = $makeError('blocking', $blocking); $errors[] = $makeError('blocking', $blocking);
} }
$queries = $v6Request($instance, 'queries?from=' . $from . '&until=' . $now . '&length=2000', 'GET', [], $sid); $queries = $v6RequestAny($instance, [
'queries',
'queries/all',
'queries?from=' . $from . '&until=' . $now,
'queries/all?from=' . $from . '&until=' . $now,
], 'GET', [], $sid);
if (!$queries['ok']) { if (!$queries['ok']) {
$errors[] = $makeError('queries', $queries); $errors[] = $makeError('queries', $queries);
} }
$upstreams = $v6Request($instance, 'stats/upstreams', 'GET', [], $sid); $upstreams = $v6RequestAny($instance, ['stats/upstreams', 'upstreams'], 'GET', [], $sid);
if (!$upstreams['ok']) { if (!$upstreams['ok']) {
$errors[] = $makeError('upstreams', $upstreams); $errors[] = $makeError('upstreams', $upstreams);
} }
@@ -383,7 +432,14 @@ if ($action === 'dashboard') {
} }
if ($queries['ok'] && is_array($queries['data'])) { if ($queries['ok'] && is_array($queries['data'])) {
$queryList = (array)($queries['data']['queries'] ?? []); $queryList = [];
if (isset($queries['data']['queries']) && is_array($queries['data']['queries'])) {
$queryList = $queries['data']['queries'];
} elseif (isset($queries['data']['data']) && is_array($queries['data']['data'])) {
$queryList = $queries['data']['data'];
} elseif (array_is_list($queries['data'])) {
$queryList = $queries['data'];
}
$topAds = []; $topAds = [];
$topQueries = []; $topQueries = [];
$sources = []; $sources = [];
@@ -418,8 +474,11 @@ if ($action === 'dashboard') {
$topQueries[$domain] = ($topQueries[$domain] ?? 0) + 1; $topQueries[$domain] = ($topQueries[$domain] ?? 0) + 1;
} }
$statusVal = (string)($entry['status'] ?? ''); $statusVal = strtoupper((string)($entry['status'] ?? ''));
$isBlocked = str_contains($statusVal, 'GRAVITY') || str_contains($statusVal, 'BLOCK'); $isBlocked = str_contains($statusVal, 'GRAVITY')
|| str_contains($statusVal, 'BLOCK')
|| str_contains($statusVal, 'DENY')
|| str_contains($statusVal, 'CNAME');
if ($isBlocked && $domain !== '') { if ($isBlocked && $domain !== '') {
$topAds[$domain] = ($topAds[$domain] ?? 0) + 1; $topAds[$domain] = ($topAds[$domain] ?? 0) + 1;
$recent[] = ['domain' => $domain, 'instance' => $instance['name']]; $recent[] = ['domain' => $domain, 'instance' => $instance['name']];
@@ -432,7 +491,14 @@ if ($action === 'dashboard') {
} }
if ($upstreams['ok'] && is_array($upstreams['data'])) { if ($upstreams['ok'] && is_array($upstreams['data'])) {
$upList = (array)($upstreams['data']['upstreams'] ?? []); $upList = [];
if (isset($upstreams['data']['upstreams']) && is_array($upstreams['data']['upstreams'])) {
$upList = $upstreams['data']['upstreams'];
} elseif (isset($upstreams['data']['data']) && is_array($upstreams['data']['data'])) {
$upList = $upstreams['data']['data'];
} elseif (array_is_list($upstreams['data'])) {
$upList = $upstreams['data'];
}
$forwardDestData = []; $forwardDestData = [];
foreach ($upList as $item) { foreach ($upList as $item) {
if (!is_array($item)) { if (!is_array($item)) {