Conditional HTTPS hint on login page (#2730)

This commit is contained in:
DL6ER
2023-10-09 21:39:43 +02:00
committed by GitHub
2 changed files with 18 additions and 8 deletions
+2 -2
View File
@@ -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>
+16 -6
View File
@@ -112,15 +112,25 @@ $(function () {
}).done(function (data) {
if (data.session.valid === true) redirect();
if (data.session.totp === true) $("#totp_input").removeClass("hidden");
});
// Get information about HTTPS port and DNS status
$.ajax({
url: "/api/info/login",
}).done(function (data) {
if (data.dns === false) showDNSfailure();
// Generate HTTPS redirection link (only used if not already HTTPS)
if (location.protocol !== "https:" && data.https_port !== 0) {
let url = "https://" + location.hostname;
if (data.https_port !== 443) url += ":" + data.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);
}
});