-
Notifications
You must be signed in to change notification settings - Fork 162
/
main.go
74 lines (60 loc) · 1.33 KB
/
main.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 (
"flag"
"log"
_ "net/http/pprof"
"runtime"
"github.com/nim4/DBShield/dbshield"
)
func usage(showUsage bool) {
print("DBShield " + dbshield.Version + "\n")
if showUsage {
flag.Usage()
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) // For Go < 1.5
config := flag.String("c", "/etc/dbshield.yml", "config `file`")
listPatterns := flag.Bool("l", false, "get list of captured patterns")
removePattern := flag.String("r", "", "remove a captured pattern")
listAbnormals := flag.Bool("a", false, "get list of abnormal queries")
showConfig := flag.Bool("k", false, "show parsed config and exit")
showVersion := flag.Bool("version", false, "show version")
showHelp := flag.Bool("h", false, "show help")
purge := flag.Bool("purge", false, "remove internal database")
//Parsing command line arguments
flag.Parse()
if *showHelp {
usage(true)
return
}
if *showVersion {
usage(false)
return
}
if err := dbshield.SetConfigFile(*config); err != nil {
log.Println(err)
return
}
if *listPatterns {
dbshield.Patterns()
return
}
if *removePattern != "" {
dbshield.RemovePattern(*removePattern)
return
}
if *listAbnormals {
dbshield.Abnormals()
return
}
if *showConfig {
dbshield.ShowConfig()
return
}
if *purge {
dbshield.Purge()
return
}
log.Println(dbshield.Start())
}