From a9d84da3b3df971232b16e4a75f9cb8df6d7efbe Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 20 May 2020 11:12:49 +0000
Subject: [PATCH] i2ptunnel, SusiDNS: Replace onblur with CSP-safe js

---
 apps/i2ptunnel/jsp/editClient.jsi        |  2 +-
 apps/i2ptunnel/jsp/editServer.jsi        |  4 ++--
 apps/routerconsole/jsp/js/resetScroll.js | 26 ++++++++++++++++++++++--
 apps/susidns/src/jsp/addressbook.jsp     |  2 +-
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/apps/i2ptunnel/jsp/editClient.jsi b/apps/i2ptunnel/jsp/editClient.jsi
index 2b0c491939..e0bafbdb49 100644
--- a/apps/i2ptunnel/jsp/editClient.jsi
+++ b/apps/i2ptunnel/jsp/editClient.jsi
@@ -504,7 +504,7 @@
             </td>
         </tr><tr>
             <td colspan="2">
-                <div class="displayText" title="<%=intl._t("Read Only: Local Destination (if known)")%>" tabindex="0" onblur="resetScrollLeft(this)"><%=destb64%></div>
+                <div class="displayText resetScrollLeft" title="<%=intl._t("Read Only: Local Destination (if known)")%>" tabindex="0"><%=destb64%></div>
             </td>
         </tr><tr>
             <td colspan="2">
diff --git a/apps/i2ptunnel/jsp/editServer.jsi b/apps/i2ptunnel/jsp/editServer.jsi
index c731cb40fd..8b07eadddc 100644
--- a/apps/i2ptunnel/jsp/editServer.jsi
+++ b/apps/i2ptunnel/jsp/editServer.jsi
@@ -181,7 +181,7 @@
             </th>
         </tr><tr>
             <td>
-                <div class="displayText" title="<%=intl._t("Read Only: Local Destination (if known)")%>" tabindex="0" onblur="resetScrollLeft(this)"><%=editBean.getDestinationBase64(curTunnel)%></div>
+                <div class="displayText resetScrollLeft" title="<%=intl._t("Read Only: Local Destination (if known)")%>" tabindex="0"><%=editBean.getDestinationBase64(curTunnel)%></div>
             </td><td>
 <%
                        String value3 = editBean.getPrivateKeyFile(curTunnel);
@@ -739,7 +739,7 @@
             </th>
         </tr><tr>
             <td colspan="2">
-                <div class="displayText" title="<%=intl._t("Read Only: Alternate Local Destination")%>" onblur="resetScrollLeft(this)"><%=ab64%></div>
+                <div class="displayText resetScrollLeft" title="<%=intl._t("Read Only: Alternate Local Destination")%>"><%=ab64%></div>
             </td>
         </tr><tr>
             <td colspan="2">
diff --git a/apps/routerconsole/jsp/js/resetScroll.js b/apps/routerconsole/jsp/js/resetScroll.js
index 0c7a578d6b..3abb5a4d47 100644
--- a/apps/routerconsole/jsp/js/resetScroll.js
+++ b/apps/routerconsole/jsp/js/resetScroll.js
@@ -1,3 +1,21 @@
+function initResetScroll()
+{
+	var buttons = document.getElementsByClassName("resetScrollLeft");
+	for(index = 0; index < buttons.length; index++)
+	{
+		var button = buttons[index];
+		addBlurHandler(button);
+	}
+}
+
+function addBlurHandler(elem)
+{
+        elem.addEventListener("blur", function() {
+            resetScrollLeft(elem);
+        });
+}
+
+
 // resets scroll position of element
 // use with onblur to clear scroll position when element loses focus
 
@@ -9,7 +27,11 @@ function resetScrollLeft(element) {
 }
 
 // reset scroll to top position
-
+// unused
 function resetScrollTop(element) {
     element.scrollTop = 0;
-}
\ No newline at end of file
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+    initResetScroll();
+}, true);
diff --git a/apps/susidns/src/jsp/addressbook.jsp b/apps/susidns/src/jsp/addressbook.jsp
index 56db76adac..d15635c721 100644
--- a/apps/susidns/src/jsp/addressbook.jsp
+++ b/apps/susidns/src/jsp/addressbook.jsp
@@ -201,7 +201,7 @@ ${book.loadBookMessages}
 <td class="names"><span class="addrhlpr"><a href="http://${addr.b32}/" target="_blank" title="<%=intl._t("Base 32 address")%>">b32</a></span></td>
 <td class="helper"><a href="http://${addr.name}/?i2paddresshelper=${addr.destination}" target="_blank" title="<%=intl._t("Helper link to share host address with option to add to addressbook")%>">link</a></td>
 <td class="names"><span class="addrhlpr"><a href="details?h=${addr.name}&amp;book=${book.book}" title="<%=intl._t("More information on this entry")%>"><%=intl._t("details")%></a></span></td>
-<td class="destinations"><div class="destaddress" name="dest_${addr.name}" width="200px" tabindex="0" onblur="resetScrollLeft(this)">${addr.destination}</div></td>
+<td class="destinations"><div class="destaddress resetScrollLeft" name="dest_${addr.name}" width="200px" tabindex="0">${addr.destination}</div></td>
 
 <c:if test="${book.validBook}">
 <td class="checkbox"><input type="checkbox" name="checked" value="${addr.name}" title="<%=intl._t("Mark for deletion")%>"></td>
-- 
GitLab