Skip to content

Commit

Permalink
chg: [website] Added a table of combined sightings for the bundles. G…
Browse files Browse the repository at this point in the history
…enerated in JavaScript on DOMContentLoaded event.
  • Loading branch information
cedricbonhomme committed Nov 13, 2024
1 parent f23ba9c commit 48610fc
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion website/web/templates/bundles/bundle.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ <h2>Meta</h2>
{% endif %}
<h2>Author</h2>
<a href="{{ url_for('user_bp.profile', login=bundle.author.login) }}">{{ bundle.author.name }}</a>
<hr />
<h2>Combined sightings</h2>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Author</th>
<th scope="col">Vulnerability</th>
<th scope="col">Source</th>
<th scope="col">Type</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody id="sighting-table-body"></tbody>
</table>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
jsonContainer = document.getElementById("jsoncontainer");
Expand All @@ -57,7 +73,62 @@ <h2>Author</h2>
// Post formatting
document.getElementById("markdown-description").innerHTML = linkifySecurityIdentifiers(document.getElementById("markdown-description").innerHTML);
formatMarkdownOutput();
});


// Populate the table of combined sightings.
const urlParts = window.location.pathname.split("/");
const uuid = urlParts[urlParts.length - 1];
const tableBody = document.getElementById("sighting-table-body");

// Function to create table rows
function addRowToTable(sighting) {
const row = document.createElement("tr");

const authorCell = document.createElement("td");
authorCell.textContent = sighting.author.name;
row.appendChild(authorCell);

const vulnerabilityCell = document.createElement("td");
vulnerabilityCell.innerHTML = '<a href="/vuln/'+sighting.vulnerability+'">'+sighting.vulnerability.toUpperCase()+'</a>';;
row.appendChild(vulnerabilityCell);

const sourceCell = document.createElement("td");
sourceCell.textContent = sighting.source;
row.appendChild(sourceCell);

const typeCell = document.createElement("td");
typeCell.textContent = sighting.type;
row.appendChild(typeCell);

const dateCell = document.createElement("td");
dateCell.textContent = new Date(sighting.creation_timestamp).toLocaleString();
row.appendChild(dateCell);

tableBody.appendChild(row);
}

// Fetch bundle data
fetch(`/api/bundle/?uuid=${uuid}`)
.then(response => response.json())
.then(bundleData => {
const vulnerabilities = bundleData.data[0]?.related_vulnerabilities || [];

// Fetch sightings for each vulnerability
vulnerabilities.forEach(vuln_id => {
fetch(`/api/sighting/?vuln_id=${vuln_id}`)
.then(response => response.json())
.then(sightingData => {
// Sort sightings by vulnerability ID
sightingData.data.sort((a, b) => a.vulnerability.toLowerCase().localeCompare(b.vulnerability.toLowerCase()));

// Add each sighting as a row in the table
sightingData.data.forEach(sighting => addRowToTable(sighting));
})
.catch(error => console.error("Error fetching sighting:", error));
});
})
.catch(error => console.error("Error fetching bundle:", error));
});

function copyCurrentPageURL() {
const currentURL = window.location.href; // Get the current page URL
Expand Down

0 comments on commit 48610fc

Please sign in to comment.