Support passwordless Pi-hole authentication and UI settings
This commit is contained in:
14
homegate.py
14
homegate.py
@@ -457,10 +457,18 @@ class NPM(API):
|
||||
|
||||
class PiHole(API):
|
||||
def login(self, password):
|
||||
self.session.headers.pop("X-FTL-SID", None)
|
||||
self.session.headers.pop("X-FTL-CSRF", None)
|
||||
self.session.cookies.clear()
|
||||
session = self.call("POST", "/auth", json={"password": password})["session"]
|
||||
require(session.get("valid") and session.get("sid"), "Pi-hole authentication failed")
|
||||
self.session.headers["X-FTL-SID"] = session["sid"]
|
||||
self.session.headers["X-FTL-CSRF"] = session["csrf"]
|
||||
# Pi-hole with authentication disabled returns valid=true, sid=null,
|
||||
# validity=-1 and no CSRF token. It needs neither auth headers nor logout.
|
||||
no_password = "sid" in session and session["sid"] is None and session.get("validity") == -1
|
||||
require(session.get("valid") is True and (session.get("sid") or no_password),
|
||||
"Pi-hole authentication failed")
|
||||
if session.get("sid"):
|
||||
self.session.headers["X-FTL-SID"] = session["sid"]
|
||||
self.session.headers["X-FTL-CSRF"] = session["csrf"]
|
||||
|
||||
def records(self):
|
||||
dns = self.call("GET", "/config/dns")["config"]["dns"]
|
||||
|
||||
Reference in New Issue
Block a user