From fff54aef3f6f913b8ff270d1ffc59abbb023852d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Feb 2023 19:09:52 +0100 Subject: [PATCH] Remove further obsolete PHP code Signed-off-by: DL6ER --- login.php | 1 - scripts/pi-hole/js/login.js | 86 ++++++++++++++++++++ scripts/pi-hole/php/footer.php | 12 +-- scripts/pi-hole/php/header.php | 3 +- scripts/pi-hole/php/header_authenticated.php | 5 +- scripts/pi-hole/php/theme.php | 55 ------------- settings.php | 2 +- 7 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 scripts/pi-hole/js/login.js delete mode 100644 scripts/pi-hole/php/theme.php diff --git a/login.php b/login.php index e837e336..8ca6e955 100644 --- a/login.php +++ b/login.php @@ -9,7 +9,6 @@ */ $wrongpassword = false; -require 'scripts/pi-hole/php/theme.php'; require 'scripts/pi-hole/php/header.php'; ?> diff --git a/scripts/pi-hole/js/login.js b/scripts/pi-hole/js/login.js new file mode 100644 index 00000000..fe9890a5 --- /dev/null +++ b/scripts/pi-hole/js/login.js @@ -0,0 +1,86 @@ +/* Pi-hole: A black hole for Internet advertisements + * (c) 2023 Pi-hole, LLC (https://pi-hole.net) + * Network-wide ad blocking via your own hardware. + * + * This file is copyright under the latest version of the EUPL. + * Please see LICENSE file for your rights under this license. */ + +/* global sha256:false */ + +function getParams() { + var GETDict = {}; + window.location.search + .substr(1) + .split("&") + .forEach(function (item) { + GETDict[item.split("=")[0]] = item.split("=")[1]; + }); + return GETDict; +} + +function computeResponse(password, challenge) { + // Compute password hash twice to mitigate rainbow + // table vulnerability + return sha256(challenge + ":" + sha256(sha256(password))); +} + +function redirect() { + // Login succeeded or not needed (empty password) + // Default: Send back to index.php (dashboard) + var target = "index.php"; + + // If specified: Send to requested page + var GETDict = getParams(); + if ("target" in GETDict) { + target = GETDict.target; + } + + // Redirect to target + window.location.replace(target); +} + +function doLogin(response) { + $.ajax({ + url: "/api/auth", + method: "POST", + data: JSON.stringify({ response: response }), + }) + .done(function () { + redirect(); + }) + .fail(function (data) { + if (data.status === 401) { + // Login failed + $("#pw-field").addClass("has-error"); + $("#error-label").show(); + } + }); +} + +$("#loginform").submit(function (e) { + // Cancel the native submit event (prevent the form from being + // submitted) because we want to do a two-step challenge-response login + e.preventDefault(); + + // Get challenge + $.ajax({ + url: "/api/auth", + method: "GET", + }).done(function (data) { + if ("challenge" in data) { + var response = computeResponse($("#loginpw").val(), data.challenge); + doLogin(response); + } else if (data.session.valid === true) + // Password may have been remove meanwhile + redirect(); + }); +}); + +$(function () { + // Check if we need to login at all + $.ajax({ + url: "/api/auth", + }).done(function (data) { + if (data.session.valid === true) redirect(); + }); +}); diff --git a/scripts/pi-hole/php/footer.php b/scripts/pi-hole/php/footer.php index c4a0bf0f..8a333efd 100644 --- a/scripts/pi-hole/php/footer.php +++ b/scripts/pi-hole/php/footer.php @@ -40,16 +40,6 @@ -