- ApiSandboxController: reduce scan() returns from 4 to 3 via ternary - ApiDocController: add MIME_JSON constant, extract buildInsomniaRequest() and buildInsomniaBody() to reduce cognitive complexity - Store sessions in Redis to fix SSO disconnect with 2 PHP replicas (round-robin load balancing caused session loss on filesystem storage) - Configure session cookie: 24h lifetime, secure auto, samesite lax - Replace Caddy analytics proxies (/stats/*, /assets/perf.js, /sperf) with direct URLs to tools-security.esy-web.dev and cloudflareinsights.com - Update JS tests for new direct analytics URLs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86 lines
2.2 KiB
JavaScript
86 lines
2.2 KiB
JavaScript
const COOKIE_NAME = 'e_ticket_consent'
|
|
const COOKIE_DAYS = 365
|
|
|
|
function getCookie(name) {
|
|
const match = new RegExp('(^| )' + name + '=([^;]+)').exec(document.cookie)
|
|
|
|
return match ? match[2] : null
|
|
}
|
|
|
|
function setCookie(name, value, days) {
|
|
const date = new Date()
|
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
|
|
document.cookie = name + '=' + value + ';expires=' + date.toUTCString() + ';path=/;SameSite=Lax;Secure'
|
|
}
|
|
|
|
function loadAnalytics() {
|
|
if (document.querySelector('script[data-analytics]')) {
|
|
return
|
|
}
|
|
|
|
if (document.body.dataset.env === 'dev') {
|
|
return
|
|
}
|
|
|
|
const script = document.createElement('script')
|
|
script.defer = true
|
|
script.src = 'https://tools-security.esy-web.dev/script.js'
|
|
script.dataset.websiteId = 'a1f85dd5-741f-4df7-840a-7ef0931ed0cc'
|
|
script.dataset.hostUrl = 'https://tools-security.esy-web.dev'
|
|
script.dataset.analytics = '1'
|
|
document.head.appendChild(script)
|
|
|
|
loadCloudflareTunnel()
|
|
}
|
|
|
|
function loadCloudflareTunnel() {
|
|
if (document.querySelector('script[data-cf-beacon]')) {
|
|
return
|
|
}
|
|
|
|
const script = document.createElement('script')
|
|
script.defer = true
|
|
script.src = 'https://static.cloudflareinsights.com/beacon.min.js'
|
|
script.dataset.cfBeacon = '{"token":"5f2f3b8e1f824be6984a348fe31d2f04","spa":true}'
|
|
document.head.appendChild(script)
|
|
}
|
|
|
|
export function initCookieConsent() {
|
|
const consent = getCookie(COOKIE_NAME)
|
|
|
|
if ('accepted' === consent) {
|
|
loadAnalytics()
|
|
|
|
return
|
|
}
|
|
|
|
if ('refused' === consent) {
|
|
return
|
|
}
|
|
|
|
const banner = document.getElementById('cookie-banner')
|
|
if (!banner) {
|
|
return
|
|
}
|
|
|
|
banner.classList.remove('hidden')
|
|
|
|
const acceptBtn = document.getElementById('cookie-accept')
|
|
const refuseBtn = document.getElementById('cookie-refuse')
|
|
|
|
if (acceptBtn) {
|
|
acceptBtn.addEventListener('click', () => {
|
|
setCookie(COOKIE_NAME, 'accepted', COOKIE_DAYS)
|
|
banner.classList.add('hidden')
|
|
loadAnalytics()
|
|
})
|
|
}
|
|
|
|
if (refuseBtn) {
|
|
refuseBtn.addEventListener('click', () => {
|
|
setCookie(COOKIE_NAME, 'refused', COOKIE_DAYS)
|
|
banner.classList.add('hidden')
|
|
})
|
|
}
|
|
}
|