diff --git a/ssrmu.sh b/ssrmu.sh index f93a3328..eca87417 100644 --- a/ssrmu.sh +++ b/ssrmu.sh @@ -5,12 +5,12 @@ export PATH #================================================= # System Required: CentOS 6+/Debian 6+/Ubuntu 14.04+ # Description: Install the ShadowsocksR mudbjson server -# Version: 1.0.9 +# Version: 1.0.10 # Author: Toyo # Blog: https://doub.io/ss-jc60/ #================================================= -sh_ver="1.0.9" +sh_ver="1.0.10" filepath=$(cd "$(dirname "$0")"; pwd) file=$(echo -e "${filepath}"|awk -F "$0" '{print $1}') ssr_folder="/usr/local/shadowsocksr" @@ -166,9 +166,12 @@ Get_User_transfer(){ #echo "u_1=${u_1}" d_1=$(${jq_file} ".[${port_num_1}].d" ${config_user_mudb_file}) #echo "d_1=${d_1}" - transfer_enable_Used_1=$(expr ${transfer_enable_1} - $(expr ${u_1} + ${d_1})) + transfer_enable_Used_2_1=$(expr ${u_1} + ${d_1}) + #echo "transfer_enable_Used_2_1=${transfer_enable_Used_2_1}" + transfer_enable_Used_1=$(expr ${transfer_enable_1} - ${transfer_enable_Used_2_1}) #echo "transfer_enable_Used_1=${transfer_enable_Used_1}" + if [[ ${transfer_enable_1} -lt 1024 ]]; then transfer_enable="${transfer_enable_1} B" elif [[ ${transfer_enable_1} -lt 1048576 ]]; then @@ -233,6 +236,22 @@ Get_User_transfer(){ transfer_enable_Used="${transfer_enable_Used} TB" fi #echo "transfer_enable_Used=${transfer_enable_Used}" + if [[ ${transfer_enable_Used_2_1} -lt 1024 ]]; then + transfer_enable_Used_2="${transfer_enable_Used_2_1} B" + elif [[ ${transfer_enable_Used_2_1} -lt 1048576 ]]; then + transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1024'}') + transfer_enable_Used_2="${transfer_enable_Used_2} KB" + elif [[ ${transfer_enable_Used_2_1} -lt 1073741824 ]]; then + transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1048576'}') + transfer_enable_Used_2="${transfer_enable_Used_2} MB" + elif [[ ${transfer_enable_Used_2_1} -lt 1099511627776 ]]; then + transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1073741824'}') + transfer_enable_Used_2="${transfer_enable_Used_2} GB" + elif [[ ${transfer_enable_Used_2_1} -lt 1125899906842624 ]]; then + transfer_enable_Used_2=$(awk 'BEGIN{printf "%.2f\n",'${transfer_enable_Used_2_1}'/'1099511627776'}') + transfer_enable_Used_2="${transfer_enable_Used_2} TB" + fi + #echo "transfer_enable_Used_2=${transfer_enable_Used_2}" } urlsafe_base64(){ date=$(echo -n "$1"|base64|sed ':a;N;s/\n/ /g;ta'|sed 's/ //g;s/=//g;s/+/-/g;s/\//_/g') @@ -293,7 +312,7 @@ View_User(){ echo -e "请输入要查看账号信息的用户 端口" stty erase '^H' && read -p "(默认: 取消):" View_user_port [[ -z "${View_user_port}" ]] && echo -e "已取消..." && exit 1 - View_user=$(echo "${user_list_all}"|grep "端口: \\\033\\[32m${View_user_port}\\\033\\[0m,") + View_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${View_user_port}"',') if [[ ! -z ${View_user} ]]; then Get_User_info "${View_user_port}" View_User_info @@ -319,7 +338,7 @@ View_User_info(){ echo -e " 用户总限速 : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}" echo -e " 禁止的端口 : ${Green_font_prefix}${forbidden_port} ${Font_color_suffix}" echo - echo -e " 已使用流量 : 上传: ${Green_font_prefix}${u}${Font_color_suffix} 下载: ${Green_font_prefix}${d}${Font_color_suffix}" + echo -e " 已使用流量 : 上传: ${Green_font_prefix}${u}${Font_color_suffix} + 下载: ${Green_font_prefix}${d}${Font_color_suffix} = ${Green_font_prefix}${transfer_enable_Used_2}${Font_color_suffix}" echo -e " 剩余的流量 : ${Green_font_prefix}${transfer_enable_Used} ${Font_color_suffix}" echo -e " 用户总流量 : ${Green_font_prefix}${transfer_enable} ${Font_color_suffix}" echo -e "${ss_link}" @@ -581,6 +600,47 @@ Set_config_forbid(){ [[ -z "${ssr_forbid}" ]] && ssr_forbid="" echo && echo ${Separator_1} && echo -e " 禁止的端口 : ${Green_font_prefix}${ssr_forbid}${Font_color_suffix}" && echo ${Separator_1} && echo } +Set_config_enable(){ + user_total=$(expr ${user_total} - 1) + for((integer = 0; integer <= ${user_total}; integer++)) + do + echo -e "integer=${integer}" + port_jq=$(${jq_file} ".[${integer}].port" "${config_user_mudb_file}") + echo -e "port_jq=${port_jq}" + if [[ "${ssr_port}" == "${port_jq}" ]]; then + enable=$(${jq_file} ".[${integer}].enable" "${config_user_mudb_file}") + echo -e "enable=${enable}" + [[ "${enable}" == "null" ]] && echo -e "${Error} 获取当前端口[${ssr_port}]的禁用状态失败 !" && exit 1 + ssr_port_num=$(cat "${config_user_mudb_file}"|grep -n '"port": '${ssr_port}','|awk -F ":" '{print $1}') + echo -e "ssr_port_num=${ssr_port_num}" + [[ "${ssr_port_num}" == "null" ]] && echo -e "${Error} 获取当前端口[${ssr_port}]的行数失败 !" && exit 1 + ssr_enable_num=$(expr ${ssr_port_num} - 5) + echo -e "ssr_enable_num=${ssr_enable_num}" + break + fi + done + if [[ "${enable}" == "1" ]]; then + echo -e "端口 [${ssr_port}] 的账号状态为:${Green_font_prefix}启用${Font_color_suffix} , 是否切换为 ${Red_font_prefix}禁用${Font_color_suffix} ?[Y/n]" + stty erase '^H' && read -p "(默认: Y):" ssr_enable_yn + [[ -z "${ssr_enable_yn}" ]] && ssr_enable_yn="y" + if [[ "${ssr_enable_yn}" == [Yy] ]]; then + ssr_enable="0" + else + echo "取消..." && exit 0 + fi + elif [[ "${enable}" == "0" ]]; then + echo -e "端口 [${ssr_port}] 的账号状态为:${Green_font_prefix}禁用${Font_color_suffix} , 是否切换为 ${Red_font_prefix}启用${Font_color_suffix} ?[Y/n]" + stty erase '^H' && read -p "(默认: Y):" ssr_enable_yn + [[ -z "${ssr_enable_yn}" ]] && ssr_enable_yn = "y" + if [[ "${ssr_enable_yn}" == [Yy] ]]; then + ssr_enable="1" + else + echo "取消..." && exit 0 + fi + else + echo -e "${Error} 当前端口的禁用状态异常[${enable}] !" && exit 1 + fi +} Set_config_all(){ lal=$1 if [[ "${lal}" == "Modify" ]]; then @@ -683,6 +743,9 @@ Modify_config_forbid(){ echo -e "${Info} 用户修改成功 ${Green_font_prefix}[端口: ${ssr_port}]${Font_color_suffix} (注意:可能需要十秒左右才会应用最新配置)" fi } +Modify_config_enable(){ + sed -i "${ssr_enable_num}"'s/"enable": '"$(echo ${enable})"',/"enable": '"$(echo ${ssr_enable})"',/' ${config_user_mudb_file} +} Modify_config_all(){ Modify_config_password Modify_config_method @@ -985,7 +1048,7 @@ Modify_port(){ echo -e "请输入要修改的用户 端口" stty erase '^H' && read -p "(默认: 取消):" ssr_port [[ -z "${ssr_port}" ]] && echo -e "已取消..." && exit 1 - Modify_user=$(echo "${user_list_all}"|grep "端口: \\\033\\[32m${ssr_port}\\\033\\[0m,") + Modify_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${ssr_port}"',') if [[ ! -z ${Modify_user} ]]; then break else @@ -1071,7 +1134,7 @@ List_port_user(){ user_port=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $4}') user_username=$(echo "${user_info}"|sed -n "${integer}p"|awk '{print $2}'|sed 's/\[//g;s/\]//g') Get_User_transfer "${user_port}" - user_list_all=${user_list_all}"用户名: ${Green_font_prefix}"${user_username}"${Font_color_suffix}, 端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}, 流量使用情况(总/剩余): ${Green_font_prefix}${transfer_enable} / ${transfer_enable_Used}${Font_color_suffix}\n" + user_list_all=${user_list_all}"用户名: ${Green_font_prefix} "${user_username}"${Font_color_suffix}\t 端口: ${Green_font_prefix}"${user_port}"${Font_color_suffix}\t 流量使用情况(已用+剩余=总): ${Green_font_prefix}${transfer_enable_Used_2}${Font_color_suffix} + ${Green_font_prefix}${transfer_enable_Used}${Font_color_suffix} = ${Green_font_prefix}${transfer_enable}${Font_color_suffix}\n" done echo && echo -e "=== 用户总数 ${Green_background_prefix} "${user_total}" ${Font_color_suffix}" echo -e ${user_list_all} @@ -1105,7 +1168,7 @@ Del_port_user(){ echo -e "请输入要删除的用户 端口" stty erase '^H' && read -p "(默认: 取消):" del_user_port [[ -z "${del_user_port}" ]] && echo -e "已取消..." && exit 1 - del_user=$(echo "${user_list_all}"|grep "端口: \\\033\\[32m${del_user_port}\\\033\\[0m,") + del_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${del_user_port}"',') if [[ ! -z ${del_user} ]]; then port=${del_user_port} match_del=$(python mujson_mgr.py -d -p "${del_user_port}"|grep -w "delete user ") @@ -1174,7 +1237,7 @@ Clear_transfer_one(){ echo -e "请输入要清零已使用流量的用户 端口" stty erase '^H' && read -p "(默认: 取消):" Clear_transfer_user_port [[ -z "${Clear_transfer_user_port}" ]] && echo -e "已取消..." && exit 1 - Clear_transfer_user=$(echo "${user_list_all}"|grep "端口: \\\033\\[32m${Clear_transfer_user_port}\\\033\\[0m,") + Clear_transfer_user=$(cat "${config_user_mudb_file}"|grep '"port": '"${Clear_transfer_user_port}"',') if [[ ! -z ${Clear_transfer_user} ]]; then match_clear=$(python mujson_mgr.py -c -p "${Clear_transfer_user_port}"|grep -w "clear user ") if [[ -z "${match_clear}" ]]; then