-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject_export.js
32 lines (30 loc) · 1.23 KB
/
project_export.js
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
function projectExport (projectId) {
// Exports JSON project data provided by ProjectID
//
// Usage:
// mongo localhost:27017/lair --eval "load('./project_export.js'); projectExport('cvxgsaKNC5cfLoeNn')"
//
// Created By: Matt Burch
if (typeof projectId !== 'string') {
return print('Invalid projectId')
}
var project = db.projects.findOne({_id: projectId})
if (typeof project === 'undefined') {
return print('No project matching ID:' + projectId)
}
var hosts = db.hosts.find({projectId: projectId}).toArray() || []
var issues = db.issues.find({projectId: projectId}).toArray() || []
hosts.forEach(function (host) {
host.longIpv4Addr = host.longIpv4Addr.toNumber()
host.services = db.services.find({hostId: host._id}).toArray()
host.webDirectories = db.web_directories.find({hostId: host._id}).toArray()
})
var people = db.people.find({projectId: projectId}).toArray()
project.hosts = hosts
project.people = people
project.issues = issues
project.credentials = db.credentials.find({projectId: projectId}).toArray()
project.authInterfaces = db.auth_interfaces.find({projectId: projectId}).toArray()
project.netblocks = db.netblocks.find({projectid: projectId}).toArray()
printjson(project)
}