-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
115 lines (83 loc) · 2.25 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"github.com/alwashali/gologrhythm"
"gopkg.in/yaml.v2"
)
var apps []*gologrhythm.LogRhtyhm
var users []*User
// Load configuration yaml in config folder to config array
func load_config() []*SIEM {
confi := []*SIEM{}
items, _ := ioutil.ReadDir("secrets\\logrhythms")
for _, item := range items {
if !item.IsDir() {
if strings.HasSuffix(item.Name(), ".yaml") {
f, err := os.Open("secrets\\logrhythms\\" + item.Name())
if err != nil {
log.Fatal("Error opening the config file: ", item.Name(), err)
}
defer f.Close()
var siem SIEM
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&siem)
if err != nil {
log.Println("Error parsing the config file: ", item.Name(), err)
}
if siem.Token == "" || siem.Host == "" || siem.Name == "" {
log.Fatal("Error: one or more yaml file fields is missing: ", item.Name(), err)
}
confi = append(confi, &siem)
}
}
}
if len(confi) == 0 {
log.Fatal("Error loading SIEM config yaml files")
}
return confi
}
func load_users() []*User {
users := []*User{}
items, err := ioutil.ReadDir("secrets\\users")
if err != nil {
log.Fatal("Error reading secrets: ", err)
}
for _, item := range items {
if !item.IsDir() {
if strings.HasSuffix(item.Name(), ".yaml") {
f, err := os.Open("secrets\\users\\" + item.Name())
if err != nil {
log.Fatal("Error opening the config file: ", item.Name(), err)
}
defer f.Close()
var user User
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&user)
if err != nil {
log.Println("Error parsing the config file: ", item.Name(), err)
}
users = append(users, &user)
}
}
}
return users
}
func loadSecrets() {
config := load_config()
for _, c := range config {
if strings.Contains(c.Host, ":") {
app := gologrhythm.Create_App(c.Name, c.Token, c.Host)
apps = append(apps, app)
} else {
// default port is 8601
host_port := fmt.Sprintf("%s:%d", c.Host, 8501)
app := gologrhythm.Create_App(c.Name, c.Token, host_port)
apps = append(apps, app)
}
}
users = load_users()
}