Skip to content

Commit

Permalink
Show warning if user already set an application password (#3048)
Browse files Browse the repository at this point in the history
  • Loading branch information
DL6ER authored Jun 27, 2024
2 parents 103bfed + d3ac2fe commit 68f2512
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
28 changes: 27 additions & 1 deletion scripts/pi-hole/js/settings-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var apiSessionsTable = null;
var ownSessionID = null;
var deleted = 0;
var TOTPdata = null;
var apppwSet = false;

function renderBool(data, type) {
// Display and search content
Expand Down Expand Up @@ -266,6 +267,13 @@ function processWebServerConfig() {
})
.done(function (data) {
setConfigValues("webserver", "webserver", data.config.webserver);
if (data.config.webserver.api.app_pwhash.value.length > 0) {
apppwSet = true;
$("#existing_apppw_warning").show();
$("#apppw_submit").text("Replace app password");
$("#apppw_submit").removeClass("btn-success");
$("#apppw_submit").addClass("btn-warning");
} else $("#apppw_clear").hide();
})
.fail(function (data) {
apiFailure(data);
Expand Down Expand Up @@ -327,7 +335,25 @@ $("#modal-apppw").on("shown.bs.modal", function () {

$("#apppw_submit").on("click", function () {
// Enable app password
setAppPassword();
if (!apppwSet) {
return setAppPassword();
}

// Else: Show confirm dialog
$.confirm({
text: "Are you sure you want to replace your previous app password? You will need to re-login to continue using the web interface.",
title: "Confirmation required",
confirm: setAppPassword,
cancel: function () {
// nothing to do
},
confirmButton: "Yes, replace password",
cancelButton: "No, go back",
post: true,
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-success",
dialogClass: "modal-dialog",
});
});

$("#apppw_clear").on("click", function () {
Expand Down
7 changes: 5 additions & 2 deletions settings-api.lp
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,13 @@ mg.include('scripts/pi-hole/lua/settings_header.lp','r')
<p>IMPORTANT: The app password generated here will only be shown
once and cannot be recovered. Make sure to store it in a safe
place!</p>
<div class="callout callout-warning" style="display: none;" id="existing_apppw_warning">
<h4>Application password already configured</h4>Enabling the new app password will forcefully log out all existing applications.
</div>
</div>
<div class="modal-footer">
<button type="button" id="apppw_clear" class="btn btn-default btn-danger pull-left">Remove currently set app password</button>
<button type="button" id="apppw_submit" class="btn btn-default btn-success">Enable new app password</button>
<button type="button" id="apppw_clear" class="btn btn-danger pull-left">Remove currently set app password</button>
<button type="button" id="apppw_submit" class="btn btn-success">Enable new app password</button>
</div>
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion style/themes/default-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ body {
h4 {
color: #44def1;
}
.callout h4 {
color: inherit;
}
.content-header > .breadcrumb > li > a {
color: #bec5cb;
}
Expand Down Expand Up @@ -627,7 +630,12 @@ input[type="password"]::-webkit-caps-lock-indicator {
}

.close {
color: #383838;
color: #fff;
text-shadow: 0 1px 0 #000;
}
.close:focus,
.close:hover {
color: #fff;
}

.login-page {
Expand Down
12 changes: 11 additions & 1 deletion style/themes/high-contrast-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ a:active {
h4 {
color: #44def1;
}
.callout h4 {
color: inherit;
}

.page-header {
border-color: #202830;
Expand Down Expand Up @@ -820,7 +823,14 @@ input[type="password"]::-webkit-caps-lock-indicator {
}

.close {
color: #383838;
color: #fff;
text-shadow: 0 1px 0 #000;
opacity: 0.4;
}
.close:focus,
.close:hover {
color: #fff;
opacity: 0.8;
}

.login-page {
Expand Down

0 comments on commit 68f2512

Please sign in to comment.