-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdelete_host_services_by_tool.js
39 lines (34 loc) · 1.1 KB
/
delete_host_services_by_tool.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
33
34
35
36
37
38
39
/* eslint-disable no-unused-vars */
/* globals Session Hosts Services Meteor */
function deleteHostServicesByTool (ipAddr, lastModBy) {
// Looks at a provided host and deletes any service by
// specified 'Last Modified By' value.
// Useful if a scanner adds large sum of bad Services.
//
//
// Usage: deleteHostServicesByTool('192.168.1.141', 'nexpose')
// Created by: Ryan Dorey
// Requires client-side updates: true
var projectId = Session.get('projectId')
var host = Hosts.findOne({
'projectId': projectId,
'ipv4': ipAddr
})
if (typeof host === 'undefined') {
console.log('No matching host found')
return
}
var services = Services.find({
'projectId': projectId,
'hostId': host._id,
'lastModifiedBY': lastModBy
}).fetch()
if (services.length < 1) {
console.log('No matching Services found')
}
services.forEach(function (service) {
console.log('Removing ' + service.protocol + '/' + service.service)
Meteor.call('removeService', projectId, service._id, function () {})
})
console.log('Total of ' + services.length + ' service(s) removed.')
}