-
Notifications
You must be signed in to change notification settings - Fork 0
/
report-bl-dest-ips.go
49 lines (40 loc) · 1.12 KB
/
report-bl-dest-ips.go
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
package reporting
import (
"html/template"
"os"
"github.com/globalsign/mgo/bson"
"github.com/activecm/rita/datatypes/blacklist"
"github.com/activecm/rita/datatypes/structure"
"github.com/activecm/rita/reporting/templates"
"github.com/activecm/rita/resources"
)
func printBLDestIPs(db string, res *resources.Resources) error {
f, err := os.Create("bl-dest-ips.html")
if err != nil {
return err
}
defer f.Close()
var blIPs []blacklist.BlacklistedIP
res.DB.Session.DB(db).
C(res.Config.T.Blacklisted.DestIPsTable).
Find(nil).Sort("-conn").All(&blIPs)
for i, ip := range blIPs {
var connected []structure.UniqueConnection
res.DB.Session.DB(db).
C(res.Config.T.Structure.UniqueConnTable).Find(
bson.M{"dst": ip.IP},
).All(&connected)
for _, uconn := range connected {
blIPs[i].ConnectedHosts = append(blIPs[i].ConnectedHosts, uconn.Src)
}
}
out, err := template.New("bl-dest-ips.html").Parse(templates.BLDestIPTempl)
if err != nil {
return err
}
w, err := getBLIPWriter(blIPs)
if err != nil {
return err
}
return out.Execute(f, &templates.ReportingInfo{DB: db, Writer: template.HTML(w)})
}