Replace inline onclick with addEventListener inside .js file to be compatible with CSP (v6) (#3104)

This commit is contained in:
Dominik
2024-08-18 18:55:02 +02:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2023 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
/* global utils:false */
document.addEventListener("DOMContentLoaded", () => {
const logoutButton = document.getElementById("logout-button");
logoutButton.addEventListener("click", () => {
utils.doLogout();
});
});

View File

@@ -9,6 +9,7 @@
]]--
mg.include('header.lp','r')
?>
<script src="<?=pihole.fileversion('scripts/pi-hole/js/logout.js')?>"></script>
<script src="<?=pihole.fileversion('scripts/vendor/select2.min.js')?>"></script>
<script src="<?=pihole.fileversion('scripts/vendor/datatables.min.js')?>"></script>
<script src="<?=pihole.fileversion('scripts/vendor/datatables.select.min.js')?>"></script>
@@ -85,7 +86,7 @@ mg.include('header.lp','r')
<a class="btn-link" href="https://github.com/pi-hole" rel="noopener" target="_blank"><i class="fa-fw menu-icon fab fa-github"></i> GitHub</a>
<a class="btn-link" href="https://discourse.pi-hole.net/c/announcements/5" rel="noopener" target="_blank"><i class="fa-fw menu-icon fa-solid fa-rocket"></i> Pi-hole Releases</a>
<? if pihole.needLogin() then ?>
<a class="btn-link" href="#" onclick="utils.doLogout();"><i class="fa-fw menu-icon fa-solid fa-arrow-right-from-bracket"></i> Log out</a>
<a class="btn-link" href="#" id="logout-button"><i class="fa-fw menu-icon fa-solid fa-arrow-right-from-bracket"></i> Log out</a>
<? end ?>
</li>
</ul>