Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
161 lines (139 loc) · 5.24 KB
/
Copy pathapp.js
File metadata and controls
161 lines (139 loc) · 5.24 KB
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
function cveTracker() {
return {
query: '',
loading: false,
error: null,
result: null,
meta: {},
yearCache: {},
distros: [
{ name: 'debian', label: 'Debian', data: null, urlTemplate: 'https://security-tracker.debian.org/tracker/{cve}' },
{ name: 'ubuntu', label: 'Ubuntu', data: null, urlTemplate: 'https://ubuntu.com/security/{cve}' },
{ name: 'rhel', label: 'RHEL/CentOS', data: null, urlTemplate: 'https://access.redhat.com/security/cve/{cve}' },
{ name: 'alpine', label: 'Alpine', data: null, urlTemplate: 'https://security.alpinelinux.org/vuln/{cve}' },
],
async init() {
try {
const response = await fetch('data/index.json');
if (response.ok) {
const data = await response.json();
this.meta = data.meta || {};
}
} catch (e) {
console.log('Index not loaded:', e);
}
// Check for ?cve= query parameter
const params = new URLSearchParams(window.location.search);
const cveParam = params.get('cve');
if (cveParam) {
this.query = cveParam.toUpperCase();
this.search();
}
},
async search() {
const cveId = this.query.trim().toUpperCase();
if (!cveId) {
this.error = 'Please enter a CVE ID';
return;
}
const cvePattern = /^CVE-\d{4}-\d{4,}$/;
if (!cvePattern.test(cveId)) {
this.error = 'Invalid CVE format. Use CVE-YYYY-NNNNN (e.g., CVE-2024-1234)';
return;
}
this.loading = true;
this.error = null;
this.result = null;
for (const distro of this.distros) {
distro.data = null;
}
try {
const year = cveId.split('-')[1];
const yearFile = `data/cve-${year}.json`;
let yearData = this.yearCache[year];
if (!yearData) {
const response = await fetch(yearFile);
if (!response.ok) {
this.error = `No data available for year ${year}`;
this.loading = false;
return;
}
yearData = await response.json();
this.yearCache[year] = yearData;
}
const cveData = yearData?.cves?.[cveId];
this.result = {
cve_id: cveId,
notInCache: !cveData,
...(cveData || {})
};
for (const distro of this.distros) {
distro.data = cveData?.distros?.[distro.name] || null;
}
} catch (e) {
// Even on error, show distro cards for manual lookup
this.result = {
cve_id: cveId,
notInCache: true
};
for (const distro of this.distros) {
distro.data = null;
}
}
// Update URL for sharing
const url = new URL(window.location);
url.searchParams.set('cve', cveId);
window.history.replaceState({}, '', url);
this.loading = false;
},
getStatusClass(distro) {
if (!distro.data) return 'status-unknown';
return 'status-' + (distro.data.status || 'unknown');
},
formatStatus(status) {
if (!status) return 'Unknown';
const labels = {
'fixed': 'Fixed',
'affected': 'Affected',
'not-affected': 'Not Affected',
'unknown': 'Unknown',
'wontfix': "Won't Fix",
'deferred': 'Deferred'
};
return labels[status] || status;
},
formatFixed(fixed) {
if (!fixed) return '';
if (Array.isArray(fixed)) {
return fixed.join(', ');
}
return fixed;
},
formatDate(isoDate) {
if (!isoDate) return '';
try {
return new Date(isoDate).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
} catch {
return isoDate;
}
},
sortedReleases(releases) {
if (!releases) return [];
return Object.keys(releases).sort((a, b) => {
// Natural sort: handle numbers properly (RHEL 8 before RHEL 10)
return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' });
});
},
getDistroUrl(distro) {
const cveId = this.result?.cve_id || this.query.trim().toUpperCase();
if (!cveId) return '#';
if (distro.data?.advisory_url) return distro.data.advisory_url;
return distro.urlTemplate.replace('{cve}', cveId);
}
};
}