-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig.go
78 lines (64 loc) · 1.84 KB
/
config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"encoding/json"
"io/ioutil"
"log"
"regexp"
"time"
"github.com/boltdb/bolt"
)
type Keyword struct {
Keyword string
Bucket string
}
type Regex struct {
Regex string
compiled *regexp.Regexp
Bucket string
Match string
}
type Config struct {
keys map[string]time.Time
db *bolt.DB
Keywords []*Keyword // A list of keywords to search for in the data.
Regexes []*Regex // A list of regular expressions to test against data.
DbFile string `json:"database_file"` // File to use for the Store database.
MaxSize int `json:"max_size"` // Do not save files larger than this many bytes.
MaxTime int `json:"max_time"` // Max time, in seconds, to store previously downloaded keys.
Sleep int // Time, in seconds, to wait between each run.
GhToken string `json:"github_token"` // Github API token
Save bool
LocalPath string `json:"local_path"`
FileBatchSize int `json:"file_batch_size"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
WebBatchSize int `json:"web_batch_size"` // How many items to display per web page.
WebServerAddr string `json:"web_server_address"`
}
func newConfig() Config {
var c Config
data, err := ioutil.ReadFile("config.json")
if err != nil {
log.Fatal("[-] Could not read config file.")
}
err = json.Unmarshal(data, &c)
if err != nil {
log.Fatal("[-] Could not parse config file.")
}
c.keys = make(map[string]time.Time)
// Compile our regular expressions
for i, _ := range c.Regexes {
r := c.Regexes[i]
r.compiled = regexp.MustCompile(r.Regex)
}
if c.FileBatchSize == 0 {
c.FileBatchSize = 100
}
if c.WebBatchSize == 0 {
c.WebBatchSize = 25
}
if c.WebServerAddr == "" {
c.WebServerAddr = "127.0.0.1:5000"
}
return c
}