Added better debugging

This commit is contained in:
2025-07-22 19:14:40 +02:00
parent 3bc64023af
commit c2f83abb60
6 changed files with 95 additions and 10 deletions

View File

@@ -0,0 +1,28 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Injects a catcher, which catches the actions of all logout elements and redirects them to the central logout."
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
license: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl"
min_ansible_version: "2.9"
platforms:
- name: Archlinux
versions:
- rolling
galaxy_tags:
- nginx
- javascript
- csp
- sub_filter
- injection
- global
repository: "https://s.veen.world/cymais"
documentation: "https://s.veen.world/cymais"
issue_tracker_url: "https://s.veen.world/cymaisissues"
dependencies:
- srv-web-7-4-core

View File

@@ -0,0 +1,13 @@
# run_once_srv_web_7_7_inj_javascript: deactivated
- name: "Load JavaScript code for '{{ application_id }}'"
set_fact:
javascript_code: "{{ lookup('template', modifier_javascript_template_file) }}"
- name: "Collapse Javascript code into one-liner for '{{application_id}}'"
set_fact:
javascript_code_one_liner: "{{ javascript_code | to_one_liner }}"
- name: "Append Javascript CSP hash for '{{application_id}}'"
set_fact:
applications: "{{ applications | append_csp_hash(application_id, javascript_code_one_liner) }}"
changed_when: false

View File

@@ -0,0 +1 @@
<script>{{ javascript_code_one_liner | replace("'", "\\'") }}</script>

View File

@@ -0,0 +1,38 @@
(function() {
const logoutUrlBase = 'https://auth.cymais.cloud/realms/cymais.cloud/protocol/openid-connect/logout';
const redirectUri = encodeURIComponent('https://cymais.cloud');
const logoutUrl = `${logoutUrlBase}?redirect_uri=${redirectUri}`;
// Check if a string matches logout keywords
function matchesLogout(str) {
return str && /logout|log\s*out|abmelden/i.test(str);
}
// Check if any attribute name contains "logout" (case-insensitive)
function hasLogoutAttribute(el) {
for (let attr of el.attributes) {
if (/logout/i.test(attr.name)) {
return true;
}
}
return false;
}
// Find all elements
const allElements = document.querySelectorAll('*');
allElements.forEach(el => {
if (
matchesLogout(el.getAttribute('name')) ||
matchesLogout(el.id) ||
matchesLogout(el.className) ||
matchesLogout(el.innerText) ||
hasLogoutAttribute(el)
) {
el.style.cursor = 'pointer';
el.addEventListener('click', function(event) {
event.preventDefault();
window.location.href = logoutUrl;
});
}
});
})();

View File

@@ -0,0 +1 @@
modifier_javascript_template_file: "{{ application_id | abs_role_path_by_application_id }}/templates/javascript.js.j2"