jQuery(document).ready(function ($) { var wpscanReport = { pageMargins: [0, 80, 0, 80], header: function () { const date = new Date(); const options = { day: 'numeric', month: 'long', year: 'numeric', }; return [ { canvas: [ { type: 'polyline', color: '#fff', points: [ { x: 0, y: 0 }, { x: 327, y: 0 }, { x: 297, y: 59 }, { x: 0, y: 59 }, ], }, { type: 'polyline', color: '#006699', points: [ { x: 327, y: 0 }, { x: 357, y: 0 }, { x: 327, y: 59 }, { x: 297, y: 59 }, ], }, { type: 'polyline', color: '#33CC99', points: [ { x: 357, y: 0 }, { x: 595.28, y: 0 }, { x: 595.28, y: 59 }, { x: 327, y: 59 }, ], }, { type: 'line', x1: 0, y1: 60, x2: 595.28, y2: 60, lineWidth: 1, color: '#D7DFE3', }, ], }, { svg: ` `, width: 112, absolutePosition: { x: 0, y: 0 }, relativePosition: { x: 40, y: 10 }, alignment: 'left', }, { text: 'wpscan.com', link: 'http://wpscan.com', fontSize: 8, absolutePosition: { x: 0, y: 0 }, relativePosition: { x: 93, y: 35 }, }, { text: 'Vulnerability Report', fontSize: 16, bold: true, color: '#ffffff', alignment: 'right', absolutePosition: { x: 0, y: 0 }, relativePosition: { x: -40, y: 13 }, }, { text: new Intl.DateTimeFormat('en-GB', options).format(date), fontSize: 10, color: '#ffffff', absolutePosition: { x: 0, y: 0 }, relativePosition: { x: -40, y: 32 }, alignment: 'right', }, ]; }, footer: function (currentPage) { return [ { canvas: [ { type: 'polyline', color: '#282d41', points: [ { x: 0, y: 26 }, { x: 0, y: 80 }, { x: 595.28, y: 80 }, ], }, ], }, { text: currentPage, alignment: 'right', fontSize: 8, absolutePosition: { x: 0, y: 0 }, relativePosition: { x: -40, y: 30 }, }, ]; }, content: [], }; /** * Fonts setup */ pdfMake.fonts = { Montserrat: { normal: 'Montserrat-Regular.ttf', bold: 'Montserrat-Bold.ttf', italics: 'Montserrat-Medium.ttf', bolditalics: 'Montserrat-Medium.ttf', }, }; /** * Background */ wpscanReport.background = function () { return { canvas: [ { type: 'rect', x: 0, y: 0, w: 595.28, h: 841.89, color: '#f1f4f6', }, ], }; }; /** * Styles */ wpscanReport.styles = { wordpressHeader: { fontSize: 14, bold: true, margin: [0, -15, 0, 0], }, header: { fontSize: 14, bold: true, margin: [40, 20, 0, 0], }, tableLine: { fillColor: '#006699 ', margin: [0, -8], fontSize: 1, }, WPTableLine: { fillColor: '#32B488 ', margin: [0, -8], fontSize: 1, }, tableHeader: { fillColor: '#f6f6f6', margin: [10, 10], fontSize: 10, bold: true, }, resTable: { margin: [10, 7, 10, 10], fillColor: '#ffffff', fontSize: 10, italics: true, }, metadata: { fontSize: 10, bold: true, color: '#333333', }, }; /** * Default style */ wpscanReport.defaultStyle = { color: '#333333', font: 'Montserrat', }; /** * border color */ var borderColor = ['#e5e5e5', '#e5e5e5', '#e5e5e5', '#e5e5e5']; /** * Tables */ $('.wpscan-report-section').each(function () { let is_security_checks = false; let is_wordpress_section = $(this).find('h3').first().text().trim() === 'WordPress'; // Table title const sectionTitle = () => { if (!is_wordpress_section) { wpscanReport.content.push({ text: $(this).find('h3').first().text(), style: 'header', }); } }; const wordpressTitle = () => { if (is_wordpress_section) { return { text: $(this).find('h3').first().text(), style: 'wordpressHeader', }; } }; if ($(this).hasClass('security-checks')) { is_security_checks = true; } /** * Table setup */ let table = { table: { headerRows: 2, widths: [], body: [[], []], }, }; let wordpressTable = { stack: [ { canvas: [ { type: 'rect', x: 0, y: 00, w: 595.28, h: 30, color: '#ECF8F1', }, ], relativePosition: { x: 0, y: -25 }, }, { table: { widths: [32, '*', 32], body: [ [ { text: ' ', border: [false, false, false, false], fillColor: '#ECF8F1', }, { text: ' ', border: [false, false, false, false], fillColor: '#ECF8F1', }, { text: ' ', border: [false, false, false, false], fillColor: '#ECF8F1', }, ], [ { text: ' ', border: [false, false, false, false], fillColor: '#ECF8F1', }, { stack: [wordpressTitle(), table], border: [false, false, false, false], fillColor: '#ECF8F1', }, { text: ' ', border: [false, false, false, false], fillColor: '#ECF8F1', }, ], [ { text: ' ', border: [false, false, false, true], borderColor: ['#D7DFE3', '#D7DFE3', '#D7DFE3', '#D7DFE3'], margin: [0, 10], fillColor: '#ECF8F1', }, { text: ' ', border: [false, false, false, true], borderColor: ['#D7DFE3', '#D7DFE3', '#D7DFE3', '#D7DFE3'], margin: [0, 10], fillColor: '#ECF8F1', }, { text: ' ', border: [false, false, false, true], borderColor: ['#D7DFE3', '#D7DFE3', '#D7DFE3', '#D7DFE3'], margin: [0, 10], fillColor: '#ECF8F1', }, ], ], }, }, ], }; let mainTable = { stack: [ sectionTitle(), { table: { widths: [32, '*', 32], body: [[{}, table, {}]], }, layout: 'noBorders', }, ], }; /** * Table head */ const colSpan = is_security_checks ? 2 : 3; const topTableBorder = is_wordpress_section ? 'WPTableLine' : 'tableLine'; // Name table.table.body[1].push({ text: 'Name', style: 'tableHeader', borderColor, }); table.table.widths.push(149); // Version if (!is_security_checks) { table.table.body[1].push({ text: 'Version', style: 'tableHeader', borderColor, }); table.table.widths.push(79); } // Vulnerabilities table.table.body[1].push({ text: 'Vulnerabilities', style: 'tableHeader', borderColor, }); table.table.widths.push('*'); table.table.body[0].push({ text: ' ', style: topTableBorder, colSpan: colSpan, border: [false, false, false, false], }); if (!is_security_checks) { table.table.body[0].push({}); } table.table.body[0].push({}); // Add rows $(this) .find('table tbody') .children() .each(function () { let row = []; // Item name let itemTitle = is_wordpress_section ? 'WordPress' : $(this).find('.plugin-title strong').text().trim(); if ($(this).find('.plugin-title .item-closed').length) { itemTitle = itemTitle + ' - ' + $(this).find('.plugin-title .item-closed').text(); } row.push({ text: itemTitle, style: 'resTable', borderColor, lineHeight: 2, }); // Item version let itemVersion = is_wordpress_section ? $(this).find('#wordpress-version').text().trim() : $(this).find('.plugin-title .item-version span').text().trim(); if (!is_security_checks) { row.push({ text: itemVersion, style: 'resTable', borderColor, }); } // Item vulnerabilities if ($(this).find('.vulnerabilities .vulnerability').length) { let col = { stack: [], style: 'resTable', lineHeight: 2, borderColor, }; // for each vulnerability $(this) .find('.vulnerabilities .vulnerability') .each(function () { let item = $(this).clone(); let title = item.find('.vulnerability-title').text().trim(); let status = item.find('.vulnerability-status').text().trim(); let severity = item.find('.vulnerability-severity span').text().trim(); let link_text = item.find('.vulnerability-link').text().trim(); let link_href = item.find('.vulnerability-link a').attr('href'); let vulnerability_text = [ { text: title, style: 'resTable' }, { text: status, style: 'resTable' }, { text: severity.charAt(0).toUpperCase() + severity.slice(1), style: 'resTable' }, { text: link_text, link: link_href, style: 'resTable' } ] col.stack.push( vulnerability_text ); }); row.push(col); } else { // No vulnerabilities found row.push({ text: $(this).find('.vulnerabilities').text().trim(), style: 'resTable', borderColor, }); } table.table.body.push(row); }); // Push the table is_wordpress_section ? wpscanReport.content.push(wordpressTable) : wpscanReport.content.push(mainTable); }); // Download $('.download-report').on('click', function () { let dt = new Date().toJSON().slice(0, 10); // pdfMake.createPdf(wpscanReport).open(); pdfMake.createPdf(wpscanReport).download(dt + '-wpscan-report.pdf'); }); });