forked from pwndoc/pwndoc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding statistics section + first graphic
- Loading branch information
Showing
18 changed files
with
390 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var Audit = require('../models/audit'); | ||
var User = require('../models/user'); | ||
var VulnerabilityCategory = require('../models/vulnerability-category'); | ||
|
||
|
||
|
||
|
||
async function getFindingByCategory(isAllowed, userId) { | ||
const categories = await VulnerabilityCategory.getAll(); | ||
const audits = await Audit.getAudits(isAllowed, userId); | ||
|
||
const data = []; | ||
|
||
for (const smallaudit of audits) { | ||
const audit = await Audit.getAudit(isAllowed, smallaudit.id, userId); | ||
const year = new Date(audit.updatedAt).getFullYear(); | ||
for (const finding of audit.findings) { | ||
const category = categories.find(cat => cat.name === finding.category); | ||
if (category) { | ||
const index = data.findIndex(d => d.year === year); | ||
if (index === -1) { | ||
data.push({ year: year, data: [] }); | ||
} | ||
const yearData = data.find(d => d.year === year); | ||
const index2 = yearData.data.findIndex(d => d.category === category.name); | ||
if (index2 === -1) { | ||
yearData.data.push({ category: category.name, count: 1 }); | ||
} else { | ||
yearData.data[index2].count++; | ||
} | ||
} | ||
} | ||
} | ||
const formattedData = data.map(d => ({ | ||
name: d.year, | ||
data: d.data.map(item => item.count) | ||
})) | ||
|
||
return formattedData; | ||
} | ||
exports.getFindingByCategory = getFindingByCategory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function (app) { | ||
|
||
var Response = require('../lib/httpResponse.js'); | ||
var Stats = require('../lib/stats.js'); | ||
var acl = require('../lib/auth').acl; | ||
|
||
|
||
app.get('/api/stats/findingByCategory', acl.hasPermission('audits:read-all'), async function (req, res) { | ||
try { | ||
var data = await Stats.getFindingByCategory(acl.isAllowed(req.decodedToken.role, 'audits:read-all'), req.decodedToken.id) | ||
Response.Ok(res, data) | ||
} | ||
catch (err) { | ||
Response.Internal(res, err) | ||
} | ||
|
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.