Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
586 lines (512 loc) · 19.7 KB
/
Copy pathscript.js
File metadata and controls
586 lines (512 loc) · 19.7 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
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// Application State
let reportData = {
title: '',
scope: '',
executiveSummary: '',
conclusion: '',
vulnerabilities: [],
recommendations: []
};
let currentTheme = 'light';
// DOM Elements
const themeToggle = document.getElementById('themeToggle');
const navItems = document.querySelectorAll('.nav-item');
const tabContents = document.querySelectorAll('.tab-content');
const addVulnerabilityBtn = document.getElementById('addVulnerability');
const addRecommendationBtn = document.getElementById('addRecommendation');
const generateReportBtn = document.getElementById('generateReport');
const downloadPDFBtn = document.getElementById('downloadPDF');
const pdfModal = document.getElementById('pdfModal');
const modalClose = document.getElementById('modalClose');
const confirmPDFBtn = document.getElementById('confirmPDF');
const cancelPDFBtn = document.getElementById('cancelPDF');
// Initialize Application
document.addEventListener('DOMContentLoaded', function() {
initializeEventListeners();
loadSavedData();
updateTheme();
});
// Event Listeners
function initializeEventListeners() {
// Theme toggle
themeToggle.addEventListener('click', toggleTheme);
// Navigation
navItems.forEach(item => {
item.addEventListener('click', () => switchTab(item.dataset.tab));
});
// Form inputs
document.getElementById('title').addEventListener('input', (e) => {
reportData.title = e.target.value;
saveData();
});
document.getElementById('scope').addEventListener('input', (e) => {
reportData.scope = e.target.value;
saveData();
});
document.getElementById('executive-summary').addEventListener('input', (e) => {
reportData.executiveSummary = e.target.value;
saveData();
});
document.getElementById('conclusion').addEventListener('input', (e) => {
reportData.conclusion = e.target.value;
saveData();
});
// Buttons
addVulnerabilityBtn.addEventListener('click', addVulnerability);
addRecommendationBtn.addEventListener('click', addRecommendation);
generateReportBtn.addEventListener('click', generateReport);
downloadPDFBtn.addEventListener('click', showPDFModal);
// Modal
modalClose.addEventListener('click', hidePDFModal);
cancelPDFBtn.addEventListener('click', hidePDFModal);
confirmPDFBtn.addEventListener('click', downloadPDF);
// Close modal on outside click
pdfModal.addEventListener('click', (e) => {
if (e.target === pdfModal) {
hidePDFModal();
}
});
}
// Theme Management
function toggleTheme() {
currentTheme = currentTheme === 'light' ? 'dark' : 'light';
updateTheme();
localStorage.setItem('theme', currentTheme);
}
function updateTheme() {
document.documentElement.setAttribute('data-theme', currentTheme);
const icon = themeToggle.querySelector('i');
icon.className = currentTheme === 'light' ? 'fas fa-moon' : 'fas fa-sun';
}
// Navigation
function switchTab(tabName) {
// Update navigation
navItems.forEach(item => {
item.classList.toggle('active', item.dataset.tab === tabName);
});
// Update content
tabContents.forEach(content => {
content.classList.toggle('active', content.id === tabName);
});
}
// Vulnerability Management
function addVulnerability() {
const vulnerability = {
id: Date.now(),
title: '',
severity: 'medium',
description: '',
impact: '',
solution: ''
};
reportData.vulnerabilities.push(vulnerability);
renderVulnerabilities();
saveData();
}
function removeVulnerability(id) {
reportData.vulnerabilities = reportData.vulnerabilities.filter(v => v.id !== id);
renderVulnerabilities();
saveData();
}
function updateVulnerability(id, field, value) {
const vulnerability = reportData.vulnerabilities.find(v => v.id === id);
if (vulnerability) {
vulnerability[field] = value;
saveData();
}
}
function renderVulnerabilities() {
const container = document.getElementById('vulnerabilityList');
container.innerHTML = '';
reportData.vulnerabilities.forEach(vuln => {
const vulnElement = createVulnerabilityElement(vuln);
container.appendChild(vulnElement);
});
}
function createVulnerabilityElement(vuln) {
const div = document.createElement('div');
div.className = 'vulnerability-item';
div.innerHTML = `
<div class="item-header">
<input type="text" class="item-title" placeholder="Vulnerability title"
value="${vuln.title}" onchange="updateVulnerability(${vuln.id}, 'title', this.value)">
<select onchange="updateVulnerability(${vuln.id}, 'severity', this.value)">
<option value="critical" ${vuln.severity === 'critical' ? 'selected' : ''}>Critical</option>
<option value="high" ${vuln.severity === 'high' ? 'selected' : ''}>High</option>
<option value="medium" ${vuln.severity === 'medium' ? 'selected' : ''}>Medium</option>
<option value="low" ${vuln.severity === 'low' ? 'selected' : ''}>Low</option>
<option value="info" ${vuln.severity === 'info' ? 'selected' : ''}>Info</option>
</select>
<span class="severity-badge severity-${vuln.severity}">${getSeverityText(vuln.severity)}</span>
<button class="remove-item" onclick="removeVulnerability(${vuln.id})">
<i class="fas fa-trash"></i>
</button>
</div>
<div class="form-group">
<label>Description</label>
<textarea placeholder="Detailed description of the vulnerability..."
onchange="updateVulnerability(${vuln.id}, 'description', this.value)">${vuln.description}</textarea>
</div>
<div class="form-group">
<label>Impact</label>
<textarea placeholder="Impact of this vulnerability on the system..."
onchange="updateVulnerability(${vuln.id}, 'impact', this.value)">${vuln.impact}</textarea>
</div>
<div class="form-group">
<label>Solution</label>
<textarea placeholder="Recommended solution method..."
onchange="updateVulnerability(${vuln.id}, 'solution', this.value)">${vuln.solution}</textarea>
</div>
`;
return div;
}
// Recommendation Management
function addRecommendation() {
const recommendation = {
id: Date.now(),
title: '',
priority: 'medium',
description: '',
implementation: ''
};
reportData.recommendations.push(recommendation);
renderRecommendations();
saveData();
}
function removeRecommendation(id) {
reportData.recommendations = reportData.recommendations.filter(r => r.id !== id);
renderRecommendations();
saveData();
}
function updateRecommendation(id, field, value) {
const recommendation = reportData.recommendations.find(r => r.id === id);
if (recommendation) {
recommendation[field] = value;
saveData();
}
}
function renderRecommendations() {
const container = document.getElementById('recommendationList');
container.innerHTML = '';
reportData.recommendations.forEach(rec => {
const recElement = createRecommendationElement(rec);
container.appendChild(recElement);
});
}
function createRecommendationElement(rec) {
const div = document.createElement('div');
div.className = 'recommendation-item';
div.innerHTML = `
<div class="item-header">
<input type="text" class="item-title" placeholder="Recommendation title"
value="${rec.title}" onchange="updateRecommendation(${rec.id}, 'title', this.value)">
<select onchange="updateRecommendation(${rec.id}, 'priority', this.value)">
<option value="critical" ${rec.priority === 'critical' ? 'selected' : ''}>Critical</option>
<option value="high" ${rec.priority === 'high' ? 'selected' : ''}>High</option>
<option value="medium" ${rec.priority === 'medium' ? 'selected' : ''}>Medium</option>
<option value="low" ${rec.priority === 'low' ? 'selected' : ''}>Low</option>
</select>
<span class="severity-badge severity-${rec.priority}">${getPriorityText(rec.priority)}</span>
<button class="remove-item" onclick="removeRecommendation(${rec.id})">
<i class="fas fa-trash"></i>
</button>
</div>
<div class="form-group">
<label>Description</label>
<textarea placeholder="Detailed description of the recommendation..."
onchange="updateRecommendation(${rec.id}, 'description', this.value)">${rec.description}</textarea>
</div>
<div class="form-group">
<label>Implementation</label>
<textarea placeholder="How to implement this recommendation..."
onchange="updateRecommendation(${rec.id}, 'implementation', this.value)">${rec.implementation}</textarea>
</div>
`;
return div;
}
// Report Generation
function generateReport() {
if (!validateReportData()) {
return;
}
const reportHTML = createReportHTML();
const previewContainer = document.getElementById('reportPreview');
previewContainer.innerHTML = reportHTML;
// Switch to preview tab
switchTab('preview');
// Show success message
showNotification('Report generated successfully!', 'success');
}
function validateReportData() {
const errors = [];
if (!reportData.title.trim()) {
errors.push('Report title is required');
}
if (!reportData.scope.trim()) {
errors.push('Scope information is required');
}
if (!reportData.executiveSummary.trim()) {
errors.push('Executive summary is required');
}
if (errors.length > 0) {
showNotification('Please fill in the missing fields:\n' + errors.join('\n'), 'error');
return false;
}
return true;
}
function createReportHTML() {
const currentDate = new Date().toLocaleDateString('en-US');
let vulnerabilitiesHTML = '';
if (reportData.vulnerabilities.length > 0) {
vulnerabilitiesHTML = reportData.vulnerabilities.map(vuln => `
<div class="vulnerability-item-report">
<h3>${vuln.title || 'Untitled Vulnerability'}
<span class="severity-badge severity-${vuln.severity}">${getSeverityText(vuln.severity)}</span>
</h3>
${vuln.description ? `<p><strong>Description:</strong> ${vuln.description}</p>` : ''}
${vuln.impact ? `<p><strong>Impact:</strong> ${vuln.impact}</p>` : ''}
${vuln.solution ? `<p><strong>Solution:</strong> ${vuln.solution}</p>` : ''}
</div>
`).join('');
} else {
vulnerabilitiesHTML = '<p>No vulnerabilities were identified during the assessment.</p>';
}
let recommendationsHTML = '';
if (reportData.recommendations.length > 0) {
recommendationsHTML = reportData.recommendations.map(rec => `
<div class="recommendation-item-report">
<h3>${rec.title || 'Untitled Recommendation'}
<span class="severity-badge severity-${rec.priority}">${getPriorityText(rec.priority)}</span>
</h3>
${rec.description ? `<p><strong>Description:</strong> ${rec.description}</p>` : ''}
${rec.implementation ? `<p><strong>Implementation:</strong> ${rec.implementation}</p>` : ''}
</div>
`).join('');
} else {
recommendationsHTML = '<p>No specific recommendations are provided at this time.</p>';
}
return `
<div class="report-content">
<h1>${reportData.title}</h1>
<div class="report-meta">
<p><strong>Report Date:</strong> ${currentDate}</p>
<p><strong>Number of Vulnerabilities:</strong> ${reportData.vulnerabilities.length}</p>
<p><strong>Number of Recommendations:</strong> ${reportData.recommendations.length}</p>
</div>
<h2>Scope</h2>
<p>${reportData.scope.replace(/\n/g, '<br>')}</p>
<h2>Executive Summary</h2>
<p>${reportData.executiveSummary.replace(/\n/g, '<br>')}</p>
<h2>Identified Vulnerabilities</h2>
<div class="vulnerability-list-report">
${vulnerabilitiesHTML}
</div>
<h2>Recommendations</h2>
<div class="recommendation-list-report">
${recommendationsHTML}
</div>
${reportData.conclusion ? `
<h2>Conclusion</h2>
<p>${reportData.conclusion.replace(/\n/g, '<br>')}</p>
` : ''}
</div>
`;
}
// PDF Management
function showPDFModal() {
if (!validateReportData()) {
return;
}
pdfModal.classList.add('active');
}
function hidePDFModal() {
pdfModal.classList.remove('active');
}
function downloadPDF() {
hidePDFModal();
// Create a new window with the report content
const reportHTML = createReportHTML();
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<title>${reportData.title}</title>
<style>
body {
font-family: 'Times New Roman', serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #2563eb;
border-bottom: 2px solid #2563eb;
padding-bottom: 10px;
}
h2 {
color: #1e293b;
margin-top: 30px;
margin-bottom: 15px;
}
h3 {
color: #1e293b;
margin-top: 20px;
margin-bottom: 10px;
}
.report-meta {
background: #f8fafc;
padding: 15px;
border-radius: 8px;
margin-bottom: 30px;
border-left: 4px solid #2563eb;
}
.vulnerability-item-report,
.recommendation-item-report {
background: #f8fafc;
border-left: 4px solid #2563eb;
padding: 15px;
margin-bottom: 15px;
border-radius: 4px;
}
.severity-badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
margin-left: 10px;
}
.severity-critical { background: #dc2626; color: white; }
.severity-high { background: #dc2626; color: white; }
.severity-medium { background: #d97706; color: white; }
.severity-low { background: #059669; color: white; }
.severity-info { background: #64748b; color: white; }
@media print {
body { margin: 0; }
.no-print { display: none; }
}
</style>
</head>
<body>
${reportHTML}
<div class="no-print" style="text-align: center; margin-top: 30px;">
<button onclick="window.print()" style="padding: 10px 20px; background: #2563eb; color: white; border: none; border-radius: 4px; cursor: pointer;">
Save as PDF
</button>
<button onclick="window.close()" style="padding: 10px 20px; background: #64748b; color: white; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px;">
Close
</button>
</div>
</body>
</html>
`);
printWindow.document.close();
// Auto-trigger print dialog after a short delay
setTimeout(() => {
printWindow.print();
}, 500);
showNotification('PDF download window opened!', 'success');
}
// Utility Functions
function getSeverityText(severity) {
const severityMap = {
'critical': 'Critical',
'high': 'High',
'medium': 'Medium',
'low': 'Low',
'info': 'Info'
};
return severityMap[severity] || 'Medium';
}
function getPriorityText(priority) {
const priorityMap = {
'critical': 'Critical',
'high': 'High',
'medium': 'Medium',
'low': 'Low'
};
return priorityMap[priority] || 'Medium';
}
function showNotification(message, type = 'info') {
// Create notification element
const notification = document.createElement('div');
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
border-radius: 8px;
color: white;
font-weight: 600;
z-index: 10000;
max-width: 400px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
animation: slideIn 0.3s ease;
`;
// Set background color based on type
const colors = {
'success': '#059669',
'error': '#dc2626',
'warning': '#d97706',
'info': '#2563eb'
};
notification.style.backgroundColor = colors[type] || colors.info;
notification.textContent = message;
// Add animation styles
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
`;
document.head.appendChild(style);
document.body.appendChild(notification);
// Remove notification after 3 seconds
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 3000);
}
// Data Persistence
function saveData() {
localStorage.setItem('pentesterReportData', JSON.stringify(reportData));
}
function loadSavedData() {
const saved = localStorage.getItem('pentesterReportData');
const savedTheme = localStorage.getItem('theme');
if (saved) {
try {
reportData = JSON.parse(saved);
// Populate form fields
document.getElementById('title').value = reportData.title || '';
document.getElementById('scope').value = reportData.scope || '';
document.getElementById('executive-summary').value = reportData.executiveSummary || '';
document.getElementById('conclusion').value = reportData.conclusion || '';
// Render dynamic content
renderVulnerabilities();
renderRecommendations();
} catch (e) {
console.error('Error loading saved data:', e);
}
}
if (savedTheme) {
currentTheme = savedTheme;
}
}
// Make functions globally available
window.updateVulnerability = updateVulnerability;
window.removeVulnerability = removeVulnerability;
window.updateRecommendation = updateRecommendation;
window.removeRecommendation = removeRecommendation;