forked from TheCreeper/JournalCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
129 lines (97 loc) · 2.15 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"encoding/json"
"io/ioutil"
// "os"
)
type GConfig struct {
Notifications Notifiers
SystemdJournal Journald
}
type Journald struct {
Sleep int64
Match []string
TriggerWords []string
}
type Notifiers struct {
Email NEmail
PushOver NPushOver
PushAlot NPushAlot
}
/* Notifiers */
type NEmail struct {
Host string
Port int
Username string
Password string
To []string
}
type NPushOver struct {
UserToken string
AppToken string
}
type NPushAlot struct {
Token string
}
/*
func GetDefaultConfig() GConfig {
var tfg GConfig
var nfr Notifiers
var mail NEmail
var pusho NPushOver
var pusha NPushAlot
mail.Host = "127.0.0.1"
mail.Port = 25
mail.Username = "notify@example.com"
mail.Password = ""
mail.To = []string {
"session opened for user"
}
nfr.Email = mail
pusho.UserToken = "token"
pusho.AppToken = "token"
nfr.PushOver = pusho
pusha.Token = "token"
nfr.PushAlot = pusha
tfg.Notifications = nfr
return tfg
}
func CheckIfResetConfig(args []string) {
if len(args) == 2 {
if args[1] == "reset" {
e := os.Remove(cfgfile)
if e != nil {
log.Fatal("Could not remove current config file. Permissions issue?")
}
Default := GetDefaultConfig()
out, e := json.Marshal(Default)
e = ioutil.WriteFile(cfgfile, out, 600)
if e != nil {
log.Fatal("cannot open settings file :(")
}
log.Fatal("Built config file. please fill it in.")
}
}
}
*/
func GetCFG(f string) (tfg GConfig, err error) {
b, err := ioutil.ReadFile(f)
if (err != nil) {
return
}
/*
tfg := GetDefaultConfig()
if e != nil {
out, e := json.Marshal(tfg)
e = ioutil.WriteFile(cfgfile, out, 600)
if e != nil {
log.Fatal("cannot open settings file :(")
}
log.Fatal("Built config file. please fill it in.")
}*/
err = json.Unmarshal(b, &tfg)
if (err != nil) {
return
}
return
}