├── README.md └── ssr.sh /README.md: -------------------------------------------------------------------------------- 1 | # tools 2 | 🙃 以学习为目的,到处copy来的脚本 3 | 4 | ## ssr.sh 5 | 6 | - 脚本说明: ShadowsocksR 一键安装/管理脚本,支持单端口/多端口切换和管理 7 | - 系统支持: CentOS6+ / Debian6+ / Ubuntu14+ 8 | 9 | ### 脚本特点: 10 | 11 | 目前网上的各个ShadowsocksR脚本基本都是只有 安装/启动/重启 等基础功能,对于小白来说还是不够简单方便。既然是一键脚本,那么就要尽可能地简单,小白更容易接受使用! 12 | 13 | - 支持 限制 用户速度 14 | - 支持 限制 端口设备数 15 | - 支持 显示 当前连接IP 16 | - 支持 显示 SS/SSR连接+二维码 17 | - 支持 切换管理 单/多端口 18 | - 支持 一键安装 锐速 19 | - 支持 一键安装 BBR 20 | - 支持 一键封禁 垃圾邮件(SMAP)/BT/PT 21 | 22 | ### 下载安装: 23 | 24 | ``` 25 | wget -N --no-check-certificate https://raw.githubusercontent.com/xnmll/tools/master/ssr.sh && chmod +x ssr.sh && bash ssr.sh 26 | ``` 27 | 28 | 29 | 30 | ------ 31 | 32 | wget ![img](file:///C:\Users\12297\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png)https://raw.githubusercontent.com/nanqinlang-tcp/tcp_nanqinlang/master/LKL/bash/tcp_nanqinlang-lkl-debian-1.1.1.sh bash tcp_![img](file:///C:\Users\12297\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png)nanqinlang-lkl-debian-1.1.1.sh 33 | 34 | wget ![img](file:///C:\Users\12297\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png)https://github.com/tcp-nanqinlang/lkl-rinetd/releases/download/1.1.0/tcp_nanqinlang-rinetd-debianorubuntu.sh 35 | bash tcp_![img](file:///C:\Users\12297\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png)nanqinlang-rinetd-debianorubuntu.sh -------------------------------------------------------------------------------- /ssr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | 5 | #================================================= 6 | # System Required: CentOS 6+/Debian 6+/Ubuntu 14.04+ 7 | # Description: Install the ShadowsocksR server 8 | # Version: 2.0.37 9 | # Author: Toyo , xnmll 10 | # Blog: https://www.xnmll.cn 11 | #================================================= 12 | 13 | sh_ver="2.0.37" 14 | filepath=$(cd "$(dirname "$0")"; pwd) 15 | file=$(echo -e "${filepath}"|awk -F "$0" '{print $1}') 16 | ssr_folder="/usr/local/shadowsocksr" 17 | ssr_ss_file="${ssr_folder}/shadowsocks" 18 | config_file="${ssr_folder}/config.json" 19 | config_folder="/etc/shadowsocksr" 20 | config_user_file="${config_folder}/user-config.json" 21 | ssr_log_file="${ssr_ss_file}/ssserver.log" 22 | Libsodiumr_file="/usr/local/lib/libsodium.so" 23 | Libsodiumr_ver_backup="1.0.13" 24 | Server_Speeder_file="/serverspeeder/bin/serverSpeeder.sh" 25 | LotServer_file="/appex/bin/serverSpeeder.sh" 26 | BBR_file="${file}/bbr.sh" 27 | jq_file="${ssr_folder}/jq" 28 | 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" 29 | Info="${Green_font_prefix}[信息]${Font_color_suffix}" 30 | Error="${Red_font_prefix}[错误]${Font_color_suffix}" 31 | Tip="${Green_font_prefix}[注意]${Font_color_suffix}" 32 | Separator_1="——————————————————————————————" 33 | 34 | check_root(){ 35 | [[ $EUID != 0 ]] && echo -e "${Error} 当前账号非ROOT(或没有ROOT权限),无法继续操作,请使用${Green_background_prefix} sudo su ${Font_color_suffix}来获取临时ROOT权限(执行后会提示输入当前账号的密码)。" && exit 1 36 | } 37 | check_sys(){ 38 | if [[ -f /etc/redhat-release ]]; then 39 | release="centos" 40 | elif cat /etc/issue | grep -q -E -i "debian"; then 41 | release="debian" 42 | elif cat /etc/issue | grep -q -E -i "ubuntu"; then 43 | release="ubuntu" 44 | elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then 45 | release="centos" 46 | elif cat /proc/version | grep -q -E -i "debian"; then 47 | release="debian" 48 | elif cat /proc/version | grep -q -E -i "ubuntu"; then 49 | release="ubuntu" 50 | elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then 51 | release="centos" 52 | fi 53 | bit=`uname -m` 54 | } 55 | check_pid(){ 56 | PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'` 57 | } 58 | SSR_installation_status(){ 59 | [[ ! -e ${config_user_file} ]] && echo -e "${Error} 没有发现 ShadowsocksR 配置文件,请检查 !" && exit 1 60 | [[ ! -e ${ssr_folder} ]] && echo -e "${Error} 没有发现 ShadowsocksR 文件夹,请检查 !" && exit 1 61 | } 62 | Server_Speeder_installation_status(){ 63 | [[ ! -e ${Server_Speeder_file} ]] && echo -e "${Error} 没有安装 锐速(Server Speeder),请检查 !" && exit 1 64 | } 65 | LotServer_installation_status(){ 66 | [[ ! -e ${LotServer_file} ]] && echo -e "${Error} 没有安装 LotServer,请检查 !" && exit 1 67 | } 68 | BBR_installation_status(){ 69 | if [[ ! -e ${BBR_file} ]]; then 70 | echo -e "${Error} 没有发现 BBR脚本,开始下载..." 71 | cd "${file}" 72 | if ! wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/bbr.sh; then 73 | echo -e "${Error} BBR 脚本下载失败 !" && exit 1 74 | else 75 | echo -e "${Info} BBR 脚本下载完成 !" 76 | chmod +x bbr.sh 77 | fi 78 | fi 79 | } 80 | # 设置 防火墙规则 81 | Add_iptables(){ 82 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT 83 | iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT 84 | ip6tables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT 85 | ip6tables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT 86 | } 87 | Del_iptables(){ 88 | iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT 89 | iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT 90 | ip6tables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT 91 | ip6tables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT 92 | } 93 | Save_iptables(){ 94 | if [[ ${release} == "centos" ]]; then 95 | service iptables save 96 | service ip6tables save 97 | else 98 | iptables-save > /etc/iptables.up.rules 99 | ip6tables-save > /etc/ip6tables.up.rules 100 | fi 101 | } 102 | Set_iptables(){ 103 | if [[ ${release} == "centos" ]]; then 104 | service iptables save 105 | service ip6tables save 106 | chkconfig --level 2345 iptables on 107 | chkconfig --level 2345 ip6tables on 108 | else 109 | iptables-save > /etc/iptables.up.rules 110 | ip6tables-save > /etc/ip6tables.up.rules 111 | 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 112 | chmod +x /etc/network/if-pre-up.d/iptables 113 | fi 114 | } 115 | # 读取 配置信息 116 | Get_IP(){ 117 | ip=$(wget -qO- -t1 -T2 ipinfo.io/ip) 118 | if [[ -z "${ip}" ]]; then 119 | ip=$(wget -qO- -t1 -T2 api.ip.sb/ip) 120 | if [[ -z "${ip}" ]]; then 121 | ip=$(wget -qO- -t1 -T2 members.3322.org/dyndns/getip) 122 | if [[ -z "${ip}" ]]; then 123 | ip="VPS_IP" 124 | fi 125 | fi 126 | fi 127 | } 128 | Get_User(){ 129 | [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 不存在,请检查 !" && exit 1 130 | port=`${jq_file} '.server_port' ${config_user_file}` 131 | password=`${jq_file} '.password' ${config_user_file} | sed 's/^.//;s/.$//'` 132 | method=`${jq_file} '.method' ${config_user_file} | sed 's/^.//;s/.$//'` 133 | protocol=`${jq_file} '.protocol' ${config_user_file} | sed 's/^.//;s/.$//'` 134 | obfs=`${jq_file} '.obfs' ${config_user_file} | sed 's/^.//;s/.$//'` 135 | protocol_param=`${jq_file} '.protocol_param' ${config_user_file} | sed 's/^.//;s/.$//'` 136 | speed_limit_per_con=`${jq_file} '.speed_limit_per_con' ${config_user_file}` 137 | speed_limit_per_user=`${jq_file} '.speed_limit_per_user' ${config_user_file}` 138 | connect_verbose_info=`${jq_file} '.connect_verbose_info' ${config_user_file}` 139 | } 140 | urlsafe_base64(){ 141 | date=$(echo -n "$1"|base64|sed ':a;N;s/\n/ /g;ta'|sed 's/ //g;s/=//g;s/+/-/g;s/\//_/g') 142 | echo -e "${date}" 143 | } 144 | ss_link_qr(){ 145 | SSbase64=$(urlsafe_base64 "${method}:${password}@${ip}:${port}") 146 | SSurl="ss://${SSbase64}" 147 | SSQRcode="http://doub.pw/qr/qr.php?text=${SSurl}" 148 | ss_link=" SS 链接 : ${Green_font_prefix}${SSurl}${Font_color_suffix} \n SS 二维码 : ${Green_font_prefix}${SSQRcode}${Font_color_suffix}" 149 | } 150 | ssr_link_qr(){ 151 | SSRprotocol=$(echo ${protocol} | sed 's/_compatible//g') 152 | SSRobfs=$(echo ${obfs} | sed 's/_compatible//g') 153 | SSRPWDbase64=$(urlsafe_base64 "${password}") 154 | SSRbase64=$(urlsafe_base64 "${ip}:${port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}") 155 | SSRurl="ssr://${SSRbase64}" 156 | SSRQRcode="http://doub.pw/qr/qr.php?text=${SSRurl}" 157 | ssr_link=" SSR 链接 : ${Red_font_prefix}${SSRurl}${Font_color_suffix} \n SSR 二维码 : ${Red_font_prefix}${SSRQRcode}${Font_color_suffix} \n " 158 | } 159 | ss_ssr_determine(){ 160 | protocol_suffix=`echo ${protocol} | awk -F "_" '{print $NF}'` 161 | obfs_suffix=`echo ${obfs} | awk -F "_" '{print $NF}'` 162 | if [[ ${protocol} = "origin" ]]; then 163 | if [[ ${obfs} = "plain" ]]; then 164 | ss_link_qr 165 | ssr_link="" 166 | else 167 | if [[ ${obfs_suffix} != "compatible" ]]; then 168 | ss_link="" 169 | else 170 | ss_link_qr 171 | fi 172 | fi 173 | else 174 | if [[ ${protocol_suffix} != "compatible" ]]; then 175 | ss_link="" 176 | else 177 | if [[ ${obfs_suffix} != "compatible" ]]; then 178 | if [[ ${obfs_suffix} = "plain" ]]; then 179 | ss_link_qr 180 | else 181 | ss_link="" 182 | fi 183 | else 184 | ss_link_qr 185 | fi 186 | fi 187 | fi 188 | ssr_link_qr 189 | } 190 | # 显示 配置信息 191 | View_User(){ 192 | SSR_installation_status 193 | Get_IP 194 | Get_User 195 | now_mode=$(cat "${config_user_file}"|grep '"port_password"') 196 | [[ -z ${protocol_param} ]] && protocol_param="0(无限)" 197 | if [[ -z "${now_mode}" ]]; then 198 | ss_ssr_determine 199 | clear && echo "===================================================" && echo 200 | echo -e " ShadowsocksR账号 配置信息:" && echo 201 | echo -e " I P\t : ${Green_font_prefix}${ip}${Font_color_suffix}" 202 | echo -e " 端口\t : ${Green_font_prefix}${port}${Font_color_suffix}" 203 | echo -e " 密码\t : ${Green_font_prefix}${password}${Font_color_suffix}" 204 | echo -e " 加密\t : ${Green_font_prefix}${method}${Font_color_suffix}" 205 | echo -e " 协议\t : ${Red_font_prefix}${protocol}${Font_color_suffix}" 206 | echo -e " 混淆\t : ${Red_font_prefix}${obfs}${Font_color_suffix}" 207 | echo -e " 设备数限制 : ${Green_font_prefix}${protocol_param}${Font_color_suffix}" 208 | echo -e " 单线程限速 : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}" 209 | echo -e " 端口总限速 : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}" 210 | echo -e "${ss_link}" 211 | echo -e "${ssr_link}" 212 | echo -e " ${Green_font_prefix} 提示: ${Font_color_suffix} 213 | 在浏览器中,打开二维码链接,就可以看到二维码图片。 214 | 协议和混淆后面的[ _compatible ],指的是 兼容原版协议/混淆。" 215 | echo && echo "===================================================" 216 | else 217 | user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l` 218 | [[ ${user_total} = "0" ]] && echo -e "${Error} 没有发现 多端口用户,请检查 !" && exit 1 219 | clear && echo "===================================================" && echo 220 | echo -e " ShadowsocksR账号 配置信息:" && echo 221 | echo -e " I P\t : ${Green_font_prefix}${ip}${Font_color_suffix}" 222 | echo -e " 加密\t : ${Green_font_prefix}${method}${Font_color_suffix}" 223 | echo -e " 协议\t : ${Red_font_prefix}${protocol}${Font_color_suffix}" 224 | echo -e " 混淆\t : ${Red_font_prefix}${obfs}${Font_color_suffix}" 225 | echo -e " 设备数限制 : ${Green_font_prefix}${protocol_param}${Font_color_suffix}" 226 | echo -e " 单线程限速 : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}" 227 | echo -e " 端口总限速 : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}" && echo 228 | for((integer = ${user_total}; integer >= 1; integer--)) 229 | do 230 | port=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 231 | password=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 232 | ss_ssr_determine 233 | echo -e ${Separator_1} 234 | echo -e " 端口\t : ${Green_font_prefix}${port}${Font_color_suffix}" 235 | echo -e " 密码\t : ${Green_font_prefix}${password}${Font_color_suffix}" 236 | echo -e "${ss_link}" 237 | echo -e "${ssr_link}" 238 | done 239 | echo -e " ${Green_font_prefix} 提示: ${Font_color_suffix} 240 | 在浏览器中,打开二维码链接,就可以看到二维码图片。 241 | 协议和混淆后面的[ _compatible ],指的是 兼容原版协议/混淆。" 242 | echo && echo "===================================================" 243 | fi 244 | } 245 | # 设置 配置信息 246 | Set_config_port(){ 247 | while true 248 | do 249 | echo -e "请输入要设置的ShadowsocksR账号 端口" 250 | stty erase '^H' && read -p "(默认: 2333):" ssr_port 251 | [[ -z "$ssr_port" ]] && ssr_port="2333" 252 | expr ${ssr_port} + 0 &>/dev/null 253 | if [[ $? == 0 ]]; then 254 | if [[ ${ssr_port} -ge 1 ]] && [[ ${ssr_port} -le 65535 ]]; then 255 | echo && echo ${Separator_1} && echo -e " 端口 : ${Green_font_prefix}${ssr_port}${Font_color_suffix}" && echo ${Separator_1} && echo 256 | break 257 | else 258 | echo -e "${Error} 请输入正确的数字(1-65535)" 259 | fi 260 | else 261 | echo -e "${Error} 请输入正确的数字(1-65535)" 262 | fi 263 | done 264 | } 265 | Set_config_password(){ 266 | echo "请输入要设置的ShadowsocksR账号 密码" 267 | stty erase '^H' && read -p "(默认: doub.io):" ssr_password 268 | [[ -z "${ssr_password}" ]] && ssr_password="xnmll.cn" 269 | echo && echo ${Separator_1} && echo -e " 密码 : ${Green_font_prefix}${ssr_password}${Font_color_suffix}" && echo ${Separator_1} && echo 270 | } 271 | Set_config_method(){ 272 | echo -e "请选择要设置的ShadowsocksR账号 加密方式 273 | ${Green_font_prefix} 1.${Font_color_suffix} none 274 | ${Tip} 如果使用 auth_chain_a 协议,请加密方式选择 none,混淆随意(建议 plain) 275 | 276 | ${Green_font_prefix} 2.${Font_color_suffix} rc4 277 | ${Green_font_prefix} 3.${Font_color_suffix} rc4-md5 278 | ${Green_font_prefix} 4.${Font_color_suffix} rc4-md5-6 279 | 280 | ${Green_font_prefix} 5.${Font_color_suffix} aes-128-ctr 281 | ${Green_font_prefix} 6.${Font_color_suffix} aes-192-ctr 282 | ${Green_font_prefix} 7.${Font_color_suffix} aes-256-ctr 283 | 284 | ${Green_font_prefix} 8.${Font_color_suffix} aes-128-cfb 285 | ${Green_font_prefix} 9.${Font_color_suffix} aes-192-cfb 286 | ${Green_font_prefix}10.${Font_color_suffix} aes-256-cfb 287 | 288 | ${Green_font_prefix}11.${Font_color_suffix} aes-128-cfb8 289 | ${Green_font_prefix}12.${Font_color_suffix} aes-192-cfb8 290 | ${Green_font_prefix}13.${Font_color_suffix} aes-256-cfb8 291 | 292 | ${Green_font_prefix}14.${Font_color_suffix} salsa20 293 | ${Green_font_prefix}15.${Font_color_suffix} chacha20 294 | ${Green_font_prefix}16.${Font_color_suffix} chacha20-ietf 295 | ${Tip} salsa20/chacha20-*系列加密方式,需要额外安装依赖 libsodium ,否则会无法启动ShadowsocksR !" && echo 296 | stty erase '^H' && read -p "(默认: 5. aes-128-ctr):" ssr_method 297 | [[ -z "${ssr_method}" ]] && ssr_method="5" 298 | if [[ ${ssr_method} == "1" ]]; then 299 | ssr_method="none" 300 | elif [[ ${ssr_method} == "2" ]]; then 301 | ssr_method="rc4" 302 | elif [[ ${ssr_method} == "3" ]]; then 303 | ssr_method="rc4-md5" 304 | elif [[ ${ssr_method} == "4" ]]; then 305 | ssr_method="rc4-md5-6" 306 | elif [[ ${ssr_method} == "5" ]]; then 307 | ssr_method="aes-128-ctr" 308 | elif [[ ${ssr_method} == "6" ]]; then 309 | ssr_method="aes-192-ctr" 310 | elif [[ ${ssr_method} == "7" ]]; then 311 | ssr_method="aes-256-ctr" 312 | elif [[ ${ssr_method} == "8" ]]; then 313 | ssr_method="aes-128-cfb" 314 | elif [[ ${ssr_method} == "9" ]]; then 315 | ssr_method="aes-192-cfb" 316 | elif [[ ${ssr_method} == "10" ]]; then 317 | ssr_method="aes-256-cfb" 318 | elif [[ ${ssr_method} == "11" ]]; then 319 | ssr_method="aes-128-cfb8" 320 | elif [[ ${ssr_method} == "12" ]]; then 321 | ssr_method="aes-192-cfb8" 322 | elif [[ ${ssr_method} == "13" ]]; then 323 | ssr_method="aes-256-cfb8" 324 | elif [[ ${ssr_method} == "14" ]]; then 325 | ssr_method="salsa20" 326 | elif [[ ${ssr_method} == "15" ]]; then 327 | ssr_method="chacha20" 328 | elif [[ ${ssr_method} == "16" ]]; then 329 | ssr_method="chacha20-ietf" 330 | else 331 | ssr_method="aes-128-ctr" 332 | fi 333 | echo && echo ${Separator_1} && echo -e " 加密 : ${Green_font_prefix}${ssr_method}${Font_color_suffix}" && echo ${Separator_1} && echo 334 | } 335 | Set_config_protocol(){ 336 | echo -e "请选择要设置的ShadowsocksR账号 协议插件 337 | ${Green_font_prefix}1.${Font_color_suffix} origin 338 | ${Green_font_prefix}2.${Font_color_suffix} auth_sha1_v4 339 | ${Green_font_prefix}3.${Font_color_suffix} auth_aes128_md5 340 | ${Green_font_prefix}4.${Font_color_suffix} auth_aes128_sha1 341 | ${Green_font_prefix}5.${Font_color_suffix} auth_chain_a 342 | ${Green_font_prefix}6.${Font_color_suffix} auth_chain_b 343 | ${Tip} 如果使用 auth_chain_a 协议,请加密方式选择 none,混淆随意(建议 plain)" && echo 344 | stty erase '^H' && read -p "(默认: 2. auth_sha1_v4):" ssr_protocol 345 | [[ -z "${ssr_protocol}" ]] && ssr_protocol="2" 346 | if [[ ${ssr_protocol} == "1" ]]; then 347 | ssr_protocol="origin" 348 | elif [[ ${ssr_protocol} == "2" ]]; then 349 | ssr_protocol="auth_sha1_v4" 350 | elif [[ ${ssr_protocol} == "3" ]]; then 351 | ssr_protocol="auth_aes128_md5" 352 | elif [[ ${ssr_protocol} == "4" ]]; then 353 | ssr_protocol="auth_aes128_sha1" 354 | elif [[ ${ssr_protocol} == "5" ]]; then 355 | ssr_protocol="auth_chain_a" 356 | elif [[ ${ssr_protocol} == "6" ]]; then 357 | ssr_protocol="auth_chain_b" 358 | else 359 | ssr_protocol="auth_sha1_v4" 360 | fi 361 | echo && echo ${Separator_1} && echo -e " 协议 : ${Green_font_prefix}${ssr_protocol}${Font_color_suffix}" && echo ${Separator_1} && echo 362 | if [[ ${ssr_protocol} != "origin" ]]; then 363 | if [[ ${ssr_protocol} == "auth_sha1_v4" ]]; then 364 | stty erase '^H' && read -p "是否设置 协议插件兼容原版(_compatible)?[Y/n]" ssr_protocol_yn 365 | [[ -z "${ssr_protocol_yn}" ]] && ssr_protocol_yn="y" 366 | [[ $ssr_protocol_yn == [Yy] ]] && ssr_protocol=${ssr_protocol}"_compatible" 367 | echo 368 | fi 369 | fi 370 | } 371 | Set_config_obfs(){ 372 | echo -e "请选择要设置的ShadowsocksR账号 混淆插件 373 | ${Green_font_prefix}1.${Font_color_suffix} plain 374 | ${Green_font_prefix}2.${Font_color_suffix} http_simple 375 | ${Green_font_prefix}3.${Font_color_suffix} http_post 376 | ${Green_font_prefix}4.${Font_color_suffix} random_head 377 | ${Green_font_prefix}5.${Font_color_suffix} tls1.2_ticket_auth 378 | ${Tip} 如果使用 ShadowsocksR 加速游戏,请选择 混淆兼容原版或 plain 混淆,然后客户端选择 plain,否则会增加延迟 !" && echo 379 | stty erase '^H' && read -p "(默认: 5. tls1.2_ticket_auth):" ssr_obfs 380 | [[ -z "${ssr_obfs}" ]] && ssr_obfs="5" 381 | if [[ ${ssr_obfs} == "1" ]]; then 382 | ssr_obfs="plain" 383 | elif [[ ${ssr_obfs} == "2" ]]; then 384 | ssr_obfs="http_simple" 385 | elif [[ ${ssr_obfs} == "3" ]]; then 386 | ssr_obfs="http_post" 387 | elif [[ ${ssr_obfs} == "4" ]]; then 388 | ssr_obfs="random_head" 389 | elif [[ ${ssr_obfs} == "5" ]]; then 390 | ssr_obfs="tls1.2_ticket_auth" 391 | else 392 | ssr_obfs="tls1.2_ticket_auth" 393 | fi 394 | echo && echo ${Separator_1} && echo -e " 混淆 : ${Green_font_prefix}${ssr_obfs}${Font_color_suffix}" && echo ${Separator_1} && echo 395 | if [[ ${ssr_obfs} != "plain" ]]; then 396 | stty erase '^H' && read -p "是否设置 混淆插件兼容原版(_compatible)?[Y/n]" ssr_obfs_yn 397 | [[ -z "${ssr_obfs_yn}" ]] && ssr_obfs_yn="y" 398 | [[ $ssr_obfs_yn == [Yy] ]] && ssr_obfs=${ssr_obfs}"_compatible" 399 | echo 400 | fi 401 | } 402 | Set_config_protocol_param(){ 403 | while true 404 | do 405 | echo -e "请输入要设置的ShadowsocksR账号 欲限制的设备数 (${Green_font_prefix} auth_* 系列协议 不兼容原版才有效 ${Font_color_suffix})" 406 | echo -e "${Tip} 设备数限制:每个端口同一时间能链接的客户端数量(多端口模式,每个端口都是独立计算),建议最少 2个。" 407 | stty erase '^H' && read -p "(默认: 无限):" ssr_protocol_param 408 | [[ -z "$ssr_protocol_param" ]] && ssr_protocol_param="" && echo && break 409 | expr ${ssr_protocol_param} + 0 &>/dev/null 410 | if [[ $? == 0 ]]; then 411 | if [[ ${ssr_protocol_param} -ge 1 ]] && [[ ${ssr_protocol_param} -le 9999 ]]; then 412 | echo && echo ${Separator_1} && echo -e " 设备数限制 : ${Green_font_prefix}${ssr_protocol_param}${Font_color_suffix}" && echo ${Separator_1} && echo 413 | break 414 | else 415 | echo -e "${Error} 请输入正确的数字(1-9999)" 416 | fi 417 | else 418 | echo -e "${Error} 请输入正确的数字(1-9999)" 419 | fi 420 | done 421 | } 422 | Set_config_speed_limit_per_con(){ 423 | while true 424 | do 425 | echo -e "请输入要设置的每个端口 单线程 限速上限(单位:KB/S)" 426 | echo -e "${Tip} 单线程限速:每个端口 单线程的限速上限,多线程即无效。" 427 | stty erase '^H' && read -p "(默认: 无限):" ssr_speed_limit_per_con 428 | [[ -z "$ssr_speed_limit_per_con" ]] && ssr_speed_limit_per_con=0 && echo && break 429 | expr ${ssr_speed_limit_per_con} + 0 &>/dev/null 430 | if [[ $? == 0 ]]; then 431 | if [[ ${ssr_speed_limit_per_con} -ge 1 ]] && [[ ${ssr_speed_limit_per_con} -le 131072 ]]; then 432 | echo && echo ${Separator_1} && echo -e " 单线程限速 : ${Green_font_prefix}${ssr_speed_limit_per_con} KB/S${Font_color_suffix}" && echo ${Separator_1} && echo 433 | break 434 | else 435 | echo -e "${Error} 请输入正确的数字(1-131072)" 436 | fi 437 | else 438 | echo -e "${Error} 请输入正确的数字(1-131072)" 439 | fi 440 | done 441 | } 442 | Set_config_speed_limit_per_user(){ 443 | while true 444 | do 445 | echo 446 | echo -e "请输入要设置的每个端口 总速度 限速上限(单位:KB/S)" 447 | echo -e "${Tip} 端口总限速:每个端口 总速度 限速上限,单个端口整体限速。" 448 | stty erase '^H' && read -p "(默认: 无限):" ssr_speed_limit_per_user 449 | [[ -z "$ssr_speed_limit_per_user" ]] && ssr_speed_limit_per_user=0 && echo && break 450 | expr ${ssr_speed_limit_per_user} + 0 &>/dev/null 451 | if [[ $? == 0 ]]; then 452 | if [[ ${ssr_speed_limit_per_user} -ge 1 ]] && [[ ${ssr_speed_limit_per_user} -le 131072 ]]; then 453 | echo && echo ${Separator_1} && echo -e " 端口总限速 : ${Green_font_prefix}${ssr_speed_limit_per_user} KB/S${Font_color_suffix}" && echo ${Separator_1} && echo 454 | break 455 | else 456 | echo -e "${Error} 请输入正确的数字(1-131072)" 457 | fi 458 | else 459 | echo -e "${Error} 请输入正确的数字(1-131072)" 460 | fi 461 | done 462 | } 463 | Set_config_all(){ 464 | Set_config_port 465 | Set_config_password 466 | Set_config_method 467 | Set_config_protocol 468 | Set_config_obfs 469 | Set_config_protocol_param 470 | Set_config_speed_limit_per_con 471 | Set_config_speed_limit_per_user 472 | } 473 | # 修改 配置信息 474 | Modify_config_port(){ 475 | sed -i 's/"server_port": '"$(echo ${port})"'/"server_port": '"$(echo ${ssr_port})"'/g' ${config_user_file} 476 | } 477 | Modify_config_password(){ 478 | sed -i 's/"password": "'"$(echo ${password})"'"/"password": "'"$(echo ${ssr_password})"'"/g' ${config_user_file} 479 | } 480 | Modify_config_method(){ 481 | sed -i 's/"method": "'"$(echo ${method})"'"/"method": "'"$(echo ${ssr_method})"'"/g' ${config_user_file} 482 | } 483 | Modify_config_protocol(){ 484 | sed -i 's/"protocol": "'"$(echo ${protocol})"'"/"protocol": "'"$(echo ${ssr_protocol})"'"/g' ${config_user_file} 485 | } 486 | Modify_config_obfs(){ 487 | sed -i 's/"obfs": "'"$(echo ${obfs})"'"/"obfs": "'"$(echo ${ssr_obfs})"'"/g' ${config_user_file} 488 | } 489 | Modify_config_protocol_param(){ 490 | sed -i 's/"protocol_param": "'"$(echo ${protocol_param})"'"/"protocol_param": "'"$(echo ${ssr_protocol_param})"'"/g' ${config_user_file} 491 | } 492 | Modify_config_speed_limit_per_con(){ 493 | sed -i 's/"speed_limit_per_con": '"$(echo ${speed_limit_per_con})"'/"speed_limit_per_con": '"$(echo ${ssr_speed_limit_per_con})"'/g' ${config_user_file} 494 | } 495 | Modify_config_speed_limit_per_user(){ 496 | sed -i 's/"speed_limit_per_user": '"$(echo ${speed_limit_per_user})"'/"speed_limit_per_user": '"$(echo ${ssr_speed_limit_per_user})"'/g' ${config_user_file} 497 | } 498 | Modify_config_connect_verbose_info(){ 499 | sed -i 's/"connect_verbose_info": '"$(echo ${connect_verbose_info})"'/"connect_verbose_info": '"$(echo ${ssr_connect_verbose_info})"'/g' ${config_user_file} 500 | } 501 | Modify_config_all(){ 502 | Modify_config_port 503 | Modify_config_password 504 | Modify_config_method 505 | Modify_config_protocol 506 | Modify_config_obfs 507 | Modify_config_protocol_param 508 | Modify_config_speed_limit_per_con 509 | Modify_config_speed_limit_per_user 510 | } 511 | Modify_config_port_many(){ 512 | sed -i 's/"'"$(echo ${port})"'":/"'"$(echo ${ssr_port})"'":/g' ${config_user_file} 513 | } 514 | Modify_config_password_many(){ 515 | sed -i 's/"'"$(echo ${password})"'"/"'"$(echo ${ssr_password})"'"/g' ${config_user_file} 516 | } 517 | # 写入 配置信息 518 | Write_configuration(){ 519 | cat > ${config_user_file}<<-EOF 520 | { 521 | "server": "0.0.0.0", 522 | "server_ipv6": "::", 523 | "server_port": ${ssr_port}, 524 | "local_address": "127.0.0.1", 525 | "local_port": 1080, 526 | 527 | "password": "${ssr_password}", 528 | "method": "${ssr_method}", 529 | "protocol": "${ssr_protocol}", 530 | "protocol_param": "${ssr_protocol_param}", 531 | "obfs": "${ssr_obfs}", 532 | "obfs_param": "", 533 | "speed_limit_per_con": ${ssr_speed_limit_per_con}, 534 | "speed_limit_per_user": ${ssr_speed_limit_per_user}, 535 | 536 | "additional_ports" : {}, 537 | "timeout": 120, 538 | "udp_timeout": 60, 539 | "dns_ipv6": false, 540 | "connect_verbose_info": 0, 541 | "redirect": "", 542 | "fast_open": false 543 | } 544 | EOF 545 | } 546 | Write_configuration_many(){ 547 | cat > ${config_user_file}<<-EOF 548 | { 549 | "server": "0.0.0.0", 550 | "server_ipv6": "::", 551 | "local_address": "127.0.0.1", 552 | "local_port": 1080, 553 | 554 | "port_password":{ 555 | "${ssr_port}":"${ssr_password}" 556 | }, 557 | "method": "${ssr_method}", 558 | "protocol": "${ssr_protocol}", 559 | "protocol_param": "${ssr_protocol_param}", 560 | "obfs": "${ssr_obfs}", 561 | "obfs_param": "", 562 | "speed_limit_per_con": ${ssr_speed_limit_per_con}, 563 | "speed_limit_per_user": ${ssr_speed_limit_per_user}, 564 | 565 | "additional_ports" : {}, 566 | "timeout": 120, 567 | "udp_timeout": 60, 568 | "dns_ipv6": false, 569 | "connect_verbose_info": 0, 570 | "redirect": "", 571 | "fast_open": false 572 | } 573 | EOF 574 | } 575 | Check_python(){ 576 | python_ver=`python -h` 577 | if [[ -z ${python_ver} ]]; then 578 | echo -e "${Info} 没有安装Python,开始安装..." 579 | if [[ ${release} == "centos" ]]; then 580 | yum install -y python 581 | else 582 | apt-get install -y python 583 | fi 584 | fi 585 | } 586 | Centos_yum(){ 587 | yum update 588 | cat /etc/redhat-release |grep 7\..*|grep -i centos>/dev/null 589 | if [[ $? = 0 ]]; then 590 | yum install -y vim unzip net-tools 591 | else 592 | yum install -y vim unzip 593 | fi 594 | } 595 | Debian_apt(){ 596 | apt-get update 597 | cat /etc/issue |grep 9\..*>/dev/null 598 | if [[ $? = 0 ]]; then 599 | apt-get install -y vim unzip net-tools 600 | else 601 | apt-get install -y vim unzip 602 | fi 603 | } 604 | # 下载 ShadowsocksR 605 | Download_SSR(){ 606 | cd "/usr/local/" 607 | wget -N --no-check-certificate "https://github.com/ToyoDAdoubi/shadowsocksr/archive/manyuser.zip" 608 | #git config --global http.sslVerify false 609 | #env GIT_SSL_NO_VERIFY=true git clone -b manyuser https://github.com/ToyoDAdoubi/shadowsocksr.git 610 | #[[ ! -e ${ssr_folder} ]] && echo -e "${Error} ShadowsocksR服务端 下载失败 !" && exit 1 611 | [[ ! -e "manyuser.zip" ]] && echo -e "${Error} ShadowsocksR服务端 压缩包 下载失败 !" && rm -rf manyuser.zip && exit 1 612 | unzip "manyuser.zip" 613 | [[ ! -e "/usr/local/shadowsocksr-manyuser/" ]] && echo -e "${Error} ShadowsocksR服务端 解压失败 !" && rm -rf manyuser.zip && exit 1 614 | mv "/usr/local/shadowsocksr-manyuser/" "/usr/local/shadowsocksr/" 615 | [[ ! -e "/usr/local/shadowsocksr/" ]] && echo -e "${Error} ShadowsocksR服务端 重命名失败 !" && rm -rf manyuser.zip && rm -rf "/usr/local/shadowsocksr-manyuser/" && exit 1 616 | rm -rf manyuser.zip 617 | [[ -e ${config_folder} ]] && rm -rf ${config_folder} 618 | mkdir ${config_folder} 619 | [[ ! -e ${config_folder} ]] && echo -e "${Error} ShadowsocksR配置文件的文件夹 建立失败 !" && exit 1 620 | echo -e "${Info} ShadowsocksR服务端 下载完成 !" 621 | } 622 | Service_SSR(){ 623 | if [[ ${release} = "centos" ]]; then 624 | if ! wget --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/other/ssr_centos -O /etc/init.d/ssr; then 625 | echo -e "${Error} ShadowsocksR服务 管理脚本下载失败 !" && exit 1 626 | fi 627 | chmod +x /etc/init.d/ssr 628 | chkconfig --add ssr 629 | chkconfig ssr on 630 | else 631 | if ! wget --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/other/ssr_debian -O /etc/init.d/ssr; then 632 | echo -e "${Error} ShadowsocksR服务 管理脚本下载失败 !" && exit 1 633 | fi 634 | chmod +x /etc/init.d/ssr 635 | update-rc.d -f ssr defaults 636 | fi 637 | echo -e "${Info} ShadowsocksR服务 管理脚本下载完成 !" 638 | } 639 | # 安装 JQ解析器 640 | JQ_install(){ 641 | if [[ ! -e ${jq_file} ]]; then 642 | cd "${ssr_folder}" 643 | if [[ ${bit} = "x86_64" ]]; then 644 | mv "jq-linux64" "jq" 645 | #wget --no-check-certificate "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file} 646 | else 647 | mv "jq-linux32" "jq" 648 | #wget --no-check-certificate "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux32" -O ${jq_file} 649 | fi 650 | [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 重命名失败,请检查 !" && exit 1 651 | chmod +x ${jq_file} 652 | echo -e "${Info} JQ解析器 安装完成,继续..." 653 | else 654 | echo -e "${Info} JQ解析器 已安装,继续..." 655 | fi 656 | } 657 | # 安装 依赖 658 | Installation_dependency(){ 659 | if [[ ${release} == "centos" ]]; then 660 | Centos_yum 661 | else 662 | Debian_apt 663 | fi 664 | [[ ! -e "/usr/bin/unzip" ]] && echo -e "${Error} 依赖 unzip(解压压缩包) 安装失败,多半是软件包源的问题,请检查 !" && exit 1 665 | Check_python 666 | #echo "nameserver 8.8.8.8" > /etc/resolv.conf 667 | #echo "nameserver 8.8.4.4" >> /etc/resolv.conf 668 | cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 669 | } 670 | Install_SSR(){ 671 | check_root 672 | [[ -e ${config_user_file} ]] && echo -e "${Error} ShadowsocksR 配置文件已存在,请检查( 如安装失败或者存在旧版本,请先卸载 ) !" && exit 1 673 | [[ -e ${ssr_folder} ]] && echo -e "${Error} ShadowsocksR 文件夹已存在,请检查( 如安装失败或者存在旧版本,请先卸载 ) !" && exit 1 674 | echo -e "${Info} 开始设置 ShadowsocksR账号配置..." 675 | Set_config_all 676 | echo -e "${Info} 开始安装/配置 ShadowsocksR依赖..." 677 | Installation_dependency 678 | echo -e "${Info} 开始下载/安装 ShadowsocksR文件..." 679 | Download_SSR 680 | echo -e "${Info} 开始下载/安装 ShadowsocksR服务脚本(init)..." 681 | Service_SSR 682 | echo -e "${Info} 开始下载/安装 JSNO解析器 JQ..." 683 | JQ_install 684 | echo -e "${Info} 开始写入 ShadowsocksR配置文件..." 685 | Write_configuration 686 | echo -e "${Info} 开始设置 iptables防火墙..." 687 | Set_iptables 688 | echo -e "${Info} 开始添加 iptables防火墙规则..." 689 | Add_iptables 690 | echo -e "${Info} 开始保存 iptables防火墙规则..." 691 | Save_iptables 692 | echo -e "${Info} 所有步骤 安装完毕,开始启动 ShadowsocksR服务端..." 693 | Start_SSR 694 | } 695 | Update_SSR(){ 696 | SSR_installation_status 697 | echo -e "因破娃暂停更新ShadowsocksR服务端,所以此功能临时禁用。" 698 | #cd ${ssr_folder} 699 | #git pull 700 | #Restart_SSR 701 | } 702 | Uninstall_SSR(){ 703 | [[ ! -e ${config_user_file} ]] && [[ ! -e ${ssr_folder} ]] && echo -e "${Error} 没有安装 ShadowsocksR,请检查 !" && exit 1 704 | echo "确定要 卸载ShadowsocksR?[y/N]" && echo 705 | stty erase '^H' && read -p "(默认: n):" unyn 706 | [[ -z ${unyn} ]] && unyn="n" 707 | if [[ ${unyn} == [Yy] ]]; then 708 | check_pid 709 | [[ ! -z "${PID}" ]] && kill -9 ${PID} 710 | if [[ -z "${now_mode}" ]]; then 711 | port=`${jq_file} '.server_port' ${config_user_file}` 712 | Del_iptables 713 | else 714 | user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l` 715 | for((integer = 1; integer <= ${user_total}; integer++)) 716 | do 717 | port=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 718 | Del_iptables 719 | done 720 | fi 721 | if [[ ${release} = "centos" ]]; then 722 | chkconfig --del ssr 723 | else 724 | update-rc.d -f ssr remove 725 | fi 726 | rm -rf ${ssr_folder} && rm -rf ${config_folder} && rm -rf /etc/init.d/ssr 727 | echo && echo " ShadowsocksR 卸载完成 !" && echo 728 | else 729 | echo && echo " 卸载已取消..." && echo 730 | fi 731 | } 732 | Check_Libsodium_ver(){ 733 | echo -e "${Info} 开始获取 libsodium 最新版本..." 734 | Libsodiumr_ver=$(wget -qO- "https://github.com/jedisct1/libsodium/tags"|grep "/jedisct1/libsodium/releases/tag/"|head -1|sed -r 's/.*tag\/(.+)\">.*/\1/') 735 | [[ -z ${Libsodiumr_ver} ]] && Libsodiumr_ver=${Libsodiumr_ver_backup} 736 | echo -e "${Info} libsodium 最新版本为 ${Green_font_prefix}${Libsodiumr_ver}${Font_color_suffix} !" 737 | } 738 | Install_Libsodium(){ 739 | if [[ -e ${Libsodiumr_file} ]]; then 740 | echo -e "${Error} libsodium 已安装 , 是否覆盖安装(更新)?[y/N]" 741 | stty erase '^H' && read -p "(默认: n):" yn 742 | [[ -z ${yn} ]] && yn="n" 743 | if [[ ${yn} == [Nn] ]]; then 744 | echo "已取消..." && exit 1 745 | fi 746 | else 747 | echo -e "${Info} libsodium 未安装,开始安装..." 748 | fi 749 | Check_Libsodium_ver 750 | if [[ ${release} == "centos" ]]; then 751 | yum update 752 | echo -e "${Info} 安装依赖..." 753 | yum -y groupinstall "Development Tools" 754 | echo -e "${Info} 下载..." 755 | wget --no-check-certificate -N "https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz" 756 | echo -e "${Info} 解压..." 757 | tar -xzf libsodium-${Libsodiumr_ver}.tar.gz && cd libsodium-${Libsodiumr_ver} 758 | echo -e "${Info} 编译安装..." 759 | ./configure --disable-maintainer-mode && make -j2 && make install 760 | echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf 761 | else 762 | apt-get update 763 | echo -e "${Info} 安装依赖..." 764 | apt-get install -y build-essential 765 | echo -e "${Info} 下载..." 766 | wget --no-check-certificate -N "https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz" 767 | echo -e "${Info} 解压..." 768 | tar -xzf libsodium-${Libsodiumr_ver}.tar.gz && cd libsodium-${Libsodiumr_ver} 769 | echo -e "${Info} 编译安装..." 770 | ./configure --disable-maintainer-mode && make -j2 && make install 771 | fi 772 | ldconfig 773 | cd .. && rm -rf libsodium-${Libsodiumr_ver}.tar.gz && rm -rf libsodium-${Libsodiumr_ver} 774 | [[ ! -e ${Libsodiumr_file} ]] && echo -e "${Error} libsodium 安装失败 !" && exit 1 775 | echo && echo -e "${Info} libsodium 安装成功 !" && echo 776 | } 777 | # 显示 连接信息 778 | debian_View_user_connection_info(){ 779 | format_1=$1 780 | if [[ -z "${now_mode}" ]]; then 781 | now_mode="单端口" && user_total="1" 782 | IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l` 783 | user_port=`${jq_file} '.server_port' ${config_user_file}` 784 | user_IP_1=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep ":${user_port} " |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u` 785 | if [[ -z ${user_IP_1} ]]; then 786 | user_IP_total="0" 787 | else 788 | user_IP_total=`echo -e "${user_IP_1}"|wc -l` 789 | if [[ ${format_1} == "IP_address" ]]; then 790 | get_IP_address 791 | else 792 | user_IP=`echo -e "\n${user_IP_1}"` 793 | fi 794 | fi 795 | user_list_all="端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}\t 链接IP总数: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}\t 当前链接IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n" 796 | user_IP="" 797 | echo -e "当前模式: ${Green_background_prefix} "${now_mode}" ${Font_color_suffix} 链接IP总数: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix}" 798 | echo -e "${user_list_all}" 799 | else 800 | now_mode="多端口" && user_total=`${jq_file} '.port_password' ${config_user_file} |sed '$d;1d' | wc -l` 801 | IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l` 802 | user_list_all="" 803 | for((integer = ${user_total}; integer >= 1; integer--)) 804 | do 805 | user_port=`${jq_file} '.port_password' ${config_user_file} |sed '$d;1d' |awk -F ":" '{print $1}' |sed -n "${integer}p" |sed -r 's/.*\"(.+)\".*/\1/'` 806 | user_IP_1=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u` 807 | if [[ -z ${user_IP_1} ]]; then 808 | user_IP_total="0" 809 | else 810 | user_IP_total=`echo -e "${user_IP_1}"|wc -l` 811 | if [[ ${format_1} == "IP_address" ]]; then 812 | get_IP_address 813 | else 814 | user_IP=`echo -e "\n${user_IP_1}"` 815 | fi 816 | fi 817 | user_list_all=${user_list_all}"端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}\t 链接IP总数: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}\t 当前链接IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n" 818 | user_IP="" 819 | done 820 | echo -e "当前模式: ${Green_background_prefix} "${now_mode}" ${Font_color_suffix} 用户总数: ${Green_background_prefix} "${user_total}" ${Font_color_suffix} 链接IP总数: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix} " 821 | echo -e "${user_list_all}" 822 | fi 823 | } 824 | centos_View_user_connection_info(){ 825 | format_1=$1 826 | if [[ -z "${now_mode}" ]]; then 827 | now_mode="单端口" && user_total="1" 828 | IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l` 829 | user_port=`${jq_file} '.server_port' ${config_user_file}` 830 | 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` 831 | if [[ -z ${user_IP_1} ]]; then 832 | user_IP_total="0" 833 | else 834 | user_IP_total=`echo -e "${user_IP_1}"|wc -l` 835 | if [[ ${format_1} == "IP_address" ]]; then 836 | get_IP_address 837 | else 838 | user_IP=`echo -e "\n${user_IP_1}"` 839 | fi 840 | fi 841 | user_list_all="端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}\t 链接IP总数: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}\t 当前链接IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n" 842 | user_IP="" 843 | echo -e "当前模式: ${Green_background_prefix} "${now_mode}" ${Font_color_suffix} 链接IP总数: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix}" 844 | echo -e "${user_list_all}" 845 | else 846 | now_mode="多端口" && user_total=`${jq_file} '.port_password' ${config_user_file} |sed '$d;1d' | wc -l` 847 | IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l` 848 | user_list_all="" 849 | for((integer = 1; integer <= ${user_total}; integer++)) 850 | do 851 | user_port=`${jq_file} '.port_password' ${config_user_file} |sed '$d;1d' |awk -F ":" '{print $1}' |sed -n "${integer}p" |sed -r 's/.*\"(.+)\".*/\1/'` 852 | 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` 853 | if [[ -z ${user_IP_1} ]]; then 854 | user_IP_total="0" 855 | else 856 | user_IP_total=`echo -e "${user_IP_1}"|wc -l` 857 | if [[ ${format_1} == "IP_address" ]]; then 858 | get_IP_address 859 | else 860 | user_IP=`echo -e "\n${user_IP_1}"` 861 | fi 862 | fi 863 | user_list_all=${user_list_all}"端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}\t 链接IP总数: ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}\t 当前链接IP: ${Green_font_prefix}${user_IP}${Font_color_suffix}\n" 864 | user_IP="" 865 | done 866 | echo -e "当前模式: ${Green_background_prefix} "${now_mode}" ${Font_color_suffix} 用户总数: ${Green_background_prefix} "${user_total}" ${Font_color_suffix} 链接IP总数: ${Green_background_prefix} "${IP_total}" ${Font_color_suffix} " 867 | echo -e "${user_list_all}" 868 | fi 869 | } 870 | View_user_connection_info(){ 871 | SSR_installation_status 872 | echo && echo -e "请选择要显示的格式: 873 | ${Green_font_prefix}1.${Font_color_suffix} 显示 IP 格式 874 | ${Green_font_prefix}2.${Font_color_suffix} 显示 IP+IP归属地 格式" && echo 875 | stty erase '^H' && read -p "(默认: 1):" ssr_connection_info 876 | [[ -z "${ssr_connection_info}" ]] && ssr_connection_info="1" 877 | if [[ ${ssr_connection_info} == "1" ]]; then 878 | View_user_connection_info_1 "" 879 | elif [[ ${ssr_connection_info} == "2" ]]; then 880 | echo -e "${Tip} 检测IP归属地(ipip.net),如果IP较多,可能时间会比较长..." 881 | View_user_connection_info_1 "IP_address" 882 | else 883 | echo -e "${Error} 请输入正确的数字(1-2)" && exit 1 884 | fi 885 | } 886 | View_user_connection_info_1(){ 887 | format=$1 888 | if [[ ${release} = "centos" ]]; then 889 | cat /etc/redhat-release |grep 7\..*|grep -i centos>/dev/null 890 | if [[ $? = 0 ]]; then 891 | debian_View_user_connection_info "$format" 892 | else 893 | centos_View_user_connection_info "$format" 894 | fi 895 | else 896 | debian_View_user_connection_info "$format" 897 | fi 898 | } 899 | get_IP_address(){ 900 | #echo "user_IP_1=${user_IP_1}" 901 | if [[ ! -z ${user_IP_1} ]]; then 902 | #echo "user_IP_total=${user_IP_total}" 903 | for((integer_1 = ${user_IP_total}; integer_1 >= 1; integer_1--)) 904 | do 905 | IP=`echo "${user_IP_1}" |sed -n "$integer_1"p` 906 | #echo "IP=${IP}" 907 | IP_address=`wget -qO- -t1 -T2 http://freeapi.ipip.net/${IP}|sed 's/\"//g;s/,//g;s/\[//g;s/\]//g'` 908 | #echo "IP_address=${IP_address}" 909 | user_IP="${user_IP}\n${IP}(${IP_address})" 910 | #echo "user_IP=${user_IP}" 911 | sleep 1s 912 | done 913 | fi 914 | } 915 | # 修改 用户配置 916 | Modify_Config(){ 917 | SSR_installation_status 918 | if [[ -z "${now_mode}" ]]; then 919 | echo && echo -e "当前模式: 单端口,你要做什么? 920 | ${Green_font_prefix}1.${Font_color_suffix} 修改 用户端口 921 | ${Green_font_prefix}2.${Font_color_suffix} 修改 用户密码 922 | ${Green_font_prefix}3.${Font_color_suffix} 修改 加密方式 923 | ${Green_font_prefix}4.${Font_color_suffix} 修改 协议插件 924 | ${Green_font_prefix}5.${Font_color_suffix} 修改 混淆插件 925 | ${Green_font_prefix}6.${Font_color_suffix} 修改 设备数限制 926 | ${Green_font_prefix}7.${Font_color_suffix} 修改 单线程限速 927 | ${Green_font_prefix}8.${Font_color_suffix} 修改 端口总限速 928 | ${Green_font_prefix}9.${Font_color_suffix} 修改 全部配置" && echo 929 | stty erase '^H' && read -p "(默认: 取消):" ssr_modify 930 | [[ -z "${ssr_modify}" ]] && echo "已取消..." && exit 1 931 | Get_User 932 | if [[ ${ssr_modify} == "1" ]]; then 933 | Set_config_port 934 | Modify_config_port 935 | Add_iptables 936 | Del_iptables 937 | Save_iptables 938 | elif [[ ${ssr_modify} == "2" ]]; then 939 | Set_config_password 940 | Modify_config_password 941 | elif [[ ${ssr_modify} == "3" ]]; then 942 | Set_config_method 943 | Modify_config_method 944 | elif [[ ${ssr_modify} == "4" ]]; then 945 | Set_config_protocol 946 | Modify_config_protocol 947 | elif [[ ${ssr_modify} == "5" ]]; then 948 | Set_config_obfs 949 | Modify_config_obfs 950 | elif [[ ${ssr_modify} == "6" ]]; then 951 | Set_config_protocol_param 952 | Modify_config_protocol_param 953 | elif [[ ${ssr_modify} == "7" ]]; then 954 | Set_config_speed_limit_per_con 955 | Modify_config_speed_limit_per_con 956 | elif [[ ${ssr_modify} == "8" ]]; then 957 | Set_config_speed_limit_per_user 958 | Modify_config_speed_limit_per_user 959 | elif [[ ${ssr_modify} == "9" ]]; then 960 | Set_config_all 961 | Modify_config_all 962 | else 963 | echo -e "${Error} 请输入正确的数字(1-9)" && exit 1 964 | fi 965 | else 966 | echo && echo -e "当前模式: 多端口,你要做什么? 967 | ${Green_font_prefix}1.${Font_color_suffix} 添加 用户配置 968 | ${Green_font_prefix}2.${Font_color_suffix} 删除 用户配置 969 | ${Green_font_prefix}3.${Font_color_suffix} 修改 用户配置 970 | —————————— 971 | ${Green_font_prefix}4.${Font_color_suffix} 修改 加密方式 972 | ${Green_font_prefix}5.${Font_color_suffix} 修改 协议插件 973 | ${Green_font_prefix}6.${Font_color_suffix} 修改 混淆插件 974 | ${Green_font_prefix}7.${Font_color_suffix} 修改 设备数限制 975 | ${Green_font_prefix}8.${Font_color_suffix} 修改 单线程限速 976 | ${Green_font_prefix}9.${Font_color_suffix} 修改 端口总限速 977 | ${Green_font_prefix}10.${Font_color_suffix} 修改 全部配置" && echo 978 | stty erase '^H' && read -p "(默认: 取消):" ssr_modify 979 | [[ -z "${ssr_modify}" ]] && echo "已取消..." && exit 1 980 | Get_User 981 | if [[ ${ssr_modify} == "1" ]]; then 982 | Add_multi_port_user 983 | elif [[ ${ssr_modify} == "2" ]]; then 984 | Del_multi_port_user 985 | elif [[ ${ssr_modify} == "3" ]]; then 986 | Modify_multi_port_user 987 | elif [[ ${ssr_modify} == "4" ]]; then 988 | Set_config_method 989 | Modify_config_method 990 | elif [[ ${ssr_modify} == "5" ]]; then 991 | Set_config_protocol 992 | Modify_config_protocol 993 | elif [[ ${ssr_modify} == "6" ]]; then 994 | Set_config_obfs 995 | Modify_config_obfs 996 | elif [[ ${ssr_modify} == "7" ]]; then 997 | Set_config_protocol_param 998 | Modify_config_protocol_param 999 | elif [[ ${ssr_modify} == "8" ]]; then 1000 | Set_config_speed_limit_per_con 1001 | Modify_config_speed_limit_per_con 1002 | elif [[ ${ssr_modify} == "9" ]]; then 1003 | Set_config_speed_limit_per_user 1004 | Modify_config_speed_limit_per_user 1005 | elif [[ ${ssr_modify} == "10" ]]; then 1006 | Set_config_method 1007 | Set_config_protocol 1008 | Set_config_obfs 1009 | Set_config_protocol_param 1010 | Set_config_speed_limit_per_con 1011 | Set_config_speed_limit_per_user 1012 | Modify_config_method 1013 | Modify_config_protocol 1014 | Modify_config_obfs 1015 | Modify_config_protocol_param 1016 | Modify_config_speed_limit_per_con 1017 | Modify_config_speed_limit_per_user 1018 | else 1019 | echo -e "${Error} 请输入正确的数字(1-9)" && exit 1 1020 | fi 1021 | fi 1022 | Restart_SSR 1023 | } 1024 | # 显示 多端口用户配置 1025 | List_multi_port_user(){ 1026 | user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l` 1027 | [[ ${user_total} = "0" ]] && echo -e "${Error} 没有发现 多端口用户,请检查 !" && exit 1 1028 | user_list_all="" 1029 | for((integer = ${user_total}; integer >= 1; integer--)) 1030 | do 1031 | user_port=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 1032 | user_password=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 1033 | user_list_all=${user_list_all}"端口: "${user_port}" 密码: "${user_password}"\n" 1034 | done 1035 | echo && echo -e "用户总数 ${Green_font_prefix}"${user_total}"${Font_color_suffix}" 1036 | echo -e ${user_list_all} 1037 | } 1038 | # 添加 多端口用户配置 1039 | Add_multi_port_user(){ 1040 | Set_config_port 1041 | Set_config_password 1042 | sed -i "8 i \" \"${ssr_port}\":\"${ssr_password}\"," ${config_user_file} 1043 | sed -i "8s/^\"//" ${config_user_file} 1044 | Add_iptables 1045 | Save_iptables 1046 | echo -e "${Info} 多端口用户添加完成 ${Green_font_prefix}[端口: ${ssr_port} , 密码: ${ssr_password}]${Font_color_suffix} " 1047 | } 1048 | # 修改 多端口用户配置 1049 | Modify_multi_port_user(){ 1050 | List_multi_port_user 1051 | echo && echo -e "请输入要修改的用户端口" 1052 | stty erase '^H' && read -p "(默认: 取消):" modify_user_port 1053 | [[ -z "${modify_user_port}" ]] && echo -e "已取消..." && exit 1 1054 | del_user=`cat ${config_user_file}|grep '"'"${modify_user_port}"'"'` 1055 | if [[ ! -z "${del_user}" ]]; then 1056 | port="${modify_user_port}" 1057 | password=`echo -e ${del_user}|awk -F ":" '{print $NF}'|sed -r 's/.*\"(.+)\".*/\1/'` 1058 | Set_config_port 1059 | Set_config_password 1060 | sed -i 's/"'$(echo ${port})'":"'$(echo ${password})'"/"'$(echo ${ssr_port})'":"'$(echo ${ssr_password})'"/g' ${config_user_file} 1061 | Del_iptables 1062 | Add_iptables 1063 | Save_iptables 1064 | echo -e "${Inof} 多端口用户修改完成 ${Green_font_prefix}[旧: ${modify_user_port} ${password} , 新: ${ssr_port} ${ssr_password}]${Font_color_suffix} " 1065 | else 1066 | echo -e "${Error} 请输入正确的端口 !" && exit 1 1067 | fi 1068 | } 1069 | # 删除 多端口用户配置 1070 | Del_multi_port_user(){ 1071 | List_multi_port_user 1072 | user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l` 1073 | [[ "${user_total}" = "1" ]] && echo -e "${Error} 多端口用户仅剩 1个,不能删除 !" && exit 1 1074 | echo -e "请输入要删除的用户端口" 1075 | stty erase '^H' && read -p "(默认: 取消):" del_user_port 1076 | [[ -z "${del_user_port}" ]] && echo -e "已取消..." && exit 1 1077 | del_user=`cat ${config_user_file}|grep '"'"${del_user_port}"'"'` 1078 | if [[ ! -z ${del_user} ]]; then 1079 | port=${del_user_port} 1080 | Del_iptables 1081 | Save_iptables 1082 | del_user_determine=`echo ${del_user:((${#del_user} - 1))}` 1083 | if [[ ${del_user_determine} != "," ]]; then 1084 | del_user_num=$(sed -n -e "/${port}/=" ${config_user_file}) 1085 | del_user_num=$(expr $del_user_num - 1) 1086 | sed -i "${del_user_num}s/,//g" ${config_user_file} 1087 | fi 1088 | sed -i "/${port}/d" ${config_user_file} 1089 | echo -e "${Info} 多端口用户删除完成 ${Green_font_prefix} ${del_user_port} ${Font_color_suffix} " 1090 | else 1091 | echo "${Error} 请输入正确的端口 !" && exit 1 1092 | fi 1093 | } 1094 | # 手动修改 用户配置 1095 | Manually_Modify_Config(){ 1096 | SSR_installation_status 1097 | port=`${jq_file} '.server_port' ${config_user_file}` 1098 | vi ${config_user_file} 1099 | if [[ -z "${now_mode}" ]]; then 1100 | ssr_port=`${jq_file} '.server_port' ${config_user_file}` 1101 | Del_iptables 1102 | Add_iptables 1103 | fi 1104 | Restart_SSR 1105 | } 1106 | # 切换端口模式 1107 | Port_mode_switching(){ 1108 | SSR_installation_status 1109 | if [[ -z "${now_mode}" ]]; then 1110 | echo && echo -e " 当前模式: ${Green_font_prefix}单端口${Font_color_suffix}" && echo 1111 | echo -e "确定要切换为 多端口模式?[y/N]" 1112 | stty erase '^H' && read -p "(默认: n):" mode_yn 1113 | [[ -z ${mode_yn} ]] && mode_yn="n" 1114 | if [[ ${mode_yn} == [Yy] ]]; then 1115 | port=`${jq_file} '.server_port' ${config_user_file}` 1116 | Set_config_all 1117 | Write_configuration_many 1118 | Del_iptables 1119 | Add_iptables 1120 | Save_iptables 1121 | Restart_SSR 1122 | else 1123 | echo && echo " 已取消..." && echo 1124 | fi 1125 | else 1126 | echo && echo -e " 当前模式: ${Green_font_prefix}多端口${Font_color_suffix}" && echo 1127 | echo -e "确定要切换为 单端口模式?[y/N]" 1128 | stty erase '^H' && read -p "(默认: n):" mode_yn 1129 | [[ -z ${mode_yn} ]] && mode_yn="n" 1130 | if [[ ${mode_yn} == [Yy] ]]; then 1131 | user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l` 1132 | for((integer = 1; integer <= ${user_total}; integer++)) 1133 | do 1134 | port=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'` 1135 | Del_iptables 1136 | done 1137 | Set_config_all 1138 | Write_configuration 1139 | Add_iptables 1140 | Restart_SSR 1141 | else 1142 | echo && echo " 已取消..." && echo 1143 | fi 1144 | fi 1145 | } 1146 | Start_SSR(){ 1147 | SSR_installation_status 1148 | check_pid 1149 | [[ ! -z ${PID} ]] && echo -e "${Error} ShadowsocksR 正在运行 !" && exit 1 1150 | /etc/init.d/ssr start 1151 | check_pid 1152 | [[ ! -z ${PID} ]] && View_User 1153 | } 1154 | Stop_SSR(){ 1155 | SSR_installation_status 1156 | check_pid 1157 | [[ -z ${PID} ]] && echo -e "${Error} ShadowsocksR 未运行 !" && exit 1 1158 | /etc/init.d/ssr stop 1159 | } 1160 | Restart_SSR(){ 1161 | SSR_installation_status 1162 | check_pid 1163 | [[ ! -z ${PID} ]] && /etc/init.d/ssr stop 1164 | /etc/init.d/ssr start 1165 | check_pid 1166 | [[ ! -z ${PID} ]] && View_User 1167 | } 1168 | View_Log(){ 1169 | SSR_installation_status 1170 | [[ ! -e ${ssr_log_file} ]] && echo -e "${Error} ShadowsocksR日志文件不存在 !" && exit 1 1171 | echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo 1172 | tail -f ${ssr_log_file} 1173 | } 1174 | # 锐速 1175 | Configure_Server_Speeder(){ 1176 | echo && echo -e "你要做什么? 1177 | ${Green_font_prefix}1.${Font_color_suffix} 安装 锐速 1178 | ${Green_font_prefix}2.${Font_color_suffix} 卸载 锐速 1179 | ———————— 1180 | ${Green_font_prefix}3.${Font_color_suffix} 启动 锐速 1181 | ${Green_font_prefix}4.${Font_color_suffix} 停止 锐速 1182 | ${Green_font_prefix}5.${Font_color_suffix} 重启 锐速 1183 | ${Green_font_prefix}6.${Font_color_suffix} 查看 锐速 状态 1184 | 1185 | 注意: 锐速和LotServer不能同时安装/启动!" && echo 1186 | stty erase '^H' && read -p "(默认: 取消):" server_speeder_num 1187 | [[ -z "${server_speeder_num}" ]] && echo "已取消..." && exit 1 1188 | if [[ ${server_speeder_num} == "1" ]]; then 1189 | Install_ServerSpeeder 1190 | elif [[ ${server_speeder_num} == "2" ]]; then 1191 | Server_Speeder_installation_status 1192 | Uninstall_ServerSpeeder 1193 | elif [[ ${server_speeder_num} == "3" ]]; then 1194 | Server_Speeder_installation_status 1195 | ${Server_Speeder_file} start 1196 | ${Server_Speeder_file} status 1197 | elif [[ ${server_speeder_num} == "4" ]]; then 1198 | Server_Speeder_installation_status 1199 | ${Server_Speeder_file} stop 1200 | elif [[ ${server_speeder_num} == "5" ]]; then 1201 | Server_Speeder_installation_status 1202 | ${Server_Speeder_file} restart 1203 | ${Server_Speeder_file} status 1204 | elif [[ ${server_speeder_num} == "6" ]]; then 1205 | Server_Speeder_installation_status 1206 | ${Server_Speeder_file} status 1207 | else 1208 | echo -e "${Error} 请输入正确的数字(1-6)" && exit 1 1209 | fi 1210 | } 1211 | Install_ServerSpeeder(){ 1212 | [[ -e ${Server_Speeder_file} ]] && echo -e "${Error} 锐速(Server Speeder) 已安装 !" && exit 1 1213 | cd /root 1214 | #借用91yun.rog的开心版锐速 1215 | wget -N --no-check-certificate https://raw.githubusercontent.com/91yun/serverspeeder/master/serverspeeder.sh 1216 | [[ ! -e "serverspeeder.sh" ]] && echo -e "${Error} 锐速安装脚本下载失败 !" && exit 1 1217 | bash serverspeeder.sh 1218 | sleep 2s 1219 | PID=`ps -ef |grep -v grep |grep "serverspeeder" |awk '{print $2}'` 1220 | if [[ ! -z ${PID} ]]; then 1221 | rm -rf /root/serverspeeder.sh 1222 | rm -rf /root/91yunserverspeeder 1223 | rm -rf /root/91yunserverspeeder.tar.gz 1224 | echo -e "${Info} 锐速(Server Speeder) 安装完成 !" && exit 1 1225 | else 1226 | echo -e "${Error} 锐速(Server Speeder) 安装失败 !" && exit 1 1227 | fi 1228 | } 1229 | Uninstall_ServerSpeeder(){ 1230 | echo "确定要卸载 锐速(Server Speeder)?[y/N]" && echo 1231 | stty erase '^H' && read -p "(默认: n):" unyn 1232 | [[ -z ${unyn} ]] && echo && echo "已取消..." && exit 1 1233 | if [[ ${unyn} == [Yy] ]]; then 1234 | chattr -i /serverspeeder/etc/apx* 1235 | /serverspeeder/bin/serverSpeeder.sh uninstall -f 1236 | echo && echo "锐速(Server Speeder) 卸载完成 !" && echo 1237 | fi 1238 | } 1239 | # LotServer 1240 | Configure_LotServer(){ 1241 | echo && echo -e "你要做什么? 1242 | ${Green_font_prefix}1.${Font_color_suffix} 安装 LotServer 1243 | ${Green_font_prefix}2.${Font_color_suffix} 卸载 LotServer 1244 | ———————— 1245 | ${Green_font_prefix}3.${Font_color_suffix} 启动 LotServer 1246 | ${Green_font_prefix}4.${Font_color_suffix} 停止 LotServer 1247 | ${Green_font_prefix}5.${Font_color_suffix} 重启 LotServer 1248 | ${Green_font_prefix}6.${Font_color_suffix} 查看 LotServer 状态 1249 | 1250 | 注意: 锐速和LotServer不能同时安装/启动!" && echo 1251 | stty erase '^H' && read -p "(默认: 取消):" lotserver_num 1252 | [[ -z "${lotserver_num}" ]] && echo "已取消..." && exit 1 1253 | if [[ ${lotserver_num} == "1" ]]; then 1254 | Install_LotServer 1255 | elif [[ ${lotserver_num} == "2" ]]; then 1256 | LotServer_installation_status 1257 | Uninstall_LotServer 1258 | elif [[ ${lotserver_num} == "3" ]]; then 1259 | LotServer_installation_status 1260 | ${LotServer_file} start 1261 | ${LotServer_file} status 1262 | elif [[ ${lotserver_num} == "4" ]]; then 1263 | LotServer_installation_status 1264 | ${LotServer_file} stop 1265 | elif [[ ${lotserver_num} == "5" ]]; then 1266 | LotServer_installation_status 1267 | ${LotServer_file} restart 1268 | ${LotServer_file} status 1269 | elif [[ ${lotserver_num} == "6" ]]; then 1270 | LotServer_installation_status 1271 | ${LotServer_file} status 1272 | else 1273 | echo -e "${Error} 请输入正确的数字(1-6)" && exit 1 1274 | fi 1275 | } 1276 | Install_LotServer(){ 1277 | [[ -e ${LotServer_file} ]] && echo -e "${Error} LotServer 已安装 !" && exit 1 1278 | #Github: https://github.com/0oVicero0/serverSpeeder_Install 1279 | wget --no-check-certificate -qO /tmp/appex.sh "https://raw.githubusercontent.com/0oVicero0/serverSpeeder_Install/master/appex.sh" 1280 | [[ ! -e "/tmp/appex.sh" ]] && echo -e "${Error} LotServer 安装脚本下载失败 !" && exit 1 1281 | bash /tmp/appex.sh 'install' 1282 | sleep 2s 1283 | PID=`ps -ef |grep -v grep |grep "appex" |awk '{print $2}'` 1284 | if [[ ! -z ${PID} ]]; then 1285 | echo -e "${Info} LotServer 安装完成 !" && exit 1 1286 | else 1287 | echo -e "${Error} LotServer 安装失败 !" && exit 1 1288 | fi 1289 | } 1290 | Uninstall_LotServer(){ 1291 | echo "确定要卸载 LotServer?[y/N]" && echo 1292 | stty erase '^H' && read -p "(默认: n):" unyn 1293 | [[ -z ${unyn} ]] && echo && echo "已取消..." && exit 1 1294 | if [[ ${unyn} == [Yy] ]]; then 1295 | wget --no-check-certificate -qO /tmp/appex.sh "https://raw.githubusercontent.com/0oVicero0/serverSpeeder_Install/master/appex.sh" && bash /tmp/appex.sh 'uninstall' 1296 | echo && echo "LotServer 卸载完成 !" && echo 1297 | fi 1298 | } 1299 | # BBR 1300 | Configure_BBR(){ 1301 | echo && echo -e " 你要做什么? 1302 | 1303 | ${Green_font_prefix}1.${Font_color_suffix} 安装 BBR 1304 | ———————— 1305 | ${Green_font_prefix}2.${Font_color_suffix} 启动 BBR 1306 | ${Green_font_prefix}3.${Font_color_suffix} 停止 BBR 1307 | ${Green_font_prefix}4.${Font_color_suffix} 查看 BBR 状态" && echo 1308 | echo -e "${Green_font_prefix} [安装前 请注意] ${Font_color_suffix} 1309 | 1. 安装开启BBR,需要更换内核,存在更换失败等风险(重启后无法开机) 1310 | 2. 本脚本仅支持 Debian / Ubuntu 系统更换内核,OpenVZ和Docker 不支持更换内核 1311 | 3. Debian 更换内核过程中会提示 [ 是否终止卸载内核 ] ,请选择 ${Green_font_prefix} NO ${Font_color_suffix}" && echo 1312 | stty erase '^H' && read -p "(默认: 取消):" bbr_num 1313 | [[ -z "${bbr_num}" ]] && echo "已取消..." && exit 1 1314 | if [[ ${bbr_num} == "1" ]]; then 1315 | Install_BBR 1316 | elif [[ ${bbr_num} == "2" ]]; then 1317 | Start_BBR 1318 | elif [[ ${bbr_num} == "3" ]]; then 1319 | Stop_BBR 1320 | elif [[ ${bbr_num} == "4" ]]; then 1321 | Status_BBR 1322 | else 1323 | echo -e "${Error} 请输入正确的数字(1-4)" && exit 1 1324 | fi 1325 | } 1326 | Install_BBR(){ 1327 | [[ ${release} = "centos" ]] && echo -e "${Error} 本脚本不支持 CentOS系统安装 BBR !" && exit 1 1328 | BBR_installation_status 1329 | bash "${BBR_file}" 1330 | } 1331 | Start_BBR(){ 1332 | BBR_installation_status 1333 | bash "${BBR_file}" start 1334 | } 1335 | Stop_BBR(){ 1336 | BBR_installation_status 1337 | bash "${BBR_file}" stop 1338 | } 1339 | Status_BBR(){ 1340 | BBR_installation_status 1341 | bash "${BBR_file}" status 1342 | } 1343 | # 其他功能 1344 | Other_functions(){ 1345 | echo && echo -e " 你要做什么? 1346 | 1347 | ${Green_font_prefix}1.${Font_color_suffix} 配置 BBR 1348 | ${Green_font_prefix}2.${Font_color_suffix} 配置 锐速(ServerSpeeder) 1349 | ${Green_font_prefix}3.${Font_color_suffix} 配置 LotServer(锐速母公司) 1350 | 注意: 锐速/LotServer/BBR 不支持 OpenVZ! 1351 | 注意: 锐速/LotServer/BBR 不能共存! 1352 | ———————————— 1353 | ${Green_font_prefix}4.${Font_color_suffix} 一键封禁 BT/PT/SPAM (iptables) 1354 | ${Green_font_prefix}5.${Font_color_suffix} 一键解封 BT/PT/SPAM (iptables) 1355 | ${Green_font_prefix}6.${Font_color_suffix} 切换 ShadowsocksR日志输出模式 1356 | ——说明:SSR默认只输出错误日志,此项可切换为输出详细的访问日志" && echo 1357 | stty erase '^H' && read -p "(默认: 取消):" other_num 1358 | [[ -z "${other_num}" ]] && echo "已取消..." && exit 1 1359 | if [[ ${other_num} == "1" ]]; then 1360 | Configure_BBR 1361 | elif [[ ${other_num} == "2" ]]; then 1362 | Configure_Server_Speeder 1363 | elif [[ ${other_num} == "3" ]]; then 1364 | Configure_LotServer 1365 | elif [[ ${other_num} == "4" ]]; then 1366 | BanBTPTSPAM 1367 | elif [[ ${other_num} == "5" ]]; then 1368 | UnBanBTPTSPAM 1369 | elif [[ ${other_num} == "6" ]]; then 1370 | Set_config_connect_verbose_info 1371 | else 1372 | echo -e "${Error} 请输入正确的数字 [1-6]" && exit 1 1373 | fi 1374 | } 1375 | # 封禁 BT PT SPAM 1376 | BanBTPTSPAM(){ 1377 | wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ban_iptables.sh && chmod +x ban_iptables.sh && bash ban_iptables.sh banall 1378 | rm -rf ban_iptables.sh 1379 | } 1380 | # 解封 BT PT SPAM 1381 | UnBanBTPTSPAM(){ 1382 | wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ban_iptables.sh && chmod +x ban_iptables.sh && bash ban_iptables.sh unbanall 1383 | rm -rf ban_iptables.sh 1384 | } 1385 | Set_config_connect_verbose_info(){ 1386 | SSR_installation_status 1387 | Get_User 1388 | if [[ ${connect_verbose_info} = "0" ]]; then 1389 | echo && echo -e "当前日志模式: ${Green_font_prefix}简单模式(只输出错误日志)${Font_color_suffix}" && echo 1390 | echo -e "确定要切换为 ${Green_font_prefix}详细模式(输出详细连接日志+错误日志)${Font_color_suffix}?[y/N]" 1391 | stty erase '^H' && read -p "(默认: n):" connect_verbose_info_ny 1392 | [[ -z "${connect_verbose_info_ny}" ]] && connect_verbose_info_ny="n" 1393 | if [[ ${connect_verbose_info_ny} == [Yy] ]]; then 1394 | ssr_connect_verbose_info="1" 1395 | Modify_config_connect_verbose_info 1396 | Restart_SSR 1397 | else 1398 | echo && echo " 已取消..." && echo 1399 | fi 1400 | else 1401 | echo && echo -e "当前日志模式: ${Green_font_prefix}详细模式(输出详细连接日志+错误日志)${Font_color_suffix}" && echo 1402 | echo -e "确定要切换为 ${Green_font_prefix}简单模式(只输出错误日志)${Font_color_suffix}?[y/N]" 1403 | stty erase '^H' && read -p "(默认: n):" connect_verbose_info_ny 1404 | [[ -z "${connect_verbose_info_ny}" ]] && connect_verbose_info_ny="n" 1405 | if [[ ${connect_verbose_info_ny} == [Yy] ]]; then 1406 | ssr_connect_verbose_info="0" 1407 | Modify_config_connect_verbose_info 1408 | Restart_SSR 1409 | else 1410 | echo && echo " 已取消..." && echo 1411 | fi 1412 | fi 1413 | } 1414 | Update_Shell(){ 1415 | echo -e "当前版本为 [ ${sh_ver} ],开始检测最新版本..." 1416 | sh_new_ver=$(wget --no-check-certificate -qO- "https://softs.fun/Bash/ssr.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1) && sh_new_type="softs" 1417 | [[ -z ${sh_new_ver} ]] && sh_new_ver=$(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1) && sh_new_type="github" 1418 | [[ -z ${sh_new_ver} ]] && echo -e "${Error} 检测最新版本失败 !" && exit 0 1419 | if [[ ${sh_new_ver} != ${sh_ver} ]]; then 1420 | echo -e "发现新版本[ ${sh_new_ver} ],是否更新?[Y/n]" 1421 | stty erase '^H' && read -p "(默认: y):" yn 1422 | [[ -z "${yn}" ]] && yn="y" 1423 | if [[ ${yn} == [Yy] ]]; then 1424 | if [[ $sh_new_type == "softs" ]]; then 1425 | wget -N --no-check-certificate https://softs.fun/Bash/ssr.sh && chmod +x ssr.sh 1426 | else 1427 | wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh && chmod +x ssr.sh 1428 | fi 1429 | echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !" 1430 | else 1431 | echo && echo " 已取消..." && echo 1432 | fi 1433 | else 1434 | echo -e "当前已是最新版本[ ${sh_new_ver} ] !" 1435 | fi 1436 | } 1437 | # 显示 菜单状态 1438 | menu_status(){ 1439 | if [[ -e ${config_user_file} ]]; then 1440 | check_pid 1441 | if [[ ! -z "${PID}" ]]; then 1442 | echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" 1443 | else 1444 | echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" 1445 | fi 1446 | now_mode=$(cat "${config_user_file}"|grep '"port_password"') 1447 | if [[ -z "${now_mode}" ]]; then 1448 | echo -e " 当前模式: ${Green_font_prefix}单端口${Font_color_suffix}" 1449 | else 1450 | echo -e " 当前模式: ${Green_font_prefix}多端口${Font_color_suffix}" 1451 | fi 1452 | else 1453 | echo -e " 当前状态: ${Red_font_prefix}未安装${Font_color_suffix}" 1454 | fi 1455 | } 1456 | check_sys 1457 | [[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1 1458 | echo -e " ShadowsocksR 一键管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} 1459 | ---- xnmll | github/xnmll ---- 1460 | 1461 | ${Green_font_prefix}1.${Font_color_suffix} 安装 ShadowsocksR 1462 | ${Green_font_prefix}2.${Font_color_suffix} 更新 ShadowsocksR 1463 | ${Green_font_prefix}3.${Font_color_suffix} 卸载 ShadowsocksR 1464 | ${Green_font_prefix}4.${Font_color_suffix} 安装 libsodium(chacha20) 1465 | ———————————— 1466 | ${Green_font_prefix}5.${Font_color_suffix} 查看 账号信息 1467 | ${Green_font_prefix}6.${Font_color_suffix} 显示 连接信息 1468 | ${Green_font_prefix}7.${Font_color_suffix} 设置 用户配置 1469 | ${Green_font_prefix}8.${Font_color_suffix} 手动 修改配置 1470 | ${Green_font_prefix}9.${Font_color_suffix} 切换 端口模式 1471 | ———————————— 1472 | ${Green_font_prefix}10.${Font_color_suffix} 启动 ShadowsocksR 1473 | ${Green_font_prefix}11.${Font_color_suffix} 停止 ShadowsocksR 1474 | ${Green_font_prefix}12.${Font_color_suffix} 重启 ShadowsocksR 1475 | ${Green_font_prefix}13.${Font_color_suffix} 查看 ShadowsocksR 日志 1476 | ———————————— 1477 | ${Green_font_prefix}14.${Font_color_suffix} 其他功能 1478 | ${Green_font_prefix}15.${Font_color_suffix} 升级脚本 1479 | " 1480 | menu_status 1481 | echo && stty erase '^H' && read -p "请输入数字 [1-15]:" num 1482 | case "$num" in 1483 | 1) 1484 | Install_SSR 1485 | ;; 1486 | 2) 1487 | Update_SSR 1488 | ;; 1489 | 3) 1490 | Uninstall_SSR 1491 | ;; 1492 | 4) 1493 | Install_Libsodium 1494 | ;; 1495 | 5) 1496 | View_User 1497 | ;; 1498 | 6) 1499 | View_user_connection_info 1500 | ;; 1501 | 7) 1502 | Modify_Config 1503 | ;; 1504 | 8) 1505 | Manually_Modify_Config 1506 | ;; 1507 | 9) 1508 | Port_mode_switching 1509 | ;; 1510 | 10) 1511 | Start_SSR 1512 | ;; 1513 | 11) 1514 | Stop_SSR 1515 | ;; 1516 | 12) 1517 | Restart_SSR 1518 | ;; 1519 | 13) 1520 | View_Log 1521 | ;; 1522 | 14) 1523 | Other_functions 1524 | ;; 1525 | 15) 1526 | Update_Shell 1527 | ;; 1528 | *) 1529 | echo -e "${Error} 请输入正确的数字 [1-15]" 1530 | ;; 1531 | esac --------------------------------------------------------------------------------