-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
476 lines (416 loc) · 14.3 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SBOM Editor</title>
<style>
body,
html {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #f0f0f0;
}
.fullscreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
#drop-zone {
background-color: #ffffff;
transition: background-color 0.3s ease;
}
#drop-zone.dragover {
background-color: #e0e0e0;
}
.drop-content {
text-align: center;
padding: 40px;
border: 3px dashed #ccc;
border-radius: 10px;
background-color: #ffffff;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
color: #333;
}
#file-input {
display: none;
}
.file-input-label,
.btn {
background-color: #4CAF50;
color: white;
padding: 12px 24px;
cursor: pointer;
border-radius: 5px;
font-size: 1em;
border: none;
transition: background-color 0.3s ease;
display: inline-block;
margin-top: 10px;
}
.file-input-label:hover,
.btn:hover {
background-color: #45a049;
}
.button-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
#loading {
background-color: rgba(255, 255, 255, 0.8);
}
.loading-content {
text-align: center;
}
.spinner {
border: 5px solid #f3f3f3;
border-top: 5px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#sbom-container {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
#sbom-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
#component-count {
font-size: 1.2em;
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
background-color: #ffffff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
th,
td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.action-btn {
padding: 6px 12px;
display: inline-block;
margin-right: 5px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.9em;
transition: background-color 0.3s ease;
}
td:last-child {
white-space: nowrap;
}
.edit-btn {
background-color: #3498db;
color: white;
}
.edit-btn:hover {
background-color: #2980b9;
}
.clone-btn {
background-color: #2ecc71;
color: white;
}
.clone-btn:hover {
background-color: #27ae60;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
.delete-btn:hover {
background-color: #c0392b;
}
#edit-modal {
background-color: rgba(0, 0, 0, 0.5);
}
.edit-content {
background-color: white;
padding: 20px;
border-radius: 5px;
width: 80%;
max-width: 600px;
}
#edit-area {
width: 100%;
height: 300px;
margin-bottom: 10px;
font-family: monospace;
}
.button-group {
text-align: right;
}
.button-group button {
margin-left: 10px;
}
.hidden {
display: none !important;
}
</style>
</head>
<body>
<div id="drop-zone" class="fullscreen">
<div class="drop-content">
<h1>SBOM Editor</h1>
<p>Drag and drop CycloneDX JSON SBOM file here</p>
<p>or</p>
<div class="button-container">
<input type="file" id="file-input" accept=".json">
<label for="file-input" class="file-input-label">Browse Files</label>
<button id="example-btn" class="btn">Example File</button>
</div>
</div>
</div>
<div id="loading" class="fullscreen hidden">
<div class="loading-content">
<div class="spinner"></div>
<p>Loading...</p>
</div>
</div>
<div id="sbom-container" class="hidden">
<div id="sbom-info">
<p id="component-count"></p>
<button id="download-btn" class="btn">Download SBOM</button>
</div>
<table id="sbom-table">
<thead>
<tr>
<th>Name</th>
<th>License</th>
<th>Author</th>
<th>Version</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="sbom-body"></tbody>
</table>
</div>
<div id="edit-modal" class="fullscreen hidden">
<div class="edit-content">
<h2>Edit Component</h2>
<textarea id="edit-area"></textarea>
<div class="button-group">
<button id="save-edit" class="btn">Save</button>
<button id="cancel-edit" class="btn">Cancel</button>
</div>
</div>
</div>
<script>
let sbomData = null;
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('file-input');
const loading = document.getElementById('loading');
const sbomContainer = document.getElementById('sbom-container');
const componentCount = document.getElementById('component-count');
const sbomTable = document.getElementById('sbom-table');
const sbomBody = document.getElementById('sbom-body');
const downloadBtn = document.getElementById('download-btn');
const editModal = document.getElementById('edit-modal');
const editArea = document.getElementById('edit-area');
const saveEditBtn = document.getElementById('save-edit');
const cancelEditBtn = document.getElementById('cancel-edit');
document.getElementById('example-btn').addEventListener('click', () => {
dropZone.classList.add('hidden');
loading.classList.remove('hidden');
fetch('example_sbom_cyclonedx.json')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load example SBOM');
}
return response.json();
})
.then(data => {
sbomData = data;
loading.classList.add('hidden');
displaySBOM();
})
.catch(error => {
console.error('Error loading example SBOM:', error);
alert('Error loading example SBOM file');
loading.classList.add('hidden');
dropZone.classList.remove('hidden');
});
});
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const file = e.dataTransfer.files[0];
if (file) {
readFile(file);
}
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
readFile(file);
}
});
function readFile(file) {
dropZone.classList.add('hidden');
loading.classList.remove('hidden');
const reader = new FileReader();
reader.onload = (e) => {
try {
const jsonString = e.target.result;
parseJSONStream(jsonString);
} catch (error) {
console.error("Error reading file:", error);
alert("Error reading file. Please try again.");
dropZone.classList.remove('hidden');
} finally {
loading.classList.add('hidden');
}
};
reader.onerror = (error) => {
console.error("FileReader error:", error);
alert("Error reading file. Please try again.");
loading.classList.add('hidden');
dropZone.classList.remove('hidden');
};
reader.readAsText(file);
}
function parseJSONStream(jsonString) {
try {
sbomData = JSON.parse(jsonString);
if (sbomData.bomFormat === "CycloneDX" && sbomData.specVersion) {
displaySBOM();
} else {
alert("Invalid SBOM format. Please ensure it's a CycloneDX JSON SBOM.");
dropZone.classList.remove('hidden');
}
} catch (error) {
console.error("JSON parsing error:", error);
alert("Error parsing SBOM file. Please make sure it's a valid JSON file.");
dropZone.classList.remove('hidden');
}
}
function displaySBOM() {
if (!sbomData || !sbomData.components) {
alert("Invalid SBOM structure. Missing components array.");
dropZone.classList.remove('hidden');
return;
}
componentCount.textContent = `Total components: ${sbomData.components.length}`;
sbomContainer.classList.remove('hidden');
sbomBody.innerHTML = '';
sbomData.components.forEach((component, index) => {
const row = sbomBody.insertRow();
row.insertCell(0).textContent = component.name || 'N/A';
row.insertCell(1).textContent = getLicenseText(component);
row.insertCell(2).textContent = component.author || 'N/A';
row.insertCell(3).textContent = component.version || 'N/A';
const actionsCell = row.insertCell(4);
actionsCell.appendChild(createButton('Edit', 'edit-btn', () => editComponent(index)));
actionsCell.appendChild(createButton('Clone', 'clone-btn', () => cloneComponent(index)));
actionsCell.appendChild(createButton('Delete', 'delete-btn', () => deleteComponent(index)));
});
}
function getLicenseText(component) {
if (!component.licenses) return 'N/A';
return component.licenses.map(l => {
if (typeof l === 'string') return l;
if (l.license) {
if (typeof l.license === 'string') return l.license;
if (l.license.id) return l.license.id;
if (l.license.name) return l.license.name;
}
return 'Unknown';
}).join(', ');
}
function createButton(text, className, onClick) {
const button = document.createElement('button');
button.textContent = text;
button.className = `action-btn ${className}`;
button.addEventListener('click', onClick);
return button;
}
function editComponent(index) {
editArea.value = JSON.stringify(sbomData.components[index], null, 2);
sbomContainer.classList.add('hidden');
editModal.classList.remove('hidden');
saveEditBtn.onclick = () => {
try {
sbomData.components[index] = JSON.parse(editArea.value);
editModal.classList.add('hidden');
sbomContainer.classList.remove('hidden');
displaySBOM();
} catch (error) {
alert("Invalid JSON. Please check your input.");
}
};
}
function cloneComponent(index) {
const clonedComponent = JSON.parse(JSON.stringify(sbomData.components[index]));
sbomData.components.splice(index + 1, 0, clonedComponent);
displaySBOM();
}
function deleteComponent(index) {
sbomData.components.splice(index, 1);
displaySBOM();
}
cancelEditBtn.addEventListener('click', () => {
editModal.classList.add('hidden');
sbomContainer.classList.remove('hidden');
});
downloadBtn.addEventListener('click', () => {
const blob = new Blob([JSON.stringify(sbomData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'sbom_edited.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
</script>
</body>
</html>