forked from radkesvat/WaterWall-Docs
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinstall.sh
More file actions
3864 lines (3647 loc) · 104 KB
/
install.sh
File metadata and controls
3864 lines (3647 loc) · 104 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
purple='\033[0;35m'
cyan='\033[0;36m'
rest='\033[0m'
# Detect the Linux distribution
detect_distribution() {
if [ -f /etc/os-release ]; then
source /etc/os-release
case "${ID}" in
ubuntu | debian)
p_m="apt-get"
;;
centos)
p_m="yum"
;;
fedora)
p_m="dnf"
;;
*)
echo -e "${red}Unsupported distribution!${rest}"
exit 1
;;
esac
else
echo -e "${red}Unsupported distribution!${rest}"
exit 1
fi
}
# Install Dependencies
check_dependencies() {
detect_distribution
local dependencies
dependencies=("wget" "curl" "unzip" "socat" "jq")
for dep in "${dependencies[@]}"; do
if ! command -v "${dep}" &>/dev/null; then
echo -e "${cyan} ${dep} ${yellow}is not installed. Installing...${rest}"
sudo "${p_m}" install "${dep}" -y
fi
done
}
# Check and nstall waterwall
install_waterwall() {
LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/radkesvat/WaterWall/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
INSTALL_DIR="/root/Waterwall"
FILE_NAME="Waterwall"
if [ ! -f "$INSTALL_DIR/$FILE_NAME" ]; then
check_dependencies
echo ""
echo -e "${cyan}============================${rest}"
echo -e "${cyan}Installing Waterwall...${rest}"
if [ -z "$LATEST_RELEASE" ]; then
echo -e "${red}Failed to get the latest release version.${rest}"
return 1
LATEST_RELEASE
fi
echo -e "${cyan}Latest version: ${yellow}${LATEST_RELEASE}${rest}"
# Determine the download URL based on the architecture
ARCH=$(uname -m)
if [ "$ARCH" == "x86_64" ]; then
DOWNLOAD_URL="https://github.com/radkesvat/WaterWall/releases/download/${LATEST_RELEASE}/Waterwall-linux-64.zip"
elif [ "$ARCH" == "aarch64" ]; then
DOWNLOAD_URL="https://github.com/radkesvat/WaterWall/releases/download/${LATEST_RELEASE}/Waterwall-linux-arm64.zip"
else
echo -e "${red}Unsupported architecture: $ARCH${rest}"
return 1
fi
# Create the installation directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Download the ZIP file directly into INSTALL_DIR
ZIP_FILE="$INSTALL_DIR/Waterwall.zip"
curl -L -o "$ZIP_FILE" "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then
echo -e "${red}Download failed.${rest}"
return 1
fi
# Unzip the downloaded file directly into INSTALL_DIR
unzip "$ZIP_FILE" -d "$INSTALL_DIR" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${red}Unzip failed.${rest}"
rm -f "$ZIP_FILE"
return 1
fi
rm -f "$ZIP_FILE"
# Set executable permission for Waterwall binary
sudo chmod +x "$INSTALL_DIR/$FILE_NAME"
if [ $? -ne 0 ]; then
echo -e "${red}Failed to set executable permission for Waterwall.${rest}"
return 1
fi
echo -e "${green}Waterwall installed successfully in $INSTALL_DIR.${rest}"
echo -e "${cyan}============================${rest}"
return 0
fi
}
#===================================
#10
# SSL CERTIFICATE
install_acme() {
cd ~
echo -e "${green}install acme...${rest}"
curl https://get.acme.sh | sh
if [ $? -ne 0 ]; then
echo -e "${red}install acme failed${rest}"
return 1
else
echo -e "${green}install acme succeed${rest}"
fi
return 0
}
# SSL Menu
ssl_cert_issue_main() {
echo -e "${yellow} ***************************${rest}"
echo -e "${yellow} |${purple} [1]${green} Get SSL Certificate${yellow} |${rest}"
echo -e "${yellow} |${purple} [2]${green} Revoke${yellow} |${rest}"
echo -e "${yellow} |${purple} [3]${green} Force Renew${yellow} |${rest}"
echo -e "${yellow} |${blue}*************************${yellow}|${rest}"
echo -e "${yellow} |${purple} [0]${green} Back to Main Menu${yellow} |${rest}"
echo -e "${yellow} ***************************${rest}"
echo -en "${cyan} Enter your choice (1-3): ${rest}"
read -r choice
case "$choice" in
0)
main
;;
1)
ssl_cert_issue
;;
2)
local domain=""
echo -e "${cyan}============================================${rest}"
echo -en "${green}Please enter your domain name to revoke the certificate: ${rest}"
read -r domain
~/.acme.sh/acme.sh --revoke -d "${domain}"
if [ $? -ne 0 ]; then
echo -e "${cyan}============================================${rest}"
echo -e "${red}Failed to revoke certificate. Please check logs.${rest}"
else
echo -e "${cyan}============================================${rest}"
echo -e "${green}Certificate revoked${rest}"
fi
;;
3)
local domain=""
echo -e "${cyan}============================================${rest}"
echo -en "${green}Please enter your domain name to forcefully renew an SSL certificate: ${rest}"
read -r domain
~/.acme.sh/acme.sh --renew -d "${domain}" --force
if [ $? -ne 0 ]; then
echo -e "${cyan}============================================${rest}"
echo -e "${red}Failed to renew certificate. Please check logs.${rest}"
else
echo -e "${cyan}============================================${rest}"
echo -e "${green}Certificate renewed${rest}"
fi
;;
*) echo -e "${red}Invalid choice${rest}" ;;
esac
}
ssl_cert_issue() {
echo -e "${cyan}============================================${rest}"
release=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
# check for acme.sh first
if [ ! -f ~/.acme.sh/acme.sh ]; then
echo -e "${green}acme.sh could not be found. we will install it${rest}"
install_acme
if [ $? -ne 0 ]; then
echo -e "${red}install acme failed, please check logs${rest}"
exit 1
fi
fi
# install socat second
case "${release}" in
ubuntu | debian | armbian)
apt update -y
;;
centos | almalinux | rocky | oracle)
yum -y update
;;
fedora)
dnf -y update
;;
arch | manjaro | parch)
pacman -Sy --noconfirm socat
;;
*)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${rest}\n"
exit 1
;;
esac
if [ $? -ne 0 ]; then
echo -e "${red}install socat failed, please check logs${rest}"
exit 1
else
echo -e "${cyan}============================${rest}"
fi
# get the domain here,and we need verify it
local domain=""
echo -en "${green}Please enter your domain name: ${rest}"
read -r domain
echo -e "${green}Your domain is:${yellow}${domain}${green},check it...${rest}"
# check if there already exists a cert
local currentCert
currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
if [ "${currentCert}" == "${domain}" ]; then
local certInfo
certInfo=$(~/.acme.sh/acme.sh --list)
echo -e "${red}system already has certs here,can not issue again,Current certs details:${rest}"
echo -e "${green} $certInfo${rest}"
exit 1
else
echo -e "${green} your domain is ready for issuing cert now...${rest}"
fi
# create a directory for install cert
certPath="/root/Waterwall/cert"
if [ ! -d "$certPath" ]; then
mkdir -p "$certPath"
else
rm -rf "$certPath"
mkdir -p "$certPath"
fi
# get needed port here
echo -e "${cyan}============================================${rest}"
echo -en "${green}Please choose which port you want to use [${yellow}Default: 80${green}]: ${rest}"
read -r WebPort
WebPort=${WebPort:-80}
if [[ ${WebPort} -gt 65535 || ${WebPort} -lt 1 ]]; then
echo -e "${red}your input ${WebPort} is invalid,will use default port${rest}"
WebPort=80
fi
echo -e "${green} will use port:${WebPort} to issue certs,please make sure this port is open...${rest}"
echo -e "${cyan}============================================${rest}"
# issue the cert
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d "${domain}" --listen-v6 --standalone --httpport "${WebPort}"
if [ $? -ne 0 ]; then
echo -e "${red}issue certs failed,please check logs${rest}"
rm -rf ~/.acme.sh/"${domain}"
exit 1
else
echo -e "${yellow}issue certs succeed,installing certs...${rest}"
fi
# install cert
~/.acme.sh/acme.sh --installcert -d "${domain}" \
--key-file /root/Waterwall/cert/privkey.pem \
--fullchain-file /root/Waterwall/cert/fullchain.pem
if [ $? -ne 0 ]; then
echo -e "${red}install certs failed,exit${rest}"
rm -rf ~/.acme.sh/"${domain}"
exit 1
else
echo -e "${green} install certs succeed,enable auto renew...${rest}"
fi
~/.acme.sh/acme.sh --upgrade --auto-upgrade
if [ $? -ne 0 ]; then
echo -e "${red}auto renew failed, certs details:${rest}"
ls -lah "$certPath"/*
chmod 755 "$certPath"/*
exit 1
else
echo -e "${green} auto renew succeed, certs details:${rest}"
ls -lah "$certPath"/*
chmod 755 "$certPath"/*
fi
sudo systemctl restart trojan.service >/dev/null 2>&1
sudo systemctl restart Waterwall.service >/dev/null 2>&1
}
#===================================
#00
# Core.json
create_core_json() {
if [ ! -d /root/Waterwall ]; then
mkdir -p /root/Waterwall
fi
if [ ! -f ~/Waterwall/core.json ]; then
echo -e "${cyan}Creating core.json...${rest}"
echo ""
cat <<EOF >~/Waterwall/core.json
{
"log": {
"path": "log/",
"core": {
"loglevel": "DEBUG",
"file": "core.log",
"console": true
},
"network": {
"loglevel": "DEBUG",
"file": "network.log",
"console": true
},
"dns": {
"loglevel": "SILENT",
"file": "dns.log",
"console": false
}
},
"dns": {},
"misc": {
"workers": 0,
"ram-profile": "server",
"libs-path": "libs/"
},
"configs": [
"config.json"
]
}
EOF
fi
}
#===================================
#0
# Trojan Core.json
create_trojan_core_json() {
if [ ! -d /root/Waterwall/trojan ]; then
mkdir -p /root/Waterwall/trojan
fi
if [ ! -f ~/Waterwall/trojan/core.json ]; then
echo -e "${cyan}Creating core.json...${rest}"
echo ""
cat <<EOF >~/Waterwall/trojan/core.json
{
"log": {
"path": "log/",
"core": {
"loglevel": "DEBUG",
"file": "core.log",
"console": true
},
"network": {
"loglevel": "DEBUG",
"file": "network.log",
"console": true
},
"dns": {
"loglevel": "SILENT",
"file": "dns.log",
"console": false
}
},
"dns": {},
"misc": {
"workers": 0,
"ram-profile": "server",
"libs-path": "libs/"
},
"configs": [
"trojan_config.json"
]
}
EOF
fi
}
#===================================
#1
# Simple Tunnel
simple_direct() {
# Function to create simple port to port config
create_simple_port_to_port() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter the local port: ${rest}"
read -r local_port
echo -en "${green}Enter the remote address: ${rest}"
read -r remote_address
echo -en "${green}Enter the remote port: ${rest}"
read -r remote_port
echo -en "${green}Do you want to Enable PreConnect (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r PreConnect
if [ "$PreConnect" != "no" ]; then
echo -en "${green}Enter Minimum-unused [${yellow}Default: 1${green}]: ${rest}"
read -r min_un
min_un=${min_un:-1}
fi
install_waterwall
if [ "$PreConnect" == "no" ]; then
output="output"
preconnect_block=""
else
output="precon_client"
preconnect_block=$(
cat <<EOF
{
"name": "precon_client",
"type": "PreConnectClient",
"settings": {
"minimum-unused": $min_un
},
"next": "output"
},
EOF
)
fi
cat <<EOF >/root/Waterwall/config.json
{
"name": "simple_port_to_port",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": $local_port,
"nodelay": true
},
"next": "$output"
},
$preconnect_block
{
"name": "output",
"type": "TcpConnector",
"settings": {
"nodelay": true,
"address": "$remote_address",
"port": $remote_port
}
}
]
}
EOF
}
# Function to create simple multiport to port config
create_simple_multiport_to_port() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter the starting local port [${yellow}greater than 23${green}]: ${rest}"
read -r start_port
echo -en "${green}Enter the ending local port [${yellow}less than 65535${green}]: ${rest}"
read -r end_port
echo -en "${green}Enter the remote address: ${rest}"
read -r remote_address
echo -en "${green}Enter the remote port: ${rest}"
read -r remote_port
echo -en "${green}Do you want to Enable PreConnect (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r PreConnect
if [ "$PreConnect" != "no" ]; then
echo -en "${green}Enter Minimum-unused [${yellow}Default: 1${green}]: ${rest}"
read -r min_un
min_un=${min_un:-1}
fi
install_waterwall
if [ "$PreConnect" == "no" ]; then
output="output"
preconnect_block=""
else
output="precon_client"
preconnect_block=$(
cat <<EOF
{
"name": "precon_client",
"type": "PreConnectClient",
"settings": {
"minimum-unused": $min_un
},
"next": "output"
},
EOF
)
fi
cat <<EOF >/root/Waterwall/config.json
{
"name": "simple_multiport_to_port",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": [$start_port,$end_port],
"nodelay": true
},
"next": "$output"
},
$preconnect_block
{
"name": "output",
"type": "TcpConnector",
"settings": {
"nodelay": true,
"address": "$remote_address",
"port": $remote_port
}
}
]
}
EOF
}
# Function to create multiport to multiport config
create_simple_multiport() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter the starting local port [${yellow}greater than 23${green}]: ${rest}"
read -r start_port
echo -en "${green}Enter the ending local port [${yellow}less than 65535${green}]: ${rest}"
read -r end_port
echo -en "${green}Enter the remote address: ${rest}"
read -r remote_address
echo -en "${green}Do you want to Enable PreConnect (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r PreConnect
if [ "$PreConnect" != "no" ]; then
echo -en "${green}Enter Minimum-unused [${yellow}Default: 1${green}]: ${rest}"
read -r min_un
min_un=${min_un:-1}
fi
install_waterwall
if [ "$PreConnect" == "no" ]; then
output="output"
preconnect_block=""
else
output="precon_client"
preconnect_block=$(
cat <<EOF
{
"name": "precon_client",
"type": "PreConnectClient",
"settings": {
"minimum-unused": $min_un
},
"next": "output"
},
EOF
)
fi
cat <<EOF >/root/Waterwall/config.json
{
"name": "simple_multiport",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": [$start_port,$end_port],
"nodelay": true
},
"next": "$output"
},
$preconnect_block
{
"name": "output",
"type": "TcpConnector",
"settings": {
"nodelay": true,
"address": "$remote_address",
"port": "src_context->port"
}
}
]
}
EOF
}
# Function to create simple port to port x2 config
create_simple_port_to_port_x2() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter the local port${cyan}s${green} (${yellow}comma-separated${green}): ${rest}"
read -r local_ports
echo -en "${green}Enter the remote ${cyan}address ${green}or ${cyan}addresses(${yellow}comma-separated${green}):${rest} "
read -r remote_addresses
echo -en "${green}Enter the remote port${cyan}s ${green}(${yellow}comma-separated${green}): ${rest}"
read -r remote_ports
IFS=',' read -ra local_ports_array <<<"$local_ports"
IFS=',' read -ra remote_addresses_array <<<"$remote_addresses"
IFS=',' read -ra remote_ports_array <<<"$remote_ports"
if [ ${#remote_addresses_array[@]} -eq 1 ]; then
single_remote_address="${remote_addresses_array[0]}"
remote_addresses_array=()
for ((i = 0; i < ${#local_ports_array[@]}; i++)); do
remote_addresses_array+=("$single_remote_address")
done
fi
if [ ${#local_ports_array[@]} -ne ${#remote_addresses_array[@]} ] || [ ${#local_ports_array[@]} -ne ${#remote_ports_array[@]} ]; then
echo -e "${red}Error: Number of local ports, remote addresses, and remote ports must be equal.${rest}"
return 1
fi
install_waterwall
cat <<EOF >/root/Waterwall/config.json
{
"name": "simple_port_to_port_x2",
"nodes": [
EOF
for i in "${!local_ports_array[@]}"; do
local_port="${local_ports_array[$i]}"
remote_address="${remote_addresses_array[$i]}"
remote_port="${remote_ports_array[$i]}"
cat <<EOF >>/root/Waterwall/config.json
{
"name": "input$((i + 1))",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": $local_port,
"nodelay": true
},
"next": "output$((i + 1))"
},
{
"name": "output$((i + 1))",
"type": "TcpConnector",
"settings": {
"nodelay": true,
"address": "$remote_address",
"port": $remote_port
}
}$([ "$i" -lt $((${#local_ports_array[@]} - 1)) ] && echo ",")
EOF
done
cat <<EOF >>/root/Waterwall/config.json
]
}
EOF
}
echo -e "${yellow} *************************************${rest}"
echo -e "${yellow} | ${purple}[1]${green} Simple port to port${yellow} |${rest}"
echo -e "${yellow} | ${purple}[2]${green} Simple Multiport to port${yellow} |${rest}"
echo -e "${yellow} | ${purple}[3]${green} Simple Multiport to Multiport${yellow} |${rest}"
echo -e "${yellow} | ${purple}[4]${green} Simple port to same port x2${yellow} |${rest}"
echo -e "${yellow} |${blue}***********************************${yellow}|${rest}"
echo -e "${yellow} | ${purple}[0] ${green}Back to ${purple}Main Menu${yellow} |${rest}"
echo -e "${yellow} *************************************${rest}"
echo -en " ${cyan}Enter your choice (1-4): ${rest}"
read -r choice
case $choice in
1)
create_simple_port_to_port
waterwall_service
;;
2)
create_simple_multiport_to_port
waterwall_service
;;
3)
create_simple_multiport
waterwall_service
;;
4)
create_simple_port_to_port_x2
waterwall_service
;;
0)
main
;;
*)
echo -e "${red}Invalid choice!${rest}"
;;
esac
}
#===================================
#2
# Tls Tunnel
tls() {
# Function to create tls port to port iran
create_tls_port_to_port_iran() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter Your Domain:${rest} "
read -r domain
echo -en "${green}Enter the local (${yellow}Client Config${green}) port: ${rest}"
read -r local_port
echo -en "${green}Enter the remote address: ${rest}"
read -r remote_address
echo -en "${green}Enter the remote (${yellow}Connection${green}) port: ${rest}"
read -r remote_port
echo -en "${green}Do you want to Enable Http2 ? (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r http2
http2=${http2:-yes}
if [ "$http2" == "no" ]; then
echo -en "${green}Do you want to Enable PreConnect ? (yes/no) [${yellow}Default: yes${green}]: ${rest}"
read -r PreConnect
PreConnect=${PreConnect:-yes}
if [ "$PreConnect" != "no" ]; then
echo -en "${green}Enter Minimum-unused [${yellow}Default: 1${green}]: ${rest}"
read -r min_un
min_un=${min_un:-1}
fi
echo -e "${cyan}============================${rest}"
fi
if [ "$http2" == "no" ] && [ "$PreConnect" == "no" ]; then
output="sslclient"
elif [ "$http2" == "no" ] && [ "$PreConnect" == "yes" ]; then
output="precon_client"
else
output="pbclient"
fi
install_waterwall
json=$(
cat <<EOF
{
"name": "tls_port_to_port_iran",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": $local_port,
"nodelay": true
},
"next": "$output"
},
EOF
)
if [ "$http2" == "yes" ]; then
json+=$(
cat <<EOF
{
"name": "pbclient",
"type": "ProtoBufClient",
"settings": {},
"next": "h2client"
},
{
"name": "h2client",
"type": "Http2Client",
"settings": {
"host": "$domain",
"port": $remote_port,
"path": "/",
"content-type": "application/grpc"
},
"next": "sslclient"
},
EOF
)
else
if [ "$PreConnect" == "yes" ]; then
json+=$(
cat <<EOF
{
"name": "precon_client",
"type": "PreConnectClient",
"settings": {
"minimum-unused": $min_un
},
"next": "sslclient"
},
EOF
)
fi
fi
if [ "$http2" == "yes" ]; then
alpn="h2"
else
alpn="http/1.1"
fi
json+=$(
cat <<EOF
{
"name": "sslclient",
"type": "OpenSSLClient",
"settings": {
"sni": "$domain",
"verify": true,
"alpn": "$alpn"
},
"next": "output"
},
{
"name": "output",
"type": "TcpConnector",
"settings": {
"nodelay": true,
"address": "$remote_address",
"port": $remote_port
}
}
]
}
EOF
)
echo "$json" >/root/Waterwall/config.json
}
# Function to create tls port to port config
create_tls_port_to_port_kharej() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter the local (${yellow}Connection${green}) port: ${rest}"
read -r local_port
echo -en "${green}Enter the remote (${yellow}Server Config${green}) port: ${rest}"
read -r remote_port
echo -en "${green}Do you want to Enable Http2 ? (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r http2
http2=${http2:-yes}
if [ "$http2" == "yes" ]; then
output="h2server"
else
output="output"
fi
install_waterwall
json=$(
cat <<EOF
{
"name": "tls_port_to_port_kharej",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": $local_port,
"nodelay": true
},
"next": "sslserver"
},
{
"name": "sslserver",
"type": "OpenSSLServer",
"settings": {
"cert-file": "/root/Waterwall/cert/fullchain.pem",
"key-file": "/root/Waterwall/cert/privkey.pem",
"alpns": [
{
"value": "h2",
"next": "node->next"
},
{
"value": "http/1.1",
"next": "node->next"
}
]
},
"next": "$output"
},
EOF
)
if [ "$http2" == "yes" ]; then
json+=$(
cat <<EOF
{
"name": "h2server",
"type": "Http2Server",
"settings": {},
"next": "pbserver"
},
{
"name": "pbserver",
"type": "ProtoBufServer",
"settings": {},
"next": "output"
},
EOF
)
fi
json+=$(
cat <<EOF
{
"name": "output",
"type": "Connector",
"settings": {
"nodelay": true,
"address": "127.0.0.1",
"port": $remote_port
}
}
]
}
EOF
)
echo "$json" >/root/Waterwall/config.json
echo -e "${yellow}If you haven't already, you should get [SSL CERTIFICATE] for your domain in the main menu.${rest}"
}
# Function to create tls multi port iran
create_tls_multi_port_iran() {
echo -e "${cyan}============================${rest}"
echo -en "${green}Enter Your Domain: ${rest}"
read -r domain
echo -en "${green}Enter the starting local port [${yellow}greater than 23${green}]: ${rest}"
read -r start_port
echo -en "${green}Enter the ending local port [${yellow}less than 65535${green}]: ${rest}"
read -r end_port
echo -en "${green}Enter the remote address: ${rest}"
read -r remote_address
echo -en "${green}Enter the remote (${yellow}Connection${green}) port: ${rest}"
read -r remote_port
echo -en "${green}Do you want to Enable Http2 ? (yes/no) [${yellow}Default: yes${green}] : ${rest}"
read -r http2
http2=${http2:-yes}
if [ "$http2" == "no" ]; then
echo -en "${green}Do you want to Enable PreConnect ? (yes/no) [${yellow}Default: yes${green}]: ${rest}"
read -r PreConnect
PreConnect=${PreConnect:-yes}
if [ "$PreConnect" != "no" ]; then
echo -en "${green}Enter Minimum-unused [${yellow}Default: 1${green}]: ${rest}"
read -r min_un
min_un=${min_un:-1}
fi
echo -e "${cyan}============================${rest}"
fi
if [ "$http2" == "no" ] && [ "$PreConnect" == "no" ]; then
output="sslclient"
elif [ "$http2" == "no" ] && [ "$PreConnect" == "yes" ]; then
output="precon_client"
else
output="pbclient"
fi
install_waterwall
json=$(
cat <<EOF
{
"name": "tls_multiport_iran",
"nodes": [
{
"name": "input",
"type": "TcpListener",
"settings": {
"address": "0.0.0.0",
"port": [$start_port,$end_port],
"nodelay": true
},
"next": "port_header"
},
{
"name": "port_header",
"type": "HeaderClient",
"settings": {
"data": "src_context->port"
},
"next": "$output"
},
EOF
)