-
Notifications
You must be signed in to change notification settings - Fork 419
/
fire.go
62 lines (55 loc) · 1.04 KB
/
fire.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
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"encoding/csv"
"fmt"
"os"
"time"
"github.com/crowdsecurity/crowdsec/pkg/cticlient"
)
func intPtr(i int) *int {
return &i
}
func main() {
client := cticlient.NewCrowdsecCTIClient(cticlient.WithAPIKey(os.Getenv("CTI_API_KEY")))
paginator := cticlient.NewFirePaginator(client, cticlient.FireParams{
Limit: intPtr(1000),
})
csvHeader := []string{
"value",
"reason",
"type",
"scope",
"duration",
}
csvFile, err := os.Create("fire.csv")
if err != nil {
panic(err)
}
defer csvFile.Close()
csvWriter := csv.NewWriter(csvFile)
allItems := make([][]string, 0)
for {
items, err := paginator.Next()
if err != nil {
panic(err)
}
if items == nil {
break
}
for _, item := range items {
if item.State == "refused" {
continue
}
banDuration := time.Until(item.Expiration.Time)
allItems = append(allItems, []string{
item.Ip,
"fire-import",
"ban",
"ip",
fmt.Sprintf("%ds", int(banDuration.Seconds())),
})
}
}
csvWriter.Write(csvHeader)
csvWriter.WriteAll(allItems)
}