/
setup.go
executable file
·64 lines (52 loc) · 1.29 KB
/
setup.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
package pitchfork
import (
"time"
)
/*
* Trident Pitchfork Lib Setup
*
* Split out so that we can call it for Tests cases too next to normal server behaviour
*/
func Setup(toolname string, confroot string, verbosedb bool, app_schema_version int) (err error) {
/* Load configuration */
err = Config.Load(toolname, confroot)
if err != nil {
Errf("Failed: %s", err.Error())
return
}
/* Our database details */
DB_Init(verbosedb)
/* Tell Pitchfork what the App DB version is */
DB_SetAppVersion(app_schema_version)
/* Try the database connection */
err = DB.Connect_def()
if err != nil {
Errf("DB connection failed: %s", err.Error())
return
}
/* Load Weak Password Dictionaries */
err = Pw_checkweak_load()
if err != nil {
Errf("Loading Weak Password Dictionaries failed: %s", err.Error())
return
}
/* Initalize translation matrix */
err = SetupTranslation()
if err != nil {
Errf("Loading translation languages failed: %s", err.Error())
return
}
return
}
/* Start background services */
func Starts() {
/* Start IP Tracker -- against brute force login attempts */
Iptrk_start(5, 10*time.Hour, "1 hour")
/* Start JWT Invalidation caching/clearing */
JwtInv_start(30 * time.Minute)
}
/* Should be deferred Starts() call */
func Stops() {
Iptrk_stop()
JwtInv_stop()
}