-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sbom.html
124 lines (111 loc) · 4.35 KB
/
Sbom.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CycloneDX SBOM Viewer (Schema 1.4)</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.container { max-width: 800px; margin: auto; }
.section { margin-bottom: 20px; }
h2 { color: #333; border-bottom: 2px solid #333; padding-bottom: 5px; }
.summary-box { background: #f8f8f8; border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; text-align: center; font-weight: bold; }
.component, .dependency { border: 1px solid #ccc; padding: 10px; margin-bottom: 10px; background-color: #f9f9f9; border-radius: 5px; }
.dropdown { cursor: pointer; padding: 8px; background-color: #eee; border-radius: 5px; margin-bottom: 5px; font-weight: bold; }
.dropdown-content { display: none; padding: 10px; }
.dropdown:hover { background-color: #ddd; }
.external-ref { margin-left: 20px; font-style: italic; }
</style>
</head>
<body>
<div class="container">
<h1>CycloneDX SBOM Viewer (Schema 1.4)</h1>
<!-- Input section for SBOM JSON file -->
<input type="file" id="fileInput" accept=".json">
<button onclick="loadSBOM()">Load SBOM</button>
<!-- BOM Info Section -->
<div id="bomInfo" class="section"></div>
<!-- Components Section -->
<div id="components" class="section"></div>
<!-- Dependencies Section -->
<div id="dependencies" class="section"></div>
</div>
<script>
function loadSBOM() {
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
if (!file) {
alert("Please select a file.");
return;
}
const reader = new FileReader();
reader.onload = function(e) {
const data = JSON.parse(e.target.result);
displaySBOM(data);
};
reader.readAsText(file);
}
function displaySBOM(data) {
const bomInfo = document.getElementById("bomInfo");
const componentsSection = document.getElementById("components");
const dependenciesSection = document.getElementById("dependencies");
// Display general BOM info
bomInfo.innerHTML = `
<h2>BOM Information</h2>
<p><strong>Format:</strong> ${data.bomFormat}</p>
<p><strong>Spec Version:</strong> ${data.specVersion}</p>
<p><strong>Serial Number:</strong> ${data.serialNumber}</p>
<p><strong>Version:</strong> ${data.version}</p>
<p><strong>Timestamp:</strong> ${data.metadata?.timestamp || "N/A"}</p>
`;
// Display components with count
componentsSection.innerHTML = `
<div class="summary-box">Total Components: ${data.components.length}</div>
<h2>Components</h2>
`;
data.components.forEach(component => {
componentsSection.innerHTML += `
<div class="component">
<div class="dropdown" onclick="toggleDropdown(this)">
<p><strong>Name:</strong> ${component.name} (v${component.version})</p>
</div>
<div class="dropdown-content">
<p><strong>BOM Reference:</strong> ${component['bom-ref']}</p>
<p><strong>Type:</strong> ${component.type}</p>
${component.group ? `<p><strong>Group:</strong> ${component.group}</p>` : ""}
<p><strong>PURL:</strong> ${component.purl || "N/A"}</p>
</div>
</div>
`;
});
// Display dependencies with count and dropdown
dependenciesSection.innerHTML = `<h2>Dependencies</h2>`;
data.dependencies.forEach(dependency => {
dependenciesSection.innerHTML += `
<div class="dependency">
<div class="dropdown" onclick="toggleDropdown(this)">
<p><strong>Component Reference:</strong> ${dependency.ref}</p>
<p><strong>Total Dependencies:</strong> ${dependency.dependsOn.length}</p>
</div>
<div class="dropdown-content">
<p><strong>Depends On:</strong></p>
<ul>
${
dependency.dependsOn.length > 0
? dependency.dependsOn.map(dep => `<li>${dep}</li>`).join('')
: '<li>None</li>'
}
</ul>
</div>
</div>
`;
});
}
// Toggle dropdown content visibility
function toggleDropdown(element) {
const content = element.nextElementSibling;
content.style.display = content.style.display === "block" ? "none" : "block";
}
</script>
</body>
</html>