forked from pagpeter/TrackMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
executable file
·43 lines (37 loc) · 1.17 KB
/
router.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
package main
import (
"fmt"
"net/url"
"strings"
"time"
)
func Log(msg string) {
t := time.Now()
formatted := t.Format("2006-01-02 15:04:05")
fmt.Printf("[%v] %v\n", formatted, msg)
}
func cleanIP(ip string) string {
return strings.Replace(strings.Replace(ip, "]", "", -1), "[", "", -1)
}
// Router returns bytes and content type that should be sent to the client
func Router(path string, res Response) ([]byte, string) {
res.TCPIP = TCPFingerprints[cleanIP(res.IP)]
res.TLS.JA4 = CalculateJa4(res.TLS)
// res.Donate = "Please consider donating to keep this API running."
Log(fmt.Sprintf("%v %v %v %v %v", cleanIP(res.IP), res.Method, res.HTTPVersion, res.path, res.TLS.JA3Hash))
// if GetUserAgent(res) == "" {
// return []byte("{\"error\": \"No user-agent\"}"), "text/html"
// }
if c.LogToDB && res.path != "/favicon.ico" {
SaveRequest(res)
}
u, _ := url.Parse("https://tls.peet.ws" + path)
m, _ := url.ParseQuery(u.RawQuery)
paths := getAllPaths()
if val, ok := paths[u.Path]; ok {
return val(res, m)
}
// 404
b, _ := ReadFile("static/404.html")
return []byte(strings.ReplaceAll(string(b), "/*DATA*/", fmt.Sprintf("%v", GetTotalRequestCount()))), "text/html"
}