Skip to content

Commit

Permalink
Show HTTPS hint on login page only when HTTPS is actually served. If …
Browse files Browse the repository at this point in the history
…it is served an a port != 443, add this port as well

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Oct 8, 2023
1 parent 549031d commit eaf068c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions login.lp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ mg.include('scripts/pi-hole/lua/header.lp','r')
<div class="text-center form-group has-error" id="dns-failure-label" style="display: none;">
<label>DNS Server failure detected, log in to see Pi-hole diagnosis messages</label>
</div>
<div class="text-center form-group has-error" id="dns-failure-label" style="display: <? if is_secure then ?>none<? else ?>block<? end ?>;">
<div class="box box-danger" id="insecure-box">
<div class="text-center form-group has-error" id="insecure-box" style="display: none;">
<div class="box box-danger">
<div class="box-header with-border pointer no-user-select">
<h3 class="box-title has-error control-label"><i class="fa fa-fw fa-triangle-exclamation"></i>&nbsp;&nbsp;Insecure network connection&nbsp;&nbsp;<i class="fa fa-fw fa-triangle-exclamation"></i></h3>
</div>
Expand Down
28 changes: 17 additions & 11 deletions scripts/pi-hole/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,24 @@ $(function () {
// Check if we need to login at all
$.ajax({
url: "/api/auth",
}).done(function (data) {
if (data.session.valid === true) redirect();
if (data.session.totp === true) $("#totp_input").removeClass("hidden");
if (data.dns === false) showDNSfailure();
});
})
.done(function (data) {
if (data.session.valid === true) redirect();
if (data.session.totp === true) $("#totp_input").removeClass("hidden");
if (data.dns === false) showDNSfailure();
})
.always(function (data) {
// Generate HTTPS redirection link (only used if not already HTTPS)
if (location.protocol !== "https:" && data.responseJSON.https_port !== 0) {
let url = "https://" + location.hostname;
if (data.responseJSON.https_port !== 443) url += ":" + data.responseJSON.https_port;
url += location.pathname + location.search + location.hash;

$("#https-link").attr("href", url);
$("#insecure-box").show();
}
});

// Clear TOTP field
$("#totp").val("");

// Generate HTTPS redirection link (only used if not already HTTPS)
if (location.protocol !== "https:") {
const url = "https:" + location.href.substring(location.protocol.length);
$("#https-link").attr("href", url);
}
});

0 comments on commit eaf068c

Please sign in to comment.