-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
146 lines (108 loc) · 3.35 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/signal"
"regexp"
"syscall"
"github.com/elazarl/goproxy"
)
type FNRadioClient struct {
Proxy *goproxy.ProxyHttpServer
Certificate *tls.Certificate
APIClient APIClient
Users map[string]APIUser
Party Party
BoundUser string
LogFile io.Writer
Logger *log.Logger
alreadyProxying bool
previousProxyEnabled uint64
previousProxyServer string
}
var client *FNRadioClient
func setupCloseHandler() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
client.Destroy()
os.Exit(0)
}()
}
func (client *FNRadioClient) handleAkamaizedConnect(host string, _ *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
return &goproxy.ConnectAction{
Action: goproxy.ConnectMitm,
TLSConfig: goproxy.TLSConfigFromCA(client.Certificate),
}, host
}
func (client *FNRadioClient) handleAkamaizedRequest(r *http.Request, _ *goproxy.ProxyCtx) (*http.Request, *http.Response) {
regex := regexp.MustCompile(`^/([^/,\s]+)/(main|master)\.blurl$`)
matchString := regex.FindStringSubmatch(r.URL.Path)
if len(matchString) > 0 {
for _, binding := range client.Users[client.BoundUser].Bindings {
if binding.ID == matchString[1] {
_ = client.Logger.Output(2, "Rewriting request "+r.URL.String()+" to station "+binding.StationUser+":"+binding.StationID)
r.URL, _ = url.Parse(APIRoot + "/users/" + binding.StationUser + "/stations/" + binding.StationID)
r.Header.Set("Authorization", client.APIClient.generateAuthHeader())
r.Header.Set("X-API-Root", APIRoot)
r.Host = r.URL.Host
break
}
}
}
return r, nil
}
func (client *FNRadioClient) Destroy() {
client.revertSystemProxy()
}
func (client *FNRadioClient) FetchSelf() {
_ = client.Logger.Output(2, "Fetching self")
user, err := client.APIClient.GetUser("@me")
if err != nil {
client.Destroy()
panic(err)
}
client.BoundUser = client.APIClient.ID
client.Users[client.APIClient.ID] = user
}
func main() {
fmt.Println("FNRadio by Jaren (@The1Jaren) [" + Version + "]")
fmt.Println("")
fmt.Println("Join our discord: https://discord.gg/bgRM3XdhnA")
fmt.Println("SAC Code: Jaren")
client = &FNRadioClient{
Proxy: goproxy.NewProxyHttpServer(),
Certificate: setupSSL(),
APIClient: APIClient{},
Users: map[string]APIUser{},
LogFile: ioutil.Discard,
}
logFile, err := os.OpenFile("FNRadio.log", os.O_CREATE|os.O_TRUNC, 0666)
if err == nil {
client.LogFile = logFile
}
client.Logger = log.New(client.LogFile, "[FNRadio] ", log.LstdFlags)
client.APIClient.Setup()
client.FetchSelf()
client.Proxy.Verbose = true
client.Proxy.Logger = log.New(client.LogFile, "[GoProxy] ", log.LstdFlags)
client.Proxy.OnRequest(goproxy.ReqHostIs("fortnite-vod.akamaized.net:443")).HandleConnect(goproxy.FuncHttpsHandler(client.handleAkamaizedConnect))
client.Proxy.OnRequest(goproxy.ReqHostIs("fortnite-vod.akamaized.net:443")).Do(goproxy.FuncReqHandler(client.handleAkamaizedRequest))
client.Proxy.OnRequest(goproxy.ReqHostIs("cdn-0001.qstv.on.epicgames.com:443")).HandleConnect(goproxy.AlwaysReject)
client.setupSystemProxy()
setupCloseHandler()
go setupCLI()
go client.readGameLog()
err = http.ListenAndServe("127.0.0.1:18149", client.Proxy)
if err != nil {
fmt.Println(err)
client.Destroy()
}
}