-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
89 lines (75 loc) · 2.27 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
// standard
"flag"
"log"
"net/http"
"os"
// external
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
var (
// config options
index_files StringArgs
uploads_dir string
address string
port string
addrport string
// channels
scanrequests chan *ScanRequest
namerequests chan *RuleSetRequest
rulerequests chan *RuleListRequest
// loggers
info *log.Logger
elog *log.Logger
)
func init() {
flag.Var(&index_files, "i", "path to yara rules")
flag.StringVar(&uploads_dir, "uploads", "uploads", "path to uploads directory")
flag.StringVar(&address, "address", "0.0.0.0", "address to bind to")
flag.StringVar(&port, "port", "9999", "port to bind to")
flag.Parse()
// initialize logger
info = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
elog = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
//build address string
addrport = address + ":" + port
}
func main() {
// create channels
info.Println("Initializing channels")
scanrequests = make(chan *ScanRequest)
namerequests = make(chan *RuleSetRequest)
rulerequests = make(chan *RuleListRequest)
// create scanner
info.Println("Initializing scanner")
scanner, err := NewScanner(scanrequests, namerequests, rulerequests)
if err != nil {
panic(err)
}
// load indexes
for _, index := range index_files {
info.Println("Loading index: " + index)
err = scanner.LoadIndex(index)
if err != nil {
panic(err)
}
}
// launch scanner
go scanner.Run()
//go scanner()
// setup http server and begin serving traffic
r := mux.NewRouter()
r.HandleFunc("/", IndexHandler).Methods("GET")
r.HandleFunc("/scanner/v1/files/", ListHandler).Methods("GET")
r.HandleFunc("/scanner/v1/files/{filename}", UploadHandler).Methods("PUT")
r.HandleFunc("/scanner/v1/files/{filename}", DownloadHandler).Methods("GET")
r.HandleFunc("/scanner/v1/files/{filename}", RemoveHandler).Methods("DELETE")
r.HandleFunc("/scanner/v1/files/{filename}/scan/", ScanHandler).Methods("GET")
r.HandleFunc("/scanner/v1/ruleset/", RuleSetListHandler).Methods("GET")
r.HandleFunc("/scanner/v1/ruleset/{ruleset}", RuleListHandler).Methods("GET")
http.Handle("/", r)
loggedRouter := handlers.CombinedLoggingHandler(os.Stdout, r)
http.ListenAndServe(addrport, loggedRouter)
}