This repository was archived by the owner on Mar 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
74 lines (67 loc) · 1.57 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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
type GConfig struct {
Token string
Watches []WatchFile
}
type WatchFile struct {
Path string
Banner string
TriggerWords []string
}
func GetDefaultConfig() GConfig {
var tfg GConfig
tfg.Token = "Fillmein"
tfg.Watches = make([]WatchFile, 0)
defaultwatch := WatchFile{
Path: "/var/log/auth.log",
TriggerWords: []string{
"Accepted publickey",
"Accepted password",
},
}
tfg.Watches = append(tfg.Watches, defaultwatch)
return tfg
}
func CheckIfResetConfig(args []string) {
if len(args) == 2 {
if args[1] == "reset" {
e := os.Remove("./.pushalotcfg.json")
if e != nil {
log.Fatal("Could not remove current config file. Permissions issue?")
}
Default := GetDefaultConfig()
out, e := json.Marshal(Default)
e = ioutil.WriteFile("./.pushalotcfg.json", out, 600)
if e != nil {
log.Fatal("cannot open settings file :(")
}
log.Fatal("Built config file. please fill it in.")
}
}
}
func GetCFG() GConfig {
b, e := ioutil.ReadFile("./.pushalotcfg.json")
tfg := GetDefaultConfig()
if e != nil {
out, e := json.Marshal(tfg)
e = ioutil.WriteFile("./.pushalotcfg.json", out, 600)
if e != nil {
log.Fatal("cannot open settings file :(")
}
log.Fatal("Built config file. please fill it in.")
}
e = json.Unmarshal(b, &tfg)
if e != nil {
log.Fatalf("Could not parse config settings. You may have to remove ./.pushalotcfg.json")
}
if tfg.Token == "Fillmein" {
log.Fatal("You need to fill in the config settings in ./.pushalotcfg.json")
}
return tfg
}