forked from pagpeter/TrackMe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.go
More file actions
executable file
·36 lines (31 loc) · 889 Bytes
/
router.go
File metadata and controls
executable file
·36 lines (31 loc) · 889 Bytes
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
package main
import (
"fmt"
"net/url"
"time"
)
func Log(msg string) {
t := time.Now()
formatted := t.Format("2006-02-01 15:04:05")
fmt.Printf("[%v] %v\n", formatted, msg)
}
// Router returns bytes and content type that should be sent to the client
func Router(path string, res Response) ([]byte, string) {
// res.Donate = "Please consider donating to keep this API running."
Log(fmt.Sprintf("%v %v %v %v %v", 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 b, "text/html"
}