Guest User

temp

a guest
Oct 29th, 2018
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 83.54 KB | None | 0 0
  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/Ubuntu 14.04+
  7. #   Description: Install the ShadowsocksR server
  8. #   Version: 1.2.8
  9. #   Author: pt3e
  10. #   Blog: http://www.pt3e.com/vpsss/
  11. #=================================================
  12.  
  13. #ssr_pid="/var/run/shadowsocks.pid"
  14. ssr_file="/etc/shadowsocksr"
  15. ssr_ss_file="/etc/shadowsocksr/shadowsocks"
  16. config_file="/etc/shadowsocksr/config.json"
  17. config_user_file="/etc/shadowsocksr/user-config.json"
  18. Libsodiumr_file="/root/libsodium"
  19. Libsodiumr_ver="1.0.11"
  20. auto_restart_cron="auto_restart_cron.sh"
  21. Green_font_prefix="\033[32m"
  22. Red_font_prefix="\033[31m"
  23. Green_background_prefix="\033[42;37m"
  24. Red_background_prefix="\033[41;37m"
  25. Font_color_suffix="\033[0m"
  26.  
  27. Separator_1="——————————————————————————————"
  28. # 脚本文字变量(Translation)
  29. Language(){
  30.     if [[ ! -e "${PWD}/lang_en" ]]; then
  31.         Word_default="默认"
  32.         Word_unlimited="无限"
  33.         Word_user="用户"
  34.         Word_port="端口"
  35.         Word_pass="密码"
  36.         Word_method="加密"
  37.         Word_protocol="协议"
  38.         Word_obfs="混淆"
  39.         Word_ss_like=" SS    链接"
  40.         Word_ss_qr_code=" SS  二维码"
  41.         Word_ssr_like=" SSR   链接"
  42.         Word_ssr_qr_code=" SSR 二维码"
  43.         Word_single_port="单端口"
  44.         Word_multi_port="多端口"
  45.         Word_current_mode="当前模式"
  46.         Word_current_status="当前状态"
  47.         Word_number_of_devices="设备数"
  48.         Word_number_of_devices_limit="设备数限制"
  49.         Word_single_threaded_speed_limit="单线程限速"
  50.         Word_port_total_speed_limit="端口总限速"
  51.         Word_the_installation_is_complete="安装完成"
  52.         Word_installation_failed="安装失败"
  53.         Word_uninstall_is_complete="卸载完成"
  54.         Word_uninstall_cancelled="卸载已取消..."
  55.         Word_canceled="已取消..."
  56.         Word_cancel="取消"
  57.         Word_startup_failed="启动失败"
  58.         Word_stop_failing="停止失败"
  59.         Word_stopped="已停止"
  60.         Word_installed="已安装"
  61.         Word_not_installed="未安装"
  62.         Word_has_started="已启动"
  63.         Word_have_not_started="未启动"
  64.         Word_running="正在运行"
  65.         Word_not_running="没有运行"
  66.         Word_info="信息"
  67.         Word_error="错误"
  68.         Word_Prompt="提示"
  69.         Word_timing_interval="定时间隔"
  70.         Word_and="并"
  71.         Word_but="但"
  72.         Word_serverspeeder="锐速"
  73.    
  74.         Info_switch_single_port_mode="你确定要切换模式为 ${Word_single_port} ?[y/N]"
  75.         Info_switch_multi_port_mode="你确定要切换模式为 ${Word_multi_port} ?[y/N]"
  76.         Info_input_port="请输入ShadowsocksR ${Word_port} [1-65535]"
  77.         Info_input_pass="请输入ShadowsocksR ${Word_pass}"
  78.         Info_input_method="请输入数字 来选择ShadowsocksR ${Word_method}"
  79.         Info_input_protocol="请输入数字 来选择ShadowsocksR ${Word_protocol}( auth_aes128_* 以后的协议不再支持 兼容原版 )"
  80.         Info_input_number_of_devices="请输入 ShadowsocksR账号欲限制的设备数 (${Green_font_prefix} auth_* 系列协议 不兼容原版才有效 ${Font_color_suffix})"
  81.         Prompt_number_of_devices="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}该设备数限制,指的是每个端口同一时间能链接的客户端数量(多端口模式,每个端口都是独立计算)。"
  82.         Info_input_obfs="请输入数字 来选择ShadowsocksR ${Word_obfs}"
  83.         Info_protocol_compatible="是否设置 协议 兼容原版 ( _compatible )? [Y/n] :"
  84.         Info_obfs_compatible="是否设置 混淆 兼容原版 ( _compatible )? [Y/n] :"
  85.         Info_protocol_obfs_compatible="是否设置 协议/混淆 兼容原版 ( _compatible )? [Y/n] :"
  86.         Info_input_single_threaded_speed_limit="请输入 你要设置的每个端口 单线程 限速上限(单位:KB/S)"
  87.         Prompt_input_single_threaded_speed_limit="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}这个指的是,每个端口 单线程的限速上限,多线程即无效。"
  88.         Info_total_port_speed_limit="请输入 你要设置的每个端口 总速度 限速上限(单位:KB/S)"
  89.         Prompt_total_port_speed_limit="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}这个指的是,每个端口 总速度 限速上限,单个端口整体限速。"
  90.    
  91.         Info_input_modify_the_type="请输入数字 来选择你要修改的类型 :
  92. 1. 修改 ${Word_port}/${Word_pass}
  93. 2. 修改 ${Word_method}/${Word_protocol}/${Word_obfs}"
  94.         info_input_select_user_id_modified="请选择并输入 你要修改的用户前面的数字 :"
  95.         Info_input_select_user_id_del="请选择并输入 你要删除的用户前面的数字 :"
  96.         Prompt_method_protocol_obfs_modified="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR ${Word_method}/${Word_protocol}/${Word_obfs}已修改!"
  97.  
  98.         Info_jq_installation_is_complete="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} JSON解析器 JQ 安装完成,继续..."
  99.         Info_jq_is_installed="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} 检测到 JSON解析器 JQ 已安装,继续..."
  100.         Info_uninstall_ssr="确定要卸载 ShadowsocksR ? [y/N]"
  101.         Info_uninstall_server_speeder="确定要卸载 ${Word_serverspeeder} ? [y/N]"
  102.         Info_install_bbr="确定要安装 BBR ? [y/n]"
  103.         Info_install_bbr_0="${Green_font_prefix} [安装前 请注意] ${Font_color_suffix}
  104. 1. 安装开启BBR,需要更换内核,存在更换失败等风险(重启后无法开机)
  105. 2. 本脚本仅支持 Debian / Ubuntu 系统更换内核,OpenVZ虚拟化 不支持更换内核 !
  106. 3. Debian 更换内核过程中会提示 [ 是否终止卸载内核 ] ,请选择 ${Green_font_prefix} NO ${Font_color_suffix}
  107. 4. 安装BBR并重启后,需要重新运行脚本开启BBR ${Green_font_prefix} bash bbr.sh start ${Font_color_suffix}"
  108.         Info_input_set_crontab_interval="请输入ShadowsocksR 定时重启的间隔"
  109.         Info_input_set_crontab_interval_default="每天凌晨2点0分 [0 2 * * *]"
  110.         Info_set_crontab_interval_0="${Green_font_prefix} 格式说明 : ${Font_color_suffix}
  111. 格式: ${Green_font_prefix} * * * * * ${Font_color_suffix},分别对应 ${Green_font_prefix} 分钟 小时 日 月 星期 ${Font_color_suffix}
  112. 示例: ${Green_font_prefix} 30 2 * * * ${Font_color_suffix},每天 凌晨2点30分时 重启一次
  113. 示例: ${Green_font_prefix} 30 2 */3 * * ${Font_color_suffix},每隔3天 凌晨2点30分时 重启一次
  114. 示例: ${Green_font_prefix} 30 */2 * * * ${Font_color_suffix},每天 每隔两小时 在30分时 重启一次"
  115.         Info_no_cron_installed="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} 检测到没有安装 corn ,开始安装..."
  116.         Info_input_set_cron="请输入数字 来选择你要做什么
  117. 1. 添加 定时任务
  118. 2. 删除 定时任务
  119. ${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}暂时只能添加设置一个定时重启任务。"
  120.         Info_set_corn_status="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} corn 当前没有定时重启任务 !"
  121.         Info_set_corn_del_success="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} corn 删除定时重启任务成功 !"
  122.         Info_set_corn_add_success="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR 定时重启任务添加成功 !"
  123.         Info_limit_the_number_of_devices="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR 设备数限制 已修改 !"
  124.         Info_port_speed_limit="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR 端口限速 已修改 !"
  125.         Info_switch_language_english="Are you sure you want to switch the script language to English ? [y/n]"
  126.         Info_switch_language_chinese="确定要切换脚本语言为 中文 ? [y/n]"
  127.         Info_switch_language_1="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} Re-run the script to see the language after switching !"
  128.  
  129.         Errpr_input_num_error="${Red_font_prefix}[${Word_error}]${Font_color_suffix} 请输入正确的数字 !"
  130.         Error_not_install_ssr="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 没有发现安装ShadowsocksR,请检查 !"
  131.         Error_ssr_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR已安装 !"
  132.         Error_no_multi_port_users_were_found="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 没有发现 多端口用户,请检查 !"
  133.         Error_jq_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} JSON解析器 JQ 安装失败 !"
  134.         Error_does_not_support_the_system="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 本脚本不支持当前系统 !"
  135.         Error_ssr_download_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 下载失败 !"
  136.         Error_ssr_failed_to_start="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 启动失败 !"
  137.         Error_the_current_mode_is_single_port="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 当前模式为 单端口,请检查 !"
  138.         Error_the_current_mode_is_multi_port="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 当前模式为 多端口,请检查 !"
  139.         Error_multi_port_user_remaining_one="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 当前多端口用户 仅剩一个,无法删除 !"
  140.         Error_startup_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 启动失败, 请检查日志 !"
  141.         Error_no_log_found="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 没有找到日志文件,请检查 !"
  142.         Error_server_speeder_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} 已安装 !"
  143.         Error_server_speeder_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} 安装失败 !"
  144.         Error_server_speeder_not_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} 没有安装,请检查 !"
  145.         Error_cron_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} corn 安装失败 !"
  146.         Error_set_corn_del_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} corn 删除定时重启任务失败 !"
  147.         Error_set_corn_add_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 定时重启任务添加失败 !"
  148.         Error_set_corn_Write_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 定时重启脚本写入失败 !"
  149.         Error_limit_the_number_of_devices_1="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR当前协议为 兼容原版(_compatible),限制设备数无效 !"
  150.         Error_limit_the_number_of_devices_2="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR当前协议为 原版(origin),限制设备数无效 !"
  151.  
  152.         Prompt_method_libsodium="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}chacha20*等加密方式 需要安装 libsodium 支持库,否则会启动失败 !"
  153.         Prompt_any_key="请按任意键继续,如有配置错误请使用 Ctrl+C 退出。"
  154.         Prompt_check_if_the_configuration_is_incorrect="请检查Shadowsocks账号配置是否有误 !"
  155.         Prompt_your_account_configuration="你的ShadowsocksR 账号配置 :"
  156.         Prompt_ssr_status_on="ShadowsocksR 正在运行 !"
  157.         Prompt_ssr_status_off="ShadowsocksR 没有运行 !"
  158.         Prompt_tip="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}
  159. 浏览器中,打开二维码链接,就可以看到二维码图片。
  160. 协议和混淆后面的[ _compatible ],指的是兼容原版Shadowsocks协议/混淆。"
  161.         Prompt_total_number_of_users="当前用户配置总数为:"
  162.         Prompt_total_number_of_ip="当前链接的IP总数为:"
  163.         Prompt_the_currently_connected_ip="当前连接的IP:"
  164.         Prompt_total_number_of_ip_number="IP数量:"
  165.         Prompt_modify_multi_port_user="多端口用户已修改 !"
  166.         Prompt_add_multi_port_user="多端口用户已添加 !"
  167.         Prompt_del_multi_port_user="多端口用户已删除 !"
  168.         Prompt_log="使用 ${Red_font_prefix} Ctrl+C ${Font_color_suffix} 键退出查看日志 !"
  169.         Prompt_switch_language_chinese=" The current scripting language: English"
  170.         Prompt_switch_language_english=" 当前脚本语言为:  中文"
  171.  
  172. #菜单
  173.         Menu_prompt_1="请输入一个数字来选择对应的选项"
  174.         Menu_prompt_2="(请输入数字 0-27): "
  175.         Menu_prompt_3="请选择并输入数字 0-27"
  176.         Menu_options="${Green_font_prefix}  1. ${Font_color_suffix}安装 ShadowsocksR
  177. ${Green_font_prefix}  2. ${Font_color_suffix}安装 libsodium(chacha20)
  178. ${Green_font_prefix}  3. ${Font_color_suffix}显示 单/多端口 账号信息
  179. ${Green_font_prefix}  4. ${Font_color_suffix}显示 单/多端口 连接信息
  180. ${Green_font_prefix}  5. ${Font_color_suffix}修改 单端口用户配置
  181. ${Green_font_prefix}  6. ${Font_color_suffix}手动 修改  用户配置
  182. ${Green_font_prefix}  7. ${Font_color_suffix}卸载 ShadowsocksR
  183. ${Green_font_prefix}  8. ${Font_color_suffix}更新 ShadowsocksR
  184. ——————————————————
  185. ${Green_font_prefix}  9. ${Font_color_suffix}切换 单/多端口 模式
  186. ${Green_font_prefix} 10. ${Font_color_suffix}添加 多端口用户配置
  187. ${Green_font_prefix} 11. ${Font_color_suffix}修改 多端口用户配置
  188. ${Green_font_prefix} 12. ${Font_color_suffix}删除 多端口用户配置
  189. ——————————————————
  190. ${Green_font_prefix} 13. ${Font_color_suffix}启动 ShadowsocksR
  191. ${Green_font_prefix} 14. ${Font_color_suffix}停止 ShadowsocksR
  192. ${Green_font_prefix} 15. ${Font_color_suffix}重启 ShadowsocksR
  193. ${Green_font_prefix} 16. ${Font_color_suffix}查看 ShadowsocksR 状态
  194. ${Green_font_prefix} 17. ${Font_color_suffix}查看 ShadowsocksR 日志
  195. ——————————————————
  196. ${Green_font_prefix} 18. ${Font_color_suffix}安装 ${Word_serverspeeder}
  197. ${Green_font_prefix} 19. ${Font_color_suffix}停止 ${Word_serverspeeder}
  198. ${Green_font_prefix} 20. ${Font_color_suffix}重启 ${Word_serverspeeder}
  199. ${Green_font_prefix} 21. ${Font_color_suffix}查看 ${Word_serverspeeder} 状态
  200. ${Green_font_prefix} 22. ${Font_color_suffix}卸载 ${Word_serverspeeder}
  201. ——————————————————"
  202.         Menu_options_bbr="${Green_font_prefix} 23. ${Font_color_suffix}安装 BBR(需更换内核, 存在风险)"
  203.         Menu_options_other="${Green_font_prefix} 24. ${Font_color_suffix}封禁 BT/PT/垃圾邮件(SPAM)
  204. ${Green_font_prefix} 25. ${Font_color_suffix}设置 ShadowsocksR 定时重启
  205. ${Green_font_prefix} 26. ${Font_color_suffix}设置 ShadowsocksR 设备数限制
  206. ${Green_font_prefix} 27. ${Font_color_suffix}设置 ShadowsocksR 速度限制
  207. ——————————————————
  208. ${Green_font_prefix}  0. ${Font_color_suffix}The scripting language is English
  209. 注意事项: ${Word_serverspeeder}/BBR 不支持 OpenVZ !"
  210.     else
  211.         Word_default="default"
  212.         Word_unlimited="unlimited"
  213.         Word_user="user"
  214.         Word_port="port"
  215.         Word_pass="pass"
  216.         Word_method="method"
  217.         Word_protocol="protocol"
  218.         Word_obfs="obfs"
  219.         Word_ss_like=" SS Like"
  220.         Word_ss_qr_code=" SS QRcode"
  221.         Word_ssr_like=" SSR Like"
  222.         Word_ssr_qr_code=" SSR QRcode"
  223.         Word_single_port="single_port"
  224.         Word_multi_port="multi_port"
  225.         Word_current_mode="Current_mode"
  226.         Word_current_status="Current_status"
  227.         Word_number_of_devices="number of devices"
  228.         Word_number_of_devices_limit="number of devices limit"
  229.         Word_single_threaded_speed_limit="single-threaded speed limit"
  230.         Word_port_total_speed_limit="port total speed limit"
  231.         Word_the_installation_is_complete="The installation is complete"
  232.         Word_installation_failed="Installation failed"
  233.         Word_uninstall_is_complete="Uninstall is complete"
  234.         Word_uninstall_cancelled="Uninstall cancelled..."
  235.         Word_canceled="Canceled..."
  236.         Word_cancel="cancel"
  237.         Word_startup_failed="Startup failed"
  238.         Word_stop_failing="Stop failing"
  239.         Word_stopped="Stopped"
  240.         Word_installed="Installed"
  241.         Word_not_installed="Not installed"
  242.         Word_has_started="Has started"
  243.         Word_have_not_started="Have not started"
  244.         Word_running="Running"
  245.         Word_not_running="Not running"
  246.         Word_info="Info"
  247.         Word_error="Error"
  248.         Word_Prompt="Prompt"
  249.         Word_timing_interval="Timing interval"
  250.         Word_and="and"
  251.         Word_but="but"
  252.         Word_serverspeeder="ServerSpeeder"
  253.    
  254.         Info_switch_single_port_mode="Are you sure you want to switch mode to ${Word_single_port} ?[y/N]"
  255.         Info_switch_multi_port_mode="Are you sure you want to switch mode to Word_multi_port ?[y/N]"
  256.         Info_input_port="Please enter ShadowsocksR ${Word_port} [1-65535]"
  257.         Info_input_pass="Please enter ShadowsocksR ${Word_pass}"
  258.         Info_input_method="Please enter the number to select ShadowsocksR ${Word_method}"
  259.         Info_input_protocol="Please enter the number to select ShadowsocksR ${Word_protocol}( auth_aes128_* 以后的协议不再支持 兼容原版 )"
  260.         Info_input_number_of_devices="Please enter the number of devices that ShadowsocksR ports want to restrict (${Green_font_prefix} Auth_ * protocol is not compatible with the original version is valid! ${Font_color_suffix})"
  261.         Prompt_number_of_devices="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}The number of devices is limited, referring to the number of clients that can be linked per port (multi_port mode, each port is independently calculated)."
  262.         Info_input_obfs="Please enter the number to select ShadowsocksR ${Word_obfs}"
  263.         Info_protocol_compatible="It is compatible with the original set protocol? ( _compatible ) [Y/n] :"
  264.         Info_obfs_compatible="It is compatible with the original set obfs? ( _compatible ) [Y/n] :"
  265.         Info_protocol_obfs_compatible="It is compatible with the original set protocol / obfs? ( _compatible ) [Y/n] :"
  266.         Info_input_single_threaded_speed_limit="Please enter the maximum speed of each port you want to set for a single thread (in KB / S)"
  267.         Prompt_input_single_threaded_speed_limit="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}This refers to the limit of each port single-threaded limit, multi-threaded that is invalid."
  268.         Info_total_port_speed_limit="Please enter the maximum speed limit for each port you want to set (in KB / S)"
  269.         Prompt_total_port_speed_limit="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}This refers to the total speed limit per port, the overall speed limit for a single port."
  270.    
  271.         Info_input_modify_the_type="Please enter a number to select the type you want to modify :
  272. 1. Modify ${Word_port}/${Word_pass}
  273. 2. Modify ${Word_method}/${Word_protocol}/${Word_obfs}"
  274.         info_input_select_user_id_modified="Please select and enter the user ID you want to modify :"
  275.         Info_input_select_user_id_del="Please select and enter the user ID you want to delete :"
  276.         Prompt_method_protocol_obfs_modified="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR ${Word_method}/${Word_protocol}/${Word_obfs} has been modified!"
  277.  
  278.         Info_jq_installation_is_complete="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} JSON parser JQ has been installed, continue ..."
  279.         Info_jq_is_installed="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} JSON parser JQ installed, continues ..."
  280.         Info_uninstall_ssr="Sure you want to uninstall ShadowsocksR ? [y/N]"
  281.         Info_uninstall_server_speeder="Sure you want to uninstall ${Word_serverspeeder} ? [y/N]"
  282.         Info_install_bbr="Sure you want to install the BBR ? [y/n]"
  283.         Info_install_bbr_0="${Green_font_prefix} [Before installation, please note the following points] ${Font_color_suffix}
  284. 1. Install BBR, need to replace the kernel, there is a risk of replacement failure (can not boot) !
  285. 2. This script only supports Debian / Ubuntu system replacement kernel, OpenVZ virtualization does not support the replacement of the kernel !
  286. 3. In the process of replacing the kernel, you will be prompted to [ terminate the uninstall kernel ], Please select [${Green_font_prefix} NO ${Font_color_suffix}]!
  287. 4. After installing BBR and restart, you need to re-run the script to open BBR [${Green_font_prefix} bash bbr.sh start ${Font_color_suffix}] !"
  288.         Info_input_set_crontab_interval="Please enter the interval at which ShadowsocksR reboots regularly"
  289.         Info_input_set_crontab_interval_default="Every morning at 2:30 am [0 2 * * *]"
  290.         Info_set_crontab_interval_0="${Green_font_prefix} Format Description : ${Font_color_suffix}
  291. Format: ${Green_font_prefix} * * * * * ${Font_color_suffix}, corresponding to ${Green_font_prefix} minutes / hour / day / month / week ${Font_color_suffix}
  292.  Example: ${Green_font_prefix}30 2 * * * ${Font_color_suffix}, every day, 2:30 am, restart once
  293.  Example: ${Green_font_prefix}30 2 * / 3 * * ${Font_color_suffix}, every 3 days, 2:30 am, restart once
  294.  Example: ${Green_font_prefix}30 * / 2 * * * ${Font_color_suffix}, every day, every two hours at 30 minutes, restart once"
  295.         Info_no_cron_installed="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} Detected no installation of corn, started to install ..."
  296.         Info_input_set_cron="Please enter a number to choose what you want to do
  297. 1. Add a timed task
  298. 2. Delete the timed task
  299. ${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}Currently only add a regular restart task."
  300.         Info_set_corn_status="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} There are currently no scheduled reboot task !"
  301.         Info_set_corn_del_success="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} Corn Remove the timing reboot mission success !"
  302.         Info_set_corn_add_success="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} Timed restart task was added successfully !"
  303.         Info_limit_the_number_of_devices="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR device limit has been modified !"
  304.         Info_port_speed_limit="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ShadowsocksR port speed limit has been modified !"
  305.         Info_switch_language_english="Are you sure you want to switch the script language to English ? [y/n]"
  306.         Info_switch_language_chinese="确定要切换脚本语言为 中文 ? [y/n]"
  307.         Info_switch_language_1="${Green_font_prefix} [${Word_info}] ${Font_color_suffix} 重新运行脚本即可看到切换后的语言 !"
  308.  
  309.         Errpr_input_num_error="${Red_font_prefix}[${Word_error}]${Font_color_suffix} Please enter the correct number !"
  310.         Error_not_install_ssr="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} No installation ShadowsocksR, please check !"
  311.         Error_ssr_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR is installed !"
  312.         Error_no_multi_port_users_were_found="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Do not find multi_port users, please check !"
  313.         Error_jq_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} JSON parser JQ installation failed !"
  314.         Error_does_not_support_the_system="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} This script does not support the current system !"
  315.         Error_ssr_download_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR download failed !"
  316.         Error_ssr_failed_to_start="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR failed to start !"
  317.         Error_the_current_mode_is_single_port="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} The current mode is single port, please check !"
  318.         Error_the_current_mode_is_multi_port="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} The current mode is multi_port, please check !"
  319.         Error_multi_port_user_remaining_one="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} The current multi_port users only one, can not be deleted !"
  320.         Error_startup_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR failed to start, please check the log !"
  321.         Error_no_log_found="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Did not find the log file, please check it out !"
  322.         Error_server_speeder_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} installed !"
  323.         Error_server_speeder_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder}  installation failed !"
  324.         Error_server_speeder_not_installed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} is not installed, please check !"
  325.         Error_cron_installation_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Corn installation failed !"
  326.         Error_set_corn_del_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Delete the scheduled reboot task fails !"
  327.         Error_set_corn_add_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Timed restart task failed to add !"
  328.         Error_set_corn_Write_failed="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} Timed restart script write failed !"
  329.         Error_limit_the_number_of_devices_1="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} The current protocol is compatible with the original (_compatible), limit the number of devices is invalid !"
  330.         Error_limit_the_number_of_devices_2="${Red_font_prefix} [${Word_error}] ${Font_color_suffix} The current agreement is the original (origin), limit the number of devices is invalid !"
  331.  
  332.         Prompt_method_libsodium="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix} Chacha20-* and other encryption methods need to install libsodium support library, otherwise it will fail to start !"
  333.         Prompt_any_key="Please press any key to continue, if the configuration error please use Ctrl + C exit."
  334.         Prompt_check_if_the_configuration_is_incorrect="请检查Shadowsocks账号配置是否有误 !"
  335.         Prompt_your_account_configuration="Your ShadowsocksR account configuration :"
  336.         Prompt_ssr_status_on="ShadowsocksR is running !"
  337.         Prompt_ssr_status_off="ShadowsocksR is not running !"
  338.         Prompt_tip="${Green_font_prefix} ${Word_Prompt}: ${Font_color_suffix}
  339. Browser, open the QRcode link, you can see the QRcode picture.
  340.  Protocols and confusion behind [_compatible], referring to the original compatible Shadowsocks protocol / obfs."
  341.         Prompt_total_number_of_users="Current total number of users:"
  342.         Prompt_total_number_of_ip="The total number of currently linked IPs is:"
  343.         Prompt_the_currently_connected_ip="The currently connected IP:"
  344.         Prompt_total_number_of_ip_number="IP number:"
  345.         Prompt_modify_multi_port_user="multi_port users have modified !"
  346.         Prompt_add_multi_port_user="multi_port users have added !"
  347.         Prompt_del_multi_port_user="multi_port user has been deleted !"
  348.         Prompt_log="Use ${Red_font_prefix} Ctrl+C ${Font_color_suffix} to exit View Log !"
  349.         Prompt_switch_language_chinese=" The current scripting language: English"
  350.         Prompt_switch_language_english=" 当前脚本语言为:  中文"
  351.  
  352. #菜单
  353.         Menu_prompt_1="Please enter a number to select the corresponding option"
  354.         Menu_prompt_2="(Please enter numbers 0-27): "
  355.         Menu_prompt_3="Please select and enter numbers 0-27 !"
  356.         Menu_options="${Green_font_prefix}  1. ${Font_color_suffix}Install Shadowsocks
  357. ${Green_font_prefix}  2. ${Font_color_suffix}Install libsodium (chacha20)
  358. ${Green_font_prefix}  3. ${Font_color_suffix}Display account information
  359. ${Green_font_prefix}  4. ${Font_color_suffix}Display connection information
  360. ${Green_font_prefix}  5. ${Font_color_suffix}Modify single-port user configuration
  361. ${Green_font_prefix}  6. ${Font_color_suffix}Manually modify user profiles
  362. ${Green_font_prefix}  7. ${Font_color_suffix}Uninstall Shadowsocks
  363. ${Green_font_prefix}  8. ${Font_color_suffix}Update Shadowsocks
  364. ——————————————————
  365. ${Green_font_prefix}  9. ${Font_color_suffix}Switch single / multi port mode
  366. ${Green_font_prefix} 10. ${Font_color_suffix}Add a multi_port user configuration
  367. ${Green_font_prefix} 11. ${Font_color_suffix}Modify multi_port user configuration
  368. ${Green_font_prefix} 12. ${Font_color_suffix}Remove the multi_port user configuration
  369. ——————————————————
  370. ${Green_font_prefix} 13. ${Font_color_suffix}Start Shadowsocks
  371. ${Green_font_prefix} 14. ${Font_color_suffix}Stop Shadowsocks
  372. ${Green_font_prefix} 15. ${Font_color_suffix}Restart Shadowsocks
  373. ${Green_font_prefix} 16. ${Font_color_suffix}View the ShadowsocksR state
  374. ${Green_font_prefix} 17. ${Font_color_suffix}View the ShadowsocksR log
  375. ——————————————————
  376. ${Green_font_prefix} 18. ${Font_color_suffix}Install ${Word_serverspeeder}
  377. ${Green_font_prefix} 19. ${Font_color_suffix}Stop ${Word_serverspeeder}
  378. ${Green_font_prefix} 20. ${Font_color_suffix}Restart ${Word_serverspeeder}
  379. ${Green_font_prefix} 21. ${Font_color_suffix}View the ${Word_serverspeeder} state
  380. ${Green_font_prefix} 22. ${Font_color_suffix}Uninstall ${Word_serverspeeder}
  381. ——————————————————"
  382.         Menu_options_bbr="${Green_font_prefix} 23. ${Font_color_suffix}Install BBR(Need to replace the kernel, there is a risk)"
  383.         Menu_options_other="${Green_font_prefix} 24. ${Font_color_suffix}Banned BT/PT/SPAM
  384. ${Green_font_prefix} 25. ${Font_color_suffix}Set ShadowsocksR scheduled reboot
  385. ${Green_font_prefix} 26. ${Font_color_suffix}Set the ShadowsocksR device limit
  386. ${Green_font_prefix} 27. ${Font_color_suffix}Set the ShadowsocksR speed limit
  387. ——————————————————
  388. ${Green_font_prefix}  0. ${Font_color_suffix}切换 脚本语言为中文
  389. Note: ${Word_serverspeeder} / BBR does not support OpenVZ !"
  390.     fi
  391.     Menu_status_1=" ${Word_current_status}: ${Green_font_prefix} ${Word_installed} ${Font_color_suffix} ${Word_and} ${Green_font_prefix} ${Word_has_started} ${Font_color_suffix}"
  392.     Menu_status_2=" ${Word_current_status}: ${Green_font_prefix} ${Word_installed} ${Font_color_suffix} ${Word_but} ${Red_font_prefix} ${Word_have_not_started} ${Font_color_suffix}"
  393.     Menu_status_3=" ${Word_current_status}: ${Red_font_prefix} ${Word_not_installed} ${Font_color_suffix}"
  394.     Menu_mode_1=" ${Word_current_mode}: ${Green_font_prefix} ${Word_single_port} ${Font_color_suffix}"
  395.     Menu_mode_2=" ${Word_current_mode}: ${Green_font_prefix} ${Word_multi_port} ${Font_color_suffix}"
  396. }
  397. #检查系统
  398. check_sys(){
  399.     if [[ -f /etc/redhat-release ]]; then
  400.         release="centos"
  401.     elif cat /etc/issue | grep -q -E -i "debian"; then
  402.         release="debian"
  403.     elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  404.         release="ubuntu"
  405.     elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  406.         release="centos"
  407.     elif cat /proc/version | grep -q -E -i "debian"; then
  408.         release="debian"
  409.     elif cat /proc/version | grep -q -E -i "ubuntu"; then
  410.         release="ubuntu"
  411.     elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  412.         release="centos"
  413.     fi
  414.     #bit=`uname -m`
  415. }
  416. SSR_install_status(){
  417.     [[ ! -e $config_user_file ]] && echo -e "${Error_not_install_ssr}" && exit 1
  418. }
  419. #获取IP
  420. getIP(){
  421.     ip=`curl -m 10 -s "ipinfo.io" | jq '.ip' | sed 's/^.//;s/.$//'`
  422.     [[ -z "$ip" ]] && ip="VPS_IP"
  423. }
  424. #获取用户账号信息
  425. getUser(){
  426.     port=`jq '.server_port' ${config_user_file}`
  427.     password=`jq '.password' ${config_user_file} | sed 's/^.//;s/.$//'`
  428.     method=`jq '.method' ${config_user_file} | sed 's/^.//;s/.$//'`
  429.     protocol=`jq '.protocol' ${config_user_file} | sed 's/^.//;s/.$//'`
  430.     obfs=`jq '.obfs' ${config_user_file} | sed 's/^.//;s/.$//'`
  431.     protocol_param=`jq '.protocol_param' ${config_user_file} | sed 's/^.//;s/.$//'`
  432.     speed_limit_per_con=`jq '.speed_limit_per_con' ${config_user_file}`
  433.     speed_limit_per_user=`jq '.speed_limit_per_user' ${config_user_file}`
  434. }
  435. # 设置 端口和密码
  436. set_port_pass(){
  437.     #设置端口
  438.     while true
  439.     do
  440.     echo -e "${Info_input_port}"
  441.     read -p "(${Word_default}: 443):" ssport
  442.     [[ -z "$ssport" ]] && ssport="443"
  443.     expr ${ssport} + 0 &>/dev/null
  444.     if [[ $? -eq 0 ]]; then
  445.         if [[ ${ssport} -ge 1 ]] && [[ ${ssport} -le 65535 ]]; then
  446.             echo && echo ${Separator_1} && echo -e "    ${Word_port} : ${Green_font_prefix}${ssport}${Font_color_suffix}" && echo ${Separator_1} && echo
  447.             break
  448.         else
  449.             echo -e "${Errpr_input_num_error}"
  450.         fi
  451.     else
  452.         echo -e "${Errpr_input_num_error}"
  453.     fi
  454.     done
  455.     #设置密码
  456.     echo "${Info_input_pass}:"
  457.     read -p "(${Word_default}: pt3e.com):" sspwd
  458.     [[ -z "${sspwd}" ]] && sspwd="pt3e.com"
  459.     echo && echo ${Separator_1} && echo -e "    ${Word_pass} : ${Green_font_prefix}${sspwd}${Font_color_suffix}" && echo ${Separator_1} && echo
  460. }
  461. # 设置 加密方式、协议和混淆等
  462. set_others(){
  463.     #设置加密方式
  464.     echo "${Info_input_method}"
  465.     echo " 1. rc4-md5"
  466.     echo " 2. aes-128-ctr"
  467.     echo " 3. aes-256-ctr"
  468.     echo " 4. aes-256-cfb"
  469.     echo " 5. aes-256-cfb8"
  470.     echo " 6. camellia-256-cfb"
  471.     echo " 7. chacha20"
  472.     echo " 8. chacha20-ietf"
  473.     echo -e "${Prompt_method_libsodium}"
  474.     echo
  475.     read -p "(${Word_default}: 4. aes-256-cfb):" ssmethod
  476.     [[ -z "${ssmethod}" ]] && ssmethod="4"
  477.     if [[ ${ssmethod} == "1" ]]; then
  478.         ssmethod="rc4-md5"
  479.     elif [[ ${ssmethod} == "2" ]]; then
  480.         ssmethod="aes-128-ctr"
  481.     elif [[ ${ssmethod} == "3" ]]; then
  482.         ssmethod="aes-256-ctr"
  483.     elif [[ ${ssmethod} == "4" ]]; then
  484.         ssmethod="aes-256-cfb"
  485.     elif [[ ${ssmethod} == "5" ]]; then
  486.         ssmethod="aes-256-cfb8"
  487.     elif [[ ${ssmethod} == "6" ]]; then
  488.         ssmethod="camellia-256-cfb"
  489.     elif [[ ${ssmethod} == "7" ]]; then
  490.         ssmethod="chacha20"
  491.     elif [[ ${ssmethod} == "8" ]]; then
  492.         ssmethod="chacha20-ietf"
  493.     else
  494.         ssmethod="aes-256-cfb"
  495.     fi
  496.     echo && echo ${Separator_1} && echo -e "    ${Word_method} : ${Green_font_prefix}${ssmethod}${Font_color_suffix}" && echo ${Separator_1} && echo
  497.     #设置协议
  498.     echo "${Info_input_protocol}"
  499.     echo " 1. origin"
  500.     echo " 2. auth_sha1_v4"
  501.     echo " 3. auth_aes128_md5"
  502.     echo " 4. auth_aes128_sha1"
  503.     echo
  504.     read -p "(${Word_default}: 2. auth_sha1_v4):" ssprotocol
  505.     [[ -z "${ssprotocol}" ]] && ssprotocol="2"
  506.     if [[ ${ssprotocol} == "1" ]]; then
  507.         ssprotocol="origin"
  508.     elif [[ ${ssprotocol} == "2" ]]; then
  509.         ssprotocol="auth_sha1_v4"
  510.     elif [[ ${ssprotocol} == "3" ]]; then
  511.         ssprotocol="auth_aes128_md5"
  512.     elif [[ ${ssprotocol} == "4" ]]; then
  513.         ssprotocol="auth_aes128_sha1"
  514.     else
  515.         ssprotocol="auth_sha1_v4"
  516.     fi
  517.     echo && echo ${Separator_1} && echo -e "    ${Word_protocol} : ${Green_font_prefix}${ssprotocol}${Font_color_suffix}" && echo ${Separator_1} && echo
  518.     #设置混淆
  519.     echo "${Info_input_obfs}"
  520.     echo " 1. plain"
  521.     echo " 2. http_simple"
  522.     echo " 3. http_post"
  523.     echo " 4. random_head"
  524.     echo " 5. tls1.2_ticket_auth"
  525.     echo
  526.     read -p "(${Word_default}: 5. tls1.2_ticket_auth):" ssobfs
  527.     [[ -z "${ssobfs}" ]] && ssobfs="5"
  528.     if [[ ${ssobfs} == "1" ]]; then
  529.         ssobfs="plain"
  530.     elif [[ ${ssobfs} == "2" ]]; then
  531.         ssobfs="http_simple"
  532.     elif [[ ${ssobfs} == "3" ]]; then
  533.         ssobfs="http_post"
  534.     elif [[ ${ssobfs} == "4" ]]; then
  535.         ssobfs="random_head"
  536.     elif [[ ${ssobfs} == "5" ]]; then
  537.         ssobfs="tls1.2_ticket_auth"
  538.     else
  539.         ssobfs="tls1.2_ticket_auth"
  540.     fi
  541.     echo && echo ${Separator_1} && echo -e "    ${Word_obfs} : ${Green_font_prefix}${ssobfs}${Font_color_suffix}" && echo ${Separator_1} && echo
  542.     #询问是否设置 ${Word_obfs} 兼容原版
  543.     if [[ ${ssprotocol} != "origin" ]]; then
  544.         if [[ ${ssobfs} != "plain" ]]; then
  545.             if [[ ${ssprotocol} == "verify_sha1" ]] || [[ ${ssprotocol} == "auth_sha1_v2" ]]  || [[ ${ssprotocol} == "auth_sha1_v4" ]]; then
  546.                 read -p "${Info_protocol_obfs_compatible}" yn1
  547.                 [[ -z "${yn1}" ]] && yn1="y"
  548.                 [[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible" && ssprotocol=${ssprotocol}"_compatible"
  549.             else
  550.                 read -p "${Info_obfs_compatible}" yn1
  551.                 [[ -z "${yn1}" ]] && yn1="y"
  552.                 [[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible"
  553.             fi
  554.         else
  555.             if [[ ${ssprotocol} == "verify_sha1" ]] || [[ ${ssprotocol} == "auth_sha1_v2" ]]  || [[ ${ssprotocol} == "auth_sha1_v4" ]]; then
  556.                 read -p "${Info_protocol_compatible}" yn1
  557.                 [[ -z "${yn1}" ]] && yn1="y"
  558.                 [[ $yn1 == [Yy] ]] && ssprotocol=${ssprotocol}"_compatible"
  559.             fi
  560.         fi
  561.     else
  562.         if [[ ${ssobfs} != "plain" ]]; then
  563.             read -p "${Info_obfs_compatible}" yn1
  564.             [[ -z "${yn1}" ]] && yn1="y"
  565.             [[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible"
  566.         fi
  567.     fi
  568.     if [[ ${ssprotocol} != "origin" ]]; then
  569.         while true
  570.         do
  571.         echo
  572.         echo -e "${Info_input_number_of_devices}"
  573.         echo -e "${Prompt_number_of_devices}"
  574.         read -p "(${Word_default}: ${Word_unlimited}):" ssprotocol_param
  575.         [[ -z "$ssprotocol_param" ]] && ssprotocol_param="" && break
  576.         expr ${ssprotocol_param} + 0 &>/dev/null
  577.         if [[ $? -eq 0 ]]; then
  578.             if [[ ${ssprotocol_param} -ge 1 ]] && [[ ${ssprotocol_param} -le 99999 ]]; then
  579.                 echo && echo ${Separator_1} && echo -e "    ${Word_number_of_devices} : ${Green_font_prefix}${ssprotocol_param}${Font_color_suffix}" && echo ${Separator_1} && echo
  580.                 break
  581.             else
  582.                 echo "${Errpr_input_num_error}"
  583.             fi
  584.         else
  585.             echo "${Errpr_input_num_error}"
  586.         fi
  587.         done
  588.     fi
  589.     # 设置单线程限速
  590.     while true
  591.     do
  592.     echo
  593.     echo -e "${Info_input_single_threaded_speed_limit}"
  594.     echo -e "${Prompt_input_single_threaded_speed_limit}"
  595.     read -p "(${Word_default}: ${Word_unlimited}):" ssspeed_limit_per_con
  596.     [[ -z "$ssspeed_limit_per_con" ]] && ssspeed_limit_per_con=0 && break
  597.     expr ${ssspeed_limit_per_con} + 0 &>/dev/null
  598.     if [[ $? -eq 0 ]]; then
  599.         if [[ ${ssspeed_limit_per_con} -ge 1 ]] && [[ ${ssspeed_limit_per_con} -le 99999 ]]; then
  600.             echo && echo ${Separator_1} && echo -e "    ${Word_single_threaded_speed_limit} : ${Green_font_prefix}${ssspeed_limit_per_con} KB/S${Font_color_suffix}" && echo ${Separator_1} && echo
  601.             break
  602.         else
  603.             echo "${Errpr_input_num_error}"
  604.         fi
  605.     else
  606.         echo "${Errpr_input_num_error}"
  607.     fi
  608.     done
  609.     # 设置端口总限速
  610.     while true
  611.     do
  612.     echo
  613.     echo -e "${Info_total_port_speed_limit}"
  614.     echo -e "${Prompt_total_port_speed_limit}"
  615.     read -p "(${Word_default}: ${Word_unlimited}):" ssspeed_limit_per_user
  616.     [[ -z "$ssspeed_limit_per_user" ]] && ssspeed_limit_per_user=0 && break
  617.     expr ${ssspeed_limit_per_user} + 0 &>/dev/null
  618.     if [[ $? -eq 0 ]]; then
  619.         if [[ ${ssspeed_limit_per_user} -ge 1 ]] && [[ ${ssspeed_limit_per_user} -le 99999 ]]; then
  620.             echo && echo ${Separator_1} && echo -e "    ${Word_port_total_speed_limit} : ${Green_font_prefix}${ssspeed_limit_per_user} KB/S${Font_color_suffix}" && echo ${Separator_1} && echo
  621.             break
  622.         else
  623.             echo "${Errpr_input_num_error}"
  624.         fi
  625.     else
  626.         echo "${Errpr_input_num_error}"
  627.     fi
  628.     done
  629. }
  630. #设置用户账号信息
  631. setUser(){
  632.     set_port_pass
  633.     set_others
  634.     #最后确认
  635.     [[ "${ssprotocol_param}" == "" ]] && ssprotocol_param="0(${Word_unlimited})"
  636.     echo && echo ${Separator_1}
  637.     echo " ${Prompt_check_if_the_configuration_is_incorrect}" && echo
  638.     echo -e " ${Word_port}\t    : ${Green_font_prefix}${ssport}${Font_color_suffix}"
  639.     echo -e " ${Word_pass}\t    : ${Green_font_prefix}${sspwd}${Font_color_suffix}"
  640.     echo -e " ${Word_method}\t    : ${Green_font_prefix}${ssmethod}${Font_color_suffix}"
  641.     echo -e " ${Word_protocol}\t    : ${Green_font_prefix}${ssprotocol}${Font_color_suffix}"
  642.     echo -e " ${Word_obfs}\t    : ${Green_font_prefix}${ssobfs} ${Font_color_suffix}"
  643.     echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${ssprotocol_param}${Font_color_suffix}"
  644.     echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${ssspeed_limit_per_con} KB/S${Font_color_suffix}"
  645.     echo -e " ${Word_port_total_speed_limit} : ${Green_font_prefix}${ssspeed_limit_per_user} KB/S${Font_color_suffix}"
  646.     echo ${Separator_1} && echo
  647.     read -p "${Prompt_any_key}" var
  648.     [[ "${ssprotocol_param}" = "0(${Word_unlimited})" ]] && ssprotocol_param=""
  649. }
  650. ss_link_qr(){
  651.     SSbase64=`echo -n "${method}:${password}@${ip}:${port}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  652.     SSurl="ss://"${SSbase64}
  653.     SSQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSurl}
  654.     ss_link="${Word_ss_like} : ${Green_font_prefix}${SSurl}${Font_color_suffix} \n${Word_ss_qr_code} : ${Green_font_prefix}${SSQRcode}${Font_color_suffix}"
  655. }
  656. ssr_link_qr(){
  657.     SSRprotocol=`echo ${protocol} | sed 's/_compatible//g'`
  658.     SSRobfs=`echo ${obfs} | sed 's/_compatible//g'`
  659.     SSRPWDbase64=`echo -n "${password}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  660.     SSRbase64=`echo -n "${ip}:${port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  661.     SSRurl="ssr://"${SSRbase64}
  662.     SSRQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSRurl}
  663.     ssr_link="${Word_ssr_like} : ${Green_font_prefix}${SSRurl}${Font_color_suffix} \n${Word_ssr_qr_code} : ${Green_font_prefix}${SSRQRcode}${Font_color_suffix} \n "
  664. }
  665. ss_link_qr_1(){
  666.     SSbase64=`echo -n "${method}:${user_password}@${ip}:${user_port}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  667.     #echo -e "${user_port}" && echo -e "${user_password}" && echo -e "${SSbase64}"
  668.     SSurl="ss://"${SSbase64}
  669.     SSQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSurl}
  670.     ss_link="${Word_ss_like} : ${Green_font_prefix}${SSurl}${Font_color_suffix} \n${Word_ss_qr_code} : ${Green_font_prefix}${SSQRcode}${Font_color_suffix}"
  671. }
  672. ssr_link_qr_1(){
  673.     SSRprotocol=`echo ${protocol} | sed 's/_compatible//g'`
  674.     SSRobfs=`echo ${obfs} | sed 's/_compatible//g'`
  675.     SSRPWDbase64=`echo -n "${user_password}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  676.     SSRbase64=`echo -n "${ip}:${user_port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
  677.     #echo -e "${user_port}" && echo -e "${user_password}" && echo -e "${SSRbase64}"
  678.     SSRurl="ssr://"${SSRbase64}
  679.     SSRQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSRurl}
  680.     ssr_link="${Word_ssr_like} : ${Green_font_prefix}${SSRurl}${Font_color_suffix} \n${Word_ssr_qr_code} : ${Green_font_prefix}${SSRQRcode}${Font_color_suffix} \n "
  681. }
  682. #显示用户账号信息
  683. viewUser(){
  684.     SSR_install_status
  685.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  686.     if [[ -z "${PID}" ]]; then
  687.         ssr_status="${Red_font_prefix} ${Word_current_status}: ${Font_color_suffix} ShadowsocksR ${Word_not_running} !"
  688.     else
  689.         ssr_status="${Green_font_prefix} ${Word_current_status}: ${Font_color_suffix} ShadowsocksR ${Word_running} !"
  690.     fi
  691.     getIP
  692.     now_mode=`jq '.port_password' ${config_user_file}`
  693.     if [[ "${now_mode}" = "null" ]]; then
  694.         getUser
  695.         SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
  696.         SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
  697.         if [[ ${protocol} = "origin" ]]; then
  698.             if [[ ${obfs} = "plain" ]]; then
  699.                 ss_link_qr
  700.                 ssr_link=""
  701.             else
  702.                 if [[ ${SSobfs} != "compatible" ]]; then
  703.                     ss_link=""
  704.                 else
  705.                     ss_link_qr
  706.                 fi
  707.             fi
  708.         else
  709.             if [[ ${SSprotocol} != "compatible" ]]; then
  710.                 ss_link=""
  711.             else
  712.                 if [[ ${SSobfs} != "compatible" ]]; then
  713.                     if [[ ${SSobfs} = "plain" ]]; then
  714.                         ss_link_qr
  715.                     else
  716.                         ss_link=""
  717.                     fi
  718.                 else
  719.                     ss_link_qr
  720.                 fi
  721.             fi
  722.         fi
  723.         ssr_link_qr
  724.         [[ -z ${protocol_param} ]] && protocol_param="0(${Word_unlimited})"
  725.         clear
  726.         echo "==================================================="
  727.         echo
  728.         echo -e " ${Prompt_your_account_configuration}"
  729.         echo
  730.         echo -e " I  P\t    : ${Green_font_prefix}${ip}${Font_color_suffix}"
  731.         echo -e " ${Word_port}\t    : ${Green_font_prefix}${port}${Font_color_suffix}"
  732.         echo -e " ${Word_pass}\t    : ${Green_font_prefix}${password}${Font_color_suffix}"
  733.         echo -e " ${Word_method}\t    : ${Green_font_prefix}${method}${Font_color_suffix}"
  734.         echo -e " ${Word_protocol}\t    : ${Green_font_prefix}${protocol}${Font_color_suffix}"
  735.         echo -e " ${Word_obfs}\t    : ${Green_font_prefix}${obfs}${Font_color_suffix}"
  736.         echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${protocol_param}${Font_color_suffix}"
  737.         echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}"
  738.         echo -e " ${Word_port_total_speed_limit} : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}"
  739.         echo -e "${ss_link}"
  740.         echo -e "${ssr_link}"
  741.         echo -e "${Prompt_tip}"
  742.         echo
  743.         echo -e ${ssr_status}
  744.         echo
  745.         echo "==================================================="
  746.     else
  747.         getUser
  748.         [[ -z ${protocol_param} ]] && protocol_param="0(${Word_unlimited})"
  749.         clear
  750.         echo "==================================================="
  751.         echo
  752.         echo -e " ${Prompt_your_account_configuration}"
  753.         echo
  754.         echo -e " I  P\t    : ${Green_font_prefix}${ip}${Font_color_suffix}"
  755.         echo -e " ${Word_method}\t    : ${Green_font_prefix}${method}${Font_color_suffix}"
  756.         echo -e " ${Word_protocol}\t    : ${Green_font_prefix}${protocol}${Font_color_suffix}"
  757.         echo -e " ${Word_obfs}\t    : ${Green_font_prefix}${obfs}${Font_color_suffix}"
  758.         echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${protocol_param}${Font_color_suffix}"
  759.         echo -e " ${Word_number_of_devices_limit} : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}"
  760.         echo -e " ${Word_port_total_speed_limit} : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}"
  761.         echo
  762.         user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  763.         [[ ${socat_total} = "0" ]] && echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} 没有发现 多端口用户,请检查 !" && exit 1
  764.         user_id=0
  765.         check_sys
  766.         if [[ ${release} = "centos" ]]; then
  767.             for((integer = 1; integer <= ${user_total}; integer++))
  768.             do
  769.                 user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  770.                 user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  771.                 user_id=$[$user_id+1]
  772.                     #echo -e ${user_port} && echo -e ${user_password} && echo -e ${user_id}
  773.                 SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
  774.                 SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
  775.                 if [[ ${protocol} = "origin" ]]; then
  776.                     if [[ ${obfs} = "plain" ]]; then
  777.                         ss_link_qr_1
  778.                         ssr_link=""
  779.                     else
  780.                         if [[ ${SSobfs} != "compatible" ]]; then
  781.                             ss_link=""
  782.                         else
  783.                             ss_link_qr_1
  784.                         fi
  785.                     fi
  786.                 else
  787.                     if [[ ${SSprotocol} != "compatible" ]]; then
  788.                         ss_link=""
  789.                     else
  790.                         if [[ ${SSobfs} != "compatible" ]]; then
  791.                             if [[ ${SSobfs} = "plain" ]]; then
  792.                                 ss_link_qr_1
  793.                             else
  794.                                 ss_link=""
  795.                             fi
  796.                         else
  797.                             ss_link_qr_1
  798.                         fi
  799.                     fi
  800.                 fi
  801.                 ssr_link_qr_1
  802.                 echo -e " ——————————${Green_font_prefix} ${Word_user} ${user_id} ${Font_color_suffix} ——————————"
  803.                 echo -e " ${Word_port}\t    : ${Green_font_prefix}${user_port}${Font_color_suffix}"
  804.                 echo -e " ${Word_pass}\t    : ${Green_font_prefix}${user_password}${Font_color_suffix}"
  805.                 echo -e "${ss_link}"
  806.                 echo -e "${ssr_link}"
  807.             done
  808.         else
  809.             for((integer = ${user_total}; integer >= 1; integer--))
  810.             do
  811.                 user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  812.                 user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  813.                 user_id=$[$user_id+1]  
  814.            
  815.                 SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
  816.                 SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
  817.                 if [[ ${protocol} = "origin" ]]; then
  818.                     if [[ ${obfs} = "plain" ]]; then
  819.                         ss_link_qr_1
  820.                         ssr_link=""
  821.                     else
  822.                         if [[ ${SSobfs} != "compatible" ]]; then
  823.                             ss_link=""
  824.                         else
  825.                             ss_link_qr_1
  826.                         fi
  827.                     fi
  828.                 else
  829.                     if [[ ${SSprotocol} != "compatible" ]]; then
  830.                         ss_link=""
  831.                     else
  832.                         if [[ ${SSobfs} != "compatible" ]]; then
  833.                             if [[ ${SSobfs} = "plain" ]]; then
  834.                                 ss_link_qr_1
  835.                             else
  836.                                 ss_link=""
  837.                             fi
  838.                         else
  839.                             ss_link_qr_1
  840.                         fi
  841.                     fi
  842.                 fi
  843.                 ssr_link_qr_1
  844.                 echo -e " —————————— ${Green_font_prefix} ${Word_user} ${user_id} ${Font_color_suffix} ——————————"
  845.                 echo -e " ${Word_port}\t    : ${Green_font_prefix}${user_port}${Font_color_suffix}"
  846.                 echo -e " ${Word_pass}\t    : ${Green_font_prefix}${user_password}${Font_color_suffix}"
  847.                 echo -e "${ss_link}"
  848.                 echo -e "${ssr_link}"
  849.             done
  850.         fi
  851.         echo -e "${Prompt_tip}"
  852.         echo
  853.         echo -e ${ssr_status}
  854.         echo
  855.         echo "==================================================="
  856.     fi
  857. }
  858. debian_apt(){
  859.     apt-get update
  860.     apt-get install -y python-pip python-m2crypto curl unzip vim git gcc build-essential make
  861. }
  862. centos_yum(){
  863.     yum update
  864.     yum install -y python-pip python-m2crypto curl unzip vim git gcc make
  865. }
  866. JQ_install(){
  867.     JQ_ver=`jq -V`
  868.     if [[ -z ${JQ_ver} ]]; then
  869.         #wget --no-check-certificate -N "https://softs.pw/Bash/other/jq-1.5.tar.gz"
  870.         wget --no-check-certificate -N "https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/other/jq-1.5.tar.gz"
  871.         tar -xzf jq-1.5.tar.gz && cd jq-1.5
  872.         ./configure --disable-maintainer-mode && make && make install
  873.         ldconfig
  874.         cd .. && rm -rf jq-1.5.tar.gz && rm -rf jq-1.5
  875.         JQ_ver=`jq -V`
  876.         [[ -z ${JQ_ver} ]]&& echo -e "${Error_jq_installation_failed}" && exit 1
  877.         echo -e "${Info_jq_installation_is_complete}"
  878.     else
  879.         echo -e "${Info_jq_is_installed}"
  880.     fi
  881. }
  882. rc.local_ss_set(){
  883. #添加开机启动
  884.     if [[ ${release} = "centos" ]]; then
  885.         chmod +x /etc/rc.d/rc.local
  886.         #sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.d/rc.local
  887.         #sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.d/rc.local
  888.         sed -i '/shadowsocksr/d' /etc/rc.d/rc.local
  889.         sed -i '/python server.py/d' /etc/rc.d/rc.local
  890.         echo -e "cd ${ssr_ss_file} && nohup python server.py a >> ssserver.log 2>&1 &" >> /etc/rc.d/rc.local
  891.     else
  892.         chmod +x /etc/rc.local
  893.         sed -i '$d' /etc/rc.local
  894.         #sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.local
  895.         #sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.local
  896.         sed -i '/shadowsocksr/d' /etc/rc.local
  897.         sed -i '/python server.py/d' /etc/rc.local
  898.         echo -e "cd ${ssr_ss_file} && nohup python server.py a >> ssserver.log 2>&1 &" >> /etc/rc.local
  899.         echo -e "exit 0" >> /etc/rc.local
  900.     fi
  901. }
  902. rc.local_ss_del(){
  903.     if [[ ${release} = "centos" ]]; then
  904.         #sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.d/rc.local
  905.         #sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.d/rc.local
  906.         sed -i '/shadowsocksr/d' /etc/rc.d/rc.local
  907.         sed -i '/python server.py/d' /etc/rc.d/rc.local
  908.     else
  909.         #sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.local
  910.         #sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.local
  911.         sed -i '/shadowsocksr/d' /etc/rc.local
  912.         sed -i '/python server.py/d' /etc/rc.local
  913.     fi
  914. }
  915. rc.local_serverspeed_set(){
  916. #添加开机启动
  917.     if [[ ${release} = "centos" ]]; then
  918.         chmod +x /etc/rc.d/rc.local
  919.         sed -i '/serverspeeder/d' /etc/rc.d/rc.local
  920.         echo -e "/serverspeeder/bin/serverSpeeder.sh start" >> /etc/rc.d/rc.local
  921.     else
  922.         chmod +x /etc/rc.local
  923.         sed -i '$d' /etc/rc.local
  924.         sed -i '/serverspeeder/d' /etc/rc.local
  925.         echo -e "/serverspeeder/bin/serverSpeeder.sh start" >> /etc/rc.local
  926.         echo -e "exit 0" >> /etc/rc.local
  927.     fi
  928. }
  929. rc.local_serverspeed_del(){
  930.     if [[ ${release} = "centos" ]]; then
  931.         sed -i '/serverspeeder/d' /etc/rc.d/rc.local
  932.     else
  933.         sed -i '/serverspeeder/d' /etc/rc.local
  934.     fi
  935. }
  936. iptables_add(){
  937.     iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssport} -j ACCEPT
  938.     iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssport} -j ACCEPT
  939. }
  940. iptables_del(){
  941.     iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
  942.     iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
  943. }
  944. iptables_set(){
  945.     #删除旧端口的防火墙规则,添加新端口的规则
  946.     iptables_del
  947.     iptables_add
  948. }
  949. set_config_port_pass(){
  950.     sed -i 's/"server_port": '$(echo ${port})'/"server_port": '$(echo ${ssport})'/g' ${config_user_file}
  951.     sed -i 's/"password": "'$(echo ${password})'"/"password": "'$(echo ${sspwd})'"/g' ${config_user_file}
  952. }
  953. set_config_method_obfs_protocol(){
  954.     sed -i 's/"method": "'$(echo ${method})'"/"method": "'$(echo ${ssmethod})'"/g' ${config_user_file}
  955.     sed -i 's/"obfs": "'$(echo ${obfs})'"/"obfs": "'$(echo ${ssobfs})'"/g' ${config_user_file}
  956.     sed -i 's/"protocol": "'$(echo ${protocol})'"/"protocol": "'$(echo ${ssprotocol})'"/g' ${config_user_file}
  957. }
  958. set_config_protocol_param(){
  959.     sed -i 's/"protocol_param": "'$(echo ${protocol_param})'"/"protocol_param": "'$(echo ${ssprotocol_param})'"/g' ${config_user_file}
  960. }
  961. set_config_speed_limit_per(){
  962.     sed -i 's/"speed_limit_per_con": '$(echo ${speed_limit_per_con})'/"speed_limit_per_con": '$(echo ${ssspeed_limit_per_con})'/g' ${config_user_file}
  963.     sed -i 's/"speed_limit_per_user": '$(echo ${speed_limit_per_user})'/"speed_limit_per_user": '$(echo ${ssspeed_limit_per_user})'/g' ${config_user_file}
  964. }
  965. #安装ShadowsocksR
  966. installSSR(){
  967.     [[ -e $config_user_file ]] && echo -e "${Error_ssr_installed}" && exit 1
  968.     setUser
  969.     check_sys
  970.     # 系统判断
  971.     if [[ ${release} = "debian" ]]; then
  972.         debian_apt
  973.     elif [[ ${release} = "ubuntu" ]]; then
  974.         debian_apt
  975.     elif [[ ${release} = "centos" ]]; then
  976.         centos_yum
  977.     else
  978.         echo -e "${Error_does_not_support_the_system}" && exit 1
  979.     fi
  980.     #修改DNS为8.8.8.8
  981.     echo "nameserver 8.8.8.8" > /etc/resolv.conf
  982.     echo "nameserver 8.8.4.4" >> /etc/resolv.conf
  983.     cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  984.     JQ_install
  985.     cd /etc
  986.     #git config --global http.sslVerify false
  987.     env GIT_SSL_NO_VERIFY=true git clone -b manyuser https://github.com/shadowsocksr/shadowsocksr.git
  988.     [[ ! -e ${config_file} ]] && echo -e "${Error_ssr_download_failed}" && exit 1
  989.     cp ${config_file} ${config_user_file}
  990.     #修改配置文件的密码 ${Word_port} 加密方式
  991.     cat > ${config_user_file}<<-EOF
  992. {
  993.     "server": "0.0.0.0",
  994.     "server_ipv6": "::",
  995.     "server_port": ${ssport},
  996.     "local_address": "127.0.0.1",
  997.     "local_port": 1080,
  998.     "password": "${sspwd}",
  999.     "timeout": 120,
  1000.     "udp_timeout": 60,
  1001.     "method": "${ssmethod}",
  1002.     "protocol": "${ssprotocol}",
  1003.     "protocol_param": "${ssprotocol_param}",
  1004.     "obfs": "${ssobfs}",
  1005.     "obfs_param": "",
  1006.     "speed_limit_per_con": ${ssspeed_limit_per_con},
  1007.     "speed_limit_per_user": ${ssspeed_limit_per_user},
  1008.     "dns_ipv6": false,
  1009.     "connect_verbose_info": 0,
  1010.     "redirect": "",
  1011.     "fast_open": false
  1012. }
  1013. EOF
  1014.  
  1015.     #添加新端口的规则
  1016.     iptables_add
  1017.     rc.local_ss_set
  1018.     #启动SSR服务端,并判断是否启动成功
  1019.     cd ${ssr_ss_file}
  1020.     nohup python server.py a >> ssserver.log 2>&1 &
  1021.     sleep 2s
  1022.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1023.     if [[ ! -z "${PID}" ]]; then
  1024.         viewUser
  1025.         echo
  1026.         echo -e "ShadowsocksR ${Word_the_installation_is_complete} !"
  1027.         echo -e "http://pt3e.com/jingxuan/"
  1028.         echo
  1029.         echo "############################################################"
  1030.     else
  1031.         echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR ${Word_startup_failed} !"
  1032.     fi
  1033. }
  1034. installLibsodium(){
  1035.     # 系统判断
  1036.     check_sys
  1037.     if [[ ${release}  != "debian" ]]; then
  1038.         if [[ ${release}  != "ubuntu" ]]; then
  1039.             if [[ ${release}  != "centos" ]]; then
  1040.                 echo -e "${Error_does_not_support_the_system}" && exit 1
  1041.             fi
  1042.         fi
  1043.     fi
  1044.     if [[ ${release} != "centos" ]]; then
  1045.         apt-get update && apt-get install -y gcc build-essential make
  1046.         cd /root
  1047.         wget  --no-check-certificate -O libsodium.tar.gz https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz
  1048.         tar -xzf libsodium.tar.gz && mv libsodium-${Libsodiumr_ver} libsodium && cd libsodium
  1049.         ./configure --disable-maintainer-mode && make -j2 && make install
  1050.         ldconfig
  1051.         cd .. && rm -rf libsodium.tar.gz && rm -rf libsodium
  1052.     else
  1053.         yum update && yum install epel-release -y && yum install libsodium -y
  1054.     fi
  1055.     echo ${Separator_1} && echo
  1056.     echo -e "Libsodium ${Word_the_installation_is_complete} !"
  1057.     echo -e "http://www.pt3e.com/jingxuan/"
  1058.     echo && echo ${Separator_1}
  1059. }
  1060. #修改单端口用户配置
  1061. modifyUser(){
  1062.     SSR_install_status
  1063.     now_mode=`jq '.port_password' ${config_user_file}`
  1064.     [[ "${now_mode}" != "null" ]] && echo -e "${Error_the_current_mode_is_multi_port}" && exit 1
  1065.     getUser
  1066.     setUser
  1067.     #修改配置文件的密码 ${Word_port} 加密方式
  1068.     set_config_port_pass
  1069.     set_config_method_obfs_protocol
  1070.     set_config_protocol_param
  1071.     set_config_speed_limit_per
  1072.     iptables_set
  1073.     RestartSSR
  1074. }
  1075. #手动修改用户配置
  1076. manuallyModifyUser(){
  1077.     SSR_install_status
  1078.     port=`jq '.server_port' ${config_user_file}`
  1079.     vi $config_user_file
  1080.     ssport=`jq '.server_port' ${config_user_file}`
  1081.     iptables_set
  1082.     RestartSSR
  1083. }
  1084. #卸载ShadowsocksR
  1085. UninstallSSR(){
  1086.     [[ ! -e $config_file ]] && echo -e "${Error_not_install_ssr}" && exit 1
  1087.     echo "${Info_uninstall_ssr}"
  1088.     echo
  1089.     read -p "(${Word_default}: n):" unyn
  1090.     [[ -z ${unyn} ]] && unyn="n"
  1091.     if [[ ${unyn} == [Yy] ]]; then
  1092. #停止ShadowsocksR服务端并删除防火墙规则,删除Shadowsocks文件夹。
  1093.         PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1094.         [[ ! -z "${PID}" ]] && kill -9 ${PID}
  1095.         cron_ssr=`crontab -l | grep "${ssr_file}/${auto_restart_cron}" | wc -l`
  1096.         if [[ ${cron_ssr} > "0" ]]; then
  1097.             crontab -l > ${ssr_file}"/crontab.bak"
  1098.             sed -i "/\/etc\/shadowsocksr\/${auto_restart_cron}/d" ${ssr_file}"/crontab.bak"
  1099.             crontab ${ssr_file}"/crontab.bak"
  1100.             rm -rf ${ssr_file}"/crontab.bak"
  1101.         fi
  1102.         now_mode=`jq '.port_password' ${config_user_file}`
  1103.         if [[ "${now_mode}" = "null" ]]; then
  1104.             port=`jq '.server_port' ${config_user_file}`
  1105.             iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
  1106.             iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
  1107.         else
  1108.             user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1109.             for((integer = 1; integer <= ${user_total}; integer++))
  1110.             do
  1111.                 port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1112.                 iptables_del
  1113.             done
  1114.         fi
  1115. #取消开机启动
  1116.         check_sys
  1117.         rc.local_ss_del
  1118.         rm -rf ${ssr_file} && rm -rf ${Libsodiumr_file} && rm -rf ${Libsodiumr_file}.tar.gz
  1119.         echo && echo "  ShadowsocksR ${Word_uninstall_is_complete} !" && echo
  1120.     else
  1121.         echo && echo "${Word_uninstall_cancelled}" && echo
  1122.     fi
  1123. }
  1124. # 更新ShadowsocksR
  1125. UpdateSSR(){
  1126.     SSR_install_status
  1127.     cd ${ssr_file}
  1128.     git pull
  1129.     RestartSSR
  1130. }
  1131. # 切换 单/多端口模式
  1132. Port_mode_switching(){
  1133.     SSR_install_status
  1134.     now_mode=`jq '.port_password' ${config_user_file}`
  1135.     if [[ "${now_mode}" = "null" ]]; then
  1136.         echo
  1137.         echo -e "   ${Word_current_mode}: ${Green_font_prefix} ${Word_single_port} ${Font_color_suffix}"
  1138.         echo
  1139.         echo -e "${Info_switch_multi_port_mode}"
  1140.         echo
  1141.         read -p "(${Word_default}: n):" mode_yn
  1142.         [[ -z ${mode_yn} ]] && mode_yn="n"
  1143.         if [[ ${mode_yn} == [Yy] ]]; then
  1144.             port=`jq '.server_port' ${config_user_file}`
  1145.             setUser
  1146.             iptables_set
  1147.             cat > ${config_user_file}<<-EOF
  1148. {
  1149.     "server": "0.0.0.0",
  1150.     "server_ipv6": "::",
  1151.     "local_address": "127.0.0.1",
  1152.     "local_port": 1080,
  1153.     "port_password":{
  1154.         "${ssport}":"${sspwd}"
  1155.     },
  1156.     "timeout": 120,
  1157.     "udp_timeout": 60,
  1158.     "method": "${ssmethod}",
  1159.     "protocol": "${ssprotocol}",
  1160.     "protocol_param": "${ssprotocol_param}",
  1161.     "obfs": "${ssobfs}",
  1162.     "obfs_param": "",
  1163.     "speed_limit_per_con": ${ssspeed_limit_per_con},
  1164.     "speed_limit_per_user": ${ssspeed_limit_per_user},
  1165.     "dns_ipv6": false,
  1166.     "connect_verbose_info": 0,
  1167.     "redirect": "",
  1168.     "fast_open": false
  1169. }
  1170. EOF
  1171.             RestartSSR
  1172.         else
  1173.             echo && echo ${Word_canceled}" && echo
  1174.         fi
  1175.     else
  1176.         echo
  1177.         echo -e "   ${Word_current_mode}: ${Green_font_prefix} ${Word_multi_port} ${Font_color_suffix}"
  1178.         echo
  1179.         echo -e "${Info_switch_single_port_mode}"
  1180.         echo
  1181.         read -p "(${Word_default}: n):" mode_yn
  1182.         [[ -z ${mode_yn} ]] && mode_yn="n"
  1183.         if [[ ${mode_yn} == [Yy] ]]; then
  1184.             user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1185.             for((integer = 1; integer <= ${user_total}; integer++))
  1186.             do
  1187.                 port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1188.                 iptables_del
  1189.             done
  1190.             setUser
  1191.             iptables_add
  1192.         cat > ${config_user_file}<<-EOF
  1193. {
  1194.     "server": "0.0.0.0",
  1195.     "server_ipv6": "::",
  1196.     "server_port": ${ssport},
  1197.     "local_address": "127.0.0.1",
  1198.     "local_port": 1080,
  1199.     "password": "${sspwd}",
  1200.     "timeout": 120,
  1201.     "udp_timeout": 60,
  1202.     "method": "${ssmethod}",
  1203.     "protocol": "${ssprotocol}",
  1204.     "protocol_param": "${ssprotocol_param}",
  1205.     "obfs": "${ssobfs}",
  1206.     "obfs_param": "",
  1207.     "speed_limit_per_con": ${ssspeed_limit_per_con},
  1208.     "speed_limit_per_user": ${ssspeed_limit_per_user},
  1209.     "dns_ipv6": false,
  1210.     "connect_verbose_info": 0,
  1211.     "redirect": "",
  1212.     "fast_open": false
  1213. }
  1214. EOF
  1215.             RestartSSR
  1216.         else
  1217.             echo && echo ${Word_canceled}" && echo
  1218.         fi
  1219.     fi
  1220. }
  1221. List_multi_port_user(){
  1222.     user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1223.     [[ ${socat_total} = "0" ]] && echo -e "${Error_no_multi_port_users_were_found}" && exit 1
  1224.     user_list_all=""
  1225.     user_id=0
  1226.     check_sys
  1227.     if [[ ${release} = "centos" ]]; then
  1228.         for((integer = 1; integer <= ${user_total}; integer++))
  1229.         do
  1230.             user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1231.             user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1232.             user_id=$[$user_id+1]
  1233.             user_list_all=${user_list_all}${user_id}". ${Word_port}: "${user_port}" ${Word_pass}: "${user_password}"\n"
  1234.         done
  1235.     else
  1236.         for((integer = ${user_total}; integer >= 1; integer--))
  1237.         do
  1238.             user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1239.             user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1240.             user_id=$[$user_id+1]
  1241.             user_list_all=${user_list_all}${user_id}". ${Word_port}: "${user_port}" ${Word_pass}: "${user_password}"\n"
  1242.         done
  1243.     fi
  1244.     echo
  1245.     echo -e "${Prompt_total_number_of_users} ${Green_font_prefix} "${user_total}" ${Font_color_suffix} "
  1246.     echo -e ${user_list_all}
  1247. }
  1248. # 添加 多端口用户配置
  1249. Add_multi_port_user(){
  1250.     SSR_install_status
  1251.     now_mode=`jq '.port_password' ${config_user_file}`
  1252.     [[ "${now_mode}" = "null" ]] && echo -e "${Error_the_current_mode_is_single_port}" && exit 1
  1253.     set_port_pass
  1254.     sed -i "7 i \"        \"${ssport}\":\"${sspwd}\"," ${config_user_file}
  1255.     sed -i "7s/^\"//" ${config_user_file}
  1256.     iptables_add
  1257.     RestartSSR
  1258.     echo -e "${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ${Prompt_add_multi_port_user} ${Green_font_prefix} [${Word_port}: ${ssport} , ${Word_pass}: ${sspwd}] ${Font_color_suffix} "
  1259. }
  1260. # 修改 多端口用户配置
  1261. Modify_multi_port_user(){
  1262.     SSR_install_status
  1263.     now_mode=`jq '.port_password' ${config_user_file}`
  1264.     [[ "${now_mode}" = "null" ]] && echo -e "${Error_the_current_mode_is_single_port}" && exit 1
  1265.     echo -e "${Info_input_modify_the_type}"
  1266.     read -p "(${Word_default}: ${Word_cancel}):" modify_type
  1267.     [[ -z "${modify_type}" ]] && exit 1
  1268.     if [[ ${modify_type} == "1" ]]; then
  1269.         List_multi_port_user
  1270.         while true
  1271.         do
  1272.         echo -e "${info_input_select_user_id_modified}"
  1273.         read -p "(${Word_default}: ${Word_cancel}):" del_user_num
  1274.         [[ -z "${del_user_num}" ]] && exit 1
  1275.         expr ${del_user_num} + 0 &>/dev/null
  1276.         if [ $? -eq 0 ]; then
  1277.             if [[ ${del_user_num} -ge 1 ]] && [[ ${del_user_num} -le ${user_total} ]]; then
  1278.                 set_port_pass
  1279.                 del_user_num_3=$[ $del_user_num + 6]
  1280.                 port=`sed -n "${del_user_num_3}p" ${config_user_file} | awk -F ":" '{print $1}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1281.                 password=`sed -n "${del_user_num_3}p" ${config_user_file} | awk -F ":" '{print $2}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1282.                 sed -i 's/"'$(echo ${port})'":"'$(echo ${password})'"/"'$(echo ${ssport})'":"'$(echo ${sspwd})'"/g' ${config_user_file}
  1283.                 iptables_set
  1284.                 RestartSSR
  1285.                 echo -e "${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ${Prompt_modify_multi_port_user} ${Green_font_prefix} ${del_user_num} ${Font_color_suffix} "
  1286.                 break
  1287.             else
  1288.                 echo "${Errpr_input_num_error}"
  1289.             fi
  1290.         else
  1291.             echo "${Errpr_input_num_error}"
  1292.         fi
  1293.         done   
  1294.     elif [[ ${modify_type} == "2" ]]; then
  1295.         set_others
  1296.         getUser
  1297.         set_config_method_obfs_protocol
  1298.         set_config_protocol_param
  1299.         set_config_speed_limit_per
  1300.         RestartSSR
  1301.         echo -e "${Prompt_method_protocol_obfs_modified}"
  1302.     fi
  1303. }
  1304. # 删除 多端口用户配置
  1305. Del_multi_port_user(){
  1306.     SSR_install_status
  1307.     now_mode=`jq '.port_password' ${config_user_file}`
  1308.     [[ "${now_mode}" = "null" ]] && echo -e "${Error_the_current_mode_is_single_port}" && exit 1
  1309.     List_multi_port_user
  1310.     user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1311.     [[ "${user_total}" -le "1" ]] && echo -e "${Error_multi_port_user_remaining_one}" && exit 1
  1312.     while true
  1313.     do
  1314.     echo -e "${Info_input_select_user_id_del}"
  1315.     read -p "(${Word_default}: ${Word_cancel}):" del_user_num
  1316.     [[ -z "${del_user_num}" ]] && exit 1
  1317.     expr ${del_user_num} + 0 &>/dev/null
  1318.     if [[ $? -eq 0 ]]; then
  1319.         if [[ ${del_user_num} -ge 1 ]] && [[ ${del_user_num} -le ${user_total} ]]; then
  1320.             del_user_num_4=$[ $del_user_num + 6]
  1321.             port=`sed -n "${del_user_num_4}p" ${config_user_file} | awk -F ":" '{print $1}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1322.             iptables_del
  1323.             del_user_num_1=$[ $del_user_num + 6 ]
  1324.             sed -i "${del_user_num_1}d" ${config_user_file}
  1325.             if [[ ${del_user_num} = ${user_total} ]]; then
  1326.                 del_user_num_1=$[ $del_user_num_1 - 1 ]
  1327.                 sed -i "${del_user_num_1}s/,$//g" ${config_user_file}
  1328.             fi
  1329.             RestartSSR
  1330.             echo -e "${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ${Prompt_del_multi_port_user} ${Green_font_prefix} ${del_user_num} ${Font_color_suffix} "
  1331.             break
  1332.         else
  1333.             echo "${Errpr_input_num_error}"
  1334.         fi
  1335.     else
  1336.         echo "${Errpr_input_num_error}"
  1337.     fi
  1338.     done
  1339. }
  1340. # 显示用户连接信息
  1341. View_user_connection_info(){
  1342.     SSR_install_status
  1343.     check_sys
  1344.     if [[ ${release} = "debian" ]]; then
  1345.         debian_View_user_connection_info
  1346.     elif [[ ${release} = "ubuntu" ]]; then
  1347.         debian_View_user_connection_info
  1348.     elif [[ ${release} = "centos" ]]; then
  1349.         centos_View_user_connection_info
  1350.     fi
  1351. }
  1352. debian_View_user_connection_info(){
  1353.     now_mode=`jq '.port_password' ${config_user_file}`
  1354.     if [[ "${now_mode}" = "null" ]]; then
  1355.         now_mode="${Word_single_port}" && user_total="1"
  1356.         IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
  1357.         user_port=`jq '.server_port' ${config_user_file}`
  1358.         user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u`
  1359.         user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
  1360.         user_list_all="1. ${Word_port}: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, ${Prompt_total_number_of_ip_number} ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, ${Prompt_the_currently_connected_ip} ${Green_font_prefix}"${user_IP}"${Font_color_suffix}\n"
  1361.         echo -e "${Word_current_mode} ${Green_font_prefix} "${now_mode}" ${Font_color_suffix} 。"
  1362.         echo -e ${user_list_all}
  1363.     else
  1364.         now_mode="${Word_multi_port}" && user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1365.         IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
  1366.         user_list_all=""
  1367.         user_id=0
  1368.         for((integer = ${user_total}; integer >= 1; integer--))
  1369.         do
  1370.             user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1371.             user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u`
  1372.             user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
  1373.             user_id=$[$user_id+1]
  1374.             user_list_all=${user_list_all}${user_id}". ${Word_port}: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, ${Prompt_total_number_of_ip_number} ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, ${Prompt_the_currently_connected_ip} ${Green_font_prefix}"${user_IP}"${Font_color_suffix}\n"
  1375.         done
  1376.         echo -e "${Word_current_mode} ${Green_font_prefix} "${now_mode}" ${Font_color_suffix}${Word_current_mode} ${Green_font_prefix} "${user_total}" ${Font_color_suffix}${Prompt_total_number_of_ip} ${Green_font_prefix} "${IP_total}" ${Font_color_suffix} "
  1377.         echo -e ${user_list_all}
  1378.     fi
  1379. }
  1380. centos_View_user_connection_info(){
  1381.     now_mode=`jq '.port_password' ${config_user_file}`
  1382.     if [[ "${now_mode}" = "null" ]]; then
  1383.         now_mode="${Word_single_port}" && user_total="1"
  1384.         IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' | grep '::ffff:' |awk '{print $4}' |sort -u |wc -l`
  1385.         user_port=`jq '.server_port' ${config_user_file}`
  1386.         user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u`
  1387.         user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l`
  1388.         user_list_all="1. ${Word_port}: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, ${Prompt_total_number_of_ip_number} ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, ${Prompt_the_currently_connected_ip} ${Green_font_prefix}"${user_IP}"${Font_color_suffix}\n"
  1389.         echo -e "${Word_current_mode} ${Green_font_prefix} "${now_mode}" ${Font_color_suffix} 。"
  1390.         echo -e ${user_list_all}
  1391.     else
  1392.         now_mode="${Word_multi_port}" && user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
  1393.         IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' | grep '::ffff:' |awk '{print $4}' |sort -u |wc -l`
  1394.         user_list_all=""
  1395.         user_id=0
  1396.         for((integer = 1; integer <= ${user_total}; integer++))
  1397.         do
  1398.             user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
  1399.             user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u`
  1400.             user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l`
  1401.             user_id=$[$user_id+1]
  1402.             user_list_all=${user_list_all}${user_id}". ${Word_port}: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, ${Prompt_total_number_of_ip_number} ${Green_font_prefix}"${user_IP_total}"${Font_color_suffix}, ${Prompt_the_currently_connected_ip} ${Green_font_prefix}"${user_IP}"${Font_color_suffix}\n"
  1403.         done
  1404.         echo -e "${Word_current_mode} ${Green_font_prefix} "${now_mode}" ${Font_color_suffix}${Word_current_mode} ${Green_font_prefix} "${user_total}" ${Font_color_suffix}${Prompt_total_number_of_ip} ${Green_font_prefix} "${IP_total}" ${Font_color_suffix} "
  1405.         echo -e ${user_list_all}
  1406.     fi
  1407. }
  1408. SSR_start(){
  1409.     cd ${ssr_ss_file}
  1410.     nohup python server.py a >> ssserver.log 2>&1 &
  1411.     sleep 2s
  1412.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1413.     if [[ ! -z "${PID}" ]]; then
  1414.         viewUser
  1415.         echo ${Separator_1} && echo && echo -e "    ShadowsocksR ${Word_has_started} !" && echo && echo ${Separator_1}
  1416.     else
  1417.         echo -e "${Error_startup_failed}"
  1418.     fi
  1419. }
  1420. #启动ShadowsocksR
  1421. StartSSR(){
  1422.     SSR_install_status
  1423.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1424.     [[ ! -z ${PID} ]] && echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR ${Word_running} !" && exit 1
  1425.     SSR_start
  1426. }
  1427. #停止ShadowsocksR
  1428. StopSSR(){
  1429.     SSR_install_status
  1430.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1431.     [[ -z $PID ]] && echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR ${Word_not_running} !" && exit 1
  1432.     kill -9 ${PID} && sleep 2s
  1433.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1434.     if [[ -z "${PID}" ]]; then
  1435.         echo ${Separator_1} && echo && echo -e "    ShadowsocksR ${Word_stopped} !" && echo && echo ${Separator_1}
  1436.     else
  1437.         echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR ${Word_stop_failing} !"
  1438.     fi
  1439. }
  1440. #重启ShadowsocksR
  1441. RestartSSR(){
  1442.     SSR_install_status
  1443.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1444.     [[ ! -z "${PID}" ]] && kill -9 ${PID}
  1445.     SSR_start
  1446. }
  1447. #查看 ShadowsocksR 日志
  1448. TailSSR(){
  1449.     [[ ! -e ${ssr_ss_file}"/ssserver.log" ]] && echo -e "${Error_no_log_found}" && exit 1
  1450.     echo && echo -e "${Prompt_log}" && echo
  1451.     tail -f ${ssr_ss_file}"/ssserver.log"
  1452. }
  1453. #查看 ShadowsocksR 状态
  1454. StatusSSR(){
  1455.     SSR_install_status
  1456.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1457.     if [[ -z "${PID}" ]]; then
  1458.         echo ${Separator_1} && echo && echo -e "    ShadowsocksR ${Word_not_running} !" && echo && echo ${Separator_1}
  1459.     else
  1460.         echo ${Separator_1} && echo && echo -e "    ShadowsocksR ${Word_running} (PID: ${PID}) !" && echo && echo ${Separator_1}
  1461.     fi
  1462. }
  1463. #安装锐速
  1464. installServerSpeeder(){
  1465.     [[ -e "/serverspeeder" ]] && echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} ${Word_installed} !" && exit 1
  1466.     cd /root
  1467.     #借用91yun.rog的开心版锐速
  1468.     wget -N --no-check-certificate https://raw.githubusercontent.com/91yun/serverspeeder/master/serverspeeder-all.sh
  1469.     bash serverspeeder-all.sh
  1470.     sleep 2s
  1471.     PID=`ps -ef |grep -v grep |grep "serverspeeder" |awk '{print $2}'`
  1472.     if [[ ! -z ${PID} ]]; then
  1473.         check_sys
  1474.         rc.local_serverspeed_set
  1475.         echo -e "${Green_font_prefix} [${Word_info}] ${Font_color_suffix} ${Word_serverspeeder} ${Word_the_installation_is_complete} !" && exit 1
  1476.     else
  1477.         echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ${Word_serverspeeder} ${Word_installation_failed} !" && exit 1
  1478.     fi
  1479. }
  1480. #查看锐速状态
  1481. StatusServerSpeeder(){
  1482.     [[ ! -e "/serverspeeder" ]] && echo -e "${Error_server_speeder_not_installed}" && exit 1
  1483.     /serverspeeder/bin/serverSpeeder.sh status
  1484. }
  1485. #停止锐速
  1486. StopServerSpeeder(){
  1487.     [[ ! -e "/serverspeeder" ]] && echo -e "${Error_server_speeder_not_installed}" && exit 1
  1488.     /serverspeeder/bin/serverSpeeder.sh stop
  1489. }
  1490. #重启锐速
  1491. RestartServerSpeeder(){
  1492.     [[ ! -e "/serverspeeder" ]] && echo -e "${Error_server_speeder_not_installed}" && exit 1
  1493.     /serverspeeder/bin/serverSpeeder.sh restart
  1494. }
  1495. #卸载锐速
  1496. UninstallServerSpeeder(){
  1497.     [[ ! -e "/serverspeeder" ]] && echo -e "${Error_server_speeder_not_installed}" && exit 1
  1498.     echo "${Info_uninstall_server}"
  1499.     echo
  1500.     read -p "(${Word_default}: n):" unyn
  1501.     [[ -z ${unyn} ]] && unyn="n"
  1502.     if [[ ${unyn} == [Yy] ]]; then
  1503.         rm -rf /root/serverspeeder-all.sh
  1504.         rm -rf /root/91yunserverspeeder
  1505.         rm -rf /root/91yunserverspeeder.tar.gz
  1506.         check_sys
  1507.         rc.local_serverspeed_del
  1508.         chattr -i /serverspeeder/etc/apx*
  1509.         /serverspeeder/bin/serverSpeeder.sh uninstall -f
  1510.         echo && echo "${Word_serverspeeder} ${Word_uninstall_is_complete} !" && echo
  1511.     else
  1512.         echo && echo "${Word_uninstall_cancelled}" && echo
  1513.     fi
  1514. }
  1515. BanBTPTSPAM(){
  1516.     wget -4qO- raw.githubusercontent.com/ToyoDAdoubi/doubi/master/Get_Out_Spam.sh | bash
  1517. }
  1518. InstallBBR(){
  1519.     echo -e "${Info_install_bbr_0}"
  1520.     echo
  1521.     echo "${Info_install_bbr}"
  1522.     read -p "(${Word_default}: ${Word_cancel}):" unyn
  1523.     [[ -z ${unyn} ]] && echo "${Word_canceled}" && exit 1
  1524.     if [[ ${unyn} == [Yy] ]]; then
  1525.         wget -N --no-check-certificate https://softs.pw/Bash/bbr.sh && chmod +x bbr.sh && bash bbr.sh
  1526.     fi
  1527. }
  1528. SetCrontab_interval(){
  1529.     echo -e "${Info_set_crontab_interval_0}"
  1530.     echo "${Info_input_set_crontab_interval}"
  1531.     read -p "(${Word_default}: ${Info_input_set_crontab_interval_default} ):" crontab_interval
  1532.     [[ -z "${crontab_interval}" ]] && crontab_interval="0 2 * * *"
  1533.     echo
  1534.     echo "——————————————————————————————"
  1535.     echo -e "   ${Word_timing_interval} : ${Red_font_prefix} ${crontab_interval} ${Font_color_suffix}"
  1536.     echo "——————————————————————————————"
  1537.     echo
  1538. }
  1539. SetCrontab(){
  1540.     SSR_install_status
  1541.     check_sys
  1542.     if [[ ${release} = "centos" ]]; then
  1543.         corn_status=`service crond status`
  1544.     else
  1545.         corn_status=`service cron status`
  1546.     fi
  1547.     if [[ -z ${corn_status} ]]; then
  1548.         echo -e "${Info_no_cron_installed}"
  1549.         if [[ ${release} = "centos" ]]; then
  1550.             yum update && yum install crond -y
  1551.         else
  1552.             apt-get update && apt-get install cron -y
  1553.         fi
  1554.         if [[ ${release} = "centos" ]]; then
  1555.             corn_status=`service crond status`
  1556.         else
  1557.             corn_status=`service cron status`
  1558.         fi
  1559.         [[ -z ${corn_status} ]] && echo -e "${Error_cron_installation_failed}" && exit 1
  1560.     fi
  1561.     echo -e "${Info_input_set_cron}"
  1562.     echo
  1563.     read -p "(${Word_default} :${Word_cancel}):" setcron_select
  1564.     [[ -z "${setcron_select}" ]] && exit 1
  1565.     if [[ ${setcron_select} != "1" ]]; then
  1566.         if [[ ${setcron_select} != "2" ]]; then
  1567.             exit 1
  1568.         fi
  1569.     fi
  1570.     cron_ssr=`crontab -l | grep "${ssr_file}/${auto_restart_cron}" | wc -l`
  1571.     if [[ ${cron_ssr} > "0" ]]; then
  1572.         crontab -l > ${ssr_file}"/crontab.bak"
  1573.         sed -i "/\/etc\/shadowsocksr\/${auto_restart_cron}/d" ${ssr_file}"/crontab.bak"
  1574.         crontab ${ssr_file}"/crontab.bak"
  1575.         rm -rf ${ssr_file}"/crontab.bak"
  1576.         cron_ssr=`crontab -l | grep "${ssr_file}/${auto_restart_cron}" | wc -l`
  1577.         if [[ ${cron_ssr} > "0" ]]; then
  1578.             echo -e "${Error_set_corn_del_failed}" && exit 1
  1579.         fi
  1580.     else
  1581.         if [[ ${setcron_select} == "2" ]]; then
  1582.             echo -e "${Info_set_corn_status}" && exit 1
  1583.         fi
  1584.     fi
  1585.     if [[ ${setcron_select} == "2" ]]; then
  1586.         echo -e "${Info_set_corn_del_success}" && exit 1
  1587.     fi
  1588.     SetCrontab_interval
  1589.     cat > ${ssr_file}"/"${auto_restart_cron}<<-EOF
  1590. #!/usr/bin/env bash
  1591. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  1592. export PATH
  1593. server_ss_file="/etc/shadowsocksr/shadowsocks/"
  1594. server_file=${server_ss_file}"server.py"
  1595. config_user_file="/etc/shadowsocksr/user-config.json"
  1596.  
  1597. [ ! -e $config_user_file ] && exit 1
  1598. PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1599. [ ! -z "${PID}" ] && kill -9 ${PID}
  1600. cd ${server_ss_file}
  1601. nohup python server.py a >> ssserver.log 2>&1 &
  1602. sleep 2s
  1603. PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1604. if [ ! -z "${PID}" ]; then
  1605.     echo -e "   ShadowsocksR 重启完成 !"
  1606. else
  1607.     echo -e "${Red_font_prefix} [${Word_error}] ${Font_color_suffix} ShadowsocksR 启动失败 !"
  1608. fi
  1609. EOF
  1610.     if [[ -s ${ssr_file}"/"${auto_restart_cron} ]]; then
  1611.         chmod +x ${ssr_file}"/"${auto_restart_cron}
  1612.         crontab -l > ${ssr_file}"/crontab.bak"
  1613.         echo "${crontab_interval} /bin/bash ${ssr_file}/${auto_restart_cron}" >> ${ssr_file}"/crontab.bak"
  1614.         crontab ${ssr_file}"/crontab.bak"
  1615.         rm -rf ${ssr_file}"/crontab.bak"
  1616.         cron_ssr=`crontab -l | grep "${ssr_file}/${auto_restart_cron}" | wc -l`
  1617.         if [[ ${cron_ssr} > "0" ]]; then
  1618.             cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  1619.             if [[ ${release} = "centos" ]]; then
  1620.                 service crond restart
  1621.             else
  1622.                 service cron restart
  1623.             fi
  1624.             echo -e "${Info_set_corn_add_success}"
  1625.         else
  1626.             echo -e "${Error_set_corn_add_failed}" && exit 1
  1627.         fi
  1628.        
  1629.     else
  1630.         rm -rf ${ssr_file}"/"${auto_restart_cron}
  1631.         echo -e "${Error_set_corn_Write_failed}"
  1632.     fi
  1633. }
  1634. # 设置设备数
  1635. Client_limit(){
  1636.     SSR_install_status
  1637.     getUser
  1638.     if [[ ${protocol} != "origin" ]]; then
  1639.         protocol_1=`echo ${protocol} | sed 's/_compatible//g'`
  1640.         if [[ ${protocol} == ${protocol_1} ]]; then
  1641.             while true
  1642.             do
  1643.             echo
  1644.             echo -e "${Info_input_number_of_devices}"
  1645.             echo -e "${Prompt_number_of_devices}"
  1646.             read -p "(${Word_default}: ${Word_unlimited}):" ssprotocol_param
  1647.             [[ -z "$ssprotocol_param" ]] && ssprotocol_param="" && break
  1648.             expr ${ssprotocol_param} + 0 &>/dev/null
  1649.             if [[ $? -eq 0 ]]; then
  1650.                 if [[ ${ssprotocol_param} -ge 1 ]] && [[ ${ssprotocol_param} -le 99999 ]]; then
  1651.                     echo && echo ${Separator_1} && echo -e "    ${Word_number_of_devices} : ${Green_font_prefix}${ssprotocol_param}${Font_color_suffix}" && echo ${Separator_1} && echo
  1652.                     break
  1653.                 else
  1654.                     echo "${Errpr_input_num_error}"
  1655.                 fi
  1656.             else
  1657.                 echo "${Errpr_input_num_error}"
  1658.             fi
  1659.             done
  1660.         else
  1661.             echo -e "${Error_limit_the_number_of_devices_1}" && exit 1
  1662.         fi
  1663.     else
  1664.         echo -e "${Error_limit_the_number_of_devices_2}" && exit 1
  1665.     fi
  1666.     set_config_protocol_param
  1667.     RestartSSR
  1668.     echo -e "${Info_limit_the_number_of_devices}"
  1669. }
  1670. Speed_limit(){
  1671.     SSR_install_status
  1672.     # 设置单线程限速
  1673.     while true
  1674.     do
  1675.     echo
  1676.     echo -e "${Info_input_single_threaded_speed_limit}"
  1677.     echo -e "${Prompt_input_single_threaded_speed_limit}"
  1678.     read -p "(${Word_default}: ${Word_unlimited}):" ssspeed_limit_per_con
  1679.     [[ -z "$ssspeed_limit_per_con" ]] && ssspeed_limit_per_con=0 && break
  1680.     expr ${ssspeed_limit_per_con} + 0 &>/dev/null
  1681.     if [[ $? -eq 0 ]]; then
  1682.         if [[ ${ssspeed_limit_per_con} -ge 1 ]] && [[ ${ssspeed_limit_per_con} -le 99999 ]]; then
  1683.             echo && echo ${Separator_1} && echo -e "    ${Word_single_threaded_speed_limit} : ${Green_font_prefix}${ssspeed_limit_per_con} KB/S ${Font_color_suffix}" && echo ${Separator_1} && echo
  1684.             break
  1685.         else
  1686.             echo "${Errpr_input_num_error}"
  1687.         fi
  1688.     else
  1689.         echo "${Errpr_input_num_error}"
  1690.     fi
  1691.     done
  1692.     # 设置端口总限速
  1693.     while true
  1694.     do
  1695.     echo
  1696.     echo -e "${Info_total_port_speed_limit}"
  1697.     echo -e "${Prompt_total_port_speed_limit}"
  1698.     read -p "(${Word_default}: ${Word_unlimited}):" ssspeed_limit_per_user
  1699.     [[ -z "$ssspeed_limit_per_user" ]] && ssspeed_limit_per_user=0 && break
  1700.     expr ${ssspeed_limit_per_user} + 0 &>/dev/null
  1701.     if [[ $? -eq 0 ]]; then
  1702.         if [[ ${ssspeed_limit_per_user} -ge 1 ]] && [[ ${ssspeed_limit_per_user} -le 99999 ]]; then
  1703.             echo && echo ${Separator_1} && echo -e "    ${Word_port_total_speed_limit} : ${Green_font_prefix}${ssspeed_limit_per_user} KB/S ${Font_color_suffix}" && echo ${Separator_1} && echo
  1704.             break
  1705.         else
  1706.             echo "${Errpr_input_num_error}"
  1707.         fi
  1708.     else
  1709.         echo "${Errpr_input_num_error}"
  1710.     fi
  1711.     done
  1712.     getUser
  1713.     set_config_speed_limit_per
  1714.     RestartSSR
  1715.     echo -e "${Info_port_speed_limit}"
  1716. }
  1717. Switch_language(){
  1718.     if [[ ! -e "${PWD}/lang_en" ]]; then
  1719.         echo -e "${Prompt_switch_language_english}"
  1720.         echo && echo -e "${Info_switch_language_english}"
  1721.         read -p "(${Word_default}: ${Word_cancel}):" unyn
  1722.         [[ -z ${unyn} ]] && echo "${Word_canceled}" && exit 1
  1723.         if [[ ${unyn} == [Yy] ]]; then
  1724.             echo "lang_en" > "${PWD}/lang_en"
  1725.             echo -e "${Info_switch_language_1}" && exit 1
  1726.         fi
  1727.     else
  1728.         echo -e "${Prompt_switch_language_chinese}"
  1729.         echo && echo -e "${Info_switch_language_chinese}"
  1730.         read -p "(${Word_default}: ${Word_cancel}):" unyn
  1731.         [[ -z ${unyn} ]] && echo "${Word_canceled}" && exit 1
  1732.         if [[ ${unyn} == [Yy] ]]; then
  1733.             rm -rf "${PWD}/lang_en"
  1734.             echo -e "${Info_switch_language_1}" && exit 1
  1735.         fi
  1736.     fi
  1737. }
  1738. Language
  1739. #菜单判断
  1740. echo
  1741. echo && echo "${Menu_prompt_1}" && echo
  1742. echo -e "${Menu_options}"
  1743. check_sys
  1744. [[ ${release} != "centos" ]] && echo -e "${Menu_options_bbr}"
  1745. echo -e "${Menu_options_other}"
  1746. if [[ -e $config_user_file ]]; then
  1747.     PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  1748.     if [[ ! -z "${PID}" ]]; then
  1749.         echo -e "${Menu_status_1}"
  1750.     else
  1751.         echo -e "${Menu_status_2}"
  1752.     fi
  1753.     now_mode_1=`jq '.port_password' ${config_user_file}`
  1754.     if [[ "${now_mode_1}" = "null" ]]; then
  1755.         echo -e "${Menu_mode_1}"
  1756.     else
  1757.         echo -e "${Menu_mode_2}"
  1758.     fi
  1759. else
  1760.     echo -e "${Menu_status_3}"
  1761. fi
  1762. echo
  1763. read -p "${Menu_prompt_2}" num
  1764.  
  1765. case "$num" in
  1766.     1)
  1767.     installSSR
  1768.     ;;
  1769.     2)
  1770.     installLibsodium
  1771.     ;;
  1772.     3)
  1773.     viewUser
  1774.     ;;
  1775.     4)
  1776.     View_user_connection_info
  1777.     ;;
  1778.     5)
  1779.     modifyUser
  1780.     ;;
  1781.     6)
  1782.     manuallyModifyUser
  1783.     ;;
  1784.     7)
  1785.     UninstallSSR
  1786.     ;;
  1787.     8)
  1788.     UpdateSSR
  1789.     ;;
  1790.     9)
  1791.     Port_mode_switching
  1792.     ;;
  1793.     10)
  1794.     Add_multi_port_user
  1795.     ;;
  1796.     11)
  1797.     Modify_multi_port_user
  1798.     ;;
  1799.     12)
  1800.     Del_multi_port_user
  1801.     ;;
  1802.     13)
  1803.     StartSSR
  1804.     ;;
  1805.     14)
  1806.     StopSSR
  1807.     ;;
  1808.     15)
  1809.     RestartSSR
  1810.     ;;
  1811.     16)
  1812.     StatusSSR
  1813.     ;;
  1814.     17)
  1815.     TailSSR
  1816.     ;;
  1817.     18)
  1818.     installServerSpeeder
  1819.     ;;
  1820.     19)
  1821.     StopServerSpeeder
  1822.     ;;
  1823.     20)
  1824.     RestartServerSpeeder
  1825.     ;;
  1826.     21)
  1827.     StatusServerSpeeder
  1828.     ;;
  1829.     22)
  1830.     UninstallServerSpeeder
  1831.     ;;
  1832.     23)
  1833.     InstallBBR
  1834.     ;;
  1835.     24)
  1836.     BanBTPTSPAM
  1837.     ;;
  1838.     25)
  1839.     SetCrontab
  1840.     ;;
  1841.     26)
  1842.     Client_limit
  1843.     ;;
  1844.     27)
  1845.     Speed_limit
  1846.     ;;
  1847.     0)
  1848.     Switch_language
  1849.     ;;
  1850.     *)
  1851.     echo "${Menu_prompt_3}"
  1852.     ;;
  1853. esac
Add Comment
Please, Sign In to add comment