Console: Fix delete confirmation on /configplugins

Replace /configclients and /configplugins onclick with js file
Remove unsafe CSP on /configclients
This commit is contained in:
zzz
2020-05-11 16:43:53 +00:00
parent 4da58258f5
commit 7da2ac9ef3
5 changed files with 36 additions and 5 deletions

View File

@ -401,9 +401,7 @@ public class ConfigClientsHelper extends HelperBase {
}
if (showDeleteButton && (!edit) && !ro) {
buf.append("<button type=\"submit\" title=\"").append(_t("Delete")).append("\" class=\"control delete\" name=\"action\" value=\"Delete ").append(index)
.append("\" onclick=\"if (!confirm('")
.append(_t("Are you sure you want to delete {0}?", _t(escapedName)))
.append("')) { return false; }\">")
.append("\" client=\"").append(_t(escapedName)).append("\">")
.append(_t("Delete")).append("<span class=hide> ").append(index).append("</span></button>");
}
buf.append("</td><td align=\"left\">");

View File

@ -3,7 +3,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<%@include file="css.jsi" %>
<%@include file="csp-unsafe.jsi" %>
<%=intl.title("config clients")%>
<style type='text/css'>
button span.hide{
@ -12,6 +11,10 @@ button span.hide{
input.default { width: 1px; height: 1px; visibility: hidden; }
</style>
<%@include file="summaryajax.jsi" %>
<script nonce="<%=cspNonce%>" type="text/javascript">
var deleteMessage = "<%=intl._t("Are you sure you want to delete {0}?")%>";
</script>
<script src="/js/configclients.js?<%=net.i2p.CoreVersion.VERSION%>" type="text/javascript"></script>
</head><body>
<%@include file="summary.jsi" %>
<jsp:useBean class="net.i2p.router.web.helpers.ConfigClientsHelper" id="clientshelper" scope="request" />

View File

@ -11,6 +11,10 @@ button span.hide{
input.default { width: 1px; height: 1px; visibility: hidden; }
</style>
<%@include file="summaryajax.jsi" %>
<script nonce="<%=cspNonce%>" type="text/javascript">
var deleteMessage = "<%=intl._t("Are you sure you want to delete {0}?")%>";
</script>
<script src="/js/configclients.js?<%=net.i2p.CoreVersion.VERSION%>" type="text/javascript"></script>
</head><body>
<%@include file="summary.jsi" %>
<jsp:useBean class="net.i2p.router.web.helpers.ConfigClientsHelper" id="clientshelper" scope="request" />

View File

@ -0,0 +1,23 @@
function init()
{
var buttons = document.getElementsByClassName("delete");
for(index = 0; index < buttons.length; index++)
{
var button = buttons[index];
addClickHandler(button);
}
}
function addClickHandler(elem)
{
elem.addEventListener("click", function() {
if (!confirm(deleteMessage.replace("{0}", elem.getAttribute("client")))) {
event.preventDefault();
return false;
}
});
}
document.addEventListener("DOMContentLoaded", function() {
init();
}, true);

View File

@ -62,4 +62,7 @@ function toggleAll(category)
}
}
}
window.addEventListener("load", init);
document.addEventListener("DOMContentLoaded", function() {
init();
}, true);