Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
264 lines (220 loc) · 8.25 KB
/
Copy pathscript.js
File metadata and controls
264 lines (220 loc) · 8.25 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
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
// Initialize Chart.js
const ctx = document.getElementById('activityChart').getContext('2d');
let activityChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Activity Level',
data: [],
borderColor: '#3498db',
tension: 0.4,
fill: true,
backgroundColor: 'rgba(52, 152, 219, 0.1)'
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
max: 100
}
}
}
});
// Initialize variables
let threatCount = 0;
let isScanning = false;
let activityInterval;
// Function to update threat level
function updateThreatLevel(level) {
const threatLevel = document.getElementById('threatLevel');
threatLevel.style.width = `${level}%`;
}
// Function to add activity to the list
function addActivity(message, type = 'info') {
const activityList = document.getElementById('activity-list');
const activityItem = document.createElement('div');
activityItem.className = 'activity-item';
const timestamp = new Date().toLocaleTimeString();
activityItem.innerHTML = `
<strong>${timestamp}</strong> - ${message}
`;
activityList.insertBefore(activityItem, activityList.firstChild);
}
// Function to update chart
function updateChart() {
const time = new Date().toLocaleTimeString();
const value = Math.random() * 100;
activityChart.data.labels.push(time);
activityChart.data.datasets[0].data.push(value);
if (activityChart.data.labels.length > 10) {
activityChart.data.labels.shift();
activityChart.data.datasets[0].data.shift();
}
activityChart.update();
}
// Start scan function
function startScan() {
if (isScanning) return;
isScanning = true;
addActivity('Starting system scan...', 'info');
// Update last scan time
document.getElementById('lastScan').textContent = new Date().toLocaleString();
// Start periodic updates
activityInterval = setInterval(() => {
updateChart();
// Simulate threat detection
if (Math.random() > 0.7) {
threatCount++;
document.getElementById('threatCount').textContent = threatCount;
addActivity('Potential threat detected!', 'danger');
updateThreatLevel(Math.min(threatCount * 10, 100));
}
}, 2000);
// Disable scan button
document.querySelector('.btn-primary').disabled = true;
}
// Stop threats function
function stopThreats() {
if (!isScanning) return;
clearInterval(activityInterval);
isScanning = false;
addActivity('Threat detection stopped', 'success');
updateThreatLevel(0);
// Enable scan button
document.querySelector('.btn-primary').disabled = false;
}
// Generate report function
// Add these at the top of your script.js file
let reports = [];
const reportsModal = new bootstrap.Modal(document.getElementById('reportsModal'));
// Update the generateReport function
function generateReport() {
addActivity('Generating security report...', 'info');
const currentThreatLevel = parseInt(document.getElementById('threatLevel').style.width) || 0;
let threatStatus;
if (currentThreatLevel < 30) threatStatus = 'low';
else if (currentThreatLevel < 70) threatStatus = 'medium';
else threatStatus = 'high';
const report = {
id: Date.now(),
date: new Date().toISOString(),
threatLevel: threatStatus,
threatsFound: threatCount,
status: isScanning ? 'Active' : 'Inactive',
details: {
systemStatus: isScanning ? 'Scanning' : 'Idle',
lastScanTime: document.getElementById('lastScan').textContent,
activityLog: Array.from(document.querySelectorAll('.activity-item'))
.map(item => item.textContent)
.slice(0, 5)
}
};
reports.unshift(report);
updateReportsTable();
addActivity('Security report generated successfully', 'success');
reportsModal.show();
}
// Add these new functions
function updateReportsTable(filteredReports = reports) {
const tbody = document.getElementById('reportsTableBody');
tbody.innerHTML = '';
filteredReports.forEach(report => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${new Date(report.date).toLocaleString()}</td>
<td><span class="badge bg-${getBadgeColor(report.threatLevel)}">${report.threatLevel}</span></td>
<td>${report.threatsFound}</td>
<td>${report.status}</td>
<td>
<button class="btn btn-sm btn-info me-1" onclick="viewReport(${report.id})">
<i class="fas fa-eye"></i>
</button>
<button class="btn btn-sm btn-success" onclick="downloadReport(${report.id})">
<i class="fas fa-download"></i>
</button>
</td>
`;
tbody.appendChild(row);
});
}
function getBadgeColor(threatLevel) {
switch(threatLevel) {
case 'low': return 'success';
case 'medium': return 'warning';
case 'high': return 'danger';
default: return 'secondary';
}
}
function filterReports() {
const dateFilter = document.getElementById('reportDateFilter').value;
const levelFilter = document.getElementById('threatLevelFilter').value;
let filtered = [...reports];
if (dateFilter) {
filtered = filtered.filter(report =>
report.date.startsWith(dateFilter)
);
}
if (levelFilter) {
filtered = filtered.filter(report =>
report.threatLevel === levelFilter
);
}
updateReportsTable(filtered);
}
function viewReport(reportId) {
const report = reports.find(r => r.id === reportId);
if (!report) return;
const detailsHtml = `
<div class="report-details">
<h4>Detailed Report</h4>
<p><strong>Date:</strong> ${new Date(report.date).toLocaleString()}</p>
<p><strong>Threat Level:</strong> ${report.threatLevel}</p>
<p><strong>Threats Found:</strong> ${report.threatsFound}</p>
<p><strong>System Status:</strong> ${report.details.systemStatus}</p>
<p><strong>Last Scan:</strong> ${report.details.lastScanTime}</p>
<h5>Recent Activity Log:</h5>
<ul>
${report.details.activityLog.map(log => `<li>${log}</li>`).join('')}
</ul>
</div>
`;
const modal = new bootstrap.Modal(document.createElement('div'));
modal.element.innerHTML = `
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Report Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">${detailsHtml}</div>
</div>
</div>
`;
document.body.appendChild(modal.element);
modal.show();
}
function downloadReport(reportId) {
const report = reports.find(r => r.id === reportId);
if (!report) return;
const doc = new jspdf.jsPDF();
doc.setFontSize(20);
doc.text('Security Report', 20, 20);
doc.setFontSize(12);
doc.text(`Date: ${new Date(report.date).toLocaleString()}`, 20, 40);
doc.text(`Threat Level: ${report.threatLevel}`, 20, 50);
doc.text(`Threats Found: ${report.threatsFound}`, 20, 60);
doc.text(`System Status: ${report.details.systemStatus}`, 20, 70);
doc.text(`Last Scan: ${report.details.lastScanTime}`, 20, 80);
doc.text('Recent Activity Log:', 20, 100);
report.details.activityLog.forEach((log, index) => {
doc.text(`- ${log}`, 25, 110 + (index * 10));
});
doc.save(`security-report-${report.id}.pdf`);
}
// Initialize threat level
updateThreatLevel(0);
// Add initial activity
addActivity('System initialized successfully', 'success');