-
Notifications
You must be signed in to change notification settings - Fork 36
/
routes.go
123 lines (111 loc) · 3.54 KB
/
routes.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
package main
import (
"encoding/json"
"fmt"
"net/url"
"strings"
)
func staticFile(file string) func(Response, url.Values) ([]byte, string) {
return func(Response, url.Values) ([]byte, string) {
b, _ := ReadFile(file)
return b, "text/html"
}
}
func apiAll(res Response, _ url.Values) ([]byte, string) {
return []byte(res.ToJson()), "application/json"
}
func apiTLS(res Response, _ url.Values) ([]byte, string) {
return []byte(Response{
TLS: res.TLS,
}.ToJson()), "application/json"
}
func apiClean(res Response, _ url.Values) ([]byte, string) {
akamai := "-"
hash := "-"
if res.HTTPVersion == "h2" {
akamai = res.Http2.AkamaiFingerprint
hash = GetMD5Hash(res.Http2.AkamaiFingerprint)
}
return []byte(SmallResponse{
JA3: res.TLS.JA3,
JA3Hash: res.TLS.JA3Hash,
JA4: res.TLS.JA4,
Akamai: akamai,
AkamaiHash: hash,
PeetPrint: res.TLS.PeetPrint,
PeetPrintHash: res.TLS.PeetPrintHash,
}.ToJson()), "application/json"
}
func apiRequestCount(_ Response, _ url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
return []byte(fmt.Sprintf(`{"total_requests": %v}`, GetTotalRequestCount())), "application/json"
}
func apiSearchJA3(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByJa3(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchH2(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByH2(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchPeetPrint(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByPeetPrint(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchUserAgent(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByUserAgent(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func index(r Response, v url.Values) ([]byte, string) {
res, ct := staticFile("static/index.html")(r, v)
data, _ := json.Marshal(r)
return []byte(strings.ReplaceAll(string(res), "/*DATA*/", string(data))), ct
}
func getAllPaths() map[string]func(Response, url.Values) ([]byte, string) {
return map[string]func(Response, url.Values) ([]byte, string){
"/": index,
"/explore": staticFile("static/explore.html"),
"/api/all": apiAll,
"/api/tls": apiTLS,
"/api/clean": apiClean,
"/api/request-count": apiRequestCount,
"/api/search-ja3": apiSearchJA3,
"/api/search-h2": apiSearchH2,
"/api/search-peetprint": apiSearchPeetPrint,
"/api/search-useragent": apiSearchUserAgent,
}
}