Koolbox commited on
Commit
58e626f
·
verified ·
1 Parent(s): b414820

Detailed Data

Browse files

Showing first 5 rows. Click "Expand" to see everything.
Expand
Because 95% of attacks have a human interaction
`; const blob = new Blob(['\ufeff', content], { type: 'application/msword' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'security_report.doc'; link.click(); } // File Handling function handleFile(file) { try { clearError(); if (!file) return; statusEl.textContent = 'Loaded: ' + file.name; const ext = (file.name.split('.').pop() || '').toLowerCase(); if (ext === 'csv') { Papa.parse(file, { header: true, skipEmptyLines: true, complete: (res) => { try { safeIngest(res.data); } catch (err) { showError('CSV parsing error: ' + err.message); } }, error: (err) => { showError('CSV read error: ' + err.message); } }); } else if (ext === 'ods') { const reader = new FileReader(); reader.onload = function(ev) { try { const data = new Uint8Array(ev.target.result); const wb = XLSX.read(data, { type: 'array' }); const ws = wb.Sheets[wb.SheetNames[0]]; const json = XLSX.utils.sheet_to_json(ws, { defval: "" }); safeIngest(json); } catch (err) { showError('Could not read ODS: ' + err.message); } }; reader.onerror = function(err) { showError('File read error: ' + err.message); }; reader.readAsArrayBuffer(file); } else { showError('Unsupported file (use .csv or .ods)'); } } catch (err) { showError('File handling error: ' + err.message); } } // Safe Data Ingestion function safeIngest(rows) { try { ingest(rows); } catch (err) { showError('Build failed: ' + err.message); } } // Data Ingestion and Processing function ingest(rows) { if (!rows || !Array.isArray(rows)) { throw new Error('Invalid data format received.'); } rawRows = rows; if (!rawRows.length) { throw new Error('No rows found in file.'); } const cols = Object.keys(rawRows[0] || {}).map(c => c.replace(/^\uFEFF/, '')); if (!cols.length) { throw new Error('No columns detected. Ensure the first row has headers.'); } const colEmail = findCol(cols, ['email']); const colName = findCol(cols, ['name', 'full name']); const colScenario = findCol(cols, ['scenario', 'campaign', 'module']); const colClicked = findCol(cols, ['clicked', 'click']); const colTrained = findCol(cols, ['trained', 'completed', 'complete']); const colTrainedAt = findCol(cols, ['trained at', 'trained_at', 'trainedat', 'completed at', 'completion']); const missing = []; if (!colEmail) missing.push('Email'); if (!colScenario) missing.push('Scenario'); if (!colClicked) missing.push('Clicked (Y/N)'); if (!colTrained) missing.push('Trained (Y/N)'); if (missing.length) { throw new Error( 'Missing expected column(s): ' + missing.join(', ') + '\nFound columns: ' + cols.join(', ') + '\nTip: headers can include these keywords:\n' + 'Email → "email"\nScenario → "scenario"/"campaign"/"module"\nClicked → "clicked"/"click"\nTrained → "trained"/"completed"/"complete"' ); } const colSucceeded = findCol(cols, ['succeed', 'succeeded', 'success']); const colMailbox = findCol(cols, ['mailbox', 'mbox', 'mb']); const colSubject = findCol(cols, ['subject', 'email subject']); const colClickedAt = findCol(cols, ['clicked at', 'click time', 'clicked_time']); const colAwareSec = findCol(cols, ['awareness_time', 'awareness seconds', 'training time (s)']); const colType = findCol(cols, ['type', 'attack type', 'vector', 'payload']); const colSentAt = findCol(cols, ['sent at', 'send time', 'delivered at', 'sent']); hasSucceededCol = !!colSucceeded; hasMailbox = !!colMailbox; hasSubject = !!colSubject; hasClickedAt = !!colClickedAt; hasAwareSec = !!colAwareSec; hasTypeCol = !!colType; hasSentAt = !!colSentAt; campaignFirstSent = null; campaignLastClick = null; const base = rawRows.map(r => { const sentAtStr = hasSentAt ? (r[colSentAt] ?? '') : ''; const clickAtStr = hasClickedAt ? (r[colClickedAt] ?? '') : ''; const sentAt = parseDateSafe(sentAtStr); const clickAt = parseDateSafe(clickAtStr); if (sentAt) campaignFirstSent = (!campaignFirstSent || sentAt < campaignFirstSent) ? sentAt : campaignFirstSent; if (clickAt) campaignLastClick = (!campaignLastClick || clickAt > campaignLastClick) ? clickAt : campaignLastClick; const scenario = String(r[colScenario] ?? '').trim() || '(none)'; const rowType = hasTypeCol ? String(r[colType] ?? '') : ''; const inferredType = rowType ? rowType : inferTypeFromScenario(scenario); return { Email: String(r[colEmail] ?? '').trim().toLowerCase(), Name: (colName ? r[colName] : '') ?? '', Scenario: scenario, Clicked_any: yn01(r[colClicked]), Trained_any: yn01(r[colTrained]), TrainedAt: (colTrainedAt ? r[colTrainedAt] : '') ?? '', Attempts: 1, Succeeded: hasSucceededCol ? yn01(r[colSucceeded]) : null, Mailbox: hasMailbox ? String(r[colMailbox] ?? '') : '', Subject: hasSubject ? String(r[colSubject] ?? '') : '', ClickedAt: hasClickedAt ? (clickAtStr || '') : '', AwarenessTimeMin: hasAwareSec ? secondsToMMSS(r[colAwareSec]) : '', Type: inferredType }; }); const bySp = {}; for (const r of base) { const k = r.Scenario + '|' + r.Email + '|' + r.Name; if (!bySp[k]) { bySp[k] = { Scenario: r.Scenario, Email: r.Email, Name: r.Name, Type: r.Type, Attempts: 0, Clicked_Any: 0, Trained_Any: 0, TrainedAtLatest: '', Succeeded: r.Succeeded ?? null, Mailbox: r.Mailbox, Subject: r.Subject, ClickedAt: r.ClickedAt, AwarenessTimeMin: r.AwarenessTimeMin }; } const o = bySp[k]; o.Attempts += 1; o.Clicked_Any = Math.max(o.Clicked_Any, r.Clicked_any); o.Trained_Any = Math.max(o.Trained_Any, r.Trained_any); if (String(r.TrainedAt || '').trim() !== '') o.TrainedAtLatest = r.TrainedAt; if (r.Succeeded != null) o.Succeeded = Math.max(o.Succeeded ?? 0, r.Succeeded); if (r.ClickedAt && !o.ClickedAt) o.ClickedAt = r.ClickedAt; if (r.AwarenessTimeMin && !o.AwarenessTimeMin) o.AwarenessTimeMin = r.AwarenessTimeMin; if (r.Type && !o.Type) o.Type = r.Type; } perScenPerson = Object.values(bySp); scenarios = Array.from(new Set(perScenPerson.map(x => x.Scenario))).sort(); build(); } // Build Report function build() { // Clear previous content scenariosContainer.innerHTML = ''; destroyCharts(); // Initialize window.__TABLES if not exists window.__TABLES = window.__TABLES || {}; if (!scenarios.length) { scenariosContainer.innerHTML = '
No scenarios in data.
'; return; } const groups = {}; scenarios.forEach(s => groups[s] = []); for (const r of perScenPerson) { groups[r.Scenario].push(r); } const kpis = Object.keys(groups).map(s => { const g = groups[s]; const uniq = new Set(g.map(x => x.Email)).size; const sends = g.reduce((a, b) => a + b.Attempts, 0); const clicked = g.reduce((a, b) => a + (b.Clicked_Any ? 1 : 0), 0); const trained = g.reduce((a, b) => a + (b.Trained_Any ? 1 : 0), 0); const succ = (hasSucceededCol && g.some(x => x.Succeeded != null)) ? g.reduce((a, b) => a + (b.Succeeded ? 1 : 0), 0) : null; const type = majorityType(g); return { Scenario: s, Unique: uniq, Sends: sends, Clicked: clicked, Trained: trained, Succeeded: succ, Type: type }; }).sort((a, b) => a.Scenario.localeCompare(b.Scenario)); const totals = kpis.reduce((a, k) => ({ Unique: a.Unique + k.Unique, Sends: a.Sends + k.Sends, Clicked: a.Clicked + k.Clicked, Trained: a.Trained + k.Trained, Succeeded: (a.Succeeded ?? 0) + (k.Succeeded ?? 0) }), { Unique: 0, Sends: 0, Clicked: 0, Trained: 0, Succeeded: 0 }); // Update KPI cards document.getElementById('uniquePeople').textContent = totals.Unique; document.getElementById('totalSends').textContent = totals.Sends; document.getElementById('clickedAny').textContent = totals.Clicked; document.getElementById('trainedAny').textContent = totals.Trained; document.getElementById('succeededAny').textContent = totals.Succeeded; // Create scenario cards kpis.forEach(k => { const scen = k.Scenario; const sub = groups[scen].slice().sort((a, b) => a.Email.localeCompare(b.Email)); const not = sub.filter(x => !x.Trained_Any).sort((a, b) => a.Email.localeCompare(b.Email)); const id = 'c_' + scen.replace(/[^a-z0-9]/gi, '_') + '_' + Math.random().toString(36).slice(2, 6); const pct = (num, den) => den ? Math.round((num / den) * 100) : 0; const pctClicked = pct(k.Clicked, k.Unique); const pctTrained = pct(k.Trained, k.Unique); const pctSucc = hasSucceededCol && k.Succeeded != null ? pct(k.Succeeded, k.Unique) : null; const card = document.createElement('div'); card.className = 'scenario-card'; card.dataset.scenario = scen; card.innerHTML = `
${scen} (Type: ${k.Type || '—'})
All Recipients
Users Not Trained
People ${k.Unique} • Sends ${k.Sends}
Clicked: ${k.Clicked} (${pctClicked}%)
Trained: ${k.Trained} (${pctTrained}%)
${hasSucceededCol && k.Succeeded != null ? `
Succeeded: ${k.Succeeded} (${pctSucc}%)
` : ''}
`; scenariosContainer.appendChild(card); // Create chart const ctx = document.getElementById(id).getContext('2d'); const datasets = [ { label: 'Sends', data: [k.Sends], backgroundColor: '#60a5fa' }, { label: 'Clicked (any)', data: [k.Clicked], backgroundColor: '#f59e0b' }, { label: 'Trained (any)', data: [k.Trained], backgroundColor: '#0fb9b9' } ]; if (hasSucceededCol && k.Succeeded != null) { datasets.push({ label: 'Succeeded (any)', data: [k.Succeeded], backgroundColor: '#94a3b8' }); } const ref = new Chart(ctx, { type: 'bar', data: { labels: [scen], datasets: datasets }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { display: false, grid: { display: false } }, y: { display: false, grid: { display: false } } } } }); chartRefs[id] = ref; card.dataset.all = JSON.stringify(sub); card.dataset.not = JSON.stringify(not); }); // Add event listeners to scenario buttons document.querySelectorAll('.scenario-card .btn').forEach(btn => { btn.addEventListener('click', function() { const scenario = this.closest('.scenario-card').dataset.scenario; if (this.dataset.all) { openAll(scenario); } else if (this.dataset.not) { openNot(scenario); } }); }); // Render mailbox statistics const anyMailbox = hasMailbox && perScenPerson.some(r => r.Mailbox && r.Clicked_Any); if (anyMailbox) { const rows = perScenPerson .filter(r => r.Clicked_Any && r.Mailbox) .map(r => ({ Mailbox: r.Mailbox, Email: r.Email, Name: r.Name, Scenario: r.Scenario, "Clicked At": (hasClickedAt ? r.ClickedAt : '') })); if (rows.length) { renderTable('mailboxTable', rows, ['Mailbox',

1 file changed +77 -47
index.html+77-47