Enhancement: support pihole v6 with api auth disabled (#3995)

This commit is contained in:
shamoon 2024-09-14 23:32:56 -07:00 committed by GitHub
parent 85736c55c9
commit 587027df37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View file

@ -57,23 +57,27 @@ export default async function piholeProxyHandler(req, res) {
}
// pihole v6
if (!cache.get(`${sessionSIDCacheKey}.${service}`)) {
if (!cache.get(`${sessionSIDCacheKey}.${service}`) && widget.key) {
await login(widget, service);
}
const sid = cache.get(`${sessionSIDCacheKey}.${service}`);
if (!sid) {
if (widget.key && !sid) {
return res.status(500).json({ error: "Failed to authenticate with Pi-hole" });
}
try {
logger.debug("Calling Pi-hole API endpoint: %s", endpoint);
const headers = {
"Content-Type": "application/json",
};
if (sid) {
headers["X-FTL-SID"] = sid;
} else {
logger.debug("Pi-hole request is unauthenticated");
}
[status, , data] = await httpProxy(formatApiCall(widgets[widget.type].api, { ...widget, endpoint }), {
headers: {
"Content-Type": "application/json",
"X-FTL-SID": sid,
},
headers,
});
if (status !== 200) {