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