-
Notifications
You must be signed in to change notification settings - Fork 0
/
brook.js
263 lines (257 loc) · 12.9 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
import { sh1, sh, s2b, b2s, home, splithostport, joinhostport, which, what, echo, log, sleep, now, exit } from "https://raw.githubusercontent.com/txthinking/denolib/master/f.js";
import { parse } from "https://deno.land/std@0.130.0/flags/mod.ts";
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);
if (parse(Deno.args).v) {
echo("v20221005");
exit(0);
}
var ip4 = (await sh1("curl -s -4 http3.ooo").catch((e) => "")).trim();
var ip6 = (await sh1("curl -s -6 http3.ooo").catch((e) => "")).trim();
if (!ip4 && !ip6) {
log("Can not find your server public IP");
exit(1);
}
var letsgo = async () => {
await which(lang("Choose what you want to do: "), [
{
anwser: lang("I want to run brook server/wsserver/wssserver/socks5"),
action: async () => {
await which(lang("Choose which you want to run: "), [
{
anwser: lang("I want to run brook server"),
action: async () => {
var port = await what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
var password = await what(lang("Type a password, such as mypassword: "), /.+/);
await sh(`joker brook server --listen :${port} --password "${password}"`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
if (ip4) {
await sh(`brook link -s ${joinhostport(ip4, port)} -p "${password}"`);
await sh(`brook link -s ${joinhostport(ip4, port)} -p "${password}" --udpovertcp`);
}
if (ip6) {
await sh(`brook link -s ${joinhostport(ip6, port)} -p "${password}"`);
await sh(`brook link -s ${joinhostport(ip6, port)} -p "${password}" --udpovertcp`);
}
echo(`${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 what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
var password = await what(lang("Type a password, such as mypassword: "), /.+/);
await sh(`joker brook wsserver --listen :${port} --password "${password}"`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
if (ip4) {
await sh(`brook link -s ws://${joinhostport(ip4, port)} -p "${password}"`);
}
if (ip6) {
await sh(`brook link -s ws://${joinhostport(ip6, port)} -p "${password}"`);
}
echo(`${lang("Tip: if there is a firewall, remember to open TCP")} ${port}`);
},
},
{
anwser: lang("I want to run brook wssserver"),
action: async () => {
if ((await sh1(`lsof -i:80`).catch((e) => "")).trim()) {
echo(lang("Port 80 is occupied!"));
exit(1);
}
var domain = await what(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await sh1(`dig +short -t A ${domain}`)).trim() != ip4 && (await sh1(`dig +short -t AAAA ${domain}`)).trim() != ip6) {
echo(lang("Please resolve your domain to your server's IP"));
exit(1);
}
var port = await what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
var password = await what(lang("Type a password, such as mypassword: "), /.+/);
await sh(`joker brook wssserver --domainaddress ${domain}:${port} --password "${password}"`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
await sh(`brook link -s wss://${joinhostport(domain, port)} -p "${password}"`);
echo(`${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 sh1(`lsof -i:80`).catch((e) => "")).trim()) {
echo(lang("Port 80 is occupied!"));
exit(1);
}
var domain = await what(lang("Type your domain, such as hello.com: "), /([1-9]|[a-z]|-|\.)+/);
if ((await sh1(`dig +short -t A ${domain}`)).trim() != ip4 && (await sh1(`dig +short -t AAAA ${domain}`)).trim() != ip6) {
echo(lang("Please resolve your domain to your server's IP"));
exit(1);
}
var port = await what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
var password = await what(lang("Type a password, such as mypassword: "), /.+/);
await sh(`joker brook wssserver --domainaddress ${domain}:${port} --password "${password}" --withoutBrookProtocol`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
await sh(`brook link -s wss://${joinhostport(domain, port)} -p "${password}" --withoutBrookProtocol`);
echo(`${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 what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
await sh(`joker brook socks5 -listen :${port} --socks5ServerIP ${ip}`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
await sh(`brook link -s socks5://${joinhostport(ip, port)}`);
echo(`${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 what(lang("Type a port, such as 9999: "), /\d+/);
if ((await sh1(`lsof -i:${port}`).catch((e) => "")).trim()) {
echo(lang("This port is occupied!"));
exit(1);
}
var username = await what(lang("Type a username, such as myusername: "), /.+/);
var password = await what(lang("Type a password, such as mypassword: "), /.+/);
await sh(`joker brook socks5 -listen :${port} --socks5ServerIP ${ip} --username "${username}" --password "${password}"`);
await sleep(2000);
await sh(`joker list`);
await sh("joker log `joker last`");
await sh(`brook link -s socks5://${joinhostport(ip, port)} --username "${username}" --password "${password}"`);
echo(`${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 sh(`joker list`);
},
},
{
anwser: lang("I want to stop a brook command"),
action: async () => {
await sh(`joker list`);
var id = await what(lang("Choose a PID your want to stop: "), /\d+/);
await sh(`joker stop ${id}`);
},
},
]);
};
await which("Language: ", [
{
anwser: "English",
action: async () => {
language = "en";
await letsgo();
},
},
{
anwser: "Chinese",
action: async () => {
language = "zh";
await letsgo();
},
},
]);