forked from Daorakle/Daorakle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssrmu.sh
734 lines (728 loc) · 30.2 KB
/
ssrmu.sh
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
#!/bin/bash
red='\e[1;31m'
green='\e[0;32m'
NC='\e[0m'
MYIP=$(wget -qO- icanhazip.com);
echo "Checking VPS"
clear
#PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
sh_ver="1.0.26"
filepath=$(cd "$(dirname "$0")"; pwd)
file=$(echo -e "${filepath}"|awk -F "$0" '{print $1}')
ssr_folder="/usr/local/shadowsocksr"
config_file="${ssr_folder}/config.json"
config_user_file="${ssr_folder}/user-config.json"
config_user_api_file="${ssr_folder}/userapiconfig.py"
config_user_mudb_file="${ssr_folder}/mudb.json"
ssr_log_file="${ssr_folder}/ssserver.log"
Libsodiumr_file="/usr/local/lib/libsodium.so"
Libsodiumr_ver_backup="1.0.17"
jq_file="${ssr_folder}/jq"
masaaktif=30
exp=`date -d "$masaaktif days" +"%Y-%m-%d"`
source /etc/os-release
OS=$ID
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[information]${Font_color_suffix}"
Error="${Red_font_prefix}[error]${Font_color_suffix}"
Tip="${Green_font_prefix}[note]${Font_color_suffix}"
Separator_1="——————————————————————————————"
check_pid(){
PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
}
SSR_installation_status(){
[[ ! -e ${ssr_folder} ]] && echo -e "${Error} ShadowsocksR folder not found, please check! "&& exit 1
}
Add_iptables(){
if [[ ! -z "${ssr_port}" ]]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT
ip6tables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT
ip6tables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT
fi
}
Del_iptables(){
if [[ ! -z "${port}" ]]; then
iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
ip6tables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
ip6tables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
fi
}
Save_iptables(){
if [[ ${OS} == "centos" ]]; then
iptables-save > /etc/sysconfig/iptable
ip6tables-save > /etc/sysconfig/ip6tables
else
iptables-save > /etc/iptables.up.rules
ip6tables-save > /etc/ip6tables.up.rules
fi
}
Set_iptables(){
if [[ ${OS} == "centos" ]]; then
iptables-save > /etc/sysconfig/iptable
ip6tables-save > /etc/sysconfig/ip6tables
chkconfig --level 2345 iptables on
chkconfig --level 2345 ip6tables on
else
iptables-save > /etc/iptables.up.rules
ip6tables-save > /etc/ip6tables.up.rules
echo -e '#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules\n/sbin/ip6tables-restore < /etc/ip6tables.up.rules' > /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables
fi
}
# 读取 配置信息
Get_IP(){
ip=$(wget -qO- -t1 -T2 ipinfo.io/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 api.ip.sb/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 members.3322.org/dyndns/getip)
if [[ -z "${ip}" ]]; then
ip="VPS_IP"
fi
fi
fi
}
Get_User_info(){
Get_user_port=$1
user_info_get=$(python mujson_mgr.py -l -p "${Get_user_port}")
match_info=$(echo "${user_info_get}"|grep -w "### user ")
if [[ -z "${match_info}" ]]; then
echo -e "${Error} Failed to get user information $ {Green Font Prefix} [Port: $ {ssh port}] $ {Font_color Suffix} " && exit 1
fi
user_name=$(echo "${user_info_get}"|grep -w "user :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
port=$(echo "${user_info_get}"|grep -w "port :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
password=$(echo "${user_info_get}"|grep -w "passwd :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
method=$(echo "${user_info_get}"|grep -w "method :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
protocol=$(echo "${user_info_get}"|grep -w "protocol :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
protocol_param=$(echo "${user_info_get}"|grep -w "protocol_param :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
[[ -z ${protocol_param} ]] && protocol_param="0(无限)"
obfs=$(echo "${user_info_get}"|grep -w "obfs :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
#transfer_enable=$(echo "${user_info_get}"|grep -w "transfer_enable :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}'|awk -F "ytes" '{print $1}'|sed 's/KB/ KB/;s/MB/ MB/;s/GB/ GB/;s/TB/ TB/;s/PB/ PB/')
#u=$(echo "${user_info_get}"|grep -w "u :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
#d=$(echo "${user_info_get}"|grep -w "d :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
forbidden_port=$(echo "${user_info_get}"|grep -w "forbidden_port :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
[[ -z ${forbidden_port} ]] && forbidden_port="Allow all"
speed_limit_per_con=$(echo "${user_info_get}"|grep -w "speed_limit_per_con :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
speed_limit_per_user=$(echo "${user_info_get}"|grep -w "speed_limit_per_user :"|sed 's/[[:space:]]//g'|awk -F ":" '{print $NF}')
Get_User_transfer "${port}"
}
Get_User_transfer(){
transfer_port=$1
#echo "transfer_port=${transfer_port}"
all_port=$(${jq_file} '.[]|.port' ${config_user_mudb_file})
#echo "all_port=${all_port}"
port_num=$(echo "${all_port}"|grep -nw "${transfer_port}"|awk -F ":" '{print $1}')
#echo "port_num=${port_num}"
port_num_1=$(expr ${port_num} - 1)
#echo "port_num_1=${port_num_1}"
transfer_enable_1=$(${jq_file} ".[${port_num_1}].transfer_enable" ${config_user_mudb_file})
#echo "transfer_enable_1=${transfer_enable_1}"
u_1=$(${jq_file} ".[${port_num_1}].u" ${config_user_mudb_file})
#echo "u_1=${u_1}"
d_1=$(${jq_file} ".[${port_num_1}].d" ${config_user_mudb_file})
#echo "d_1=${d_1}"
transfer_enable_Used_2_1=$(expr ${u_1} + ${d_1})
#echo "transfer_enable_Used_2_1=${transfer_enable_Used_2_1}"
transfer_enable_Used_1=$(expr ${transfer_enable_1} - ${transfer_enable_Used_2_1})
#echo "transfer_enable_Used_1=${transfer_enable_Used_1}"
if [[ ${transfer_enable_1} -lt 1024 ]]; then
transfer_enable="${transfer_enable_1} B"
elif [[ ${transfer_enable_1} -lt 1048576 ]]; then
transfer_enable=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_1}'/'1024'}')
transfer_enable="${transfer_enable} KB"
elif [[ ${transfer_enable_1} -lt 1073741824 ]]; then
transfer_enable=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_1}'/'1048576'}')
transfer_enable="${transfer_enable} MB"
elif [[ ${transfer_enable_1} -lt 1099511627776 ]]; then
transfer_enable=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_1}'/'1073741824'}')
transfer_enable="${transfer_enable} GB"
elif [[ ${transfer_enable_1} -lt 1125899906842624 ]]; then
transfer_enable=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_1}'/'1099511627776'}')
transfer_enable="${transfer_enable} TB"
fi
#echo "transfer_enable=${transfer_enable}"
if [[ ${u_1} -lt 1024 ]]; then
u="${u_1} B"
elif [[ ${u_1} -lt 1048576 ]]; then
u=$(awk 'BEGIN{printf "%.2f\n",'${u_1}'/'1024'}')
u="${u} KB"
elif [[ ${u_1} -lt 1073741824 ]]; then
u=$(awk 'BEGIN{printf "%.2f\n",'${u_1}'/'1048576'}')
u="${u} MB"
elif [[ ${u_1} -lt 1099511627776 ]]; then
u=$(awk 'BEGIN{printf "%.2f\n",'${u_1}'/'1073741824'}')
u="${u} GB"
elif [[ ${u_1} -lt 1125899906842624 ]]; then
u=$(awk 'BEGIN{printf "%.2f\n",'${u_1}'/'1099511627776'}')
u="${u} TB"
fi
#echo "u=${u}"
if [[ ${d_1} -lt 1024 ]]; then
d="${d_1} B"
elif [[ ${d_1} -lt 1048576 ]]; then
d=$(awk 'BEGIN{printf "%.2f\n",'${d_1}'/'1024'}')
d="${d} KB"
elif [[ ${d_1} -lt 1073741824 ]]; then
d=$(awk 'BEGIN{printf "%.2f\n",'${d_1}'/'1048576'}')
d="${d} MB"
elif [[ ${d_1} -lt 1099511627776 ]]; then
d=$(awk 'BEGIN{printf "%.2f\n",'${d_1}'/'1073741824'}')
d="${d} GB"
elif [[ ${d_1} -lt 1125899906842624 ]]; then
d=$(awk 'BEGIN{printf "%.2f\n",'${d_1}'/'1099511627776'}')
d="${d} TB"
fi
#echo "d=${d}"
if [[ ${transfer_enable_Used_1} -lt 1024 ]]; then
transfer_enable_Used="${transfer_enable_Used_1} B"
elif [[ ${transfer_enable_Used_1} -lt 1048576 ]]; then
transfer_enable_Used=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_1}'/'1024'}')
transfer_enable_Used="${transfer_enable_Used} KB"
elif [[ ${transfer_enable_Used_1} -lt 1073741824 ]]; then
transfer_enable_Used=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_1}'/'1048576'}')
transfer_enable_Used="${transfer_enable_Used} MB"
elif [[ ${transfer_enable_Used_1} -lt 1099511627776 ]]; then
transfer_enable_Used=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_1}'/'1073741824'}')
transfer_enable_Used="${transfer_enable_Used} GB"
elif [[ ${transfer_enable_Used_1} -lt 1125899906842624 ]]; then
transfer_enable_Used=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_1}'/'1099511627776'}')
transfer_enable_Used="${transfer_enable_Used} TB"
fi
#echo "transfer_enable_Used=${transfer_enable_Used}"
if [[ ${transfer_enable_Used_2_1} -lt 1024 ]]; then
transfer_enable_Used_2="${transfer_enable_Used_2_1} B"
elif [[ ${transfer_enable_Used_2_1} -lt 1048576 ]]; then
transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1024'}')
transfer_enable_Used_2="${transfer_enable_Used_2} KB"
elif [[ ${transfer_enable_Used_2_1} -lt 1073741824 ]]; then
transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1048576'}')
transfer_enable_Used_2="${transfer_enable_Used_2} MB"
elif [[ ${transfer_enable_Used_2_1} -lt 1099511627776 ]]; then
transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1073741824'}')
transfer_enable_Used_2="${transfer_enable_Used_2} GB"
elif [[ ${transfer_enable_Used_2_1} -lt 1125899906842624 ]]; then
transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1099511627776'}')
transfer_enable_Used_2="${transfer_enable_Used_2} TB"
fi
#echo "transfer_enable_Used_2=${transfer_enable_Used_2}"
}
urlsafe_base64(){
date=$(echo -n "$1"|base64|sed ':a;N;s/\n/ /g;ta'|sed 's/ //g;s/=//g;s/+/-/g;s/\//_/g')
echo -e "${date}"
}
ssr_link_qr(){
SSRprotocol=$(echo ${protocol} | sed 's/_compatible//g')
SSRobfs=$(echo ${obfs} | sed 's/_compatible//g')
SSRPWDbase64=$(urlsafe_base64 "${password}")
SSRbase64=$(urlsafe_base64 "${ip}:${port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}")
SSRurl="ssr://${SSRbase64}"
ssr_link=" SSR Link : ${Red_font_prefix}${SSRurl}${Font_color_suffix} \n"
}
ss_ssr_determine(){
protocol_suffix=`echo ${protocol} | awk -F "_" '{print $NF}'`
obfs_suffix=`echo ${obfs} | awk -F "_" '{print $NF}'`
ssr_link_qr
}
# Display configuration information
View_User(){
SSR_installation_status
List_port_user
while true
do
echo -e "Please enter the user port to view the account information"
read -e -p "(Default: cancel):" View_user_port
[[ -z "${View_user_port}" ]] && echo -e "cancel..." && exit 1
View_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${View_user_port}"',')
if [[ ! -z ${View_user} ]]; then
Get_User_info "${View_user_port}"
View_User_info
break
else
echo -e "${Error} Please enter the correct port !"
fi
done
}
View_User_info(){
ip=$(cat ${config_user_api_file}|grep "SERVER_PUB_ADDR = "|awk -F "[']" '{print $2}')
[[ -z "${ip}" ]] && Get_IP
ss_ssr_determine
clear && echo "===================================================" && echo
echo -e " User [${user_name}] configuration info:" && echo
echo -e " IP : ${Green_font_prefix}${ip}${Font_color_suffix}"
echo -e " Port : ${Green_font_prefix}${port}${Font_color_suffix}"
echo -e " Password : ${Green_font_prefix}${password}${Font_color_suffix}"
echo -e " Encryption : ${Green_font_prefix}${method}${Font_color_suffix}"
echo -e " Protocol : ${Red_font_prefix}${protocol}${Font_color_suffix}"
echo -e " obfs : ${Red_font_prefix}${obfs}${Font_color_suffix}"
echo -e " Device limit : ${Green_font_prefix}${protocol_param}${Font_color_suffix}"
echo -e "${ssr_link}"
echo && echo "==================================================="
}
# 设置 配置信息
Set_config_enable(){
user_total=$(expr ${user_total} - 1)
for((integer = 0; integer <= ${user_total}; integer++))
do
echo -e "integer=${integer}"
port_jq=$(${jq_file} ".[${integer}].port" "${config_user_mudb_file}")
echo -e "port_jq=${port_jq}"
if [[ "${ssr_port}" == "${port_jq}" ]]; then
enable=$(${jq_file} ".[${integer}].enable" "${config_user_mudb_file}")
echo -e "enable=${enable}"
[[ "${enable}" == "null" ]] && echo -e "${Error} Get the current port[${ssr_port}]Disabled state failed !" && exit 1
ssr_port_num=$(cat "${config_user_mudb_file}"|grep -n '"port": '${ssr_port}','|awk -F ":" '{print $1}')
echo -e "ssr_port_num=${ssr_port_num}"
[[ "${ssr_port_num}" == "null" ]] && echo -e "${Error} Get currentPort[${ssr_port}]Number of rows failed !" && exit 1
ssr_enable_num=$(expr ${ssr_port_num} - 5)
echo -e "ssr_enable_num=${ssr_enable_num}"
break
fi
done
if [[ "${enable}" == "1" ]]; then
echo -e "Port [${ssr_port}] The account status is:${Green_font_prefix}Enabled ${Font_color_suffix} , switch to ${Red_font_prefix}Disabled${Font_color_suffix} ?[Y/n]"
read -e -p "(Default: Y):" ssr_enable_yn
[[ -z "${ssr_enable_yn}" ]] && ssr_enable_yn="y"
if [[ "${ssr_enable_yn}" == [Yy] ]]; then
ssr_enable="0"
else
echo "Cancel..." && exit 0
fi
elif [[ "${enable}" == "0" ]]; then
echo -e "Port [${ssr_port}] The account status is:${Green_font_prefix}Disabled ${Font_color_suffix} , switch to ${Red_font_prefix}Disabled${Font_color_suffix} ?[Y/n]"
read -e -p "(Default: Y):" ssr_enable_yn
[[ -z "${ssr_enable_yn}" ]] && ssr_enable_yn = "y"
if [[ "${ssr_enable_yn}" == [Yy] ]]; then
ssr_enable="1"
else
echo "cancel..." && exit 0
fi
else
echo -e "${Error} The disabled status of the current port varies[${enable}] !" && exit 1
fi
}
Set_user_api_server_pub_addr(){
addr=$1
if [[ "${addr}" == "Modify" ]]; then
server_pub_addr=$(cat ${config_user_api_file}|grep "SERVER_PUB_ADDR = "|awk -F "[']" '{print $2}')
if [[ -z ${server_pub_addr} ]]; then
echo -e "${Error} Failed to obtain the currently configured server IP or domain name!" && exit 1
else
echo -e "${Info} The currently configured server IP or domain name is: ${Green_font_prefix}${server_pub_addr}${Font_color_suffix}"
fi
fi
echo "Please enter the server IP or domain name to be displayed in the user's configuration (when the server has multiple IPs, you can specify the IP or domain name displayed in the user's configuration)"
read -e -p "(Default: Automatic detection of external network IP):" ssr_server_pub_addr
if [[ -z "${ssr_server_pub_addr}" ]]; then
Get_IP
if [[ ${ip} == "VPS_IP" ]]; then
while true
do
read -e -p "${Error} Automatic detection of external network IP failed, please manually enter the server IP or domain name" ssr_server_pub_addr
if [[ -z "$ssr_server_pub_addr" ]]; then
echo -e "${Error} Can not be empty!"
else
break
fi
done
else
ssr_server_pub_addr="${ip}"
fi
fi
echo && echo ${Separator_1} && echo -e " IP or domain name : ${Green_font_prefix}${ssr_server_pub_addr}${Font_color_suffix}" && echo ${Separator_1} && echo
}
Set_config_all(){
lal=$1
if [[ "${lal}" == "Modify" ]]; then
Set_config_password
Set_config_method
Set_config_protocol
Set_config_obfs
Set_config_protocol_param
Set_config_speed_limit_per_con
Set_config_speed_limit_per_user
Set_config_transfer
Set_config_forbid
else
Set_config_user
Set_config_port
Set_config_password
Set_config_method
Set_config_protocol
Set_config_obfs
Set_config_protocol_param
Set_config_speed_limit_per_con
Set_config_speed_limit_per_user
Set_config_transfer
Set_config_forbid
fi
}
Modify_config_password(){
match_edit=$(python mujson_mgr.py -e -p "${ssr_port}" -k "${ssr_password}"|grep -w "edit user ")
if [[ -z "${match_edit}" ]]; then
echo -e "${Error} User password modification failed ${Green_font_prefix}[Port: ${ssr_port}]${Font_color_suffix} " && exit 1
else
echo -e "${Info} User password modified successfully ${Green_font_prefix}[Port: ${ssr_port}]${Font_color_suffix} (It may take about 10 seconds to apply the latest configuration)"
fi
}
Modify_config_enable(){
sed -i "${ssr_enable_num}"'s/"enable": '"$(echo ${enable})"',/"enable": '"$(echo ${ssr_enable})"',/' ${config_user_mudb_file}
}
Modify_user_api_server_pub_addr(){
sed -i "s/SERVER_PUB_ADDR = '${server_pub_addr}'/SERVER_PUB_ADDR = '${ssr_server_pub_addr}'/" ${config_user_api_file}
}
centos_View_user_connection_info(){
format_1=$1
user_info=$(python mujson_mgr.py -l)
user_total=$(echo "${user_info}"|wc -l)
[[ -z ${user_info} ]] && echo -e "${Error} Didn't find the user, please check again !" && exit 1
IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l`
user_list_all=""
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $4}')
user_IP_1=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep ":${user_port} "|grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u`
if [[ -z ${user_IP_1} ]]; then
user_IP_total="0"
else
user_IP_total=`echo -e "${user_IP_1}"|wc -l`
if [[ ${format_1} == "IP_address" ]]; then
get_IP_address
else
user_IP=`echo -e "\n${user_IP_1}"`
fi
fi
user_list_all=${user_list_all}"Port: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, The total number of linked IPs: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, Current linked IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n"
user_IP=""
done
echo -e "The total number of users: ${Green_background_prefix} "${user_total}" ${Font_color_suffix} ,The total number of linked IPs: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix} "
echo -e "${user_list_all}"
}
debian_View_user_connection_info(){
format_1=$1
user_info=$(python mujson_mgr.py -l)
user_total=$(echo "${user_info}"|wc -l)
[[ -z ${user_info} ]] && echo -e "${Error} Didn't find the user, please check again! " && exit 1
IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
user_list_all=""
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $4}')
user_IP_1=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep ":${user_port} " |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u`
if [[ -z ${user_IP_1} ]]; then
user_IP_total="0"
else
user_IP_total=`echo -e "${user_IP_1}"|wc -l`
if [[ ${format_1} == "IP_address" ]]; then
get_IP_address
else
user_IP=`echo -e "\n${user_IP_1}"`
fi
fi
user_list_all=${user_list_all}"Port: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, The total number of linked IPs: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, Current linked IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n"
user_IP=""
done
echo -e "The total number of users: ${Green_background_prefix} "${user_total}" ${Font_color_suffix} ,The total number of linked IPs: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix} "
echo -e "${user_list_all}"
}
View_user_connection_info(){
SSR_installation_status
echo && echo -e "Please select the format to display:
${Green_font_prefix}1.${Font_color_suffix} display IP
${Green_font_prefix}2.${Font_color_suffix} display IP+Resolve the DNS name " && echo
read -e -p "(Default: 1):" ssr_connection_info
[[ -z "${ssr_connection_info}" ]] && ssr_connection_info="1"
if [[ ${ssr_connection_info} == "1" ]]; then
View_user_connection_info_1 ""
elif [[ ${ssr_connection_info} == "2" ]]; then
echo -e "${Tip} Detect IP (ipip.net),it can take longer time if there are many IPs"
View_user_connection_info_1 "IP_address"
else
echo -e "${Error} Please enter the correct number(1-2)" && exit 1
fi
}
View_user_connection_info_1(){
format=$1
if [[ ${release} = "centos" ]]; then
cat /etc/redhat-release |grep 7\..*|grep -i centos>/dev/null
if [[ $? = 0 ]]; then
debian_View_user_connection_info "$format"
else
centos_View_user_connection_info "$format"
fi
else
debian_View_user_connection_info "$format"
fi
}
get_IP_address(){
if [[ ! -z ${user_IP_1} ]]; then
for((integer_1 = ${user_IP_total}; integer_1 >= 1; integer_1--))
do
IP=`echo "${user_IP_1}" |sed -n "$integer_1"p`
IP_address=`wget -qO- -t1 -T2 http://freeapi.ipip.net/${IP}|sed 's/\"//g;s/,//g;s/\[//g;s/\]//g'`
user_IP="${user_IP}\n${IP}(${IP_address})"
sleep 1s
done
fi
}
List_port_user(){
user_info=$(python mujson_mgr.py -l)
user_total=$(echo "${user_info}"|wc -l)
[[ -z ${user_info} ]] && echo -e "${Error} Didn't find the user, please check again! " && exit 1
user_list_all=""
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $4}')
user_username=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $2}'|sed 's/\[//g;s/\]//g')
Get_User_transfer "${user_port}"
user_list_all=${user_list_all}"Username: ${Green_font_prefix} "${user_username}"${Font_color_suffix} Port: ${Green_font_prefix}"${user_port}"${Font_color_suffix} Traffic usage (used + remaining = total): ${Green_font_prefix}${transfer_enable_Used_2}${Font_color_suffix} + ${Green_font_prefix}${transfer_enable_Used}${Font_color_suffix} = ${Green_font_prefix}${transfer_enable}${Font_color_suffix}\n"
done
echo && echo -e "=== Total of all users ${Green_background_prefix} "${user_total}" ${Font_color_suffix}"
echo -e ${user_list_all}
}
Manually_Modify_Config(){
SSR_installation_status
nano ${config_user_mudb_file}
echo "Do you want to restart ShadowsocksR? [Y/n]" && echo
read -e -p "(Default: y):" yn
[[ -z ${yn} ]] && yn="y"
if [[ ${yn} == [Yy] ]]; then
Restart_SSR
fi
}
Clear_transfer(){
SSR_installation_status
echo && echo -e "What do you want to do?
${Green_font_prefix}1.${Font_color_suffix} Clear single user traffic
${Green_font_prefix}2.${Font_color_suffix} Clear all user traffic (irreparable)
${Green_font_prefix}3.${Font_color_suffix} All user traffic is cleared on startup
${Green_font_prefix}4.${Font_color_suffix} Stop timing all user traffic
${Green_font_prefix}5.${Font_color_suffix} Modify the timing of all user traffic" && echo
read -e -p "(Default: batal):" ssr_modify
[[ -z "${ssr_modify}" ]] && echo "Dibatalkan..." && exit 1
if [[ ${ssr_modify} == "1" ]]; then
Clear_transfer_one
elif [[ ${ssr_modify} == "2" ]]; then
echo "Are you sure you want to clear all user traffic[y/N]" && echo
read -e -p "(Default: n):" yn
[[ -z ${yn} ]] && yn="n"
if [[ ${yn} == [Yy] ]]; then
Clear_transfer_all
else
echo "cancel..."
fi
elif [[ ${ssr_modify} == "3" ]]; then
check_crontab
Set_crontab
Clear_transfer_all_cron_start
elif [[ ${ssr_modify} == "4" ]]; then
check_crontab
Clear_transfer_all_cron_stop
elif [[ ${ssr_modify} == "5" ]]; then
check_crontab
Clear_transfer_all_cron_modify
else
echo -e "${Error} Please enter the correct number (1-5) " && exit 1
fi
}
Clear_transfer_one(){
List_port_user
while true
do
echo -e "Please enter the port of the user who wants to reset the data"
read -e -p "(Default: batal):" Clear_transfer_user_port
[[ -z "${Clear_transfer_user_port}" ]] && echo -e "Dibatalkan..." && exit 1
Clear_transfer_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${Clear_transfer_user_port}"',')
if [[ ! -z ${Clear_transfer_user} ]]; then
match_clear=$(python mujson_mgr.py -c -p "${Clear_transfer_user_port}"|grep -w "clear user ")
if [[ -z "${match_clear}" ]]; then
echo -e "${Error} Failed to reset data used by the user ${Green_font_prefix}[Port: ${Clear_transfer_user_port}]${Font_color_suffix} "
else
echo -e "${Info} Successfully reseted user-used data${Green_font_prefix}[Port: ${Clear_transfer_user_port}]${Font_color_suffix} "
fi
break
else
echo -e "${Error} Please enter the correct Port!"
fi
done
}
Clear_transfer_all(){
cd "${ssr_folder}"
user_info=$(python mujson_mgr.py -l)
user_total=$(echo "${user_info}"|wc -l)
[[ -z ${user_info} ]] && echo -e "${Error} No users were found, please check!" && exit 1
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $4}')
match_clear=$(python mujson_mgr.py -c -p "${user_port}"|grep -w "clear user ")
if [[ -z "${match_clear}" ]]; then
echo -e "${Error} Failed to reset data used by the user ${Green_font_prefix}[Port: ${user_port}]${Font_color_suffix} "
else
echo -e "${Info} The user has successfully reset traffic ${Green_font_prefix}[Port: ${user_port}]${Font_color_suffix} "
fi
done
echo -e "${Info} All user traffic is removed! "
}
Clear_transfer_all_cron_start(){
crontab -l > "$file/crontab.bak"
sed -i "/ssrmu.sh/d" "$file/crontab.bak"
echo -e "\n${Crontab_time} /bin/bash $file/ssrmu.sh clearall" >> "$file/crontab.bak"
crontab "$file/crontab.bak"
rm -r "$file/crontab.bak"
cron_config=$(crontab -l | grep "ssrmu.sh")
if [[ -z ${cron_config} ]]; then
echo -e "${Error} Failed to reset all user traffic at normal time!" && exit 1
else
echo -e "${Info} All user traffic is cleared and it starts successfully!"
fi
}
Clear_transfer_all_cron_stop(){
crontab -l > "$file/crontab.bak"
sed -i "/ssrmu.sh/d" "$file/crontab.bak"
crontab "$file/crontab.bak"
rm -r "$file/crontab.bak"
cron_config=$(crontab -l | grep "ssrmu.sh")
if [[ ! -z ${cron_config} ]]; then
echo -e "${Error} Fail to clear all user traffic regularly to quit!" && exit 1
else
echo -e "${Info}All user traffic is cleaned regularly and stopped successfully!"
fi
}
Clear_transfer_all_cron_modify(){
Set_crontab
Clear_transfer_all_cron_stop
Clear_transfer_all_cron_start
}
Set_crontab(){
echo -e "Please enter an interval to clear the flow
=== Format Description ===
* * * * * In accordance with the minutes, hours, days, months, weeks
${Green_font_prefix} 0 2 1 * * ${Font_color_suffix} On behalf of every month at 2 o'clock on the 1st, clean used traffic
${Green_font_prefix} 0 2 15 * * ${Font_color_suffix} On the 15th of each month at 2: 0 pm Remove used traffic
${Green_font_prefix} 0 2 */7 * * ${Font_color_suffix} Used traffic will be cleared at 2 o'clock every 7 days
${Green_font_prefix} 0 2 * * 0 ${Font_color_suffix} Every Sunday (7) clean the flow used
${Green_font_prefix} 0 2 * * 3 ${Font_color_suffix} every Wednesday (3) clear the flow used" && echo
read -e -p "(Default: 0 2 1 * * 2 o'clock on the 1st of every month):" Crontab_time
[[ -z "${Crontab_time}" ]] && Crontab_time="0 2 1 * *"
}
Start_SSR(){
SSR_installation_status
check_pid
[[ ! -z ${PID} ]] && echo -e "${Error} ShadowsocksR Running! " && exit 1
/etc/init.d/ssrmu start
}
Stop_SSR(){
SSR_installation_status
check_pid
[[ -z ${PID} ]] && echo -e "${Error} ShadowsocksR Is Not Running" && exit 1
/etc/init.d/ssrmu stop
}
Restart_SSR(){
SSR_installation_status
check_pid
[[ ! -z ${PID} ]] && /etc/init.d/ssrmu stop
/etc/init.d/ssrmu start
}
View_Log(){
SSR_installation_status
[[ ! -e ${ssr_log_file} ]] && echo -e "${Error} The Shadowsocks log file does not exist! " && exit 1
echo && echo -e "${Tip} Click ${Red_font_prefix}Ctrl+C${Font_color_suffix} Stop Displaying logs " && echo
tail -f ${ssr_log_file}
}
Update_Shell(){
echo -e "The current version is [$ {sh_ver}], start checking for the latest version ... "
sh_new_ver=$(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/hybtoy/ssrrmu/master/ssrrmu.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1) && sh_new_type="github"
[[ -z ${sh_new_ver} ]] && sh_new_ver=$(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/hybtoy/ssrrmu/master/ssrrmu.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1) && sh_new_type="github"
[[ -z ${sh_new_ver} ]] && echo -e "${Error} Failed to detect the latest version! " && exit 0
if [[ ${sh_new_ver} != ${sh_ver} ]]; then
echo -e "Versi baru ditemukan[ ${sh_new_ver} ],Do you want to be updated? [Y/n]"
read -e -p "(default: y):" yn
[[ -z "${yn}" ]] && yn="y"
if [[ ${yn} == [Yy] ]]; then
cd "${file}"
if [[ $sh_new_type == "github" ]]; then
wget -N --no-check-certificate https://raw.githubusercontent.com/hybtoy/ssrrmu/master/ssrrmu.sh && chmod +x ssrrmu.sh
fi
echo -e "The Script Has Been Updated To The Latest Version..."
else
echo && echo "cancel..." && echo
fi
else
echo -e "Currently The Latest Version[ ${sh_new_ver} ] !"
fi
exit 0
}
menu_status(){
if [[ -e ${ssr_folder} ]]; then
check_pid
if [[ ! -z "${PID}" ]]; then
echo -e " Current status: ${Green_font_prefix} Installed${Font_color_suffix} & ${Green_font_prefix} Running${Font_color_suffix}"
else
echo -e " Current status: ${Green_font_prefix} Installed${Font_color_suffix} but ${Red_font_prefix} Not Running${Font_color_suffix}"
fi
cd "${ssr_folder}"
else
echo -e " Current status: ${Red_font_prefix}tidak terinstall${Font_color_suffix}"
fi
}
if [[ "${action}" == "clearall" ]]; then
Clear_transfer_all
elif [[ "${action}" == "monitor" ]]; then
crontab_monitor_ssr
else
menu_status
echo -e " Menu ShadowsocksR
Versi: ${Green_font_prefix}[v${sh_ver}]${Font_color_suffix}
${Green_font_prefix}1.${Font_color_suffix} Check the account information
${Green_font_prefix}2.${Font_color_suffix} Display the connection information
${Green_font_prefix}3.${Font_color_suffix} Change Password User
${Green_font_prefix}4.${Font_color_suffix} Manually Modify User Configuration
${Green_font_prefix}5.${Font_color_suffix} Clear The Used Traffic
${Green_font_prefix}6.${Font_color_suffix} Start ShadowsocksR
${Green_font_prefix}7.${Font_color_suffix} Stop ShadowsocksR
${Green_font_prefix}8.${Font_color_suffix} Restart ShadowsocksR
${Green_font_prefix}9.${Font_color_suffix} Cek ShadowsocksR log
${Green_font_prefix}10.${Font_color_suffix} Upgrade script
${Tip} Username And User Port Can Not Be Changed, If You Need To Modify, Use The Script To Manually Change The Function!
"
echo && read -e -p "Please enter the correct number [1-10]:" num
case "$num" in
1)
View_User
;;
2)
View_user_connection_info
;;
3)
Modify_port
Set_config_password
Modify_config_password
;;
4)
Manually_Modify_Config
;;
5)
Clear_transfer
;;
6)
Start_SSR
;;
7)
Stop_SSR
;;
8)
Restart_SSR
;;
9)
View_Log
;;
10)
Update_Shell
;;
*)
echo -e "${Error} Please enter the correct number [1-10] "
;;
esac
fi