-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrook.js
319 lines (313 loc) · 16.7 KB
/
brook.js
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import lib from 'https://bash.ooo/lib.js';
import { $ } from 'bun';
function joinhostport(host, port){
if(host.indexOf(":") != -1){
return `[${host}]:${port}`
}
return `${host}:${port}`
}
var i18n = {
"Choose what you want to do: ": {
zh: "选择你想做什么: ",
},
"I want to run brook server/wsserver/wssserver/socks5": {
zh: "我想运行 brook server/wsserver/wssserver/socks5",
},
"Choose which you want to run: ": {
zh: "选择你要运行什么: ",
},
"I want to run brook server": {
zh: "我想运行 brook server",
},
"Type a port, such as 9999: ": {
zh: "输入一个端口,比如 9999: ",
},
"This port is occupied!": {
zh: "这个端口被占用了!",
},
"Type a password, such as mypassword: ": {
zh: "输入一个密码,比如 mypassword: ",
},
"Tip: if there is a firewall, remember to open TCP and UDP": {
zh: "如果有防火墙,记得开放 TCP 和 UDP 端口",
},
"I want to run brook wsserver": {
zh: "我想运行 brook wsserver",
},
"Tip: if there is a firewall, remember to open TCP": {
zh: "如果有防火墙,记得开放 TCP 端口",
},
"I want to run brook wssserver": {
zh: "我想运行 brook wssserver",
},
"Port 80 is occupied!": {
zh: "端口 80 被占用了!",
},
"Type your domain, such as hello.com:": {
zh: "输入你的域名,比如 hello.com: ",
},
"Please resolve your domain to your server's IP": {
zh: "请解析你的域名到你服务器的IP",
},
"Tip: if there is a firewall, remember to open TCP 80 and": {
zh: "如果有防火墙,记得开放 TCP 端口 80 和",
},
"I want to run brook wssserver withoutBrookProtocol": {
zh: "我想运行 brook wssserver 及 withoutBrookProtocol",
},
"I want to run brook socks5 without username and password": {
zh: "我想运行 brook socks5,不设置用户名和密码",
},
"I want to run brook socks5 with username and password": {
zh: "我想运行 brook socks5,并设置用户名和密码",
},
"Type a username, such as myusername: ": {
zh: "输入一个用户名,比如 myusername: ",
},
"I want to see running brook command": {
zh: "我想查看运行中的 brook 命令",
},
"I want to stop a brook command": {
zh: "我想停止一个运行中的 brook 命令",
},
"Choose a PID your want to stop: ": {
zh: "选择你要停止的命令 ID",
},
};
var language = "";
var lang = (s) => (i18n[s] ? i18n[s][language] ?? s : s);
var ip4 = (await $`curl -s -4 http3.ooo`.text().catch((e) => "")).trim();
var ip6 = (await $`curl -s -6 http3.ooo`.text().catch((e) => "")).trim();
if (!ip4) {
console.log("Can not find your server public IPv4");
process.exit(1);
}
if (!ip6) {
console.log("Can not find your server public IPv6");
process.exit(1);
}
var letsgo = async () => {
await lib.select(lang("Choose what you want to do: "), [
{
anwser: lang("I want to run brook server/wsserver/wssserver/socks5"),
action: async () => {
await lib.select(lang("Choose which you want to run: "), [
{
anwser: lang("I want to run brook server"),
action: async () => {
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook server --listen :${port} --password "${password}"`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
if (ip4) {
await $`brook link -s ${joinhostport(ip4, port)} -p "${password}" --udpovertcp`
}
if (ip6) {
await $`brook link -s ${joinhostport(ip6, port)} -p "${password}" --udpovertcp`
}
console.log(`${lang("Tip: if there is a firewall, remember to open TCP and UDP")} ${port}`);
},
},
{
anwser: lang("I want to run brook wsserver"),
action: async () => {
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook wsserver --listen :${port} --password "${password}"`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
if (ip4) {
await $`brook link -s ws://${joinhostport(ip4, port)} -p "${password}"`
}
if (ip6) {
await $`brook link -s ws://${joinhostport(ip6, port)} -p "${password}"`
}
console.log(`${lang("Tip: if there is a firewall, remember to open TCP")} ${port}`);
},
},
{
anwser: lang("I want to run brook wssserver"),
action: async () => {
if ((await $`lsof -i:80`.text().catch((e) => "")).trim()) {
console.log(lang("Port 80 is occupied!"));
process.exit(1);
}
var domain = await lib.question(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await $`dig +short -t A ${domain}`.text()).trim() != ip4 && (await $`dig +short -t AAAA ${domain}`.text()).trim() != ip6) {
console.log(lang("Please resolve your domain to your server's IP"));
process.exit(1);
}
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook wssserver --domainaddress ${domain}:${port} --password "${password}"`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s wss://${joinhostport(domain, port)} -p "${password}"`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP 80 and")} ${port}`);
},
},
{
anwser: lang("I want to run brook wssserver withoutBrookProtocol"),
action: async () => {
if ((await $`lsof -i:80`.text().catch((e) => "")).trim()) {
console.log(lang("Port 80 is occupied!"));
process.exit(1);
}
var domain = await lib.question(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await $`dig +short -t A ${domain}`.text()).trim() != ip4 && (await $`dig +short -t AAAA ${domain}`.text()).trim() != ip6) {
console.log(lang("Please resolve your domain to your server's IP"));
process.exit(1);
}
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook wssserver --domainaddress ${domain}:${port} --password "${password}" --withoutBrookProtocol`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s wss://${joinhostport(domain, port)} -p "${password}" --withoutBrookProtocol`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP 80 and")} ${port}`);
},
},
{
anwser: lang("I want to run brook quicserver"),
action: async () => {
if ((await $`lsof -i:80`.text().catch((e) => "")).trim()) {
console.log(lang("Port 80 is occupied!"));
process.exit(1);
}
var domain = await lib.question(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await $`dig +short -t A ${domain}`.text()).trim() != ip4 && (await $`dig +short -t AAAA ${domain}`.text()).trim() != ip6) {
console.log(lang("Please resolve your domain to your server's IP"));
process.exit(1);
}
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook quicserver --domainaddress ${domain}:${port} --password "${password}"`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s quic://${joinhostport(domain, port)} -p "${password}" --udpoverstream`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP 80 and")} ${port}`);
},
},
{
anwser: lang("I want to run brook quicserver withoutBrookProtocol"),
action: async () => {
if ((await $`lsof -i:80`.text().catch((e) => "")).trim()) {
console.log(lang("Port 80 is occupied!"));
process.exit(1);
}
var domain = await lib.question(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await $`dig +short -t A ${domain}`.text()).trim() != ip4 && (await $`dig +short -t AAAA ${domain}`.text()).trim() != ip6) {
console.log(lang("Please resolve your domain to your server's IP"));
process.exit(1);
}
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook quicserver --domainaddress ${domain}:${port} --password "${password}" --withoutBrookProtocol`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s quic://${joinhostport(domain, port)} -p "${password}" --udpoverstream --withoutBrookProtocol`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP 80 and")} ${port}`);
},
},
{
anwser: lang("I want to run brook socks5 without username and password"),
action: async () => {
var ip = ip4 ? ip4 : ip6;
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
await $`joker brook socks5 -listen :${port} --socks5ServerIP ${ip}`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s socks5://${joinhostport(ip, port)}`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP and UDP")} ${port}`);
},
},
{
anwser: lang("I want to run brook socks5 with username and password"),
action: async () => {
var ip = ip4 ? ip4 : ip6;
var port = await lib.question(lang("Type a port, such as 9999: "), /\d+/);
if ((await $`lsof -i:${port}`.text().catch((e) => "")).trim()) {
console.log(lang("This port is occupied!"));
process.exit(1);
}
var username = await lib.question(lang("Type a username, such as myusername: "), /.+/);
var password = await lib.question(lang("Type a password, such as mypassword: "), /.+/);
await $`joker brook socks5 -listen :${port} --socks5ServerIP ${ip} --username "${username}" --password "${password}"`
await Bun.sleep(2000);
await $`joker list`
await $`joker log $(joker last)`
await $`brook link -s socks5://${joinhostport(ip, port)} --username "${username}" --password "${password}"`
console.log(`${lang("Tip: if there is a firewall, remember to open TCP and UDP")} ${port}`);
},
},
]);
},
},
{
anwser: lang("I want to see running brook command"),
action: async () => {
await $`joker list`
},
},
{
anwser: lang("I want to stop a brook command"),
action: async () => {
await $`joker list`
var id = await lib.question(lang("Choose a PID your want to stop: "), /\d+/);
await $`joker stop ${id}`
},
},
]);
};
await lib.select("Language: ", [
{
anwser: "English",
action: async () => {
language = "en";
await letsgo();
},
},
{
anwser: "Chinese",
action: async () => {
language = "zh";
await letsgo();
},
},
]);